CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 <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...
 
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,
JetCorrectionsRecord
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.

"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

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

default constructor

Definition at line 290 of file TopDQMHelpers.h.

References SelectionStep< Object >::btagLabel_, SelectionStep< Object >::btagWorkingPoint_, SelectionStep< Object >::eidCutValue_, SelectionStep< Object >::electronId_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), 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.

291  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(nullptr) {
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";
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 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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:171
edm::ESGetToken< JetCorrector, JetCorrectionsRecord > jetCorrector_
jet corrector as extra selection type
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 eidCutValue_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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
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 243 of file TopDQMHelpers.h.

243 {};

Member Function Documentation

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

apply selection

Definition at line 320 of file TopDQMHelpers.h.

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

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 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
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
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.

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

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 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
int min_
min/max for object multiplicity
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:552
double eidCutValue_
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:443
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
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.

References accept(), JetCorrector::correction(), pfClustersFromHGC3DClusters_cfi::corrector, edm::EventSetup::find(), edm::Event::getByToken(), edm::EventSetup::getData(), metsig::jet, dqmiodumpmetadata::n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

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 }
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:178
Log< level::Info, true > LogVerbatim
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
edm::ESGetToken< JetCorrector, JetCorrectionsRecord > jetCorrector_
jet corrector as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
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_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int min_
min/max for object multiplicity
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:72
double btagWorkingPoint_
choice of b-tag working point as extra selection type
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
constexpr bool hasValidIndex() const noexcept
Definition: ESGetToken.h:74
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 415 of file TopDQMHelpers.h.

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

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 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label as extra selection type
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
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

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

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

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().

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().

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().

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().

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().

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().

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

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

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

string cut selector

Definition at line 283 of file TopDQMHelpers.h.

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().