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  if (!histoNamesReady) {
55  histoNamesReady = true;
56  histoNames_ = iGetter.getMEs();
57  }
58  std::vector<const std::string *> res;
59  std::size_t nsize = name.size();
60 
61  for (const auto &histoName : histoNames_) {
62  std::size_t lsize = histoName.size();
63  if ((lsize >= nsize) && (histoName.find(name) == (lsize - nsize))) {
64  res.push_back(&histoName);
65  }
66  }
67  if (res.empty()) {
68  std::ostringstream oss;
69  oss << "Histogram " << name << " not found in " << outputInternalPath_;
70  char sep = ':';
71  for (auto const &histoName : histoNames_) {
72  oss << sep << ' ' << histoName;
73  sep = ',';
74  }
75  oss << '.';
76  edm::LogWarning("ElectronDqmHarvesterBase::find") << oss.str();
77  return nullptr;
78  } else if (res.size() > 1) {
79  std::ostringstream oss;
80  oss << "Ambiguous histograms for " << name << " in " << outputInternalPath_;
81  char sep = ':';
82  for (auto const resItr : res) {
83  oss << sep << ' ' << *resItr;
84  sep = ',';
85  }
86  oss << '.';
87  edm::LogWarning("ElectronDqmHarvesterBase::find") << oss.str();
88  return nullptr;
89  }
90  return res[0];
91 }
92 
94 
96  DQMStore::IGetter &iGetter,
97  edm::LuminosityBlock const &,
98  edm::EventSetup const &) {
99  if (finalStep_ == "AtLumiEnd") {
100  if (finalDone_) {
101  edm::LogWarning("ElectronDqmHarvesterBase::endLuminosityBlock") << "finalize() already called";
102  }
104  finalDone_ = true;
105  }
106 }
107 
109  if (finalStep_ == "AtJobEnd") {
110  if (finalDone_) {
111  edm::LogWarning("ElectronDqmHarvesterBase::dqmEndJob") << "finalize() already called";
112  }
114  finalDone_ = true;
115  }
117  finalize(iBooker, iGetter);
118 }
119 
121  const std::string &name) {
122  const std::string *fullName = find(iGetter, name);
123  if (fullName) {
124  return iGetter.get(inputInternalPath_ + "/" + *fullName);
125  } else {
126  return nullptr;
127  }
128 }
129 
131  // TODO: remove no longer supported in DQMStore.
132 }
133 
135  DQMStore::IGetter &iGetter,
136  const std::string &name,
137  const std::string &num,
138  const std::string &denom,
139  const std::string &titleX,
140  const std::string &titleY,
141  const std::string &title) {
142  return bookH1andDivide(iBooker, iGetter, name, get(iGetter, num), get(iGetter, denom), titleX, titleY, title);
143 }
144 
146  DQMStore::IGetter &iGetter,
147  const std::string &name,
148  const std::string &num,
149  const std::string &denom,
150  const std::string &titleX,
151  const std::string &titleY,
152  const std::string &title) {
153  return bookH2andDivide(iBooker, iGetter, name, get(iGetter, num), get(iGetter, denom), titleX, titleY, title);
154 }
155 
157  DQMStore::IGetter &iGetter,
158  const std::string &clone,
159  const std::string &original,
160  const std::string &title) {
161  return cloneH1(iBooker, iGetter, clone, get(iGetter, original), title);
162 }
163 
165  DQMStore::IGetter &iGetter,
166  const std::string &me2d,
167  const std::string &title,
168  const std::string &titleX,
169  const std::string &titleY,
170  Double_t minimum,
171  Double_t maximum) {
172  return profileX(iBooker, iGetter, get(iGetter, me2d), title, titleX, titleY, minimum, maximum);
173 }
174 
176  DQMStore::IGetter &iGetter,
177  const std::string &me2d,
178  const std::string &title,
179  const std::string &titleX,
180  const std::string &titleY,
181  Double_t minimum,
182  Double_t maximum) {
183  return profileY(iBooker, iGetter, get(iGetter, me2d), title, titleX, titleY, minimum, maximum);
184 }
185 
187  const std::string &name,
188  const std::string &title,
189  int nchX,
190  double lowX,
191  double highX,
192  const std::string &titleX,
193  const std::string &titleY,
194  Option_t *option) {
196  MonitorElement *me = iBooker.book1D(newName(name), title, nchX, lowX, highX);
197  if (!titleX.empty()) {
198  me->setAxisTitle(titleX);
199  }
200  if (!titleY.empty()) {
201  me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str());
202  }
203  if (TString(option) != "") {
204  me->setOption(option);
205  }
206  if (bookStatOverflowFlag_) {
207  me->setStatOverflows(kTRUE);
208  }
209  return me;
210 }
211 
213  const std::string &name,
214  const std::string &title,
215  int nchX,
216  double lowX,
217  double highX,
218  const std::string &titleX,
219  const std::string &titleY,
220  Option_t *option) {
222  MonitorElement *me = iBooker.book1D(newName(name), title, nchX, lowX, highX);
223  me->enableSumw2();
224  if (!titleX.empty()) {
225  me->setAxisTitle(titleX);
226  }
227  if (!titleY.empty()) {
228  me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str());
229  }
230  if (TString(option) != "") {
231  me->setOption(option);
232  }
233  if (bookStatOverflowFlag_) {
234  me->getTH1F()->StatOverflows(kTRUE);
235  }
236  return me;
237 }
238 
240  const std::string &name,
241  const std::string &title,
242  int nchX,
243  double lowX,
244  double highX,
245  int nchY,
246  double lowY,
247  double highY,
248  const std::string &titleX,
249  const std::string &titleY,
250  Option_t *option) {
252  MonitorElement *me = iBooker.book2D(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
253  if (!titleX.empty()) {
254  me->setAxisTitle(titleX);
255  }
256  if (!titleY.empty()) {
257  me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str());
258  }
259  if (TString(option) != "") {
260  me->setOption(option);
261  }
262  if (bookStatOverflowFlag_) {
263  me->getTH1F()->StatOverflows(kTRUE);
264  }
265  return me;
266 }
267 
269  const std::string &name,
270  const std::string &title,
271  int nchX,
272  double lowX,
273  double highX,
274  int nchY,
275  double lowY,
276  double highY,
277  const std::string &titleX,
278  const std::string &titleY,
279  Option_t *option) {
281  MonitorElement *me = iBooker.book2D(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
282  me->enableSumw2();
283  if (!titleX.empty()) {
284  me->setAxisTitle(titleX);
285  }
286  if (!titleY.empty()) {
287  me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str());
288  }
289  if (TString(option) != "") {
290  me->setOption(option);
291  }
292  if (bookStatOverflowFlag_) {
293  me->getTH1F()->StatOverflows(kTRUE);
294  }
295  return me;
296 }
297 
299  const std::string &name,
300  const std::string &title,
301  int nchX,
302  double lowX,
303  double highX,
304  double lowY,
305  double highY,
306  const std::string &titleX,
307  const std::string &titleY,
308  Option_t *option) {
310  MonitorElement *me = iBooker.bookProfile(newName(name), title, nchX, lowX, highX, lowY, highY, " ");
311  if (!titleX.empty()) {
312  me->getTProfile()->GetXaxis()->SetTitle(titleX.c_str());
313  }
314  if (!titleY.empty()) {
315  me->getTProfile()->GetYaxis()->SetTitle(titleY.c_str());
316  }
317  if (TString(option) != "") {
318  me->getTProfile()->SetOption(option);
319  }
320  if (bookStatOverflowFlag_) {
321  me->getTH1F()->StatOverflows(kTRUE);
322  }
323  return me;
324 }
325 
327  DQMStore::IGetter &iGetter,
328  const std::string &name,
331  const std::string &titleX,
332  const std::string &titleY,
333  const std::string &title) {
334  if ((!num) || (!denom))
335  return nullptr;
338  TH1F *h_temp = (TH1F *)num->getTH1F()->Clone(name2.c_str());
339  h_temp->Reset();
340  h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
341  h_temp->GetXaxis()->SetTitle(titleX.c_str());
342  h_temp->GetYaxis()->SetTitle(titleY.c_str());
343  if (!title.empty()) {
344  h_temp->SetTitle(title.c_str());
345  }
346  if (verbosity_ > 0) {
347  h_temp->Print();
348  }
349  MonitorElement *me = iBooker.book1D(name2, h_temp);
350  if (bookEfficiencyFlag_) {
351  me->setEfficiencyFlag();
352  }
353  delete h_temp;
354  return me;
355 }
356 
358  DQMStore::IGetter &iGetter,
359  const std::string &name,
362  const std::string &titleX,
363  const std::string &titleY,
364  const std::string &title) {
365  if ((!num) || (!denom))
366  return nullptr;
369  TH2F *h_temp = (TH2F *)num->getTH2F()->Clone(name2.c_str());
370  h_temp->Reset();
371  h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
372  h_temp->GetXaxis()->SetTitle(titleX.c_str());
373  h_temp->GetYaxis()->SetTitle(titleY.c_str());
374  if (!title.empty()) {
375  h_temp->SetTitle(title.c_str());
376  }
377  if (verbosity_ > 0) {
378  h_temp->Print();
379  }
380  MonitorElement *me = iBooker.book2D(name2, h_temp);
381  if (bookEfficiencyFlag_) {
382  me->setEfficiencyFlag();
383  }
384  delete h_temp;
385  return me;
386 }
387 
389  DQMStore::IGetter &iGetter,
390  const std::string &name,
392  const std::string &title) {
393  if (!original)
394  return nullptr;
397  TH1F *h_temp = (TH1F *)original->getTH1F()->Clone(name2.c_str());
398  h_temp->Reset();
399  if (!title.empty()) {
400  h_temp->SetTitle(title.c_str());
401  }
402  MonitorElement *me = iBooker.book1D(name2, h_temp);
403  delete h_temp;
404  return me;
405 }
406 
408  DQMStore::IGetter &iGetter,
409  MonitorElement *me2d,
410  const std::string &title,
411  const std::string &titleX,
412  const std::string &titleY,
413  Double_t minimum,
414  Double_t maximum) {
416  std::string name2 = me2d->getName() + "_pfx";
417  TProfile *p1_temp = me2d->getTH2F()->ProfileX();
418  if (!title.empty()) {
419  p1_temp->SetTitle(title.c_str());
420  }
421  if (!titleX.empty()) {
422  p1_temp->GetXaxis()->SetTitle(titleX.c_str());
423  }
424  if (!titleY.empty()) {
425  p1_temp->GetYaxis()->SetTitle(titleY.c_str());
426  }
427  if (minimum != -1111) {
428  p1_temp->SetMinimum(minimum);
429  }
430  if (maximum != -1111) {
431  p1_temp->SetMaximum(maximum);
432  }
433  MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
434  delete p1_temp;
435  return me;
436 }
437 
439  DQMStore::IGetter &iGetter,
440  MonitorElement *me2d,
441  const std::string &title,
442  const std::string &titleX,
443  const std::string &titleY,
444  Double_t minimum,
445  Double_t maximum) {
447  std::string name2 = me2d->getName() + "_pfy";
448  TProfile *p1_temp = me2d->getTH2F()->ProfileY();
449  if (!title.empty()) {
450  p1_temp->SetTitle(title.c_str());
451  }
452  if (!titleX.empty()) {
453  p1_temp->GetXaxis()->SetTitle(titleX.c_str());
454  }
455  if (!titleY.empty()) {
456  p1_temp->GetYaxis()->SetTitle(titleY.c_str());
457  }
458  if (minimum != -1111) {
459  p1_temp->SetMinimum(minimum);
460  }
461  if (maximum != -1111) {
462  p1_temp->SetMaximum(maximum);
463  }
464  MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
465  delete p1_temp;
466  return me;
467 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
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 std::vector< std::string > getMEs() const
Definition: DQMStore.cc:737
void setBookPrefix(const std::string &)
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="")
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
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 &)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
void setBookEfficiencyFlag(const bool &)
MonitorElement * cloneH1(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, MonitorElement *original, const std::string &title="")
MonitorElement * cloneH1(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, const std::string &original, const std::string &title="")
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:690
const std::string & getName() const
get name of ME
std::vector< std::string > histoNames_
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")
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::string newName(const std::string &name)
ElectronDqmHarvesterBase(const edm::ParameterSet &conf)
virtual void finalize(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override