BCVariable.h
1 #ifndef __BCVARIABLE__H
2 #define __BCVARIABLE__H
3 
16 /*
17  * Copyright (C) 2007-2013, the BAT core developer team
18  * All rights reserved.
19  *
20  * For the licensing terms see doc/COPYING.
21  * For documentation see http://mpp.mpg.de/bat
22  */
23 
24 // ---------------------------------------------------------
25 #include <string>
26 #include <cmath>
27 
28 class TH1;
29 class TH2;
30 class TH3;
31 class TRandom;
32 
33 // ---------------------------------------------------------
34 
36 {
37 
38 public:
39 
45  BCVariable();
46 
54  BCVariable(const std::string& name, double lowerlimit, double upperlimit, const std::string& latexname = "", const std::string& unitstring = "");
55 
58  virtual ~BCVariable() {};
59 
67  virtual const std::string& GetPrefix() const
68  { return fPrefix; }
69 
72  virtual const std::string& GetName() const
73  { return fName; }
74 
77  virtual const std::string& GetSafeName() const
78  { return fSafeName; }
79 
82  virtual const std::string& GetLatexName() const
83  { return (fLatexName.empty()) ? fName : fLatexName; }
84 
87  virtual const std::string& GetUnitString() const
88  { return fUnitString; }
89 
92  virtual std::string GetLatexNameWithUnits() const
93  { if (GetUnitString().empty()) return GetLatexName(); return GetLatexName() + " " + GetUnitString(); }
94 
97  virtual double GetLowerLimit() const
98  { return fLowerLimit; }
99 
102  virtual double GetUpperLimit() const
103  { return fUpperLimit; }
104 
109  virtual double GetRangeWidth() const
110  { return fUpperLimit - fLowerLimit; }
111 
114  virtual double GetRangeCenter() const
115  { return (fUpperLimit + fLowerLimit) / 2.; }
116 
119  virtual unsigned GetPrecision() const
120  { return fPrecision;}
121 
124  virtual bool FillH1() const
125  { return fFillH1; }
126 
129  virtual bool FillH2() const
130  { return fFillH2; }
131 
134  virtual unsigned GetNbins() const
135  { return fNbins; }
136 
144  virtual void SetName(const std::string& name);
145 
148  virtual void SetLatexName(const std::string& latex_name)
149  { fLatexName = latex_name; }
150 
153  virtual void SetUnitString(const std::string& unit_string)
154  { fUnitString = unit_string; }
155 
159  virtual void SetLowerLimit(double limit)
160  { SetLimits(limit, fUpperLimit); }
161 
165  virtual void SetUpperLimit(double limit)
166  { SetLimits(fLowerLimit, limit); }
167 
172  virtual void SetLimits(double lowerlimit = 0, double upperlimit = 1);
173 
177  virtual void SetPrecision(unsigned precision)
178  { fPrecision = precision; }
179 
183  virtual void FillHistograms(bool flag)
184  { FillHistograms(flag, flag); }
185 
190  virtual void FillHistograms(bool fill_1d, bool fill_2d)
191  { FillH1(fill_1d); FillH2(fill_2d); }
192 
195  virtual void FillH1(bool flag)
196  { fFillH1 = flag; }
197 
200  virtual void FillH2(bool flag)
201  { fFillH2 = flag; }
202 
203 
204  virtual void SetNbins(unsigned nbins)
205  { fNbins = nbins; }
214  virtual bool IsNamed(const std::string& name) const
215  { return fName.compare(name) == 0; }
216 
220  virtual bool IsSafeNamed(const std::string& safename) const
221  { return fSafeName.compare(safename) == 0; }
222 
228  virtual double PositionInRange(double x) const
229  { return (x - fLowerLimit) / (fUpperLimit - fLowerLimit); }
230 
235  virtual double ValueFromPositionInRange(double p) const
236  { return fLowerLimit + p * (fUpperLimit - fLowerLimit); }
237 
242  virtual void CalculatePrecision(bool force = false);
243 
246  virtual bool IsAtLimit(double value) const;
247 
250  virtual bool IsWithinLimits(double value) const
251  { return (value >= fLowerLimit and value <= fUpperLimit); }
252 
255  virtual void PrintSummary() const;
256 
261  virtual std::string OneLineSummary(bool print_prefix = true, int name_length = -1) const;
262 
265  virtual std::string H1Title() const;
266 
270  virtual std::string H2Title(const BCVariable& ordinate) const;
271 
276  virtual std::string H3Title(const BCVariable& ordinate_y, const BCVariable& ordinate_z) const;
277 
285  virtual TH1* CreateH1(const std::string& name) const;
286 
295  virtual TH2* CreateH2(const std::string& name, const BCVariable& ordinate) const;
296 
306  virtual TH3* CreateH3(const std::string& name, const BCVariable& ordinate_y, const BCVariable& ordinate_z) const;
307 
311  virtual double GetUniformRandomValue(TRandom* const R) const;
312 
315 protected:
317  std::string fPrefix;
318 
320  std::string fName;
321 
323  std::string fSafeName;
324 
326  double fLowerLimit;
327 
329  double fUpperLimit;
330 
332  unsigned fPrecision;
333 
335  std::string fLatexName;
336 
338  std::string fUnitString;
339 
341  bool fFillH1;
342 
344  bool fFillH2;
345 
347  unsigned fNbins;
348 
349 };
350 #endif
std::string fSafeName
Safe name of the variable for use in ROOT object naming.
Definition: BCVariable.h:323
virtual TH1 * CreateH1(const std::string &name) const
Creates a 1D Histogram for this variable.
Definition: BCVariable.cxx:132
virtual bool IsSafeNamed(const std::string &safename) const
Check if safe name is that of variable.
Definition: BCVariable.h:220
std::string fUnitString
Unit string for variable.
Definition: BCVariable.h:338
virtual std::string OneLineSummary(bool print_prefix=true, int name_length=-1) const
Definition: BCVariable.cxx:98
virtual const std::string & GetUnitString() const
Definition: BCVariable.h:87
unsigned fPrecision
Necessary precision for output.
Definition: BCVariable.h:332
virtual std::string H2Title(const BCVariable &ordinate) const
Definition: BCVariable.cxx:115
virtual void FillH1(bool flag)
Set the filling of 1D histogram.
Definition: BCVariable.h:195
double fUpperLimit
The upper limit of the variable value.
Definition: BCVariable.h:329
virtual std::string H1Title() const
Definition: BCVariable.cxx:109
A class representing a variable of a model.
Definition: BCVariable.h:35
virtual ~BCVariable()
Destructor.
Definition: BCVariable.h:58
unsigned fNbins
The number of equal-size bins used in histograms involving this variable.
Definition: BCVariable.h:347
virtual double GetLowerLimit() const
Definition: BCVariable.h:97
BCVariable()
The default constructor.
Definition: BCVariable.cxx:23
virtual bool IsWithinLimits(double value) const
Definition: BCVariable.h:250
virtual const std::string & GetPrefix() const
Definition: BCVariable.h:67
virtual void FillH2(bool flag)
Set the filling of 2D histograms.
Definition: BCVariable.h:200
virtual std::string H3Title(const BCVariable &ordinate_y, const BCVariable &ordinate_z) const
Definition: BCVariable.cxx:123
virtual bool IsNamed(const std::string &name) const
Check if name is that of variable.
Definition: BCVariable.h:214
virtual void FillHistograms(bool flag)
Set the filling of 1D and 2D histograms.
Definition: BCVariable.h:183
double fLowerLimit
The lower limit of the variable value.
Definition: BCVariable.h:326
virtual void SetName(const std::string &name)
Definition: BCVariable.cxx:52
virtual void CalculatePrecision(bool force=false)
Calculate the necessary precision for outputting this parameter and replace current precision is smal...
Definition: BCVariable.cxx:70
virtual const std::string & GetLatexName() const
Definition: BCVariable.h:82
virtual void SetUnitString(const std::string &unit_string)
Definition: BCVariable.h:153
virtual double GetUpperLimit() const
Definition: BCVariable.h:102
bool fFillH1
Flag to store MCMC samples in 1D histogram.
Definition: BCVariable.h:341
virtual bool FillH2() const
Definition: BCVariable.h:129
virtual void SetLatexName(const std::string &latex_name)
Definition: BCVariable.h:148
virtual bool IsAtLimit(double value) const
Definition: BCVariable.cxx:78
virtual void SetLimits(double lowerlimit=0, double upperlimit=1)
Set the limits of the variable values.
Definition: BCVariable.cxx:59
std::string fLatexName
The latex name of the variable.
Definition: BCVariable.h:335
virtual bool FillH1() const
Definition: BCVariable.h:124
virtual double GetRangeCenter() const
Returns center of variable range.
Definition: BCVariable.h:114
virtual std::string GetLatexNameWithUnits() const
Definition: BCVariable.h:92
std::string fName
The name of the variable.
Definition: BCVariable.h:320
virtual double PositionInRange(double x) const
return position in range of given value from 0 (at lower limit) to 1 (at upper limit) ...
Definition: BCVariable.h:228
virtual void SetLowerLimit(double limit)
Set the lower limit of the variable values.
Definition: BCVariable.h:159
virtual unsigned GetNbins() const
Definition: BCVariable.h:134
virtual void FillHistograms(bool fill_1d, bool fill_2d)
Set the filling of 1D and 2D histograms.
Definition: BCVariable.h:190
std::string fPrefix
prefix for output
Definition: BCVariable.h:317
virtual void SetPrecision(unsigned precision)
Set the precision of the output of variable.
Definition: BCVariable.h:177
virtual double ValueFromPositionInRange(double p) const
Translate from unit interval to value in variable range.
Definition: BCVariable.h:235
virtual const std::string & GetName() const
Definition: BCVariable.h:72
virtual double GetUniformRandomValue(TRandom *const R) const
Get random value uniformly distributed in range.
Definition: BCVariable.cxx:159
virtual void PrintSummary() const
Prints a variable summary on the screen.
Definition: BCVariable.cxx:89
virtual void SetUpperLimit(double limit)
Set the upper limit of the variable values.
Definition: BCVariable.h:165
virtual double GetRangeWidth() const
Returns the range width of the variable values.
Definition: BCVariable.h:109
bool fFillH2
Flag to store MCMC samples in 2D histograms.
Definition: BCVariable.h:344
virtual unsigned GetPrecision() const
Definition: BCVariable.h:119
virtual const std::string & GetSafeName() const
Definition: BCVariable.h:77