KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVHistogram.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Mon Feb 3 11:02:18 2014
2 //Author: John Frankland,,,
3 
4 #include "KVHistogram.h"
5 #include <TROOT.h>
6 
8 
9 
10 
11 
12 
14 void KVHistogram::ParseExpressionAndSelection()
15 {
16  if (!fHisto) return;
17  KVString exp, sel, weight, x, y, z, meanrms;
18  ParseHistoTitle(fHisto->GetTitle(), exp, sel, weight);
19  ParseExpressionString(exp, x, y, z);
20  fParams.SetValue("VARX", x);
21  fParams.SetValue("VARY", y);
22  fParams.SetValue("VARZ", z);
23  fParams.SetValue("SELECTION", sel);
24  fParams.SetValue("EXPRESSION", exp);
25  fParams.SetValue("WEIGHT", weight);
26  meanrms.Form("%f (%f)", fHisto->GetMean(), fHisto->GetRMS());
27  fParams.SetValue("MEANRMSX", meanrms);
28  meanrms.Form("%f (%f)", fHisto->GetMean(2), fHisto->GetRMS(2));
29  fParams.SetValue("MEANRMSY", meanrms);
30 }
31 
32 
33 
35 
37 {
38  if (fHisto) return fHisto->GetMean(axis);
39  return fCut->GetMean(axis);
40 }
41 
42 
43 
46 
48 {
49  // Default constructor
50  fHisto = h;
51  fCut = nullptr;
52  fParams.SetValue("WEIGHT", "1");
53  if (h) {
55  SetType("Histo");
56  SetName(h->GetName());
57  SetLabel(h->ClassName());
58  }
59 }
60 
61 
62 
65 
67 {
68  // Ctor for TCutG object
69  fHisto = nullptr;
70  fCut = cut;
71  SetType("Cut");
72  fParams.SetValue("VARX", cut->GetVarX());
73  fParams.SetValue("VARY", cut->GetVarY());
74  fParams.SetValue("VARZ", "");
75  fParams.SetValue("SELECTION", "");
76  fParams.SetValue("EXPRESSION", "");
77  fParams.SetValue("WEIGHT", "1");
78  fParams.SetValue("MEANRMSX", -1);
79  fParams.SetValue("MEANRMSY", -1);
80  SetName(cut->GetName());
81  SetLabel(cut->ClassName());
82 }
83 
84 
85 
88 
90 {
91  // Destructor
93 }
94 
95 
96 
100 
101 void KVHistogram::ParseHistoTitle(const Char_t* title, KVString& exp, KVString& sel, KVString& weight)
102 {
103  // Take histo title "VAREXP [WEIGHT] { SELECTION }"
104  // and separate the three components
105 
106  exp = "";
107  sel = "";
108  weight = "1";
109  TString tmp(title);
110  Int_t ss = tmp.Index("{");
111  if (ss > 0) {
112  Int_t se = tmp.Index("}");
113  sel = tmp(ss + 1, se - ss - 1);
114  sel.Remove(TString::kBoth, ' ');
115  exp = tmp(0, ss);
116  exp.Remove(TString::kBoth, ' ');
117  }
118  else {
119  exp = tmp;
120  exp.Remove(TString::kBoth, ' ');
121  }
122  // get weight from expression string if any
123  KVString tmp1(exp);
124  tmp1.Begin(" ");
125  exp = tmp1.Next();
126  if (!tmp1.End()) {
127  weight = tmp1.Next();
128  weight.Remove(TString::kBoth, '[');
129  weight.Remove(TString::kBoth, ']');
130  }
131 }
132 
133 
134 
137 
139  KVString& varZ)
140 {
141  // Parse expression strings "VARZ:VARY:VARX" or "VARY:VARX" or "VARX"
142 
143  KVString tmp(exp);
144  tmp.Remove(TString::kBoth, ' ');
145  // hide any "::" scope resolution operators (e.g. TMath::DegToRad)
146  tmp.ReplaceAll("::", "_scope_");
147  Int_t nvar = tmp.CountChar(':');
148  tmp.Begin(":");
149  varX = varY = varZ = "";
150  if (nvar == 2) {
151  varZ = tmp.Next();
152  varZ.ReplaceAll("_scope_", "::");
153  }
154  if (nvar >= 1) {
155  varY = tmp.Next();
156  varY.ReplaceAll("_scope_", "::");
157  }
158  varX = tmp.Next();
159  varX.ReplaceAll("_scope_", "::");
160 }
161 
162 
163 
165 
167 {
168  return fParams.GetStringValue("VARX");
169 }
170 
171 
173 
175 {
176  return fParams.GetStringValue("VARY");
177 }
178 
179 
181 
183 {
184  return fParams.GetStringValue("VARZ");
185 }
186 
187 
189 
191 {
192  return fParams.GetStringValue("SELECTION");
193 }
194 
195 
196 
199 
201 {
202  // Return weighting used for filling histogram
203  return fParams.GetStringValue("WEIGHT");
204 }
205 
206 
207 
209 
211 {
212  return fParams.GetStringValue("MEANRMSX");
213 }
214 
215 
216 
218 
220 {
221  return fParams.GetStringValue("MEANRMSY");
222 }
223 
224 
225 
228 
229 void KVHistogram::SetWeight(const Char_t* weight)
230 {
231  // Set weighting factor used to fill histogram
232  fParams.SetValue("WEIGHT", weight);
233 }
234 
235 
236 
238 
240 {
243  std::cout << "KVHistogram::" << GetName() << " " << GetLabel();
244 // cout << " X:" << GetVarX();
245 // if(IsType("Cut")){
246 // cout << " Y:" << GetVarY();
247 // }
248 // else
249 // {
250 // if(strcmp(GetVarY(),"")) cout << " Y:" << GetVarY();
251 // if(strcmp(GetVarZ(),"")) cout << " Z:" << GetVarZ();
252 // if(strcmp(GetSelection(),"")) cout << " [" << GetSelection() << "]";
253 // }
254  if (GetHisto()) std::cout << " : " << GetHisto()->GetTitle();
255  else std::cout << " : " << GetCut()->GetName();
256  std::cout << std::endl;
258 }
259 
260 
261 
264 
266 {
267  // In order to have context menu access to the contained histogram or cut
268  if (fHisto) return (TObject*)fHisto;
269  return fCut;
270 }
271 
272 
273 
275 
277 {
278  return fParams.GetStringValue("EXPRESSION");
279 }
280 
281 
282 
284 
286 {
287  if (fHisto) return fHisto->GetTitle();
288  if (fCut) return fCut->GetName();
289  return "";
290 }
291 
292 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define SafeDelete(p)
char Char_t
double Double_t
const char Option_t
double exp(double)
void SetLabel(const Char_t *lab)
Definition: KVBase.h:194
const Char_t * GetLabel() const
Definition: KVBase.h:198
virtual void SetType(const Char_t *str)
Definition: KVBase.h:172
Wrapper for histograms and graphical cuts used by KVTreeAnalyzer.
Definition: KVHistogram.h:19
const Char_t * GetHistoTitle() const
TCutG * GetCut() const
Definition: KVHistogram.h:40
const Char_t * GetVarZ() const
static void ParseExpressionString(const Char_t *exp, KVString &varX, KVString &varY, KVString &varZ)
Parse expression strings "VARZ:VARY:VARX" or "VARY:VARX" or "VARX".
static void ParseHistoTitle(const Char_t *title, KVString &exp, KVString &sel, KVString &weight)
void SetWeight(const Char_t *)
Set weighting factor used to fill histogram.
const Char_t * GetVarY() const
const Char_t * GetMeanRMSY() const
const Char_t * GetExpression() const
KVHistogram(TH1 *h=nullptr)
Default constructor.
Definition: KVHistogram.cpp:47
Double_t GetMean(Int_t axis=1) const
Definition: KVHistogram.cpp:36
TH1 * fHisto
pointer to histogram
Definition: KVHistogram.h:21
void ls(Option_t *option="") const
const Char_t * GetSelection() const
TH1 * GetHisto() const
Definition: KVHistogram.h:36
TObject * GetObject() const
In order to have context menu access to the contained histogram or cut.
const Char_t * GetWeight() const
Return weighting used for filling histogram.
const Char_t * GetMeanRMSX() const
const Char_t * GetVarX() const
virtual ~KVHistogram()
Destructor.
Definition: KVHistogram.cpp:89
KVNameValueList fParams
histogram parameters
Definition: KVHistogram.h:23
void ParseExpressionAndSelection()
Definition: KVHistogram.cpp:14
TCutG * fCut
pointer to cut
Definition: KVHistogram.h:22
void SetValue(const Char_t *name, value_type value)
const Char_t * GetStringValue(const Char_t *name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
const char * GetVarY() const
const char * GetVarX() const
virtual Double_t GetMean(Int_t axis=1) const
virtual Double_t GetMean(Int_t axis=1) const
virtual const char * GetName() const
virtual const char * GetTitle() const
virtual void SetName(const char *name)
virtual const char * ClassName() const
static Int_t IncreaseDirLevel()
static void IndentLevel()
static Int_t DecreaseDirLevel()
Int_t CountChar(Int_t c) const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
TString & ReplaceAll(const char *s1, const char *s2)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t y[n]
Double_t x[n]
TH1 * h