CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RunHistogramManager.h
Go to the documentation of this file.
1 #ifndef DPGAnalysis_SiStripTools_RunHistogramManager_H
2 #define DPGAnalysis_SiStripTools_RunHistogramManager_H
3 
4 #include <vector>
5 #include <map>
6 #include <string>
12 #include "TH2F.h"
13 #include "TProfile2D.h"
14 
15 class TH1F;
16 class TProfile;
17 
19 public:
21  virtual ~BaseHistoParams();
22 
23  // virtual void beginRun(const edm::Run& iRun, TFileDirectory& subrun);
24  virtual void beginRun(const unsigned int irun, TFileDirectory& subrun, const char* fillrun) = 0;
25 };
26 
27 template <class T>
28 class HistoParams : public BaseHistoParams {
29 public:
30  HistoParams(T** pointer,
31  const std::string type,
32  const std::string name,
33  const std::string title,
34  const unsigned int nbinx = -1,
35  const double xmin = -1.,
36  const double xmax = -1.,
37  const unsigned int nbiny = -1,
38  const double ymin = -1.,
39  const double ymax = -1.)
40  : BaseHistoParams(),
41  _pointer(pointer),
42  _type(type),
43  _name(name),
44  _title(title),
45  _nbinx(nbinx),
46  _xmin(xmin),
47  _xmax(xmax),
48  _nbiny(nbiny),
49  _ymin(ymin),
50  _ymax(ymax),
51  _runpointers() {}
52 
53  ~HistoParams() override {
54  delete _pointer;
55  LogDebug("Destructor") << "Destroy " << _name;
56  }
57 
58  void beginRun(const unsigned int irun, TFileDirectory& subrun, const char* fillrun) override {
59  if (_runpointers.find(irun) != _runpointers.end()) {
60  *_pointer = _runpointers[irun];
61  LogDebug("TH1Fbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
62 
63  } else {
64  char title[400];
65  sprintf(title, "%s %s %d", _title.c_str(), fillrun, irun);
66 
67  _runpointers[irun] = subrun.make<T>(_name.c_str(), title, _nbinx, _xmin, _xmax);
68 
69  *_pointer = _runpointers[irun];
70  LogDebug("TH1Fbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
71  }
72  }
73 
74 private:
79  unsigned int _nbinx;
80  double _xmin;
81  double _xmax;
82  unsigned int _nbiny;
83  double _ymin;
84  double _ymax;
85  std::map<unsigned int, T*> _runpointers;
86 };
87 
88 template <>
89 class HistoParams<TH2F> : public BaseHistoParams {
90 public:
91  HistoParams(TH2F** pointer,
92  const std::string type,
93  const std::string name,
94  const std::string title,
95  const unsigned int nbinx = -1,
96  const double xmin = -1.,
97  const double xmax = -1.,
98  const unsigned int nbiny = -1,
99  const double ymin = -1.,
100  const double ymax = -1.)
101  : BaseHistoParams(),
102  _pointer(pointer),
103  _type(type),
104  _name(name),
105  _title(title),
106  _nbinx(nbinx),
107  _xmin(xmin),
108  _xmax(xmax),
109  _nbiny(nbiny),
110  _ymin(ymin),
111  _ymax(ymax),
112  _runpointers() {}
113 
114  ~HistoParams() override {
115  delete _pointer;
116  LogDebug("TH2FDestructor") << "Destroy " << _name;
117  }
118 
119  void beginRun(const unsigned int irun, TFileDirectory& subrun, const char* fillrun) override {
120  if (_runpointers.find(irun) != _runpointers.end()) {
121  *_pointer = _runpointers[irun];
122  LogDebug("TH2Fbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
123 
124  } else {
125  char title[400];
126  sprintf(title, "%s %s %d", _title.c_str(), fillrun, irun);
127 
128  _runpointers[irun] = subrun.make<TH2F>(_name.c_str(), title, _nbinx, _xmin, _xmax, _nbiny, _ymin, _ymax);
129 
130  *_pointer = _runpointers[irun];
131  LogDebug("TH2Fbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
132  }
133  }
134 
135 private:
136  TH2F** _pointer;
140  unsigned int _nbinx;
141  double _xmin;
142  double _xmax;
143  unsigned int _nbiny;
144  double _ymin;
145  double _ymax;
146  std::map<unsigned int, TH2F*> _runpointers;
147 };
148 
149 template <>
150 class HistoParams<TProfile2D> : public BaseHistoParams {
151 public:
152  HistoParams(TProfile2D** pointer,
153  const std::string type,
154  const std::string name,
155  const std::string title,
156  const unsigned int nbinx = -1,
157  const double xmin = -1.,
158  const double xmax = -1.,
159  const unsigned int nbiny = -1,
160  const double ymin = -1.,
161  const double ymax = -1.)
162  : BaseHistoParams(),
163  _pointer(pointer),
164  _type(type),
165  _name(name),
166  _title(title),
167  _nbinx(nbinx),
168  _xmin(xmin),
169  _xmax(xmax),
170  _nbiny(nbiny),
171  _ymin(ymin),
172  _ymax(ymax),
173  _runpointers() {}
174 
175  ~HistoParams() override {
176  delete _pointer;
177  LogDebug("TProfile2DDestructor") << "Destroy " << _name;
178  }
179 
180  void beginRun(const unsigned int irun, TFileDirectory& subrun, const char* fillrun) override {
181  if (_runpointers.find(irun) != _runpointers.end()) {
182  *_pointer = _runpointers[irun];
183  LogDebug("TProfile2Dbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
184 
185  } else {
186  char title[400];
187  sprintf(title, "%s %s %d", _title.c_str(), fillrun, irun);
188 
189  _runpointers[irun] = subrun.make<TProfile2D>(_name.c_str(), title, _nbinx, _xmin, _xmax, _nbiny, _ymin, _ymax);
190 
191  *_pointer = _runpointers[irun];
192  LogDebug("TProfile2Dbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
193  }
194  }
195 
196 private:
197  TProfile2D** _pointer;
201  unsigned int _nbinx;
202  double _xmin;
203  double _xmax;
204  unsigned int _nbiny;
205  double _ymin;
206  double _ymax;
207  std::map<unsigned int, TProfile2D*> _runpointers;
208 };
209 
211 public:
215 
216  TH1F** makeTH1F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax);
217  TProfile** makeTProfile(
218  const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax);
219  TH2F** makeTH2F(const char* name,
220  const char* title,
221  const unsigned int nbinx,
222  const double xmin,
223  const double xmax,
224  const unsigned int nbiny,
225  const double ymin,
226  const double ymax);
227  TProfile2D** makeTProfile2D(const char* name,
228  const char* title,
229  const unsigned int nbinx,
230  const double xmin,
231  const double xmax,
232  const unsigned int nbiny,
233  const double ymin,
234  const double ymax);
235 
236  void beginRun(const edm::Run& iRun);
237  void beginRun(const edm::Run& iRun, TFileDirectory& subdir);
238  void beginRun(const unsigned int irun);
239  void beginRun(const unsigned int irun, TFileDirectory& subdir);
240 
241 private:
243  std::vector<BaseHistoParams*> _histograms;
245 };
246 
247 #endif // DPGAnalysis_SiStripTools_RunHistogramManager_H
edm::EDGetTokenT< edm::ConditionsInRunBlock > _conditionsInRunToken
HistoParams(TProfile2D **pointer, const std::string type, const std::string name, const std::string title, const unsigned int nbinx=-1, const double xmin=-1., const double xmax=-1., const unsigned int nbiny=-1, const double ymin=-1., const double ymax=-1.)
~HistoParams() override
HistoParams(T **pointer, const std::string type, const std::string name, const std::string title, const unsigned int nbinx=-1, const double xmin=-1., const double xmax=-1., const unsigned int nbiny=-1, const double ymin=-1., const double ymax=-1.)
std::string _title
std::map< unsigned int, T * > _runpointers
void beginRun(const unsigned int irun, TFileDirectory &subrun, const char *fillrun) override
void beginRun(const unsigned int irun, TFileDirectory &subrun, const char *fillrun) override
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
RunHistogramManager(edm::ConsumesCollector &&iC, const bool fillHistograms=false)
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
T * make(const Args &...args) const
make new ROOT object
std::vector< BaseHistoParams * > _histograms
HistoParams(TH2F **pointer, const std::string type, const std::string name, const std::string title, const unsigned int nbinx=-1, const double xmin=-1., const double xmax=-1., const unsigned int nbiny=-1, const double ymin=-1., const double ymax=-1.)
std::map< unsigned int, TH2F * > _runpointers
TProfile2D ** makeTProfile2D(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
void beginRun(const edm::Run &iRun)
std::map< unsigned int, TProfile2D * > _runpointers
std::string _type
unsigned int _nbiny
std::string _name
TH2F ** makeTH2F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
long double T
virtual void beginRun(const unsigned int irun, TFileDirectory &subrun, const char *fillrun)=0
Definition: Run.h:45
unsigned int _nbinx
#define LogDebug(id)
void beginRun(const unsigned int irun, TFileDirectory &subrun, const char *fillrun) override