Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphPolargram.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Sebastian Boser, Mathieu Demaret 02/02/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TGraphPolargram
13\ingroup BasicGraphics
14
15To draw polar axis
16
17TGraphPolargram draw the polar axis of the TGraphPolar.
18
19Example:
20
21Begin_Macro(source)
22{
23 TCanvas * CPol = new TCanvas("CPol","TGraphPolar Examples",500,500);
24
25 Double_t rmin=0;
26 Double_t rmax=TMath::Pi()*2;
27 Double_t r[1000];
28 Double_t theta[1000];
29
30 TF1 * fp1 = new TF1("fplot","cos(x)",rmin,rmax);
31 for (Int_t ipt = 0; ipt < 1000; ipt++) {
32 r[ipt] = ipt*(rmax-rmin)/1000+rmin;
33 theta[ipt] = fp1->Eval(r[ipt]);
34 }
35 TGraphPolar * grP1 = new TGraphPolar(1000,r,theta);
36 grP1->SetTitle("");
37 grP1->SetLineColor(2);
38 grP1->Draw("AOL");
39}
40End_Macro
41*/
42
43#include "TGraphPolar.h"
44#include "TGraphPolargram.h"
45#include "TGaxis.h"
46#include "THLimitsFinder.h"
47#include "TVirtualPad.h"
48#include "TColor.h"
49#include "TLatex.h"
50#include "TEllipse.h"
51#include "TMath.h"
52
53#include <string>
54
55////////////////////////////////////////////////////////////////////////////////
56/// TGraphPolargram Constructor.
57
59 Double_t tmin, Double_t tmax, const char *opt):
60 TNamed(name, "Polargram")
61{
62 Init();
63 fNdivRad = 508;
64 fNdivPol = 508;
65 fPolarLabels = nullptr;
66 fRwrmax = rmax;
67 fRwrmin = rmin;
68 fRwtmin = tmin;
69 fRwtmax = tmax;
70
71 TString s = opt;
72 s.ToUpper();
73 if (s.Contains("R")) {
74 fRadian = kTRUE;
75 fRwtmin = 0;
76 fRwtmax = 2*TMath::Pi();
77 } else if (s.Contains("D")) {
78 fDegree = kTRUE;
79 fRwtmin = 0;
80 fRwtmax = 360;
81 } else if (s.Contains("G")) {
82 fGrad = kTRUE;
83 fRwtmin = 0;
84 fRwtmax = 200;
85 }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Short constructor used in the case of a spider plot.
90
92 TNamed(name,"Polargram")
93{
94 Init();
95 fNdivRad = 0;
96 fNdivPol = 0;
97 fPolarLabels = nullptr;
98 fRwrmax = 1;
99 fRwrmin = 0;
100 fRwtmax = 0;
101 fRwtmin = 0;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// TGraphPolargram destructor.
106
111
112////////////////////////////////////////////////////////////////////////////////
113/// Set the Polar range.
114/// \param[in] tmin the start number.
115/// \param[in] tmax the end number.
116
118{
119 if (tmin < tmax) {
120 fRwtmin = tmin;
121 fRwtmax = tmax;
122 }
123 if (gPad) gPad->Modified();
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Everything within the circle belongs to the TGraphPolargram.
128
130{
131 if (!gPad) return 9999;
132 Int_t i;
133 Double_t x = gPad->AbsPixeltoX(px);
134 Double_t y = gPad->AbsPixeltoY(py);
135
136 // Check if close to a (major) radial line.
137 Double_t rad = TMath::Sqrt(x*x+y*y);
138 Int_t div = (Int_t)rad*(fNdivRad%100);
140 TMath::Abs(rad-(div+1)*1./(fNdivRad%100)));
141 Int_t drad = gPad->XtoPixel(dr)-gPad->XtoPixel(0);
142
143 // Check if close to a (major) Polar line.
144 // This is not a proper calculation, but rather fast.
146 for (i=0; i<(fNdivPol%100); i++) {
147 Double_t theta = i*2*TMath::Pi()/(fNdivPol%100);
148
149 // Attention: px,py in pixel units, line given in user coordinates.
150 Int_t dthis = DistancetoLine(px,py,0.,0.,TMath::Cos(theta),
151 TMath::Sin(theta));
152
153 // Fails if we are outside box described by the line.
154 // (i.e for all hor/vert lines)
155 if (dthis==9999) {
156
157 // Outside -> Get distance to endpoint of line.
158 if (rad>1) {
160 TMath::Power(px-gPad->XtoPixel(TMath::Cos(theta)),2)+
161 TMath::Power(py-gPad->YtoPixel(TMath::Sin(theta)),2));
162 } else {
163
164 // Check for horizontal line.
165 if (((TMath::Abs(theta-TMath::Pi())<0.1) &&
166 ((px-gPad->XtoPixel(0))<0)) ||
167 ((TMath::Abs(theta)<0.1) &&
168 ((px-gPad->XtoPixel(0))>0))) {
169 dthis = TMath::Abs(py-gPad->YtoPixel(0.));
170 }
171
172 //Check for vertical line.
173 if (((TMath::Abs(theta-TMath::PiOver2())<0.1) &&
174 ((py-gPad->YtoPixel(0))>0)) ||
175 ((TMath::Abs(theta-3*TMath::PiOver2())<0.1) &&
176 (py-gPad->YtoPixel(0))<0)) {
177 dthis = TMath::Abs(px-gPad->XtoPixel(0.));
178 }
179 if (dthis==9999) {
180
181 // Inside, but out of box for nonorthogonal line ->
182 // get distance to start point.
184 TMath::Power(px-gPad->XtoPixel(0.),2)+
185 TMath::Power(py-gPad->YtoPixel(0.),2));
186 }
187 }
188 }
189
190 // Take distance to closes line.
192 }
193 return TMath::Min(drad, dt);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Draw Polargram.
198
200{
201 Paint(options);
202 AppendPad(options);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Indicate that there is something to click here.
207
209{
210 if (!gPad) return;
211
212 Int_t kMaxDiff = 20;
213 static Int_t d1, d2, d3, px1, py1, px3, py3;
214 static Bool_t p1, p2, p3, p4, p5, p6, p7, p8;
215 Double_t px2, py2;
216 p2 = p3 = p4 = p5 = p6 = p7 = p8 = kFALSE;
217 if (!gPad->IsEditable()) return;
218 switch (event) {
219 case kMouseMotion:
220 px1 = gPad->XtoAbsPixel(TMath::Cos(GetAngle()));
221 py1 = gPad->YtoAbsPixel(TMath::Sin(GetAngle()));
222 d1 = TMath::Abs(px1 - px) + TMath::Abs(py1-py); //simply take sum of pixels differences
223 p1 = kFALSE;
224 px2 = gPad->XtoAbsPixel(-1);
225 py2 = gPad->YtoAbsPixel(1);
226 d2 = (Int_t)(TMath::Abs(px2 - px) + TMath::Abs(py2 - py)) ;
227 px3 = gPad->XtoAbsPixel(-1);
228 py3 = gPad->YtoAbsPixel(-1);
229 d3 = TMath::Abs(px3 - px) + TMath::Abs(py3 - py) ; //simply take sum of pixels differences
230 // check if point is close to the radial axis
231 if (d1 < kMaxDiff) {
232 gPad->SetCursor(kMove);
233 p1 = kTRUE;
234 }
235 // check if point is close to the left high axis
236 if ( d2 < kMaxDiff) {
237 gPad->SetCursor(kHand);
238 p7 = kTRUE;
239 }
240 // check if point is close to the left down axis
241 if ( d3 < kMaxDiff) {
242 gPad->SetCursor(kHand);
243 p8 = kTRUE;
244 }
245 // check if point is close to a main circle
246 if (!p1 && !p7 ) {
247 p6 = kTRUE;
248 gPad->SetCursor(kHand);
249 }
250 break;
251
252 case kButton1Down:
253 // Record initial coordinates
254 //px4 = px;
255 //py4 = py;
256
257 case kButton1Motion:
258 if (p1) {
259 px2 = gPad->AbsPixeltoX(px);
260 py2 = gPad->AbsPixeltoY(py);
261 if ( px2 < 0 && py2 < 0) {p2 = kTRUE;};
262 if ( px2 < 0 && py2 > 0 ) {p3 = kTRUE;};
263 if ( px2 > 0 && py2 > 0 ) {p4 = kTRUE;};
264 if ( px2 > 0 && py2 < 0 ) {p5 = kTRUE;};
265 px2 = TMath::ACos(TMath::Abs(px2));
266 py2 = TMath::ASin(TMath::Abs(py2));
267 if (p2) {
268 fAxisAngle = TMath::Pi()+(px2+py2)/2;
269 p2 = kFALSE;
270 };
271 if (p3) {
272 fAxisAngle = TMath::Pi()-(px2+py2)/2;
273 p3 = kFALSE;
274 };
275 if (p4) {
276 fAxisAngle = (px2+py2)/2;
277 p4 = kFALSE;
278 };
279 if (p5) {
280 fAxisAngle = -(px2+py2)/2;
281 p5 = kFALSE;
282 };
283 }
284 break;
285
286 case kButton1Up:
287 Paint();
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Find the alignement rule to apply for TText::SetTextAlign(Short_t).
293
295{
296 Double_t pi = TMath::Pi();
297
298 while(angle < 0 || angle > 2*pi){
299 if(angle < 0) angle+=2*pi;
300 if(angle > 2*pi) angle-=2*pi;
301 }
303 if(angle > 0 && angle < pi/2) return 11;
304 else if(angle > pi/2 && angle < pi) return 31;
305 else if(angle > pi && angle < 3*pi/2) return 33;
306 else if(angle > 3*pi/2 && angle < 2*pi) return 13;
307 else if(angle == 0 || angle == 2*pi) return 12;
308 else if(angle == pi/2) return 21;
309 else if(angle == pi) return 32;
310 else if(angle == 3*pi/2) return 23;
311 else return 0;
312 }
313 else{
314 if(angle >= 0 && angle <= pi/2) return 12;
315 else if((angle > pi/2 && angle <= pi) || (angle > pi && angle <= 3*pi/2)) return 32;
316 else if(angle > 3*pi/2 && angle <= 2*pi) return 12;
317 else return 0;
318 }
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Determine the orientation of the polar labels according to their angle.
323
325{
326 Double_t pi = TMath::Pi();
327 Double_t convraddeg = 180.0/pi;
328
329 while(angle < 0 || angle > 2*pi){
330 if(angle < 0) angle+=2*pi;
331 if(angle > 2*pi) angle-=2*pi;
332 }
333
334 if(angle >= 0 && angle <= pi/2) return angle*convraddeg;
335 else if(angle > pi/2 && angle <= pi) return (angle + pi)*convraddeg;
336 else if(angle > pi && angle <= 3*pi/2) return (angle - pi)*convraddeg;
337 else if(angle > 3*pi/2 && angle <= 2*pi) return angle*convraddeg;
338 else return 0;
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Initialize some of the fields of TGraphPolargram.
343
345{
346 fAxisAngle = 0;
347 fCutRadial = 0;
348 fDegree = kFALSE;
349 fGrad = kFALSE;
350 fLineStyle = 3;
352 fPolarLabelFont = 62;
353 fPolarOffset = 0.04;
354 fPolarTextSize = 0.04;
355 fRadialOffset = 0.025;
356 fRadian = kTRUE;
358 fRadialLabelFont = 62;
359 fRadialTextSize = 0.035;
360 fTickpolarSize = 0.02;
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Paint TGraphPolargram.
365
384
385////////////////////////////////////////////////////////////////////////////////
386/// This is simplified from TEllipse::PaintEllipse.
387/// Draw this ellipse with new coordinates.
388
391{
392 if (!gPad) return;
393
394 Int_t i;
395 const Int_t np = 200; // Number of point to draw circle
396 static Double_t x[np+3], y[np+3];
397
398 // Set number of points approximatively proportional to the ellipse
399 // circumference.
400
402 Int_t n = (Int_t)(np*circ/((gPad->GetX2()-gPad->GetX1())+
403 (gPad->GetY2()-gPad->GetY1())));
404 if (n < 8) n = 8;
405 if (n > np) n = np;
407 Double_t dphi = (phimax-phimin)*TMath::Pi()/(180*n);
408 Double_t ct = TMath::Cos(TMath::Pi()*theta/180);
409 Double_t st = TMath::Sin(TMath::Pi()*theta/180);
410 for (i=0; i<=n; i++) {
411 angle = phimin*TMath::Pi()/180 + Double_t(i)*dphi;
412 dx = r*TMath::Cos(angle);
413 dy = r*TMath::Sin(angle);
414 x[i] = x1 + dx*ct - dy*st;
415 y[i] = y1 + dx*st + dy*ct;
416 }
417 gPad->PaintPolyLine(n+1,x,y);
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Draw Polar divisions.
422/// Check for editable pad or create default.
423
425{
426 if (!gPad) return ;
427 Int_t i, j, rnum, rden, first, last;
428
429 gPad->RangeAxis(-1,-1,1,1);
430 gPad->Range(-1.25,-1.25,1.25,1.25);
433
434 if (!gPad->GetLogy()) {
435 for (i=0; i<ndivMajor; i++) {
437 Double_t theta = i*2*TMath::Pi()/ndivMajor;
443 Double_t corr = 0.01;
444
446 textangular.SetTextColor(GetPolarColorLabel());
447 textangular.SetTextFont(GetPolarLabelFont());
448
449 TString form = " ";
450 TGaxis axis;
452 // Polar numbers are aligned with their axis.
453 if(!fPolarLabels && optionLabels){;
454 if (fRadian) {
455 // Radian case.
456 ReduceFraction(2*i, ndivMajor, rnum, rden); // Reduces the fraction.
457 if (rnum == 0) form.Form("%d",rnum);
458 if (rnum == 1 && rden == 1) form = "#pi";
459 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
460 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
461 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
462 textangular.SetTextAlign(FindAlign(theta));
463 textangular.PaintLatex(costhetas,
464 sinthetas, FindTextAngle(theta),
465 GetPolarLabelSize(), form.Data());
466 } else {
467 // Any other cases: numbers are aligned with their axis.
468 form.Form("%5.3g",txtval);
469 axis.LabelsLimits(form.Data(),first,last);
470 TString s = form;
471 if (first != 0) s.Remove(0, first);
472 textangular.SetTextAlign(FindAlign(theta));
473 textangular.PaintLatex(costhetas,
474 sinthetas, FindTextAngle(theta),
475 GetPolarLabelSize(), s);
476 }
477 } else if (fPolarLabels){
478 // print the specified polar labels
479 textangular.SetTextAlign(FindAlign(theta));
482 }
483 } else {
484 // Polar numbers are shown horizontally.
486 if (fRadian) {
487 // Radian case
489 if (rnum == 0) form.Form("%d",rnum);
490 if (rnum == 1 && rden == 1) form = "#pi";
491 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
492 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
493 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
494 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
495 textangular.SetTextAlign(FindAlign(theta));
496 textangular.PaintLatex(costhetas,corr+sinthetas,0,
497 GetPolarLabelSize(),form.Data());
498 } else {
499 // Any other cases where numbers are shown horizontally.
500 form.Form("%5.3g",txtval);
501 axis.LabelsLimits(form.Data(),first,last);
502 TString s = form;
503 if (first != 0) s.Remove(0, first);
504 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
505 textangular.SetTextAlign(FindAlign(theta));
506 textangular.PaintLatex(costhetas, //j'ai efface des offset la
507 corr+sinthetas,0,GetPolarLabelSize(),s);
508 }
509 } else if (fPolarLabels) {
510 // print the specified polar labels
511 textangular.SetTextAlign(FindAlign(theta));
513 }
514 }
516 //Check if SetTickPolar is activated, and draw tick marks
517 Bool_t issettickpolar = gPad->GetTicky();
518
519 if (issettickpolar) {
520 if (theta != 0 && theta !=TMath::Pi()) {
523 }
524 if (theta == 0 || theta ==TMath::Pi()) {
525 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
526 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
527 }
528 }
531 gPad->PaintLine(0.,0.,costheta,sintheta);
532 // Add minor lines w/o text.
534 TAttLine::SetLineStyle(2); //Minor lines always in this style.
535 TAttLine::Modify(); //Changes line attributes apart from style.
536 for (j=1; j<ndivMinor; j++) {
538 gPad->PaintLine(0.,0.,TMath::Cos(thetamin),TMath::Sin(thetamin));
539 }
542 }
543 } else {
545 Int_t test= 1;
546 while (big >= 10) {
547 big = big/10;
548 test++;
549 }
550 for (i=1; i<=test; i++) {
551 Double_t txtval = pow((double)10,(double)(i-1));
552 Double_t theta = (i-1)*2*TMath::Pi()/(double)(test);
558 Double_t corr = 0.01;
559
561 textangular.SetTextColor(GetPolarColorLabel());
562 textangular.SetTextFont(GetPolarLabelFont());
563
564 TString form = " ";
565 TGaxis axis;
566
569 // Polar numbers are aligned with their axis.
570 form.Form("%5.3g",txtval);
571 axis.LabelsLimits(form.Data(),first,last);
572 TString s = form;
573 if (first != 0) s.Remove(0, first);
574 textangular.SetTextAlign(FindAlign(theta));
575 textangular.PaintLatex(costhetas,
577 }
578 else if (fPolarLabels){
579 // print the specified polar labels
580 textangular.SetTextAlign(FindAlign(theta));
582 }
583
584 } else {
586 // Polar numbers are shown horizontally.
587 form.Form("%5.3g",txtval);
588 axis.LabelsLimits(form.Data(),first,last);
589 TString s = form;
590 if (first != 0) s.Remove(0, first);
591 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
592 textangular.SetTextAlign(FindAlign(theta));
593 textangular.PaintLatex(costhetas,
594 corr+sinthetas,0,GetPolarLabelSize(),s);
595 } else if (fPolarLabels){
596 // print the specified polar labels
597 textangular.SetTextAlign(FindAlign(theta));
599 }
600 }
601
603 //Check if SetTickPolar is activated, and draw tick marks
604 Bool_t issettickpolar = gPad->GetTicky();
605 if (issettickpolar) {
606 if (theta != 0 && theta !=TMath::Pi()) {
609 }
610 if (theta == 0 || theta ==TMath::Pi()) {
611 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
612 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
613 }
614 }
617 gPad->PaintLine(0.,0.,costheta,sintheta);
618 // Add minor lines w/o text.
620 TAttLine::SetLineStyle(2); //Minor lines always in this style.
621 TAttLine::Modify(); //Changes line attributes apart from style.
622 Double_t a=0;
623 Double_t b,c,d;
624 b = TMath::Log(10)*test;
625 d= 2*TMath::Pi()/(double)test;
626 for (j=1; j<9; j++) {
628 c=a/b*6.28+d*(i-1);
629 gPad->PaintLine(0.,0.,TMath::Cos(c),TMath::Sin(c));
630 }
633 }
634 }
635}
636
637////////////////////////////////////////////////////////////////////////////////
638/// Paint radial divisions.
639/// Check for editable pad or create default.
640
642{
643 if (!gPad) return ;
644
645 static char chopt[8] = "";
646 Int_t i,j;
647 Int_t ndiv = TMath::Abs(fNdivRad);
648 Int_t ndivMajor = ndiv%100;
649 Int_t ndivMinor = ndiv/100;
650 Int_t ndivmajor = 0;
651 Double_t frwrmin = 0., frwrmax = 0., binWidth = 0;
652
654 frwrmax, ndivmajor,binWidth,"");
655
656 if (!gPad->GetLogx()) {
657 gPad->RangeAxis(-1,-1,1,1);
658 gPad->Range(-1.25,-1.25,1.25,1.25);
664 Int_t ndivminor = 0;
665
666 chopt[0] = 0;
667 strncat(chopt, "SDH", 4);
668 if (fNdivRad < 0) strncat(chopt, "N",2);
669 if(drawaxis){
670 // Paint axis.
671 TGaxis axis;
677 umin, umax, ndiv, chopt, 0., kFALSE);
678 }
679
680 // Paint Circles.
681 // First paint main circle.
682 PaintCircle(0.,0.,1,0.,360,0);
683 // Optimised case.
684 if (fNdivRad>0 ) {
685 Double_t frwrmini = 0., frwrmaxi = 0., binWidth2 =0;
688 Double_t dist2 = dist/(ndivminor);
689 // Paint major circles.
690 for (i=1; i<=ndivmajor+2; i++) {
693 PaintCircle(0.,0.,rmajmin,0.,360,0);
694
695 //Paint minor circles.
698 for (j=1; j<ndivminor+1; j++) {
699 if (rmajmin+j*dist2<=1) PaintCircle(0.,0.,rmajmin+j*dist2,0.,360,0);
700 }
701 rmajmin = (frwrmin-fRwrmin)/(fRwrmax-fRwrmin)+(i-1)*dist;
702 }
703 // Non-optimized case.
704 } else {
705
706 // Paint major circles.
707 for (i=1; i<=ndivMajor; i++) {
710 Double_t rmaj = i*1./ndivMajor;
711 PaintCircle(0.,0.,rmaj,0.,360,0);
712
713 // Paint minor circles.
714 for (j=1; j<ndivMinor; j++) {
717 PaintCircle(0.,0.,rmaj- j*1./(ndivMajor*ndivMinor),0.,360,0);
718 }
719 }
720 }
721 } else {
722 // Draw Log scale on radial axis if option activated.
724 Int_t test= 0;
725 while (big >= 10) {
726 big = big/10;
727 test++;
728 }
729 for (i=1; i<=test; i++) {
733 ecart = ((double) i)/ ((double) test);
734 PaintCircle(0.,0.,ecart,0,360,0);
737 Double_t a=0;
738 Double_t b,c,d;
739 b = TMath::Log(10)*test;
740 d = 1/(double)test;
741 for (j=1; j<9; j++) {
742 a = TMath::Log(j+1)-TMath::Log(j)+a;
743 c = a/b+d*(i-1);
744 PaintCircle(0,0.,c,0.,360,0);
745 }
746 }
747 }
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Reduce fractions.
754
756{
757 Int_t a = 0;
758 Int_t b = 0;
759 Int_t i = 0;
760 Int_t j = 0;
761 a = den;
762 b = num;
763 if (b > a) {
764 j = b;
765 } else {
766 j = a;
767 }
768 for (i=j; i > 1; i--) {
769 if ((a % i == 0) && (b % i == 0)) {
770 a = a/i;
771 b = b/i;
772 }
773 }
774 rden = a;
775 rnum = b;
776}
777
778////////////////////////////////////////////////////////////////////////////////
779/// Set axis angle.
780
785
786////////////////////////////////////////////////////////////////////////////////
787/// Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99
788/// - i sets the major Polar divisions.
789/// - j sets the minor Polar divisions.
790
792{
793 if (ndiv > 0)
794 fNdivPol = ndiv;
795 if (gPad) gPad->Modified();
796}
797
798////////////////////////////////////////////////////////////////////////////////
799/// Set the number of radial divisions: enter a number ij with 0<i<99 and 0<j<99
800/// - i sets the major radial divisions.
801/// - j sets the minor radial divisions.
802
804{
805 fNdivRad = ndiv;
806 if (gPad) gPad->Modified();
807}
808
809////////////////////////////////////////////////////////////////////////////////
810/// Set some specified polar labels, used in the case of a spider plot.
811
813{
814 if(!fPolarLabels)
816 fPolarLabels[div] = label;
817 if (gPad) gPad->Modified();
818}
819
820////////////////////////////////////////////////////////////////////////////////
821/// Set Polar labels color.
822
827
828////////////////////////////////////////////////////////////////////////////////
829
831{
832 // Set Polar label font.
833
835}
836
837////////////////////////////////////////////////////////////////////////////////
838/// Set angular labels size.
839
844
845////////////////////////////////////////////////////////////////////////////////
846/// Set the labels offset.
847
853
854////////////////////////////////////////////////////////////////////////////////
855/// Set radial labels color.
856
861
862////////////////////////////////////////////////////////////////////////////////
863/// Set radial label font.
864
869
870////////////////////////////////////////////////////////////////////////////////
871/// Set radial labels size.
872
877
878////////////////////////////////////////////////////////////////////////////////
879/// Set the labels offset.
880
886
887////////////////////////////////////////////////////////////////////////////////
888/// Allows to change range Polar.
889/// \param[in] tmin the start number.
890/// \param[in] tmax the end number.
891
893{
894 fDegree = kFALSE;
895 fGrad = kFALSE;
896 fRadian = kFALSE;
897
898 if (tmin < tmax) {
899 fRwtmin = tmin;
900 fRwtmax = tmax;
901 }
902 if (gPad) gPad->Modified();
903}
904
905////////////////////////////////////////////////////////////////////////////////
906/// Set the radial range.
907/// \param[in] rmin radius at center of the circle.
908/// \param[in] rmax radius at the intersection of the right X axis part and the circle.
909
911{
912 if (rmin < rmax) {
913 fRwrmin = rmin;
914 fRwrmax = rmax;
915 }
916 if (gPad) gPad->Modified();
917}
918
919////////////////////////////////////////////////////////////////////////////////
920/// Set polar ticks size.
921
926
927////////////////////////////////////////////////////////////////////////////////
928/// The Polar circle is labelled using degree.
929
931{
932 fDegree = kTRUE;
933 fGrad = kFALSE;
934 fRadian = kFALSE;
935 ChangeRangePolar(0,360);
936}
937
938////////////////////////////////////////////////////////////////////////////////
939/// The Polar circle is labelled using gradian.
940
942{
943 fGrad = kTRUE;
944 fRadian = kFALSE;
945 fDegree = kFALSE;
946 ChangeRangePolar(0,200);
947}
948
949////////////////////////////////////////////////////////////////////////////////
950/// The Polar circle is labelled using radian.
951
959
960////////////////////////////////////////////////////////////////////////////////
961/// Set range from 0 to 2*pi
962
967
968
969////////////////////////////////////////////////////////////////////////////////
970/// Save TGraphPolargram as primitive
971
973{
974 if (!option || strcmp(option, "nodraw"))
975 return;
976
977 TString opt = "";
978 if (fDegree)
979 opt = "d";
980 else if (fGrad)
981 opt = "g";
982
984 out, Class(), "polargram",
985 TString::Format("\"%s\", %g, %g, %g, %g, \"%s\"", GetName(), fRwrmin, fRwrmax, fRwtmin, fRwtmax, opt.Data()));
986
987 SaveLineAttributes(out, "polargram", -1, -1, -1);
988 SaveTextAttributes(out, "polargram", -1, -1, -1, -1, -1);
989
990 if (fAxisAngle)
991 out << " polargram->SetAxisAngle(" << std::to_string((int)(fAxisAngle / TMath::Pi() * 180)).c_str() << ");\n";
992
993 if (fNdivPol != 508)
994 out << " polargram->SetNdivPolar(" << std::to_string(fNdivPol).c_str() << ");\n";
995 out << " polargram->SetPolarLabelColor(" << TColor::SavePrimitiveColor(fPolarLabelColor) << ");\n";
996 out << " polargram->SetPolarLabelFont(" << std::to_string(fPolarLabelFont).c_str() << ");\n";
997 out << " polargram->SetPolarLabelSize(" << std::to_string(fPolarTextSize).c_str() << ");\n";
998 if (fPolarOffset != 0.04)
999 out << " polargram->SetPolarOffset(" << std::to_string(fPolarOffset).c_str() << ");\n";
1000 out << " polargram->SetTickpolarSize(" << std::to_string(fTickpolarSize).c_str() << ");\n";
1001 if (fPolarLabels)
1002 for(Int_t n = 0; n < fNdivPol; n++)
1003 if (!fPolarLabels[n].IsNull())
1004 out << " polargram->SetPolarLabel(\"" << fPolarLabels[n] << "\");\n";
1005
1006 if (fNdivRad != 508)
1007 out << " polargram->SetNdivRadial(" << std::to_string(fNdivRad).c_str() << ");\n";
1008 out << " polargram->SetRadialLabelColor(" << TColor::SavePrimitiveColor(fRadialLabelColor) << ");\n";
1009 out << " polargram->SetRadialLabelFont(" << std::to_string(fRadialLabelFont).c_str() << ");\n";
1010 out << " polargram->SetRadialLabelSize(" << std::to_string(fRadialTextSize).c_str() << ");\n";
1011 if (fRadialOffset != 0.04)
1012 out << " polargram->SetRadialOffset(" << std::to_string(fRadialOffset).c_str() << ");\n";
1013}
1014
@ kMouseMotion
Definition Buttons.h:23
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kButton1Down
Definition Buttons.h:17
@ kMove
Definition GuiTypes.h:374
@ kHand
Definition GuiTypes.h:374
const Int_t kMaxPixel
Max value for an int.
Definition GuiTypes.h:369
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Font_t
Font number (short)
Definition RtypesCore.h:95
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:110
#define gPad
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:246
Style_t fLineStyle
Line style.
Definition TAttLine.h:24
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
Compute distance from point px,py to a line.
Definition TAttLine.cxx:210
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:274
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:372
static TString SavePrimitiveColor(Int_t ci)
Convert color in C++ statement which can be used in SetColor directives Produced statement either inc...
Definition TColor.cxx:2556
The axis painter class.
Definition TGaxis.h:26
virtual void PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, Double_t &wmin, Double_t &wmax, Int_t &ndiv, Option_t *chopt="", Double_t gridlength=0, Bool_t drawGridOnly=kFALSE)
Control function to draw an axis.
Definition TGaxis.cxx:1007
void SetLabelFont(Int_t labelfont)
Definition TGaxis.h:107
void SetLabelOffset(Float_t labeloffset)
Definition TGaxis.h:108
void SetLabelColor(Int_t labelcolor)
Definition TGaxis.h:106
void SetLabelSize(Float_t labelsize)
Definition TGaxis.h:109
void LabelsLimits(const char *label, Int_t &first, Int_t &last)
Internal method to find first and last character of a label.
Definition TGaxis.cxx:2534
Double_t fRwrmin
Minimal radial value (real world)
void ReduceFraction(Int_t Num, Int_t Denom, Int_t &rnum, Int_t &rden)
Reduce fractions.
static TClass * Class()
Double_t GetPolarLabelSize()
Color_t fRadialLabelColor
Set color of the radial labels.
void SetPolarLabelColor(Color_t tcolorangular=1)
Set Polar labels color.
void PaintPolarDivisions(Bool_t noLabels)
Draw Polar divisions.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Everything within the circle belongs to the TGraphPolargram.
void SetRangePolar(Double_t tmin, Double_t tmax)
Allows to change range Polar.
Double_t fPolarTextSize
Set Polar text size.
Double_t fRwtmin
Minimal angular value (real world)
Double_t GetRadialOffset()
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Indicate that there is something to click here.
void Init()
Initialize some of the fields of TGraphPolargram.
TGraphPolargram(const char *name="")
Short constructor used in the case of a spider plot.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save TGraphPolargram as primitive.
Double_t fRadialTextSize
Double_t GetTickpolarSize()
void SetPolarOffset(Double_t PolarOffset=0.04)
Set the labels offset.
void SetTwoPi()
Set range from 0 to 2*pi.
Double_t FindTextAngle(Double_t theta)
Determine the orientation of the polar labels according to their angle.
void SetRadialLabelColor(Color_t tcolorradial=1)
Set radial labels color.
void PaintCircle(Double_t x, Double_t y, Double_t r, Double_t phimin, Double_t phimax, Double_t theta)
This is simplified from TEllipse::PaintEllipse.
void SetRangeRadial(Double_t rmin, Double_t rmax)
Set the radial range.
void SetTickpolarSize(Double_t tickpolarsize=0.02)
Set polar ticks size.
void SetAxisAngle(Double_t angle=0)
Set axis angle.
void SetToDegree()
The Polar circle is labelled using degree.
void SetNdivPolar(Int_t Ndiv=508)
Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99.
Int_t fNdivRad
Number of radial divisions.
Font_t GetPolarLabelFont()
void Draw(Option_t *options="") override
Draw Polargram.
Double_t fTickpolarSize
Set size of Tickmarks.
void SetRadialLabelSize(Double_t radialsize=0.035)
Set radial labels size.
Font_t fPolarLabelFont
Set font of angular labels.
TString * fPolarLabels
! [fNdivPol] Specified polar labels
void PaintRadialDivisions(Bool_t drawaxis)
Paint radial divisions.
void SetToGrad()
The Polar circle is labelled using gradian.
Double_t GetAngle()
~TGraphPolargram() override
TGraphPolargram destructor.
void ChangeRangePolar(Double_t tmin, Double_t tmax)
Set the Polar range.
void SetPolarLabelSize(Double_t angularsize=0.04)
Set angular labels size.
void SetRadialLabelFont(Font_t tfontradial=62)
Set radial label font.
Double_t fAxisAngle
Set angle of the radial axis.
void SetToRadian()
The Polar circle is labelled using radian.
Double_t fRwtmax
Minimal angular value (real world)
Double_t fRwrmax
Maximal radial value (real world)
void SetPolarLabel(Int_t div, const TString &label)
Set some specified polar labels, used in the case of a spider plot.
Font_t fRadialLabelFont
Set font of radial labels.
Int_t fNdivPol
Number of polar divisions.
Font_t GetRadialLabelFont()
Int_t fCutRadial
if fCutRadial = 0, circles are cut by radial axis if fCutRadial = 1, circles are not cut
Color_t fPolarLabelColor
Set color of the angular labels.
Double_t fPolarOffset
Offset for Polar labels.
void Paint(Option_t *options="") override
Paint TGraphPolargram.
void SetPolarLabelFont(Font_t tfontangular=62)
void SetRadialOffset(Double_t RadialOffset=0.025)
Set the labels offset.
Color_t GetRadialColorLabel()
Int_t FindAlign(Double_t angle)
Find the alignement rule to apply for TText::SetTextAlign(Short_t).
void SetNdivRadial(Int_t Ndiv=508)
Set the number of radial divisions: enter a number ij with 0<i<99 and 0<j<99.
Double_t GetRadialLabelSize()
Color_t GetPolarColorLabel()
Double_t fRadialOffset
Offset for radial labels.
static void Optimize(Double_t A1, Double_t A2, Int_t nold, Double_t &BinLow, Double_t &BinHigh, Int_t &nbins, Double_t &BWID, Option_t *option="")
Static function to compute reasonable axis limits.
To draw Mathematical Formula.
Definition TLatex.h:20
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:881
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:771
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
TString & Remove(Ssiz_t pos)
Definition TString.h:694
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Definition TMath.h:643
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Definition TMath.h:635
constexpr Double_t PiOver2()
Definition TMath.h:54
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:767
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:732
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:611
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122