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 = "gsfElectrons";
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  if(select_(*obj)){++n;
324  }
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 = (int)(*electronId)[elecs_gsf->refAt(idx_gsf)];
332  if( electronId_.isUninitialized() ? true : ( (eID & eidPattern_) && (eID >= 5) ) )
333  ++n;
334 
335  }
336  }
337  idx_gsf++;
338  }
339  }
340 
341  // special treatment for electrons
342  else if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
343  unsigned int idx = obj-src->begin();
344  int eID = (int)(*electronId)[src->refAt(idx)];
345  if( electronId_.isUninitialized() ? true : ( (eID & eidPattern_) && (eID >= 5) ) ){
346  if(select_(*obj))++n;
347  }
348  }
349 
350 
351  // normal treatment
352  else{
353  if(select_(*obj))++n;
354  }
355  }
356  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
357  return (min_<0 && max_<0) ? (n>0):accept;
358 }
359 
360 
361 template <typename Object>
363 {
364  // fetch input collection
366  if( !event.getByToken(src_, src) ) return false;
367 
368  // load electronId value map if configured such
370  if(!electronId_.isUninitialized()) {
371  if( !event.getByToken(electronId_, electronId) ) 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 
378  if(select_(*obj))++n;
379  }
380  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
381  return (min_<0 && max_<0) ? (n>0):accept;
382 }
383 
385 template <typename Object>
387 {
388  // fetch input collection
390  if( !event.getByToken(src_, src) ) return false;
391 
392  // load btag collection if configured such
393  // NOTE that the JetTagCollection needs an
394  // edm::View to reco::Jets; we have to add
395  // another Handle bjets for this purpose
399  if(!btagLabel_.isUninitialized()){
400  if( !event.getByToken(src_, bjets) ) return false;
401  if( !event.getByToken(btagLabel_, btagger) ) return false;
402  if( !event.getByToken(pvs_, pvertex) ) return false;
403  }
404 
405  // load jetID value map if configured such
407  if(jetIDSelect_){
408  if( !event.getByToken(jetIDLabel_, jetID) ) return false;
409 
410  }
411 
412  // load jet corrector if configured such
413  const JetCorrector* corrector=0;
414  if(!jetCorrector_.empty()){
415  // check whether a jet correcto is in the event setup or not
416  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
417  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
418  }
419  else{
420  edm::LogVerbatim( "TopDQMHelpers" )
421  << "\n"
422  << "------------------------------------------------------------------------------------- \n"
423  << " No JetCorrectionsRecord available from EventSetup: \n"
424  << " - Jets will not be corrected. \n"
425  << " - If you want to change this add the following lines to your cfg file \n"
426  << " \n"
427  << " ## load jet corrections \n"
428  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
429  << " process.prefer(\"ak5CaloL2L3\") \n"
430  << " \n"
431  << "------------------------------------------------------------------------------------- \n";
432  }
433  }
434  // determine multiplicity of selected objects
435  int n=0;
436  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
437  // check for chosen btag discriminator to be above the
438  // corresponding working point if configured such
439  unsigned int idx = obj-src->begin();
440  if( btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
441  bool passedJetID=true;
442  // check jetID for calo jets
443  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
444  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
445  }
446  if(passedJetID){
447  // scale jet energy if configured such
448  Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
449  if(select_(jet))++n;
450  }
451  }
452  }
453  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
454  return (min_<0 && max_<0) ? (n>0):accept;
455 }
456 
457 
458 
459 
460 
461 
462 
463 
464 #endif
465 
466 /* Local Variables: */
467 /* show-trailing-whitespace: t */
468 /* truncate-lines: t */
469 /* 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:7
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:32
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