CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
SelectionStep< Object > Class Template Reference

Templated helper class to allow a selection on a certain object collection. More...

#include "DQM/Physics/interface/TopDQMHelpers.h"

Public Member Functions

bool select (const edm::Event &event)
 apply selection More...
 
bool select (const edm::Event &event, const std::string &type)
 apply selection with special treatment for PFCandidates More...
 
bool select (const edm::Event &event, const edm::EventSetup &setup)
 apply selection override for jets More...
 
 SelectionStep (const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
 default constructor More...
 
bool selectVertex (const edm::Event &event)
 
 ~SelectionStep ()
 default destructor More...
 

Private Attributes

edm::EDGetTokenT
< reco::JetTagCollection
btagLabel_
 choice for b-tag as extra selection type More...
 
double btagWorkingPoint_
 choice of b-tag working point as extra selection type More...
 
int eidPattern_
 
edm::EDGetTokenT
< edm::ValueMap< float > > 
electronId_
 electronId label as extra selection type More...
 
edm::EDGetTokenT< edm::View
< reco::GsfElectron > > 
gsfEs_
 
std::string jetCorrector_
 jet corrector as extra selection type More...
 
edm::EDGetTokenT
< reco::JetIDValueMap
jetIDLabel_
 jetID as an extra selection type More...
 
StringCutObjectSelector
< reco::JetID > * 
jetIDSelect_
 selection string on the jetID More...
 
int max_
 
int min_
 min/max for object multiplicity More...
 
edm::EDGetTokenT< edm::View
< reco::Vertex > > 
pvs_
 
StringCutObjectSelector< Object > select_
 string cut selector More...
 
edm::EDGetTokenT< edm::View
< Object > > 
src_
 input collection More...
 

Detailed Description

template<typename Object>
class SelectionStep< Object >

Templated helper class to allow a selection on a certain object collection.

Templated helper class to allow a selection on a certain object collection, which may be monitored by a separate class afterwards. The class wraps and slightly extends the features of the StringCutParser to allow also to apply event based selections, according to a minimal or maximal number of elements in the collection after the object selection has been applied. It takes an edm::ParameterSet in the constructor, which should contain the following elements:

The parameters src and select are mandatory. The parameters min and max are optional. The parameters electronId and jetCorrector are optional. They are added to keep the possibility to apply selections on id'ed electrons or on corrected jets. They may be omitted in the PSet for simplification reasons if not needed at any time. They are not effiective for other object collections but electrons or jets. If none of the two parameters min or max is found in the event the select function returns true if at least one object fullfilled the requirements.

The class has one template value, which is the object collection to apply the selection on. This has to be parsed to the StringCutParser class. The function select is overrided for jets to circumvent problems with the template specialisation. Note that for MET not type1 or muon corrections are supported on reco candidates.

Definition at line 175 of file TopDQMHelpers.h.

Constructor & Destructor Documentation

template<typename Object >
SelectionStep< Object >::SelectionStep ( const edm::ParameterSet cfg,
edm::ConsumesCollector &&  iC 
)

default constructor

Definition at line 226 of file TopDQMHelpers.h.

References SelectionStep< Object >::btagLabel_, SelectionStep< Object >::btagWorkingPoint_, SelectionStep< Object >::eidPattern_, SelectionStep< Object >::electronId_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), SelectionStep< Object >::gsfEs_, SelectionStep< Object >::jetCorrector_, bTagSequences_cff::jetID, SelectionStep< Object >::jetIDLabel_, SelectionStep< Object >::jetIDSelect_, SelectionStep< Object >::max_, SelectionStep< Object >::min_, SelectionStep< Object >::src_, and AlCaHLTBitMon_QueryRunRegistry::string.

226  :
227  select_(cfg.getParameter<std::string>("select")),
228  jetIDSelect_( 0)
229 {
230  //cout<<"In new constructor"<<endl;
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";
239  if(cfg.existsAs<edm::ParameterSet>("electronId")){
240  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
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");
250  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
251  }
252  //cout<<"// read jetID information if it exists"<<endl;
253  if(cfg.existsAs<edm::ParameterSet>("jetID")){
257  }
258  //cout<<"// end"<<endl;
259 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
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_
int min_
min/max for object multiplicity
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
double btagWorkingPoint_
choice of b-tag working point as extra selection type
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
std::string jetCorrector_
jet corrector as extra selection type
StringCutObjectSelector< Object > select_
string cut selector
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
template<typename Object>
SelectionStep< Object >::~SelectionStep ( )
inline

default destructor

Definition at line 180 of file TopDQMHelpers.h.

180 {};

Member Function Documentation

template<typename Object >
bool SelectionStep< Object >::select ( const edm::Event event)

apply selection

Definition at line 263 of file TopDQMHelpers.h.

References accept(), edm::Event::getByToken(), customizeTrackingMonitorSeedNumber::idx, n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

Referenced by TopSingleLeptonDQM::analyze(), SingleTopTChannelLeptonDQM::analyze(), TopDiLeptonOfflineDQM::analyze(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and Vispa.Views.AbstractView.AbstractView::restoreSelection().

264 {
265  // fetch input collection
267  if( !event.getByToken(src_, src) ) return false;
268 
269  // load electronId value map if configured such
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 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
int min_
min/max for object multiplicity
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool isUninitialized() const
Definition: EDGetToken.h:71
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector
template<typename Object >
bool SelectionStep< Object >::select ( const edm::Event event,
const std::string &  type 
)

apply selection with special treatment for PFCandidates

Definition at line 297 of file TopDQMHelpers.h.

References accept(), edm::Event::getByToken(), reco::PFCandidate::gsfElectronRef(), customizeTrackingMonitorSeedNumber::idx, edm::Ref< C, T, F >::isNonnull(), reco::PFCandidate::muonRef(), n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

Referenced by Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and Vispa.Views.AbstractView.AbstractView::restoreSelection().

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
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;
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 }
type
Definition: HCALResponse.h:21
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
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
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int min_
min/max for object multiplicity
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:570
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:446
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
bool isUninitialized() const
Definition: EDGetToken.h:71
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector
template<typename Object >
bool SelectionStep< Object >::select ( const edm::Event event,
const edm::EventSetup setup 
)

apply selection override for jets

apply selection (w/o using the template class Object), override for jets

Definition at line 389 of file TopDQMHelpers.h.

References accept(), JetCorrector::correction(), edm::EventSetup::find(), edm::Event::getByToken(), JetCorrector::getJetCorrector(), customizeTrackingMonitorSeedNumber::idx, metsig::jet, bTagSequences_cff::jetID, n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

Referenced by Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and Vispa.Views.AbstractView.AbstractView::restoreSelection().

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 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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
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_
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
int min_
min/max for object multiplicity
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 btagWorkingPoint_
choice of b-tag working point as extra selection type
bool isUninitialized() const
Definition: EDGetToken.h:71
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
std::string jetCorrector_
jet corrector as extra selection type
StringCutObjectSelector< Object > select_
string cut selector
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
template<typename Object >
bool SelectionStep< Object >::selectVertex ( const edm::Event event)

Definition at line 365 of file TopDQMHelpers.h.

References accept(), edm::Event::getByToken(), n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

Referenced by TopSingleLeptonDQM::analyze().

366 {
367  // fetch input collection
369  if( !event.getByToken(src_, src) ) return false;
370 
371  // load electronId value map if configured such
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 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
int min_
min/max for object multiplicity
bool isUninitialized() const
Definition: EDGetToken.h:71
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector

Member Data Documentation

template<typename Object>
edm::EDGetTokenT<reco::JetTagCollection > SelectionStep< Object >::btagLabel_
private

choice for b-tag as extra selection type

Definition at line 209 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
double SelectionStep< Object >::btagWorkingPoint_
private

choice of b-tag working point as extra selection type

Definition at line 211 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
int SelectionStep< Object >::eidPattern_
private

electronId pattern we expect the following pattern: 0: fails 1: passes electron ID only 2: passes electron Isolation only 3: passes electron ID and Isolation only 4: passes conversion rejection 5: passes conversion rejection and ID 6: passes conversion rejection and Isolation 7: passes the whole selection As described on https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID

Definition at line 205 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::EDGetTokenT<edm::ValueMap<float> > SelectionStep< Object >::electronId_
private

electronId label as extra selection type

Definition at line 194 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::EDGetTokenT<edm::View<reco::GsfElectron> > SelectionStep< Object >::gsfEs_
private

Definition at line 216 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
std::string SelectionStep< Object >::jetCorrector_
private

jet corrector as extra selection type

Definition at line 207 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::EDGetTokenT<reco::JetIDValueMap> SelectionStep< Object >::jetIDLabel_
private

jetID as an extra selection type

Definition at line 213 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
StringCutObjectSelector<reco::JetID>* SelectionStep< Object >::jetIDSelect_
private

selection string on the jetID

Definition at line 220 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
int SelectionStep< Object >::max_
private

Definition at line 192 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
int SelectionStep< Object >::min_
private

min/max for object multiplicity

Definition at line 192 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::EDGetTokenT<edm::View<reco::Vertex> > SelectionStep< Object >::pvs_
private

Definition at line 215 of file TopDQMHelpers.h.

template<typename Object>
StringCutObjectSelector<Object> SelectionStep< Object >::select_
private

string cut selector

Definition at line 218 of file TopDQMHelpers.h.

template<typename Object>
edm::EDGetTokenT<edm::View<Object> > SelectionStep< Object >::src_
private

input collection

Definition at line 190 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().