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 
11 
21 inline bool
22 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath)
23 {
24  bool passed=false;
25  const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
26  for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
27  if(triggerNames.triggerNames()[i] == triggerPath) {
28  if(triggerTable.accept(i)){
29  passed=true;
30  break;
31  }
32  }
33  }
34  return passed;
35 }
36 
37 inline bool
38 accept(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
39 {
40  bool passed=false;
41  for(unsigned int j=0; j<triggerPaths.size(); ++j){
42  if(accept(event, triggerTable, triggerPaths[j])){
43  passed=true;
44  break;
45  }
46  }
47  return passed;
48 }
49 
50 
53 
65 class Calculate {
66  public:
68  Calculate(int maxNJets, double wMass);
71 
73  double massWBoson(const std::vector<reco::Jet>& jets);
75  double massTopQuark(const std::vector<reco::Jet>& jets);
76 
77  private:
81  void operator()(const std::vector<reco::Jet>& jets);
82 
83  private:
85  bool failed_;
87  int maxNJets_;
89  double wMass_;
91  double massWBoson_;
93  double massTopQuark_;
94 };
95 
96 
107 
148 template <typename Object>
150 public:
152  SelectionStep(const edm::ParameterSet& cfg);
155 
157  bool select(const edm::Event& event);
159  bool select(const edm::Event& event, const edm::EventSetup& setup);
160  bool selectVertex(const edm::Event& event);
161 private:
165  int min_, max_;
187 
189 
194 };
195 
197 template <typename Object>
199  src_( cfg.getParameter<edm::InputTag>( "src" )),
200  select_( cfg.getParameter<std::string>("select")),
201  jetIDSelect_(0)
202 {
203  // construct min/max if the corresponding params
204  // exist otherwise they are initialized with -1
205  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
206  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
207  // read electron extras if they exist
208  if(cfg.existsAs<edm::ParameterSet>("electronId")){
209  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
210  electronId_= elecId.getParameter<edm::InputTag>("src");
211  eidPattern_= elecId.getParameter<int>("pattern");
212  }
213  // read jet corrector label if it exists
214  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
215  // read btag information if it exists
216  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
217  edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
218  btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
219  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
220  }
221  // read jetID information if it exists
222  if(cfg.existsAs<edm::ParameterSet>("jetID")){
224  jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
226  }
227 }
228 
230 template <typename Object>
232 {
233  // fetch input collection
235  if( !event.getByLabel(src_, src) ) return false;
236 
237  // load electronId value map if configured such
239  if(!electronId_.label().empty()) {
240  if( !event.getByLabel(electronId_, electronId) ) return false;
241  }
242 
243  // determine multiplicity of selected objects
244  int n=0;
245  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
246  // special treatment for electrons
247  if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
248  unsigned int idx = obj-src->begin();
249  if( electronId_.label().empty() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){
250  if(select_(*obj))++n;
251  }
252  }
253  // normal treatment
254  else{
255  if(select_(*obj))++n;
256  }
257  }
258  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
259  return (min_<0 && max_<0) ? (n>0):accept;
260 }
261 template <typename Object>
263 {
264  // fetch input collection
266  if( !event.getByLabel(src_, src) ) return false;
267 
268  // load electronId value map if configured such
270  if(!electronId_.label().empty()) {
271  if( !event.getByLabel(electronId_, electronId) ) return false;
272  }
273 
274  // determine multiplicity of selected objects
275  int n=0;
276  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
277 
278  if(select_(*obj))++n;
279  }
280  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
281  return (min_<0 && max_<0) ? (n>0):accept;
282 }
283 
285 template <typename Object>
287 {
288  // fetch input collection
290  if( !event.getByLabel(src_, src) ) return false;
291 
292  // load btag collection if configured such
293  // NOTE that the JetTagCollection needs an
294  // edm::View to reco::Jets; we have to add
295  // another Handle bjets for this purpose
299  if(!btagLabel_.label().empty()){
300  if( !event.getByLabel(src_, bjets) ) return false;
301  if( !event.getByLabel(btagLabel_, btagger) ) return false;
302  if( !event.getByLabel(pvs_, pvertex) ) return false;
303  }
304 
305  // load jetID value map if configured such
307  if(jetIDSelect_){
308  if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
309 
310  }
311 
312  // load jet corrector if configured such
313  const JetCorrector* corrector=0;
314  if(!jetCorrector_.empty()){
315  // check whether a jet correcto is in the event setup or not
316  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
317  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
318  }
319  else{
320  edm::LogVerbatim( "TopDQMHelpers" )
321  << "\n"
322  << "------------------------------------------------------------------------------------- \n"
323  << " No JetCorrectionsRecord available from EventSetup: \n"
324  << " - Jets will not be corrected. \n"
325  << " - If you want to change this add the following lines to your cfg file \n"
326  << " \n"
327  << " ## load jet corrections \n"
328  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
329  << " process.prefer(\"ak5CaloL2L3\") \n"
330  << " \n"
331  << "------------------------------------------------------------------------------------- \n";
332  }
333  }
334  // determine multiplicity of selected objects
335  int n=0;
336  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
337  // check for chosen btag discriminator to be above the
338  // corresponding working point if configured such
339  unsigned int idx = obj-src->begin();
340  if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
341  bool passedJetID=true;
342  // check jetID for calo jets
343  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
344  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
345  }
346  if(passedJetID){
347  // scale jet energy if configured such
348  Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
349  if(select_(jet))++n;
350  }
351  }
352  }
353  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
354  return (min_<0 && max_<0) ? (n>0):accept;
355 }
356 
357 #endif
double massWBoson_
cache of w boson mass estimate
Definition: TopDQMHelpers.h:91
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
bool select(const edm::Event &event)
apply selection
edm::InputTag src_
input collection
~Calculate()
default destructor
Definition: TopDQMHelpers.h:70
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
double massTopQuark_
cache of top quark mass estimate
Definition: TopDQMHelpers.h:93
bool selectVertex(const edm::Event &event)
bool accept() const
Has at least one path accepted the event?
double massTopQuark(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:22
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
double massWBoson(const std::vector< reco::Jet > &jets)
calculate W boson mass estimate
Definition: TopDQMHelpers.cc:9
~SelectionStep()
default destructor
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
edm::InputTag pvs_
edm::InputTag jetIDLabel_
jetID as an extra selection type
Helper class for the calculation of a top and a W boson mass estime.
Definition: TopDQMHelpers.h:65
int min_
min/max for object multiplicity
int maxNJets_
max. number of jets to be considered
Definition: TopDQMHelpers.h:87
vector< PseudoJet > jets
int j
Definition: DBlmapReader.cc:9
double wMass_
paramater of the w boson mass
Definition: TopDQMHelpers.h:89
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
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:51
edm::InputTag electronId_
electronId label as extra selection type
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)
bool failed_
indicate failed associations
Definition: TopDQMHelpers.h:85
Calculate(int maxNJets, double wMass)
default constructor
Definition: TopDQMHelpers.cc:3
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
std::string jetCorrector_
jet corrector as extra selection type
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::InputTag btagLabel_
choice for b-tag as extra selection type
StringCutObjectSelector< Object > select_
string cut selector
SelectionStep(const edm::ParameterSet &cfg)
default constructor