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_
 
std::string jetCorrector_
 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 237 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 289 of file TopDQMHelpers.h.

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

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

242 {};

Member Function Documentation

◆ select() [1/3]

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

apply selection

Definition at line 319 of file TopDQMHelpers.h.

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

References accept(), topSingleLeptonDQM_PU_cfi::electronId, training_settings::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 439 of file TopDQMHelpers.h.

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

References accept(), pfClustersFromHGC3DClusters_cfi::corrector, JetCorrector::getJetCorrector(), training_settings::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 355 of file TopDQMHelpers.h.

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

References accept(), topSingleLeptonDQM_PU_cfi::electronId, reco::PFCandidate::gsfElectronRef(), training_settings::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 414 of file TopDQMHelpers.h.

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

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 273 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 275 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 269 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 257 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 280 of file TopDQMHelpers.h.

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

◆ jetCorrector_

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

jet corrector as extra selection type

Definition at line 271 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 277 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 284 of file TopDQMHelpers.h.

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

◆ max_

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

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

◆ select_

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

string cut selector

Definition at line 282 of file TopDQMHelpers.h.

◆ src_

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

input collection

Definition at line 253 of file TopDQMHelpers.h.

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

dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
topSingleLeptonDQM_PU_cfi.electronId
electronId
when omitted electron plots will be filled w/o cut on electronId
Definition: topSingleLeptonDQM_PU_cfi.py:39
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
SelectionStep::jetCorrector_
std::string jetCorrector_
jet corrector as extra selection type
Definition: TopDQMHelpers.h:271
JetCorrector
Definition: JetCorrector.h:19
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
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:30
reco::PFCandidate::muonRef
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:421
SelectionStep::src_
edm::EDGetTokenT< edm::View< Object > > src_
input collection
Definition: TopDQMHelpers.h:253
edm::EDGetTokenT::isUninitialized
bool isUninitialized() const
Definition: EDGetToken.h:70
SelectionStep::max_
int max_
Definition: TopDQMHelpers.h:255
SelectionStep::btagLabel_
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
Definition: TopDQMHelpers.h:273
SelectionStep::pvs_
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
Definition: TopDQMHelpers.h:279
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:49
SelectionStep::min_
int min_
min/max for object multiplicity
Definition: TopDQMHelpers.h:255
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::AssociationVector
Definition: AssociationVector.h:67
SelectionStep::jetIDLabel_
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
Definition: TopDQMHelpers.h:277
edm::View
Definition: CaloClusterFwd.h:14
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
edm::LogVerbatim
Definition: MessageLogger.h:297
JetCorrector::getJetCorrector
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:48
looper.cfg
cfg
Definition: looper.py:297
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
type
type
Definition: HCALResponse.h:21
SelectionStep::btagWorkingPoint_
double btagWorkingPoint_
choice of b-tag working point as extra selection type
Definition: TopDQMHelpers.h:275
metsig::jet
Definition: SignAlgoResolutions.h:47
edm::ValueMap< float >
StringCutObjectSelector< reco::JetID >
SelectionStep::eidCutValue_
double eidCutValue_
Definition: TopDQMHelpers.h:269
SelectionStep::jetIDSelect_
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
Definition: TopDQMHelpers.h:284
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:40
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:280
SelectionStep::electronId_
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
Definition: TopDQMHelpers.h:257
SelectionStep::select_
StringCutObjectSelector< Object > select_
string cut selector
Definition: TopDQMHelpers.h:282