CMS 3D CMS Logo

ObjMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
29 
30 class ObjMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
31 public:
34 
36  ~ObjMonitor() throw() override;
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 protected:
41  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
42 
43 private:
44  bool looseJetId(const double& abseta,
45  const double& NHF,
46  const double& NEMF,
47  const double& CHF,
48  const double& CEMF,
49  const unsigned& NumNeutralParticles,
50  const unsigned& CHM);
51 
52  bool tightJetId(const double& abseta,
53  const double& NHF,
54  const double& NEMF,
55  const double& CHF,
56  const double& CEMF,
57  const unsigned& NumNeutralParticles,
58  const unsigned& CHM);
59 
61 
64 
68  edm::EDGetTokenT<reco::MuonCollection> muoToken_;
71 
72  //objects to plot
73  //add your own with corresponding switch
74  bool do_met_;
76  bool do_jet_;
78  bool do_ht_;
80  bool do_hmg_;
82 
85 
88  std::string jetId_;
94 
95  unsigned njets_;
96  unsigned nelectrons_;
97  unsigned nmuons_;
98  unsigned nphotons_;
99  unsigned nmesons_;
100 };
101 
103  : folderName_(iConfig.getParameter<std::string>("FolderName")),
104  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
106  metToken_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
107  jetToken_(mayConsume<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jets"))),
108  eleToken_(mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
109  muoToken_(mayConsume<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
110  phoToken_(mayConsume<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photons"))),
111  trkToken_(mayConsume<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))),
112  do_met_(iConfig.getParameter<bool>("doMETHistos")),
113  do_jet_(iConfig.getParameter<bool>("doJetHistos")),
114  do_ht_(iConfig.getParameter<bool>("doHTHistos")),
115  do_hmg_(iConfig.getParameter<bool>("doHMesonGammaHistos")),
117  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
119  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
120  metSelection_(iConfig.getParameter<std::string>("metSelection")),
121  jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
122  jetId_(iConfig.getParameter<std::string>("jetId")),
123  htjetSelection_(iConfig.getParameter<std::string>("htjetSelection")),
124  eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
125  muoSelection_(iConfig.getParameter<std::string>("muoSelection")),
126  phoSelection_(iConfig.getParameter<std::string>("phoSelection")),
127  trkSelection_(iConfig.getParameter<std::string>("trkSelection")),
128  njets_(iConfig.getParameter<int>("njets")),
129  nelectrons_(iConfig.getParameter<int>("nelectrons")),
130  nmuons_(iConfig.getParameter<int>("nmuons")),
131  nphotons_(iConfig.getParameter<int>("nphotons")),
132  nmesons_(iConfig.getParameter<int>("nmesons")) {
133  if (do_met_) {
134  metDQM_.initialise(iConfig);
135  }
136  if (do_jet_) {
137  jetDQM_.initialise(iConfig);
138  }
139  if (do_ht_) {
140  htDQM_.initialise(iConfig);
141  }
142  if (do_hmg_) {
143  hmgDQM_.initialise(iConfig);
144  }
145 }
146 
149  num_genTriggerEventFlag_.reset();
150  }
152  den_genTriggerEventFlag_.reset();
153  }
154 }
155 
156 void ObjMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
157  // Initialize the GenericTriggerEventFlag
159  num_genTriggerEventFlag_->initRun(iRun, iSetup);
161  den_genTriggerEventFlag_->initRun(iRun, iSetup);
162 
163  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
165  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
166  den_genTriggerEventFlag_->allHLTPathsAreValid());
167 
168  // if valid HLT paths are required,
169  // create DQM outputs only if all paths are valid
171  return;
172  }
173 
174  std::string currentFolder = folderName_;
175  ibooker.setCurrentFolder(currentFolder);
176 
177  if (do_met_)
178  metDQM_.bookHistograms(ibooker);
179  if (do_jet_)
180  jetDQM_.bookHistograms(ibooker);
181  if (do_ht_)
182  htDQM_.bookHistograms(ibooker);
183  if (do_hmg_)
184  hmgDQM_.bookHistograms(ibooker);
185 }
186 
188  // if valid HLT paths are required,
189  // analyze event only if all paths are valid
191  return;
192  }
193 
194  // Filter out events if Trigger Filtering is requested
195  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
196  return;
197 
199  iEvent.getByToken(metToken_, metHandle);
200  reco::PFMET pfmet = metHandle->front();
201  if (!metSelection_(pfmet))
202  return;
203 
204  float met = pfmet.pt();
205  float phi = pfmet.phi();
206 
208  iEvent.getByToken(jetToken_, jetHandle);
209  std::vector<reco::PFJet> jets;
210  std::vector<reco::PFJet> htjets;
211  if (jetHandle->size() < njets_)
212  return;
213  for (auto const& j : *jetHandle) {
214  if (jetSelection_(j)) {
215  if (jetId_ == "loose" || jetId_ == "tight") {
216  double abseta = abs(j.eta());
217  double NHF = j.neutralHadronEnergyFraction();
218  double NEMF = j.neutralEmEnergyFraction();
219  double CHF = j.chargedHadronEnergyFraction();
220  double CEMF = j.chargedEmEnergyFraction();
221  unsigned NumNeutralParticles = j.neutralMultiplicity();
222  unsigned CHM = j.chargedMultiplicity();
223  bool passId = (jetId_ == "loose" && looseJetId(abseta, NHF, NEMF, CHF, CEMF, NumNeutralParticles, CHM)) ||
224  (jetId_ == "tight" && tightJetId(abseta, NHF, NEMF, CHF, CEMF, NumNeutralParticles, CHM));
225  if (passId)
226  jets.push_back(j);
227  } else
228  jets.push_back(j);
229  }
230  if (htjetSelection_(j))
231  htjets.push_back(j);
232  }
233  if (jets.size() < njets_)
234  return;
235 
237  iEvent.getByToken(eleToken_, eleHandle);
238  std::vector<reco::GsfElectron> electrons;
239  if (eleHandle->size() < nelectrons_)
240  return;
241  for (auto const& e : *eleHandle) {
242  if (eleSelection_(e))
243  electrons.push_back(e);
244  }
245  if (electrons.size() < nelectrons_)
246  return;
247 
249  iEvent.getByToken(muoToken_, muoHandle);
250  if (muoHandle->size() < nmuons_)
251  return;
252  std::vector<reco::Muon> muons;
253  for (auto const& m : *muoHandle) {
254  if (muoSelection_(m))
255  muons.push_back(m);
256  }
257  if (muons.size() < nmuons_)
258  return;
259 
261  iEvent.getByToken(phoToken_, phoHandle);
262  if (phoHandle->size() < nphotons_)
263  return;
264  std::vector<reco::Photon> photons;
265  for (auto const& m : *phoHandle) {
266  if (phoSelection_(m))
267  photons.push_back(m);
268  }
269  if (photons.size() < nphotons_)
270  return;
271 
272  std::vector<TLorentzVector> passedMesons;
273  if (do_hmg_) {
275  iEvent.getByToken(trkToken_, trkHandle);
276  // find isolated mesons (phi or rho)
277  TLorentzVector t1, t2;
278  float hadronMassHyp[2] = {0.1396, 0.4937}; // pi or K mass
279  float loMassLim[2] = {0.5, 0.9}; // rho or phi mass
280  float hiMassLim[2] = {1.0, 1.11}; // rho or phi mass
281 
282  for (size_t i = 0; i < trkHandle->size(); ++i) {
283  const reco::Track trk1 = trkHandle->at(i);
284  if (!trkSelection_(trk1))
285  continue;
286  for (size_t j = i + 1; j < trkHandle->size(); ++j) {
287  const reco::Track trk2 = trkHandle->at(j);
288  if (!trkSelection_(trk2))
289  continue;
290  if (trk1.charge() * trk2.charge() != -1)
291  continue;
292 
293  for (unsigned hyp = 0; hyp < 2; ++hyp) {
294  t1.SetPtEtaPhiM(trk1.pt(), trk1.eta(), trk1.phi(), hadronMassHyp[hyp]);
295  t2.SetPtEtaPhiM(trk2.pt(), trk2.eta(), trk2.phi(), hadronMassHyp[hyp]);
296  TLorentzVector mesCand = t1 + t2;
297 
298  // cuts
299  if (mesCand.M() < loMassLim[hyp] || mesCand.M() > hiMassLim[hyp])
300  continue; //mass
301  if (mesCand.Pt() < 35. || fabs(mesCand.Rapidity()) > 2.1)
302  continue; //pT eta
303 
304  // isolation
305  float absIso = 0.;
306  for (size_t k = 0; k < trkHandle->size(); ++k) {
307  if (k == i || k == j)
308  continue;
309  const reco::Track trkN = trkHandle->at(k);
310  if (trkN.charge() == 0 || trkN.pt() < 0.5 || (trkN.dz() > 0.1) ||
311  deltaR(trkN.eta(), trkN.phi(), mesCand.Eta(), mesCand.Phi()) > 0.5)
312  continue;
313  absIso += trkN.pt();
314  }
315  if (absIso / mesCand.Pt() > 0.2)
316  continue;
317  passedMesons.push_back(mesCand);
318  }
319  }
320  }
321  if (passedMesons.size() < nmesons_)
322  return;
323  }
324 
325  bool passNumCond = num_genTriggerEventFlag_->off() || num_genTriggerEventFlag_->accept(iEvent, iSetup);
326  int ls = iEvent.id().luminosityBlock();
327 
328  if (do_met_)
329  metDQM_.fillHistograms(met, phi, ls, passNumCond);
330  if (do_jet_)
331  jetDQM_.fillHistograms(jets, pfmet, ls, passNumCond);
332  if (do_ht_)
333  htDQM_.fillHistograms(htjets, met, ls, passNumCond);
334  if (do_hmg_)
335  hmgDQM_.fillHistograms(photons, passedMesons, ls, passNumCond);
336 }
337 
338 bool ObjMonitor::looseJetId(const double& abseta,
339  const double& NHF,
340  const double& NEMF,
341  const double& CHF,
342  const double& CEMF,
343  const unsigned& NumNeutralParticles,
344  const unsigned& CHM) {
345  if (abseta <= 2.7) {
346  unsigned NumConst = CHM + NumNeutralParticles;
347 
348  return ((NumConst > 1 && NHF < 0.99 && NEMF < 0.99) &&
349  ((abseta <= 2.4 && CHF > 0 && CHM > 0 && CEMF < 0.99) || abseta > 2.4));
350  } else if (abseta <= 3) {
351  return (NumNeutralParticles > 2 && NEMF > 0.01 && NHF < 0.98);
352  } else {
353  return NumNeutralParticles > 10 && NEMF < 0.90;
354  }
355 }
356 bool ObjMonitor::tightJetId(const double& abseta,
357  const double& NHF,
358  const double& NEMF,
359  const double& CHF,
360  const double& CEMF,
361  const unsigned& NumNeutralParticles,
362  const unsigned& CHM) {
363  if (abseta <= 2.7) {
364  unsigned NumConst = CHM + NumNeutralParticles;
365  return (NumConst > 1 && NHF < 0.90 && NEMF < 0.90) &&
366  ((abseta <= 2.4 && CHF > 0 && CHM > 0 && CEMF < 0.99) || abseta > 2.4);
367  } else if (abseta <= 3) {
368  return (NHF < 0.98 && NEMF > 0.01 && NumNeutralParticles > 2);
369  } else {
370  return (NEMF < 0.90 && NumNeutralParticles > 10);
371  }
372 }
373 
376  desc.add<std::string>("FolderName", "HLT/OBJ");
377  desc.add<bool>("requireValidHLTPaths", true);
378 
379  desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
380  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
381  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
382  desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
383  desc.add<edm::InputTag>("photons", edm::InputTag("gedPhotons"));
384  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
385  desc.add<std::string>("metSelection", "pt > 0");
386  desc.add<std::string>("jetSelection", "pt > 0");
387  desc.add<std::string>("jetId", "");
388  desc.add<std::string>("htjetSelection", "pt > 30");
389  desc.add<std::string>("eleSelection", "pt > 0");
390  desc.add<std::string>("muoSelection", "pt > 0");
391  desc.add<std::string>("phoSelection", "pt > 0");
392  desc.add<std::string>("trkSelection", "pt > 0");
393  desc.add<int>("njets", 0);
394  desc.add<int>("nelectrons", 0);
395  desc.add<int>("nmuons", 0);
396  desc.add<int>("nphotons", 0);
397  desc.add<int>("nmesons", 0);
398 
401  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
402  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
403 
404  desc.add<bool>("doMETHistos", true);
407  desc.add<bool>("doJetHistos", true);
409  desc.add<bool>("doHTHistos", true);
411  desc.add<bool>("doHMesonGammaHistos", true);
413 
414  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
415 
416  descriptions.add("objMonitoring", desc);
417 }
418 
419 // Define this as a plug-in
void fillHistograms(const double &met, const double &phi, const int &ls, const bool passCond)
Definition: METDQM.cc:50
edm::EDGetTokenT< reco::TrackCollection > trkToken_
Definition: ObjMonitor.cc:70
dqm::reco::DQMStore DQMStore
Definition: ObjMonitor.cc:33
void fillHistograms(const std::vector< reco::PFJet > &jets, const reco::PFMET &pfmet, const int ls, const bool passCond)
Definition: JetDQM.cc:130
unsigned nelectrons_
Definition: ObjMonitor.cc:96
void initialise(const edm::ParameterSet &iConfig)
Definition: JetDQM.cc:8
Definition: Photon.py:1
void bookHistograms(DQMStore::IBooker &)
Definition: METDQM.cc:18
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ObjMonitor.cc:374
bool looseJetId(const double &abseta, const double &NHF, const double &NEMF, const double &CHF, const double &CEMF, const unsigned &NumNeutralParticles, const unsigned &CHM)
Definition: ObjMonitor.cc:338
double pt() const final
transverse momentum
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: ObjMonitor.cc:90
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: ObjMonitor.cc:86
static void fillJetDescription(edm::ParameterSetDescription &histoPSet)
Definition: JetDQM.cc:220
void fillHistograms(const reco::PhotonCollection &photons, const std::vector< TLorentzVector > &mesons, const int ls, const bool passCond)
void bookHistograms(DQMStore::IBooker &)
Definition: HTDQM.cc:18
static void fillMetDescription(edm::ParameterSetDescription &histoPSet)
Definition: METDQM.cc:68
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: ObjMonitor.cc:67
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
void initialise(const edm::ParameterSet &iConfig)
Definition: HTDQM.cc:7
const bool requireValidHLTPaths_
Definition: ObjMonitor.cc:62
bool tightJetId(const double &abseta, const double &NHF, const double &NEMF, const double &CHF, const double &CEMF, const unsigned &NumNeutralParticles, const unsigned &CHM)
Definition: ObjMonitor.cc:356
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
static void fillHmgDescription(edm::ParameterSetDescription &histoPSet)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
unsigned nmuons_
Definition: ObjMonitor.cc:97
const std::string folderName_
Definition: ObjMonitor.cc:60
unsigned nphotons_
Definition: ObjMonitor.cc:98
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: ObjMonitor.cc:87
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: ObjMonitor.cc:91
void initialise(const edm::ParameterSet &iConfig)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
int charge() const
track electric charge
Definition: TrackBase.h:596
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
int iEvent
Definition: GenABIO.cc:224
std::string jetId_
Definition: ObjMonitor.cc:88
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: ObjMonitor.cc:83
bool hltPathsAreValid_
Definition: ObjMonitor.cc:63
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: ObjMonitor.cc:65
void initialise(const edm::ParameterSet &iConfig)
Definition: METDQM.cc:7
Definition: Muon.py:1
void bookHistograms(DQMStore::IBooker &)
Definition: JetDQM.cc:29
~ObjMonitor() override
Definition: ObjMonitor.cc:147
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: ObjMonitor.cc:84
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
bool do_met_
Definition: ObjMonitor.cc:74
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillHtDescription(edm::ParameterSetDescription &histoPSet)
Definition: HTDQM.cc:69
bool do_jet_
Definition: ObjMonitor.cc:76
edm::EDGetTokenT< reco::PhotonCollection > phoToken_
Definition: ObjMonitor.cc:69
void bookHistograms(DQMStore::IBooker &)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
def ls(path, rec=False)
Definition: eostools.py:349
bool do_ht_
Definition: ObjMonitor.cc:78
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: ObjMonitor.cc:187
JetDQM jetDQM_
Definition: ObjMonitor.cc:77
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
Definition: HTDQM.h:9
unsigned nmesons_
Definition: ObjMonitor.cc:99
HMesonGammaDQM hmgDQM_
Definition: ObjMonitor.cc:81
void add(std::string const &label, ParameterSetDescription const &psetDescription)
dqm::reco::MonitorElement MonitorElement
Definition: ObjMonitor.cc:32
bool do_hmg_
Definition: ObjMonitor.cc:80
StringCutObjectSelector< reco::PFJet, true > htjetSelection_
Definition: ObjMonitor.cc:89
std::vector< PFJet > PFJetCollection
collection of PFJet objects
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: ObjMonitor.cc:66
fixed size matrix
HLT enums.
StringCutObjectSelector< reco::Photon, true > phoSelection_
Definition: ObjMonitor.cc:92
void fillHistograms(const std::vector< reco::PFJet > &htjets, const double &met, const int &ls, const bool passCond)
Definition: HTDQM.cc:45
Definition: METDQM.h:9
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: ObjMonitor.cc:68
unsigned njets_
Definition: ObjMonitor.cc:95
double phi() const final
momentum azimuthal angle
METDQM metDQM_
Definition: ObjMonitor.cc:75
ObjMonitor(const edm::ParameterSet &)
Definition: ObjMonitor.cc:102
static void fillPSetDescription(edm::ParameterSetDescription &desc)
StringCutObjectSelector< reco::Track, true > trkSelection_
Definition: ObjMonitor.cc:93
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: ObjMonitor.cc:156
Definition: Run.h:45
Definition: JetDQM.h:13
HTDQM htDQM_
Definition: ObjMonitor.cc:79
Collection of PF MET.