CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQMOffline/Muon/src/EfficiencyPlotter.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Muon/src/EfficiencyPlotter.h"
00002 
00003 // Framework
00004 #include <FWCore/Framework/interface/Event.h>
00005 #include "DataFormats/Common/interface/Handle.h" 
00006 #include <FWCore/Framework/interface/ESHandle.h>
00007 #include <FWCore/Framework/interface/MakerMacros.h>
00008 #include <FWCore/Framework/interface/EventSetup.h>
00009 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00010 
00011 
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "DQMServices/Core/interface/MonitorElement.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/Run.h"
00016 
00017 #include <iostream>
00018 #include <stdio.h>
00019 #include <string>
00020 #include <math.h>
00021 #include "TF1.h"
00022 #include "TH1F.h"
00023 
00024 
00025 using namespace edm;
00026 using namespace std;
00027 
00028 
00029 EfficiencyPlotter::EfficiencyPlotter(const edm::ParameterSet& ps){
00030   parameters = ps;
00031   theDbe = edm::Service<DQMStore>().operator->();
00032 }
00033 EfficiencyPlotter::~EfficiencyPlotter(){}
00034 
00035 void EfficiencyPlotter::beginJob(void){
00036   //metname = "muonRecoTest";
00037   
00038   metname = "EfficiencyAnalyzer";
00039   theDbe->setCurrentFolder("Muons/EfficiencyAnalyzer");
00040 
00041   LogTrace(metname)<<"[EfficiencyPlotter] beginJob: Parameters initialization";
00042  
00043   // efficiency plot
00044   etaBin = parameters.getParameter<int>("etaBin");
00045   etaMin = parameters.getParameter<double>("etaMin");
00046   etaMax = parameters.getParameter<double>("etaMax");
00047   h_eff_eta_TightMu = theDbe->book1D("Eff_eta_TightMu", "TightMu Efficiency vs #eta", etaBin, etaMin, etaMax);
00048   h_eff_hp_eta_TightMu = theDbe->book1D("Eff_hp_eta_TightMu", "High Pt TightMu Efficiency vs #eta", etaBin, etaMin, etaMax);
00049 
00050   phiBin = parameters.getParameter<int>("phiBin");
00051   phiMin = parameters.getParameter<double>("phiMin");
00052   phiMax = parameters.getParameter<double>("phiMax");
00053   h_eff_phi_TightMu = theDbe->book1D("Eff_phi_TightMu", "TightMu Efficiency vs #phi", phiBin, phiMin, phiMax);
00054 
00055   ptBin = parameters.getParameter<int>("ptBin");
00056   ptMin = parameters.getParameter<double>("ptMin");
00057   ptMax = parameters.getParameter<double>("ptMax");
00058   h_eff_pt_TightMu = theDbe->book1D("Eff_pt_TightMu", "TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
00059   h_eff_pt_barrel_TightMu = theDbe->book1D("Eff_pt_barrel_TightMu", "Barrel: TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
00060   h_eff_pt_endcap_TightMu = theDbe->book1D("Eff_pt_endcap_TightMu", "Endcap: TightMu Efficiency vs Pt", ptBin, ptMin, ptMax);
00061 
00062 
00063   h_eff_eta_TightMu->setEfficiencyFlag();
00064   h_eff_hp_eta_TightMu->setEfficiencyFlag();
00065   h_eff_phi_TightMu->setEfficiencyFlag();
00066   h_eff_pt_TightMu->setEfficiencyFlag();
00067   h_eff_pt_barrel_TightMu->setEfficiencyFlag();
00068   h_eff_pt_endcap_TightMu->setEfficiencyFlag();
00069 
00070 }
00071 
00072 
00073 void EfficiencyPlotter::beginRun(Run const& run, EventSetup const& eSetup) {
00074   LogTrace(metname)<<"[EfficiencyPlotter]: beginRun";
00075 }
00076 void EfficiencyPlotter::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00077   LogTrace(metname)<<"[EfficiencyPlotter]: beginLuminosityBlock";
00078   // Get the run number
00079   run = lumiSeg.run();
00080 }
00081 void EfficiencyPlotter::analyze(const edm::Event& e, const edm::EventSetup& context){
00082   nevents++;
00083   LogTrace(metname)<< "[EfficiencyPlotter]: "<<nevents<<" events";
00084 }
00085 void EfficiencyPlotter::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00086   //  LogTrace(metname)<<"[EfficiencyPlotter]: endLuminosityBlock, performing the DQM LS client operation";
00087   // counts number of lumiSegs 
00088   nLumiSegs = lumiSeg.id().luminosityBlock();
00089 }
00090 void EfficiencyPlotter::endRun(Run const& run, EventSetup const& eSetup) {
00091   LogTrace(metname)<<"[EfficiencyPlotter]: endRun, performing the DQM end of run client operation";
00092   
00093  
00094 
00095   string numpath_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_pt";
00096   string denpath_pt = "Muons/EfficiencyAnalyzer/allProbes_pt";
00097   
00098   MonitorElement *Numerator_pt   = theDbe->get(numpath_pt);
00099   MonitorElement *Denominator_pt = theDbe->get(denpath_pt);
00100   
00101   if (Numerator_pt && Denominator_pt){
00102  
00103     TH1F *h_numerator_pt   = Numerator_pt->getTH1F();
00104     TH1F *h_denominator_pt = Denominator_pt->getTH1F();
00105 
00106     TH1F *h_eff_pt = h_eff_pt_TightMu->getTH1F();
00107     
00108     h_eff_pt->Sumw2(); 
00109     
00110     h_eff_pt->Divide(h_numerator_pt, h_denominator_pt, 1., 1., "B");
00111 
00112   }
00113 
00114   string numpath_barrel_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_barrel_pt";
00115   string denpath_barrel_pt = "Muons/EfficiencyAnalyzer/allProbes_barrel_pt";
00116   
00117   MonitorElement *Numerator_barrel_pt   = theDbe->get(numpath_barrel_pt);
00118   MonitorElement *Denominator_barrel_pt = theDbe->get(denpath_barrel_pt);
00119   
00120   if (Numerator_barrel_pt && Denominator_barrel_pt){
00121  
00122     TH1F *h_numerator_barrel_pt   = Numerator_barrel_pt->getTH1F();
00123     TH1F *h_denominator_barrel_pt = Denominator_barrel_pt->getTH1F();
00124 
00125     TH1F *h_eff_barrel_pt = h_eff_pt_barrel_TightMu->getTH1F();
00126     
00127     h_eff_barrel_pt->Sumw2(); 
00128     
00129     h_eff_barrel_pt->Divide(h_numerator_barrel_pt, h_denominator_barrel_pt, 1., 1., "B");
00130 
00131   }
00132 
00133   string numpath_endcap_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_endcap_pt";
00134   string denpath_endcap_pt = "Muons/EfficiencyAnalyzer/allProbes_endcap_pt";
00135   
00136   MonitorElement *Numerator_endcap_pt   = theDbe->get(numpath_endcap_pt);
00137   MonitorElement *Denominator_endcap_pt = theDbe->get(denpath_endcap_pt);
00138   
00139   if (Numerator_endcap_pt && Denominator_endcap_pt){
00140  
00141     TH1F *h_numerator_endcap_pt   = Numerator_endcap_pt->getTH1F();
00142     TH1F *h_denominator_endcap_pt = Denominator_endcap_pt->getTH1F();
00143 
00144     TH1F *h_eff_endcap_pt = h_eff_pt_endcap_TightMu->getTH1F();
00145     
00146     h_eff_endcap_pt->Sumw2(); 
00147     
00148     h_eff_endcap_pt->Divide(h_numerator_endcap_pt, h_denominator_endcap_pt, 1., 1., "B");
00149 
00150   }
00151 
00152   string numpath_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_eta";
00153   string denpath_eta = "Muons/EfficiencyAnalyzer/allProbes_eta";
00154   
00155   MonitorElement *Numerator_eta   = theDbe->get(numpath_eta);
00156   MonitorElement *Denominator_eta = theDbe->get(denpath_eta);
00157   
00158   if (Numerator_eta && Denominator_eta){
00159  
00160     TH1F *h_numerator_eta   = Numerator_eta->getTH1F();
00161     TH1F *h_denominator_eta = Denominator_eta->getTH1F();
00162 
00163     TH1F *h_eff_eta = h_eff_eta_TightMu->getTH1F();
00164     
00165     h_eff_eta->Sumw2(); 
00166     
00167     h_eff_eta->Divide(h_numerator_eta, h_denominator_eta, 1., 1., "B");
00168 
00169   }
00170 
00171   string numpath_hp_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_hp_eta";
00172   string denpath_hp_eta = "Muons/EfficiencyAnalyzer/allProbes_hp_eta";
00173   
00174   MonitorElement *Numerator_hp_eta   = theDbe->get(numpath_hp_eta);
00175   MonitorElement *Denominator_hp_eta = theDbe->get(denpath_hp_eta);
00176   
00177   if (Numerator_hp_eta && Denominator_hp_eta){
00178  
00179     TH1F *h_numerator_hp_eta   = Numerator_hp_eta->getTH1F();
00180     TH1F *h_denominator_hp_eta = Denominator_hp_eta->getTH1F();
00181 
00182     TH1F *h_eff_hp_eta = h_eff_hp_eta_TightMu->getTH1F();
00183     
00184     h_eff_hp_eta->Sumw2(); 
00185     
00186     h_eff_hp_eta->Divide(h_numerator_hp_eta, h_denominator_hp_eta, 1., 1., "B");
00187 
00188   }
00189 
00190 
00191 string numpath_phi = "Muons/EfficiencyAnalyzer/passProbes_TightMu_phi";
00192   string denpath_phi = "Muons/EfficiencyAnalyzer/allProbes_phi";
00193   
00194   MonitorElement *Numerator_phi   = theDbe->get(numpath_phi);
00195   MonitorElement *Denominator_phi = theDbe->get(denpath_phi);
00196   
00197   if (Numerator_phi && Denominator_phi){
00198  
00199     TH1F *h_numerator_phi   = Numerator_phi->getTH1F();
00200     TH1F *h_denominator_phi = Denominator_phi->getTH1F();
00201 
00202     TH1F *h_eff_phi = h_eff_phi_TightMu->getTH1F();
00203     
00204     h_eff_phi->Sumw2(); 
00205     
00206     h_eff_phi->Divide(h_numerator_phi, h_denominator_phi, 1., 1., "B");
00207 
00208   }
00209 
00210 
00211 
00212 
00213 
00214     /*   for(int i=1; i<=ptBin; i++){
00215       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00216       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00217       ptEfficiency->setBinContent(i,efficiency);
00218     }
00219     }*/
00220   
00221 
00222   /*
00223   numpath = "Muons/EfficiencyAnalyzer/Numerator_eta";
00224   denpath = "Muons/EfficiencyAnalyzer/Denominator_eta";
00225   Numerator   = theDbe->get(numpath);
00226   Denominator = theDbe->get(numpath);
00227   if (Numerator && Denominator){
00228     TH1F *h_numerator   = Numerator->getTH1F();
00229     TH1F *h_denominator = Denominator->getTH1F();
00230    
00231     for(int i=1; i<=etaBin; i++){
00232       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00233       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00234       etaEfficiency->setBinContent(i,efficiency);
00235     }
00236   }
00237   
00238   numpath = "Muons/EfficiencyAnalyzer/Numerator_phi";
00239   denpath = "Muons/EfficiencyAnalyzer/Denominator_phi";
00240   Numerator   = theDbe->get(numpath);
00241   Denominator = theDbe->get(numpath);
00242   
00243   if (Numerator && Denominator){
00244     TH1F *h_numerator   = Numerator->getTH1F();
00245     TH1F *h_denominator = Denominator->getTH1F();
00246     
00247     //    h_numerator->Divide(h_denominator);
00248       if(h_numerator->GetXaxis()->GetNbins()!=ptBin ||
00249         h_numerator->GetXaxis()->GetXmax()!=ptBin  ||
00250         h_numerator->GetXaxis()->GetXmin()!=ptBin){
00251         LogTrace(metname)<<"[EfficiencyPlotter] wrong histo binning on eta histograms";
00252         return;
00253         }
00254   
00255     for(int i=1; i<=phiBin; i++){
00256       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00257       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00258       phiEfficiency->setBinContent(i,efficiency);
00259     }
00260 
00261     }*/
00262 }
00263 
00264 
00265 void EfficiencyPlotter::endJob(){
00266   LogTrace(metname)<< "[EfficiencyPlotter] endJob called!";
00267   theDbe->rmdir("Muons/EfficiencyAnalyzer");
00268 }
00269