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 "TLatex.h"
49#include "TEllipse.h"
50#include "TMath.h"
51
53
54////////////////////////////////////////////////////////////////////////////////
55/// TGraphPolargram Constructor.
56
58 Double_t tmin, Double_t tmax, const char *opt):
59 TNamed(name, "Polargram")
60{
61 Init();
62 fNdivRad = 508;
63 fNdivPol = 508;
64 fPolarLabels = nullptr;
65 fRwrmax = rmax;
66 fRwrmin = rmin;
67 fRwtmin = tmin;
68 fRwtmax = tmax;
69
70 TString s = opt;
71 s.ToUpper();
72 if (s.Contains("R")) {
73 fRadian = kTRUE;
74 fRwtmin = 0;
75 fRwtmax = 2*TMath::Pi();
76 } else if (s.Contains("D")) {
77 fDegree = kTRUE;
78 fRwtmin = 0;
79 fRwtmax = 360;
80 } else if (s.Contains("G")) {
81 fGrad = kTRUE;
82 fRwtmin = 0;
83 fRwtmax = 200;
84 }
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Short constructor used in the case of a spider plot.
89
91 TNamed(name,"Polargram")
92{
93 Init();
94 fNdivRad = 0;
95 fNdivPol = 0;
96 fPolarLabels = nullptr;
97 fRwrmax = 1;
98 fRwrmin = 0;
99 fRwtmax = 0;
100 fRwtmin = 0;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// TGraphPolargram destructor.
105
107{
108 if (fPolarLabels) delete [] fPolarLabels;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Set the Polar range.
113/// \param[in] tmin the start number.
114/// \param[in] tmax the end number.
115
117{
118 if (tmin < tmax) {
119 fRwtmin = tmin;
120 fRwtmax = tmax;
121 }
122 if (gPad) gPad->Modified();
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Everything within the circle belongs to the TGraphPolargram.
127
129{
130 if (!gPad) return 9999;
131 Int_t i;
132 Double_t x = gPad->AbsPixeltoX(px);
133 Double_t y = gPad->AbsPixeltoY(py);
134
135 // Check if close to a (major) radial line.
136 Double_t rad = TMath::Sqrt(x*x+y*y);
137 Int_t div = (Int_t)rad*(fNdivRad%100);
138 Double_t dr = TMath::Min(TMath::Abs(rad-div*1./(fNdivRad%100)),
139 TMath::Abs(rad-(div+1)*1./(fNdivRad%100)));
140 Int_t drad = gPad->XtoPixel(dr)-gPad->XtoPixel(0);
141
142 // Check if close to a (major) Polar line.
143 // This is not a proper calculation, but rather fast.
144 Int_t dt = kMaxPixel;
145 for (i=0; i<(fNdivPol%100); i++) {
146 Double_t theta = i*2*TMath::Pi()/(fNdivPol%100);
147
148 // Attention: px,py in pixel units, line given in user coordinates.
149 Int_t dthis = DistancetoLine(px,py,0.,0.,TMath::Cos(theta),
150 TMath::Sin(theta));
151
152 // Fails if we are outside box described by the line.
153 // (i.e for all hor/vert lines)
154 if (dthis==9999) {
155
156 // Outside -> Get distance to endpoint of line.
157 if (rad>1) {
158 dthis = (Int_t)TMath::Sqrt(
159 TMath::Power(px-gPad->XtoPixel(TMath::Cos(theta)),2)+
160 TMath::Power(py-gPad->YtoPixel(TMath::Sin(theta)),2));
161 } else {
162
163 // Check for horizontal line.
164 if (((TMath::Abs(theta-TMath::Pi())<0.1) &&
165 ((px-gPad->XtoPixel(0))<0)) ||
166 ((TMath::Abs(theta)<0.1) &&
167 ((px-gPad->XtoPixel(0))>0))) {
168 dthis = TMath::Abs(py-gPad->YtoPixel(0.));
169 }
170
171 //Check for vertical line.
172 if (((TMath::Abs(theta-TMath::PiOver2())<0.1) &&
173 ((py-gPad->YtoPixel(0))>0)) ||
174 ((TMath::Abs(theta-3*TMath::PiOver2())<0.1) &&
175 (py-gPad->YtoPixel(0))<0)) {
176 dthis = TMath::Abs(px-gPad->XtoPixel(0.));
177 }
178 if (dthis==9999) {
179
180 // Inside, but out of box for nonorthogonal line ->
181 // get distance to start point.
182 dthis = (Int_t)TMath::Sqrt(
183 TMath::Power(px-gPad->XtoPixel(0.),2)+
184 TMath::Power(py-gPad->YtoPixel(0.),2));
185 }
186 }
187 }
188
189 // Take distance to closes line.
190 dt = TMath::Min(dthis,dt);
191 }
192 return TMath::Min(drad, dt);
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Draw Polargram.
197
199{
200 Paint(options);
201 AppendPad(options);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Indicate that there is something to click here.
206
208{
209 if (!gPad) return;
210
211 Int_t kMaxDiff = 20;
212 static Int_t d1, d2, d3, px1, py1, px3, py3;
213 static Bool_t p1, p2, p3, p4, p5, p6, p7, p8;
214 Double_t px2, py2;
215 p2 = p3 = p4 = p5 = p6 = p7 = p8 = kFALSE;
216 if (!gPad->IsEditable()) return;
217 switch (event) {
218 case kMouseMotion:
219 px1 = gPad->XtoAbsPixel(TMath::Cos(GetAngle()));
220 py1 = gPad->YtoAbsPixel(TMath::Sin(GetAngle()));
221 d1 = TMath::Abs(px1 - px) + TMath::Abs(py1-py); //simply take sum of pixels differences
222 p1 = kFALSE;
223 px2 = gPad->XtoAbsPixel(-1);
224 py2 = gPad->YtoAbsPixel(1);
225 d2 = (Int_t)(TMath::Abs(px2 - px) + TMath::Abs(py2 - py)) ;
226 px3 = gPad->XtoAbsPixel(-1);
227 py3 = gPad->YtoAbsPixel(-1);
228 d3 = TMath::Abs(px3 - px) + TMath::Abs(py3 - py) ; //simply take sum of pixels differences
229 // check if point is close to the radial axis
230 if (d1 < kMaxDiff) {
231 gPad->SetCursor(kMove);
232 p1 = kTRUE;
233 }
234 // check if point is close to the left high axis
235 if ( d2 < kMaxDiff) {
236 gPad->SetCursor(kHand);
237 p7 = kTRUE;
238 }
239 // check if point is close to the left down axis
240 if ( d3 < kMaxDiff) {
241 gPad->SetCursor(kHand);
242 p8 = kTRUE;
243 }
244 // check if point is close to a main circle
245 if (!p1 && !p7 ) {
246 p6 = kTRUE;
247 gPad->SetCursor(kHand);
248 }
249 break;
250
251 case kButton1Down:
252 // Record initial coordinates
253 //px4 = px;
254 //py4 = py;
255
256 case kButton1Motion:
257 if (p1) {
258 px2 = gPad->AbsPixeltoX(px);
259 py2 = gPad->AbsPixeltoY(py);
260 if ( px2 < 0 && py2 < 0) {p2 = kTRUE;};
261 if ( px2 < 0 && py2 > 0 ) {p3 = kTRUE;};
262 if ( px2 > 0 && py2 > 0 ) {p4 = kTRUE;};
263 if ( px2 > 0 && py2 < 0 ) {p5 = kTRUE;};
264 px2 = TMath::ACos(TMath::Abs(px2));
265 py2 = TMath::ASin(TMath::Abs(py2));
266 if (p2) {
267 fAxisAngle = TMath::Pi()+(px2+py2)/2;
268 p2 = kFALSE;
269 };
270 if (p3) {
271 fAxisAngle = TMath::Pi()-(px2+py2)/2;
272 p3 = kFALSE;
273 };
274 if (p4) {
275 fAxisAngle = (px2+py2)/2;
276 p4 = kFALSE;
277 };
278 if (p5) {
279 fAxisAngle = -(px2+py2)/2;
280 p5 = kFALSE;
281 };
282 }
283 break;
284
285 case kButton1Up:
286 Paint();
287 }
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Find the alignement rule to apply for TText::SetTextAlign(Short_t).
292
294{
295 Double_t pi = TMath::Pi();
296
297 while(angle < 0 || angle > 2*pi){
298 if(angle < 0) angle+=2*pi;
299 if(angle > 2*pi) angle-=2*pi;
300 }
302 if(angle > 0 && angle < pi/2) return 11;
303 else if(angle > pi/2 && angle < pi) return 31;
304 else if(angle > pi && angle < 3*pi/2) return 33;
305 else if(angle > 3*pi/2 && angle < 2*pi) return 13;
306 else if(angle == 0 || angle == 2*pi) return 12;
307 else if(angle == pi/2) return 21;
308 else if(angle == pi) return 32;
309 else if(angle == 3*pi/2) return 23;
310 else return 0;
311 }
312 else{
313 if(angle >= 0 && angle <= pi/2) return 12;
314 else if((angle > pi/2 && angle <= pi) || (angle > pi && angle <= 3*pi/2)) return 32;
315 else if(angle > 3*pi/2 && angle <= 2*pi) return 12;
316 else return 0;
317 }
318}
319
320////////////////////////////////////////////////////////////////////////////////
321/// Determine the orientation of the polar labels according to their angle.
322
324{
325 Double_t pi = TMath::Pi();
326 Double_t convraddeg = 180.0/pi;
327
328 while(angle < 0 || angle > 2*pi){
329 if(angle < 0) angle+=2*pi;
330 if(angle > 2*pi) angle-=2*pi;
331 }
332
333 if(angle >= 0 && angle <= pi/2) return angle*convraddeg;
334 else if(angle > pi/2 && angle <= pi) return (angle + pi)*convraddeg;
335 else if(angle > pi && angle <= 3*pi/2) return (angle - pi)*convraddeg;
336 else if(angle > 3*pi/2 && angle <= 2*pi) return angle*convraddeg;
337 else return 0;
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Initialize some of the fields of TGraphPolargram.
342
344{
345 fAxisAngle = 0;
346 fCutRadial = 0;
347 fDegree = kFALSE;
348 fGrad = kFALSE;
349 fLineStyle = 3;
351 fPolarLabelFont = 62;
352 fPolarOffset = 0.04;
353 fPolarTextSize = 0.04;
354 fRadialOffset = 0.025;
355 fRadian = kTRUE;
357 fRadialLabelFont = 62;
358 fRadialTextSize = 0.035;
359 fTickpolarSize = 0.02;
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Paint TGraphPolargram.
364
366{
367 TString opt = chopt;
368 opt.ToUpper();
369
370 Bool_t optionpoldiv = opt.Contains('P'),
371 optionraddiv = opt.Contains('R'),
372 optionLabels = !opt.Contains('N');
373
374 if (!optionpoldiv && !optionraddiv)
375 optionpoldiv = optionraddiv = kTRUE;
376
378
379 PaintRadialDivisions(optionraddiv);
380 if (optionpoldiv)
381 PaintPolarDivisions(optionLabels);
382}
383
384////////////////////////////////////////////////////////////////////////////////
385/// This is simplified from TEllipse::PaintEllipse.
386/// Draw this ellipse with new coordinates.
387
389 Double_t phimin, Double_t phimax, Double_t theta)
390{
391 if (!gPad) return;
392
393 Int_t i;
394 const Int_t np = 200; // Number of point to draw circle
395 static Double_t x[np+3], y[np+3];
396
397 // Set number of points approximatively proportional to the ellipse
398 // circumference.
399
400 Double_t circ = TMath::Pi()*2*r*(phimax-phimin)/36;
401 Int_t n = (Int_t)(np*circ/((gPad->GetX2()-gPad->GetX1())+
402 (gPad->GetY2()-gPad->GetY1())));
403 if (n < 8) n = 8;
404 if (n > np) n = np;
405 Double_t angle,dx,dy;
406 Double_t dphi = (phimax-phimin)*TMath::Pi()/(180*n);
407 Double_t ct = TMath::Cos(TMath::Pi()*theta/180);
408 Double_t st = TMath::Sin(TMath::Pi()*theta/180);
409 for (i=0; i<=n; i++) {
410 angle = phimin*TMath::Pi()/180 + Double_t(i)*dphi;
411 dx = r*TMath::Cos(angle);
412 dy = r*TMath::Sin(angle);
413 x[i] = x1 + dx*ct - dy*st;
414 y[i] = y1 + dx*st + dy*ct;
415 }
416 gPad->PaintPolyLine(n+1,x,y);
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Draw Polar divisions.
421/// Check for editable pad or create default.
422
424{
425 if (!gPad) return ;
426 Int_t i, j, rnum, rden, first, last;
427
428 gPad->RangeAxis(-1,-1,1,1);
429 gPad->Range(-1.25,-1.25,1.25,1.25);
430 Int_t ndivMajor = fNdivPol%100;
431 Int_t ndivMinor = fNdivPol/100;
432
433 if (!gPad->GetLogy()) {
434 for (i=0; i<ndivMajor; i++) {
435 Double_t txtval = fRwtmin + i*(fRwtmax-fRwtmin)/ndivMajor;
436 Double_t theta = i*2*TMath::Pi()/ndivMajor;
437 Double_t costheta = TMath::Cos(theta);
438 Double_t sintheta = TMath::Sin(theta);
439 Double_t tantheta = TMath::Tan(theta);
440 Double_t costhetas = (1+fPolarOffset)*costheta;
441 Double_t sinthetas = (1+fPolarOffset)*sintheta;
442 Double_t corr = 0.01;
443
444 TLatex textangular;
445 textangular.SetTextColor(GetPolarColorLabel());
446 textangular.SetTextFont(GetPolarLabelFont());
447
448 TString form = " ";
449 TGaxis axis;
451 // Polar numbers are aligned with their axis.
452 if(!fPolarLabels && optionLabels){;
453 if (fRadian) {
454 // Radian case.
455 ReduceFraction(2*i, ndivMajor, rnum, rden); // Reduces the fraction.
456 if (rnum == 0) form.Form("%d",rnum);
457 if (rnum == 1 && rden == 1) form = "#pi";
458 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
459 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
460 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
461 textangular.SetTextAlign(FindAlign(theta));
462 textangular.PaintLatex(costhetas,
463 sinthetas, FindTextAngle(theta),
464 GetPolarLabelSize(), form.Data());
465 } else {
466 // Any other cases: numbers are aligned with their axis.
467 form.Form("%5.3g",txtval);
468 axis.LabelsLimits(form.Data(),first,last);
469 TString s = form;
470 if (first != 0) s.Remove(0, first);
471 textangular.SetTextAlign(FindAlign(theta));
472 textangular.PaintLatex(costhetas,
473 sinthetas, FindTextAngle(theta),
474 GetPolarLabelSize(), s);
475 }
476 } else if (fPolarLabels){
477 // print the specified polar labels
478 textangular.SetTextAlign(FindAlign(theta));
479 textangular.PaintLatex(costhetas,sinthetas,FindTextAngle(theta),
481 }
482 } else {
483 // Polar numbers are shown horizontally.
484 if(!fPolarLabels && optionLabels){
485 if (fRadian) {
486 // Radian case
487 ReduceFraction(2*i, ndivMajor, rnum, rden);
488 if (rnum == 0) form.Form("%d",rnum);
489 if (rnum == 1 && rden == 1) form = "#pi";
490 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
491 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
492 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
493 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
494 textangular.SetTextAlign(FindAlign(theta));
495 textangular.PaintLatex(costhetas,corr+sinthetas,0,
496 GetPolarLabelSize(),form.Data());
497 } else {
498 // Any other cases where numbers are shown horizontally.
499 form.Form("%5.3g",txtval);
500 axis.LabelsLimits(form.Data(),first,last);
501 TString s = form;
502 if (first != 0) s.Remove(0, first);
503 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
504 textangular.SetTextAlign(FindAlign(theta));
505 textangular.PaintLatex(costhetas, //j'ai efface des offset la
506 corr+sinthetas,0,GetPolarLabelSize(),s);
507 }
508 } else if (fPolarLabels) {
509 // print the specified polar labels
510 textangular.SetTextAlign(FindAlign(theta));
511 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
512 }
513 }
515 //Check if SetTickPolar is activated, and draw tick marks
516 Bool_t issettickpolar = gPad->GetTicky();
517
518 if (issettickpolar) {
519 if (theta != 0 && theta !=TMath::Pi()) {
520 gPad->PaintLine((sintheta-GetTickpolarSize())/tantheta,sintheta-GetTickpolarSize(),
521 (sintheta+GetTickpolarSize())/tantheta,sintheta+GetTickpolarSize());
522 }
523 if (theta == 0 || theta ==TMath::Pi()) {
524 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
525 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
526 }
527 }
530 gPad->PaintLine(0.,0.,costheta,sintheta);
531 // Add minor lines w/o text.
532 Int_t oldLineStyle = GetLineStyle();
533 TAttLine::SetLineStyle(2); //Minor lines always in this style.
534 TAttLine::Modify(); //Changes line attributes apart from style.
535 for (j=1; j<ndivMinor; j++) {
536 Double_t thetamin = theta+j*2*TMath::Pi()/(ndivMajor*ndivMinor);
537 gPad->PaintLine(0.,0.,TMath::Cos(thetamin),TMath::Sin(thetamin));
538 }
539 TAttLine::SetLineStyle(oldLineStyle);
541 }
542 } else {
543 Int_t big = (Int_t)fRwtmax;
544 Int_t test= 1;
545 while (big >= 10) {
546 big = big/10;
547 test++;
548 }
549 for (i=1; i<=test; i++) {
550 Double_t txtval = pow((double)10,(double)(i-1));
551 Double_t theta = (i-1)*2*TMath::Pi()/(double)(test);
552 Double_t costheta = TMath::Cos(theta);
553 Double_t sintheta = TMath::Sin(theta);
554 Double_t tantheta = TMath::Tan(theta);
555 Double_t costhetas = (1+fPolarOffset)*costheta;
556 Double_t sinthetas = (1+fPolarOffset)*sintheta;
557 Double_t corr = 0.01;
558
559 TLatex textangular;
560 textangular.SetTextColor(GetPolarColorLabel());
561 textangular.SetTextFont(GetPolarLabelFont());
562
563 TString form = " ";
564 TGaxis axis;
565
567 if(!fPolarLabels && optionLabels){
568 // Polar numbers are aligned with their axis.
569 form.Form("%5.3g",txtval);
570 axis.LabelsLimits(form.Data(),first,last);
571 TString s = form;
572 if (first != 0) s.Remove(0, first);
573 textangular.SetTextAlign(FindAlign(theta));
574 textangular.PaintLatex(costhetas,
575 sinthetas, FindTextAngle(theta), GetPolarLabelSize(), s);
576 }
577 else if (fPolarLabels){
578 // print the specified polar labels
579 textangular.SetTextAlign(FindAlign(theta));
580 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
581 }
582
583 } else {
584 if(!fPolarLabels && optionLabels){
585 // Polar numbers are shown horizontally.
586 form.Form("%5.3g",txtval);
587 axis.LabelsLimits(form.Data(),first,last);
588 TString s = form;
589 if (first != 0) s.Remove(0, first);
590 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
591 textangular.SetTextAlign(FindAlign(theta));
592 textangular.PaintLatex(costhetas,
593 corr+sinthetas,0,GetPolarLabelSize(),s);
594 } else if (fPolarLabels){
595 // print the specified polar labels
596 textangular.SetTextAlign(FindAlign(theta));
597 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
598 }
599 }
600
602 //Check if SetTickPolar is activated, and draw tick marks
603 Bool_t issettickpolar = gPad->GetTicky();
604 if (issettickpolar) {
605 if (theta != 0 && theta !=TMath::Pi()) {
606 gPad->PaintLine((sintheta-GetTickpolarSize())/tantheta,sintheta-GetTickpolarSize(),
607 (sintheta+GetTickpolarSize())/tantheta,sintheta+GetTickpolarSize());
608 }
609 if (theta == 0 || theta ==TMath::Pi()) {
610 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
611 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
612 }
613 }
616 gPad->PaintLine(0.,0.,costheta,sintheta);
617 // Add minor lines w/o text.
618 Int_t oldLineStyle = GetLineStyle();
619 TAttLine::SetLineStyle(2); //Minor lines always in this style.
620 TAttLine::Modify(); //Changes line attributes apart from style.
621 Double_t a=0;
622 Double_t b,c,d;
623 b = TMath::Log(10)*test;
624 d= 2*TMath::Pi()/(double)test;
625 for (j=1; j<9; j++) {
626 a=TMath::Log(j+1)-TMath::Log(j)+a;
627 c=a/b*6.28+d*(i-1);
628 gPad->PaintLine(0.,0.,TMath::Cos(c),TMath::Sin(c));
629 }
630 TAttLine::SetLineStyle(oldLineStyle);
632 }
633 }
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Paint radial divisions.
638/// Check for editable pad or create default.
639
641{
642 if (!gPad) return ;
643
644 static char chopt[8] = "";
645 Int_t i,j;
646 Int_t ndiv = TMath::Abs(fNdivRad);
647 Int_t ndivMajor = ndiv%100;
648 Int_t ndivMinor = ndiv/100;
649 Int_t ndivmajor = 0;
650 Double_t frwrmin = 0., frwrmax = 0., binWidth = 0;
651
652 THLimitsFinder::Optimize(fRwrmin,fRwrmax,ndivMajor,frwrmin,
653 frwrmax, ndivmajor,binWidth,"");
654
655 if (!gPad->GetLogx()) {
656 gPad->RangeAxis(-1,-1,1,1);
657 gPad->Range(-1.25,-1.25,1.25,1.25);
658 Double_t umin = fRwrmin;
659 Double_t umax = fRwrmax;
660 Double_t rmajmin = (frwrmin-fRwrmin)/(fRwrmax-fRwrmin);
661 Double_t rmajmax = (frwrmax-fRwrmin)/(fRwrmax-fRwrmin);
662 Double_t dist = (rmajmax-rmajmin)/ndivmajor;
663 Int_t ndivminor = 0;
664
665 chopt[0] = 0;
666 strncat(chopt, "SDH", 4);
667 if (fNdivRad < 0) strncat(chopt, "N",2);
668 if(drawaxis){
669 // Paint axis.
670 TGaxis axis;
676 umin, umax, ndiv, chopt, 0., kFALSE);
677 }
678
679 // Paint Circles.
680 // First paint main circle.
681 PaintCircle(0.,0.,1,0.,360,0);
682 // Optimised case.
683 if (fNdivRad>0 ) {
684 Double_t frwrmini = 0., frwrmaxi = 0., binWidth2 =0;
685 THLimitsFinder::Optimize(frwrmin,frwrmin+binWidth,ndivMinor,frwrmini,
686 frwrmaxi, ndivminor,binWidth2,"");
687 Double_t dist2 = dist/(ndivminor);
688 // Paint major circles.
689 for (i=1; i<=ndivmajor+2; i++) {
692 PaintCircle(0.,0.,rmajmin,0.,360,0);
693
694 //Paint minor circles.
697 for (j=1; j<ndivminor+1; j++) {
698 if (rmajmin+j*dist2<=1) PaintCircle(0.,0.,rmajmin+j*dist2,0.,360,0);
699 }
700 rmajmin = (frwrmin-fRwrmin)/(fRwrmax-fRwrmin)+(i-1)*dist;
701 }
702 // Non-optimized case.
703 } else {
704
705 // Paint major circles.
706 for (i=1; i<=ndivMajor; i++) {
709 Double_t rmaj = i*1./ndivMajor;
710 PaintCircle(0.,0.,rmaj,0.,360,0);
711
712 // Paint minor circles.
713 for (j=1; j<ndivMinor; j++) {
716 PaintCircle(0.,0.,rmaj- j*1./(ndivMajor*ndivMinor),0.,360,0);
717 }
718 }
719 }
720 } else {
721 // Draw Log scale on radial axis if option activated.
722 Int_t big = (Int_t)fRwrmax;
723 Int_t test= 0;
724 while (big >= 10) {
725 big = big/10;
726 test++;
727 }
728 for (i=1; i<=test; i++) {
731 Double_t ecart;
732 ecart = ((double) i)/ ((double) test);
733 PaintCircle(0.,0.,ecart,0,360,0);
736 Double_t a=0;
737 Double_t b,c,d;
738 b = TMath::Log(10)*test;
739 d = 1/(double)test;
740 for (j=1; j<9; j++) {
741 a = TMath::Log(j+1)-TMath::Log(j)+a;
742 c = a/b+d*(i-1);
743 PaintCircle(0,0.,c,0.,360,0);
744 }
745 }
746 }
749}
750
751////////////////////////////////////////////////////////////////////////////////
752/// Reduce fractions.
753
755{
756 Int_t a = 0;
757 Int_t b = 0;
758 Int_t i = 0;
759 Int_t j = 0;
760 a = den;
761 b = num;
762 if (b > a) {
763 j = b;
764 } else {
765 j = a;
766 }
767 for (i=j; i > 1; i--) {
768 if ((a % i == 0) && (b % i == 0)) {
769 a = a/i;
770 b = b/i;
771 }
772 }
773 rden = a;
774 rnum = b;
775}
776
777////////////////////////////////////////////////////////////////////////////////
778/// Set axis angle.
779
781{
782 fAxisAngle = angle/180*TMath::Pi();
783}
784
785////////////////////////////////////////////////////////////////////////////////
786/// Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99
787/// - i sets the major Polar divisions.
788/// - j sets the minor Polar divisions.
789
791{
792 if (ndiv > 0)
793 fNdivPol = ndiv;
794 if (gPad) gPad->Modified();
795}
796
797////////////////////////////////////////////////////////////////////////////////
798/// Set the number of radial divisions: enter a number ij with 0<i<99 and 0<j<99
799/// - i sets the major radial divisions.
800/// - j sets the minor radial divisions.
801
803{
804 fNdivRad = ndiv;
805 if (gPad) gPad->Modified();
806}
807
808////////////////////////////////////////////////////////////////////////////////
809/// Set some specified polar labels, used in the case of a spider plot.
810
812{
813 if(!fPolarLabels)
815 fPolarLabels[div] = label;
816 if (gPad) gPad->Modified();
817}
818
819////////////////////////////////////////////////////////////////////////////////
820/// Set Polar labels color.
821
823{
824 fPolarLabelColor = tcolorangular;
825}
826
827////////////////////////////////////////////////////////////////////////////////
828
830{
831 // Set Polar label font.
832
833 fPolarLabelFont = tfontangular;
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Set angular labels size.
838
840{
841 fPolarTextSize = angularsize;
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Set the labels offset.
846
848{
849 fPolarOffset = angularOffset;
850 if (gPad) gPad->Modified();
851}
852
853////////////////////////////////////////////////////////////////////////////////
854/// Set radial labels color.
855
857{
858 fRadialLabelColor = tcolorradial;
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Set radial label font.
863
865{
866 fRadialLabelFont = tfontradial;
867}
868
869////////////////////////////////////////////////////////////////////////////////
870/// Set radial labels size.
871
873{
874 fRadialTextSize = radialsize;
875}
876
877////////////////////////////////////////////////////////////////////////////////
878/// Set the labels offset.
879
881{
882 fRadialOffset = radialOffset;
883 if (gPad) gPad->Modified();
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Allows to change range Polar.
888/// \param[in] tmin the start number.
889/// \param[in] tmax the end number.
890
892{
893 fDegree = kFALSE;
894 fGrad = kFALSE;
895 fRadian = kFALSE;
896
897 if (tmin < tmax) {
898 fRwtmin = tmin;
899 fRwtmax = tmax;
900 }
901 if (gPad) gPad->Modified();
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/// Set the radial range.
906/// \param[in] rmin radius at center of the circle.
907/// \param[in] rmax radius at the intersection of the right X axis part and the circle.
908
910{
911 if (rmin < rmax) {
912 fRwrmin = rmin;
913 fRwrmax = rmax;
914 }
915 if (gPad) gPad->Modified();
916}
917
918////////////////////////////////////////////////////////////////////////////////
919/// Set polar ticks size.
920
922{
923 fTickpolarSize = tickpolarsize;
924}
925
926////////////////////////////////////////////////////////////////////////////////
927/// The Polar circle is labelled using degree.
928
930{
931 fDegree = kTRUE;
932 fGrad = kFALSE;
933 fRadian = kFALSE;
934 ChangeRangePolar(0,360);
935}
936
937////////////////////////////////////////////////////////////////////////////////
938/// The Polar circle is labelled using gradian.
939
941{
942 fGrad = kTRUE;
943 fRadian = kFALSE;
944 fDegree = kFALSE;
945 ChangeRangePolar(0,200);
946}
947
948////////////////////////////////////////////////////////////////////////////////
949/// The Polar circle is labelled using radian.
950
952{
953 fRadian = kTRUE;
954 fGrad = kFALSE;
955 fDegree = kFALSE;
957}
958
959////////////////////////////////////////////////////////////////////////////////
960/// Set range from 0 to 2*pi
961
963{
965}
@ 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
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:85
short Font_t
Definition RtypesCore.h:81
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:247
Style_t fLineStyle
Line style.
Definition TAttLine.h:22
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:211
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:42
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
The axis painter class.
Definition TGaxis.h:24
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:1008
void SetLabelFont(Int_t labelfont)
Definition TGaxis.h:105
void SetLabelOffset(Float_t labeloffset)
Definition TGaxis.h:106
void SetLabelColor(Int_t labelcolor)
Definition TGaxis.h:104
void SetLabelSize(Float_t labelsize)
Definition TGaxis.h:107
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:2533
To draw polar axis.
Double_t fRwrmin
Minimal radial value (real world)
void ReduceFraction(Int_t Num, Int_t Denom, Int_t &rnum, Int_t &rden)
Reduce fractions.
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.
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:18
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2114
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:202
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
TString & Remove(Ssiz_t pos)
Definition TString.h:685
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:752
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:636
Double_t ASin(Double_t)
Returns the principal value of the arc sine of x, expressed in radians.
Definition TMath.h:628
constexpr Double_t PiOver2()
Definition TMath.h:51
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:760
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:666
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:725
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:604
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123