CMS 3D CMS Logo

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