CMS 3D CMS Logo

PatTriggerAnalyzer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1D.h"
5 #include "TH2D.h"
6 
14 
16 public:
18  explicit PatTriggerAnalyzer(const edm::ParameterSet& iConfig);
20  ~PatTriggerAnalyzer() override;
21 
22 private:
24  void beginJob() override;
26  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
28  void endJob() override;
29 
39  unsigned minID_;
41  unsigned maxID_;
42 
44  std::map<std::string, TH1D*> histos1D_;
45  std::map<std::string, TH2D*> histos2D_;
46 
48  std::map<unsigned, unsigned> sumN_;
49  std::map<unsigned, double> sumPt_;
50 };
51 
52 #include "TMath.h"
53 
57 
58 using namespace pat;
59 
61  : // pat::Trigger
62  trigger_(iConfig.getParameter<edm::InputTag>("trigger")),
63  // pat::TriggerEvent
64  triggerEventToken_(consumes<TriggerEvent>(iConfig.getParameter<edm::InputTag>("triggerEvent"))),
65  // muon input collection
66  muonsToken_(consumes<MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
67  // muon match objects
68  muonMatch_(iConfig.getParameter<std::string>("muonMatch")),
69  // minimal id for of all trigger objects
70  minID_(iConfig.getParameter<unsigned>("minID")),
71  // maximal id for of all trigger objects
72  maxID_(iConfig.getParameter<unsigned>("maxID")),
73  histos1D_(),
74  histos2D_() {}
75 
77 
80 
81  // pt correlation plot
82  histos2D_["ptTrigCand"] =
83  fileService->make<TH2D>("ptTrigCand", "Object vs. candidate p_{T} (GeV)", 60, 0., 300., 60, 0., 300.);
84  histos2D_["ptTrigCand"]->SetXTitle("candidate p_{T} (GeV)");
85  histos2D_["ptTrigCand"]->SetYTitle("object p_{T} (GeV)");
86  // eta correlation plot
87  histos2D_["etaTrigCand"] =
88  fileService->make<TH2D>("etaTrigCand", "Object vs. candidate #eta", 50, -2.5, 2.5, 50, -2.5, 2.5);
89  histos2D_["etaTrigCand"]->SetXTitle("candidate #eta");
90  histos2D_["etaTrigCand"]->SetYTitle("object #eta");
91  // phi correlation plot
92  histos2D_["phiTrigCand"] = fileService->make<TH2D>(
93  "phiTrigCand", "Object vs. candidate #phi", 60, -TMath::Pi(), TMath::Pi(), 60, -TMath::Pi(), TMath::Pi());
94  histos2D_["phiTrigCand"]->SetXTitle("candidate #phi");
95  histos2D_["phiTrigCand"]->SetYTitle("object #phi");
96  // turn-on curves
97  histos1D_["turnOn"] = fileService->make<TH1D>("turnOn", "p_{T} (GeV) of matched candidate", 10, 0., 50.);
98  histos1D_["turnOn"]->SetXTitle("candidate p_{T} (GeV)");
99  histos1D_["turnOn"]->SetYTitle("# of objects");
100  // mean pt for all trigger objects
101  histos1D_["ptMean"] = fileService->make<TH1D>(
102  "ptMean", "Mean p_{T} (GeV) per trigger object type", maxID_ - minID_ + 1, minID_ - 0.5, maxID_ + 0.5);
103  histos1D_["ptMean"]->SetXTitle("trigger object type");
104  histos1D_["ptMean"]->SetYTitle("mean p_{T} (GeV)");
105 
106  // initialize counters for mean pt calculation
107  for (unsigned id = minID_; id <= maxID_; ++id) {
108  sumN_[id] = 0;
109  sumPt_[id] = 0.;
110  }
111 }
112 
114  // PAT trigger event
117 
118  // PAT object collection
120  iEvent.getByToken(muonsToken_, muons);
121 
122  // PAT trigger helper for trigger matching information
123  const helper::TriggerMatchHelper matchHelper;
124 
125  /*
126  kinematics comparison
127  */
128 
129  // loop over muon references (PAT muons have been used in the matcher in task 3)
130  for (size_t iMuon = 0; iMuon < muons->size(); ++iMuon) {
131  // we need all these ingedients to recieve matched trigger objects from the matchHelper
132  const TriggerObjectRef trigRef(matchHelper.triggerMatchObject(muons, iMuon, muonMatch_, iEvent, *triggerEvent));
133  // finally we can fill the histograms
134  if (trigRef.isAvailable() && trigRef.isNonnull()) { // check references (necessary!)
135  histos2D_["ptTrigCand"]->Fill(muons->at(iMuon).pt(), trigRef->pt());
136  histos2D_["etaTrigCand"]->Fill(muons->at(iMuon).eta(), trigRef->eta());
137  histos2D_["phiTrigCand"]->Fill(muons->at(iMuon).phi(), trigRef->phi());
138  }
139  }
140 
141  /*
142  turn-on curve
143  */
144 
145  // get the trigger objects corresponding to the used matching (HLT muons)
146  const TriggerObjectRefVector trigRefs(triggerEvent->objects(trigger::TriggerMuon));
147  // loop over selected trigger objects
148  for (TriggerObjectRefVector::const_iterator iTrig = trigRefs.begin(); iTrig != trigRefs.end(); ++iTrig) {
149  // get all matched candidates for the trigger object
150  const reco::CandidateBaseRefVector candRefs(
151  matchHelper.triggerMatchCandidates((*iTrig), muonMatch_, iEvent, *triggerEvent));
152  if (candRefs.empty())
153  continue;
154  // fill the histogram...
155  // (only for the first match, since we resolved ambiguities in the matching configuration,
156  // so that we have one at maximum per trigger object)
157  reco::CandidateBaseRef muonRef(candRefs.at(0));
158  if (muonRef.isAvailable() && muonRef.isNonnull()) {
159  histos1D_["turnOn"]->Fill(muonRef->pt());
160  }
161  }
162 
163  /*
164  mean pt
165  */
166 
167  // loop over all trigger match objects from minID to maxID; have
168  // a look to DataFormats/HLTReco/interface/TriggerTypeDefs.h to
169  // know more about the available trrigger object id's
170  for (unsigned id = minID_; id <= maxID_; ++id) {
171  // vector of all objects for a given object id
172  const TriggerObjectRefVector objRefs(triggerEvent->objects(id));
173  // buffer the number of objects
174  sumN_[id] += objRefs.size();
175  // iterate the objects and buffer the pt of the objects
176  for (TriggerObjectRefVector::const_iterator iRef = objRefs.begin(); iRef != objRefs.end(); ++iRef) {
177  sumPt_[id] += (*iRef)->pt();
178  }
179  }
180 }
181 
183  // normalize the entries for the mean pt plot
184  for (unsigned id = minID_; id <= maxID_; ++id) {
185  if (sumN_[id] != 0)
186  histos1D_["ptMean"]->Fill(id, sumPt_[id] / sumN_[id]);
187  }
188 }
189 
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PatTriggerAnalyzer::histos1D_
std::map< std::string, TH1D * > histos1D_
histogram management
Definition: PatTriggerAnalyzer.cc:44
TriggerHelper.h
PatTriggerAnalyzer::beginJob
void beginJob() override
everythin that needs to be done before the event loop
Definition: PatTriggerAnalyzer.cc:78
PatTriggerAnalyzer::sumN_
std::map< unsigned, unsigned > sumN_
internals for meanPt histogram calculation
Definition: PatTriggerAnalyzer.cc:48
PatTriggerAnalyzer::sumPt_
std::map< unsigned, double > sumPt_
Definition: PatTriggerAnalyzer.cc:49
fileService
edm::Service< TFileService > fileService
Definition: HSCPValidator.cc:91
pat::TriggerEvent
Analysis-level trigger event class.
Definition: TriggerEvent.h:39
edm::EDGetTokenT< pat::TriggerEvent >
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
EDAnalyzer.h
edm::RefVector
Definition: EDProductfwd.h:27
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
trigger::TriggerMuon
Definition: TriggerTypeDefs.h:68
pat::MuonCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
PatTriggerAnalyzer::histos2D_
std::map< std::string, TH2D * > histos2D_
Definition: PatTriggerAnalyzer.cc:45
PatTriggerAnalyzer::PatTriggerAnalyzer
PatTriggerAnalyzer(const edm::ParameterSet &iConfig)
default constructor
Definition: PatTriggerAnalyzer.cc:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileService.h
PatTriggerAnalyzer::muonMatch_
std::string muonMatch_
input for trigger match objects
Definition: PatTriggerAnalyzer.cc:37
edm::ParameterSet
Definition: ParameterSet.h:47
PatTriggerAnalyzer::trigger_
edm::InputTag trigger_
input for patTrigger
Definition: PatTriggerAnalyzer.cc:31
Event.h
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
PatTriggerAnalyzer::~PatTriggerAnalyzer
~PatTriggerAnalyzer() override
default destructor
Definition: PatTriggerAnalyzer.cc:76
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
PatTriggerAnalyzer::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
everythin that needs to be done during the event loop
Definition: PatTriggerAnalyzer.cc:113
PDWG_DiPhoton_SD_cff.triggerEvent
triggerEvent
Definition: PDWG_DiPhoton_SD_cff.py:39
edm::RefToBaseVector
Definition: EDProductfwd.h:29
PatTriggerAnalyzer
Definition: PatTriggerAnalyzer.cc:15
PatTriggerAnalyzer::triggerEventToken_
edm::EDGetTokenT< pat::TriggerEvent > triggerEventToken_
input for patTriggerEvent
Definition: PatTriggerAnalyzer.cc:33
InputTag.h
PatTriggerAnalyzer::maxID_
unsigned maxID_
maximal id for meanPt plot
Definition: PatTriggerAnalyzer.cc:41
PatTriggerAnalyzer::muonsToken_
edm::EDGetTokenT< pat::MuonCollection > muonsToken_
input for muons
Definition: PatTriggerAnalyzer.cc:35
std
Definition: JetResolutionObject.h:76
TriggerEvent.h
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
edm::RefVectorIterator
Definition: EDProductfwd.h:33
PatTriggerAnalyzer::endJob
void endJob() override
everythin that needs to be done after the event loop
Definition: PatTriggerAnalyzer.cc:182
edm::RefToBase< Candidate >
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
PatTriggerAnalyzer::minID_
unsigned minID_
minimal id for meanPt plot
Definition: PatTriggerAnalyzer.cc:39
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64