CMS 3D CMS Logo

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 <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::JetTagCollectionbtagLabel_
 choice for b-tag as extra selection type More...
 
double btagWorkingPoint_
 choice of b-tag working point as extra selection type More...
 
double eidCutValue_
 
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
 electronId label as extra selection type More...
 
edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfEs_
 
edm::EDGetTokenT< reco::JetCorrectorjetCorrector_
 jet corrector as extra selection type More...
 
edm::EDGetTokenT< reco::JetIDValueMapjetIDLabel_
 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.

"DQM/Physics/interface/TopDQMHelpers.h"

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

Constructor & Destructor Documentation

◆ SelectionStep()

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

default constructor

Definition at line 292 of file TopDQMHelpers.h.

References SelectionStep< Object >::btagLabel_, SelectionStep< Object >::btagWorkingPoint_, looper::cfg, SelectionStep< Object >::eidCutValue_, SelectionStep< Object >::electronId_, edm::ParameterSet::getParameter(), SelectionStep< Object >::gsfEs_, ProducerED_cfi::InputTag, SelectionStep< Object >::jetCorrector_, SelectionStep< Object >::jetIDLabel_, SelectionStep< Object >::jetIDSelect_, SelectionStep< Object >::max_, SelectionStep< Object >::min_, SelectionStep< Object >::src_, and AlCaHLTBitMon_QueryRunRegistry::string.

293  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(nullptr) {
294  src_ = iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
295  // exist otherwise they are initialized with -1
296  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
297  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
298  std::string mygSF = "gedGsfElectrons";
299  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
300  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
301  edm::ParameterSet elecId = cfg.getParameter<edm::ParameterSet>("electronId");
303  eidCutValue_ = elecId.getParameter<double>("cutValue");
304  }
305  if (cfg.exists("jetCorrector")) {
306  jetCorrector_ = iC.consumes<reco::JetCorrector>(edm::InputTag(cfg.getParameter<std::string>("jetCorrector")));
307  }
308  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
309  edm::ParameterSet jetBTagger = cfg.getParameter<edm::ParameterSet>("jetBTagger");
311  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
312  }
313  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
314  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
316  jetIDSelect_ = new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
317  }
318 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
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 eidCutValue_
double btagWorkingPoint_
choice of b-tag working point as extra selection type
edm::EDGetTokenT< reco::JetCorrector > jetCorrector_
jet corrector as extra selection type
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
StringCutObjectSelector< Object > select_
string cut selector
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type

◆ ~SelectionStep()

template<typename Object >
SelectionStep< Object >::~SelectionStep ( )
inline

default destructor

Definition at line 245 of file TopDQMHelpers.h.

245 {};

Member Function Documentation

◆ select() [1/3]

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

apply selection

Definition at line 322 of file TopDQMHelpers.h.

References accept(), topSingleLeptonDQM_PU_cfi::electronId, heavyIonCSV_trainingSettings::idx, dqmiodumpmetadata::n, getGTfromDQMFile::obj, TrackRefitter_38T_cff::src, and funct::true.

322  {
323  // fetch input collection
325  if (!event.getByToken(src_, src))
326  return false;
327 
328  // load electronId value map if configured such
330  if (!electronId_.isUninitialized()) {
331  if (!event.getByToken(electronId_, electronId))
332  return false;
333  }
334 
335  // determine multiplicity of selected objects
336  int n = 0;
337  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
338  // special treatment for electrons
339  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
340  unsigned int idx = obj - src->begin();
341  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
342  if (select_(*obj))
343  ++n;
344  }
345  }
346  // normal treatment
347  else {
348  if (select_(*obj))
349  ++n;
350  }
351  }
352  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
353  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
354 }
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
electronId
when omitted electron plots will be filled w/o cut on electronId
int min_
min/max for object multiplicity
double eidCutValue_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector
Definition: event.py:1

◆ select() [2/3]

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

References accept(), topSingleLeptonDQM_PU_cfi::electronId, reco::PFCandidate::gsfElectronRef(), heavyIonCSV_trainingSettings::idx, edm::Ref< C, T, F >::isNonnull(), reco::PFCandidate::muonRef(), dqmiodumpmetadata::n, getGTfromDQMFile::obj, TrackRefitter_38T_cff::src, and funct::true.

358  {
359  // fetch input collection
361  if (!event.getByToken(src_, src))
362  return false;
363 
364  // special for gsfElectron
366 
367  // load electronId value map if configured such
369  if (!electronId_.isUninitialized()) {
370  if (!event.getByToken(electronId_, electronId))
371  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  // special treatment for PF candidates
378  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
379  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
380 
381  if (objtmp.muonRef().isNonnull() && type == "muon") {
382  if (select_(*obj)) {
383  ++n;
384  }
385  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
386  if (select_(*obj)) {
388  ++n;
389  } else if (((double)(*electronId)[obj->gsfElectronRef()] >= eidCutValue_)) {
390  ++n;
391  }
392  }
393  // idx_gsf++;
394  }
395  }
396 
397  // special treatment for electrons
398  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
399  unsigned int idx = obj - src->begin();
400  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
401  if (select_(*obj))
402  ++n;
403  }
404  }
405 
406  // normal treatment
407  else {
408  if (select_(*obj))
409  ++n;
410  }
411  }
412  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
413  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
414 }
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:557
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
electronId
when omitted electron plots will be filled w/o cut on electronId
int min_
min/max for object multiplicity
double eidCutValue_
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:448
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector
Definition: event.py:1

◆ select() [3/3]

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

References accept(), pfClustersFromHGC3DClusters_cfi::corrector, heavyIonCSV_trainingSettings::idx, edm::HandleBase::isValid(), metsig::jet, dqmiodumpmetadata::n, getGTfromDQMFile::obj, edm::Handle< T >::product(), TrackRefitter_38T_cff::src, and funct::true.

442  {
443  // fetch input collection
445  if (!event.getByToken(src_, src))
446  return false;
447 
448  // load btag collection if configured such
449  // NOTE that the JetTagCollection needs an
450  // edm::View to reco::Jets; we have to add
451  // another Handle bjets for this purpose
455  if (!btagLabel_.isUninitialized()) {
456  if (!event.getByToken(src_, bjets))
457  return false;
458  if (!event.getByToken(btagLabel_, btagger))
459  return false;
460  if (!event.getByToken(pvs_, pvertex))
461  return false;
462  }
463 
464  // load jetID value map if configured such
466  if (jetIDSelect_) {
467  if (!event.getByToken(jetIDLabel_, jetID))
468  return false;
469  }
470 
471  // load jet corrector if configured such
472  const reco::JetCorrector* corrector = nullptr;
474  // check whether a jet corrector is in the event or not
475  edm::Handle<reco::JetCorrector> correctorHandle = event.getHandle(jetCorrector_);
476  if (correctorHandle.isValid()) {
477  corrector = correctorHandle.product();
478  } else {
479  edm::LogVerbatim("TopDQMHelpers") << "\n"
480  << "---------------------------------------------------------------\n"
481  << " No reco::JetCorrrector available from Event:\n"
482  << " - Jets will not be corrected.\n"
483  << "---------------------------------------------------------------"
484  "\n";
485  }
486  }
487  // determine multiplicity of selected objects
488  int n = 0;
489  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
490  // check for chosen btag discriminator to be above the
491  // corresponding working point if configured such
492  unsigned int idx = obj - src->begin();
493  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] > btagWorkingPoint_) {
494  bool passedJetID = true;
495  // check jetID for calo jets
496  if (jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
497  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
498  }
499  if (passedJetID) {
500  // scale jet energy if configured such
501  Object jet = *obj;
502  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
503  if (select_(jet))
504  ++n;
505  }
506  }
507  }
508  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
509  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
510 }
Log< level::Info, true > LogVerbatim
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
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< reco::JetCorrector > jetCorrector_
jet corrector as extra selection type
bool isValid() const
Definition: HandleBase.h:70
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
StringCutObjectSelector< Object > select_
string cut selector
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
Definition: event.py:1

◆ selectVertex()

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

Definition at line 417 of file TopDQMHelpers.h.

References accept(), topSingleLeptonDQM_PU_cfi::electronId, dqmiodumpmetadata::n, getGTfromDQMFile::obj, and TrackRefitter_38T_cff::src.

417  {
418  // fetch input collection
420  if (!event.getByToken(src_, src))
421  return false;
422 
423  // load electronId value map if configured such
425  if (!electronId_.isUninitialized()) {
426  if (!event.getByToken(electronId_, electronId))
427  return false;
428  }
429 
430  // determine multiplicity of selected objects
431  int n = 0;
432  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
433  if (select_(*obj))
434  ++n;
435  }
436  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
437  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
438 }
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
electronId
when omitted electron plots will be filled w/o cut on electronId
int min_
min/max for object multiplicity
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::View< Object > > src_
input collection
StringCutObjectSelector< Object > select_
string cut selector
Definition: event.py:1

Member Data Documentation

◆ btagLabel_

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

choice for b-tag as extra selection type

Definition at line 276 of file TopDQMHelpers.h.

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

◆ btagWorkingPoint_

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

choice of b-tag working point as extra selection type

Definition at line 278 of file TopDQMHelpers.h.

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

◆ eidCutValue_

template<typename Object >
double SelectionStep< Object >::eidCutValue_
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 272 of file TopDQMHelpers.h.

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

◆ electronId_

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

electronId label as extra selection type

Definition at line 260 of file TopDQMHelpers.h.

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

◆ gsfEs_

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

Definition at line 283 of file TopDQMHelpers.h.

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

◆ jetCorrector_

template<typename Object >
edm::EDGetTokenT<reco::JetCorrector> SelectionStep< Object >::jetCorrector_
private

jet corrector as extra selection type

Definition at line 274 of file TopDQMHelpers.h.

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

◆ jetIDLabel_

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

jetID as an extra selection type

Definition at line 280 of file TopDQMHelpers.h.

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

◆ jetIDSelect_

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

selection string on the jetID

Definition at line 287 of file TopDQMHelpers.h.

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

◆ max_

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

Definition at line 258 of file TopDQMHelpers.h.

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

◆ min_

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

min/max for object multiplicity

Definition at line 258 of file TopDQMHelpers.h.

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

◆ pvs_

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

Definition at line 282 of file TopDQMHelpers.h.

◆ select_

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

string cut selector

Definition at line 285 of file TopDQMHelpers.h.

◆ src_

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

input collection

Definition at line 256 of file TopDQMHelpers.h.

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