CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
pf2pat::ElectronIDPFCandidateSelectorDefinition Class Reference

Selects PFCandidates basing on cuts provided with string cut parser. More...

#include "CommonTools/ParticleFlow/interface/ElectronIDPFCandidateSelectorDefinition.h"

Inheritance diagram for pf2pat::ElectronIDPFCandidateSelectorDefinition:
pf2pat::PFCandidateSelectorDefinition

Public Member Functions

 ElectronIDPFCandidateSelectorDefinition (const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
 
void select (const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
 
- Public Member Functions inherited from pf2pat::PFCandidateSelectorDefinition
const_iterator begin () const
 
const_iterator end () const
 
 PFCandidateSelectorDefinition ()
 
const containerselected () const
 
size_t size () const
 

Private Attributes

edm::EDGetTokenT< edm::ValueMap< float > > electronIdToken_
 
edm::EDGetTokenT< reco::GsfElectronCollectionelectronsToken_
 
bool isBitMap_
 
uint32_t mask_
 
double value_
 

Additional Inherited Members

- Public Types inherited from pf2pat::PFCandidateSelectorDefinition
typedef reco::PFCandidateCollection collection
 
typedef boost::transform_iterator< Pointer, container::const_iterator > const_iterator
 
typedef std::vector< reco::PFCandidatecontainer
 
typedef edm::Handle< collectionHandleToCollection
 
- Protected Attributes inherited from pf2pat::PFCandidateSelectorDefinition
container selected_
 

Detailed Description

Selects PFCandidates basing on cuts provided with string cut parser.

Author
Giovanni Petrucciani
Version
Id
ElectronIDPFCandidateSelectorDefinition.h,v 1.1 2011/01/28 20:56:44 srappocc Exp

Definition at line 24 of file ElectronIDPFCandidateSelectorDefinition.h.

Constructor & Destructor Documentation

◆ ElectronIDPFCandidateSelectorDefinition()

pf2pat::ElectronIDPFCandidateSelectorDefinition::ElectronIDPFCandidateSelectorDefinition ( const edm::ParameterSet cfg,
edm::ConsumesCollector &&  iC 
)
inline

Definition at line 25 of file ElectronIDPFCandidateSelectorDefinition.h.

References looper::cfg, Exception, isBitMap_, mask_, and value_.

27  iC.consumes<reco::GsfElectronCollection>(cfg.getParameter<edm::InputTag>("recoGsfElectrons"))),
28  electronIdToken_(iC.consumes<edm::ValueMap<float> >(cfg.getParameter<edm::InputTag>("electronIdMap"))) {
29  if (cfg.exists("bitsToCheck")) {
30  isBitMap_ = true;
31  mask_ = 0;
32  if (cfg.existsAs<std::vector<std::string> >("bitsToCheck")) {
33  std::vector<std::string> strbits = cfg.getParameter<std::vector<std::string> >("bitsToCheck");
34  for (std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
35  istrbit != estrbit;
36  ++istrbit) {
37  if (*istrbit == "id") {
38  mask_ |= 1;
39  } else if (*istrbit == "iso") {
40  mask_ |= 2;
41  } else if (*istrbit == "conv") {
42  mask_ |= 4;
43  } else if (*istrbit == "ip") {
44  mask_ |= 8;
45  } else
46  throw cms::Exception("Configuration")
47  << "ElectronIDPFCandidateSelector: "
48  << "bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n"
49  << "Otherwise, use uint32_t bitmask).\n";
50  }
51  } else if (cfg.existsAs<uint32_t>("bitsToCheck")) {
52  mask_ = cfg.getParameter<uint32_t>("bitsToCheck");
53  } else {
54  throw cms::Exception("Configuration")
55  << "ElectronIDPFCandidateSelector: "
56  << "bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n";
57  }
58  } else {
59  isBitMap_ = false;
60  value_ = cfg.getParameter<double>("electronIdCut");
61  }
62  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_

Member Function Documentation

◆ select()

void pf2pat::ElectronIDPFCandidateSelectorDefinition::select ( const HandleToCollection hc,
const edm::Event e,
const edm::EventSetup s 
)
inline

Definition at line 64 of file ElectronIDPFCandidateSelectorDefinition.h.

References submitPVResolutionJobs::count, MillePedeFileConverter_cfg::e, topSingleLeptonDQM_PU_cfi::electronId, electronIdToken_, pwdgSkimBPark_cfi::electrons, electronsToken_, isBitMap_, edm::Ref< C, T, F >::isNull(), crabWrapper::key, mask_, pf2pat::PFCandidateSelectorDefinition::selected_, and value_.

64  {
65  selected_.clear();
66 
68  e.getByToken(electronsToken_, electrons);
69 
71  e.getByToken(electronIdToken_, electronId);
72 
73  unsigned key = 0;
74  for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
75  // Get GsfTrack for matching with reco::GsfElectron objects
76  reco::GsfTrackRef PfTk = pfc->gsfTrackRef();
77 
78  // skip ones without GsfTrack: they won't be matched anyway
79  if (PfTk.isNull())
80  continue;
81 
82  int match = -1;
83  // try first the non-ambiguous tracks
84  for (auto it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
85  if (it->gsfTrack() == PfTk) {
86  match = it - electrons->begin();
87  break;
88  }
89  }
90  // then the ambiguous ones
91  if (match == -1) {
92  for (auto it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
93  if (std::count(it->ambiguousGsfTracks().begin(), it->ambiguousGsfTracks().end(), PfTk) > 0) {
94  match = it - electrons->begin();
95  break;
96  }
97  }
98  }
99  // if found, make a GsfElectronRef and read electron id
100  if (match != -1) {
102  float eleId = (*electronId)[ref];
103  bool pass = false;
104  if (isBitMap_) {
105  uint32_t thisval = eleId;
106  pass = ((thisval & mask_) == mask_);
107  } else {
108  pass = (eleId > value_);
109  }
110  if (pass) {
111  selected_.push_back(reco::PFCandidate(*pfc));
112  reco::PFCandidatePtr ptrToMother(hc, key);
113  selected_.back().setSourceCandidatePtr(ptrToMother);
114  }
115  }
116  }
117  }
electronId
when omitted electron plots will be filled w/o cut on electronId
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10

Member Data Documentation

◆ electronIdToken_

edm::EDGetTokenT<edm::ValueMap<float> > pf2pat::ElectronIDPFCandidateSelectorDefinition::electronIdToken_
private

Definition at line 121 of file ElectronIDPFCandidateSelectorDefinition.h.

Referenced by select().

◆ electronsToken_

edm::EDGetTokenT<reco::GsfElectronCollection> pf2pat::ElectronIDPFCandidateSelectorDefinition::electronsToken_
private

Definition at line 120 of file ElectronIDPFCandidateSelectorDefinition.h.

Referenced by select().

◆ isBitMap_

bool pf2pat::ElectronIDPFCandidateSelectorDefinition::isBitMap_
private

◆ mask_

uint32_t pf2pat::ElectronIDPFCandidateSelectorDefinition::mask_
private

◆ value_

double pf2pat::ElectronIDPFCandidateSelectorDefinition::value_
private