CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/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     if (h_eff_pt->GetSumw2N() == 0) h_eff_pt->Sumw2();
00109  
00110     
00111     h_eff_pt->Divide(h_numerator_pt, h_denominator_pt, 1., 1., "B");
00112 
00113   }
00114 
00115   string numpath_barrel_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_barrel_pt";
00116   string denpath_barrel_pt = "Muons/EfficiencyAnalyzer/allProbes_barrel_pt";
00117   
00118   MonitorElement *Numerator_barrel_pt   = theDbe->get(numpath_barrel_pt);
00119   MonitorElement *Denominator_barrel_pt = theDbe->get(denpath_barrel_pt);
00120   
00121   if (Numerator_barrel_pt && Denominator_barrel_pt){
00122  
00123     TH1F *h_numerator_barrel_pt   = Numerator_barrel_pt->getTH1F();
00124     TH1F *h_denominator_barrel_pt = Denominator_barrel_pt->getTH1F();
00125 
00126     TH1F *h_eff_barrel_pt = h_eff_pt_barrel_TightMu->getTH1F();
00127     
00128     if (h_eff_barrel_pt->GetSumw2N() == 0) h_eff_barrel_pt->Sumw2();
00129 
00130     h_eff_barrel_pt->Divide(h_numerator_barrel_pt, h_denominator_barrel_pt, 1., 1., "B");
00131 
00132   }
00133 
00134   string numpath_endcap_pt = "Muons/EfficiencyAnalyzer/passProbes_TightMu_endcap_pt";
00135   string denpath_endcap_pt = "Muons/EfficiencyAnalyzer/allProbes_endcap_pt";
00136   
00137   MonitorElement *Numerator_endcap_pt   = theDbe->get(numpath_endcap_pt);
00138   MonitorElement *Denominator_endcap_pt = theDbe->get(denpath_endcap_pt);
00139   
00140   if (Numerator_endcap_pt && Denominator_endcap_pt){
00141  
00142     TH1F *h_numerator_endcap_pt   = Numerator_endcap_pt->getTH1F();
00143     TH1F *h_denominator_endcap_pt = Denominator_endcap_pt->getTH1F();
00144 
00145     TH1F *h_eff_endcap_pt = h_eff_pt_endcap_TightMu->getTH1F();
00146       
00147     if (h_eff_endcap_pt->GetSumw2N() == 0) h_eff_endcap_pt->Sumw2();
00148 
00149     h_eff_endcap_pt->Divide(h_numerator_endcap_pt, h_denominator_endcap_pt, 1., 1., "B");
00150 
00151   }
00152 
00153   string numpath_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_eta";
00154   string denpath_eta = "Muons/EfficiencyAnalyzer/allProbes_eta";
00155   
00156   MonitorElement *Numerator_eta   = theDbe->get(numpath_eta);
00157   MonitorElement *Denominator_eta = theDbe->get(denpath_eta);
00158   
00159   if (Numerator_eta && Denominator_eta){
00160  
00161     TH1F *h_numerator_eta   = Numerator_eta->getTH1F();
00162     TH1F *h_denominator_eta = Denominator_eta->getTH1F();
00163 
00164     TH1F *h_eff_eta = h_eff_eta_TightMu->getTH1F();
00165     
00166     if (h_eff_eta->GetSumw2N() == 0) h_eff_eta->Sumw2();
00167 
00168     h_eff_eta->Divide(h_numerator_eta, h_denominator_eta, 1., 1., "B");
00169 
00170   }
00171 
00172   string numpath_hp_eta = "Muons/EfficiencyAnalyzer/passProbes_TightMu_hp_eta";
00173   string denpath_hp_eta = "Muons/EfficiencyAnalyzer/allProbes_hp_eta";
00174   
00175   MonitorElement *Numerator_hp_eta   = theDbe->get(numpath_hp_eta);
00176   MonitorElement *Denominator_hp_eta = theDbe->get(denpath_hp_eta);
00177   
00178   if (Numerator_hp_eta && Denominator_hp_eta){
00179  
00180     TH1F *h_numerator_hp_eta   = Numerator_hp_eta->getTH1F();
00181     TH1F *h_denominator_hp_eta = Denominator_hp_eta->getTH1F();
00182 
00183     TH1F *h_eff_hp_eta = h_eff_hp_eta_TightMu->getTH1F();
00184        
00185     if (h_eff_hp_eta->GetSumw2N() == 0) h_eff_hp_eta->Sumw2();
00186 
00187     h_eff_hp_eta->Divide(h_numerator_hp_eta, h_denominator_hp_eta, 1., 1., "B");
00188 
00189   }
00190 
00191 
00192 string numpath_phi = "Muons/EfficiencyAnalyzer/passProbes_TightMu_phi";
00193   string denpath_phi = "Muons/EfficiencyAnalyzer/allProbes_phi";
00194   
00195   MonitorElement *Numerator_phi   = theDbe->get(numpath_phi);
00196   MonitorElement *Denominator_phi = theDbe->get(denpath_phi);
00197   
00198   if (Numerator_phi && Denominator_phi){
00199  
00200     TH1F *h_numerator_phi   = Numerator_phi->getTH1F();
00201     TH1F *h_denominator_phi = Denominator_phi->getTH1F();
00202 
00203     TH1F *h_eff_phi = h_eff_phi_TightMu->getTH1F();
00204        
00205     if (h_eff_phi->GetSumw2N() == 0) h_eff_phi->Sumw2();
00206 
00207     h_eff_phi->Divide(h_numerator_phi, h_denominator_phi, 1., 1., "B");
00208 
00209   }
00210 
00211 
00212 
00213 
00214 
00215     /*   for(int i=1; i<=ptBin; i++){
00216       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00217       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00218       ptEfficiency->setBinContent(i,efficiency);
00219     }
00220     }*/
00221   
00222 
00223   /*
00224   numpath = "Muons/EfficiencyAnalyzer/Numerator_eta";
00225   denpath = "Muons/EfficiencyAnalyzer/Denominator_eta";
00226   Numerator   = theDbe->get(numpath);
00227   Denominator = theDbe->get(numpath);
00228   if (Numerator && Denominator){
00229     TH1F *h_numerator   = Numerator->getTH1F();
00230     TH1F *h_denominator = Denominator->getTH1F();
00231    
00232     for(int i=1; i<=etaBin; i++){
00233       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00234       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00235       etaEfficiency->setBinContent(i,efficiency);
00236     }
00237   }
00238   
00239   numpath = "Muons/EfficiencyAnalyzer/Numerator_phi";
00240   denpath = "Muons/EfficiencyAnalyzer/Denominator_phi";
00241   Numerator   = theDbe->get(numpath);
00242   Denominator = theDbe->get(numpath);
00243   
00244   if (Numerator && Denominator){
00245     TH1F *h_numerator   = Numerator->getTH1F();
00246     TH1F *h_denominator = Denominator->getTH1F();
00247     
00248     //    h_numerator->Divide(h_denominator);
00249       if(h_numerator->GetXaxis()->GetNbins()!=ptBin ||
00250         h_numerator->GetXaxis()->GetXmax()!=ptBin  ||
00251         h_numerator->GetXaxis()->GetXmin()!=ptBin){
00252         LogTrace(metname)<<"[EfficiencyPlotter] wrong histo binning on eta histograms";
00253         return;
00254         }
00255   
00256     for(int i=1; i<=phiBin; i++){
00257       if (h_denominator->GetBinContent(i) == 0)  efficiency = 0;
00258       else                                       efficiency = double(h_numerator->GetBinContent(i))/double(h_denominator->GetBinContent(i));
00259       phiEfficiency->setBinContent(i,efficiency);
00260     }
00261 
00262     }*/
00263 }
00264 
00265 
00266 void EfficiencyPlotter::endJob(){
00267   LogTrace(metname)<< "[EfficiencyPlotter] endJob called!";
00268   theDbe->rmdir("Muons/EfficiencyAnalyzer");
00269 }
00270