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