CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTMonElectronConsumer.cc
Go to the documentation of this file.
5 
11 
12 using namespace edm;
13 
15 {
16 
17  LogDebug("HLTMonElectronConsumer") << "constructor...." ;
18 
19  logFile_.open("HLTMonElectronConsumer.log");
20 
21  dbe = NULL;
22  if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
23  dbe = Service < DQMStore > ().operator->();
24  dbe->setVerbose(0);
25  }
26 
27  outputFile_ =
28  iConfig.getUntrackedParameter <std::string>("outputFile", "");
29  if (outputFile_.size() != 0) {
30  LogInfo("HLTMonElectronConsumer") << "L1T Monitoring histograms will be saved to "
31  << outputFile_ ;
32  }
33  else {
34  outputFile_ = "L1TDQM.root";
35  }
36 
37  bool disable =
38  iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
39  if (disable) {
40  outputFile_ = "";
41  }
42 
43  pixeltag_=iConfig.getParameter<edm::InputTag>("PixelTag");
44  isotag_=iConfig.getParameter<edm::InputTag>("IsoTag");
45 
46  dirname_="HLT/HLTMonElectron/"+iConfig.getParameter<std::string>("@module_label");
47  pixeldirname_="HLT/HLTMonElectron/"+pixeltag_.label();
48  isodirname_="HLT/HLTMonElectron/"+isotag_.label();
49 
50  if (dbe != NULL) {
51  dbe->setCurrentFolder(dirname_);
52  }
53 
54 }
55 
56 
58 {
59 
60  // do anything here that needs to be done at desctruction time
61  // (e.g. close files, deallocate resources etc.)
62 
63 }
64 
65 
66 //
67 // member functions
68 //
69 
70 // ------------ method called to for each event ------------
71 void
73 {
74  //total pixelmatch efficiencies from summary histo
75  if(pixeltotal!=NULL){
76  LogInfo("HLTMonElectronConsumer") << " pixelhisto " << pixeltotal->getBinContent(1);
77  if(pixeltotal->getBinContent(1)!=0)
78  pixelEff->Fill(pixeltotal->getBinContent(2)/pixeltotal->getBinContent(1));
79  else
80  pixelEff->Fill(0.);
81 
82  if(pixeltotal->getBinContent(3)!=0)
83  trackEff->Fill(pixeltotal->getBinContent(4)/pixeltotal->getBinContent(3));
84  else
85  trackEff->Fill(0.);
86 
87  // efficiency as kinematic function
88  for(int i =0; i<2 ;i++){
89  TH1F* num;
90  TH1F* denom;
91  num=pixelhistosEt[2*i+1]->getTH1F();
92  denom=pixelhistosEt[2*i]->getTH1F();
93  for(int j=1; j <= pixelhistosEtOut[i]->getNbinsX();j++ ){
94  if(denom->GetBinContent(j)!=0)
95  pixelhistosEtOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
96  else
97  pixelhistosEtOut[i]->setBinContent(j,0.);
98  }
99  num=pixelhistosEta[2*i+1]->getTH1F();
100  denom=pixelhistosEta[2*i]->getTH1F();
101  for(int j=1; j <= pixelhistosEtaOut[i]->getNbinsX();j++ ){
102  if(denom->GetBinContent(j)!=0)
103  pixelhistosEtaOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
104  else
105  pixelhistosEtaOut[i]->setBinContent(j,0.);
106  }
107  num=pixelhistosPhi[2*i+1]->getTH1F();
108  denom=pixelhistosPhi[2*i]->getTH1F();
109  for(int j=1; j <= pixelhistosPhiOut[i]->getNbinsX();j++ ){
110  if(denom->GetBinContent(j)!=0)
111  pixelhistosPhiOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
112  else
113  pixelhistosPhiOut[i]->setBinContent(j,0.);
114  }
115  }
116  }else
117  LogInfo("HLTMonElectronConsumer") << " empty pixelhisto " ;
118 
119  if(isototal!=NULL){
120  TH1F* refhist = isototal->getTH1F();
121  for(int i =1; i<= refhist->GetNbinsX();i++){
122  if(refhist->GetMaximum(i)!=0)
123  isocheck->setBinContent(i,refhist->GetBinContent(i)/refhist->GetMaximum());
124  else
125  isocheck->setBinContent(i,0.);
126  }
127  }else
128  LogInfo("HLTMonElectronConsumer") << " empty isohisto " ;
129 
130 
131 
132 }
133 
134 
135 // ------------ method called once each job just before starting event loop ------------
136 void
138 {
139 
140  DQMStore *dbe = 0;
141  dbe = Service < DQMStore > ().operator->();
142 
143  if (dbe) {
144  dbe->setCurrentFolder(dirname_);
145  dbe->rmdir(dirname_);
146  }
147 
148 
149  if (dbe) {
150  dbe->setCurrentFolder(dirname_);
151 
152 
153  // load pixel MEs
154  std::string tmpname = pixeldirname_ + "/total eff";
155  LogInfo("HLTMonElectronConsumer") << " reading histo: " << tmpname;
156  pixeltotal=dbe->get(tmpname);
157  TH1F* refhist;
158  if(pixeltotal!=0){
159  for(int i = 0; i<4; i++){
160  LogInfo("HLTMonElectronConsumer") << "loop iteration: "<<i ;
161  refhist=pixeltotal->getTH1F();
162  LogInfo("HLTMonElectronConsumer") << "retrieving: " << pixeldirname_ + "/" + refhist->GetXaxis()->GetBinLabel(i+1) + "eta";
163  tmpname = pixeldirname_ + "/" + refhist->GetXaxis()->GetBinLabel(i+1) + "eta";
164  pixelhistosEta[i]=dbe->get(tmpname);
165  tmpname = pixeldirname_ + "/" + refhist->GetXaxis()->GetBinLabel(i+1) + "et";
166  pixelhistosEt[i]=dbe->get(tmpname);
167  tmpname = pixeldirname_ + "/" + refhist->GetXaxis()->GetBinLabel(i+1) + "phi";
168  pixelhistosPhi[i]=dbe->get(tmpname);
169  }
170  LogInfo("HLTMonElectronConsumer") << "Et ";
171  refhist = pixelhistosEt[0]->getTH1F();
172  pixelhistosEtOut[0] =dbe->book1D("pixel eff et","pixel eff et",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
173  pixelhistosEtOut[1] =dbe->book1D("track eff et","track eff et",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
174  LogInfo("HLTMonElectronConsumer") << "Eta ";
175  refhist = pixelhistosEta[0]->getTH1F();
176  pixelhistosEtaOut[0] =dbe->book1D("pixel eff eta","pixel eff eta",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
177  pixelhistosEtaOut[1] =dbe->book1D("track eff eta","track eff eta",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
178  LogInfo("HLTMonElectronConsumer") << "Phi ";
179  refhist = pixelhistosPhi[0]->getTH1F();
180  pixelhistosPhiOut[0] =dbe->book1D("pixel eff phi","pixel eff phi",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
181  pixelhistosPhiOut[1] =dbe->book1D("track eff phi","track eff phi",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
182  }else
183  LogInfo("HLTMonElectronConsumer") << "pixelhisto doesn't exist during beginJob" ;
184 
185  pixelEff=dbe->bookFloat("total pixelmatch");
186  trackEff=dbe->bookFloat("total trackmatch");
187 
188  LogInfo("HLTMonElectronConsumer") << "writing: " << pixelEff->getPathname();
189 
190 
191  tmpname = isodirname_ + "/total eff";
192  LogInfo("HLTMonElectronConsumer") << " reading histo: " << tmpname;
193  isototal=dbe->get(tmpname);
194  refhist = isototal->getTH1F();
195  isocheck = dbe->book1D("consistency check","consistency check",refhist->GetNbinsX(),refhist->GetXaxis()->GetXmin(),refhist->GetXaxis()->GetXmax());
196 
197 
198  } // end "if(dbe)"
199 }
200 
201 // ------------ method called once each job just after ending the event loop ------------
202 void
204 
205 // std::cout << "HLTMonElectronConsumer: end job...." << std::endl;
206 
207  if (outputFile_.size() != 0 && dbe)
208  dbe->save(outputFile_);
209 
210  return;
211 }
212 
213 //DEFINE_FWK_MODULE(HLTMonElectronConsumer);
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2535
#define NULL
Definition: scimark2.h:8
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:659
int iEvent
Definition: GenABIO.cc:243
HLTMonElectronConsumer(const edm::ParameterSet &)
int j
Definition: DBlmapReader.cc:9
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
TH1F * getTH1F(void) const
long long int num
Definition: procUtils.cc:71
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::string const & label() const
Definition: InputTag.h:42
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434