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