CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/Muon/src/MuonRecoTest.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2009/12/22 17:42:44 $
00006  *  $Revision: 1.11 $
00007  *  \author G. Mila - INFN Torino
00008  */
00009 
00010 
00011 #include <DQMOffline/Muon/src/MuonRecoTest.h>
00012 
00013 // Framework
00014 #include <FWCore/Framework/interface/Event.h>
00015 #include "DataFormats/Common/interface/Handle.h" 
00016 #include <FWCore/Framework/interface/ESHandle.h>
00017 #include <FWCore/Framework/interface/MakerMacros.h>
00018 #include <FWCore/Framework/interface/EventSetup.h>
00019 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00020 
00021 
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include "FWCore/Framework/interface/Run.h"
00026 
00027 #include <iostream>
00028 #include <stdio.h>
00029 #include <string>
00030 #include <math.h>
00031 #include "TF1.h"
00032 
00033 using namespace edm;
00034 using namespace std;
00035 
00036 
00037 MuonRecoTest::MuonRecoTest(const edm::ParameterSet& ps){
00038 
00039   parameters = ps;
00040 
00041   theDbe = edm::Service<DQMStore>().operator->();
00042 
00043   prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
00044 
00045 }
00046 
00047 
00048 MuonRecoTest::~MuonRecoTest(){
00049 
00050   LogTrace(metname) << "MuonRecoTest: analyzed " << nevents << " events";
00051 
00052 }
00053 
00054 
00055 void MuonRecoTest::beginJob(void){
00056 
00057   metname = "muonRecoTest";
00058   theDbe->setCurrentFolder("Muons/Tests/muonRecoTest");
00059 
00060   LogTrace(metname)<<"[MuonRecoTest] beginJob: Parameters initialization";
00061  
00062   // efficiency plot
00063 
00064   etaBin = parameters.getParameter<int>("etaBin");
00065   etaMin = parameters.getParameter<double>("etaMin");
00066   etaMax = parameters.getParameter<double>("etaMax");
00067   etaEfficiency = theDbe->book1D("etaEfficiency_staMuon", "#eta_{STA} efficiency", etaBin, etaMin, etaMax);
00068 
00069   phiBin = parameters.getParameter<int>("phiBin");
00070   phiMin = parameters.getParameter<double>("phiMin");
00071   phiMax = parameters.getParameter<double>("phiMax");
00072   phiEfficiency = theDbe->book1D("phiEfficiency_staMuon", "#phi_{STA} efficiency", phiBin, phiMin, phiMax);
00073 
00074   // alignment plots
00075   globalRotation.push_back(theDbe->book1D("muVStkSytemRotation_posMu_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{+}",50,0,200));
00076   globalRotation.push_back(theDbe->book1D("muVStkSytemRotation_negMu_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{-}",50,0,200));
00077   globalRotation.push_back(theDbe->book1D("muVStkSytemRotation_profile", "pT_{TK} / pT_{GLB} vs pT_{GLB} profile for #mu^{+}-#mu^{-}",50,0,200));
00078 
00079 }
00080 
00081 void MuonRecoTest::beginRun(Run const& run, EventSetup const& eSetup) {
00082 
00083   LogTrace(metname)<<"[MuonRecoTest]: beginRun";
00084 
00085 }
00086 
00087 void MuonRecoTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00088 
00089   //  LogTrace(metname)<<"[MuonRecoTest]: beginLuminosityBlock";
00090 
00091   // Get the run number
00092   run = lumiSeg.run();
00093 
00094 }
00095 
00096 
00097 void MuonRecoTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00098 
00099   nevents++;
00100   LogTrace(metname)<< "[MuonRecoTest]: "<<nevents<<" events";
00101 
00102 }
00103 
00104 
00105 
00106 void MuonRecoTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00107 
00108   //  LogTrace(metname)<<"[MuonRecoTest]: endLuminosityBlock, performing the DQM LS client operation";
00109   
00110   // counts number of lumiSegs 
00111   nLumiSegs = lumiSeg.id().luminosityBlock();
00112   
00113   // prescale factor
00114   if ( nLumiSegs%prescaleFactor != 0 ) return;
00115 
00116 }
00117 
00118 void MuonRecoTest::endRun(Run const& run, EventSetup const& eSetup) {
00119 
00120   LogTrace(metname)<<"[MuonRecoTest]: endRun, performing the DQM end of run client operation";
00121 
00122   string path = "Muons/MuonRecoAnalyzer/StaEta_ifCombinedAlso";
00123   MonitorElement * staEtaIfComb_histo = theDbe->get(path);
00124   path = "Muons/MuonRecoAnalyzer/StaEta";
00125   MonitorElement * staEta_histo = theDbe->get(path);
00126 
00127   if(staEtaIfComb_histo && staEta_histo){
00128     TH1F * staEtaIfComb_root = staEtaIfComb_histo->getTH1F();
00129     TH1F * staEta_root = staEta_histo->getTH1F();
00130 
00131     if(staEtaIfComb_root->GetXaxis()->GetNbins()!=etaBin
00132        || staEtaIfComb_root->GetXaxis()->GetXmax()!=etaMax
00133        || staEtaIfComb_root->GetXaxis()->GetXmin()!=etaMin){
00134       LogTrace(metname)<<"[MuonRecoTest] wrong histo binning on eta histograms";
00135       return;
00136     }
00137 
00138     for(int i=1; i<=etaBin; i++){
00139       if(staEta_root->GetBinContent(i)!=0){
00140         double efficiency = double(staEtaIfComb_root->GetBinContent(i))/double(staEta_root->GetBinContent(i));
00141         etaEfficiency->setBinContent(i,efficiency);
00142       }
00143     }
00144   }
00145 
00146   path = "Muons/MuonRecoAnalyzer/StaPhi_ifCombinedAlso";
00147   MonitorElement * staPhiIfComb_histo = theDbe->get(path);
00148   path = "Muons/MuonRecoAnalyzer/StaPhi";
00149   MonitorElement * staPhi_histo = theDbe->get(path);
00150 
00151   if(staPhiIfComb_histo && staPhi_histo){
00152  
00153     TH1F * staPhiIfComb_root = staPhiIfComb_histo->getTH1F();
00154     TH1F * staPhi_root = staPhi_histo->getTH1F();
00155 
00156     if(staPhiIfComb_root->GetXaxis()->GetNbins()!=phiBin
00157        || staPhiIfComb_root->GetXaxis()->GetXmax()!=phiMax
00158        || staPhiIfComb_root->GetXaxis()->GetXmin()!=phiMin){
00159       LogTrace(metname)<<"[MuonRecoTest] wrong histo binning on phi histograms";
00160       return;
00161     }
00162 
00163     for(int i=1; i<=etaBin; i++){
00164       if(staPhi_root->GetBinContent(i)!=0){
00165         double efficiency = double(staPhiIfComb_root->GetBinContent(i))/double(staPhi_root->GetBinContent(i));
00166         phiEfficiency->setBinContent(i,efficiency);
00167       }
00168     }
00169   }
00170 
00171 
00172   // efficiency test 
00173   string EfficiencyCriterionName = parameters.getUntrackedParameter<string>("efficiencyTestName","EfficiencyInRange"); 
00174 
00175   // eta efficiency
00176   const QReport * theEtaQReport = etaEfficiency->getQReport(EfficiencyCriterionName);
00177   if(theEtaQReport) {
00178     vector<dqm::me_util::Channel> badChannels = theEtaQReport->getBadChannels();
00179     for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00180          channel != badChannels.end(); channel++) {
00181       LogTrace(metname)<<"[etaEfficiency test] bad ranges: "<<(*channel).getBin()<<"  Contents : "<<(*channel).getContents()<<endl;
00182     }
00183     LogTrace(metname)<< "-------- type: [etaEfficiency]  "<<theEtaQReport->getMessage()<<" ------- "<<theEtaQReport->getStatus()<<endl;
00184   }
00185   // phi efficiency
00186   const QReport * thePhiQReport = phiEfficiency->getQReport(EfficiencyCriterionName);
00187   if(thePhiQReport) {
00188     vector<dqm::me_util::Channel> badChannels = thePhiQReport->getBadChannels();
00189     for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00190          channel != badChannels.end(); channel++) {
00191       LogTrace(metname)<< "[phiEfficiency test] bad ranges: "<<(*channel).getBin()<<"  Contents : "<<(*channel).getContents()<<endl;
00192     }
00193     LogTrace(metname)<<"-------- type: [phiEfficiency]  "<<thePhiQReport->getMessage()<<" ------- "<<thePhiQReport->getStatus()<<endl;
00194   }
00195 
00196   //alignment plot
00197   string pathPos = "Muons/MuonRecoAnalyzer/muVStkSytemRotation_posMu";
00198   MonitorElement * muVStkSytemRotation_posMu_histo = theDbe->get(pathPos);
00199   string pathNeg = "Muons/MuonRecoAnalyzer/muVStkSytemRotation_negMu";
00200   MonitorElement * muVStkSytemRotation_negMu_histo = theDbe->get(pathNeg);
00201   if(muVStkSytemRotation_posMu_histo && muVStkSytemRotation_negMu_histo){
00202 
00203     TH2F * muVStkSytemRotation_posMu_root = muVStkSytemRotation_posMu_histo->getTH2F();
00204     TProfile * muVStkSytemRotation_posMu_profile = muVStkSytemRotation_posMu_root->ProfileX("",1,100);
00205     TH2F * muVStkSytemRotation_negMu_root = muVStkSytemRotation_negMu_histo->getTH2F();
00206     TProfile * muVStkSytemRotation_negMu_profile = muVStkSytemRotation_negMu_root->ProfileX("",1,100);
00207 
00208     for(int x=1; x<50; x++){
00209       globalRotation[0]->Fill((x*4)-1,muVStkSytemRotation_posMu_profile->GetBinContent(x));
00210       globalRotation[0]->setBinError(x,muVStkSytemRotation_posMu_profile->GetBinError(x));
00211       globalRotation[1]->Fill((x*4)-1,muVStkSytemRotation_negMu_profile->GetBinContent(x));
00212       globalRotation[1]->setBinError(x,muVStkSytemRotation_negMu_profile->GetBinError(x));
00213       globalRotation[2]->Fill((x*4)-1,muVStkSytemRotation_posMu_profile->GetBinContent(x)-muVStkSytemRotation_negMu_profile->GetBinContent(x));
00214       globalRotation[2]->setBinError(x,sqrt((muVStkSytemRotation_posMu_profile->GetBinError(x)*muVStkSytemRotation_posMu_profile->GetBinError(x))
00215                                             + (muVStkSytemRotation_negMu_profile->GetBinError(x)*muVStkSytemRotation_negMu_profile->GetBinError(x))));
00216     }
00217   }
00218 
00219 }
00220 
00221 void MuonRecoTest::endJob(){
00222   
00223   LogTrace(metname)<< "[MuonRecoTest] endJob called!";
00224   theDbe->rmdir("Muons/Tests/muonRecoTest");
00225   
00226 }
00227