test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>
15 
20 
30 inline bool accept(const edm::Event& event,
31  const edm::TriggerResults& triggerTable,
32  const std::string& triggerPath) {
33  bool passed = false;
34  const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
35  for (unsigned int i = 0; i < triggerNames.triggerNames().size(); ++i) {
36  if (triggerNames.triggerNames()[i] == triggerPath) {
37  if (triggerTable.accept(i)) {
38  passed = true;
39  break;
40  }
41  }
42  }
43  return passed;
44 }
45 
46 inline bool accept(const edm::Event& event,
47  const edm::TriggerResults& triggerTable,
48  const std::vector<std::string>& triggerPaths) {
49  bool passed = false;
50  for (unsigned int j = 0; j < triggerPaths.size(); ++j) {
51  if (accept(event, triggerTable, triggerPaths[j])) {
52  passed = true;
53  break;
54  }
55  }
56  return passed;
57 }
58 
61 
73  public:
75  Calculate_miniAOD(int maxNJets, double wMass);
78 
80  double massWBoson(const std::vector<pat::Jet>& jets);
82  double massTopQuark(const std::vector<pat::Jet>& jets);
84  // double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<bool>
85  // bjet);
86  double massBTopQuark(const std::vector<pat::Jet>& jets,
87  std::vector<double> VbtagWP, double btagWP_);
88 
90  double tmassWBoson(pat::Muon* lep, const pat::MET& met,
91  const pat::Jet& b);
93  double tmassTopQuark(pat::Muon* lep, const pat::MET& met,
94  const pat::Jet& b);
95 
96 
98  double tmassWBoson(pat::Electron* lep, const pat::MET& met,
99  const pat::Jet& b);
101  double tmassTopQuark(pat::Electron* lep, const pat::MET& met,
102  const pat::Jet& b);
103 
104  private:
108  void operator()(const std::vector<pat::Jet>& jets);
110  void operator2(const std::vector<pat::Jet>&, std::vector<double>, double);
112  void operator()(const pat::Jet& bJet, pat::Electron* lepton,
113  const pat::MET& met);
114 
115  void operator()(const pat::Jet& bJet, pat::Muon* lepton,
116  const pat::MET& met);
117 
118  private:
120  bool failed_;
124  double wMass_;
126  double massWBoson_;
132  double tmassWBoson_;
135 };
136 
137 
138 
139 class Calculate {
140  public:
142  Calculate(int maxNJets, double wMass);
145 
147  double massWBoson(const std::vector<reco::Jet>& jets);
149  double massTopQuark(const std::vector<reco::Jet>& jets);
151  // double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<bool>
152  // bjet);
153  double massBTopQuark(const std::vector<reco::Jet>& jets,
154  std::vector<double> VbtagWP, double btagWP_);
155 
157  double tmassWBoson(reco::RecoCandidate* lep, const reco::MET& met,
158  const reco::Jet& b);
160  double tmassTopQuark(reco::RecoCandidate* lep, const reco::MET& met,
161  const reco::Jet& b);
162 
163  private:
167  void operator()(const std::vector<reco::Jet>& jets);
169  void operator2(const std::vector<reco::Jet>&, std::vector<double>, double);
171  void operator()(const reco::Jet& bJet, reco::RecoCandidate* lepton,
172  const reco::MET& met);
173 
174  private:
176  bool failed_;
180  double wMass_;
182  double massWBoson_;
188  double tmassWBoson_;
191 };
192 
203 
252 template <typename Object>
254  public:
259 
261  bool select(const edm::Event& event);
262  bool select(const edm::Event& event, const std::string& type);
264  bool select(const edm::Event& event, const edm::EventSetup& setup);
265  bool selectVertex(const edm::Event& event);
266 
267  private:
271  int min_, max_;
285  double eidCutValue_;
294 
301 };
302 
304 template <typename Object>
307  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(0) {
308 
309  src_ =
310  iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
311  // exist otherwise they are initialized with -1
312  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
313  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
314  std::string mygSF = "gedGsfElectrons";
315  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(
316  cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
317  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
318  edm::ParameterSet elecId =
319  cfg.getParameter<edm::ParameterSet>("electronId");
320  electronId_ = iC.consumes<edm::ValueMap<float> >(
321  elecId.getParameter<edm::InputTag>("src"));
322  eidCutValue_ = elecId.getParameter<double>("cutValue");
323  }
324  if (cfg.exists("jetCorrector")) {
325  jetCorrector_ = cfg.getParameter<std::string>("jetCorrector");
326  }
327  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
328  edm::ParameterSet jetBTagger =
329  cfg.getParameter<edm::ParameterSet>("jetBTagger");
330  btagLabel_ = iC.consumes<reco::JetTagCollection>(
331  jetBTagger.getParameter<edm::InputTag>("label"));
332  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
333  }
334  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
335  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
336  jetIDLabel_ = iC.consumes<reco::JetIDValueMap>(
337  jetID.getParameter<edm::InputTag>("label"));
339  jetID.getParameter<std::string>("select"));
340  }
341 }
342 
344 template <typename Object>
346 
347  // fetch input collection
349  if (!event.getByToken(src_, src)) return false;
350 
351  // load electronId value map if configured such
353  if (!electronId_.isUninitialized()) {
354  if (!event.getByToken(electronId_, electronId)) return false;
355  }
356 
357  // determine multiplicity of selected objects
358  int n = 0;
359  for (typename edm::View<Object>::const_iterator obj = src->begin();
360  obj != src->end(); ++obj) {
361  // special treatment for electrons
362  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
363  unsigned int idx = obj - src->begin();
364  if (electronId_.isUninitialized()
365  ? true
366  : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
367  if (select_(*obj)) ++n;
368  }
369  }
370  // normal treatment
371  else {
372  if (select_(*obj)) ++n;
373  }
374  }
375  bool accept =
376  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
377  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
378 }
379 
381 template <typename Object>
383  const std::string& type) {
384  // fetch input collection
386  if (!event.getByToken(src_, src)) return false;
387 
388  // special for gsfElectron
390 
391  // load electronId value map if configured such
393  if (!electronId_.isUninitialized()) {
394  if (!event.getByToken(electronId_, electronId)) return false;
395  }
396 
397  // determine multiplicity of selected objects
398  int n = 0;
399  for (typename edm::View<Object>::const_iterator obj = src->begin();
400  obj != src->end(); ++obj) {
401 
402  // special treatment for PF candidates
403  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
404  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
405 
406  if (objtmp.muonRef().isNonnull() && type == "muon") {
407  if (select_(*obj)) {
408  ++n;
409  }
410  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
411  if (select_(*obj)) {
412  if (electronId_.isUninitialized()) {
413  ++n;
414  } else if (((double)(*electronId)[obj->gsfElectronRef()] >=
415  eidCutValue_)) {
416  ++n;
417  }
418  }
419  // idx_gsf++;
420  }
421  }
422 
423  // special treatment for electrons
424  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
425  unsigned int idx = obj - src->begin();
426  if (electronId_.isUninitialized()
427  ? true
428  : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
429  if (select_(*obj)) ++n;
430  }
431  }
432 
433  // normal treatment
434  else {
435  if (select_(*obj)) ++n;
436  }
437  }
438  bool accept =
439  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
440  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
441 }
442 
443 template <typename Object>
445  // fetch input collection
447  if (!event.getByToken(src_, src)) return false;
448 
449  // load electronId value map if configured such
451  if (!electronId_.isUninitialized()) {
452  if (!event.getByToken(electronId_, electronId)) return false;
453  }
454 
455  // determine multiplicity of selected objects
456  int n = 0;
457  for (typename edm::View<Object>::const_iterator obj = src->begin();
458  obj != src->end(); ++obj) {
459 
460  if (select_(*obj)) ++n;
461  }
462  bool accept =
463  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
464  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
465 }
466 
468 template <typename Object>
470  const edm::EventSetup& setup) {
471  // fetch input collection
473  if (!event.getByToken(src_, src)) return false;
474 
475  // load btag collection if configured such
476  // NOTE that the JetTagCollection needs an
477  // edm::View to reco::Jets; we have to add
478  // another Handle bjets for this purpose
482  if (!btagLabel_.isUninitialized()) {
483  if (!event.getByToken(src_, bjets)) return false;
484  if (!event.getByToken(btagLabel_, btagger)) return false;
485  if (!event.getByToken(pvs_, pvertex)) return false;
486  }
487 
488  // load jetID value map if configured such
490  if (jetIDSelect_) {
491  if (!event.getByToken(jetIDLabel_, jetID)) return false;
492  }
493 
494  // load jet corrector if configured such
495  const JetCorrector* corrector = 0;
496  if (!jetCorrector_.empty()) {
497  // check whether a jet correcto is in the event setup or not
499  JetCorrectionsRecord>())) {
500  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
501  } else {
502  edm::LogVerbatim("TopDQMHelpers")
503  << "\n"
504  << "---------------------------------------------------------------\n"
505  << " No JetCorrectionsRecord available from EventSetup:\n"
506  << " - Jets will not be corrected.\n"
507  << " - If you want to change this add the following lines to your "
508  "cfg file:\n"
509  << "\n"
510  << " ## load jet corrections\n"
511  << " process.load(\""
512  "JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff"
513  "\")\n"
514  << " process.prefer(\"ak5CaloL2L3\")\n"
515  << "---------------------------------------------------------------"
516  "\n";
517  }
518  }
519  // determine multiplicity of selected objects
520  int n = 0;
521  for (typename edm::View<Object>::const_iterator obj = src->begin();
522  obj != src->end(); ++obj) {
523  // check for chosen btag discriminator to be above the
524  // corresponding working point if configured such
525  unsigned int idx = obj - src->begin();
526  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] >
527  btagWorkingPoint_) {
528  bool passedJetID = true;
529  // check jetID for calo jets
530  if (jetIDSelect_ &&
531  dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
532  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
533  }
534  if (passedJetID) {
535  // scale jet energy if configured such
536  Object jet = *obj;
537  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
538  if (select_(jet)) ++n;
539  }
540  }
541  }
542  bool accept =
543  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
544  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
545 }
546 
547 #endif
548 
549 /* Local Variables: */
550 /* show-trailing-whitespace: t */
551 /* truncate-lines: t */
552 /* End: */
~Calculate_miniAOD()
default destructor
Definition: TopDQMHelpers.h:77
double massWBoson_
cache of w boson mass estimate
type
Definition: HCALResponse.h:21
Analysis-level MET class.
Definition: MET.h:43
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
double massBTopQuark_
cache of b-tagged top quark mass estimate
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
tuple cfg
Definition: looper.py:293
double massBTopQuark(const std::vector< reco::Jet > &jets, std::vector< double > VbtagWP, double btagWP_)
calculate b-tagged t-quark mass estimate
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
double massTopQuark_
cache of top quark mass estimate
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
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)
bool accept() const
Has at least one path accepted the event?
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
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfEs_
bool failed_
indicate failed associations
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:30
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
~SelectionStep()
default destructor
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
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)
tuple corrector
Definition: mvaPFMET_cff.py:86
Definition: MET.h:42
vector< PseudoJet > jets
int maxNJets_
max. number of jets to be considered
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:574
int j
Definition: DBlmapReader.cc:9
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
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
double massTopQuark(const std::vector< pat::Jet > &jets)
calculate t-quark mass estimate
double tmassTopQuark(pat::Muon *lep, const pat::MET &met, const pat::Jet &b)
calculate top quark transverse mass estimate
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
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
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double massBTopQuark(const std::vector< pat::Jet > &jets, std::vector< double > VbtagWP, double btagWP_)
calculate b-tagged t-quark mass estimate
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:50
double b
Definition: hdecay.h:120
Analysis-level electron class.
Definition: Electron.h:52
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:39
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:81
static EventSetupRecordKey makeKey()
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:42
std::string jetCorrector_
jet corrector as extra selection type
Analysis-level muon class.
Definition: Muon.h:49
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