CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HTMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
37 
38 class HTMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
39 public:
42 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 protected:
48  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
49  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
50 
51 private:
52  const std::string folderName_;
53 
56 
62 
63  edm::EDGetTokenT<reco::PFMETCollection> metToken_;
64  edm::EDGetTokenT<reco::JetView> jetToken_;
65  edm::EDGetTokenT<reco::GsfElectronCollection> eleToken_;
66  edm::EDGetTokenT<reco::MuonCollection> muoToken_;
67  edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
68 
72 
74  ObjME htVsLS_;
77 
80 
86  unsigned njets_;
87  unsigned nelectrons_;
88  unsigned nmuons_;
89  double dEtaCut_;
90 
91  static constexpr double MAXedge_PHI = 3.2;
92  static constexpr int Nbin_PHI = 64;
93  static constexpr MEbinning phi_binning_{Nbin_PHI, -MAXedge_PHI, MAXedge_PHI};
94 
96 
97  enum quant { HT, MJJ, SOFTDROP };
99 };
100 
102  : folderName_(iConfig.getParameter<std::string>("FolderName")),
103  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
104  hltPathsAreValid_(false),
105  metInputTag_(iConfig.getParameter<edm::InputTag>("met")),
106  jetInputTag_(iConfig.getParameter<edm::InputTag>("jets")),
107  eleInputTag_(iConfig.getParameter<edm::InputTag>("electrons")),
108  muoInputTag_(iConfig.getParameter<edm::InputTag>("muons")),
109  vtxInputTag_(iConfig.getParameter<edm::InputTag>("vertices")),
110  metToken_(consumes<reco::PFMETCollection>(metInputTag_)),
111  jetToken_(mayConsume<reco::JetView>(jetInputTag_)),
112  eleToken_(mayConsume<reco::GsfElectronCollection>(eleInputTag_)),
113  muoToken_(mayConsume<reco::MuonCollection>(muoInputTag_)),
114  vtxToken_(mayConsume<reco::VertexCollection>(vtxInputTag_)),
115  ht_variable_binning_(
116  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("htBinning")),
117  ht_binning_(
118  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("htPSet"))),
119  ls_binning_(
120  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
122  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
124  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
125  metSelection_(iConfig.getParameter<std::string>("metSelection")),
126  jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
127  eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
128  muoSelection_(iConfig.getParameter<std::string>("muoSelection")),
129  jetSelection_HT_(iConfig.getParameter<std::string>("jetSelection_HT")),
130  njets_(iConfig.getParameter<unsigned>("njets")),
131  nelectrons_(iConfig.getParameter<unsigned>("nelectrons")),
132  nmuons_(iConfig.getParameter<unsigned>("nmuons")),
133  dEtaCut_(iConfig.getParameter<double>("dEtaCut")),
134  warningWasPrinted_(false) {
135  /* mia: THIS CODE SHOULD BE DELETED !!!! */
136  string quantity = iConfig.getParameter<std::string>("quantity");
137  if (quantity == "HT") {
138  quantity_ = HT;
139  } else if (quantity == "Mjj") {
140  quantity_ = MJJ;
141  } else if (quantity == "softdrop") {
143  } else {
144  throw cms::Exception("quantity not defined")
145  << "the quantity '" << quantity << "' is undefined. Please check your config!" << std::endl;
146  }
147 }
148 
151  num_genTriggerEventFlag_.reset();
152  }
154  den_genTriggerEventFlag_.reset();
155  }
156 }
157 
158 void HTMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
159  // Initialize the GenericTriggerEventFlag
161  num_genTriggerEventFlag_->initRun(iRun, iSetup);
162  }
164  den_genTriggerEventFlag_->initRun(iRun, iSetup);
165  }
166 
167  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
169  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
170  den_genTriggerEventFlag_->allHLTPathsAreValid());
171 
172  // if valid HLT paths are required,
173  // create DQM outputs only if all paths are valid
175  return;
176  }
177 
178  std::string histname, histtitle;
179 
180  std::string currentFolder = folderName_;
181  ibooker.setCurrentFolder(currentFolder);
182 
183  switch (quantity_) {
184  case HT: {
185  histname = "ht_variable";
186  histtitle = "HT";
187  bookME(ibooker, qME_variableBinning_, histname, histtitle, ht_variable_binning_);
188  setMETitle(qME_variableBinning_, "HT [GeV]", "events / [GeV]");
189 
190  histname = "htVsLS";
191  histtitle = "HT vs LS";
192  bookME(ibooker,
193  htVsLS_,
194  histname,
195  histtitle,
200  ht_binning_.xmax);
201  setMETitle(htVsLS_, "LS", "HT [GeV]");
202 
203  histname = "deltaphi_metjet1";
204  histtitle = "DPHI_METJ1";
205  bookME(ibooker, deltaphimetj1ME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
206  setMETitle(deltaphimetj1ME_, "delta phi (met, j1)", "events / 0.1 rad");
207 
208  histname = "deltaphi_jet1jet2";
209  histtitle = "DPHI_J1J2";
210  bookME(ibooker, deltaphij1j2ME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
211  setMETitle(deltaphij1j2ME_, "delta phi (j1, j2)", "events / 0.1 rad");
212  break;
213  }
214 
215  case MJJ: {
216  histname = "mjj_variable";
217  histtitle = "Mjj";
218  bookME(ibooker, qME_variableBinning_, histname, histtitle, ht_variable_binning_);
219  setMETitle(qME_variableBinning_, "Mjj [GeV]", "events / [GeV]");
220  break;
221  }
222 
223  case SOFTDROP: {
224  histname = "softdrop_variable";
225  histtitle = "softdropmass";
226  bookME(ibooker, qME_variableBinning_, histname, histtitle, ht_variable_binning_);
227  setMETitle(qME_variableBinning_, "leading jet softdropmass [GeV]", "events / [GeV]");
228  break;
229  }
230  }
231 }
232 
234  // if valid HLT paths are required,
235  // analyze event only if all paths are valid
237  return;
238  }
239 
240  // Filter out events if Trigger Filtering is requested
241  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
242  return;
243 
245  iEvent.getByToken(metToken_, metHandle);
246  if (not metHandle.isValid()) {
247  if (not warningWasPrinted_) {
248  edm::LogWarning("HTMonitor") << "skipping events because the collection " << metInputTag_.label().c_str()
249  << " is not available";
250  warningWasPrinted_ = true;
251  }
252  return;
253  }
254  reco::PFMET pfmet = metHandle->front();
255  if (!metSelection_(pfmet))
256  return;
257 
258  edm::Handle<reco::JetView> jetHandle; //add a configurable jet collection & jet pt selection
259  iEvent.getByToken(jetToken_, jetHandle);
260  if (!jetHandle.isValid()) {
261  if (not warningWasPrinted_) {
262  edm::LogWarning("HTMonitor") << "skipping events because the collection " << jetInputTag_.label().c_str()
263  << " is not available";
264  warningWasPrinted_ = true;
265  }
266  return;
267  }
268  std::vector<reco::Jet> jets;
269  if (jetHandle->size() < njets_)
270  return;
271  for (auto const& j : *jetHandle) {
272  if (jetSelection_(j)) {
273  jets.push_back(j);
274  }
275  }
276 
277  if (jets.size() < njets_)
278  return;
279 
280  float deltaPhi_met_j1 = 10.0;
281  float deltaPhi_j1_j2 = 10.0;
282 
283  if (!jets.empty())
284  deltaPhi_met_j1 = fabs(deltaPhi(pfmet.phi(), jets[0].phi()));
285  if (jets.size() >= 2)
286  deltaPhi_j1_j2 = fabs(deltaPhi(jets[0].phi(), jets[1].phi()));
287 
288  std::vector<reco::GsfElectron> electrons;
290  iEvent.getByToken(eleToken_, eleHandle);
291  if (eleHandle.isValid()) {
292  if (eleHandle->size() < nelectrons_)
293  return;
294  for (auto const& e : *eleHandle) {
295  if (eleSelection_(e))
296  electrons.push_back(e);
297  }
298  if (electrons.size() < nelectrons_)
299  return;
300  } else {
301  if (not warningWasPrinted_) {
302  if (eleInputTag_.label().empty())
303  edm::LogWarning("HTMonitor") << "GsfElectronCollection not set";
304  else
305  edm::LogWarning("HTMonitor") << "skipping events because the collection " << eleInputTag_.label().c_str()
306  << " is not available";
307 
308  warningWasPrinted_ = true;
309  }
310  if (!eleInputTag_.label().empty())
311  return;
312  }
313 
314  reco::Vertex vtx;
316  iEvent.getByToken(vtxToken_, vtxHandle);
317  if (vtxHandle.isValid()) {
318  for (auto const& v : *vtxHandle) {
319  bool isFake = v.isFake();
320 
321  if (!isFake) {
322  vtx = v;
323  break;
324  }
325  }
326  } else {
327  if (not warningWasPrinted_) {
328  if (vtxInputTag_.label().empty())
329  edm::LogWarning("HTMonitor") << "VertexCollection not set";
330  else
331  edm::LogWarning("HTMonitor") << "skipping events because the collection " << vtxInputTag_.label().c_str()
332  << " is not available";
333 
334  warningWasPrinted_ = true;
335  }
336  if (!vtxInputTag_.label().empty())
337  return;
338  }
339 
340  std::vector<reco::Muon> muons;
342  iEvent.getByToken(muoToken_, muoHandle);
343  if (muoHandle.isValid()) {
344  if (muoHandle->size() < nmuons_)
345  return;
346  for (auto const& m : *muoHandle) {
347  if (muoSelection_(m) && m.isGlobalMuon() && m.isPFMuon() && m.globalTrack()->normalizedChi2() < 10. &&
348  m.globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && m.numberOfMatchedStations() > 1 &&
349  fabs(m.muonBestTrack()->dxy(vtx.position())) < 0.2 && fabs(m.muonBestTrack()->dz(vtx.position())) < 0.5 &&
350  m.innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
351  m.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5)
352  muons.push_back(m);
353  }
354  if (muons.size() < nmuons_)
355  return;
356  } else {
357  if (not warningWasPrinted_) {
358  if (muoInputTag_.label().empty())
359  edm::LogWarning("HTMonitor") << "MuonCollection not set";
360  else
361  edm::LogWarning("HTMonitor") << "skipping events because the collection " << muoInputTag_.label().c_str()
362  << " is not available";
363 
364  warningWasPrinted_ = true;
365  }
366  if (!muoInputTag_.label().empty())
367  return;
368  }
369 
370  // fill histograms
371  switch (quantity_) {
372  case HT: {
373  float ht = 0.0;
374  for (auto const& j : *jetHandle) {
375  if (jetSelection_HT_(j))
376  ht += j.pt();
377  }
378 
379  // filling histograms (denominator)
381 
382  deltaphimetj1ME_.denominator->Fill(deltaPhi_met_j1);
383  deltaphij1j2ME_.denominator->Fill(deltaPhi_j1_j2);
384 
385  int ls = iEvent.id().luminosityBlock();
386  htVsLS_.denominator->Fill(ls, ht);
387 
388  // applying selection for numerator
389  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
390  return;
391 
392  // filling histograms (num_genTriggerEventFlag_)
394 
395  htVsLS_.numerator->Fill(ls, ht);
396  deltaphimetj1ME_.numerator->Fill(deltaPhi_met_j1);
397  deltaphij1j2ME_.numerator->Fill(deltaPhi_j1_j2);
398  break;
399  }
400 
401  case MJJ: {
402  if (jets.size() < 2)
403  return;
404 
405  // deltaEta cut
406  if (fabs(jets[0].p4().Eta() - jets[1].p4().Eta()) >= dEtaCut_)
407  return;
408  float mjj = (jets[0].p4() + jets[1].p4()).M();
409 
411 
412  // applying selection for numerator
413  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
414  return;
415 
417  break;
418  }
419 
420  case SOFTDROP: {
421  if (jets.size() < 2)
422  return;
423 
424  // deltaEta cut
425  if (fabs(jets[0].p4().Eta() - jets[1].p4().Eta()) >= dEtaCut_)
426  return;
427 
428  float softdrop = jets[0].p4().M();
429 
431 
432  // applying selection for numerator
433  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
434  return;
435 
437  break;
438  }
439  }
440 }
441 
444  desc.add<std::string>("FolderName", "HLT/HT");
445  desc.add<bool>("requireValidHLTPaths", true);
446 
447  desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
448  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
449  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
450  desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
451  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
452  desc.add<std::string>("metSelection", "pt > 0");
453  desc.add<std::string>("jetSelection", "pt > 0");
454  desc.add<std::string>("eleSelection", "pt > 0");
455  desc.add<std::string>("muoSelection", "pt > 0");
456  desc.add<std::string>("jetSelection_HT", "pt > 30 && eta < 2.5");
457  desc.add<unsigned>("njets", 0);
458  desc.add<unsigned>("nelectrons", 0);
459  desc.add<unsigned>("nmuons", 0);
460  desc.add<double>("dEtaCut", 1.3);
461 
462  edm::ParameterSetDescription genericTriggerEventPSet;
463  GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
464  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
465  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
466 
469  fillHistoPSetDescription(htPSet);
470  histoPSet.add<edm::ParameterSetDescription>("htPSet", htPSet);
471  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140.,
472  150., 160., 170., 180., 190., 200., 220., 240., 260., 280., 300.,
473  350., 400., 450., 500., 550., 600., 650., 700., 750., 800., 850.,
474  900., 950., 1000., 1050., 1100., 1200., 1300., 1400., 1500., 2000., 2500.};
475  histoPSet.add<std::vector<double> >("htBinning", bins);
476 
479  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
480 
481  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
482 
483  desc.add<std::string>("quantity", "HT");
484 
485  descriptions.add("htMonitoring", desc);
486 }
487 
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: HTMonitor.cc:66
static constexpr int Nbin_PHI
Definition: HTMonitor.cc:92
muoSelection_(iConfig.getParameter< std::string >("muoSelection"))
StringCutObjectSelector< reco::Jet, true > jetSelection_
Definition: HTMonitor.cc:82
double dEtaCut_
Definition: HTMonitor.cc:89
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
quant quantity_
Definition: HTMonitor.cc:98
static constexpr double MAXedge_PHI
Definition: HTMonitor.cc:91
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const bool requireValidHLTPaths_
Definition: HTMonitor.cc:54
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::reco::DQMStore DQMStore
Definition: HTMonitor.cc:41
den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter< edm::ParameterSet >("denGenericTriggerEventPSet"), consumesCollector(),*this))
eleSelection_(iConfig.getParameter< std::string >("eleSelection"))
edm::InputTag muoInputTag_
Definition: HTMonitor.cc:60
def ls
Definition: eostools.py:349
~HTMonitor() override
Definition: HTMonitor.cc:149
std::vector< double > ht_variable_binning_
Definition: HTMonitor.cc:69
ObjME deltaphij1j2ME_
Definition: HTMonitor.cc:76
unsigned njets_
Definition: HTMonitor.cc:86
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: HTMonitor.cc:67
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
ls_binning_(getHistoPSet(iConfig.getParameter< edm::ParameterSet >("histoPSet").getParameter< edm::ParameterSet >("lsPSet")))
edm::View< Jet > JetView
edm references
Definition: JetCollection.h:11
edm::InputTag jetInputTag_
Definition: HTMonitor.cc:58
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
const Point & position() const
position
Definition: Vertex.h:127
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: HTMonitor.cc:79
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
MEbinning ht_binning_
Definition: HTMonitor.cc:70
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
edm::InputTag eleInputTag_
Definition: HTMonitor.cc:59
MEbinning ls_binning_
Definition: HTMonitor.cc:71
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: HTMonitor.cc:84
nmuons_(iConfig.getParameter< unsigned int >("nmuons"))
#define override(base_class)
vector< PseudoJet > jets
MonitorElement * denominator
MonitorElement * numerator
HTMonitor(const edm::ParameterSet &)
Definition: HTMonitor.cc:101
njets_(iConfig.getParameter< unsigned int >("njets"))
metSelection_(iConfig.getParameter< std::string >("metSelection"))
static constexpr MEbinning phi_binning_
Definition: HTMonitor.cc:93
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
metToken_(consumes< reco::PFMETCollection >(iConfig.getParameter< edm::InputTag >("met")))
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: HTMonitor.cc:65
num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter< edm::ParameterSet >("numGenericTriggerEventPSet"), consumesCollector(),*this))
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: HTMonitor.cc:81
edm::InputTag vtxInputTag_
Definition: HTMonitor.cc:61
edm::InputTag metInputTag_
Definition: HTMonitor.cc:57
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: HTMonitor.cc:83
unsigned nelectrons_
Definition: HTMonitor.cc:87
edm::EDGetTokenT< reco::JetView > jetToken_
Definition: HTMonitor.cc:64
const std::string folderName_
Definition: HTMonitor.cc:52
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: HTMonitor.cc:233
ObjME deltaphimetj1ME_
Definition: HTMonitor.cc:75
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::string const & label() const
Definition: InputTag.h:36
constexpr char Jet[]
Definition: modules.cc:9
edm::EventID id() const
Definition: EventBase.h:59
bool warningWasPrinted_
Definition: HTMonitor.cc:95
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HTMonitor.cc:442
tuple muons
Definition: patZpeak.py:41
ObjME htVsLS_
Definition: HTMonitor.cc:74
bool hltPathsAreValid_
Definition: HTMonitor.cc:55
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: HTMonitor.cc:63
dqm::reco::MonitorElement MonitorElement
Definition: HTMonitor.cc:40
Log< level::Warning, false > LogWarning
jetSelection_(iConfig.getParameter< std::string >("jetSelection"))
Definition: HT.h:21
ObjME qME_variableBinning_
Definition: HTMonitor.cc:73
double phi() const final
momentum azimuthal angle
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HTMonitor.cc:158
static void fillPSetDescription(edm::ParameterSetDescription &desc)
unsigned nmuons_
Definition: HTMonitor.cc:88
StringCutObjectSelector< reco::Jet, true > jetSelection_HT_
Definition: HTMonitor.cc:85
Definition: Run.h:45
nelectrons_(iConfig.getParameter< unsigned int >("nelectrons"))
Collection of PF MET.
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: HTMonitor.cc:78