CMS 3D CMS Logo

TopHLTOfflineDQMHelper.h
Go to the documentation of this file.
1 #ifndef TOPHLTOFFLINEDQMHELPER
2 #define TOPHLTOFFLINEDQMHELPER
3 
4 #include <string>
5 #include <vector>
6 //#include <math>
7 #include "TString.h"
14 
15 /*Originally from DQM/Physics package, written by Roger Wolf and Jeremy Andrea*/
25 inline bool
26 acceptHLT(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  TString name = triggerNames.triggerNames()[i].c_str();
32  //std::cout << name << " " << triggerTable.accept(i) << std::endl;
33  if(name.Contains(TString(triggerPath.c_str()), TString::kIgnoreCase)) {
34  if(triggerTable.accept(i)){
35  passed=true;
36  break;
37  }
38  }
39  }
40  return passed;
41 }
42 
43 inline bool
44 acceptHLT(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
45 {
46  bool passed=false;
47  for(const auto & triggerPath : triggerPaths){
48  if(acceptHLT(event, triggerTable, triggerPath)){
49  passed=true;
50  break;
51  }
52  }
53  return passed;
54 }
55 
56 
59 
72 class CalculateHLT {
73  public:
75  CalculateHLT(int maxNJets, double wMass);
77  ~CalculateHLT()= default;;
78 
80  double massWBoson(const std::vector<reco::Jet>& jets);
82  double massTopQuark(const std::vector<reco::Jet>& jets);
84 /* double tmassWBoson(const T& mu, const reco::CaloMET& met, const reco::Jet& b);
86  double tmassTopQuark(const T& mu, const reco::CaloMET& met, const reco::Jet& b);
88  double masslb(const T& mu, const reco::CaloMET& met, const reco::Jet& b);*/
89 
91  double tmassWBoson(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
93  double tmassTopQuark(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
95  double masslb(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
96 
97  private:
101  void operator()(const std::vector<reco::Jet>& jets);
102  void operator()(const reco::Jet& bJet, reco::RecoCandidate* lepton, const reco::MET& met);
103  private:
105  bool failed_;
109  double wMass_;
111  double massWBoson_;
115  double tmassWBoson_;
119  double mlb_;
120 
121 
122 };
123 
124 
136 
177  public:
178  virtual ~SelectionStepHLTBase() = default;
179  virtual bool select(const edm::Event& event) {
180  return false;
181  };
182 
183  virtual bool select(const edm::Event& event, const edm::EventSetup& setup) {
184  assert(false);
185  return false;
186  };
187 };
188 
189 template <typename Object>
191 public:
195  ~SelectionStepHLT() override = default;
196 
198  bool select(const edm::Event& event) override;
200  bool select(const edm::Event& event, const edm::EventSetup& setup) override;
201  bool selectVertex(const edm::Event& event);
202 private:
206  int min_, max_;
228 
230 
235 };
236 
238 template <typename Object>
240  src_( iC.consumes< edm::View<Object> >(cfg.getParameter<edm::InputTag>( "src" ))),
241  select_( cfg.getParameter<std::string>("select")),
242  jetIDSelect_(nullptr)
243 {
244  // construct min/max if the corresponding params
245  // exist otherwise they are initialized with -1
246  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
247  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
248  // read electron extras if they exist
249  if(cfg.existsAs<edm::ParameterSet>("electronId")){
250  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
251  electronId_= iC.consumes< edm::ValueMap<float> >(elecId.getParameter<edm::InputTag>("src"));
252  eidPattern_= elecId.getParameter<int>("pattern");
253  }
254  // read jet corrector label if it exists
255  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
256  // read btag information if it exists
257  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
258  edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
259  btagLabel_= iC.consumes< reco::JetTagCollection >(jetBTagger.getParameter<edm::InputTag>("label"));
260  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
261  }
262  // read jetID information if it exists
263  if(cfg.existsAs<edm::ParameterSet>("jetID")){
265  jetIDLabel_ = iC.consumes< reco::JetIDValueMap >(jetID.getParameter<edm::InputTag>("label"));
267  }
268 }
269 
271 template <typename Object>
273 {
274  // fetch input collection
276  if( !event.getByToken(src_, src) ) return false;
277 
278  // load electronId value map if configured such
281  if( !event.getByToken(electronId_, electronId) ) return false;
282  }
283 
284  // determine multiplicity of selected objects
285  int n=0;
286  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
287  // special treatment for electrons
288  if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
289  unsigned int idx = obj-src->begin();
290  if( electronId_.isUninitialized() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){
291  if(select_(*obj))++n;
292  }
293  }
294  // normal treatment
295  else{
296  if(select_(*obj))++n;
297  }
298  }
299  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
300  return (min_<0 && max_<0) ? (n>0):accept;
301 }
302 template <typename Object>
304 {
305  // fetch input collection
307  if( !event.getByToken(src_, src) ) return false;
308 
309  // load electronId value map if configured such
312  if( !event.getByToken(electronId_, electronId) ) return false;
313  }
314 
315  // determine multiplicity of selected objects
316  int n=0;
317  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
318 
319  if(select_(*obj))++n;
320  }
321  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
322  return (min_<0 && max_<0) ? (n>0):accept;
323 }
324 
325 template <typename Object>
327 {
328  throw cms::Exception("SelectionStepHLT") << "you fail" << std::endl;
329  return false;
330 }
331 #endif
T getParameter(std::string const &) const
bool failed_
indicate failed associations
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
bool select(const edm::Event &event) override
apply selection
double masslb(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate mlb estimate
double massTopQuark(const std::vector< reco::Jet > &jets)
calculate top quark mass estimate
void operator()(const std::vector< reco::Jet > &jets)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
double wMass_
paramater of the w boson mass
Base class for all types of Jets.
Definition: Jet.h:20
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
int min_
min/max for object multiplicity
bool accept() const
Has at least one path accepted the event?
double tmassTopQuark(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate top quark transverse mass estimate
bool exists(std::string const &parameterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
virtual bool select(const edm::Event &event, const edm::EventSetup &setup)
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
CalculateHLT(int maxNJets, double wMass)
default constructor
#define nullptr
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
SelectionStepHLT(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
default constructor
double massWBoson_
cache of w boson mass estimate
bool selectVertex(const edm::Event &event)
double mlb_
cache of mlb estimate
Definition: MET.h:42
vector< PseudoJet > jets
double massTopQuark_
cache of top quark mass estimate
const int mu
Definition: Constants.h:22
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
maxNJets
maximum number of jets taken into account per event for each hypothesis (this parameter is used in th...
double tmassWBoson(reco::RecoCandidate *mu, const reco::MET &met, const reco::Jet &b)
calculate W boson transverse mass estimate
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
~CalculateHLT()=default
default destructor
StringCutObjectSelector< Object > select_
string cut selector
bool acceptHLT(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
met
===> hadronic RAZOR
edm::EDGetTokenT< edm::View< Object > > src_
input collection
double tmassWBoson_
cache of W boson transverse mass estimate
virtual bool select(const edm::Event &event)
double b
Definition: hdecay.h:120
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
int maxNJets_
max. number of jets to be considered
double btagWorkingPoint_
choice of b-tag working point as extra selection type
HLT enums.
std::string jetCorrector_
jet corrector as extra selection type
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
bool isUninitialized() const
Definition: EDGetToken.h:73
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
double tmassTopQuark_
cache of top quark transverse mass estimate
static std::string const triggerPaths
Definition: EdmProvDump.cc:43
Definition: event.py:1