CMS 3D CMS Logo

HigPhotonJetHLTOfflineSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HigPhotonJetHLTOfflineSource
4 // Class: HigPhotonJetHLTOfflineSource
5 //
6 
7 //
8 // Author: Xin Shi <Xin.Shi@cern.ch>
9 // Created: 2014.07.22
10 //
11 
12 // system include files
13 #include <memory>
14 #include <iostream>
15 
16 // user include files
20 
28 
30 
42 
43 #include <TLorentzVector.h>
44 #include <TH2F.h>
45 
46 // Define the interface
48 
49 public:
50 
52 
53 private:
54 
55  // Analyzer Methods
56  void dqmBeginRun(const edm::Run &,
57  const edm::EventSetup &) override;
59  edm::Run const &,
60  edm::EventSetup const &) override;
61  void analyze(const edm::Event &,
62  const edm::EventSetup &) override;
63  void endRun(const edm::Run &,
64  const edm::EventSetup &) override;
67 
68  // Input from Configuration File
71  std::vector<std::string> hltPathsToCheck_;
73  bool verbose_;
75 
81 
82  double pfjetMinPt_;
83  double photonMinPt_;
84 
85  // Member Variables
86 
113 
114  double evtsrun_;
115 
116 };
117 
118 
119 // Class Methods
120 
122  pset_(pset)
123 {
124  hltProcessName_ = pset.getParameter<std::string>("hltProcessName");
125  hltPathsToCheck_ = pset.getParameter<std::vector<std::string>>("hltPathsToCheck");
126  verbose_ = pset.getUntrackedParameter<bool>("verbose", false);
127  triggerAccept_ = pset.getUntrackedParameter<bool>("triggerAccept", true);
128  triggerResultsToken_ = consumes <edm::TriggerResults> (pset.getParameter<edm::InputTag>("triggerResultsToken"));
129  dirname_ = pset.getUntrackedParameter<std::string>("dirname", std::string("HLT/Higgs/PhotonJet/"));
130  pvToken_ = consumes<reco::VertexCollection> (pset.getParameter<edm::InputTag>("pvToken"));
131  photonsToken_ = consumes<reco::PhotonCollection> (pset.getParameter<edm::InputTag>("photonsToken"));
132  pfMetToken_ = consumes<reco::PFMETCollection> (pset.getParameter<edm::InputTag>("pfMetToken"));
133  pfJetsToken_ = consumes<reco::PFJetCollection> (pset.getParameter<edm::InputTag>("pfJetsToken"));
134  pfjetMinPt_ = pset.getUntrackedParameter<double>("pfjetMinPt", 0.0);
135  photonMinPt_ = pset.getUntrackedParameter<double>("photonMinPt", 0.0);
136 }
137 
138 void
140  const edm::EventSetup & iSetup)
141 { // Initialize hltConfig
142  HLTConfigProvider hltConfig;
143  bool changedConfig;
144  if (!hltConfig.init(iRun, iSetup, hltProcessName_, changedConfig)) {
145  edm::LogError("HLTPhotonJetVal") << "Initialization of HLTConfigProvider failed!!";
146  return;
147  }
148 
149  evtsrun_ = 0;
150 }
151 
152 
153 void
155  edm::Run const & iRun,
156  edm::EventSetup const & iSetup)
157 {
158  iBooker.setCurrentFolder(dirname_);
159  nvertices_reco_ = iBooker.book1D("nvertices_reco", "Reco: Number of vertices", 100, 0, 100);
160  nvertices_ = iBooker.book1D("nvertices", "Number of vertices", 100, 0, 100);
161  nphotons_reco_ = iBooker.book1D("nphotons_reco", "Reco: Number of photons", 100, 0, 10);
162  nphotons_ = iBooker.book1D("nphotons", "Number of photons", 100, 0, 10);
163  photonpt_reco_ = iBooker.book1D("photonpt_reco", "Reco: Photons pT", 100, 0, 500);
164  photonpt_ = iBooker.book1D("photonpt", "Photons pT", 100, 0, 500);
165  photonrapidity_reco_ = iBooker.book1D("photonrapidity_reco", "Reco: Photons rapidity;y_{#gamma}", 100, -2.5, 2.5);
166  photonrapidity_ = iBooker.book1D("photonrapidity", "Photons rapidity;y_{#gamma}", 100, -2.5, 2.5);
167  pfmet_reco_ = iBooker.book1D("pfmet_reco", "Reco: PF MET", 100, 0, 250);
168  pfmet_ = iBooker.book1D("pfmet", "PF MET", 100, 0, 250);
169  pfmetphi_reco_ = iBooker.book1D("pfmetphi_reco", "Reco: PF MET phi;#phi_{PFMET}", 100, -4, 4);
170  pfmetphi_ = iBooker.book1D("pfmetphi", "PF MET phi;#phi_{PFMET}", 100, -4, 4);
171  delphiphomet_reco_ = iBooker.book1D("delphiphomet_reco", "Reco: #Delta#phi(photon, MET);#Delta#phi(#gamma,MET)", 100, 0, 4);
172  delphiphomet_ = iBooker.book1D("delphiphomet", "#Delta#phi(photon, MET);#Delta#phi(#gamma,MET)", 100, 0, 4);
173  npfjets_reco_ = iBooker.book1D("npfjets_reco", "Reco: Number of PF Jets", 100, 0, 20);
174  npfjets_ = iBooker.book1D("npfjets", "Number of PF Jets", 100, 0, 20);
175  delphijetmet_reco_ = iBooker.book1D("delphijetmet_reco", "Reco: #Delta#phi(PFJet, MET);#Delta#phi(Jet,MET)", 100, 0, 4);
176  delphijetmet_ = iBooker.book1D("delphijetmet", "#Delta#phi(PFJet, MET);#Delta#phi(Jet,MET)", 100, 0, 4);
177  invmassjj_reco_ = iBooker.book1D("invmassjj_reco", "Reco: Inv mass two leading jets;M_{jj}[GeV]", 100, 0, 2000);
178  invmassjj_ = iBooker.book1D("invmassjj", "Inv mass two leading jets;M_{jj}[GeV]", 100, 0, 2000);
179  deletajj_reco_ = iBooker.book1D("deletajj_reco", "Reco: #Delta#eta(jj);|#Delta#eta_{jj}|", 100, 0, 6);
180  deletajj_ = iBooker.book1D("deletajj", "#Delta#eta(jj);|#Delta#eta_{jj}|", 100, 0, 6);
181  triggers_reco_ = iBooker.book1D("triggers_reco", "Reco: Triggers", hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
182  triggers_ = iBooker.book1D("triggers", "Triggers", hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
183  trigvsnvtx_reco_ = iBooker.book2D("trigvsnvtx_reco", "Reco: Trigger vs. # vertices;N_{vertices};Trigger", 100, 0, 100, hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
184  trigvsnvtx_ = iBooker.book2D("trigvsnvtx", "Trigger vs. # vertices;N_{vertices};Trigger", 100, 0, 100, hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
185 }
186 
187 
188 void
190  const edm::EventSetup& iSetup)
191 {
192  // Count total number of events in one run
193  evtsrun_++;
194 
196  iEvent.getByToken(triggerResultsToken_, triggerResults);
197  if(!triggerResults.isValid()) {
198  edm::LogError("HigPhotonJetHLT")<<"Missing triggerResults collection" << std::endl;
199  return;
200  }
201 
202  // Check whether contains monitored trigger and accepted
203  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
204  bool triggered = isMonitoredTriggerAccepted(triggerNames, triggerResults);
205 
206  // if (!triggered) return;
207 
208  // Test scale
209  // if (evtsrun_ > 10) return;
210 
211  // N Vertices
213  iEvent.getByToken(pvToken_, vertices);
214  if(!vertices.isValid()) return;
215  if (verbose_)
216  std::cout << "xshi:: N vertices : " << vertices->size() << std::endl;
217 
218  // Set trigger name labels
219  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
221  }
222 
223  // Fill trigger info
224  for (unsigned int itrig = 0; itrig < triggerResults->size(); itrig++){
225  const std::string& triggername = triggerNames.triggerName(itrig);
226  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
227  if ( triggername.find(hltPathsToCheck_[i]) != std::string::npos) {
228  triggers_reco_->Fill(i);
229  trigvsnvtx_reco_->Fill(vertices->size(), i);
230  if (triggered) triggers_->Fill(i);
231  if (triggered) trigvsnvtx_->Fill(vertices->size(), i);
232  }
233  }
234  }
235 
236  nvertices_reco_->Fill(vertices->size());
237  if (triggered) nvertices_->Fill(vertices->size());
238 
239  // PF MET
241  iEvent.getByToken(pfMetToken_, pfmets);
242  if (!pfmets.isValid()) return;
243  const reco::PFMET pfmet = pfmets->front();
244  pfmet_reco_->Fill(pfmet.et());
245  if (triggered) pfmet_->Fill(pfmet.et());
246  if (verbose_)
247  std::cout << "xshi:: number of pfmets: " << pfmets->size() << std::endl;
248 
249  pfmetphi_reco_->Fill(pfmet.phi());
250  if (triggered) pfmetphi_->Fill(pfmet.phi());
251 
252  // Photons
254  iEvent.getByToken(photonsToken_, photons);
255  if(!photons.isValid()) return;
256  int nphotons = 0;
257  for(auto const & phoIter : *photons){
258  if (phoIter.pt() < photonMinPt_ ) continue;
259  nphotons++;
260  photonpt_reco_->Fill(phoIter.pt());
261  photonrapidity_reco_->Fill(phoIter.rapidity());
262  if (triggered) photonpt_->Fill(phoIter.pt());
263  if (triggered) photonrapidity_->Fill(phoIter.rapidity());
264  double tmp_delphiphomet = fabs(deltaPhi(phoIter.phi(), pfmet.phi()));
265  delphiphomet_reco_->Fill(tmp_delphiphomet);
266  if (triggered) delphiphomet_->Fill(tmp_delphiphomet);
267  }
268  nphotons_reco_->Fill(nphotons);
269  if (triggered) nphotons_->Fill(nphotons);
270 
271  // PF Jet
273  iEvent.getByToken(pfJetsToken_, pfjets);
274  if(!pfjets.isValid()) return;
275  if (verbose_)
276  std::cout << "xshi:: N pfjets : " << pfjets->size() << std::endl;
277 
278  double min_delphijetmet = 6.0;
279  TLorentzVector p4jet1, p4jet2, p4jj;
280  // Two leading jets eta
281  double etajet1(0), etajet2(0);
282  int njet = 0;
283  for(auto const & jetIter : *pfjets){
284  if (jetIter.pt() < pfjetMinPt_ ) continue;
285  njet++;
286 
287  double tmp_delphijetmet = fabs(deltaPhi(jetIter.phi(), pfmet.phi()));
288  if (tmp_delphijetmet < min_delphijetmet)
289  min_delphijetmet = tmp_delphijetmet;
290 
291  if (njet == 1) {
292  p4jet1.SetXYZM(jetIter.px(), jetIter.py(), jetIter.pz(), jetIter.mass());
293  etajet1 = jetIter.eta();
294  }
295  if (njet == 2){
296  p4jet2.SetXYZM(jetIter.px(), jetIter.py(), jetIter.pz(), jetIter.mass());
297  etajet2 = jetIter.eta();
298  }
299  }
300  npfjets_reco_->Fill(njet);
301  if (triggered) npfjets_->Fill(njet);
302 
303  delphijetmet_reco_->Fill(min_delphijetmet);
304  if (triggered) delphijetmet_->Fill(min_delphijetmet);
305  p4jj = p4jet1 + p4jet2;
306  double deletajj = etajet1 - etajet2 ;
307  if (verbose_)
308  std::cout << "xshi:: invmass jj " << p4jj.M() << std::endl;
309 
310  invmassjj_reco_->Fill(p4jj.M());
311  deletajj_reco_->Fill(deletajj);
312  if (triggered) invmassjj_->Fill(p4jj.M());
313  if (triggered) deletajj_->Fill(deletajj);
314 }
315 
316 
317 void
319  const edm::EventSetup& iSetup)
320 {
321  // Normalize to the total number of events in the run
322  TH2F* h = trigvsnvtx_->getTH2F();
323  double integral = h->Integral();
324  double norm = (integral > 0.) ? evtsrun_*hltPathsToCheck_.size()/integral : 1.;
325  h->Scale(norm);
326  if (verbose_) {
327  std::cout << "xshi:: endRun total number of events: " << evtsrun_
328  << ", integral = " << h->Integral()
329  << ", norm = " << norm << std::endl;
330  }
331 }
332 
333 bool
336 {
337  for (unsigned int itrig = 0; itrig < triggerResults->size(); itrig++){
338  // Only consider the triggered case.
339  if ( triggerAccept_ && ( (*triggerResults)[itrig].accept() != 1) ) continue;
340  const std::string& triggername = triggerNames.triggerName(itrig);
341  for (auto const & i : hltPathsToCheck_) {
342  if ( triggername.find(i) != std::string::npos) {
343  return true;
344  }
345  }
346  }
347 
348  return false;
349 }
350 
351 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::PFJetCollection > pfJetsToken_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::PFMETCollection > pfMetToken_
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
edm::EDGetTokenT< reco::VertexCollection > pvToken_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
void endRun(const edm::Run &, const edm::EventSetup &) override
void Fill(long long x)
virtual double phi() const final
momentum azimuthal angle
virtual double et() const final
transverse energy
edm::EDGetTokenT< reco::PhotonCollection > photonsToken_
int iEvent
Definition: GenABIO.cc:230
unsigned int size() const
Get number of paths stored.
void analyze(const edm::Event &, const edm::EventSetup &) override
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool isValid() const
Definition: HandleBase.h:74
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:69
HigPhotonJetHLTOfflineSource(const edm::ParameterSet &)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
bool isMonitoredTriggerAccepted(const edm::TriggerNames &, const edm::Handle< edm::TriggerResults > &)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::vector< std::string > hltPathsToCheck_
TH2F * getTH2F(void) const
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:239
Definition: Run.h:42