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 edm::EventSetup &setup)
 apply selection override for jets More...
 
bool select (const edm::Event &event, const std::string &type)
 apply selection with special treatment for PFCandidates 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::ESGetToken< JetCorrector, JetCorrectionsRecordjetCorrector_
 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 238 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 290 of file TopDQMHelpers.h.

291  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(nullptr) {
292  src_ = iC.consumes<edm::View<Object> >(cfg.getParameter<edm::InputTag>("src"));
293  // exist otherwise they are initialized with -1
294  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
295  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
296  std::string mygSF = "gedGsfElectrons";
297  gsfEs_ = iC.consumes<edm::View<reco::GsfElectron> >(cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
298  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
299  edm::ParameterSet elecId = cfg.getParameter<edm::ParameterSet>("electronId");
301  eidCutValue_ = elecId.getParameter<double>("cutValue");
302  }
303  if (cfg.exists("jetCorrector")) {
304  jetCorrector_ = iC.esConsumes(edm::ESInputTag("", cfg.getParameter<std::string>("jetCorrector")));
305  }
306  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
307  edm::ParameterSet jetBTagger = cfg.getParameter<edm::ParameterSet>("jetBTagger");
309  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
310  }
311  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
312  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
314  jetIDSelect_ = new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
315  }
316 }

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

◆ ~SelectionStep()

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

default destructor

Definition at line 243 of file TopDQMHelpers.h.

243 {};

Member Function Documentation

◆ select() [1/3]

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

apply selection

Definition at line 320 of file TopDQMHelpers.h.

320  {
321  // fetch input collection
323  if (!event.getByToken(src_, src))
324  return false;
325 
326  // load electronId value map if configured such
328  if (!electronId_.isUninitialized()) {
329  if (!event.getByToken(electronId_, electronId))
330  return false;
331  }
332 
333  // determine multiplicity of selected objects
334  int n = 0;
335  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
336  // special treatment for electrons
337  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
338  unsigned int idx = obj - src->begin();
339  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
340  if (select_(*obj))
341  ++n;
342  }
343  }
344  // normal treatment
345  else {
346  if (select_(*obj))
347  ++n;
348  }
349  }
350  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
351  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
352 }

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

◆ select() [2/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 440 of file TopDQMHelpers.h.

440  {
441  // fetch input collection
443  if (!event.getByToken(src_, src))
444  return false;
445 
446  // load btag collection if configured such
447  // NOTE that the JetTagCollection needs an
448  // edm::View to reco::Jets; we have to add
449  // another Handle bjets for this purpose
453  if (!btagLabel_.isUninitialized()) {
454  if (!event.getByToken(src_, bjets))
455  return false;
456  if (!event.getByToken(btagLabel_, btagger))
457  return false;
458  if (!event.getByToken(pvs_, pvertex))
459  return false;
460  }
461 
462  // load jetID value map if configured such
464  if (jetIDSelect_) {
465  if (!event.getByToken(jetIDLabel_, jetID))
466  return false;
467  }
468 
469  // load jet corrector if configured such
470  const JetCorrector* corrector = nullptr;
472  // check whether a jet correcto is in the event setup or not
473  if (setup.find(edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>())) {
474  corrector = &setup.getData(jetCorrector_);
475  } else {
476  edm::LogVerbatim("TopDQMHelpers") << "\n"
477  << "---------------------------------------------------------------\n"
478  << " No JetCorrectionsRecord available from EventSetup:\n"
479  << " - Jets will not be corrected.\n"
480  << " - If you want to change this add the following lines to your "
481  "cfg file:\n"
482  << "\n"
483  << " ## load jet corrections\n"
484  << " process.load(\""
485  "JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff"
486  "\")\n"
487  << " process.prefer(\"ak5CaloL2L3\")\n"
488  << "---------------------------------------------------------------"
489  "\n";
490  }
491  }
492  // determine multiplicity of selected objects
493  int n = 0;
494  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
495  // check for chosen btag discriminator to be above the
496  // corresponding working point if configured such
497  unsigned int idx = obj - src->begin();
498  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] > btagWorkingPoint_) {
499  bool passedJetID = true;
500  // check jetID for calo jets
501  if (jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
502  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
503  }
504  if (passedJetID) {
505  // scale jet energy if configured such
506  Object jet = *obj;
507  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
508  if (select_(jet))
509  ++n;
510  }
511  }
512  }
513  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
514  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
515 }

References accept(), pfClustersFromHGC3DClusters_cfi::corrector, heavyIonCSV_trainingSettings::idx, metsig::jet, dqmiodumpmetadata::n, getGTfromDQMFile::obj, singleTopDQM_cfi::setup, TrackRefitter_38T_cff::src, and funct::true.

◆ select() [3/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 356 of file TopDQMHelpers.h.

356  {
357  // fetch input collection
359  if (!event.getByToken(src_, src))
360  return false;
361 
362  // special for gsfElectron
364 
365  // load electronId value map if configured such
367  if (!electronId_.isUninitialized()) {
368  if (!event.getByToken(electronId_, electronId))
369  return false;
370  }
371 
372  // determine multiplicity of selected objects
373  int n = 0;
374  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
375  // special treatment for PF candidates
376  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
377  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
378 
379  if (objtmp.muonRef().isNonnull() && type == "muon") {
380  if (select_(*obj)) {
381  ++n;
382  }
383  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
384  if (select_(*obj)) {
386  ++n;
387  } else if (((double)(*electronId)[obj->gsfElectronRef()] >= eidCutValue_)) {
388  ++n;
389  }
390  }
391  // idx_gsf++;
392  }
393  }
394 
395  // special treatment for electrons
396  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
397  unsigned int idx = obj - src->begin();
398  if (electronId_.isUninitialized() ? true : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
399  if (select_(*obj))
400  ++n;
401  }
402  }
403 
404  // normal treatment
405  else {
406  if (select_(*obj))
407  ++n;
408  }
409  }
410  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
411  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
412 }

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.

◆ selectVertex()

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

Definition at line 415 of file TopDQMHelpers.h.

415  {
416  // fetch input collection
418  if (!event.getByToken(src_, src))
419  return false;
420 
421  // load electronId value map if configured such
423  if (!electronId_.isUninitialized()) {
424  if (!event.getByToken(electronId_, electronId))
425  return false;
426  }
427 
428  // determine multiplicity of selected objects
429  int n = 0;
430  for (typename edm::View<Object>::const_iterator obj = src->begin(); obj != src->end(); ++obj) {
431  if (select_(*obj))
432  ++n;
433  }
434  bool accept = (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
435  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
436 }

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

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 274 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 276 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 270 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 258 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 281 of file TopDQMHelpers.h.

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

◆ jetCorrector_

template<typename Object >
edm::ESGetToken<JetCorrector, JetCorrectionsRecord> SelectionStep< Object >::jetCorrector_
private

jet corrector as extra selection type

Definition at line 272 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 278 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 285 of file TopDQMHelpers.h.

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

◆ max_

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

Definition at line 256 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 256 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 280 of file TopDQMHelpers.h.

◆ select_

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

string cut selector

Definition at line 283 of file TopDQMHelpers.h.

◆ src_

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

input collection

Definition at line 254 of file TopDQMHelpers.h.

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

edm::ESInputTag
Definition: ESInputTag.h:87
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
topSingleLeptonDQM_PU_cfi.electronId
electronId
when omitted electron plots will be filled w/o cut on electronId
Definition: topSingleLeptonDQM_PU_cfi.py:39
edm::ConsumesCollector::esConsumes
auto esConsumes()
Definition: ConsumesCollector.h:97
edm::Handle
Definition: AssociativeIterator.h:50
JetCorrector
Definition: JetCorrector.h:19
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::ESGetToken::isInitialized
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:72
edm::ESGetToken::hasValidIndex
constexpr bool hasValidIndex() const noexcept
Definition: ESGetToken.h:74
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
pfClustersFromHGC3DClusters_cfi.corrector
corrector
Definition: pfClustersFromHGC3DClusters_cfi.py:5
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
reco::PFCandidate::muonRef
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:421
SelectionStep::src_
edm::EDGetTokenT< edm::View< Object > > src_
input collection
Definition: TopDQMHelpers.h:254
SelectionStep::max_
int max_
Definition: TopDQMHelpers.h:256
SelectionStep::btagLabel_
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
Definition: TopDQMHelpers.h:274
SelectionStep::pvs_
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
Definition: TopDQMHelpers.h:280
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
SelectionStep::min_
int min_
min/max for object multiplicity
Definition: TopDQMHelpers.h:256
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::AssociationVector
Definition: AssociationVector.h:67
SelectionStep::jetIDLabel_
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
Definition: TopDQMHelpers.h:278
edm::View
Definition: CaloClusterFwd.h:14
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
looper.cfg
cfg
Definition: looper.py:296
SelectionStep::btagWorkingPoint_
double btagWorkingPoint_
choice of b-tag working point as extra selection type
Definition: TopDQMHelpers.h:276
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
metsig::jet
Definition: SignAlgoResolutions.h:47
edm::ValueMap< float >
StringCutObjectSelector< reco::JetID >
SelectionStep::eidCutValue_
double eidCutValue_
Definition: TopDQMHelpers.h:270
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SelectionStep::jetIDSelect_
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
Definition: TopDQMHelpers.h:285
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
event
Definition: event.py:1
reco::PFCandidate::gsfElectronRef
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:530
edm::InputTag
Definition: InputTag.h:15
SelectionStep::gsfEs_
edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfEs_
Definition: TopDQMHelpers.h:281
SelectionStep::electronId_
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
Definition: TopDQMHelpers.h:258
SelectionStep::select_
StringCutObjectSelector< Object > select_
string cut selector
Definition: TopDQMHelpers.h:283
SelectionStep::jetCorrector_
edm::ESGetToken< JetCorrector, JetCorrectionsRecord > jetCorrector_
jet corrector as extra selection type
Definition: TopDQMHelpers.h:272