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 <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_
 
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.

"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.

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 253 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 305 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.

307  : select_(cfg.getParameter<std::string>("select")), jetIDSelect_(0) {
308 
309  src_ =
311  // exist otherwise they are initialized with -1
312  cfg.exists("min") ? min_ = cfg.getParameter<int>("min") : min_ = -1;
313  cfg.exists("max") ? max_ = cfg.getParameter<int>("max") : max_ = -1;
314  std::string mygSF = "gedGsfElectrons";
316  cfg.getUntrackedParameter<edm::InputTag>("myGSF", mygSF));
317  if (cfg.existsAs<edm::ParameterSet>("electronId")) {
318  edm::ParameterSet elecId =
319  cfg.getParameter<edm::ParameterSet>("electronId");
321  elecId.getParameter<edm::InputTag>("src"));
322  eidCutValue_ = elecId.getParameter<double>("cutValue");
323  }
324  if (cfg.exists("jetCorrector")) {
325  jetCorrector_ = cfg.getParameter<std::string>("jetCorrector");
326  }
327  if (cfg.existsAs<edm::ParameterSet>("jetBTagger")) {
328  edm::ParameterSet jetBTagger =
329  cfg.getParameter<edm::ParameterSet>("jetBTagger");
331  jetBTagger.getParameter<edm::InputTag>("label"));
332  btagWorkingPoint_ = jetBTagger.getParameter<double>("workingPoint");
333  }
334  if (cfg.existsAs<edm::ParameterSet>("jetID")) {
335  edm::ParameterSet jetID = cfg.getParameter<edm::ParameterSet>("jetID");
337  jetID.getParameter<edm::InputTag>("label"));
339  jetID.getParameter<std::string>("select"));
340  }
341 }
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:186
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_
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 258 of file TopDQMHelpers.h.

258 {};

Member Function Documentation

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

apply selection

Definition at line 345 of file TopDQMHelpers.h.

References accept(), edm::Event::getByToken(), gen::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().

345  {
346 
347  // fetch input collection
349  if (!event.getByToken(src_, src)) return false;
350 
351  // load electronId value map if configured such
353  if (!electronId_.isUninitialized()) {
354  if (!event.getByToken(electronId_, electronId)) return false;
355  }
356 
357  // determine multiplicity of selected objects
358  int n = 0;
359  for (typename edm::View<Object>::const_iterator obj = src->begin();
360  obj != src->end(); ++obj) {
361  // special treatment for electrons
362  if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
363  unsigned int idx = obj - src->begin();
365  ? true
366  : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
367  if (select_(*obj)) ++n;
368  }
369  }
370  // normal treatment
371  else {
372  if (select_(*obj)) ++n;
373  }
374  }
375  bool accept =
376  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
377  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
378 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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:30
int min_
min/max for object multiplicity
double eidCutValue_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool isUninitialized() const
Definition: EDGetToken.h:73
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 382 of file TopDQMHelpers.h.

References accept(), edm::Event::getByToken(), reco::PFCandidate::gsfElectronRef(), edm::Ref< C, T, F >::isNonnull(), reco::PFCandidate::muonRef(), gen::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().

383  {
384  // fetch input collection
386  if (!event.getByToken(src_, src)) return false;
387 
388  // special for gsfElectron
390 
391  // load electronId value map if configured such
393  if (!electronId_.isUninitialized()) {
394  if (!event.getByToken(electronId_, electronId)) return false;
395  }
396 
397  // determine multiplicity of selected objects
398  int n = 0;
399  for (typename edm::View<Object>::const_iterator obj = src->begin();
400  obj != src->end(); ++obj) {
401 
402  // special treatment for PF candidates
403  if (dynamic_cast<const reco::PFCandidate*>(&*obj)) {
404  reco::PFCandidate objtmp = dynamic_cast<const reco::PFCandidate&>(*obj);
405 
406  if (objtmp.muonRef().isNonnull() && type == "muon") {
407  if (select_(*obj)) {
408  ++n;
409  }
410  } else if (objtmp.gsfElectronRef().isNonnull() && type == "electron") {
411  if (select_(*obj)) {
413  ++n;
414  } else if (((double)(*electronId)[obj->gsfElectronRef()] >=
415  eidCutValue_)) {
416  ++n;
417  }
418  }
419  // idx_gsf++;
420  }
421  }
422 
423  // special treatment for electrons
424  else if (dynamic_cast<const reco::GsfElectron*>(&*obj)) {
425  unsigned int idx = obj - src->begin();
427  ? true
428  : ((double)(*electronId)[src->refAt(idx)] >= eidCutValue_)) {
429  if (select_(*obj)) ++n;
430  }
431  }
432 
433  // normal treatment
434  else {
435  if (select_(*obj)) ++n;
436  }
437  }
438  bool accept =
439  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
440  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
441 }
type
Definition: HCALResponse.h:21
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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:30
int min_
min/max for object multiplicity
reco::GsfElectronRef gsfElectronRef() const
return a reference to the corresponding GsfElectron if any
Definition: PFCandidate.cc:579
double eidCutValue_
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:455
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool isUninitialized() const
Definition: EDGetToken.h:73
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 469 of file TopDQMHelpers.h.

References accept(), JetCorrector::correction(), mvaPFMET_cff::corrector, edm::EventSetup::find(), edm::Event::getByToken(), JetCorrector::getJetCorrector(), metsig::jet, edm::eventsetup::EventSetupRecordKey::makeKey(), gen::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().

470  {
471  // fetch input collection
473  if (!event.getByToken(src_, src)) return false;
474 
475  // load btag collection if configured such
476  // NOTE that the JetTagCollection needs an
477  // edm::View to reco::Jets; we have to add
478  // another Handle bjets for this purpose
482  if (!btagLabel_.isUninitialized()) {
483  if (!event.getByToken(src_, bjets)) return false;
484  if (!event.getByToken(btagLabel_, btagger)) return false;
485  if (!event.getByToken(pvs_, pvertex)) return false;
486  }
487 
488  // load jetID value map if configured such
490  if (jetIDSelect_) {
491  if (!event.getByToken(jetIDLabel_, jetID)) return false;
492  }
493 
494  // load jet corrector if configured such
495  const JetCorrector* corrector = 0;
496  if (!jetCorrector_.empty()) {
497  // check whether a jet correcto is in the event setup or not
499  JetCorrectionsRecord>())) {
500  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
501  } else {
502  edm::LogVerbatim("TopDQMHelpers")
503  << "\n"
504  << "---------------------------------------------------------------\n"
505  << " No JetCorrectionsRecord available from EventSetup:\n"
506  << " - Jets will not be corrected.\n"
507  << " - If you want to change this add the following lines to your "
508  "cfg file:\n"
509  << "\n"
510  << " ## load jet corrections\n"
511  << " process.load(\""
512  "JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff"
513  "\")\n"
514  << " process.prefer(\"ak5CaloL2L3\")\n"
515  << "---------------------------------------------------------------"
516  "\n";
517  }
518  }
519  // determine multiplicity of selected objects
520  int n = 0;
521  for (typename edm::View<Object>::const_iterator obj = src->begin();
522  obj != src->end(); ++obj) {
523  // check for chosen btag discriminator to be above the
524  // corresponding working point if configured such
525  unsigned int idx = obj - src->begin();
526  if (btagLabel_.isUninitialized() ? true : (*btagger)[bjets->refAt(idx)] >
528  bool passedJetID = true;
529  // check jetID for calo jets
530  if (jetIDSelect_ &&
531  dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())) {
532  passedJetID = (*jetIDSelect_)((*jetID)[src->refAt(idx)]);
533  }
534  if (passedJetID) {
535  // scale jet energy if configured such
536  Object jet = *obj;
537  jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
538  if (select_(jet)) ++n;
539  }
540  }
541  }
542  bool accept =
543  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
544  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
545 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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:30
edm::EDGetTokenT< edm::View< reco::Vertex > > pvs_
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
int min_
min/max for object multiplicity
edm::EDGetTokenT< reco::JetTagCollection > btagLabel_
choice for b-tag as extra selection type
tuple corrector
Definition: mvaPFMET_cff.py:86
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
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
static EventSetupRecordKey makeKey()
bool isUninitialized() const
Definition: EDGetToken.h:73
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 444 of file TopDQMHelpers.h.

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

444  {
445  // fetch input collection
447  if (!event.getByToken(src_, src)) return false;
448 
449  // load electronId value map if configured such
451  if (!electronId_.isUninitialized()) {
452  if (!event.getByToken(electronId_, electronId)) return false;
453  }
454 
455  // determine multiplicity of selected objects
456  int n = 0;
457  for (typename edm::View<Object>::const_iterator obj = src->begin();
458  obj != src->end(); ++obj) {
459 
460  if (select_(*obj)) ++n;
461  }
462  bool accept =
463  (min_ >= 0 ? n >= min_ : true) && (max_ >= 0 ? n <= max_ : true);
464  return (min_ < 0 && max_ < 0) ? (n > 0) : accept;
465 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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:30
int min_
min/max for object multiplicity
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool isUninitialized() const
Definition: EDGetToken.h:73
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 289 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 291 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 285 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 273 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 296 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 287 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 293 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 300 of file TopDQMHelpers.h.

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

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

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

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

string cut selector

Definition at line 298 of file TopDQMHelpers.h.

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

input collection

Definition at line 269 of file TopDQMHelpers.h.

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