CMS 3D CMS Logo

JetMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
18 
19 class JetMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
20 public:
23 
25  ~JetMonitor() throw() override;
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
28 
29 protected:
31  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
32 
33  bool isBarrel(double eta);
34  bool isEndCapP(double eta);
35  bool isEndCapM(double eta);
36  bool isForward(double eta);
37 
38  void bookMESub(DQMStore::IBooker&,
39  ObjME* a_me,
40  const int len_,
41  const std::string& h_Name,
42  const std::string& h_Title,
43  const std::string& h_subOptName,
44  const std::string& h_subOptTitle,
45  const bool doPhi = true,
46  const bool doEta = true,
47  const bool doEtaPhi = true,
48  const bool doVsLS = true);
49  void FillME(ObjME* a_me,
50  const double pt_,
51  const double phi_,
52  const double eta_,
53  const int ls_,
54  const std::string& denu,
55  const bool doPhi = true,
56  const bool doEta = true,
57  const bool doEtaPhi = true,
58  const bool doVsLS = true);
59 
60 private:
62 
65 
66  double ptcut_;
69 
71 
72  edm::EDGetTokenT<edm::View<reco::Jet> > jetSrc_;
73 
76 
80 
81  ObjME a_ME[7];
87 
88  std::vector<double> v_jetpt;
89  std::vector<double> v_jeteta;
90  std::vector<double> v_jetphi;
91 
92  // (mia) not optimal, we should make use of variable binning which reflects the detector !
93  MEbinning jet_phi_binning_{64, -3.2, 3.2};
95 };
96 
98  : folderName_(iConfig.getParameter<std::string>("FolderName")),
99  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
100  hltPathsAreValid_(false),
101  ptcut_(iConfig.getParameter<double>("ptcut")),
102  isPFJetTrig(iConfig.getParameter<bool>("ispfjettrg")),
103  isCaloJetTrig(iConfig.getParameter<bool>("iscalojettrg")),
104  enableFullMonitoring_(iConfig.getParameter<bool>("enableFullMonitoring")),
105  jetSrc_(mayConsume<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("jetSrc"))),
106  num_genTriggerEventFlag_(new GenericTriggerEventFlag(
107  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
108  den_genTriggerEventFlag_(new GenericTriggerEventFlag(
109  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
110  jetpt_binning_(getHistoPSet(
111  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("jetPSet"))),
112  jetptThr_binning_(getHistoPSet(
113  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("jetPtThrPSet"))),
114  ls_binning_(getHistoPSet(
115  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))) {}
116 
119  num_genTriggerEventFlag_.reset();
120  }
122  den_genTriggerEventFlag_.reset();
123  }
124 }
125 
126 void JetMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
127  // Initialize the GenericTriggerEventFlag
129  num_genTriggerEventFlag_->initRun(iRun, iSetup);
130  }
132  den_genTriggerEventFlag_->initRun(iRun, iSetup);
133  }
134 
135  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
137  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
138  den_genTriggerEventFlag_->allHLTPathsAreValid());
139 
140  // if valid HLT paths are required,
141  // create DQM outputs only if all paths are valid
143  return;
144  }
145 
146  std::string histname, histtitle;
147  std::string hist_obtag = "";
148  std::string histtitle_obtag = "";
149  std::string currentFolder = folderName_;
150  ibooker.setCurrentFolder(currentFolder);
151 
152  if (isPFJetTrig) {
153  hist_obtag = "pfjet";
154  histtitle_obtag = "PFJet";
155  } else if (isCaloJetTrig) {
156  hist_obtag = "calojet";
157  histtitle_obtag = "CaloJet";
158  } else {
159  hist_obtag = "pfjet";
160  histtitle_obtag = "PFJet";
161  } //default is pfjet
162 
163  bookMESub(ibooker, a_ME, sizeof(a_ME) / sizeof(a_ME[0]), hist_obtag, histtitle_obtag, "", "");
164  bookMESub(ibooker,
165  a_ME_HB,
166  sizeof(a_ME_HB) / sizeof(a_ME_HB[0]),
167  hist_obtag,
168  histtitle_obtag,
169  "HB",
170  "(HB)",
171  true,
172  true,
173  true,
174  false);
175  bookMESub(ibooker,
176  a_ME_HE,
177  sizeof(a_ME_HE) / sizeof(a_ME_HE[0]),
178  hist_obtag,
179  histtitle_obtag,
180  "HE",
181  "(HE)",
182  true,
183  true,
184  true,
185  false);
186  bookMESub(ibooker,
187  a_ME_HF,
188  sizeof(a_ME_HF) / sizeof(a_ME_HF[0]),
189  hist_obtag,
190  histtitle_obtag,
191  "HF",
192  "(HF)",
193  true,
194  true,
195  true,
196  false);
197 
198  //check the flag
199  if (!enableFullMonitoring_) {
200  return;
201  }
202 
203  bookMESub(ibooker,
204  a_ME_HE_p,
205  sizeof(a_ME_HE_p) / sizeof(a_ME_HE_p[0]),
206  hist_obtag,
207  histtitle_obtag,
208  "HE_p",
209  "(HE+)",
210  true,
211  false,
212  true,
213  false);
214  bookMESub(ibooker,
215  a_ME_HE_m,
216  sizeof(a_ME_HE_m) / sizeof(a_ME_HE_m[0]),
217  hist_obtag,
218  histtitle_obtag,
219  "HE_m",
220  "(HE-)",
221  true,
222  false,
223  true,
224  false);
225 }
226 
228  // if valid HLT paths are required,
229  // analyze event only if all paths are valid
231  return;
232  }
233 
234  // Filter out events if Trigger Filtering is requested
235  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
236  return;
237 
238  const int ls = iEvent.id().luminosityBlock();
239 
240  v_jetpt.clear();
241  v_jeteta.clear();
242  v_jetphi.clear();
243 
245  iEvent.getByToken(jetSrc_, offjets);
246  if (!offjets.isValid()) {
247  edm::LogWarning("JetMonitor") << "Jet handle not valid \n";
248  return;
249  }
250  for (edm::View<reco::Jet>::const_iterator ibegin = offjets->begin(), iend = offjets->end(), ijet = ibegin;
251  ijet != iend;
252  ++ijet) {
253  if (ijet->pt() < ptcut_) {
254  continue;
255  }
256  v_jetpt.push_back(ijet->pt());
257  v_jeteta.push_back(ijet->eta());
258  v_jetphi.push_back(ijet->phi());
259  // cout << "jetpt (view ) : " << ijet->pt() << endl;
260  }
261 
262  if (v_jetpt.empty())
263  return;
264  double jetpt_ = v_jetpt[0];
265  double jeteta_ = v_jeteta[0];
266  double jetphi_ = v_jetphi[0];
267 
268  FillME(a_ME, jetpt_, jetphi_, jeteta_, ls, "denominator");
269  if (isBarrel(jeteta_)) {
270  FillME(a_ME_HB, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
271  } else if (isEndCapP(jeteta_)) {
272  FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
273  if (enableFullMonitoring_) {
274  FillME(a_ME_HE_p, jetpt_, jetphi_, jeteta_, ls, "denominator", true, false, true, false);
275  }
276  } else if (isEndCapM(jeteta_)) {
277  FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
278  if (enableFullMonitoring_) {
279  FillME(a_ME_HE_m, jetpt_, jetphi_, jeteta_, ls, "denominator", true, false, true, false);
280  }
281  } else if (isForward(jeteta_)) {
282  FillME(a_ME_HF, jetpt_, jetphi_, jeteta_, ls, "denominator", true, true, true, false);
283  }
284 
285  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
286  return; // Require Numerator //
287 
288  FillME(a_ME, jetpt_, jetphi_, jeteta_, ls, "numerator");
289  if (isBarrel(jeteta_)) {
290  FillME(a_ME_HB, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
291  } else if (isEndCapP(jeteta_)) {
292  FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
293  if (enableFullMonitoring_) {
294  FillME(a_ME_HE_p, jetpt_, jetphi_, jeteta_, ls, "numerator", true, false, true, false);
295  }
296  } else if (isEndCapM(jeteta_)) {
297  FillME(a_ME_HE, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
298  if (enableFullMonitoring_) {
299  FillME(a_ME_HE_m, jetpt_, jetphi_, jeteta_, ls, "numerator", true, false, true, false);
300  }
301  } else if (isForward(jeteta_)) {
302  FillME(a_ME_HF, jetpt_, jetphi_, jeteta_, ls, "numerator", true, true, true, false);
303  }
304 }
305 
306 bool JetMonitor::isBarrel(double eta) {
307  bool output = false;
308  if (fabs(eta) <= 1.3)
309  output = true;
310  return output;
311 }
312 
314  bool output = false;
315  if (fabs(eta) <= 3.0 && fabs(eta) > 1.3 && (eta < 0))
316  output = true; // (mia) this magic number should come from some file in CMSSW !!!
317  return output;
318 }
319 
322  bool output = false;
323  if (fabs(eta) <= 3.0 && fabs(eta) > 1.3 && (eta > 0))
324  output = true; // (mia) this magic number should come from some file in CMSSW !!!
325  return output;
326 }
327 
330  bool output = false;
331  if (fabs(eta) > 3.0)
332  output = true;
333  return output;
334 }
335 
337  const double pt_,
338  const double phi_,
339  const double eta_,
340  const int ls_,
341  const std::string& DenoOrNume,
342  const bool doPhi,
343  const bool doEta,
344  const bool doEtaPhi,
345  const bool doVsLS) {
346  if (DenoOrNume == "denominator") {
347  // index 0 = pt, 1 = ptThreshold , 2 = pt vs ls , 3 = phi, 4 = eta,
348  // 5 = eta vs phi, 6 = eta vs pt , 7 = abs(eta) , 8 = abs(eta) vs phi
349  a_me[0].denominator->Fill(pt_); // pt
350  a_me[1].denominator->Fill(pt_); // jetpT Threshold binning for pt
351  if (doVsLS)
352  a_me[2].denominator->Fill(ls_, pt_); // pt vs ls
353  if (doPhi)
354  a_me[3].denominator->Fill(phi_); // phi
355  if (doEta)
356  a_me[4].denominator->Fill(eta_); // eta
357  if (doEtaPhi)
358  a_me[5].denominator->Fill(eta_, phi_); // eta vs phi
359  if (doEtaPhi)
360  a_me[6].denominator->Fill(eta_, pt_); // eta vs pT
361  } else if (DenoOrNume == "numerator") {
362  a_me[0].numerator->Fill(pt_); // pt
363  a_me[1].numerator->Fill(pt_); // jetpT Threshold binning for pt
364  if (doVsLS)
365  a_me[2].numerator->Fill(ls_, pt_); // pt vs ls
366  if (doPhi)
367  a_me[3].numerator->Fill(phi_); // phi
368  if (doEta)
369  a_me[4].numerator->Fill(eta_); // eta
370  if (doEtaPhi)
371  a_me[5].numerator->Fill(eta_, phi_); // eta vs phi
372  if (doEtaPhi)
373  a_me[6].numerator->Fill(eta_, pt_); // eta vs pT
374  } else {
375  edm::LogWarning("JetMonitor") << "CHECK OUT denu option in FillME !!! DenoOrNume ? : " << DenoOrNume << std::endl;
376  }
377 }
378 
380  ObjME* a_me,
381  const int len_,
382  const std::string& h_Name,
383  const std::string& h_Title,
384  const std::string& h_subOptName,
385  const std::string& hSubT,
386  const bool doPhi,
387  const bool doEta,
388  const bool doEtaPhi,
389  const bool doVsLS) {
390  std::string hName = h_Name;
391  std::string hTitle = h_Title;
392  const std::string hSubN = h_subOptName.empty() ? "" : "_" + h_subOptName;
393 
394  int nbin_phi = jet_phi_binning_.nbins;
395  double maxbin_phi = jet_phi_binning_.xmax;
396  double minbin_phi = jet_phi_binning_.xmin;
397 
398  int nbin_eta = jet_eta_binning_.nbins;
399  double maxbin_eta = jet_eta_binning_.xmax;
400  double minbin_eta = jet_eta_binning_.xmin;
401 
402  hName = h_Name + "pT" + hSubN;
403  hTitle = h_Title + " pT " + hSubT;
404  bookME(Ibooker, a_me[0], hName, hTitle, jetpt_binning_.nbins, jetpt_binning_.xmin, jetpt_binning_.xmax);
405  setMETitle(a_me[0], h_Title + " pT [GeV]", "events / [GeV]");
406 
407  hName = h_Name + "pT_pTThresh" + hSubN;
408  hTitle = h_Title + " pT " + hSubT;
409  bookME(Ibooker, a_me[1], hName, hTitle, jetptThr_binning_.nbins, jetptThr_binning_.xmin, jetptThr_binning_.xmax);
410  setMETitle(a_me[1], h_Title + "pT [GeV]", "events / [GeV]");
411 
412  if (doVsLS) {
413  hName = h_Name + "pTVsLS" + hSubN;
414  hTitle = h_Title + " vs LS " + hSubT;
415  bookME(Ibooker,
416  a_me[2],
417  hName,
418  hTitle,
424  setMETitle(a_me[2], "LS", h_Title + "pT [GeV]");
425  }
426 
427  if (doPhi) {
428  hName = h_Name + "phi" + hSubN;
429  hTitle = h_Title + " phi " + hSubT;
430  bookME(Ibooker, a_me[3], hName, hTitle, nbin_phi, minbin_phi, maxbin_phi);
431  setMETitle(a_me[3], h_Title + " #phi", "events / 0.1 rad");
432  }
433 
434  if (doEta) {
435  hName = h_Name + "eta" + hSubN;
436  hTitle = h_Title + " eta " + hSubT;
437  bookME(Ibooker, a_me[4], hName, hTitle, nbin_eta, minbin_eta, maxbin_eta);
438  setMETitle(a_me[4], h_Title + " #eta", "events");
439  }
440 
441  if (doEtaPhi) {
442  hName = h_Name + "EtaVsPhi" + hSubN;
443  hTitle = h_Title + " eta Vs phi " + hSubT;
444  bookME(Ibooker, a_me[5], hName, hTitle, nbin_eta, minbin_eta, maxbin_eta, nbin_phi, minbin_phi, maxbin_phi);
445  setMETitle(a_me[5], h_Title + " #eta", "#phi");
446  }
447 
448  if (doEtaPhi) {
449  hName = h_Name + "EtaVspT" + hSubN;
450  hTitle = h_Title + " eta Vs pT " + hSubT;
451  bookME(Ibooker,
452  a_me[6],
453  hName,
454  hTitle,
455  nbin_eta,
456  minbin_eta,
457  maxbin_eta,
461  setMETitle(a_me[6], h_Title + " #eta", "Leading Jet pT [GeV]");
462  }
463 }
464 
467  desc.add<std::string>("FolderName", "HLT/Jet");
468  desc.add<bool>("requireValidHLTPaths", true);
469 
470  desc.add<edm::InputTag>("jetSrc", edm::InputTag("ak4PFJetsCHS"));
471  desc.add<double>("ptcut", 20);
472  desc.add<bool>("ispfjettrg", true);
473  desc.add<bool>("iscalojettrg", false);
474 
475  desc.add<bool>("enableFullMonitoring", true);
476 
479 
480  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
481  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
482 
490  histoPSet.add<std::vector<double> >("jetptBinning",
491  {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
492  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.});
493 
497 
498  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
499 
500  descriptions.add("jetMonitoring", desc);
501 }
502 
ObjME a_ME_HB[7]
Definition: JetMonitor.cc:82
dqm::reco::DQMStore DQMStore
Definition: JetMonitor.cc:22
bool isBarrel(double eta)
Definition: JetMonitor.cc:306
const bool enableFullMonitoring_
Definition: JetMonitor.cc:70
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
ObjME a_ME_HE[7]
Definition: JetMonitor.cc:83
MEbinning ls_binning_
Definition: JetMonitor.cc:79
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
JetMonitor(const edm::ParameterSet &)
Definition: JetMonitor.cc:97
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
void FillME(ObjME *a_me, const double pt_, const double phi_, const double eta_, const int ls_, const std::string &denu, const bool doPhi=true, const bool doEta=true, const bool doEtaPhi=true, const bool doVsLS=true)
Definition: JetMonitor.cc:336
bool hltPathsAreValid_
Definition: JetMonitor.cc:64
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
bool isCaloJetTrig
Definition: JetMonitor.cc:68
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
dqm::reco::MonitorElement MonitorElement
Definition: JetMonitor.cc:21
const std::string folderName_
Definition: JetMonitor.cc:61
void Fill(long long x)
ObjME a_ME_HE_p[7]
Definition: JetMonitor.cc:85
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: JetMonitor.cc:465
MEbinning jet_phi_binning_
Definition: JetMonitor.cc:93
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: JetMonitor.cc:75
Definition: Jet.py:1
bool isEndCapM(double eta)
Definition: JetMonitor.cc:313
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: JetMonitor.cc:227
MonitorElement * denominator
MonitorElement * numerator
MEbinning jetpt_binning_
Definition: JetMonitor.cc:77
ObjME a_ME_HF[7]
Definition: JetMonitor.cc:84
ObjME a_ME[7]
Definition: JetMonitor.cc:81
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MEbinning jetptThr_binning_
Definition: JetMonitor.cc:78
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: JetMonitor.cc:126
edm::EDGetTokenT< edm::View< reco::Jet > > jetSrc_
Definition: JetMonitor.cc:72
def ls(path, rec=False)
Definition: eostools.py:349
std::vector< double > v_jetpt
Definition: JetMonitor.cc:88
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
void bookME(DQMStore::IBooker &, ObjME &me, const std::string &histname, const std::string &histtitle, const uint nbins, const double xmin, const double xmax, const bool bookDen=true)
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: JetMonitor.cc:74
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
bool isPFJetTrig
Definition: JetMonitor.cc:67
Definition: output.py:1
void bookMESub(DQMStore::IBooker &, ObjME *a_me, const int len_, const std::string &h_Name, const std::string &h_Title, const std::string &h_subOptName, const std::string &h_subOptTitle, const bool doPhi=true, const bool doEta=true, const bool doEtaPhi=true, const bool doVsLS=true)
Definition: JetMonitor.cc:379
~JetMonitor() override
Definition: JetMonitor.cc:117
Log< level::Warning, false > LogWarning
std::vector< double > v_jeteta
Definition: JetMonitor.cc:89
const bool requireValidHLTPaths_
Definition: JetMonitor.cc:63
bool isForward(double eta)
For Hcal Forward Area.
Definition: JetMonitor.cc:329
static void fillPSetDescription(edm::ParameterSetDescription &desc)
std::vector< double > v_jetphi
Definition: JetMonitor.cc:90
ObjME a_ME_HE_m[7]
Definition: JetMonitor.cc:86
MEbinning jet_eta_binning_
Definition: JetMonitor.cc:94
Definition: Run.h:45
bool isEndCapP(double eta)
For Hcal Endcap Plus Area.
Definition: JetMonitor.cc:321
double ptcut_
Definition: JetMonitor.cc:66