CMS 3D CMS Logo

ElectronDqmHarvesterBase.cc
Go to the documentation of this file.
1 
3 //#include "DQMServices/Core/interface/DQMStore.h"
7 #include "TMath.h"
8 #include "TFile.h"
9 #include "TH1F.h"
10 #include "TH1I.h"
11 #include "TH2F.h"
12 #include "TProfile.h"
13 #include "TTree.h"
14 #include <iostream>
15 #include <algorithm>
16 #include <sstream>
17 
19  : bookPrefix_("ele"), bookIndex_(0), histoNamesReady(false), finalDone_(false) {
20  verbosity_ = conf.getUntrackedParameter<int>("Verbosity");
21  finalStep_ = conf.getParameter<std::string>("FinalStep");
22  inputFile_ = conf.getParameter<std::string>("InputFile");
23  outputFile_ = conf.getParameter<std::string>("OutputFile");
24  inputInternalPath_ = conf.getParameter<std::string>("InputFolderName");
25  outputInternalPath_ = conf.getParameter<std::string>("OutputFolderName");
26 }
27 
29 
31 
33 
34 void ElectronDqmHarvesterBase::setBookEfficiencyFlag(const bool &eff_flag) { bookEfficiencyFlag_ = eff_flag; }
35 
36 void ElectronDqmHarvesterBase::setBookStatOverflowFlag(const bool &statOverflow_flag) {
37  bookStatOverflowFlag_ = statOverflow_flag;
38 }
39 
41  if (bookPrefix_.empty()) {
42  return name;
43  }
44  std::ostringstream oss;
45  oss << bookPrefix_;
46  if (bookIndex_ >= 0) {
47  oss << bookIndex_++;
48  }
49  oss << "_" << name;
50  return oss.str();
51 }
52 
54  typedef std::vector<std::string> HistoNames;
55  typedef HistoNames::iterator HistoNamesItr;
56  if (!histoNamesReady) {
57  histoNamesReady = true;
58  histoNames_ = iGetter.getMEs();
59  }
60  HistoNamesItr histoName;
61  std::vector<HistoNamesItr> res;
62 
63  for (histoName = histoNames_.begin(); histoName != histoNames_.end(); ++histoName) {
64  std::size_t nsize = name.size(), lsize = histoName->size();
65  if ((lsize >= nsize) && (histoName->find(name) == (lsize - nsize))) {
66  res.push_back(histoName);
67  }
68  }
69  if (res.empty()) {
70  std::ostringstream oss;
71  oss << "Histogram " << name << " not found in " << outputInternalPath_;
72  char sep = ':';
73  for (histoName = histoNames_.begin(); histoName != histoNames_.end(); ++histoName) {
74  oss << sep << ' ' << *histoName;
75  sep = ',';
76  }
77  oss << '.';
78  edm::LogWarning("ElectronDqmHarvesterBase::find") << oss.str();
79  return nullptr;
80  } else if (res.size() > 1) {
81  std::ostringstream oss;
82  oss << "Ambiguous histograms for " << name << " in " << outputInternalPath_;
83  char sep = ':';
84  std::vector<HistoNamesItr>::iterator resItr;
85  for (resItr = res.begin(); resItr != res.end(); ++resItr) {
86  oss << sep << ' ' << (**resItr);
87  sep = ',';
88  }
89  oss << '.';
90  edm::LogWarning("ElectronDqmHarvesterBase::find") << oss.str();
91  return nullptr;
92  } else {
93  return &*res[0];
94  }
95 }
96 
98 
100  DQMStore::IGetter &iGetter,
101  edm::LuminosityBlock const &,
102  edm::EventSetup const &) {
103  if (finalStep_ == "AtLumiEnd") {
104  if (finalDone_) {
105  edm::LogWarning("ElectronDqmHarvesterBase::endLuminosityBlock") << "finalize() already called";
106  }
108  finalDone_ = true;
109  }
110 }
111 
113  if (finalStep_ == "AtJobEnd") {
114  if (finalDone_) {
115  edm::LogWarning("ElectronDqmHarvesterBase::dqmEndJob") << "finalize() already called";
116  }
118  finalDone_ = true;
119  }
121  finalize(iBooker, iGetter);
122 }
123 
125  const std::string &name) {
126  const std::string *fullName = find(iGetter, name);
127  if (fullName) {
128  return iGetter.get(inputInternalPath_ + "/" + *fullName);
129  } else {
130  return nullptr;
131  }
132 }
133 
135  // TODO: remove no longer supported in DQMStore.
136 }
137 
139  DQMStore::IGetter &iGetter,
140  const std::string &name,
141  const std::string &num,
142  const std::string &denom,
143  const std::string &titleX,
144  const std::string &titleY,
145  const std::string &title) {
146  return bookH1andDivide(iBooker, iGetter, name, get(iGetter, num), get(iGetter, denom), titleX, titleY, title);
147 }
148 
150  DQMStore::IGetter &iGetter,
151  const std::string &name,
152  const std::string &num,
153  const std::string &denom,
154  const std::string &titleX,
155  const std::string &titleY,
156  const std::string &title) {
157  return bookH2andDivide(iBooker, iGetter, name, get(iGetter, num), get(iGetter, denom), titleX, titleY, title);
158 }
159 
161  DQMStore::IGetter &iGetter,
162  const std::string &clone,
163  const std::string &original,
164  const std::string &title) {
165  return cloneH1(iBooker, iGetter, clone, get(iGetter, original), title);
166 }
167 
169  DQMStore::IGetter &iGetter,
170  const std::string &me2d,
171  const std::string &title,
172  const std::string &titleX,
173  const std::string &titleY,
174  Double_t minimum,
175  Double_t maximum) {
176  return profileX(iBooker, iGetter, get(iGetter, me2d), title, titleX, titleY, minimum, maximum);
177 }
178 
180  DQMStore::IGetter &iGetter,
181  const std::string &me2d,
182  const std::string &title,
183  const std::string &titleX,
184  const std::string &titleY,
185  Double_t minimum,
186  Double_t maximum) {
187  return profileY(iBooker, iGetter, get(iGetter, me2d), title, titleX, titleY, minimum, maximum);
188 }
189 
191  const std::string &name,
192  const std::string &title,
193  int nchX,
194  double lowX,
195  double highX,
196  const std::string &titleX,
197  const std::string &titleY,
198  Option_t *option) {
200  MonitorElement *me = iBooker.book1D(newName(name), title, nchX, lowX, highX);
201  if (!titleX.empty()) {
202  me->setAxisTitle(titleX);
203  }
204  if (!titleY.empty()) {
205  me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str());
206  }
207  if (TString(option) != "") {
208  me->setOption(option);
209  }
210  if (bookStatOverflowFlag_) {
211  me->getTH1F()->StatOverflows(kTRUE);
212  }
213  return me;
214 }
215 
217  const std::string &name,
218  const std::string &title,
219  int nchX,
220  double lowX,
221  double highX,
222  const std::string &titleX,
223  const std::string &titleY,
224  Option_t *option) {
226  MonitorElement *me = iBooker.book1D(newName(name), title, nchX, lowX, highX);
227  me->enableSumw2();
228  if (!titleX.empty()) {
229  me->setAxisTitle(titleX);
230  }
231  if (!titleY.empty()) {
232  me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str());
233  }
234  if (TString(option) != "") {
235  me->setOption(option);
236  }
237  if (bookStatOverflowFlag_) {
238  me->getTH1F()->StatOverflows(kTRUE);
239  }
240  return me;
241 }
242 
244  const std::string &name,
245  const std::string &title,
246  int nchX,
247  double lowX,
248  double highX,
249  int nchY,
250  double lowY,
251  double highY,
252  const std::string &titleX,
253  const std::string &titleY,
254  Option_t *option) {
256  MonitorElement *me = iBooker.book2D(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
257  if (!titleX.empty()) {
258  me->setAxisTitle(titleX);
259  }
260  if (!titleY.empty()) {
261  me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str());
262  }
263  if (TString(option) != "") {
264  me->setOption(option);
265  }
266  if (bookStatOverflowFlag_) {
267  me->getTH1F()->StatOverflows(kTRUE);
268  }
269  return me;
270 }
271 
273  const std::string &name,
274  const std::string &title,
275  int nchX,
276  double lowX,
277  double highX,
278  int nchY,
279  double lowY,
280  double highY,
281  const std::string &titleX,
282  const std::string &titleY,
283  Option_t *option) {
285  MonitorElement *me = iBooker.book2D(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
286  me->enableSumw2();
287  if (!titleX.empty()) {
288  me->setAxisTitle(titleX);
289  }
290  if (!titleY.empty()) {
291  me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str());
292  }
293  if (TString(option) != "") {
294  me->setOption(option);
295  }
296  if (bookStatOverflowFlag_) {
297  me->getTH1F()->StatOverflows(kTRUE);
298  }
299  return me;
300 }
301 
303  const std::string &name,
304  const std::string &title,
305  int nchX,
306  double lowX,
307  double highX,
308  double lowY,
309  double highY,
310  const std::string &titleX,
311  const std::string &titleY,
312  Option_t *option) {
314  MonitorElement *me = iBooker.bookProfile(newName(name), title, nchX, lowX, highX, lowY, highY, " ");
315  if (!titleX.empty()) {
316  me->getTProfile()->GetXaxis()->SetTitle(titleX.c_str());
317  }
318  if (!titleY.empty()) {
319  me->getTProfile()->GetYaxis()->SetTitle(titleY.c_str());
320  }
321  if (TString(option) != "") {
322  me->getTProfile()->SetOption(option);
323  }
324  if (bookStatOverflowFlag_) {
325  me->getTH1F()->StatOverflows(kTRUE);
326  }
327  return me;
328 }
329 
331  DQMStore::IGetter &iGetter,
332  const std::string &name,
335  const std::string &titleX,
336  const std::string &titleY,
337  const std::string &title) {
338  if ((!num) || (!denom))
339  return nullptr;
341  std::string name2 = newName(name);
342  TH1F *h_temp = (TH1F *)num->getTH1F()->Clone(name2.c_str());
343  h_temp->Reset();
344  h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
345  h_temp->GetXaxis()->SetTitle(titleX.c_str());
346  h_temp->GetYaxis()->SetTitle(titleY.c_str());
347  if (!title.empty()) {
348  h_temp->SetTitle(title.c_str());
349  }
350  if (verbosity_ > 0) {
351  h_temp->Print();
352  }
353  MonitorElement *me = iBooker.book1D(name2, h_temp);
354  if (bookEfficiencyFlag_) {
355  me->setEfficiencyFlag();
356  }
357  delete h_temp;
358  return me;
359 }
360 
362  DQMStore::IGetter &iGetter,
363  const std::string &name,
366  const std::string &titleX,
367  const std::string &titleY,
368  const std::string &title) {
369  if ((!num) || (!denom))
370  return nullptr;
372  std::string name2 = newName(name);
373  TH2F *h_temp = (TH2F *)num->getTH2F()->Clone(name2.c_str());
374  h_temp->Reset();
375  h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
376  h_temp->GetXaxis()->SetTitle(titleX.c_str());
377  h_temp->GetYaxis()->SetTitle(titleY.c_str());
378  if (!title.empty()) {
379  h_temp->SetTitle(title.c_str());
380  }
381  if (verbosity_ > 0) {
382  h_temp->Print();
383  }
384  MonitorElement *me = iBooker.book2D(name2, h_temp);
385  if (bookEfficiencyFlag_) {
386  me->setEfficiencyFlag();
387  }
388  delete h_temp;
389  return me;
390 }
391 
393  DQMStore::IGetter &iGetter,
394  const std::string &name,
396  const std::string &title) {
397  if (!original)
398  return nullptr;
400  std::string name2 = newName(name);
401  TH1F *h_temp = (TH1F *)original->getTH1F()->Clone(name2.c_str());
402  h_temp->Reset();
403  if (!title.empty()) {
404  h_temp->SetTitle(title.c_str());
405  }
406  MonitorElement *me = iBooker.book1D(name2, h_temp);
407  delete h_temp;
408  return me;
409 }
410 
412  DQMStore::IGetter &iGetter,
413  MonitorElement *me2d,
414  const std::string &title,
415  const std::string &titleX,
416  const std::string &titleY,
417  Double_t minimum,
418  Double_t maximum) {
420  std::string name2 = me2d->getName() + "_pfx";
421  TProfile *p1_temp = me2d->getTH2F()->ProfileX();
422  if (!title.empty()) {
423  p1_temp->SetTitle(title.c_str());
424  }
425  if (!titleX.empty()) {
426  p1_temp->GetXaxis()->SetTitle(titleX.c_str());
427  }
428  if (!titleY.empty()) {
429  p1_temp->GetYaxis()->SetTitle(titleY.c_str());
430  }
431  if (minimum != -1111) {
432  p1_temp->SetMinimum(minimum);
433  }
434  if (maximum != -1111) {
435  p1_temp->SetMaximum(maximum);
436  }
437  MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
438  delete p1_temp;
439  return me;
440 }
441 
443  DQMStore::IGetter &iGetter,
444  MonitorElement *me2d,
445  const std::string &title,
446  const std::string &titleX,
447  const std::string &titleY,
448  Double_t minimum,
449  Double_t maximum) {
451  std::string name2 = me2d->getName() + "_pfy";
452  TProfile *p1_temp = me2d->getTH2F()->ProfileY();
453  if (!title.empty()) {
454  p1_temp->SetTitle(title.c_str());
455  }
456  if (!titleX.empty()) {
457  p1_temp->GetXaxis()->SetTitle(titleX.c_str());
458  }
459  if (!titleY.empty()) {
460  p1_temp->GetYaxis()->SetTitle(titleY.c_str());
461  }
462  if (minimum != -1111) {
463  p1_temp->SetMinimum(minimum);
464  }
465  if (maximum != -1111) {
466  p1_temp->SetMaximum(maximum);
467  }
468  MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
469  delete p1_temp;
470  return me;
471 }
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
MonitorElement * profileX(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MonitorElement *me2d, const std::string &title="", const std::string &titleX="", const std::string &titleY="", Double_t minimum=-1111, Double_t maximum=-1111)
void remove(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const std::string &name)
MonitorElement * bookH1withSumw2(DQMStore::IBooker &, const std::string &name, const std::string &title, int nchX, double lowX, double highX, const std::string &titleX="", const std::string &titleY="Events", Option_t *option="E1 P")
MonitorElement * bookH2(DQMStore::IBooker &, const std::string &name, const std::string &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const std::string &titleX="", const std::string &titleY="", Option_t *option="COLZ")
const std::string * find(DQMStore::IGetter &iGetter, const std::string &name)
MonitorElement * bookH1(DQMStore::IBooker &, const std::string &name, const std::string &title, int nchX, double lowX, double highX, const std::string &titleX="", const std::string &titleY="Events", Option_t *option="E1 P")
virtual void setOption(const char *option)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
virtual TH1F * getTH1F() const
void setBookPrefix(const std::string &)
const std::string & getName() const
get name of ME
MonitorElement * get(DQMStore::IGetter &iGetter, const std::string &name)
MonitorElement * bookH2andDivide(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, MonitorElement *num, MonitorElement *denom, const std::string &titleX, const std::string &titleY, const std::string &title="")
Definition: Electron.h:6
MonitorElement * bookH1andDivide(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, MonitorElement *num, MonitorElement *denom, const std::string &titleX, const std::string &titleY, const std::string &title="")
MonitorElement * profileY(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MonitorElement *me2d, const std::string &title="", const std::string &titleX="", const std::string &titleY="", Double_t minimum=-1111, Double_t maximum=-1111)
MonitorElement * bookH2withSumw2(DQMStore::IBooker &, const std::string &name, const std::string &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const std::string &titleX="", const std::string &titleY="", Option_t *option="COLZ")
void setBookStatOverflowFlag(const bool &)
std::vector< std::string > getMEs()
Definition: DQMStore.cc:455
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
void setBookEfficiencyFlag(const bool &)
MonitorElement * cloneH1(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, MonitorElement *original, const std::string &title="")
virtual TProfile * getTProfile() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::vector< std::string > histoNames_
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
MonitorElement * bookP1(DQMStore::IBooker &, const std::string &name, const std::string &title, int nchX, double lowX, double highX, double lowY, double highY, const std::string &titleX="", const std::string &titleY="", Option_t *option="E1 P")
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437
std::string newName(const std::string &name)
virtual TH1 * getTH1() const
ElectronDqmHarvesterBase(const edm::ParameterSet &conf)
virtual void finalize(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)