CMS 3D CMS Logo

triggerEfficiency.cc
Go to the documentation of this file.
1 /* \class testAnalyzer
2  * author: Noli Pasquale
3  * version 0.1
4  * TriggerEfficiency module
5  *
6  */
21 #include "TH1.h"
22 #include <vector>
23 #include <string>
24 #include <iostream>
25 #include <iterator>
26 using namespace edm;
27 using namespace std;
28 using namespace reco;
29 using namespace pat;
30 
31 class testAnalyzer : public edm::EDAnalyzer {
32 public:
34 
35 private:
36  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
37  void endJob() override;
38  int SingleTrigger_, DoubleTrigger_, NoTrigger_, zmumuIncrement_;
41  string pathName_;
42  int nbinsEta_;
43  double minEta_, maxEta_;
44  int nbinsPt_;
45  double minPt_, maxPt_;
48  TH1D *h_numberTrigMuon_, *h_numberMuon_;
49  TH1D *h_numberTrigMuon_ptStudy_, *h_numberMuon_ptStudy_;
51  vector<double> vectorPt, vectorEta;
52 };
53 
55  : selectMuonToken_(consumes<vector<pat::Muon> >(pset.getParameter<InputTag>("selectMuon"))),
56  zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("ZMuMu"))),
57  pathName_(pset.getParameter<string>("pathName")),
58  nbinsEta_(pset.getParameter<int>("EtaBins")),
59  minEta_(pset.getParameter<double>("minEta")),
60  maxEta_(pset.getParameter<double>("maxEta")),
61  nbinsPt_(pset.getParameter<int>("PtBins")),
62  minPt_(pset.getParameter<double>("minPt")),
63  maxPt_(pset.getParameter<double>("maxPt")),
64  nbinsEtaPt_(pset.getParameter<int>("EtaPt80Bins")) {
65  SingleTrigger_ = 0;
66  DoubleTrigger_ = 0;
67  NoTrigger_ = 0;
68  zmumuIncrement_ = 0;
70  h_pt_distribution_ = fs->make<TH1D>("PtResolution ", "Pt Resolution", 200, -4., 4.);
71  h_numberMuon_ = fs->make<TH1D>("Denominatore", "Number of Muons vs Eta", nbinsEta_, minEta_, maxEta_);
73  fs->make<TH1D>("NumeratoreTrigMuon", "Number of Triggered Muons vs Eta", nbinsEta_, minEta_, maxEta_);
74  h_numberMuon_ptStudy_ = fs->make<TH1D>("DenominatorePtStudy", "Number of Muons vs Pt", nbinsPt_, minPt_, maxPt_);
76  fs->make<TH1D>("NumeratoreTrigMuonPtStudy", "Number of Triggered Muons vs Pt", nbinsPt_, minPt_, maxPt_);
77  h_EtaDist_Pt80_ = fs->make<TH1D>("EtaDistr", "Eta distribution (Pt>80)", nbinsEtaPt_, minEta_, maxEta_);
78 }
79 
81  Handle<vector<pat::Muon> > selectMuon;
82  event.getByToken(selectMuonToken_, selectMuon);
84  event.getByToken(zMuMuToken_, zMuMu);
85  int zmumuSize = zMuMu->size();
86  if (zmumuSize > 0) {
87  for (int i = 0; i < zmumuSize; ++i) {
88  bool singleTrigFlag0 = false;
89  bool singleTrigFlag1 = false;
91  const Candidate& zMuMuCand = (*zMuMu)[i];
92  CandidateBaseRef dau0 = zMuMuCand.daughter(0)->masterClone();
93  CandidateBaseRef dau1 = zMuMuCand.daughter(1)->masterClone();
94  const pat::Muon& mu0 = dynamic_cast<const pat::Muon&>(*dau0); //cast in patMuon
95  const pat::Muon& mu1 = dynamic_cast<const pat::Muon&>(*dau1);
98  double EtaPatMu0 = mu0.eta();
99  double EtaPatMu1 = mu1.eta();
100  double PtPatMu0 = mu0.pt();
101  double PtPatMu1 = mu1.pt();
102  h_numberMuon_->Fill(EtaPatMu0);
103  h_numberMuon_->Fill(EtaPatMu1);
104  h_numberMuon_ptStudy_->Fill(PtPatMu0);
105  h_numberMuon_ptStudy_->Fill(PtPatMu1);
106  int dimTrig0 = mu0HLTMatches.size();
107  int dimTrig1 = mu1HLTMatches.size();
108  if (dimTrig0 != 0) {
109  for (int j = 0; j < dimTrig0; ++j) {
110  singleTrigFlag0 = true;
111  h_numberTrigMuon_->Fill(EtaPatMu0);
112  h_numberTrigMuon_ptStudy_->Fill(PtPatMu0);
113  double PtTrig = mu0HLTMatches[j].pt();
114  double PtDif = PtTrig - PtPatMu0;
115  h_pt_distribution_->Fill(PtDif);
116  }
117  } else {
118  if (PtPatMu0 > 80) {
119  h_EtaDist_Pt80_->Fill(EtaPatMu0);
120  vectorPt.push_back(PtPatMu0);
121  vectorEta.push_back(EtaPatMu0);
122  }
123  }
124  if (dimTrig1 != 0) {
125  for (int j = 0; j < dimTrig1; ++j) {
126  singleTrigFlag1 = true;
127  h_numberTrigMuon_->Fill(EtaPatMu1);
128  h_numberTrigMuon_ptStudy_->Fill(PtPatMu1);
129  double PtTrig = mu0HLTMatches[j].pt();
130  double PtDif = PtTrig - PtPatMu1;
131  h_pt_distribution_->Fill(PtDif);
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)
142  DoubleTrigger_++;
143  if (singleTrigFlag0 && !singleTrigFlag1)
144  SingleTrigger_++;
145  if (!singleTrigFlag0 && singleTrigFlag1)
146  SingleTrigger_++;
147  if (!singleTrigFlag0 && !singleTrigFlag1)
148  NoTrigger_++;
149 
150  } //end loop on ZMuMu candidates
151  } //end check on ZMuMu
152 }
153 
155  cout << "DoubleTrigger = " << DoubleTrigger_ << " , SingleTrigger = " << SingleTrigger_
156  << " , NoTrigger = " << NoTrigger_ << " ,zmumuIncrement = " << zmumuIncrement_ << endl;
157  double OneTrig = (double)SingleTrigger_ / (double)zmumuIncrement_;
158  double DoubleTrig = (double)DoubleTrigger_ / (double)zmumuIncrement_;
159  cout << "eps^2 = " << DoubleTrig << endl;
160  cout << "2eps(1 - eps) = " << OneTrig << endl;
161  int dimVec = vectorPt.size();
162  for (int i = 0; i < dimVec; ++i)
163  cout << "Pt = " << vectorPt[i] << " ==> Eta = " << vectorEta[i] << endl;
164 }
165 
167 
void endJob() override
double eta() const final
momentum pseudorapidity
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
TH1D * h_numberMuon_ptStudy_
vector< double > vectorEta
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
size_type size() const
double pt() const final
transverse momentum
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HeavyIon.h:7
EDGetTokenT< vector< pat::Muon > > selectMuonToken_
EDGetTokenT< CandidateView > zMuMuToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: Muon.py:1
TH1D * h_numberTrigMuon_
testAnalyzer(const edm::ParameterSet &pset)
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:682
virtual const CandidateBaseRef & masterClone() const =0
zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
fixed size matrix
TH1D * h_pt_distribution_
HLT enums.
TH1D * h_numberTrigMuon_ptStudy_
Analysis-level muon class.
Definition: Muon.h:51
Definition: event.py:1
vector< double > vectorPt