CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQMOffline/Muon/src/EfficiencyAnalyzer.cc

Go to the documentation of this file.
00001 /* This Class Header */
00002 #include "DQMOffline/Muon/src/EfficiencyAnalyzer.h"
00003 
00004 /* Collaborating Class Header */
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include "DataFormats/MuonReco/interface/Muon.h"
00012 #include "DataFormats/MuonReco/interface/MuonFwd.h" 
00013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00014 #include "DataFormats/Math/interface/deltaR.h"
00015 
00016 using namespace edm;
00017 
00018 #include "TLorentzVector.h"
00019 #include "TFile.h"
00020 #include <vector>
00021 #include "math.h"
00022 
00023 
00024 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00025 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00026 
00027 
00028 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00029 #include "DataFormats/TrackReco/interface/Track.h"
00030 
00031 /* C++ Headers */
00032 #include <iostream>
00033 #include <fstream>
00034 #include <cmath>
00035 using namespace std;
00036 using namespace edm;
00037 
00038 EfficiencyAnalyzer::EfficiencyAnalyzer(const edm::ParameterSet& pSet, MuonServiceProxy *theService):MuonAnalyzerBase(theService){ 
00039   parameters = pSet;
00040 }
00041 
00042 EfficiencyAnalyzer::~EfficiencyAnalyzer() { }
00043 
00044 void EfficiencyAnalyzer::beginJob(DQMStore * dbe) {
00045 #ifdef DEBUG
00046   cout << "[EfficiencyAnalyzer] Parameters initialization" <<endl;
00047 #endif
00048   metname = "EfficiencyAnalyzer";
00049   LogTrace(metname)<<"[EfficiencyAnalyzer] Parameters initialization";
00050   dbe->setCurrentFolder("Muons/EfficiencyAnalyzer");  
00051   
00052   theMuonCollectionLabel = parameters.getParameter<edm::InputTag>("MuonCollection");
00053   theTrackCollectionLabel = parameters.getParameter<edm::InputTag>("TrackCollection");
00054 
00055 
00056   ptBin_ = parameters.getParameter<int>("ptBin");
00057   ptMin_ = parameters.getParameter<double>("ptMin");
00058   ptMax_ = parameters.getParameter<double>("ptMax");
00059 
00060   etaBin_ = parameters.getParameter<int>("etaBin");
00061   etaMin_ = parameters.getParameter<double>("etaMin");
00062   etaMax_ = parameters.getParameter<double>("etaMax");
00063 
00064   phiBin_ = parameters.getParameter<int>("phiBin");
00065   phiMin_ = parameters.getParameter<double>("phiMin");
00066   phiMax_ = parameters.getParameter<double>("phiMax");
00067 
00068 
00069 
00070   test_TightMu_Minv  = dbe->book1D("test_TightMu_Minv"  ,"Minv",50,70,110);
00071 
00072   h_allProbes_pt = dbe->book1D("allProbes_pt","All Probes Pt", ptBin_, ptMin_, ptMax_);
00073   h_allProbes_barrel_pt = dbe->book1D("allProbes_barrel_pt","Barrel: all Probes Pt", ptBin_, ptMin_, ptMax_);
00074   h_allProbes_endcap_pt = dbe->book1D("allProbes_endcap_pt","Endcap: all Probes Pt", ptBin_, ptMin_, ptMax_);
00075   h_allProbes_eta = dbe->book1D("allProbes_eta","All Probes Eta", etaBin_, etaMin_, etaMax_);
00076   h_allProbes_hp_eta = dbe->book1D("allProbes_hp_eta","High Pt all Probes Eta", etaBin_, etaMin_, etaMax_);
00077   h_allProbes_phi = dbe->book1D("allProbes_phi","All Probes Phi", phiBin_, phiMin_, phiMax_);
00078 
00079   h_passProbes_TightMu_pt = dbe->book1D("passProbes_TightMu_pt","TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
00080  h_passProbes_TightMu_barrel_pt = dbe->book1D("passProbes_TightMu_barrel_pt","Barrel: TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
00081  h_passProbes_TightMu_endcap_pt = dbe->book1D("passProbes_TightMu_endcap_pt","Endcap: TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
00082   h_passProbes_TightMu_eta = dbe->book1D("passProbes_TightMu_eta","TightMu Passing Probes #eta", etaBin_, etaMin_, etaMax_);
00083   h_passProbes_TightMu_hp_eta = dbe->book1D("passProbes_TightMu_hp_eta","High Pt TightMu Passing Probes #eta", etaBin_, etaMin_, etaMax_);
00084   h_passProbes_TightMu_phi = dbe->book1D("passProbes_TightMu_phi","TightMu Passing Probes #phi", phiBin_, phiMin_, phiMax_);
00085 
00086 
00087 
00088   /*h_failProbes_TightMu_pt = dbe->book1D("failProbes_TightMu_pt","TightMu Failling Probes Pt", ptBin_ , ptMin_ , ptMax_ );
00089   h_failProbes_TightMu_eta = dbe->book1D("failProbes_TightMu_eta","TightMu Failling Probes #eta", etaBin_, etaMin_, etaMax_);
00090   h_failProbes_TightMu_phi = dbe->book1D("failProbes_TightMu_phi","TightMu Failling Probes #phi", phiBin_, phiMin_, phiMax_);
00091   */
00092 
00093 #ifdef DEBUG
00094   cout << "[EfficiencyAnalyzer] Parameters initialization DONE" <<endl;
00095 #endif
00096 }
00097 
00098 void EfficiencyAnalyzer::analyze(const edm::Event & iEvent,const edm::EventSetup& iSetup) {
00099 
00100   LogTrace(metname)<<"[EfficiencyAnalyzer] Analyze the mu in different eta regions";
00101   
00102   edm::Handle<reco::MuonCollection> muons;
00103   iEvent.getByLabel(theMuonCollectionLabel, muons);
00104 
00105 
00106   edm::Handle<reco::TrackCollection> tracks;
00107   iEvent.getByLabel(theTrackCollectionLabel,tracks); 
00108 
00109 
00110   reco::BeamSpot beamSpot;
00111   Handle<reco::BeamSpot> beamSpotHandle;
00112   iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
00113   beamSpot = *beamSpotHandle;
00114 
00115   if(!muons.isValid()) return;
00116 
00117 
00118   // Loop on muon collection
00119   TLorentzVector Mu1, Mu2;
00120 
00121   bool isMB = false;
00122   bool isME = false;
00123 
00124   for (reco::MuonCollection::const_iterator recoMu1 = muons->begin(); recoMu1!=muons->end(); ++recoMu1) {
00125 
00126     LogTrace(metname)<<"[EfficiencyAnalyzer] loop over first muons" << endl;
00127 
00128     //--- Define combined isolation
00129     reco::MuonIsolation Iso_muon = recoMu1->isolationR03();
00130     float combIso = (Iso_muon.emEt + Iso_muon.hadEt + Iso_muon.sumPt);  
00131     
00132     //--- Is Global Muon 
00133     if (!recoMu1->isGlobalMuon()) continue;
00134 
00135       // get the track combinig the information from both the Tracker and the Spectrometer
00136       reco::TrackRef recoCombinedGlbTrack1 = recoMu1->combinedMuon();    
00137       float muPt1 = recoCombinedGlbTrack1->pt();
00138       Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
00139       
00140 
00141       //--- Define if it is a tight muon
00142       if (recoMu1->isGlobalMuon() && recoMu1->isTrackerMuon() && recoMu1->combinedMuon()->normalizedChi2()<10. 
00143           && recoMu1->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu1->combinedMuon()->dxy(beamSpot.position()))<0.2 && recoMu1->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu1->numberOfMatches() > 1) {
00144 
00145         //-- is isolated muon
00146         if (muPt1 > 15  && (combIso/muPt1) < 0.1 ) {
00147 
00148 
00149           for (reco::MuonCollection::const_iterator recoMu2 = muons->begin(); recoMu2!=muons->end(); ++recoMu2){ 
00150           
00151             LogTrace(metname)<<"[EfficiencyAnalyzer] loop over second muon" <<endl;
00152           
00153             if (recoMu2 == recoMu1) continue;
00154 
00155             
00156             if (recoMu2->eta() < 1.479 )  isMB = true;
00157             if (recoMu2->eta() >= 1.479 ) isME = true;
00158 
00159 
00160             //--> should we apply track quality cuts??? 
00161             Mu2.SetPxPyPzE(recoMu2->px(), recoMu2->py(), recoMu2->pz(), recoMu2->p());
00162 
00163             if (!recoMu2->isTrackerMuon()) continue;
00164 
00165             if ( recoMu2->pt() < 5 ) continue;
00166 
00167             if ( (recoMu1->charge())*(recoMu2->charge()) > 0 ) continue; 
00168 
00169             float Minv = (Mu1+Mu2).M();
00170             
00171             if ( Minv < 70 ||  Minv > 110 ) continue; 
00172 
00173             h_allProbes_pt->Fill(recoMu2->pt());
00174             h_allProbes_eta->Fill(recoMu2->eta());
00175             h_allProbes_phi->Fill(recoMu2->phi());
00176 
00177 
00178             if (isMB) h_allProbes_barrel_pt->Fill(recoMu2->pt());
00179             if (isME) h_allProbes_endcap_pt->Fill(recoMu2->pt());
00180             if(recoMu2->pt() > 20 ) h_allProbes_hp_eta->Fill(recoMu2->eta());
00181 
00182 
00183             test_TightMu_Minv->Fill(Minv);
00184 
00185          
00186             // Probes passing the tight muon criteria 
00187 
00188             if (recoMu2->isGlobalMuon() && recoMu2->isTrackerMuon() && recoMu2->combinedMuon()->normalizedChi2()<10. && recoMu2->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu2->combinedMuon()->dxy(beamSpot.position()))<0.2 && recoMu2->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu2->numberOfMatches() > 1) { 
00189                  
00190                  h_passProbes_TightMu_pt->Fill(recoMu2->pt());
00191                  h_passProbes_TightMu_eta->Fill(recoMu2->eta());
00192                  h_passProbes_TightMu_phi->Fill(recoMu2->phi());
00193 
00194                  if (isMB) h_passProbes_TightMu_barrel_pt->Fill(recoMu2->pt());
00195                  if (isME) h_passProbes_TightMu_endcap_pt->Fill(recoMu2->pt());
00196                  if( recoMu2->pt() > 20 ) h_passProbes_TightMu_hp_eta->Fill(recoMu2->eta());
00197        
00198             }
00199           }
00200               
00201         }
00202       }
00203   }
00204 }
00205 
00206 
00207 
00208 
00209