CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual void dqmBeginRun(const edm::Run &,
57  const edm::EventSetup &) override;
58  virtual void bookHistograms(DQMStore::IBooker &,
59  edm::Run const &,
60  edm::EventSetup const &) override;
61  virtual void analyze(const edm::Event &,
62  const edm::EventSetup &) override;
63  virtual 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
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  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(reco::PhotonCollection::const_iterator phoIter=photons->begin();
258  phoIter!=photons->end();++phoIter){
259  if (phoIter->pt() < photonMinPt_ ) continue;
260  nphotons++;
261  photonpt_reco_->Fill(phoIter->pt());
262  photonrapidity_reco_->Fill(phoIter->rapidity());
263  if (triggered) photonpt_->Fill(phoIter->pt());
264  if (triggered) photonrapidity_->Fill(phoIter->rapidity());
265  double tmp_delphiphomet = fabs(deltaPhi(phoIter->phi(), pfmet.phi()));
266  delphiphomet_reco_->Fill(tmp_delphiphomet);
267  if (triggered) delphiphomet_->Fill(tmp_delphiphomet);
268  }
269  nphotons_reco_->Fill(nphotons);
270  if (triggered) nphotons_->Fill(nphotons);
271 
272  // PF Jet
274  iEvent.getByToken(pfJetsToken_, pfjets);
275  if(!pfjets.isValid()) return;
276  if (verbose_)
277  std::cout << "xshi:: N pfjets : " << pfjets->size() << std::endl;
278 
279  double min_delphijetmet = 6.0;
280  TLorentzVector p4jet1, p4jet2, p4jj;
281  // Two leading jets eta
282  double etajet1(0), etajet2(0);
283  int njet = 0;
284  for(reco::PFJetCollection::const_iterator jetIter=pfjets->begin();
285  jetIter!=pfjets->end();++jetIter){
286  if (jetIter->pt() < pfjetMinPt_ ) continue;
287  njet++;
288 
289  double tmp_delphijetmet = fabs(deltaPhi(jetIter->phi(), pfmet.phi()));
290  if (tmp_delphijetmet < min_delphijetmet)
291  min_delphijetmet = tmp_delphijetmet;
292 
293  if (njet == 1) {
294  p4jet1.SetXYZM(jetIter->px(), jetIter->py(), jetIter->pz(), jetIter->mass());
295  etajet1 = jetIter->eta();
296  }
297  if (njet == 2){
298  p4jet2.SetXYZM(jetIter->px(), jetIter->py(), jetIter->pz(), jetIter->mass());
299  etajet2 = jetIter->eta();
300  }
301  }
302  npfjets_reco_->Fill(njet);
303  if (triggered) npfjets_->Fill(njet);
304 
305  delphijetmet_reco_->Fill(min_delphijetmet);
306  if (triggered) delphijetmet_->Fill(min_delphijetmet);
307  p4jj = p4jet1 + p4jet2;
308  double deletajj = etajet1 - etajet2 ;
309  if (verbose_)
310  std::cout << "xshi:: invmass jj " << p4jj.M() << std::endl;
311 
312  invmassjj_reco_->Fill(p4jj.M());
313  deletajj_reco_->Fill(deletajj);
314  if (triggered) invmassjj_->Fill(p4jj.M());
315  if (triggered) deletajj_->Fill(deletajj);
316 }
317 
318 
319 void
321  const edm::EventSetup& iSetup)
322 {
323  // Normalize to the total number of events in the run
324  TH2F* h = trigvsnvtx_->getTH2F();
325  double norm = evtsrun_*hltPathsToCheck_.size()/h->Integral();
326  h->Scale(norm);
327  if (verbose_) {
328  std::cout << "xshi:: endRun total number of events: " << evtsrun_
329  << ", integral = " << h->Integral()
330  << ", norm = " << norm << std::endl;
331  }
332 }
333 
334 bool
337 {
338  for (unsigned int itrig = 0; itrig < triggerResults->size(); itrig++){
339  // Only consider the triggered case.
340  if ( triggerAccept_ && ( (*triggerResults)[itrig].accept() != 1) ) continue;
341  std::string triggername = triggerNames.triggerName(itrig);
342  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
343  if ( triggername.find(hltPathsToCheck_[i]) != std::string::npos) {
344  return true;
345  }
346  }
347  }
348 
349  return false;
350 }
351 
352 //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_
int i
Definition: DBlmapReader.cc:9
virtual void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:215
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool isMonitoredTriggerAccepted(const edm::TriggerNames, const edm::Handle< edm::TriggerResults >)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual 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_
virtual double phi() const final
momentum azimuthal angle
edm::EDGetTokenT< reco::VertexCollection > pvToken_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
int njet
Definition: HydjetWrapper.h:95
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
void Fill(long long x)
edm::EDGetTokenT< reco::PhotonCollection > photonsToken_
int iEvent
Definition: GenABIO.cc:230
virtual 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:75
HigPhotonJetHLTOfflineSource(const edm::ParameterSet &)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
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
virtual double et() const final
transverse energy
tuple cout
Definition: gather_cfg.py:145
std::vector< std::string > hltPathsToCheck_
TH2F * getTH2F(void) const
Definition: Run.h:43