PageRenderTime 30ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ElectroWeakAnalysis/ZMuMu/plugins/triggerEfficiency.cc

https://github.com/aivanov-cern/cmssw
C++ | 164 lines | 148 code | 10 blank | 6 comment | 17 complexity | 02c58b1981eddbf44606ed8feb6110da MD5 | raw file
  1/* \class testAnalyzer
  2 * author: Noli Pasquale
  3 * version 0.1
  4 * TriggerEfficiency module
  5 *
  6 */
  7#include "FWCore/Framework/interface/EDAnalyzer.h"
  8#include "FWCore/Utilities/interface/InputTag.h"
  9#include "FWCore/Framework/interface/Event.h"
 10#include "DataFormats/Common/interface/Handle.h"
 11#include "DataFormats/Candidate/interface/Particle.h"
 12#include "DataFormats/Candidate/interface/Candidate.h"
 13#include "DataFormats/Candidate/interface/CandMatchMap.h"
 14#include "DataFormats/PatCandidates/interface/Muon.h"
 15#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
 16#include "FWCore/ServiceRegistry/interface/Service.h"
 17#include "CommonTools/UtilAlgos/interface/TFileService.h"
 18#include "FWCore/ParameterSet/interface/ParameterSet.h"
 19#include "DataFormats/Common/interface/AssociationVector.h"
 20#include "DataFormats/PatCandidates/interface/PATObject.h"
 21#include "TH1.h"
 22#include <vector>
 23#include <string>
 24#include <iostream>
 25#include <iterator>
 26using namespace edm;
 27using namespace std;
 28using namespace reco;
 29using namespace pat;
 30
 31class testAnalyzer : public edm::EDAnalyzer {
 32public:
 33  testAnalyzer(const edm::ParameterSet& pset);
 34private:
 35  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
 36  virtual void endJob() override;
 37  int SingleTrigger_ ,DoubleTrigger_ ,  NoTrigger_ , zmumuIncrement_ ;
 38  InputTag selectMuon_, zMuMu_ ;
 39  string pathName_;
 40  int  nbinsEta_;
 41  double minEta_ , maxEta_;
 42  int  nbinsPt_;
 43  double minPt_ , maxPt_;
 44  int nbinsEtaPt_;
 45  TH1D *h_pt_distribution_;
 46  TH1D *h_numberTrigMuon_, *h_numberMuon_ ;  
 47  TH1D *h_numberTrigMuon_ptStudy_, *h_numberMuon_ptStudy_ ;  
 48  TH1D *h_EtaDist_Pt80_; 
 49  vector<double> vectorPt , vectorEta ;
 50};
 51
 52testAnalyzer::testAnalyzer(const edm::ParameterSet& pset) : 
 53  selectMuon_( pset.getParameter<InputTag>( "selectMuon" ) ),
 54  zMuMu_( pset.getParameter<InputTag>( "ZMuMu" ) ),
 55  pathName_( pset.getParameter<string>( "pathName" ) ),
 56  nbinsEta_( pset.getParameter<int>( "EtaBins" ) ),
 57  minEta_( pset.getParameter<double>( "minEta" ) ),
 58  maxEta_( pset.getParameter<double>( "maxEta" ) ),
 59  nbinsPt_( pset.getParameter<int>( "PtBins" ) ),
 60  minPt_( pset.getParameter<double>( "minPt" ) ),
 61  maxPt_( pset.getParameter<double>( "maxPt" ) ),
 62  nbinsEtaPt_( pset.getParameter<int>( "EtaPt80Bins" ) ){
 63  SingleTrigger_= 0;
 64  DoubleTrigger_= 0;
 65  NoTrigger_= 0;
 66  zmumuIncrement_=0;
 67  Service<TFileService> fs;
 68  h_pt_distribution_ = fs->make<TH1D>("PtResolution ","Pt Resolution",200,-4.,4.);
 69  h_numberMuon_ = fs->make<TH1D>("Denominatore","Number of Muons vs Eta",nbinsEta_,minEta_,maxEta_);
 70  h_numberTrigMuon_ = fs->make<TH1D>("NumeratoreTrigMuon","Number of Triggered Muons vs Eta",nbinsEta_ ,minEta_,maxEta_); 
 71  h_numberMuon_ptStudy_ = fs->make<TH1D>("DenominatorePtStudy","Number of Muons vs Pt",nbinsPt_,minPt_,maxPt_);
 72  h_numberTrigMuon_ptStudy_ = fs->make<TH1D>("NumeratoreTrigMuonPtStudy","Number of Triggered Muons vs Pt",nbinsPt_,minPt_,maxPt_);
 73  h_EtaDist_Pt80_ = fs->make<TH1D>("EtaDistr","Eta distribution (Pt>80)",nbinsEtaPt_,minEta_,maxEta_);
 74}
 75
 76void testAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
 77  Handle<vector<pat::Muon> > selectMuon;
 78  event.getByLabel(selectMuon_, selectMuon);
 79  Handle<CandidateView> zMuMu;
 80  event.getByLabel(zMuMu_, zMuMu);
 81  int zmumuSize = zMuMu->size();
 82  if(zmumuSize > 0){
 83    for( int i = 0; i < zmumuSize ; ++i){
 84      bool singleTrigFlag0 = false;
 85      bool singleTrigFlag1 = false;
 86      zmumuIncrement_++;
 87      const Candidate & zMuMuCand = (*zMuMu)[i];
 88      CandidateBaseRef dau0 = zMuMuCand.daughter(0)->masterClone();
 89      CandidateBaseRef dau1 = zMuMuCand.daughter(1)->masterClone();
 90      const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0);//cast in patMuon
 91      const pat::Muon& mu1 = dynamic_cast<const pat::Muon&>(*dau1);
 92      const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
 93	mu0.triggerObjectMatchesByPath( pathName_ );
 94      const pat::TriggerObjectStandAloneCollection mu1HLTMatches = 
 95	mu1.triggerObjectMatchesByPath( pathName_ );
 96      double EtaPatMu0 = mu0.eta();
 97      double EtaPatMu1 = mu1.eta();
 98      double PtPatMu0 = mu0.pt();
 99      double PtPatMu1 = mu1.pt();
100      h_numberMuon_->Fill(EtaPatMu0);
101      h_numberMuon_->Fill(EtaPatMu1);
102      h_numberMuon_ptStudy_->Fill(PtPatMu0);
103      h_numberMuon_ptStudy_->Fill(PtPatMu1);
104      int dimTrig0 = mu0HLTMatches.size();
105      int dimTrig1 = mu1HLTMatches.size();
106      if(dimTrig0 !=0){
107	for(int j = 0; j < dimTrig0 ; ++j){
108	singleTrigFlag0 = true;
109	h_numberTrigMuon_->Fill(EtaPatMu0);
110	h_numberTrigMuon_ptStudy_->Fill(PtPatMu0);
111	double PtTrig = mu0HLTMatches[j].pt();
112	double PtDif = PtTrig-PtPatMu0;
113	h_pt_distribution_->Fill(PtDif);
114	}
115      }
116      else{
117	if(PtPatMu0>80) {
118	  h_EtaDist_Pt80_->Fill(EtaPatMu0);
119	  vectorPt.push_back(PtPatMu0);
120	  vectorEta.push_back(EtaPatMu0);
121	}
122      }
123      if(dimTrig1 !=0){
124	for(int j = 0; j < dimTrig1 ; ++j){
125	  singleTrigFlag1 = true;
126	  h_numberTrigMuon_->Fill(EtaPatMu1);
127	  h_numberTrigMuon_ptStudy_->Fill(PtPatMu1);
128	  double PtTrig = mu0HLTMatches[j].pt();
129	  double PtDif = PtTrig-PtPatMu1;
130	  h_pt_distribution_->Fill(PtDif);
131	}
132      }	 
133      else{
134	if(PtPatMu0>80) {
135	  h_EtaDist_Pt80_->Fill(EtaPatMu1);
136	  vectorPt.push_back(PtPatMu0);
137	  vectorEta.push_back(EtaPatMu0);
138	}
139      }
140      
141      if(singleTrigFlag0 && singleTrigFlag1)DoubleTrigger_++;
142      if(singleTrigFlag0 && !singleTrigFlag1)SingleTrigger_++;
143      if(!singleTrigFlag0 && singleTrigFlag1)SingleTrigger_++;
144      if(!singleTrigFlag0 && !singleTrigFlag1)NoTrigger_++;
145
146    }//end loop on ZMuMu candidates
147  }//end check on ZMuMu
148 
149}  
150
151void testAnalyzer::endJob() {
152  cout<< "DoubleTrigger = " << DoubleTrigger_ << " , SingleTrigger = " << SingleTrigger_ << " , NoTrigger = "<< NoTrigger_ <<" ,zmumuIncrement = "<< zmumuIncrement_ << endl;
153  double OneTrig = (double)SingleTrigger_/(double)zmumuIncrement_;
154  double DoubleTrig = (double)DoubleTrigger_/(double)zmumuIncrement_;
155  cout<< "eps^2 = " <<  DoubleTrig << endl;
156  cout<< "2eps(1 - eps) = " << OneTrig << endl;
157  int dimVec =vectorPt.size();
158  for(int i = 0; i<dimVec; ++i) cout << "Pt = " << vectorPt[i] << " ==> Eta = " << vectorEta[i] << endl;
159}
160
161#include "FWCore/Framework/interface/MakerMacros.h"
162
163DEFINE_FWK_MODULE(testAnalyzer);
164