BCHistogramBase.h
1 #ifndef __BCHistogramBase__H
2 #define __BCHistogramBase__H
3 
11 /*
12  * Copyright (C) 2007-2018, the BAT core developer team
13  * All rights reserved.
14  *
15  * For the licensing terms see doc/COPYING.
16  * For documentation see http://mpp.mpg.de/bat
17  */
18 
19 // ---------------------------------------------------------
20 
21 #include <vector>
22 #include <string>
23 #include <utility>
24 
25 #include <TLegend.h>
26 
27 class TH1;
28 class TLegendEntry;
29 class TObject;
30 
31 // ---------------------------------------------------------
32 
34 {
35 public:
36 
43  kBlackWhite = 0,
44  kGreenYellowRed = 1,
45  kBlueOrange = 2,
46  kRedGreen = 3
47  };
48 
58  BCHistogramBase(const TH1* const hist = 0, int dimension = 0);
59 
62  BCHistogramBase(const BCHistogramBase& other);
63 
66  virtual ~BCHistogramBase();
67 
76 
79  friend void swap(BCHistogramBase& first, BCHistogramBase& second);
80 
83  BCHistogramBase& operator=(const TH1* const hist)
84  { SetHistogram(hist); return *this; }
85 
88  BCHistogramBase& operator=(const TH1& hist)
89  { SetHistogram(&hist); return *this; }
90 
98  TH1* GetHistogram()
99  { return fHistogram; };
100 
103  unsigned GetDimension() const
104  { return fDimension; }
105 
108  TLegend& GetLegend()
109  { return fLegend; }
110 
113  unsigned GetNLegendColumns() const
114  { return fNLegendColumns; }
115 
118  std::vector<double>& GetBestFitParameters()
119  { return fGlobalMode; }
120 
123  const std::vector<double>& GetBestFitParameters() const
124  { return fGlobalMode; }
125 
129  double GetBestFitParameters(unsigned i) const
130  { return fGlobalMode.at(i); }
131 
134  std::vector<double>& GetLocalMode()
135  { return fLocalMode; }
136 
139  const std::vector<double>& GetLocalMode() const
140  { return fLocalMode; }
141 
145  double GetLocalMode(unsigned i)
146  { return fLocalMode.at(i); }
147 
152  int GetBandColor(int index) const
153  { return fBandColors.at(index); };
154 
157  bool GetBandOvercoverage() const
158  { return fBandOvercoverage; }
159 
162  int GetLineColor() const
163  { return fLineColor; }
164 
167  int GetLineStyle() const
168  { return fLineStyle; }
169 
172  int GetLineWidth() const
173  { return fLineWidth; }
174 
177  int GetMarkerColor() const
178  { return fMarkerColor; }
179 
182  double GetMarkerScale() const
183  { return fMarkerScale; }
184 
187  short GetBandFillStyle() const
188  { return fBandFillStyle; }
189 
192  unsigned GetNBands() const
193  { return fNBands; }
194 
197  unsigned GetNSmooth() const
198  { return fNSmooth; }
199 
202  bool GetDrawGlobalMode() const
203  { return fDrawGlobalMode; }
204 
208  { return fDrawGlobalMode and fDrawGlobalModeArrows; }
209 
213  { return fGlobalModeMarkerStyle; }
214 
217  bool GetDrawLocalMode() const
218  { return fDrawLocalMode; }
219 
223  { return fDrawLocalMode and fDrawLocalModeArrows; }
224 
228  { return fLocalModeMarkerStyle; }
229 
232  bool GetDrawMean() const
233  { return fDrawMean; }
234 
237  int GetMeanMarkerStyle() const
238  { return fMeanMarkerStyle; }
239 
243  { return fDrawMean and fDrawStandardDeviation; }
244 
247  bool GetLogx() const
248  { return fLogx; }
249 
252  bool GetLogy() const
253  { return fLogy; }
254 
257  bool GetLogz() const
258  { return fLogz; }
259 
262  bool GetGridx() const
263  { return fGridx; }
264 
267  bool GetGridy() const
268  { return fGridy; }
269 
272  std::vector<double>& GetIntervals()
273  { return fIntervals; }
274 
277  const std::vector<double>& GetIntervals() const
278  { return fIntervals; }
279 
282  std::string& GetROOToptions()
283  { return fROOToptions; }
284 
287  const std::string& GetROOToptions() const
288  { return fROOToptions; }
289 
297  virtual void CopyOptions(const BCHistogramBase& other);
298 
301  void SetGlobalMode(std::vector<double> gm)
302  { fGlobalMode = gm; }
303 
307  { fGlobalMode.clear(); }
308 
311  void SetGlobalMode(unsigned i, double lm)
312  { if (i < fGlobalMode.size()) fGlobalMode[i] = lm; }
313 
316  void SetLocalMode(std::vector<double> lm)
317  { fLocalMode = lm; }
318 
322  { fLocalMode.clear(); }
323 
326  void SetLocalMode(unsigned i, double lm)
327  { if (i < fLocalMode.size()) fLocalMode[i] = lm; }
328 
338  virtual void SetColorScheme(BCHColorScheme scheme);
339 
343  void AddBandColor(int c)
344  { fBandColors.push_back(c); }
345 
350  void SetBandColor(unsigned i, int c)
351  { if (i < fBandColors.size()) fBandColors[i] = c; }
352 
355  void SetBandOvercoverage(bool flag = true)
356  { fBandOvercoverage = flag; }
357 
361  void SetLineColor(int c)
362  { fLineColor = c; }
363 
367  void SetLineStyle(int s)
368  { fLineStyle = s; }
369 
373  void SetLineWidth(int w)
374  { fLineWidth = w; }
375 
379  void SetMarkerColor(int c)
380  { fMarkerColor = c; }
381 
384  void SetMarkerScale(double s)
385  { fMarkerScale = s; }
386 
390  void SetBandFillStyle(short f)
391  { fBandFillStyle = f; }
392 
395  virtual void SetHistogram(const TH1* const hist);
396 
399  void SetLogx(bool flag = true)
400  { fLogx = flag; }
401 
404  void SetLogy(bool flag = true)
405  { fLogy = flag; }
406 
409  void SetLogz(bool flag = true)
410  { fLogz = flag; }
411 
414  void SetGridx(bool flag = true)
415  { fGridx = flag; }
416 
419  void SetGridy(bool flag = true)
420  { fGridy = flag; }
421 
424  void SetNBands(unsigned n)
425  { fNBands = n; fIntervals = DefaultIntervals(); }
426 
429  void SetNSmooth(unsigned n)
430  { fNSmooth = n; }
431 
434  void SetDrawGlobalMode(bool flag = true, bool arrows = true)
435  { fDrawGlobalMode = flag; fDrawGlobalModeArrows = arrows;}
436 
441  { fGlobalModeMarkerStyle = s; }
442 
445  void SetDrawLocalMode(bool flag = true, bool arrows = true)
446  { fDrawLocalMode = flag; fDrawLocalModeArrows = arrows;}
447 
452  { fLocalModeMarkerStyle = s; }
453 
458  void SetDrawMean(bool flag = true, bool stddev = true)
459  { fDrawMean = flag; fDrawStandardDeviation = stddev;}
460 
464  void SetMeanMarkerStyle(int s)
465  { fMeanMarkerStyle = s; }
466 
469  void SetDrawLegend(bool flag = true)
470  { fDrawLegend = flag; }
471 
474  void SetNLegendColumns(unsigned n)
475  { fNLegendColumns = n; }
476 
479  void SetStats(bool flag = true)
480  { fDrawStats = flag; }
481 
484  void SetIntervals(std::vector<double> intervals)
485  { fIntervals = intervals; }
486 
489  void SetInterval(double interval)
490  { fIntervals.clear(); fIntervals.push_back(interval); }
491 
493  void AddInterval(double interval)
494  { fIntervals.push_back(interval); }
495 
497  void SetROOToptions(const std::string& options)
498  { fROOToptions = options; }
499 
508  virtual bool Valid() const;
509 
510  void ClearBandColors()
511  { fBandColors.clear(); }
512 
513  void ClearIntervals()
514  { fIntervals.clear(); }
515 
519  void Smooth(int n = -1);
520 
524  virtual void Draw();
525 
528  virtual void DrawBands(const std::string& /*options*/)
529  { }
530 
533  virtual void DrawMarkers();
534 
537  virtual void DrawGlobalMode();
538 
541  virtual void DrawLocalMode();
542 
545  virtual void DrawMean();
546 
550  virtual double ResizeLegend();
551 
554  virtual void DrawLegend();
555 
560  void GetNonzeroBinDensityMassVector(std::vector<std::pair<double, double> >& bin_dens_mass, int sort = -1);
561 
571  std::vector<std::pair<double, double> > GetSmallestIntervalBounds(std::vector<double> masses, bool overcoverage = true);
572 
579  virtual std::vector<double> GetSmallestIntervalSize(std::vector<double> masses, bool overcoverage = true);
580 
587  virtual double GetSmallestIntervalSize(double mass, bool overcoverage = true);
588 
594  virtual void CheckIntervals(std::vector<double>& intervals, int sort);
595 
600  virtual std::vector<double> DefaultIntervals(int nbands = -1);
601 
604  TLegendEntry* AddLegendEntry(TObject* obj, const std::string& label, const std::string& options);
605 
608  TLegendEntry* AddBandLegendEntry(TObject* obj, const std::string& label, const std::string& options);
609 
612 protected:
613 
617 
620  TLegend fLegend;
621 
624  unsigned fNLegendColumns;
625 
628  std::vector<double> fGlobalMode;
629 
632  std::vector<double> fLocalMode;
633 
636  std::vector<int> fBandColors;
637 
641 
645 
649 
653 
657 
661 
664  double fMarkerScale;
665 
668  bool fLogx;
669 
672  bool fLogy;
673 
676  bool fLogz;
677 
680  bool fGridx;
681 
684  bool fGridy;
685 
688  unsigned fNBands;
689 
692  unsigned fNSmooth;
693 
697 
701 
705 
709 
713 
717 
720  bool fDrawMean;
721 
725 
729 
733 
737 
741 
744  std::vector<double> fIntervals;
745 
748  std::string fROOToptions;
749 
752  mutable std::vector<TObject*> fROOTObjects;
753 
756  std::vector<TLegendEntry*> fExtraLegendEntries;
757 
758 };
759 
760 // ---------------------------------------------------------
761 
762 #endif
double fMarkerScale
Marker size scale.
friend void swap(BCHistogramBase &first, BCHistogramBase &second)
Swap function.
BCHistogramBase & operator=(BCHistogramBase other)
Assignment operator.
bool fDrawGlobalModeArrows
Flag for drawing global mode arrows.
std::vector< int > fBandColors
The colors of the color scheme.
void SetMeanMarkerStyle(int s)
Set mean marker style.
void SetLocalModeMarkerStyle(int s)
Set Local mode marker style.
virtual void DrawMean()
Draw mean and standard deviation.
void SetMarkerScale(double s)
Set marker size scale.
std::string fROOToptions
ROOT drawing options.
virtual void DrawMarkers()
Draw markers (global mode, local mode, etc.).
int fMarkerColor
Marker color.
bool fGridy
Flag for drawing of grid on y axis.
int GetLineWidth() const
void SetLineColor(int c)
Set histogram line color.
TLegend & GetLegend()
bool GetLogz() const
virtual std::vector< double > GetSmallestIntervalSize(std::vector< double > masses, bool overcoverage=true)
Get smallest interval sizes in dimensions of histogram: length (1D), area (2D), volume (3D)...
unsigned GetNSmooth() const
void SetGlobalMode(std::vector< double > gm)
Set global mode.
bool GetLogx() const
double GetMarkerScale() const
void SetStats(bool flag=true)
Set drawing of ROOT histogram stats box.
const std::vector< double > & GetIntervals() const
bool fLogz
Flag for controlling log plotting of z axis.
const std::string & GetROOToptions() const
bool fLogx
Flag for controlling log plotting of x axis.
TLegendEntry * AddLegendEntry(TObject *obj, const std::string &label, const std::string &options)
Add legend entry, checking first for unused extra entries.
short fBandFillStyle
The fill style for the bands.
int fLineStyle
histogram line style.
void SetGridx(bool flag=true)
Sets drawing of grid on x axis.
void SetIntervals(std::vector< double > intervals)
Set intervals to be drawn.
virtual void CheckIntervals(std::vector< double > &intervals, int sort)
Check intervals: remove values below 0 or above 1.
bool GetDrawGlobalModeArrows() const
int fMeanMarkerStyle
Holds option for mean marker style.
virtual void Draw()
Draw distribution into the active pad.
int GetBandColor(int index) const
Returns a band color of the current color scheme.
void GetNonzeroBinDensityMassVector(std::vector< std::pair< double, double > > &bin_dens_mass, int sort=-1)
Fill vector with values and integrals of nonzero bins sorted by value.
const std::vector< double > & GetLocalMode() const
virtual void DrawBands(const std::string &)
Draw bands.
virtual void CopyOptions(const BCHistogramBase &other)
Copy options from.
void SetBandColor(unsigned i, int c)
Set band color.
bool GetDrawMean() const
TH1 * fHistogram
The histogram.
bool fDrawStandardDeviation
Flag for drawing standard deviation.
std::vector< double > fIntervals
intervals to draw.
void SetLogx(bool flag=true)
Sets drawing of x axis in log.
std::vector< std::pair< double, double > > GetSmallestIntervalBounds(std::vector< double > masses, bool overcoverage=true)
Get probability density levels bounding from below the smallest-interval levels with probability mass...
short GetBandFillStyle() const
std::vector< double > fLocalMode
Local mode.
void Smooth(int n=-1)
Applying ROOT smoothing to histogram, and renormalize.
void SetNLegendColumns(unsigned n)
Set number of columns in legend.
BCHistogramBase(const TH1 *const hist=0, int dimension=0)
The default constructor.
virtual ~BCHistogramBase()
The default destructor.
void SetGlobalMode(unsigned i, double lm)
Set global mode element.
double GetLocalMode(unsigned i)
BCHColorScheme
An enumerator for the color schemes.
void SetGlobalModeMarkerStyle(int s)
Set global mode marker style.
std::string & GetROOToptions()
void SetDrawGlobalMode(bool flag=true, bool arrows=true)
Set drawing of global mode.
A base class for drawing histograms in BAT style.
bool GetLogy() const
virtual void SetHistogram(const TH1 *const hist)
Sets the histogram.
int fLineColor
histogram line color.
bool GetDrawGlobalMode() const
virtual void SetColorScheme(BCHColorScheme scheme)
Sets the color scheme.
void AddBandColor(int c)
Add band color.
virtual void DrawGlobalMode()
Draw global mode.
unsigned GetDimension() const
int GetLocalModeMarkerStyle() const
virtual std::vector< double > DefaultIntervals(int nbands=-1)
Return default intervals.
int fGlobalModeMarkerStyle
Holds option for global-mode marker style.
bool fBandOvercoverage
flag for whether bands should overcover.
bool fGridx
Flag for drawing of grid on x axis.
std::vector< TObject * > fROOTObjects
Storage for plot objects.
void SetDrawLocalMode(bool flag=true, bool arrows=true)
Set drawing of global mode.
virtual void DrawLocalMode()
Draw global mode.
int fLineWidth
histogram line width.
bool GetDrawStandardDeviation() const
bool GetBandOvercoverage() const
void SetNSmooth(unsigned n)
Sets number of times to smooth the histogram using ROOT&#39;s smoothing function.
int GetMeanMarkerStyle() const
std::vector< double > & GetLocalMode()
BCHistogramBase & operator=(const TH1 &hist)
Assign TH1 histogram with operator.
void SetDrawLegend(bool flag=true)
Set drawing of legend.
virtual double ResizeLegend()
Resize legend and set it for placement at the top of the pad.
void SetDrawMean(bool flag=true, bool stddev=true)
Set drawing of mean.
const std::vector< double > & GetBestFitParameters() const
int GetLineColor() const
virtual bool Valid() const
Whether histogram has been set and filled.
void SetBandFillStyle(short f)
Set band fill style.
std::vector< double > & GetIntervals()
int GetLineStyle() const
bool GetDrawLocalMode() const
void SetROOToptions(const std::string &options)
Set ROOT drawing options.
int GetMarkerColor() const
Returns the marker colors (used for mean, median, and mode.
void SetLocalMode(std::vector< double > lm)
Set local mode.
void SetGridy(bool flag=true)
Sets drawing of grid on y axis.
void SetBandOvercoverage(bool flag=true)
Set band coverage to be overcoverage (true) or undercoverage (false).
void SetNBands(unsigned n)
Sets number of credibility interval bands to draw.
bool fDrawMean
Flag for drawing mean.
std::vector< TLegendEntry * > fExtraLegendEntries
Storage for unused legend entries (for use with multicolumn legends).
bool fDrawGlobalMode
Flag for drawing global mode.
std::vector< double > fGlobalMode
Global mode.
unsigned GetNLegendColumns() const
void SetLineWidth(int w)
Set histogram line width.
std::vector< double > & GetBestFitParameters()
int fLocalModeMarkerStyle
Holds option for local-mode marker style.
bool GetGridy() const
void SetLogy(bool flag=true)
Sets drawing of y axis in log.
int GetBestFitParametersMarkerStyle() const
void UnsetGlobalMode()
Unset global mode.
bool fDrawLegend
Flag for drawing legend.
unsigned fNLegendColumns
number of columns to be set for legend.
double GetBestFitParameters(unsigned i) const
bool fDrawLocalModeArrows
Flag for drawing local mode arrows.
void UnsetLocalMode()
Unset local mode.
bool fDrawLocalMode
Flag for drawing local mode.
bool GetDrawLocalModeArrows() const
void SetLogz(bool flag=true)
Sets drawing of z axis in log.
BCHistogramBase & operator=(const TH1 *const hist)
Assign TH1 histogram with operator.
unsigned GetNBands() const
unsigned fNSmooth
Number of times to smooth histogram using ROOT&#39;s smooth function.
void SetMarkerColor(int c)
Set marker color (used for mean, median, and mode).
void SetInterval(double interval)
Set intervals to one single value.
void AddInterval(double interval)
Add interval value.
int fDimension
Dimension of histogram.
void SetLocalMode(unsigned i, double lm)
Set local mode element.
virtual void DrawLegend()
Resize histogram and draw legend.
unsigned fNBands
Number of credibility interval bands to draw.
void SetLineStyle(int s)
Set histogram line style.
TLegendEntry * AddBandLegendEntry(TObject *obj, const std::string &label, const std::string &options)
Add band legend entry, creating unused extra entries if necessary.
bool GetGridx() const
bool fLogy
Flag for controlling log plotting of y axis.
TLegend fLegend
Legend.
bool fDrawStats
Flag for drawing stats box.