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 
190 
239 template <typename Object>
241 public:
246 
248  bool select(const edm::Event& event);
249  bool select(const edm::Event& event, const std::string& type);
251  bool select(const edm::Event& event, const edm::EventSetup& setup);
252  bool selectVertex(const edm::Event& event);
253 
254 private:
258  int min_, max_;
272  double eidCutValue_;
281 
288 };
289 
291 template <typename Object>
293  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(nullptr) {
294  src_ = iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
295  // exist otherwise they are initialized with -1
296  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
297  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
298  std::string mygSF = "gedGsfElectrons";
299  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
300  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
301  edm::ParameterSet elecId = cfg.getParameter<edm::ParameterSet>("electronId");
302  electronId_ = iC.consumes<edm::ValueMap<float> >(elecId.getParameter<edm::InputTag>("src"));
303  eidCutValue_ = elecId.getParameter<double>("cutValue");
304  }
305  if (cfg.exists("jetCorrector")) {
306  jetCorrector_ = iC.consumes<reco::JetCorrector>(edm::InputTag(cfg.getParameter<std::string>("jetCorrector")));
307  }
308  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
309  edm::ParameterSet jetBTagger = cfg.getParameter<edm::ParameterSet>("jetBTagger");
310  btagLabel_ = iC.consumes<reco::JetTagCollection>(jetBTagger.getParameter<edm::InputTag>("label"));
311  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
312  }
313  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
314  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
315  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
317  }
318 }
319 
321 template <typename Object>
323  // fetch input collection
325  if (!event.getByToken(src_, src))
326  return false;
327 
328  // load electronId value map if configured such
330  if (!electronId_.isUninitialized()) {
331  if (!event.getByToken(electronId_, electronId))
332  return false;
333  }
334 
335  // determine multiplicity of selected objects
336  int n = 0;
337  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
338  // special treatment for electrons
339  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
340  unsigned int idx = obj - src->begin();
341  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
342  if (select_(*obj))
343  ++n;
344  }
345  }
346  // normal treatment
347  else {
348  if (select_(*obj))
349  ++n;
350  }
351  }
352  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
353  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
354 }
355 
357 template <typename Object>
359  // fetch input collection
361  if (!event.getByToken(src_, src))
362  return false;
363 
364  // special for gsfElectron
366 
367  // load electronId value map if configured such
369  if (!electronId_.isUninitialized()) {
370  if (!event.getByToken(electronId_, electronId))
371  return false;
372  }
373 
374  // determine multiplicity of selected objects
375  int n = 0;
376  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
377  // special treatment for PF candidates
378  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
379  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
380 
381  if (objtmp.muonRef().isNonnull() && type == "muon") {
382  if (select_(*obj)) {
383  ++n;
384  }
385  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
386  if (select_(*obj)) {
387  if (electronId_.isUninitialized()) {
388  ++n;
389  } else if (((double)(*electronId)[obj->gsfElectronRef()] >= eidCutValue_)) {
390  ++n;
391  }
392  }
393  // idx_gsf++;
394  }
395  }
396 
397  // special treatment for electrons
398  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
399  unsigned int idx = obj - src->begin();
400  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
401  if (select_(*obj))
402  ++n;
403  }
404  }
405 
406  // normal treatment
407  else {
408  if (select_(*obj))
409  ++n;
410  }
411  }
412  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
413  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
414 }
415 
416 template <typename Object>
418  // fetch input collection
420  if (!event.getByToken(src_, src))
421  return false;
422 
423  // load electronId value map if configured such
425  if (!electronId_.isUninitialized()) {
426  if (!event.getByToken(electronId_, electronId))
427  return false;
428  }
429 
430  // determine multiplicity of selected objects
431  int n = 0;
432  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
433  if (select_(*obj))
434  ++n;
435  }
436  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
437  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
438 }
439 
441 template <typename Object>
443  // fetch input collection
445  if (!event.getByToken(src_, src))
446  return false;
447 
448  // load btag collection if configured such
449  // NOTE that the JetTagCollection needs an
450  // edm::View to reco::Jets; we have to add
451  // another Handle bjets for this purpose
455  if (!btagLabel_.isUninitialized()) {
456  if (!event.getByToken(src_, bjets))
457  return false;
458  if (!event.getByToken(btagLabel_, btagger))
459  return false;
460  if (!event.getByToken(pvs_, pvertex))
461  return false;
462  }
463 
464  // load jetID value map if configured such
466  if (jetIDSelect_) {
467  if (!event.getByToken(jetIDLabel_, jetID))
468  return false;
469  }
470 
471  // load jet corrector if configured such
472  const reco::JetCorrector* corrector = nullptr;
473  if (!jetCorrector_.isUninitialized()) {
474  // check whether a jet corrector is in the event or not
475  edm::Handle<reco::JetCorrector> correctorHandle = event.getHandle(jetCorrector_);
476  if (correctorHandle.isValid()) {
477  corrector = correctorHandle.product();
478  } else {
479  edm::LogVerbatim("TopDQMHelpers") << "\n"
480  << "---------------------------------------------------------------\n"
481  << " No reco::JetCorrrector available from Event:\n"
482  << " - Jets will not be corrected.\n"
483  << "---------------------------------------------------------------"
484  "\n";
485  }
486  }
487  // determine multiplicity of selected objects
488  int n = 0;
489  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
490  // check for chosen btag discriminator to be above the
491  // corresponding working point if configured such
492  unsigned int idx = obj - src->begin();
493  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] > btagWorkingPoint_) {
494  bool passedJetID = true;
495  // check jetID for calo jets
496  if (jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
497  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
498  }
499  if (passedJetID) {
500  // scale jet energy if configured such
501  Object jet = *obj;
502  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
503  if (select_(jet))
504  ++n;
505  }
506  }
507  }
508  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
509  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
510 }
511 
512 #endif
513 
514 /* Local Variables: */
515 /* show-trailing-whitespace: t */
516 /* truncate-lines: t */
517 /* 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:307
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::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
T const * product() const
Definition: Handle.h:70
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:232
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:559
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:450
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:120
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
edm::EDGetTokenT< reco::JetCorrector > jetCorrector_
jet corrector as extra selection type
bool isValid() const
Definition: HandleBase.h:70
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:88
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