Logo ROOT   6.14/05
Reference Guide
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 
15 To draw polar axis
16 
17 TGraphPolargram draw the polar axis of the TGraphPolar.
18 
19 Example:
20 
21 Begin_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->SetLineColor(2);
37  grP1->Draw("AOL");
38 
39  return CPol;
40 }
41 End_Macro
42 */
43 
44 #include "TGraphPolar.h"
45 #include "TGraphPolargram.h"
46 #include "TGaxis.h"
47 #include "THLimitsFinder.h"
48 #include "TVirtualPad.h"
49 #include "TROOT.h"
50 #include "TLatex.h"
51 #include "TEllipse.h"
52 #include "TMath.h"
53 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// TGraphPolargram Constructor.
58 
60  Double_t tmin, Double_t tmax):
61  TNamed(name,"Polargram")
62 {
63  Init();
64  fNdivRad = 508;
65  fNdivPol = 508;
66  fPolarLabels = NULL;
67  fRwrmax = rmax;
68  fRwrmin = rmin;
69  fRwtmin = tmin;
70  fRwtmax = tmax;
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Short constructor used in the case of a spider plot.
75 
77  TNamed(name,"Polargram")
78 {
79  Init();
80  fNdivRad = 0;
81  fNdivPol = 0;
82  fPolarLabels = NULL;
83  fRwrmax = 1;
84  fRwrmin = 0;
85  fRwtmax = 0;
86  fRwtmin = 0;
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// TGraphPolargram destructor.
91 
93 {
94  if (fPolarLabels != NULL) delete [] fPolarLabels;
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Set the Polar range.
99 /// \param[in] tmin the start number.
100 /// \param[in] tmax the end number.
101 
103 {
104  if (tmin < tmax) {
105  fRwtmin = tmin;
106  fRwtmax = tmax;
107  }
108  if (gPad) gPad->Modified();
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Everything within the circle belongs to the TGraphPolargram.
113 
115 {
116  Int_t i;
117  Double_t x = gPad->AbsPixeltoX(px);
118  Double_t y = gPad->AbsPixeltoY(py);
119 
120  // Check if close to a (major) radial line.
121  Double_t rad = TMath::Sqrt(x*x+y*y);
122  Int_t div = (Int_t)rad*(fNdivRad%100);
123  Double_t dr = TMath::Min(TMath::Abs(rad-div*1./(fNdivRad%100)),
124  TMath::Abs(rad-(div+1)*1./(fNdivRad%100)));
125  Int_t drad = gPad->XtoPixel(dr)-gPad->XtoPixel(0);
126 
127  // Check if close to a (major) Polar line.
128  // This is not a proper calculation, but rather fast.
129  Int_t dt = kMaxPixel;
130  for (i=0; i<(fNdivPol%100); i++) {
131  Double_t theta = i*2*TMath::Pi()/(fNdivPol%100);
132 
133  // Attention: px,py in pixel units, line given in user coordinates.
134  Int_t dthis = DistancetoLine(px,py,0.,0.,TMath::Cos(theta),
135  TMath::Sin(theta));
136 
137  // Fails if we are outside box described by the line.
138  // (i.e for all hor/vert lines)
139  if (dthis==9999) {
140 
141  // Outside -> Get distance to endpoint of line.
142  if (rad>1) {
143  dthis = (Int_t)TMath::Sqrt(
144  TMath::Power(px-gPad->XtoPixel(