CMS 3D CMS Logo

TopDQMHelpers.h
Go to the documentation of this file.
1 #ifndef TOPDQMHELPERS
2 #define TOPDQMHELPERS
3 
4 #include <string>
5 #include <vector>
6 #include <iostream>
16 
21 
31 inline bool accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath) {
32  bool passed = false;
33  const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
34  for (unsigned int i = 0; i < triggerNames.triggerNames().size(); ++i) {
35  if (triggerNames.triggerNames()[i] == triggerPath) {
36  if (triggerTable.accept(i)) {
37  passed = true;
38  break;
39  }
40  }
41  }
42  return passed;
43 }
44 
45 inline bool accept(const edm::Event& event,
46  const edm::TriggerResults& triggerTable,
47  const std::vector<std::string>& triggerPaths) {
48  bool passed = false;
49  for (unsigned int j = 0; j < triggerPaths.size(); ++j) {
50  if (accept(event, triggerTable, triggerPaths[j])) {
51  passed = true;
52  break;
53  }
54  }
55  return passed;
56 }
57 
60 
72 public:
74  Calculate_miniAOD(int maxNJets, double wMass);
77 
79  double massWBoson(const std::vector<pat::Jet>& jets);
81  double massTopQuark(const std::vector<pat::Jet>& jets);
83  // double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<bool>
84  // bjet);
85  double massBTopQuark(const std::vector<pat::Jet>& jets, std::vector<double> VbtagWP, double btagWP_);
86 
88  double tmassWBoson(pat::Muon* lep, const pat::MET& met, const pat::Jet& b);
90  double tmassTopQuark(pat::Muon* lep, const pat::MET& met, const pat::Jet& b);
91 
93  double tmassWBoson(pat::Electron* lep, const pat::MET& met, const pat::Jet& b);
95  double tmassTopQuark(pat::Electron* lep, const pat::MET& met, const pat::Jet& b);
96 
97 private:
101  void operator()(const std::vector<pat::Jet>& jets);
103  void operator2(const std::vector<pat::Jet>&, std::vector<double>, double);
105  void operator()(const pat::Jet& bJet, pat::Electron* lepton, const pat::MET& met);
106 
107  void operator()(const pat::Jet& bJet, pat::Muon* lepton, const pat::MET& met);
108 
109 private:
111  bool failed_;
115  double wMass_;
117  double massWBoson_;
123  double tmassWBoson_;
126 };
127 
128 class Calculate {
129 public:
131  Calculate(int maxNJets, double wMass);
134 
136  double massWBoson(const std::vector<reco::Jet>& jets);
138  double massTopQuark(const std::vector<reco::Jet>& jets);
140  // double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<bool>
141  // bjet);
142  double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<double> VbtagWP, double btagWP_);
143 
145  double tmassWBoson(reco::RecoCandidate* lep, const reco::MET& met, const reco::Jet& b);
147  double tmassTopQuark(reco::RecoCandidate* lep, const reco::MET& met, const reco::Jet& b);
148 
149 private:
153  void operator()(const std::vector<reco::Jet>& jets);
155  void operator2(const std::vector<reco::Jet>&, std::vector<double>, double);
157  void operator()(const reco::Jet& bJet, reco::RecoCandidate* lepton, const reco::MET& met);
158 
159 private:
161  bool failed_;
165  double wMass_;
167  double massWBoson_;
173  double tmassWBoson_;
176 };
177 
188 
237 template <typename Object>
239 public:
244 
246  bool select(const edm::Event& event);
247  bool select(const edm::Event& event, const std::string& type);
249  bool select(const edm::Event& event, const edm::EventSetup& setup);
250  bool selectVertex(const edm::Event& event);
251 
252 private:
256  int min_, max_;
270  double eidCutValue_;
279 
286 };
287 
289 template <typename Object>
291  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(nullptr) {
292  src_ = iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
293  // exist otherwise they are initialized with -1
294  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
295  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
296  std::string mygSF = "gedGsfElectrons";
297  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
298  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
299  edm::ParameterSet elecId = cfg.getParameter<edm::ParameterSet>("electronId");
300  electronId_ = iC.consumes<edm::ValueMap<float> >(elecId.getParameter<edm::InputTag>("src"));
301  eidCutValue_ = elecId.getParameter<double>("cutValue");
302  }
303  if (cfg.exists("jetCorrector")) {
304  jetCorrector_ = iC.esConsumes(edm::ESInputTag("", cfg.getParameter<std::string>("jetCorrector")));
305  }
306  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
307  edm::ParameterSet jetBTagger = cfg.getParameter<edm::ParameterSet>("jetBTagger");
308  btagLabel_ = iC.consumes<reco::JetTagCollection>(jetBTagger.getParameter<edm::InputTag>("label"));
309  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
310  }
311  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
312  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
313  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
315  }
316 }
317 
319 template <typename Object>
321  // fetch input collection
323  if (!event.getByToken(src_, src))
324  return false;
325 
326  // load electronId value map if configured such
328  if (!electronId_.isUninitialized()) {
329  if (!event.getByToken(electronId_, electronId))
330  return false;
331  }
332 
333  // determine multiplicity of selected objects
334  int n = 0;
335  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
336  // special treatment for electrons
337  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
338  unsigned int idx = obj - src->begin();
339  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
340  if (select_(*obj))
341  ++n;
342  }
343  }
344  // normal treatment
345  else {
346  if (select_(*obj))
347  ++n;
348  }
349  }
350  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
351  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
352 }
353 
355 template <typename Object>
357  // fetch input collection
359  if (!event.getByToken(src_, src))
360  return false;
361 
362  // special for gsfElectron
364 
365  // load electronId value map if configured such
367  if (!electronId_.isUninitialized()) {
368  if (!event.getByToken(electronId_, electronId))
369  return false;
370  }
371 
372  // determine multiplicity of selected objects
373  int n = 0;
374  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
375  // special treatment for PF candidates
376  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
377  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
378 
379  if (objtmp.muonRef().isNonnull() && type == "muon") {
380  if (select_(*obj)) {
381  ++n;
382  }
383  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
384  if (select_(*obj)) {
385  if (electronId_.isUninitialized()) {
386  ++n;
387  } else if (((double)(*electronId)[obj->gsfElectronRef()] >= eidCutValue_)) {
388  ++n;
389  }
390  }
391  // idx_gsf++;
392  }
393  }
394 
395  // special treatment for electrons
396  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
397  unsigned int idx = obj - src->begin();
398  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
399  if (select_(*obj))
400  ++n;
401  }
402  }
403 
404  // normal treatment
405  else {
406  if (select_(*obj))
407  ++n;
408  }
409  }
410  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
411  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
412 }
413 
414 template <typename Object>
416  // fetch input collection
418  if (!event.getByToken(src_, src))
419  return false;
420 
421  // load electronId value map if configured such
423  if (!electronId_.isUninitialized()) {
424  if (!event.getByToken(electronId_, electronId))
425  return false;
426  }
427 
428  // determine multiplicity of selected objects
429  int n = 0;
430  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
431  if (select_(*obj))
432  ++n;
433  }
434  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
435  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
436 }
437 
439 template <typename Object>
441  // fetch input collection
443  if (!event.getByToken(src_, src))
444  return false;
445 
446  // load btag collection if configured such
447  // NOTE that the JetTagCollection needs an
448  // edm::View to reco::Jets; we have to add
449  // another Handle bjets for this purpose
453  if (!btagLabel_.isUninitialized()) {
454  if (!event.getByToken(src_, bjets))
455  return false;
456  if (!event.getByToken(btagLabel_, btagger))
457  return false;
458  if (!event.getByToken(pvs_, pvertex))
459  return false;
460  }
461 
462  // load jetID value map if configured such
464  if (jetIDSelect_) {
465  if (!event.getByToken(jetIDLabel_, jetID))
466  return false;
467  }
468 
469  // load jet corrector if configured such
470  const JetCorrector* corrector = nullptr;
471  if (!jetCorrector_.isInitialized() && jetCorrector_.hasValidIndex()) {
472  // check whether a jet correcto is in the event setup or not
473  if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
474  corrector = &setup.getData(jetCorrector_);
475  } else {
476  edm::LogVerbatim("TopDQMHelpers") << "\n"
477  << "---------------------------------------------------------------\n"
478  << " No JetCorrectionsRecord available from EventSetup:\n"
479  << " - Jets will not be corrected.\n"
480  << " - If you want to change this add the following lines to your "
481  "cfg file:\n"
482  << "\n"
483  << " ## load jet corrections\n"
484  << " process.load(\""
485  "JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff"
486  "\")\n"
487  << " process.prefer(\"ak5CaloL2L3\")\n"
488  << "---------------------------------------------------------------"
489  "\n";
490  }
491  }
492  // determine multiplicity of selected objects
493  int n = 0;
494  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
495  // check for chosen btag discriminator to be above the
496  // corresponding working point if configured such
497  unsigned int idx = obj - src->begin();
498  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] > btagWorkingPoint_) {
499  bool passedJetID = true;
500  // check jetID for calo jets
501  if (jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
502  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
503  }
504  if (passedJetID) {
505  // scale jet energy if configured such
506  Object jet = *obj;
507  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
508  if (select_(jet))
509  ++n;
510  }
511  }
512  }
513  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
514  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
515 }
516 
517 #endif
518 
519 /* Local Variables: */
520 /* show-trailing-whitespace: t */
521 /* truncate-lines: t */
522 /* End: */
~Calculate_miniAOD()
default destructor
Definition: TopDQMHelpers.h:76
bool accept() const
Has at least one path accepted the event?
double massWBoson_
cache of w boson mass estimate
Log< level::Info, true > LogVerbatim
Analysis-level MET class.
Definition: MET.h:40
double massBTopQuark_
cache of b-tagged top quark mass estimate
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double massBTopQuark(const std::vector< reco::Jet > &jets, std::vector< double > VbtagWP, double btagWP_)
calculate b-tagged t-quark mass estimate
bool select(const edm::Event &event)
apply selection
~Calculate()
default destructor
double tmassWBoson(pat::Muon *lep, const pat::MET &met, const pat::Jet &b)
calculate W boson transverse mass estimate
SelectionStep(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
default constructor
double massTopQuark_
cache of top quark mass estimate
double massTopQuark_
cache of top quark mass estimate
double tmassTopQuark_
cache of top quark transverse mass estimate
Base class for all types of Jets.
Definition: Jet.h:20
bool selectVertex(const edm::Event &event)
edm::ESGetToken< JetCorrector, JetCorrectionsRecord > jetCorrector_
jet corrector as extra selection type
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
double massTopQuark(const std::vector< reco::Jet > &jets)
calculate t-quark mass estimate
edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfEs_
bool failed_
indicate failed associations
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:552
double massWBoson(const std::vector< pat::Jet > &jets)
calculate W boson mass estimate
double massWBoson_
cache of w boson mass estimate
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
~SelectionStep()
default destructor
electronId
when omitted electron plots will be filled w/o cut on electronId
void operator2(const std::vector< reco::Jet > &, std::vector< double >, double)
do the calculation of the t-quark mass with one b-jet
Helper class for the calculation of a top and a W boson mass estime.
int min_
min/max for object multiplicity
double tmassWBoson_
cache of W boson transverse mass estimate
int maxNJets_
max. number of jets to be considered
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
void operator()(const std::vector< pat::Jet > &jets)
Definition: MET.h:41
int maxNJets_
max. number of jets to be considered
double eidCutValue_
double wMass_
paramater of the w boson mass
double wMass_
paramater of the w boson mass
double tmassTopQuark(reco::RecoCandidate *lep, const reco::MET &met, const reco::Jet &b)
calculate top quark transverse mass estimate
double massTopQuark(const std::vector< pat::Jet > &jets)
calculate t-quark mass estimate
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:443
double tmassTopQuark(pat::Muon *lep, const pat::MET &met, const pat::Jet &b)
calculate top quark transverse mass estimate
void operator2(const std::vector< pat::Jet > &, std::vector< double >, double)
do the calculation of the t-quark mass with one b-jet
double tmassWBoson(reco::RecoCandidate *lep, const reco::MET &met, const reco::Jet &b)
calculate W boson transverse mass estimate
double massBTopQuark(const std::vector< pat::Jet > &jets, std::vector< double > VbtagWP, double btagWP_)
calculate b-tagged t-quark mass estimate
double b
Definition: hdecay.h:118
Analysis-level electron class.
Definition: Electron.h:51
Analysis-level calorimeter jet class.
Definition: Jet.h:77
double btagWorkingPoint_
choice of b-tag working point as extra selection type
Templated helper class to allow a selection on a certain object collection.
void operator()(const std::vector< reco::Jet > &jets)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
bool failed_
indicate failed associations
Calculate_miniAOD(int maxNJets, double wMass)
default constructor
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
double tmassTopQuark_
cache of top quark transverse mass estimate
edm::EDGetTokenT< edm::View< Object > > src_
input collection
Calculate(int maxNJets, double wMass)
default constructor
Definition: TopDQMHelpers.cc:3
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
static std::string const triggerPaths
Definition: EdmProvDump.cc:48
Analysis-level muon class.
Definition: Muon.h:51
StringCutObjectSelector< Object > select_
string cut selector
double tmassWBoson_
cache of W boson transverse mass estimate
double massBTopQuark_
cache of b-tagged top quark mass estimate
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
Definition: event.py:1