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
18 
26 
28 
40 
41 #include <TLorentzVector.h>
42 #include <TH2F.h>
43 
44 // Define the interface
46 public:
48 
49 private:
50  // Analyzer Methods
51  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
52  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54  void dqmEndRun(const edm::Run&, const edm::EventSetup&) override;
56 
57  // Input from Configuration File
60  std::vector<std::string> hltPathsToCheck_;
62  bool verbose_;
64  bool perLSsaving_; //to avoid nanoDQMIO crashing, driven by DQMServices/Core/python/DQMStore_cfi.py
65 
71 
72  double pfjetMinPt_;
73  double photonMinPt_;
74 
75  // Member Variables
76 
103 
104  double evtsrun_;
105 };
106 
107 // Class Methods
108 
110  hltProcessName_ = pset.getParameter<std::string>("hltProcessName");
111  hltPathsToCheck_ = pset.getParameter<std::vector<std::string>>("hltPathsToCheck");
112  verbose_ = pset.getUntrackedParameter<bool>("verbose", false);
113  perLSsaving_ = pset.getUntrackedParameter<bool>("perLSsaving", false);
114  triggerAccept_ = pset.getUntrackedParameter<bool>("triggerAccept", true);
115  triggerResultsToken_ = consumes<edm::TriggerResults>(pset.getParameter<edm::InputTag>("triggerResultsToken"));
116  dirname_ = pset.getUntrackedParameter<std::string>("dirname", std::string("HLT/Higgs/PhotonJet/"));
117  pvToken_ = consumes<reco::VertexCollection>(pset.getParameter<edm::InputTag>("pvToken"));
118  photonsToken_ = consumes<reco::PhotonCollection>(pset.getParameter<edm::InputTag>("photonsToken"));
119  pfMetToken_ = consumes<reco::PFMETCollection>(pset.getParameter<edm::InputTag>("pfMetToken"));
120  pfJetsToken_ = consumes<reco::PFJetCollection>(pset.getParameter<edm::InputTag>("pfJetsToken"));
121  pfjetMinPt_ = pset.getUntrackedParameter<double>("pfjetMinPt", 0.0);
122  photonMinPt_ = pset.getUntrackedParameter<double>("photonMinPt", 0.0);
123 }
124 
126  const edm::EventSetup& iSetup) { // Initialize hltConfig
128  bool changedConfig;
129  if (!hltConfig.init(iRun, iSetup, hltProcessName_, changedConfig)) {
130  edm::LogError("HLTPhotonJetVal") << "Initialization of HLTConfigProvider failed!!";
131  return;
132  }
133 
134  evtsrun_ = 0;
135 }
136 
138  edm::Run const& iRun,
139  edm::EventSetup const& iSetup) {
140  iBooker.setCurrentFolder(dirname_);
141  nvertices_reco_ = iBooker.book1D("nvertices_reco", "Reco: Number of vertices", 100, 0, 100);
142  nvertices_ = iBooker.book1D("nvertices", "Number of vertices", 100, 0, 100);
143  nphotons_reco_ = iBooker.book1D("nphotons_reco", "Reco: Number of photons", 100, 0, 10);
144  nphotons_ = iBooker.book1D("nphotons", "Number of photons", 100, 0, 10);
145  photonpt_reco_ = iBooker.book1D("photonpt_reco", "Reco: Photons pT", 100, 0, 500);
146  photonpt_ = iBooker.book1D("photonpt", "Photons pT", 100, 0, 500);
147  photonrapidity_reco_ = iBooker.book1D("photonrapidity_reco", "Reco: Photons rapidity;y_{#gamma}", 100, -2.5, 2.5);
148  photonrapidity_ = iBooker.book1D("photonrapidity", "Photons rapidity;y_{#gamma}", 100, -2.5, 2.5);
149  pfmet_reco_ = iBooker.book1D("pfmet_reco", "Reco: PF MET", 100, 0, 250);
150  pfmet_ = iBooker.book1D("pfmet", "PF MET", 100, 0, 250);
151  pfmetphi_reco_ = iBooker.book1D("pfmetphi_reco", "Reco: PF MET phi;#phi_{PFMET}", 100, -4, 4);
152  pfmetphi_ = iBooker.book1D("pfmetphi", "PF MET phi;#phi_{PFMET}", 100, -4, 4);
154  iBooker.book1D("delphiphomet_reco", "Reco: #Delta#phi(photon, MET);#Delta#phi(#gamma,MET)", 100, 0, 4);
155  delphiphomet_ = iBooker.book1D("delphiphomet", "#Delta#phi(photon, MET);#Delta#phi(#gamma,MET)", 100, 0, 4);
156  npfjets_reco_ = iBooker.book1D("npfjets_reco", "Reco: Number of PF Jets", 100, 0, 20);
157  npfjets_ = iBooker.book1D("npfjets", "Number of PF Jets", 100, 0, 20);
159  iBooker.book1D("delphijetmet_reco", "Reco: #Delta#phi(PFJet, MET);#Delta#phi(Jet,MET)", 100, 0, 4);
160  delphijetmet_ = iBooker.book1D("delphijetmet", "#Delta#phi(PFJet, MET);#Delta#phi(Jet,MET)", 100, 0, 4);
161  invmassjj_reco_ = iBooker.book1D("invmassjj_reco", "Reco: Inv mass two leading jets;M_{jj}[GeV]", 100, 0, 2000);
162  invmassjj_ = iBooker.book1D("invmassjj", "Inv mass two leading jets;M_{jj}[GeV]", 100, 0, 2000);
163  deletajj_reco_ = iBooker.book1D("deletajj_reco", "Reco: #Delta#eta(jj);|#Delta#eta_{jj}|", 100, 0, 6);
164  deletajj_ = iBooker.book1D("deletajj", "#Delta#eta(jj);|#Delta#eta_{jj}|", 100, 0, 6);
166  iBooker.book1D("triggers_reco", "Reco: Triggers", hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
167  triggers_ = iBooker.book1D("triggers", "Triggers", hltPathsToCheck_.size(), 0, hltPathsToCheck_.size());
168  trigvsnvtx_reco_ = iBooker.book2D("trigvsnvtx_reco",
169  "Reco: Trigger vs. # vertices;N_{vertices};Trigger",
170  100,
171  0,
172  100,
173  hltPathsToCheck_.size(),
174  0,
175  hltPathsToCheck_.size());
176  trigvsnvtx_ = iBooker.book2D("trigvsnvtx",
177  "Trigger vs. # vertices;N_{vertices};Trigger",
178  100,
179  0,
180  100,
181  hltPathsToCheck_.size(),
182  0,
183  hltPathsToCheck_.size());
184 }
185 
187  // Count total number of events in one run
188  evtsrun_++;
189 
192  if (!triggerResults.isValid()) {
193  edm::LogError("HigPhotonJetHLT") << "Missing triggerResults collection" << std::endl;
194  return;
195  }
196 
197  // Check whether contains monitored trigger and accepted
198  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
200 
201  // if (!triggered) return;
202 
203  // Test scale
204  // if (evtsrun_ > 10) return;
205 
206  // N Vertices
208  iEvent.getByToken(pvToken_, vertices);
209  if (!vertices.isValid())
210  return;
211  if (verbose_)
212  std::cout << "xshi:: N vertices : " << vertices->size() << std::endl;
213 
214  // Set trigger name labels
215  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
217  }
218 
219  // Fill trigger info
220  for (unsigned int itrig = 0; itrig < triggerResults->size(); itrig++) {
221  const std::string& triggername = triggerNames.triggerName(itrig);
222  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
223  if (triggername.find(hltPathsToCheck_[i]) != std::string::npos) {
225  trigvsnvtx_reco_->Fill(vertices->size(), i);
226  if (triggered)
227  triggers_->Fill(i);
228  if (triggered)
229  trigvsnvtx_->Fill(vertices->size(), i);
230  }
231  }
232  }
233 
234  nvertices_reco_->Fill(vertices->size());
235  if (triggered)
236  nvertices_->Fill(vertices->size());
237 
238  // PF MET
240  iEvent.getByToken(pfMetToken_, pfmets);
241  if (!pfmets.isValid())
242  return;
243  const reco::PFMET pfmet = pfmets->front();
244  pfmet_reco_->Fill(pfmet.et());
245  if (triggered)
246  pfmet_->Fill(pfmet.et());
247  if (verbose_)
248  std::cout << "xshi:: number of pfmets: " << pfmets->size() << std::endl;
249 
250  pfmetphi_reco_->Fill(pfmet.phi());
251  if (triggered)
252  pfmetphi_->Fill(pfmet.phi());
253 
254  // Photons
256  iEvent.getByToken(photonsToken_, photons);
257  if (!photons.isValid())
258  return;
259  int nphotons = 0;
260  for (auto const& phoIter : *photons) {
261  if (phoIter.pt() < photonMinPt_)
262  continue;
263  nphotons++;
264  photonpt_reco_->Fill(phoIter.pt());
265  photonrapidity_reco_->Fill(phoIter.rapidity());
266  if (triggered)
267  photonpt_->Fill(phoIter.pt());
268  if (triggered)
269  photonrapidity_->Fill(phoIter.rapidity());
270  double tmp_delphiphomet = fabs(deltaPhi(phoIter.phi(), pfmet.phi()));
271  delphiphomet_reco_->Fill(tmp_delphiphomet);
272  if (triggered)
273  delphiphomet_->Fill(tmp_delphiphomet);
274  }
276  if (triggered)
278 
279  // PF Jet
281  iEvent.getByToken(pfJetsToken_, pfjets);
282  if (!pfjets.isValid())
283  return;
284  if (verbose_)
285  std::cout << "xshi:: N pfjets : " << pfjets->size() << std::endl;
286 
287  double min_delphijetmet = 6.0;
288  TLorentzVector p4jet1, p4jet2, p4jj;
289  // Two leading jets eta
290  double etajet1(0), etajet2(0);
291  int njet = 0;
292  for (auto const& jetIter : *pfjets) {
293  if (jetIter.pt() < pfjetMinPt_)
294  continue;
295  njet++;
296 
297  double tmp_delphijetmet = fabs(deltaPhi(jetIter.phi(), pfmet.phi()));
298  if (tmp_delphijetmet < min_delphijetmet)
299  min_delphijetmet = tmp_delphijetmet;
300 
301  if (njet == 1) {
302  p4jet1.SetXYZM(jetIter.px(), jetIter.py(), jetIter.pz(), jetIter.mass());
303  etajet1 = jetIter.eta();
304  }
305  if (njet == 2) {
306  p4jet2.SetXYZM(jetIter.px(), jetIter.py(), jetIter.pz(), jetIter.mass());
307  etajet2 = jetIter.eta();
308  }
309  }
311  if (triggered)
312  npfjets_->Fill(njet);
313 
314  delphijetmet_reco_->Fill(min_delphijetmet);
315  if (triggered)
316  delphijetmet_->Fill(min_delphijetmet);
317  p4jj = p4jet1 + p4jet2;
318  double deletajj = etajet1 - etajet2;
319  if (verbose_)
320  std::cout << "xshi:: invmass jj " << p4jj.M() << std::endl;
321 
322  invmassjj_reco_->Fill(p4jj.M());
323  deletajj_reco_->Fill(deletajj);
324  if (triggered)
325  invmassjj_->Fill(p4jj.M());
326  if (triggered)
327  deletajj_->Fill(deletajj);
328 }
329 
331  // Normalize to the total number of events in the run
332  if (!perLSsaving_) {
333  TH2F* h = trigvsnvtx_->getTH2F();
334  double integral = h->Integral();
335  double norm = (integral > 0.) ? evtsrun_ * hltPathsToCheck_.size() / integral : 1.;
336  h->Scale(norm);
337  if (verbose_) {
338  std::cout << "xshi:: endRun total number of events: " << evtsrun_ << ", integral = " << h->Integral()
339  << ", norm = " << norm << std::endl;
340  }
341  }
342 }
343 
346  for (unsigned int itrig = 0; itrig < triggerResults->size(); itrig++) {
347  // Only consider the triggered case.
348  if (triggerAccept_ && ((*triggerResults)[itrig].accept() != 1))
349  continue;
350  const std::string& triggername = triggerNames.triggerName(itrig);
351  for (auto const& i : hltPathsToCheck_) {
352  if (triggername.find(i) != std::string::npos) {
353  return true;
354  }
355  }
356  }
357 
358  return false;
359 }
360 
361 //define this as a plug-in
edm::EDGetTokenT< reco::PFJetCollection > pfJetsToken_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::PFMETCollection > pfMetToken_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
edm::EDGetTokenT< reco::VertexCollection > pvToken_
Log< level::Error, false > LogError
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
int njet
Definition: HydjetWrapper.h:89
void Fill(long long x)
edm::EDGetTokenT< reco::PhotonCollection > photonsToken_
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
static std::string const triggerResults
Definition: EdmProvDump.cc:44
virtual 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)
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:70
HigPhotonJetHLTOfflineSource(const edm::ParameterSet &)
bool isMonitoredTriggerAccepted(const edm::TriggerNames &, const edm::Handle< edm::TriggerResults > &)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
double et() const final
transverse energy
std::vector< std::string > hltPathsToCheck_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
double phi() const final
momentum azimuthal angle
void dqmEndRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45