CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronIDPFCandidateSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef CommonTools_ParticleFlow_ElectronIDPFCandidateSelectorDefinition
2 #define CommonTools_ParticleFlow_ElectronIDPFCandidateSelectorDefinition
3 
17 #include <algorithm>
18 
19 namespace pf2pat {
20 
22 
24  electrons_( cfg.getParameter< edm::InputTag >( "recoGsfElectrons" ) ),
25  electronId_( cfg.getParameter< edm::InputTag >( "electronIdMap" ) )
26  {
27  if (cfg.exists("bitsToCheck")) {
28  isBitMap_ = true;
29  mask_ = 0;
30  if (cfg.existsAs<std::vector<std::string> >("bitsToCheck")) {
31  std::vector<std::string> strbits = cfg.getParameter<std::vector<std::string> >("bitsToCheck");
32  for (std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
33  istrbit != estrbit; ++istrbit) {
34  if (*istrbit == "id" ) { mask_ |= 1; }
35  else if (*istrbit == "iso") { mask_ |= 2; }
36  else if (*istrbit == "conv") { mask_ |= 4; }
37  else if (*istrbit == "ip") { mask_ |= 8; }
38  else throw cms::Exception("Configuration") << "ElectronIDPFCandidateSelector: " <<
39  "bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n" <<
40  "Otherwise, use uint32_t bitmask).\n";
41  }
42  } else if (cfg.existsAs<uint32_t>("bitsToCheck")) {
43  mask_ = cfg.getParameter<uint32_t>("bitsToCheck");
44  } else {
45  throw cms::Exception("Configuration") << "ElectronIDPFCandidateSelector: " <<
46  "bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n";
47  }
48  } else {
49  isBitMap_ = false;
50  value_ = cfg.getParameter<double>("electronIdCut");
51  }
52  }
53 
54  void select( const HandleToCollection & hc,
55  const edm::Event & e,
56  const edm::EventSetup& s) {
57  selected_.clear();
58 
60  e.getByLabel(electrons_, electrons);
61 
63  e.getByLabel(electronId_, electronId);
64 
65  unsigned key=0;
66  for( collection::const_iterator pfc = hc->begin();
67  pfc != hc->end(); ++pfc, ++key) {
68 
69  // Get GsfTrack for matching with reco::GsfElectron objects
70  reco::GsfTrackRef PfTk = pfc->gsfTrackRef();
71 
72  // skip ones without GsfTrack: they won't be matched anyway
73  if (PfTk.isNull()) continue;
74 
75  int match = -1;
76  // try first the non-ambiguous tracks
77  for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
78  if (it->gsfTrack() == PfTk) { match = it - electrons->begin(); break; }
79  }
80  // then the ambiguous ones
81  if (match == -1) {
82  for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
83  if (std::count(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
84  match = it - electrons->begin(); break;
85  }
86  }
87  }
88  // if found, make a GsfElectronRef and read electron id
89  if (match != -1) {
90  reco::GsfElectronRef ref(electrons,match);
91  float eleId = (*electronId)[ref];
92  bool pass = false;
93  if (isBitMap_) {
94  uint32_t thisval = eleId;
95  pass = ((thisval & mask_) == mask_);
96  } else {
97  pass = (eleId > value_);
98  }
99  if (pass) {
100  selected_.push_back( reco::PFCandidate(*pfc) );
101  reco::PFCandidatePtr ptrToMother( hc, key );
102  selected_.back().setSourceCandidatePtr( ptrToMother );
103  }
104  }
105  }
106  }
107 
108  private:
111  bool isBitMap_;
112  uint32_t mask_;
113  double value_;
114  };
115 }
116 
117 #endif
T getParameter(std::string const &) const
Selects PFCandidates basing on cuts provided with string cut parser.
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isNull() const
Checks for null.
Definition: Ref.h:247
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
list key
Definition: combine.py:13
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6