BCAux.h
1 #ifndef __BCAUX__H
2 #define __BCAUX__H
3 
15 /*
16  * Copyright (C) 2007-2018, the BAT core developer team
17  * All rights reserved.
18  *
19  * For the licensing terms see doc/COPYING.
20  * For documentation see http://mpp.mpg.de/bat
21  */
22 
23 // ---------------------------------------------------------
24 
25 #include <string>
26 
27 #include "BCH1D.h"
28 #include "BCH2D.h"
29 
30 #include <TROOT.h>
31 
32 class TH2;
33 
34 // ---------------------------------------------------------
35 
36 namespace BCAux
37 {
38 
43 template <typename T>
44 class BCTrash
45 {
46 public:
48  BCTrash() {}
49  BCTrash(const BCTrash<T>&) {}
50  BCTrash<T>& operator=(const BCTrash<T>&)
51  {
52  return *this;
53  }
54 
55  ~BCTrash()
56  {
57  for (unsigned i = 0; i < fStorage.size(); ++i)
58  delete fStorage[i];
59  }
60 
61  void Put(T* object)
62  {
63  fStorage.push_back(object);
64  }
66 
67 private:
68  std::vector<T*> fStorage;
69 };
70 
73 void SetStyle();
74 
78 void DefaultToPDF(std::string& filename);
79 
85 TH2* Transpose(const TH2* const h, const std::string& name = "");
86 
88 enum BCRange {
95 };
96 
102 BCAux::BCRange RangeType(double xmin, double xmax);
103 
108 void MakeFinite(double& xmin, double& xmax);
109 
112 std::string SafeName(const std::string& name);
113 
116 bool AllowedCharacter(char c);
117 
123 };
124 
131 
138 
145 void DrawKnowledgeUpdate(BCHistogramBase& prior, BCHistogramBase& posterior, bool draw_prior_first, BCTrash<TObject>& trash);
146 
155 unsigned PrintPlots(std::vector<BCH1D>& h1, std::vector<BCH2D>& h2, const std::string& filename, unsigned hdiv = 1, unsigned vdiv = 1);
156 
172 {
173 public:
176 
177 private:
178  // not implemented
180  RootSideEffectGuard& operator=(const RootSideEffectGuard&);
181 
182  TDirectory* fDirectory;
183 };
184 
188 template <class T>
189 T* OwnClone(const T* o)
190 {
191  return static_cast<T*>(gROOT->CloneObject(o, false));
192 }
193 
197 template <class T>
198 T* OwnClone(const T* o, const std::string& name)
199 {
200  T* res = OwnClone(o);
201  res->SetName(name.c_str());
202  return res;
203 }
204 
205 }
206 
207 // ---------------------------------------------------------
208 
209 #endif
Posterior drawn with detailed info, prior drawn as overlaid line.
Definition: BCAux.h:121
void DrawKnowledgeUpdate(BCHistogramBase &prior, BCHistogramBase &posterior, bool draw_prior_first, BCTrash< TObject > &trash)
Draw knowledge update plot into current TPad.
Definition: BCAux.cxx:236
void MakeFinite(double &xmin, double &xmax)
Make an infinite range finite by setting inf values to max.
Definition: BCAux.cxx:102
T * OwnClone(const T *o)
Create a clone of the input but avoid registering the object with ROOT so it cannot be deleted twice...
Definition: BCAux.h:189
A trash to keep heap-allocated objects of type T alive until the trash goes out of scope...
Definition: BCAux.h:44
BCRange
Range types.
Definition: BCAux.h:88
A guard object to prevent ROOT from taking over ownership of TNamed objects.
Definition: BCAux.h:171
unsigned PrintPlots(std::vector< BCH1D > &h1, std::vector< BCH2D > &h2, const std::string &filename, unsigned hdiv=1, unsigned vdiv=1)
Print plots.
Definition: BCAux.cxx:339
A class for handling 2D distributions.
Definition: BCH2D.h:37
BCAux::BCRange RangeType(double xmin, double xmax)
Return type of range as a BCAux::BCRange enum.
Definition: BCAux.cxx:85
TH2 * Transpose(const TH2 *const h, const std::string &name="")
Transpose a TH2.
Definition: BCAux.cxx:55
Prior drawn with detailed info, posterior drawn as overlaid line.
Definition: BCAux.h:122
std::string SafeName(const std::string &name)
Convert a name into a safe name for use in ROOT object naming.
Definition: BCAux.cxx:111
void SetStyle()
Definition: BCAux.cxx:30
A base class for drawing histograms in BAT style.
lower < upper, lower limit finite, upper limit infinite
Definition: BCAux.h:91
void SetKnowledgeUpdateDrawingStyle(BCH1D &prior, BCH1D &posterior, BCAux::BCKnowledgeUpdateDrawingStyle style=BCAux::kKnowledgeUpdateDefaultStyle)
Use pre-made drawing options for knowledge update plots.
Definition: BCAux.cxx:132
BCKnowledgeUpdateDrawingStyle
An enumerator for the knowledge update drawing style presets.
Definition: BCAux.h:119
Simple line-drawn histograms.
Definition: BCAux.h:120
A class for handling 1D distributions.
Definition: BCH1D.h:34
void DefaultToPDF(std::string &filename)
Force file extension to be .pdf if not already .pdf or .ps.
Definition: BCAux.cxx:36
lower > upper
Definition: BCAux.h:94
lower limit == upper limit
Definition: BCAux.h:93
lower < upper, lower and upper limits finite
Definition: BCAux.h:89
lower < upper, lower limit infinite, upper limit finite
Definition: BCAux.h:90
bool AllowedCharacter(char c)
Definition: BCAux.cxx:119
lower < upper, lower and upper limits infinite
Definition: BCAux.h:92
Some functions not fitting anywhere else.