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 = "gsfElectrons";
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 SingleTopTChannelLeptonDQM::analyze(), TopSingleLeptonDQM::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  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 }
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 386 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().

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 }
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 362 of file TopDQMHelpers.h.

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

Referenced by TopSingleLeptonDQM::analyze().

363 {
364  // fetch input collection
366  if( !event.getByToken(src_, src) ) return false;
367 
368  // load electronId value map if configured such
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 }
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().