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 using namespace std;
25 inline bool
26 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath)
27 {
28  bool passed=false;
29  const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
30  for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
31  if(triggerNames.triggerNames()[i] == triggerPath) {
32  if(triggerTable.accept(i)){
33  passed=true;
34  break;
35  }
36  }
37  }
38  return passed;
39 }
40 
41 inline bool
42 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
43 {
44  bool passed=false;
45  for(unsigned int j=0; j<triggerPaths.size(); ++j){
46  if(accept(event, triggerTable, triggerPaths[j])){
47  passed=true;
48  break;
49  }
50  }
51  return passed;
52 }
53 
54 
57 
69 class Calculate {
70  public:
72  Calculate(int maxNJets, double wMass);
75 
77  double massWBoson(const std::vector<reco::Jet>& jets);
79  double massTopQuark(const std::vector<reco::Jet>& jets);
81  //double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<bool> bjet);
82  double massBTopQuark(const std::vector<reco::Jet>& jets, std::vector<double> VbtagWP, double btagWP_);
83 
85  double tmassWBoson(reco::RecoCandidate* lep, const reco::MET& met, const reco::Jet& b);
87  double tmassTopQuark(reco::RecoCandidate* lep, const reco::MET& met, const reco::Jet& b);
88 
89  private:
93  void operator()(const std::vector<reco::Jet>& jets);
95  void operator2(const std::vector<reco::Jet>& , std::vector<double> , double);
97  void operator()(const reco::Jet& bJet, reco::RecoCandidate* lepton, const reco::MET& met);
98 
99 
100  private:
102  bool failed_;
106  double wMass_;
108  double massWBoson_;
114  double tmassWBoson_;
117 
118 
119 
120 };
121 
122 
133 
174 template <typename Object>
176 public:
181 
183  bool select(const edm::Event& event);
184  bool select(const edm::Event& event, const std::string& type );
186  bool select(const edm::Event& event, const edm::EventSetup& setup);
187  bool selectVertex(const edm::Event& event);
188 private:
192  int min_, max_;
214 
221 
222 };
223 
225 template <typename Object>
227  select_(cfg.getParameter<std::string>("select")),
228  jetIDSelect_( 0)
229 {
230  //cout<<"In new constructor"<<endl;
231  src_ = iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
232  //cout<<"// construct min/max if the corresponding params"<<endl;
233  // exist otherwise they are initialized with -1
234  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
235  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
236  //cout<<"// read electron extras if they exist"<<endl;
237  std::string mygSF = "gedGsfElectrons";
238  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
239  if(cfg.existsAs<edm::ParameterSet>("electronId")){
240  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
241  electronId_= iC.consumes<edm::ValueMap<float> >(elecId.getParameter<edm::InputTag>("src"));
242  eidPattern_= elecId.getParameter<int>("pattern");
243  }
244  //cout<<"// read jet corrector label if it exists"<<endl;
245  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
246  //cout<<"// read btag information if it exists"<<endl;
247  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
248  edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
249  btagLabel_=iC.consumes<reco::JetTagCollection>(jetBTagger.getParameter<edm::InputTag>("label"));
250  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
251  }
252  //cout<<"// read jetID information if it exists"<<endl;
253  if(cfg.existsAs<edm::ParameterSet>("jetID")){
255  jetIDLabel_ =iC.consumes<reco::JetIDValueMap>(jetID.getParameter<edm::InputTag>("label"));
257  }
258  //cout<<"// end"<<endl;
259 }
260 
262 template <typename Object>
264 {
265  // fetch input collection
267  if( !event.getByToken(src_, src) ) return false;
268 
269  // load electronId value map if configured such
271  if(!electronId_.isUninitialized()){
272  if( !event.getByToken(electronId_, electronId) ) return false;
273  }
274 
275  // determine multiplicity of selected objects
276  int n=0;
277  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
278  // special treatment for electrons
279  if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
280  unsigned int idx = obj-src->begin();
281  if( electronId_.isUninitialized() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){
282  if(select_(*obj))++n;
283  }
284  }
285  // normal treatment
286  else{
287  if(select_(*obj))++n;
288  }
289  }
290  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
291  return (min_<0 && max_<0) ? (n>0):accept;
292 }
293 
294 
296 template <typename Object>
298 {
299  // fetch input collection
301  if( !event.getByToken(src_, src) ) return false;
302 
303  // special for gsfElectron
305 
306  // load electronId value map if configured such
308  if(!electronId_.isUninitialized()){
309  if( !event.getByToken(electronId_, electronId) ) return false;
310  }
311 
312  // determine multiplicity of selected objects
313  int n=0;
314  unsigned int idx_gsf = 0;
315  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
316 
317 
318  // special treatment for PF candidates
319  if (dynamic_cast<const reco::PFCandidate*>(&*obj)){
320  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
321 
322  if (objtmp.muonRef().isNonnull() && type == "muon") {
323 
324  if(select_(*obj)){++n;
325  }
326  }
327  else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
328  if( !event.getByToken(gsfEs_, elecs_gsf) ) continue;
329  if(select_(*obj)){
330  if(elecs_gsf->refAt(idx_gsf).isNonnull()){
331  int eID=0;
332  if (!electronId_.isUninitialized()){
333  eID = (int)(*electronId)[elecs_gsf->refAt(idx_gsf)];
334  }
335  if( electronId_.isUninitialized() ? true : ( (eID & eidPattern_) && (eID >= 5) ) )
336  ++n;
337 
338  }
339  }
340  idx_gsf++;
341  }
342  }
343 
344  // special treatment for electrons
345  else if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
346  unsigned int idx = obj-src->begin();
347  int eID = (int)(*electronId)[src->refAt(idx)];
348  if( electronId_.isUninitialized() ? true : ( (eID & eidPattern_) && (eID >= 5) ) ){
349  if(select_(*obj))++n;
350  }
351  }
352 
353 
354  // normal treatment
355  else{
356  if(select_(*obj))++n;
357  }
358  }
359  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
360  return (min_<0 && max_<0) ? (n>0):accept;
361 }
362 
363 
364 template <typename Object>
366 {
367  // fetch input collection
369  if( !event.getByToken(src_, src) ) return false;
370 
371  // load electronId value map if configured such
373  if(!electronId_.isUninitialized()) {
374  if( !event.getByToken(electronId_, electronId) ) return false;
375  }
376 
377  // determine multiplicity of selected objects
378  int n=0;
379  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
380 
381  if(select_(*obj))++n;
382  }
383  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
384  return (min_<0 && max_<0) ? (n>0):accept;
385 }
386 
388 template <typename Object>
390 {
391  // fetch input collection
393  if( !event.getByToken(src_, src) ) return false;
394 
395  // load btag collection if configured such
396  // NOTE that the JetTagCollection needs an
397  // edm::View to reco::Jets; we have to add
398  // another Handle bjets for this purpose
402  if(!btagLabel_.isUninitialized()){
403  if( !event.getByToken(src_, bjets) ) return false;
404  if( !event.getByToken(btagLabel_, btagger) ) return false;
405  if( !event.getByToken(pvs_, pvertex) ) return false;
406  }
407 
408  // load jetID value map if configured such
410  if(jetIDSelect_){
411  if( !event.getByToken(jetIDLabel_, jetID) ) return false;
412 
413  }
414 
415  // load jet corrector if configured such
416  const JetCorrector* corrector=0;
417  if(!jetCorrector_.empty()){
418  // check whether a jet correcto is in the event setup or not
419  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
420  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
421  }
422  else{
423  edm::LogVerbatim( "TopDQMHelpers" )
424  << "\n"
425  << "------------------------------------------------------------------------------------- \n"
426  << " No JetCorrectionsRecord available from EventSetup: \n"
427  << " - Jets will not be corrected. \n"
428  << " - If you want to change this add the following lines to your cfg file \n"
429  << " \n"
430  << " ## load jet corrections \n"
431  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
432  << " process.prefer(\"ak5CaloL2L3\") \n"
433  << " \n"
434  << "------------------------------------------------------------------------------------- \n";
435  }
436  }
437  // determine multiplicity of selected objects
438  int n=0;
439  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
440  // check for chosen btag discriminator to be above the
441  // corresponding working point if configured such
442  unsigned int idx = obj-src->begin();
443  if( btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
444  bool passedJetID=true;
445  // check jetID for calo jets
446  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
447  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
448  }
449  if(passedJetID){
450  // scale jet energy if configured such
451  Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
452  if(select_(jet))++n;
453  }
454  }
455  }
456  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
457  return (min_<0 && max_<0) ? (n>0):accept;
458 }
459 
460 
461 
462 
463 
464 
465 
466 
467 #endif
468 
469 /* Local Variables: */
470 /* show-trailing-whitespace: t */
471 /* truncate-lines: t */
472 /* End: */
double massWBoson_
cache of w boson mass estimate
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
bool select(const edm::Event &event)
apply selection
~Calculate()
default destructor
Definition: TopDQMHelpers.h:74
SelectionStep(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
default constructor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfEs_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
~SelectionStep()
default destructor
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
Helper class for the calculation of a top and a W boson mass estime.
Definition: TopDQMHelpers.h:69
int min_
min/max for object multiplicity
int maxNJets_
max. number of jets to be considered
Definition: MET.h:39
vector< PseudoJet > jets
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:570
int j
Definition: DBlmapReader.cc:9
double wMass_
paramater of the w boson mass
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
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:446
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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
double btagWorkingPoint_
choice of b-tag working point as extra selection type
Templated helper class to allow a selection on a certain object collection.
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
bool failed_
indicate failed associations
edm::EDGetTokenT< edm::View< Object > > src_
input collection
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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