KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVGraph.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Wed Jun 19 09:06:08 2013
2 //Author: dgruyer
3 
4 #include "KVGraph.h"
5 #include "TPad.h"
6 #include "TAxis.h"
7 #include "TMath.h"
8 #include "Riostream.h"
9 #include "TH2F.h"
10 #include "KVGaxis.h"
11 #include "KVNumberList.h"
12 
14 
15 
16 
20 {
21  // Default constructor
22  init();
23 }
24 
25 
26 
27 //KVGraph::KVGraph(const KVGraph& obj) : TGraph()
28 //{
29 // // Copy constructor
30 // // This ctor is used to make a copy of an existing object (for example
31 // // when a method returns an object), and it is always a good idea to
32 // // implement it.
33 // // If your class allocates memory in its constructor(s) then it is ESSENTIAL :-)
34 
35 // obj.Copy(*this);
36 //}
37 
38 
39 
42 
44 {
45  // Write your code here
46  init();
47 }
48 
49 
50 
51 //KVGraph::KVGraph(Int_t n, const Int_t* x, const Int_t* y) : TGraphErrors(n, x, y)
52 //{
53 // // Write your code here
54 // init();
55 //}
56 
58 
59 //KVGraph::KVGraph(Int_t n, const Float_t* x, const Float_t* y) : TGraphErrors(n, x, y)
60 //{
61 // // Write your code here
62 // init();
63 //}
64 
66 
67 //KVGraph::KVGraph(Int_t n, const Double_t* x, const Double_t* y) : TGraphErrors(n, x, y)
68 //{
69 // // Write your code here
70 // init();
71 //}
72 
74 
75 //KVGraph::KVGraph(const TVectorF& vx, const TVectorF& vy) : TGraphErrors(vx, vy)
76 //{
77 // // Write your code here
78 // init();
79 //}
80 
82 
83 //KVGraph::KVGraph(const TVectorD& vx, const TVectorD& vy) : TGraphErrors(vx, vy)
84 //{
85 // // Write your code here
86 // init();
87 //}
88 
90 
91 //KVGraph::KVGraph(const TH1* h) : TGraphErrors(h)
92 //{
93 // // Write your code here
94 // init();
95 //}
96 
98 
99 //KVGraph::KVGraph(const TF1* f, Option_t* option) : TGraphErrors(f, option)
100 //{
101 // // Write your code here
102 // init();
103 //}
104 
106 
107 //KVGraph::KVGraph(const char* filename, const char* format, Option_t* option) : TGraphErrors(filename, format, option)
108 //{
109 // // Write your code here
110 // init();
111 //}
112 
113 
116 
118 {
119  // Destructor
120 }
121 
122 
123 
125 
127 {
128  TGraphErrors::Draw(chopt);
129 
130  gPad->SetFillColor(0);
131  gPad->SetBorderMode(0);
132  gPad->SetBorderSize(2);
133  gPad->SetFrameBorderMode(0);
134  gPad->SetFrameLineColor(0);
135  gPad->SetFrameBorderMode(0);
136 
137  gPad->Modified();
138  gPad->Update();
139 
140  TString opt(chopt);
141  opt.ToLower();
142  if (!opt.Contains("t")) return;
143 
144  Double_t xmin = GetXaxis()->GetXmin();
145  Double_t xmax = GetXaxis()->GetXmax();
146  Double_t ymin = GetYaxis()->GetXmin();
147  Double_t ymax = GetYaxis()->GetXmax();
148 
151 
152  Double_t xstr, xstp, ystr, ystp;
153  if (fUseX) {
156  }
157  else {
158  xstr = xmin;
159  xstp = xmax;
160  }
161 
162  if (fUseY) {
165  }
166  else {
167  ystr = ymin;
168  ystp = ymax;
169  }
170 
171  switch (fCropMode) {
172  case kNoCrop:
173  xstr = TMath::Min(xmin, xstr);
174  xstp = TMath::Max(xmax, xstp);
175  ystr = TMath::Min(ymin, ystr);
176  ystp = TMath::Max(ymax, ystp);
177  break;
178  case kCropOnDiv:
179  break;
180  case kCropOnGraph:
182  xstp = TMath::Max(TMath::MaxElement(GetN(), GetX()), xstp);
183  ystr = TMath::Min(TMath::MinElement(GetN(), GetY()), ystr);
184  ystp = TMath::Max(TMath::MaxElement(GetN(), GetY()), ystp);
185  break;
186  case kCropMin:
188  xstp = TMath::Max(xmax, xstp);
189  ystr = TMath::Min(TMath::MinElement(GetN(), GetY()), ystr);
190  ystp = TMath::Max(ymax, ystp);
191  break;
192  }
193 
194  TGaxis* axis = 0;
195  // draw new x axis and hide the old one but keeping its option
196  if (fUseX) axis = new KVGaxis(xstr, ymin, xstp, ymin, fNDivX, fDisplayDivX);
197  else axis = new TGaxis(xstr, ymin, xstp, ymin, xstr, xstp, fNDivX);
199  HideAxis(GetXaxis());
200  axis->Draw();
201 
202  // draw new y axis and hide the old one but keeping its option
203  if (fUseY) axis = new KVGaxis(xmin, ystr, xmin, ystp, fNDivY, fDisplayDivY);
204  else axis = new TGaxis(xmin, ystr, xmin, ystp, ystr, ystp, fNDivY);
206  HideAxis(GetYaxis());
207  axis->Draw();
208 
209  gPad->Modified();
210  gPad->Update();
211 }
212 
213 
214 
216 
218 {
219  ax->SetTitleSize(0.0);
220  ax->SetTickLength(0);
221  ax->SetAxisColor(0);
222  ax->SetLabelColor(0);
223 }
224 
225 
226 
228 
230 {
231  Double_t* x;
232  if (xAxis) x = GetX();
233  else x = GetY();
234 
235  KVNumberList nb;
236  for (Int_t i = 0; i < GetN(); i++) nb.Add((x[i]) * 100);
237 
238  nb.Begin();
239 
240  Double_t* bins = new Double_t[nbins];
241  Int_t i = 0;
242  while (!nb.End()) bins[i++] = (nb.Next()) / 100.;
243 
244  return bins;
245 }
246 
247 
248 
250 
252 {
253  fDisplayDivX = 0;
254  fDisplayDivY = 0;
255  fNDivX = fNDivY = 0;
257  fUseX = fUseY = kTRUE;
258 }
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
271 
int Int_t
#define xstr(s)
Definition: KVBase.cpp:56
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
const Bool_t kFALSE
bool Bool_t
double Double_t
const Bool_t kTRUE
const char Option_t
float xmin
float ymin
float xmax
float ymax
#define gPad
Extension of TGaxis class optimised for KVGraph visualisation.
Definition: KVGaxis.h:17
Extension of TGraph class with new draw option.
Definition: KVGraph.h:15
Double_t * fDisplayDivX
Definition: KVGraph.h:17
Int_t fNDivY
Definition: KVGraph.h:19
Int_t fNDivX
Definition: KVGraph.h:19
@ kNoCrop
Definition: KVGraph.h:31
@ kCropOnGraph
Definition: KVGraph.h:33
@ kCropOnDiv
Definition: KVGraph.h:32
@ kCropMin
Definition: KVGraph.h:34
Bool_t fUseX
Definition: KVGraph.h:20
void HideAxis(TAxis *ax)
Definition: KVGraph.cpp:217
Double_t * GetBinArray(Int_t &nbins, Bool_t xAxis=kTRUE)
Definition: KVGraph.cpp:229
Double_t * fDisplayDivY
Definition: KVGraph.h:18
virtual void init()
Definition: KVGraph.cpp:251
KVGraph()
Default constructor.
Definition: KVGraph.cpp:19
Bool_t fUseY
Definition: KVGraph.h:20
void Draw(Option_t *chopt="")
Definition: KVGraph.cpp:126
virtual ~KVGraph()
Destructor.
Definition: KVGraph.cpp:117
Int_t fCropMode
Definition: KVGraph.h:22
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:83
Bool_t End(void) const
Definition: KVNumberList.h:197
void Begin(void) const
void Add(Int_t)
Add value 'n' to the list.
Int_t Next(void) const
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
virtual void SetTitleSize(Float_t size=0.04)
virtual void SetTickLength(Float_t length=0.03)
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Double_t GetXmax() const
Double_t GetXmin() const
virtual void ImportAxisAttributes(TAxis *axis)
Int_t GetN() const
Double_t * GetX() const
virtual void Draw(Option_t *chopt="")
TAxis * GetXaxis() const
TAxis * GetYaxis() const
Double_t * GetY() const
virtual void Draw(Option_t *option="")
void ToLower()
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t x[n]
const Int_t n
Double_t Min(Double_t a, Double_t b)
T MinElement(Long64_t n, const T *a)
T MaxElement(Long64_t n, const T *a)
Double_t Max(Double_t a, Double_t b)