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

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

Definition at line 26 of file ElectronIDPFCandidateSelectorDefinition.h.

References Exception, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), isBitMap_, mask_, and value_.

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

Member Function Documentation

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

Definition at line 57 of file ElectronIDPFCandidateSelectorDefinition.h.

References KineDebug3::count(), electronIdToken_, lowPtElectrons_cff::electrons, electronsToken_, edm::Event::getByToken(), isBitMap_, edm::Ref< C, T, F >::isNull(), crabWrapper::key, mask_, match(), pf2pat::PFCandidateSelectorDefinition::selected_, and value_.

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

59  {
60  selected_.clear();
61 
63  e.getByToken(electronsToken_, electrons);
64 
66  e.getByToken(electronIdToken_, electronId);
67 
68  unsigned key=0;
69  for( collection::const_iterator pfc = hc->begin();
70  pfc != hc->end(); ++pfc, ++key) {
71 
72  // Get GsfTrack for matching with reco::GsfElectron objects
73  reco::GsfTrackRef PfTk = pfc->gsfTrackRef();
74 
75  // skip ones without GsfTrack: they won't be matched anyway
76  if (PfTk.isNull()) continue;
77 
78  int match = -1;
79  // try first the non-ambiguous tracks
80  for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
81  if (it->gsfTrack() == PfTk) { match = it - electrons->begin(); break; }
82  }
83  // then the ambiguous ones
84  if (match == -1) {
85  for (reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
86  if (std::count(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
87  match = it - electrons->begin(); break;
88  }
89  }
90  }
91  // if found, make a GsfElectronRef and read electron id
92  if (match != -1) {
93  reco::GsfElectronRef ref(electrons,match);
94  float eleId = (*electronId)[ref];
95  bool pass = false;
96  if (isBitMap_) {
97  uint32_t thisval = eleId;
98  pass = ((thisval & mask_) == mask_);
99  } else {
100  pass = (eleId > value_);
101  }
102  if (pass) {
103  selected_.push_back( reco::PFCandidate(*pfc) );
104  reco::PFCandidatePtr ptrToMother( hc, key );
105  selected_.back().setSourceCandidatePtr( ptrToMother );
106  }
107  }
108  }
109  }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool isNull() const
Checks for null.
Definition: Ref.h:248
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
susybsm::HSCParticleCollection hc
Definition: classes.h:25
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

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

Definition at line 113 of file ElectronIDPFCandidateSelectorDefinition.h.

Referenced by select().

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

Definition at line 112 of file ElectronIDPFCandidateSelectorDefinition.h.

Referenced by select().

bool pf2pat::ElectronIDPFCandidateSelectorDefinition::isBitMap_
private
uint32_t pf2pat::ElectronIDPFCandidateSelectorDefinition::mask_
private
double pf2pat::ElectronIDPFCandidateSelectorDefinition::value_
private