BCH1D.h
1 #ifndef __BCH1D__H
2 #define __BCH1D__H
3 
16 /*
17  * Copyright (C) 2007-2018, 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 
26 #include "BCHistogramBase.h"
27 
28 #include <vector>
29 
30 class TH1;
31 
32 // ---------------------------------------------------------
33 
34 class BCH1D : public BCHistogramBase
35 {
36 
37 public:
38 
45  kNoBands = -1,
46  kCentralInterval = 0,
47  kSmallestInterval = 1,
48  kUpperLimit = 2,
49  kLowerLimit = 3,
50  kUserSpecified = 4
51  };
52 
60  BCH1D(const TH1* const hist = 0);
61 
64  BCH1D(const BCH1D& other);
65 
68  virtual ~BCH1D() {};
69 
78  double GetLocalMode()
79  { return GetLocalMode(0); }
80 
85  { return GetBestFitParameters(0); }
86 
89  double GetMedian()
90  { return this->GetQuantile(0.5); };
91 
97  double GetQuantile(double probability);
98 
104  double GetLimit(double probability)
105  { return this->GetQuantile(probability); };
106 
110  { return fBandType; }
111 
114  unsigned GetNQuantiles()
115  { return fNQuantiles; }
116 
120  { return fQuantileLineColor; }
121 
125  { return fDrawMedian; }
126 
130  { return fDrawCentral68; }
131 
138 
141  void CopyOptions(const BCH1D& other);
142 
145  void SetColorScheme(BCHColorScheme scheme);
146 
148 
151  void SetGlobalMode(double mode)
152  { SetGlobalMode(std::vector<double>(1, mode)); }
153 
155 
158  void SetLocalMode(double mode)
159  { SetLocalMode(std::vector<double>(1, mode)); }
160 
164  { fBandType = bt; }
165 
169  void SetDrawQuantiles(unsigned n)
170  { fNQuantiles = n; }
171 
176  { fQuantileLineColor = c; }
177 
182  void SetDrawMedian(bool flag = true, bool central68 = true)
183  { fDrawMedian = flag; fDrawCentral68 = central68;}
184 
191 
195  virtual void CheckIntervals(std::vector<double>& intervals);
196 
201  virtual std::vector<double> DefaultIntervals(int nbands = -1);
202 
205  virtual void DrawBands(const std::string& options = "same");
206 
209  virtual void DrawMarkers();
210 
213  virtual void DrawQuantiles(unsigned n);
214 
217  virtual void DrawMedian();
218 
224  void PrintSummary(const std::string& prefix = "", unsigned prec = 6, std::vector<double> intervals = std::vector<double>(0));
225 
228  struct BCH1DInterval {
230  double xmin;
231  double xmax;
232  double mode;
233  double relative_height;
234  double relative_mass;
236  BCH1DInterval();
237 
242  void PrintSummary(const std::string& prefix = "", unsigned prec = 6) const;
243  };
244 
249  std::vector<BCH1D::BCH1DInterval> intervals;
250  double total_mass;
251  double mode;
252  double max_val;
254 
256 
261  void PrintSummary(const std::string& prefix = "", unsigned prec = 6) const;
262  };
263 
267  std::vector<BCH1D::BCH1DSmallestInterval> GetSmallestIntervals(std::vector<double> masses);
268 
273  { return GetSmallestIntervals(std::vector<double>(1, mass)).at(0); }
274 
289  TH1* GetSubHistogram(double min, double max, const std::string& name = "", bool preserve_range = false);
290 
293 protected:
294 
298 
301  unsigned fNQuantiles;
302 
306 
310 
314 };
315 
316 // ---------------------------------------------------------
317 
318 #endif
double GetLimit(double probability)
Return the quantile of the distribution.
Definition: BCH1D.h:104
unsigned fNQuantiles
Number of quantiles to draw.
Definition: BCH1D.h:301
virtual void DrawBands(const std::string &options="same")
Draw bands.
Definition: BCH1D.cxx:135
int GetQuantileLineColor()
Definition: BCH1D.h:119
double GetLocalMode()
Definition: BCH1D.h:78
void PrintSummary(const std::string &prefix="", unsigned prec=6) const
Print information to log.
Definition: BCH1D.cxx:441
double GetQuantile(double probability)
Returns the quantile of the distribution.
Definition: BCH1D.cxx:68
virtual std::vector< double > DefaultIntervals(int nbands=-1)
Return default intervals.
Definition: BCH1D.cxx:97
bool GetDrawCentral68()
Definition: BCH1D.h:129
void SetBandType(BCH1DBandType bt)
Set band type.
Definition: BCH1D.h:163
void SetGlobalMode(std::vector< double > gm)
Set global mode.
TH1 * GetSubHistogram(double min, double max, const std::string &name="", bool preserve_range=false)
Get histogram with bins outside min, max band being zero.
Definition: BCH1D.cxx:352
virtual void DrawMarkers()
Draw markers: global mode, local mode, mean, quantiles, median.
Definition: BCH1D.cxx:230
virtual ~BCH1D()
The default destructor.
Definition: BCH1D.h:68
void CopyOptions(const BCH1D &other)
Copy options from other.
Definition: BCH1D.cxx:50
virtual void CheckIntervals(std::vector< double > &intervals)
Check intervals: remove values below 0 or above 1, and sort to proper order for band type...
Definition: BCH1D.cxx:83
virtual void CheckIntervals(std::vector< double > &intervals, int sort)
Check intervals: remove values below 0 or above 1.
BCH1D(const TH1 *const hist=0)
The default constructor.
Definition: BCH1D.cxx:32
unsigned GetNQuantiles()
Definition: BCH1D.h:114
virtual void CopyOptions(const BCHistogramBase &other)
Copy options from.
bool GetDrawMedian()
Definition: BCH1D.h:124
double GetBestFitParameters()
Definition: BCH1D.h:84
Contains information about an interval.
Definition: BCH1D.h:228
void SetDrawQuantiles(unsigned n)
Set draw quantiles.
Definition: BCH1D.h:169
double GetMedian()
Definition: BCH1D.h:89
BCHColorScheme
An enumerator for the color schemes.
A base class for drawing histograms in BAT style.
BCH1D::BCH1DSmallestInterval GetSmallestIntervals(double mass)
Definition: BCH1D.h:272
BCH1DBandType
Enum for type of bands to be drawn on plot.
Definition: BCH1D.h:44
void SetDrawMedian(bool flag=true, bool central68=true)
Set drawing of median.
Definition: BCH1D.h:182
std::vector< BCH1D::BCH1DSmallestInterval > GetSmallestIntervals(std::vector< double > masses)
Definition: BCH1D.cxx:452
std::vector< double > & GetLocalMode()
void SetQuantileLineColor(int c)
Set quantile line color.
Definition: BCH1D.h:175
void PrintSummary(const std::string &prefix="", unsigned prec=6, std::vector< double > intervals=std::vector< double >(0))
Print information to log.
Definition: BCH1D.cxx:408
bool fDrawMedian
flag for drawing median.
Definition: BCH1D.h:309
virtual void DrawQuantiles(unsigned n)
Draw quantiles.
Definition: BCH1D.cxx:239
void SetColorScheme(BCHColorScheme scheme)
Sets the color scheme.
Definition: BCH1D.cxx:61
bool fDrawCentral68
flag for darwing central 68% interval arrows.
Definition: BCH1D.h:313
void SetLocalMode(std::vector< double > lm)
Set local mode.
A class for handling 1D distributions.
Definition: BCH1D.h:34
void SetGlobalMode(double mode)
Set global mode.
Definition: BCH1D.h:151
std::vector< double > & GetBestFitParameters()
Vector of intervals with information about total mass.
Definition: BCH1D.h:247
int fQuantileLineColor
Quantile line color.
Definition: BCH1D.h:305
virtual void DrawMedian()
Draw median & central 68% interval.
Definition: BCH1D.cxx:311
void SetLocalMode(double mode)
Set local mode.
Definition: BCH1D.h:158
BCH1DBandType GetBandType()
Definition: BCH1D.h:109
BCH1DBandType fBandType
Band type.
Definition: BCH1D.h:297