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);
139 Double_t dr = TMath::Min(TMath::Abs(rad-div*1./(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.
145 Int_t dt = kMaxPixel;
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) {
159 dthis = (Int_t)TMath::Sqrt(
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.
183 dthis = (Int_t)TMath::Sqrt(
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.
191 dt = TMath::Min(dthis,dt);
192 }
193 return TMath::Min(drad, dt);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Draw Polargram.
198
200{
201 Paint(options); // FIXME: why paint here ?
202 AppendPad(options);
203}
204
206 public:
207
209};
210
211////////////////////////////////////////////////////////////////////////////////
212/// Indicate that there is something to click here.
213
215{
216 if (!gPad || !gPad->IsEditable())
217 return;
218
219 auto &parent = *gPad;
220
221 Int_t kMaxDiff = 20;
222
223 switch (event) {
224 case kMouseMotion:
225 case kButton1Down: {
226 Int_t px1 = parent.XtoAbsPixel(TMath::Cos(GetAngle()));
227 Int_t py1 = parent.YtoAbsPixel(TMath::Sin(GetAngle()));
228
229 Int_t d1 = TMath::Abs(px1 - px) + TMath::Abs(py1-py); //simply take sum of pixels differences
230
231 if (d1 < kMaxDiff) {
232 parent.SetCursor(kMove);
233 if (event == kButton1Down)
234 parent.MakeInteractive<TGraphPolargramInteractive>(this);
235 }
236 break;
237 }
238
239 case kButton1Motion:
240 if (auto inter = parent.GetInteractive<TGraphPolargramInteractive>(this)) {
241 auto dx = parent.AbsPixeltoX(px);
242 auto dy = parent.AbsPixeltoY(py);
243 inter->angle = TMath::ATan2(dy, dx);
244
245 Double_t xx[2], yy[2];
246 xx[0] = yy[0] = 0;
247 xx[1] = TMath::Cos(inter->angle);
248 yy[1] = TMath::Sin(inter->angle);
249 TAttLine{kBlack, 1, 2}.ModifyOn(parent);
250 parent.PaintPolyLine(2, xx, yy, "ipolargram");
251 parent.UpdateAsync();
252 }
253 break;
254
255 case kButton1Up:
256 if (auto inter = parent.GetInteractive<TGraphPolargramInteractive>(this)) {
257 fAxisAngle = inter->angle;
258 parent.Modified();
259 parent.FreeInteractive(this); // remove interactive
260 }
261 break;
262 }
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Find the alignement rule to apply for TText::SetTextAlign(Short_t).
267
269{
270 Double_t pi = TMath::Pi();
271
272 while(angle < 0 || angle > 2*pi){
273 if(angle < 0) angle+=2*pi;
274 if(angle > 2*pi) angle-=2*pi;
275 }
277 if(angle > 0 && angle < pi/2) return 11;
278 else if(angle > pi/2 && angle < pi) return 31;
279 else if(angle > pi && angle < 3*pi/2) return 33;
280 else if(angle > 3*pi/2 && angle < 2*pi) return 13;
281 else if(angle == 0 || angle == 2*pi) return 12;
282 else if(angle == pi/2) return 21;
283 else if(angle == pi) return 32;
284 else if(angle == 3*pi/2) return 23;
285 else return 0;
286 }
287 else{
288 if(angle >= 0 && angle <= pi/2) return 12;
289 else if((angle > pi/2 && angle <= pi) || (angle > pi && angle <= 3*pi/2)) return 32;
290 else if(angle > 3*pi/2 && angle <= 2*pi) return 12;
291 else return 0;
292 }
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Determine the orientation of the polar labels according to their angle.
297
299{
300 Double_t pi = TMath::Pi();
301 Double_t convraddeg = 180.0/pi;
302
303 while(angle < 0 || angle > 2*pi){
304 if(angle < 0) angle+=2*pi;
305 if(angle > 2*pi) angle-=2*pi;
306 }
307
308 if(angle >= 0 && angle <= pi/2) return angle*convraddeg;
309 else if(angle > pi/2 && angle <= pi) return (angle + pi)*convraddeg;
310 else if(angle > pi && angle <= 3*pi/2) return (angle - pi)*convraddeg;
311 else if(angle > 3*pi/2 && angle <= 2*pi) return angle*convraddeg;
312 else return 0;
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Initialize some of the fields of TGraphPolargram.
317
319{
320 fAxisAngle = 0;
321 fCutRadial = 0;
322 fDegree = kFALSE;
323 fGrad = kFALSE;
324 fLineStyle = 3;
326 fPolarLabelFont = 62;
327 fPolarOffset = 0.04;
328 fPolarTextSize = 0.04;
329 fRadialOffset = 0.025;
330 fRadian = kTRUE;
332 fRadialLabelFont = 62;
333 fRadialTextSize = 0.035;
334 fTickpolarSize = 0.02;
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Paint TGraphPolargram.
339
341{
342 TString opt = chopt;
343 opt.ToUpper();
344
345 Bool_t optionpoldiv = opt.Contains('P'),
346 optionraddiv = opt.Contains('R'),
347 optionLabels = !opt.Contains('N');
348
349 if (!optionpoldiv && !optionraddiv)
350 optionpoldiv = optionraddiv = kTRUE;
351
353
354 PaintRadialDivisions(optionraddiv);
355 if (optionpoldiv)
356 PaintPolarDivisions(optionLabels);
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// This is simplified from TEllipse::PaintEllipse.
361/// Draw this ellipse with new coordinates.
362
364 Double_t phimin, Double_t phimax, Double_t theta)
365{
366 if (!gPad) return;
367
368 Int_t i;
369 const Int_t np = 200; // Number of point to draw circle
370 static Double_t x[np+3], y[np+3];
371
372 // Set number of points approximatively proportional to the ellipse
373 // circumference.
374
375 Double_t circ = TMath::Pi()*2*r*(phimax-phimin)/36;
376 Int_t n = (Int_t)(np*circ/((gPad->GetX2()-gPad->GetX1())+
377 (gPad->GetY2()-gPad->GetY1())));
378 if (n < 8) n = 8;
379 if (n > np) n = np;
380 Double_t angle,dx,dy;
381 Double_t dphi = (phimax-phimin)*TMath::Pi()/(180*n);
382 Double_t ct = TMath::Cos(TMath::Pi()*theta/180);
383 Double_t st = TMath::Sin(TMath::Pi()*theta/180);
384 for (i=0; i<=n; i++) {
385 angle = phimin*TMath::Pi()/180 + Double_t(i)*dphi;
386 dx = r*TMath::Cos(angle);
387 dy = r*TMath::Sin(angle);
388 x[i] = x1 + dx*ct - dy*st;
389 y[i] = y1 + dx*st + dy*ct;
390 }
391 gPad->PaintPolyLine(n+1,x,y);
392}
393
394////////////////////////////////////////////////////////////////////////////////
395/// Draw Polar divisions.
396/// Check for editable pad or create default.
397
399{
400 if (!gPad) return ;
401 Int_t i, j, rnum, rden, first, last;
402
403 gPad->RangeAxis(-1,-1,1,1);
404 gPad->Range(-1.25,-1.25,1.25,1.25);
405 Int_t ndivMajor = fNdivPol%100;
406 Int_t ndivMinor = fNdivPol/100;
407
408 if (!gPad->GetLogy()) {
409 for (i=0; i<ndivMajor; i++) {
410 Double_t txtval = fRwtmin + i*(fRwtmax-fRwtmin)/ndivMajor;
411 Double_t theta = i*2*TMath::Pi()/ndivMajor;
412 Double_t costheta = TMath::Cos(theta);
413 Double_t sintheta = TMath::Sin(theta);
414 Double_t tantheta = TMath::Tan(theta);
415 Double_t costhetas = (1+fPolarOffset)*costheta;
416 Double_t sinthetas = (1+fPolarOffset)*sintheta;
417 Double_t corr = 0.01;
418
419 TLatex textangular;
420 textangular.SetTextColor(GetPolarColorLabel());
421 textangular.SetTextFont(GetPolarLabelFont());
422
423 TString form = " ";
424 TGaxis axis;
426 // Polar numbers are aligned with their axis.
427 if(!fPolarLabels && optionLabels){;
428 if (fRadian) {
429 // Radian case.
430 ReduceFraction(2*i, ndivMajor, rnum, rden); // Reduces the fraction.
431 if (rnum == 0) form.Form("%d",rnum);
432 if (rnum == 1 && rden == 1) form = "#pi";
433 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
434 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
435 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
436 textangular.SetTextAlign(FindAlign(theta));
437 textangular.PaintLatex(costhetas,
438 sinthetas, FindTextAngle(theta),
439 GetPolarLabelSize(), form.Data());
440 } else {
441 // Any other cases: numbers are aligned with their axis.
442 form.Form("%5.3g",txtval);
443 axis.LabelsLimits(form.Data(),first,last);
444 TString s = form;
445 if (first != 0) s.Remove(0, first);
446 textangular.SetTextAlign(FindAlign(theta));
447 textangular.PaintLatex(costhetas,
448 sinthetas, FindTextAngle(theta),
449 GetPolarLabelSize(), s);
450 }
451 } else if (fPolarLabels){
452 // print the specified polar labels
453 textangular.SetTextAlign(FindAlign(theta));
454 textangular.PaintLatex(costhetas,sinthetas,FindTextAngle(theta),
456 }
457 } else {
458 // Polar numbers are shown horizontally.
459 if(!fPolarLabels && optionLabels){
460 if (fRadian) {
461 // Radian case
462 ReduceFraction(2*i, ndivMajor, rnum, rden);
463 if (rnum == 0) form.Form("%d",rnum);
464 if (rnum == 1 && rden == 1) form = "#pi";
465 if (rnum == 1 && rden != 1) form.Form("#frac{#pi}{%d}",rden);
466 if (rnum != 1 && rden == 1 && i !=0) form.Form("%d#pi",rnum);
467 if (rnum != 1 && rden != 1) form.Form("#frac{%d#pi}{%d}",rnum,rden);
468 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
469 textangular.SetTextAlign(FindAlign(theta));
470 textangular.PaintLatex(costhetas,corr+sinthetas,0,
471 GetPolarLabelSize(),form.Data());
472 } else {
473 // Any other cases where numbers are shown horizontally.
474 form.Form("%5.3g",txtval);
475 axis.LabelsLimits(form.Data(),first,last);
476 TString s = form;
477 if (first != 0) s.Remove(0, first);
478 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
479 textangular.SetTextAlign(FindAlign(theta));
480 textangular.PaintLatex(costhetas, //j'ai efface des offset la
481 corr+sinthetas,0,GetPolarLabelSize(),s);
482 }
483 } else if (fPolarLabels) {
484 // print the specified polar labels
485 textangular.SetTextAlign(FindAlign(theta));
486 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
487 }
488 }
490 //Check if SetTickPolar is activated, and draw tick marks
491 Bool_t issettickpolar = gPad->GetTicky();
492
493 if (issettickpolar) {
494 if (theta != 0 && theta !=TMath::Pi()) {
495 gPad->PaintLine((sintheta-GetTickpolarSize())/tantheta,sintheta-GetTickpolarSize(),
496 (sintheta+GetTickpolarSize())/tantheta,sintheta+GetTickpolarSize());
497 }
498 if (theta == 0 || theta ==TMath::Pi()) {
499 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
500 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
501 }
502 }
505 gPad->PaintLine(0.,0.,costheta,sintheta);
506 // Add minor lines w/o text.
507 Int_t oldLineStyle = GetLineStyle();
508 TAttLine::SetLineStyle(2); //Minor lines always in this style.
509 TAttLine::Modify(); //Changes line attributes apart from style.
510 for (j=1; j<ndivMinor; j++) {
511 Double_t thetamin = theta+j*2*TMath::Pi()/(ndivMajor*ndivMinor);
512 gPad->PaintLine(0.,0.,TMath::Cos(thetamin),TMath::Sin(thetamin));
513 }
514 TAttLine::SetLineStyle(oldLineStyle);
516 }
517 } else {
518 Int_t big = (Int_t)fRwtmax;
519 Int_t test= 1;
520 while (big >= 10) {
521 big = big/10;
522 test++;
523 }
524 for (i=1; i<=test; i++) {
525 Double_t txtval = pow((double)10,(double)(i-1));
526 Double_t theta = (i-1)*2*TMath::Pi()/(double)(test);
527 Double_t costheta = TMath::Cos(theta);
528 Double_t sintheta = TMath::Sin(theta);
529 Double_t tantheta = TMath::Tan(theta);
530 Double_t costhetas = (1+fPolarOffset)*costheta;
531 Double_t sinthetas = (1+fPolarOffset)*sintheta;
532 Double_t corr = 0.01;
533
534 TLatex textangular;
535 textangular.SetTextColor(GetPolarColorLabel());
536 textangular.SetTextFont(GetPolarLabelFont());
537
538 TString form = " ";
539 TGaxis axis;
540
542 if(!fPolarLabels && optionLabels){
543 // Polar numbers are aligned with their axis.
544 form.Form("%5.3g",txtval);
545 axis.LabelsLimits(form.Data(),first,last);
546 TString s = form;
547 if (first != 0) s.Remove(0, first);
548 textangular.SetTextAlign(FindAlign(theta));
549 textangular.PaintLatex(costhetas,
550 sinthetas, FindTextAngle(theta), GetPolarLabelSize(), s);
551 }
552 else if (fPolarLabels){
553 // print the specified polar labels
554 textangular.SetTextAlign(FindAlign(theta));
555 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
556 }
557
558 } else {
559 if(!fPolarLabels && optionLabels){
560 // Polar numbers are shown horizontally.
561 form.Form("%5.3g",txtval);
562 axis.LabelsLimits(form.Data(),first,last);
563 TString s = form;
564 if (first != 0) s.Remove(0, first);
565 if(theta >= 3*TMath::Pi()/12.0 && theta < 2*TMath::Pi()/3.0) corr=0.04;
566 textangular.SetTextAlign(FindAlign(theta));
567 textangular.PaintLatex(costhetas,
568 corr+sinthetas,0,GetPolarLabelSize(),s);
569 } else if (fPolarLabels){
570 // print the specified polar labels
571 textangular.SetTextAlign(FindAlign(theta));
572 textangular.PaintText(costhetas,sinthetas,fPolarLabels[i]);
573 }
574 }
575
577 //Check if SetTickPolar is activated, and draw tick marks
578 Bool_t issettickpolar = gPad->GetTicky();
579 if (issettickpolar) {
580 if (theta != 0 && theta !=TMath::Pi()) {
581 gPad->PaintLine((sintheta-GetTickpolarSize())/tantheta,sintheta-GetTickpolarSize(),
582 (sintheta+GetTickpolarSize())/tantheta,sintheta+GetTickpolarSize());
583 }
584 if (theta == 0 || theta ==TMath::Pi()) {
585 gPad->PaintLine(1-GetTickpolarSize(),0,1+GetTickpolarSize(),0);
586 gPad->PaintLine(-1+GetTickpolarSize(),0,-1-GetTickpolarSize(),0);
587 }
588 }
591 gPad->PaintLine(0.,0.,costheta,sintheta);
592 // Add minor lines w/o text.
593 Int_t oldLineStyle = GetLineStyle();
594 TAttLine::SetLineStyle(2); //Minor lines always in this style.
595 TAttLine::Modify(); //Changes line attributes apart from style.
596 Double_t a=0;
597 Double_t b,c,d;
598 b = TMath::Log(10)*test;
599 d= 2*TMath::Pi()/(double)test;
600 for (j=1; j<9; j++) {
601 a=TMath::Log(j+1)-TMath::Log(j)+a;
602 c=a/b*6.28+d*(i-1);
603 gPad->PaintLine(0.,0.,TMath::Cos(c),TMath::Sin(c));
604 }
605 TAttLine::SetLineStyle(oldLineStyle);
607 }
608 }
609}
610
611////////////////////////////////////////////////////////////////////////////////
612/// Paint radial divisions.
613/// Check for editable pad or create default.
614
616{
617 if (!gPad) return ;
618
619 static char chopt[8] = "";
620 Int_t i,j;
621 Int_t ndiv = TMath::Abs(fNdivRad);
622 Int_t ndivMajor = ndiv%100;
623 Int_t ndivMinor = ndiv/100;
624 Int_t ndivmajor = 0;
625 Double_t frwrmin = 0., frwrmax = 0., binWidth = 0;
626
627 THLimitsFinder::Optimize(fRwrmin,fRwrmax,ndivMajor,frwrmin,
628 frwrmax, ndivmajor,binWidth,"");
629
630 if (!gPad->GetLogx()) {
631 gPad->RangeAxis(-1,-1,1,1);
632 gPad->Range(-1.25,-1.25,1.25,1.25);
633 Double_t umin = fRwrmin;
634 Double_t umax = fRwrmax;
635 Double_t rmajmin = (frwrmin-fRwrmin)/(fRwrmax-fRwrmin);
636 Double_t rmajmax = (frwrmax-fRwrmin)/(fRwrmax-fRwrmin);
637 Double_t dist = (rmajmax-rmajmin)/ndivmajor;
638 Int_t ndivminor = 0;
639
640 chopt[0] = 0;
641 strncat(chopt, "SDH", 4);
642 if (fNdivRad < 0) strncat(chopt, "N",2);
643 if(drawaxis){
644 // Paint axis.
645 TGaxis axis;
651 umin, umax, ndiv, chopt, 0., kFALSE);
652 }
653
654 // Paint Circles.
655 // First paint main circle.
656 PaintCircle(0.,0.,1,0.,360,0);
657 // Optimised case.
658 if (fNdivRad>0 ) {
659 Double_t frwrmini = 0., frwrmaxi = 0., binWidth2 =0;
660 THLimitsFinder::Optimize(frwrmin,frwrmin+binWidth,ndivMinor,frwrmini,
661 frwrmaxi, ndivminor,binWidth2,"");
662 Double_t dist2 = dist/(ndivminor);
663 // Paint major circles.
664 for (i=1; i<=ndivmajor+2; i++) {
667 PaintCircle(0.,0.,rmajmin,0.,360,0);
668
669 //Paint minor circles.
672 for (j=1; j<ndivminor+1; j++) {
673 if (rmajmin+j*dist2<=1) PaintCircle(0.,0.,rmajmin+j*dist2,0.,360,0);
674 }
675 rmajmin = (frwrmin-fRwrmin)/(fRwrmax-fRwrmin)+(i-1)*dist;
676 }
677 // Non-optimized case.
678 } else {
679
680 // Paint major circles.
681 for (i=1; i<=ndivMajor; i++) {
684 Double_t rmaj = i*1./ndivMajor;
685 PaintCircle(0.,0.,rmaj,0.,360,0);
686
687 // Paint minor circles.
688 for (j=1; j<ndivMinor; j++) {
691 PaintCircle(0.,0.,rmaj- j*1./(ndivMajor*ndivMinor),0.,360,0);
692 }
693 }
694 }
695 } else {
696 // Draw Log scale on radial axis if option activated.
697 Int_t big = (Int_t)fRwrmax;
698 Int_t test= 0;
699 while (big >= 10) {
700 big = big/10;
701 test++;
702 }
703 for (i=1; i<=test; i++) {
706 Double_t ecart;
707 ecart = ((double) i)/ ((double) test);
708 PaintCircle(0.,0.,ecart,0,360,0);
711 Double_t a=0;
712 Double_t b,c,d;
713 b = TMath::Log(10)*test;
714 d = 1/(double)test;
715 for (j=1; j<9; j++) {
716 a = TMath::Log(j+1)-TMath::Log(j)+a;
717 c = a/b+d*(i-1);
718 PaintCircle(0,0.,c,0.,360,0);
719 }
720 }
721 }
724}
725
726////////////////////////////////////////////////////////////////////////////////
727/// Reduce fractions.
728
730{
731 Int_t a = 0;
732 Int_t b = 0;
733 Int_t i = 0;
734 Int_t j = 0;
735 a = den;
736 b = num;
737 if (b > a) {
738 j = b;
739 } else {
740 j = a;
741 }
742 for (i=j; i > 1; i--) {
743 if ((a % i == 0) && (b % i == 0)) {
744 a = a/i;
745 b = b/i;
746 }
747 }
748 rden = a;
749 rnum = b;
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Set axis angle.
754
759
760////////////////////////////////////////////////////////////////////////////////
761/// Set the number of Polar divisions: enter a number ij with 0<i<99 and 0<j<99
762/// - i sets the major Polar divisions.
763/// - j sets the minor Polar divisions.
764
766{
767 if (ndiv > 0)
768 fNdivPol = ndiv;
769 if (gPad) gPad->Modified();
770}
771
772////////////////////////////////////////////////////////////////////////////////
773/// Set the number of radial divisions: enter a number ij with 0<i<99 and 0<j<99
774/// - i sets the major radial divisions.
775/// - j sets the minor radial divisions.
776
778{
779 fNdivRad = ndiv;
780 if (gPad) gPad->Modified();
781}
782
783////////////////////////////////////////////////////////////////////////////////
784/// Set some specified polar labels, used in the case of a spider plot.
785
787{
788 if(!fPolarLabels)
790 fPolarLabels[div] = label;
791 if (gPad) gPad->Modified();
792}
793
794////////////////////////////////////////////////////////////////////////////////
795/// Set Polar labels color.
796
798{
799 fPolarLabelColor = tcolorangular;
800}
801
802////////////////////////////////////////////////////////////////////////////////
803
805{
806 // Set Polar label font.
807
808 fPolarLabelFont = tfontangular;
809}
810
811////////////////////////////////////////////////////////////////////////////////
812/// Set angular labels size.
813
815{
816 fPolarTextSize = angularsize;
817}
818
819////////////////////////////////////////////////////////////////////////////////
820/// Set the labels offset.
821
823{
824 fPolarOffset = angularOffset;
825 if (gPad) gPad->Modified();
826}
827
828////////////////////////////////////////////////////////////////////////////////
829/// Set radial labels color.
830
832{
833 fRadialLabelColor = tcolorradial;
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Set radial label font.
838
840{
841 fRadialLabelFont = tfontradial;
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Set radial labels size.
846
848{
849 fRadialTextSize = radialsize;
850}
851
852////////////////////////////////////////////////////////////////////////////////
853/// Set the labels offset.
854
856{
857 fRadialOffset = radialOffset;
858 if (gPad) gPad->Modified();
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Allows to change range Polar.
863/// \param[in] tmin the start number.
864/// \param[in] tmax the end number.
865
867{
868 fDegree = kFALSE;
869 fGrad = kFALSE;
870 fRadian = kFALSE;
871
872 if (tmin < tmax) {
873 fRwtmin = tmin;
874 fRwtmax = tmax;
875 }
876 if (gPad) gPad->Modified();
877}
878
879////////////////////////////////////////////////////////////////////////////////
880/// Set the radial range.
881/// \param[in] rmin radius at center of the circle.
882/// \param[in] rmax radius at the intersection of the right X axis part and the circle.
883
885{
886 if (rmin < rmax) {
887 fRwrmin = rmin;
888 fRwrmax = rmax;
889 }
890 if (gPad) gPad->Modified();
891}
892
893////////////////////////////////////////////////////////////////////////////////
894/// Set polar ticks size.
895
897{
898 fTickpolarSize = tickpolarsize;
899}
900
901////////////////////////////////////////////////////////////////////////////////
902/// The Polar circle is labelled using degree.
903
905{
906 fDegree = kTRUE;
907 fGrad = kFALSE;
908 fRadian = kFALSE;
909 ChangeRangePolar(0,360);
910}
911
912////////////////////////////////////////////////////////////////////////////////
913/// The Polar circle is labelled using gradian.
914
916{
917 fGrad = kTRUE;
918 fRadian = kFALSE;
919 fDegree = kFALSE;
920 ChangeRangePolar(0,200);
921}
922
923////////////////////////////////////////////////////////////////////////////////
924/// The Polar circle is labelled using radian.
925
933
934////////////////////////////////////////////////////////////////////////////////
935/// Set range from 0 to 2*pi
936
941
942
943////////////////////////////////////////////////////////////////////////////////
944/// Save TGraphPolargram as primitive
945
947{
948 if (!option || strcmp(option, "nodraw"))
949 return;
950
951 TString opt = "";
952 if (fDegree)
953 opt = "d";
954 else if (fGrad)
955 opt = "g";
956
958 out, Class(), "polargram",
959 TString::Format("\"%s\", %g, %g, %g, %g, \"%s\"", GetName(), fRwrmin, fRwrmax, fRwtmin, fRwtmax, opt.Data()));
960
961 SaveLineAttributes(out, "polargram", -1, -1, -1);
962 SaveTextAttributes(out, "polargram", -1, -1, -1, -1, -1);
963
964 if (fAxisAngle)
965 out << " polargram->SetAxisAngle(" << std::to_string((int)(fAxisAngle / TMath::Pi() * 180)).c_str() << ");\n";
966
967 if (fNdivPol != 508)
968 out << " polargram->SetNdivPolar(" << std::to_string(fNdivPol).c_str() << ");\n";
969 out << " polargram->SetPolarLabelColor(" << TColor::SavePrimitiveColor(fPolarLabelColor) << ");\n";
970 out << " polargram->SetPolarLabelFont(" << std::to_string(fPolarLabelFont).c_str() << ");\n";
971 out << " polargram->SetPolarLabelSize(" << std::to_string(fPolarTextSize).c_str() << ");\n";
972 if (fPolarOffset != 0.04)
973 out << " polargram->SetPolarOffset(" << std::to_string(fPolarOffset).c_str() << ");\n";
974 out << " polargram->SetTickpolarSize(" << std::to_string(fTickpolarSize).c_str() << ");\n";
975 if (fPolarLabels)
976 for(Int_t n = 0; n < fNdivPol; n++)
977 if (!fPolarLabels[n].IsNull())
978 out << " polargram->SetPolarLabel(\"" << fPolarLabels[n] << "\");\n";
979
980 if (fNdivRad != 508)
981 out << " polargram->SetNdivRadial(" << std::to_string(fNdivRad).c_str() << ");\n";
982 out << " polargram->SetRadialLabelColor(" << TColor::SavePrimitiveColor(fRadialLabelColor) << ");\n";
983 out << " polargram->SetRadialLabelFont(" << std::to_string(fRadialLabelFont).c_str() << ");\n";
984 out << " polargram->SetRadialLabelSize(" << std::to_string(fRadialTextSize).c_str() << ");\n";
985 if (fRadialOffset != 0.04)
986 out << " polargram->SetRadialOffset(" << std::to_string(fRadialOffset).c_str() << ");\n";
987}
988
@ kMouseMotion
Definition Buttons.h:23
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kButton1Down
Definition Buttons.h:17
@ kMove
Definition GuiTypes.h:375
const Int_t kMaxPixel
Max value for an int.
Definition GuiTypes.h:370
#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
cudaEvent_t event
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Font_t
Font number (short)
Definition RtypesCore.h:96
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
@ kBlack
Definition Rtypes.h:65
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:142
#define gPad
Line Attributes class.
Definition TAttLine.h:21
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual void ModifyOn(TVirtualPad &pad)
Change current line attributes on specified pad.
Definition TAttLine.cxx:255
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:246
Style_t fLineStyle
Line style.
Definition TAttLine.h:25
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:289
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
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:399
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:2569
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:1006
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:2526
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
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2146
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:204
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:886
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:776
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
void ToUpper()
Change string to upper case.
Definition TString.cxx:1203
TString & Remove(Ssiz_t pos)
Definition TString.h:695
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:2460
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:731
Helper class to store interactive parameters for individual objects Should be used via MakeInteractiv...
Definition TVirtualPad.h:72
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
constexpr Double_t PiOver2()
Definition TMath.h:54
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:659
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:769
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:734
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:607
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:601
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:613
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122