CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronDqmHarvesterBase.cc
Go to the documentation of this file.
1 
3 //#include "DQMServices/Core/interface/DQMStore.h"
8 #include "TMath.h"
9 #include "TFile.h"
10 #include "TH1F.h"
11 #include "TH1I.h"
12 #include "TH2F.h"
13 #include "TProfile.h"
14 #include "TTree.h"
15 #include <iostream>
16 #include <algorithm>
17 #include <sstream>
18 
20  : bookPrefix_("ele"), bookIndex_(0), histoNamesReady(false), finalDone_(false)
21  {
22  verbosity_ = conf.getUntrackedParameter<int>("Verbosity") ;
23  finalStep_ = conf.getParameter<std::string>("FinalStep") ;
24  inputFile_ = conf.getParameter<std::string>("InputFile") ;
25  outputFile_ = conf.getParameter<std::string>("OutputFile") ;
26  inputInternalPath_ = conf.getParameter<std::string>("InputFolderName") ;
27  outputInternalPath_ = conf.getParameter<std::string>("OutputFolderName") ;
28  }
29 
31  {
32  }
33 
35  { bookPrefix_ = prefix ; }
36 
38  { bookIndex_ = index ; }
39 
41  { bookEfficiencyFlag_ = eff_flag ;}
42 
43 void ElectronDqmHarvesterBase::setBookStatOverflowFlag( const bool & statOverflow_flag )
44  { bookStatOverflowFlag_ = statOverflow_flag ;}
45 
47  {
48  if (bookPrefix_.empty())
49  { return name ; }
50  std::ostringstream oss ;
51  oss<<bookPrefix_ ;
52  if (bookIndex_>=0)
53  { oss<<bookIndex_++ ; }
54  oss<<"_"<<name ;
55  return oss.str() ;
56  }
57 
59  {
60  typedef std::vector<std::string> HistoNames ;
61  typedef HistoNames::iterator HistoNamesItr ;
62  if (!histoNamesReady)
63  { histoNamesReady = true ; histoNames_ = iGetter.getMEs() ; }
64  HistoNamesItr histoName ;
65  std::vector<HistoNamesItr> res ;
66 
67  for ( histoName = histoNames_.begin() ; histoName != histoNames_.end() ; ++histoName )
68  {
69  std::size_t nsize = name.size(), lsize = histoName->size() ;
70  if ( (lsize>=nsize) &&
71  (histoName->find(name)==(lsize-nsize)) )
72  { res.push_back(histoName) ; }
73  }
74  if (res.size()==0)
75  {
76  std::ostringstream oss ;
77  oss<<"Histogram "<<name<<" not found in "<<outputInternalPath_ ;
78  char sep = ':' ;
79  for ( histoName = histoNames_.begin() ; histoName != histoNames_.end() ; ++histoName )
80  { oss<<sep<<' '<<*histoName ; sep = ',' ; }
81  oss<<'.' ;
82  edm::LogWarning("ElectronDqmHarvesterBase::find")<<oss.str() ;
83  return 0 ;
84  }
85  else if (res.size()>1)
86  {
87  std::ostringstream oss ;
88  oss<<"Ambiguous histograms for "<<name<<" in "<<outputInternalPath_ ;
89  char sep = ':' ;
90  std::vector<HistoNamesItr>::iterator resItr ;
91  for ( resItr = res.begin() ; resItr != res.end() ; ++resItr )
92  { oss<<sep<<' '<<(**resItr) ; sep = ',' ; }
93  oss<<'.' ;
94  edm::LogWarning("ElectronDqmHarvesterBase::find")<<oss.str() ;
95  return 0 ;
96  }
97  else
98  {
99  return &*res[0] ;
100  }
101  }
102 
104  {
105  }
106 
108  {
109  if (finalStep_=="AtLumiEnd")
110  {
111  if (finalDone_)
112  {
113  edm::LogWarning("ElectronDqmHarvesterBase::endLuminosityBlock")<<"finalize() already called" ;
114  }
116  finalDone_ = true ;
117  }
118 
119  }
120 
122  {
123 
124  if (finalStep_=="AtJobEnd")
125  {
126  if (finalDone_)
127  { edm::LogWarning("ElectronDqmHarvesterBase::dqmEndJob")<<"finalize() already called" ; }
129  finalDone_ = true ;
130  }
132  finalize( iBooker, iGetter ) ;
133 
134  }
135 
137  {
138  const std::string * fullName = find(iGetter, name) ;
139  if (fullName)
140  { return iGetter.get(inputInternalPath_+"/"+*fullName) ; }
141  else
142  { return 0 ; }
143  }
144 
146  {
147  const std::string * fullName = find(iGetter, name) ;
148  if (fullName)
149  {
151  iGetter.removeElement(*fullName) ;
152  }
153  }
154 
156  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
157  const std::string & name, const std::string & num, const std::string & denom,
158  const std::string & titleX, const std::string & titleY,
159  const std::string & title )
160  {
161  return bookH1andDivide(iBooker, iGetter, name,get(iGetter, num),get(iGetter, denom),titleX,titleY,title) ;
162  }
163 
165  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
166  const std::string & name, const std::string & num, const std::string & denom,
167  const std::string & titleX, const std::string & titleY,
168  const std::string & title )
169  { return bookH2andDivide(iBooker, iGetter, name,get(iGetter, num),get(iGetter, denom),titleX,titleY,title) ; }
170 
172  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
173  const std::string & clone, const std::string & original,
174  const std::string & title )
175  { return cloneH1(iBooker, iGetter, clone,get(iGetter, original),title) ; }
176 
178  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
179  const std::string & me2d,
180  const std::string & title, const std::string & titleX, const std::string & titleY,
181  Double_t minimum, Double_t maximum )
182  { return profileX(iBooker, iGetter, get(iGetter, me2d),title,titleX,titleY,minimum,maximum) ; }
183 
185  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
186  const std::string & me2d,
187  const std::string & title, const std::string & titleX, const std::string & titleY,
188  Double_t minimum, Double_t maximum )
189  { return profileY(iBooker, iGetter, get(iGetter, me2d),title,titleX,titleY,minimum,maximum) ; }
190 
192  ( DQMStore::IBooker & iBooker, const std::string & name, const std::string & title,
193  int nchX, double lowX, double highX,
194  const std::string & titleX, const std::string & titleY,
195  Option_t * option )
196  {
197  iBooker.setCurrentFolder(outputInternalPath_);
198  MonitorElement * me = iBooker.book1D(newName(name),title,nchX,lowX,highX) ;
199  if (titleX!="") { me->getTH1F()->GetXaxis()->SetTitle(titleX.c_str()) ; }
200  if (titleY!="") { me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str()) ; }
201  if (TString(option)!="") { me->getTH1F()->SetOption(option) ; }
202  if (bookStatOverflowFlag_) {me->getTH1F()->StatOverflows(kTRUE) ; }
203  return me ;
204  }
205 
207  ( DQMStore::IBooker & iBooker, const std::string & name, const std::string & title,
208  int nchX, double lowX, double highX,
209  const std::string & titleX, const std::string & titleY,
210  Option_t * option )
211  {
212  iBooker.setCurrentFolder(outputInternalPath_);
213  MonitorElement * me = iBooker.book1D(newName(name),title,nchX,lowX,highX) ;
214  me->getTH1F()->Sumw2() ;
215  if (titleX!="") { me->getTH1F()->GetXaxis()->SetTitle(titleX.c_str()) ; }
216  if (titleY!="") { me->getTH1F()->GetYaxis()->SetTitle(titleY.c_str()) ; }
217  if (TString(option)!="") { me->getTH1F()->SetOption(option) ; }
218  if (bookStatOverflowFlag_) {me->getTH1F()->StatOverflows(kTRUE) ; }
219  return me ;
220  }
221 
223  ( DQMStore::IBooker & iBooker, const std::string & name, const std::string & title,
224  int nchX, double lowX, double highX,
225  int nchY, double lowY, double highY,
226  const std::string & titleX, const std::string & titleY,
227  Option_t * option )
228  {
229  iBooker.setCurrentFolder(outputInternalPath_);
230  MonitorElement * me = iBooker.book2D(newName(name),title,nchX,lowX,highX,nchY,lowY,highY) ;
231  if (titleX!="") { me->getTH2F()->GetXaxis()->SetTitle(titleX.c_str()) ; }
232  if (titleY!="") { me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str()) ; }
233  if (TString(option)!="") { me->getTH2F()->SetOption(option) ; }
234  if (bookStatOverflowFlag_) {me->getTH1F()->StatOverflows(kTRUE) ; }
235  return me ;
236  }
237 
239  ( DQMStore::IBooker & iBooker, const std::string & name, const std::string & title,
240  int nchX, double lowX, double highX,
241  int nchY, double lowY, double highY,
242  const std::string & titleX, const std::string & titleY,
243  Option_t * option )
244  {
245  iBooker.setCurrentFolder(outputInternalPath_);
246  MonitorElement * me = iBooker.book2D(newName(name),title,nchX,lowX,highX,nchY,lowY,highY) ;
247  me->getTH2F()->Sumw2() ;
248  if (titleX!="") { me->getTH2F()->GetXaxis()->SetTitle(titleX.c_str()) ; }
249  if (titleY!="") { me->getTH2F()->GetYaxis()->SetTitle(titleY.c_str()) ; }
250  if (TString(option)!="") { me->getTH2F()->SetOption(option) ; }
251  if (bookStatOverflowFlag_) {me->getTH1F()->StatOverflows(kTRUE) ; }
252  return me ;
253  }
254 
256  ( DQMStore::IBooker & iBooker, const std::string & name, const std::string & title,
257  int nchX, double lowX, double highX,
258  double lowY, double highY,
259  const std::string & titleX, const std::string & titleY,
260  Option_t * option )
261  {
262  iBooker.setCurrentFolder(outputInternalPath_);
263  MonitorElement * me = iBooker.bookProfile(newName(name),title,nchX,lowX,highX,lowY,highY," ") ;
264  if (titleX!="") { me->getTProfile()->GetXaxis()->SetTitle(titleX.c_str()) ; }
265  if (titleY!="") { me->getTProfile()->GetYaxis()->SetTitle(titleY.c_str()) ; }
266  if (TString(option)!="") { me->getTProfile()->SetOption(option) ; }
267  if (bookStatOverflowFlag_) {me->getTH1F()->StatOverflows(kTRUE) ; }
268  return me ;
269  }
270 
272  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
273  const std::string & name, MonitorElement * num, MonitorElement * denom,
274  const std::string & titleX, const std::string & titleY,
275  const std::string & title )
276  {
277  if ((!num)||(!denom)) return 0 ;
278  iBooker.setCurrentFolder(outputInternalPath_);
279  std::string name2 = newName(name) ;
280  TH1F * h_temp = (TH1F *)num->getTH1F()->Clone(name2.c_str()) ;
281  h_temp->Reset() ;
282  h_temp->Divide(num->getTH1(),denom->getTH1(),1,1,"b") ;
283  h_temp->GetXaxis()->SetTitle(titleX.c_str()) ;
284  h_temp->GetYaxis()->SetTitle(titleY.c_str()) ;
285  if (title!="") { h_temp->SetTitle(title.c_str()) ; }
286  if (verbosity_>0) { h_temp->Print() ; }
287  MonitorElement * me = iBooker.book1D(name2,h_temp) ;
288  if (bookEfficiencyFlag_) { me->setEfficiencyFlag(); }
289  delete h_temp ;
290  return me ;
291  }
292 
294  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
295  const std::string & name, MonitorElement * num, MonitorElement * denom,
296  const std::string & titleX, const std::string & titleY,
297  const std::string & title )
298  {
299  if ((!num)||(!denom)) return 0 ;
300  iBooker.setCurrentFolder(outputInternalPath_);
301  std::string name2 = newName(name) ;
302  TH2F * h_temp = (TH2F *)num->getTH2F()->Clone(name2.c_str()) ;
303  h_temp->Reset() ;
304  h_temp->Divide(num->getTH1(),denom->getTH1(),1,1,"b") ;
305  h_temp->GetXaxis()->SetTitle(titleX.c_str()) ;
306  h_temp->GetYaxis()->SetTitle(titleY.c_str()) ;
307  if (title!="") { h_temp->SetTitle(title.c_str()) ; }
308  if (verbosity_>0) { h_temp->Print() ; }
309  MonitorElement * me = iBooker.book2D(name2,h_temp) ;
310  if (bookEfficiencyFlag_) { me->setEfficiencyFlag(); }
311  delete h_temp ;
312  return me ;
313  }
314 
316  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,
317  const std::string & name, MonitorElement * original,
318  const std::string & title )
319  {
320  if (!original) return 0 ;
321  iBooker.setCurrentFolder(outputInternalPath_);
322  std::string name2 = newName(name) ;
323  TH1F * h_temp = (TH1F *)original->getTH1F()->Clone(name2.c_str()) ;
324  h_temp->Reset() ;
325  if (title!="") { h_temp->SetTitle(title.c_str()) ; }
326  MonitorElement * me = iBooker.book1D(name2,h_temp) ;
327  delete h_temp ;
328  return me ;
329  }
330 
332  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter, MonitorElement * me2d,
333  const std::string & title, const std::string & titleX, const std::string & titleY,
334  Double_t minimum, Double_t maximum )
335  {
336  iBooker.setCurrentFolder(outputInternalPath_);
337  std::string name2 = me2d->getName()+"_pfx" ;
338  TProfile * p1_temp = me2d->getTH2F()->ProfileX() ;
339  if (title!="") { p1_temp->SetTitle(title.c_str()) ; }
340  if (titleX!="") { p1_temp->GetXaxis()->SetTitle(titleX.c_str()) ; }
341  if (titleY!="") { p1_temp->GetYaxis()->SetTitle(titleY.c_str()) ; }
342  if (minimum!=-1111) { p1_temp->SetMinimum(minimum) ; }
343  if (maximum!=-1111) { p1_temp->SetMaximum(maximum) ; }
344  MonitorElement * me = iBooker.bookProfile(name2,p1_temp) ;
345  delete p1_temp ;
346  return me ;
347  }
348 
350  ( DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter,MonitorElement * me2d,
351  const std::string & title, const std::string & titleX, const std::string & titleY,
352  Double_t minimum, Double_t maximum )
353  {
354  iBooker.setCurrentFolder(outputInternalPath_);
355  std::string name2 = me2d->getName()+"_pfy" ;
356  TProfile * p1_temp = me2d->getTH2F()->ProfileY() ;
357  if (title!="") { p1_temp->SetTitle(title.c_str()) ; }
358  if (titleX!="") { p1_temp->GetXaxis()->SetTitle(titleX.c_str()) ; }
359  if (titleY!="") { p1_temp->GetYaxis()->SetTitle(titleY.c_str()) ; }
360  if (minimum!=-1111) { p1_temp->SetMinimum(minimum) ; }
361  if (maximum!=-1111) { p1_temp->SetMaximum(maximum) ; }
362  MonitorElement * me = iBooker.bookProfile(name2,p1_temp) ;
363  delete p1_temp ;
364  return me ;
365  }
366 
367 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
void remove(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, const std::string &name)
const std::string * find(DQMStore::IGetter &iGetter, const std::string &name)
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
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")
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
void setBookPrefix(const std::string &)
list original
Definition: definitions.py:57
MonitorElement * cloneH1(DQMStore::IBooker &iBooker, DQMStore::IGetter &, const std::string &name, MonitorElement *original, const std::string &title="")
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 setBookStatOverflowFlag(const bool &)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
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")
TH1 * getTH1(void) const
void setBookEfficiencyFlag(const bool &)
std::vector< std::string > getMEs(void)
Definition: DQMStore.cc:310
tuple conf
Definition: dbtoconf.py:185
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")
string fullName
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
TH1F * getTH1F(void) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
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 * 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")
std::vector< std::string > histoNames_
TProfile * getTProfile(void) const
void setEfficiencyFlag(void)
volatile std::atomic< bool > shutdown_flag false
MonitorElement * get(DQMStore::IGetter &iGetter, const std::string &name)
TH2F * getTH2F(void) const
void removeElement(Args &&...args)
Definition: DQMStore.h:202
std::string newName(const std::string &name)
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")
ElectronDqmHarvesterBase(const edm::ParameterSet &conf)
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)
virtual void finalize(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
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="")