CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EfficiencyPlotter.cc
Go to the documentation of this file.
2 
3 // Framework
10 
11 
16 
17 #include <iostream>
18 #include <stdio.h>
19 #include <string>
20 #include <math.h>
21 #include "TF1.h"
22 #include "TH1F.h"
23 
24 
25 using namespace edm;
26 using namespace std;
27 
28 
30  parameters = ps;
31  theDbe = edm::Service<DQMStore>().operator->();
32 }
34 
36  //metname = "muonRecoTest";
37 
38  metname = "EfficiencyAnalyzer";
39  theDbe->setCurrentFolder("Muons/EfficiencyAnalyzer");
40 
41  LogTrace(metname)<<"[EfficiencyPlotter] beginJob: Parameters initialization";
42 
43  // efficiency plot
44  etaBin = parameters.getParameter<int>("etaBin");
45  etaMin = parameters.getParameter<double>("etaMin");
46  etaMax = parameters.getParameter<double>("etaMax");
47  h_eff_eta_TightMu = theDbe->book1D("Eff_eta_TightMu", "TightMu Efficiency vs #eta", etaBin, etaMin, etaMax);
48  h_eff_hp_eta_TightMu = theDbe->book1D("Eff_hp_eta_TightMu", "High Pt TightMu Efficiency vs #eta", etaBin, etaMin, etaMax);
49 
50  phiBin = parameters.getParameter<int>("phiBin");
51  phiMin = parameters.getParameter<double>("phiMin");
52  phiMax = parameters.getParameter<double>("phiMax");
53  h_eff_phi_TightMu = theDbe->book1D("Eff_phi_TightMu", "TightMu Efficiency vs #phi", phiBin, phiMin, phiMax);
54 
55  ptBin = parameters.getParameter<int>("ptBin");
56  ptMin = parameters.getParameter<double>("ptMin");
57  ptMax = parameters.getParameter<double>("ptMax");
58  h_eff_pt_TightMu = theDbe->book1D("Eff_pt_TightMu", "TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
59  h_eff_pt_barrel_TightMu = theDbe->book1D("Eff_pt_barrel_TightMu", "Barrel: TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
60  h_eff_pt_endcap_TightMu = theDbe->book1D("Eff_pt_endcap_TightMu", "Endcap: TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
61 
62 
63  h_eff_eta_TightMu->setEfficiencyFlag();
64  h_eff_hp_eta_TightMu->setEfficiencyFlag();
65  h_eff_phi_TightMu->setEfficiencyFlag();
66  h_eff_pt_TightMu->setEfficiencyFlag();
67  h_eff_pt_barrel_TightMu->setEfficiencyFlag();
68  h_eff_pt_endcap_TightMu->setEfficiencyFlag();
69 
70 }
71 
72 
73 void EfficiencyPlotter::beginRun(Run const& run, EventSetup const& eSetup) {
74  LogTrace(metname)<<"[EfficiencyPlotter]: beginRun";
75 }
77  LogTrace(metname)<<"[EfficiencyPlotter]: beginLuminosityBlock";
78  // Get the run number
79  run = lumiSeg.run();
80 }
82  nevents++;
83  LogTrace(metname)<< "[EfficiencyPlotter]: "<<nevents<<" events";
84 }
86  // LogTrace(metname)<<"[EfficiencyPlotter]: endLuminosityBlock, performing the DQM LS client operation";
87  // counts number of lumiSegs
88  nLumiSegs = lumiSeg.id().luminosityBlock();
89 }
90 void EfficiencyPlotter::endRun(Run const& run, EventSetup const& eSetup) {
91  LogTrace(metname)<<"[EfficiencyPlotter]: endRun, performing the DQM end of run client operation";
92 
93 
94 
95  string numpath_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_pt";
96  string denpath_pt = "Muons/EfficiencyAnalyzer/allProbes_pt";
97 
98  MonitorElement *Numerator_pt = theDbe->get(numpath_pt);
99  MonitorElement *Denominator_pt = theDbe->get(denpath_pt);
100 
101  if (Numerator_pt && Denominator_pt){
102 
103  TH1F *h_numerator_pt = Numerator_pt->getTH1F();
104  TH1F *h_denominator_pt = Denominator_pt->getTH1F();
105 
106  TH1F *h_eff_pt = h_eff_pt_TightMu->getTH1F();
107 
108  if (h_eff_pt->GetSumw2N() == 0) h_eff_pt->Sumw2();
109 
110 
111  h_eff_pt->Divide(h_numerator_pt, h_denominator_pt, 1., 1., "B");
112 
113  }
114 
115  string numpath_barrel_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_barrel_pt";
116  string denpath_barrel_pt = "Muons/EfficiencyAnalyzer/allProbes_barrel_pt";
117 
118  MonitorElement *Numerator_barrel_pt = theDbe->get(numpath_barrel_pt);
119  MonitorElement *Denominator_barrel_pt = theDbe->get(denpath_barrel_pt);
120 
121  if (Numerator_barrel_pt && Denominator_barrel_pt){
122 
123  TH1F *h_numerator_barrel_pt = Numerator_barrel_pt->getTH1F();
124  TH1F *h_denominator_barrel_pt = Denominator_barrel_pt->getTH1F();
125 
126  TH1F *h_eff_barrel_pt = h_eff_pt_barrel_TightMu->getTH1F();
127 
128  if (h_eff_barrel_pt->GetSumw2N() == 0) h_eff_barrel_pt->Sumw2();
129 
130  h_eff_barrel_pt->Divide(h_numerator_barrel_pt, h_denominator_barrel_pt, 1., 1., "B");
131 
132  }
133 
134  string numpath_endcap_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_endcap_pt";
135  string denpath_endcap_pt = "Muons/EfficiencyAnalyzer/allProbes_endcap_pt";
136 
137  MonitorElement *Numerator_endcap_pt = theDbe->get(numpath_endcap_pt);
138  MonitorElement *Denominator_endcap_pt = theDbe->get(denpath_endcap_pt);
139 
140  if (Numerator_endcap_pt && Denominator_endcap_pt){
141 
142  TH1F *h_numerator_endcap_pt = Numerator_endcap_pt->getTH1F();
143  TH1F *h_denominator_endcap_pt = Denominator_endcap_pt->getTH1F();
144 
145  TH1F *h_eff_endcap_pt = h_eff_pt_endcap_TightMu->getTH1F();
146 
147  if (h_eff_endcap_pt->GetSumw2N() == 0) h_eff_endcap_pt->Sumw2();
148 
149  h_eff_endcap_pt->Divide(h_numerator_endcap_pt, h_denominator_endcap_pt, 1., 1., "B");
150 
151  }
152 
153  string numpath_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_eta";
154  string denpath_eta = "Muons/EfficiencyAnalyzer/allProbes_eta";
155 
156  MonitorElement *Numerator_eta = theDbe->get(numpath_eta);
157  MonitorElement *Denominator_eta = theDbe->get(denpath_eta);
158 
159  if (Numerator_eta && Denominator_eta){
160 
161  TH1F *h_numerator_eta = Numerator_eta->getTH1F();
162  TH1F *h_denominator_eta = Denominator_eta->getTH1F();
163 
164  TH1F *h_eff_eta = h_eff_eta_TightMu->getTH1F();
165 
166  if (h_eff_eta->GetSumw2N() == 0) h_eff_eta->Sumw2();
167 
168  h_eff_eta->Divide(h_numerator_eta, h_denominator_eta, 1., 1., "B");
169 
170  }
171 
172  string numpath_hp_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_hp_eta";
173  string denpath_hp_eta = "Muons/EfficiencyAnalyzer/allProbes_hp_eta";
174 
175  MonitorElement *Numerator_hp_eta = theDbe->get(numpath_hp_eta);
176  MonitorElement *Denominator_hp_eta = theDbe->get(denpath_hp_eta);
177 
178  if (Numerator_hp_eta && Denominator_hp_eta){
179 
180  TH1F *h_numerator_hp_eta = Numerator_hp_eta->getTH1F();
181  TH1F *h_denominator_hp_eta = Denominator_hp_eta->getTH1F();
182 
183  TH1F *h_eff_hp_eta = h_eff_hp_eta_TightMu->getTH1F();
184 
185  if (h_eff_hp_eta->GetSumw2N() == 0) h_eff_hp_eta->Sumw2();
186 
187  h_eff_hp_eta->Divide(h_numerator_hp_eta, h_denominator_hp_eta, 1., 1., "B");
188 
189  }
190 
191 
192 string numpath_phi = "Muons/EfficiencyAnalyzer/passProbes_TightMu_phi";
193  string denpath_phi = "Muons/EfficiencyAnalyzer/allProbes_phi";
194 
195  MonitorElement *Numerator_phi = theDbe->get(numpath_phi);
196  MonitorElement *Denominator_phi = theDbe->get(denpath_phi);
197 
198  if (Numerator_phi && Denominator_phi){
199 
200  TH1F *h_numerator_phi = Numerator_phi->getTH1F();
201  TH1F *h_denominator_phi = Denominator_phi->getTH1F();
202 
203  TH1F *h_eff_phi = h_eff_phi_TightMu->getTH1F();
204 
205  if (h_eff_phi->GetSumw2N() == 0) h_eff_phi->Sumw2();
206 
207  h_eff_phi->Divide(h_numerator_phi, h_denominator_phi, 1., 1., "B");
208 
209  }
210 
211 
212 
213 
214 
215  /* for(int i=1; i<=ptBin; i++){
216  if (h_denominator->GetBinContent(i) == 0) efficiency = 0;
217  else efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
218  ptEfficiency->setBinContent(i,efficiency);
219  }
220  }*/
221 
222 
223  /*
224  numpath = "Muons/EfficiencyAnalyzer/Numerator_eta";
225  denpath = "Muons/EfficiencyAnalyzer/Denominator_eta";
226  Numerator = theDbe->get(numpath);
227  Denominator = theDbe->get(numpath);
228  if (Numerator && Denominator){
229  TH1F *h_numerator = Numerator->getTH1F();
230  TH1F *h_denominator = Denominator->getTH1F();
231 
232  for(int i=1; i<=etaBin; i++){
233  if (h_denominator->GetBinContent(i) == 0) efficiency = 0;
234  else efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
235  etaEfficiency->setBinContent(i,efficiency);
236  }
237  }
238 
239  numpath = "Muons/EfficiencyAnalyzer/Numerator_phi";
240  denpath = "Muons/EfficiencyAnalyzer/Denominator_phi";
241  Numerator = theDbe->get(numpath);
242  Denominator = theDbe->get(numpath);
243 
244  if (Numerator && Denominator){
245  TH1F *h_numerator = Numerator->getTH1F();
246  TH1F *h_denominator = Denominator->getTH1F();
247 
248  // h_numerator->Divide(h_denominator);
249  if(h_numerator->GetXaxis()->GetNbins()!=ptBin ||
250  h_numerator->GetXaxis()->GetXmax()!=ptBin ||
251  h_numerator->GetXaxis()->GetXmin()!=ptBin){
252  LogTrace(metname)<<"[EfficiencyPlotter] wrong histo binning on eta histograms";
253  return;
254  }
255 
256  for(int i=1; i<=phiBin; i++){
257  if (h_denominator->GetBinContent(i) == 0) efficiency = 0;
258  else efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
259  phiEfficiency->setBinContent(i,efficiency);
260  }
261 
262  }*/
263 }
264 
265 
267  LogTrace(metname)<< "[EfficiencyPlotter] endJob called!";
268  theDbe->rmdir("Muons/EfficiencyAnalyzer");
269 }
270 
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic.
LuminosityBlockID id() const
dictionary parameters
Definition: Parameters.py:2
const std::string metname
EfficiencyPlotter(const edm::ParameterSet &ps)
Constructor.
void endJob()
Endjob.
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
virtual ~EfficiencyPlotter()
Destructor.
RunNumber_t run() const
int nevents
#define LogTrace(id)
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
TH1F * getTH1F(void) const
void beginJob(void)
BeginJob.
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup)
LuminosityBlockNumber_t luminosityBlock() const
Definition: Run.h:33