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 Member Functions | Private Attributes
GsfElectronLinker Class Reference

#include <GsfElectronLinker.h>

Inheritance diagram for GsfElectronLinker:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginRun (edm::Run &run, const edm::EventSetup &es)
 
 GsfElectronLinker (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~GsfElectronLinker ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

bool fetchCandidateCollection (edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
 
bool fetchGsfElectronCollection (edm::Handle< reco::GsfElectronCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
 
void fillValueMap (edm::Handle< reco::GsfElectronCollection > &c, const edm::OrphanHandle< reco::PFCandidateCollection > &pfHandle, edm::ValueMap< reco::PFCandidateRef >::Filler &filler) const
 

Private Attributes

std::map< reco::GsfElectronRef,
unsigned > 
electronCandidateMap_
 map GsfElectron PFCandidate (index) More...
 
edm::InputTag inputTagGsfElectrons_
 Input GsfElectrons. More...
 
edm::InputTag inputTagPFCandidates_
 Input PFCandidates. More...
 
std::string nameOutputPF_
 name of output collection of PFCandidate More...
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Fills the GsfElectron Ref into the PFCandidate Produces the ValueMap <GsfElectronRef,PFCandidateRef> F. Beaudette 8 March 2011

Definition at line 23 of file GsfElectronLinker.h.

Constructor & Destructor Documentation

GsfElectronLinker::GsfElectronLinker ( const edm::ParameterSet iConfig)
explicit

Definition at line 9 of file GsfElectronLinker.cc.

References edm::ParameterSet::getParameter(), inputTagGsfElectrons_, inputTagPFCandidates_, and nameOutputPF_.

9  {
11  = iConfig.getParameter<edm::InputTag>("PFCandidate");
13  = iConfig.getParameter<edm::InputTag>("GsfElectrons");
15  = iConfig.getParameter<std::string>("OutputPF");
16 
17  produces<reco::PFCandidateCollection>(nameOutputPF_);
18  produces<edm::ValueMap<reco::PFCandidateRef> > (nameOutputPF_);
19 }
edm::InputTag inputTagPFCandidates_
Input PFCandidates.
T getParameter(std::string const &) const
edm::InputTag inputTagGsfElectrons_
Input GsfElectrons.
std::string nameOutputPF_
name of output collection of PFCandidate
GsfElectronLinker::~GsfElectronLinker ( )

Definition at line 21 of file GsfElectronLinker.cc.

21 {;}

Member Function Documentation

void GsfElectronLinker::beginRun ( edm::Run run,
const edm::EventSetup es 
)
virtual

Reimplemented from edm::EDProducer.

Definition at line 23 of file GsfElectronLinker.cc.

23 {;}
bool GsfElectronLinker::fetchCandidateCollection ( edm::Handle< reco::PFCandidateCollection > &  c,
const edm::InputTag tag,
const edm::Event iEvent 
) const
private

Definition at line 81 of file GsfElectronLinker.cc.

References newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by produce().

83  {
84  bool found = iEvent.getByLabel(tag, c);
85 
86  if(!found )
87  {
88  std::ostringstream err;
89  err<<" cannot get PFCandidates: "
90  <<tag<<std::endl;
91  edm::LogError("GsfElectronLinker")<<err.str();
92  }
93  return found;
94 
95 }
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
bool GsfElectronLinker::fetchGsfElectronCollection ( edm::Handle< reco::GsfElectronCollection > &  c,
const edm::InputTag tag,
const edm::Event iEvent 
) const
private

Definition at line 97 of file GsfElectronLinker.cc.

References newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by produce().

99  {
100  bool found = iEvent.getByLabel(tag, c);
101 
102  if(!found )
103  {
104  std::ostringstream err;
105  err<<" cannot get GsfElectrons: "
106  <<tag<<std::endl;
107  edm::LogError("GsfElectronLinker")<<err.str();
108  }
109  return found;
110 
111 }
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
void GsfElectronLinker::fillValueMap ( edm::Handle< reco::GsfElectronCollection > &  c,
const edm::OrphanHandle< reco::PFCandidateCollection > &  pfHandle,
edm::ValueMap< reco::PFCandidateRef >::Filler &  filler 
) const
private

Definition at line 113 of file GsfElectronLinker.cc.

References electronCandidateMap_, edm::helper::Filler< Map >::insert(), and makeHLTPrescaleTable::values.

Referenced by produce().

115  {
116  unsigned nElectrons=electrons->size();
117  std::vector<reco::PFCandidateRef> values;
118  for(unsigned ielec=0;ielec<nElectrons;++ielec) {
119  reco::GsfElectronRef gsfElecRef(electrons,ielec);
120  std::map<reco::GsfElectronRef,unsigned>::const_iterator itcheck=electronCandidateMap_.find(gsfElecRef);
121  if(itcheck==electronCandidateMap_.end()) {
122  values.push_back(reco::PFCandidateRef());
123  } else {
124  values.push_back(reco::PFCandidateRef(pfHandle,itcheck->second));
125  }
126  }
127  filler.insert(electrons,values.begin(),values.end());
128 }
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::map< reco::GsfElectronRef, unsigned > electronCandidateMap_
map GsfElectron PFCandidate (index)
void GsfElectronLinker::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 25 of file GsfElectronLinker.cc.

References reco::PFCandidate::e, electronCandidateMap_, fetchCandidateCollection(), fetchGsfElectronCollection(), fillValueMap(), gsfElectrons_cfi::gsfElectrons, reco::PFCandidate::gsfTrackRef(), i, inputTagGsfElectrons_, inputTagPFCandidates_, nameOutputPF_, reco::PFCandidate::particleId(), reco::tau::pfCandidates(), edm::Event::put(), reco::PFCandidate::setGsfElectronRef(), reco::PFCandidate::setSourceCandidatePtr(), and ntuplemaker::status.

25  {
26  electronCandidateMap_.clear();
27  std::auto_ptr<reco::PFCandidateCollection>
28  pfCandidates_p(new reco::PFCandidateCollection);
29 
30  std::auto_ptr<edm::ValueMap<reco::PFCandidateRef> >
32  edm::ValueMap<reco::PFCandidateRef>::Filler pfMapFiller(*pfMap_p);
33 
35  bool status=fetchCandidateCollection(pfCandidates,
37  iEvent );
38 
40  status=fetchGsfElectronCollection(gsfElectrons,
42  iEvent );
43 
44  unsigned ncand=(status)?pfCandidates->size():0;
45 
46  for( unsigned i=0; i<ncand; ++i ) {
47  edm::Ptr<reco::PFCandidate> candPtr(pfCandidates,i);
48  reco::PFCandidate cand = (*pfCandidates)[i];
49  cand.setSourceCandidatePtr(candPtr);
50 
51  // if not an electron or not GsfTrackRef
52  if( (cand.particleId()!=reco::PFCandidate::e) ) {
53  pfCandidates_p->push_back(cand);
54  continue; // Watch out ! Continue
55  }
56 
57  // if it is an electron. Find the GsfElectron with the same GsfTrack
58  const reco::GsfTrackRef & gsfTrackRef(cand.gsfTrackRef());
59  GsfElectronEqual myEqual(gsfTrackRef);
60  std::vector<reco::GsfElectron>::const_iterator itcheck=find_if(gsfElectrons->begin(),gsfElectrons->end(),myEqual);
61  if(itcheck==gsfElectrons->end()) {
62  std::ostringstream err;
63  err << " Problem in GsfElectronLinker: no GsfElectron " << std::endl;
64  edm::LogError("GsfElectronLinker") << err.str();
65  continue; // Watch out ! Continue
66  }
67  reco::GsfElectronRef electronRef(gsfElectrons,itcheck-gsfElectrons->begin());
68  cand.setGsfElectronRef(electronRef);
69  electronCandidateMap_[electronRef]=i;
70  pfCandidates_p->push_back(cand);
71  }
72 
73  const edm::OrphanHandle<reco::PFCandidateCollection> pfCandidateRefProd =
74  iEvent.put(pfCandidates_p,nameOutputPF_);
75 
76  fillValueMap(gsfElectrons,pfCandidateRefProd,pfMapFiller);
77  iEvent.put(pfMap_p,nameOutputPF_);
78 }
edm::InputTag inputTagPFCandidates_
Input PFCandidates.
int i
Definition: DBlmapReader.cc:9
void setGsfElectronRef(const reco::GsfElectronRef &ref)
set GsfElectronRef
Definition: PFCandidate.cc:466
void setSourceCandidatePtr(const PFCandidatePtr &ptr)
Definition: PFCandidate.h:111
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
void fillValueMap(edm::Handle< reco::GsfElectronCollection > &c, const edm::OrphanHandle< reco::PFCandidateCollection > &pfHandle, edm::ValueMap< reco::PFCandidateRef >::Filler &filler) const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::map< reco::GsfElectronRef, unsigned > electronCandidateMap_
map GsfElectron PFCandidate (index)
bool fetchGsfElectronCollection(edm::Handle< reco::GsfElectronCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:368
bool fetchCandidateCollection(edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
tuple status
Definition: ntuplemaker.py:245
virtual ParticleType particleId() const
Definition: PFCandidate.h:314
edm::InputTag inputTagGsfElectrons_
Input GsfElectrons.
std::string nameOutputPF_
name of output collection of PFCandidate

Member Data Documentation

std::map<reco::GsfElectronRef,unsigned> GsfElectronLinker::electronCandidateMap_
private

map GsfElectron PFCandidate (index)

Definition at line 59 of file GsfElectronLinker.h.

Referenced by fillValueMap(), and produce().

edm::InputTag GsfElectronLinker::inputTagGsfElectrons_
private

Input GsfElectrons.

Definition at line 53 of file GsfElectronLinker.h.

Referenced by GsfElectronLinker(), and produce().

edm::InputTag GsfElectronLinker::inputTagPFCandidates_
private

Input PFCandidates.

Definition at line 50 of file GsfElectronLinker.h.

Referenced by GsfElectronLinker(), and produce().

std::string GsfElectronLinker::nameOutputPF_
private

name of output collection of PFCandidate

Definition at line 56 of file GsfElectronLinker.h.

Referenced by GsfElectronLinker(), and produce().