CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

GsfElectronLinker Class Reference

#include <GsfElectronLinker.h>

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

List of all members.

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

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)
edm::InputTag inputTagGsfElectrons_
 Input GsfElectrons.
edm::InputTag inputTagPFCandidates_
 Input PFCandidates.
std::string nameOutputPF_
 name of output collection of PFCandidate

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

                                                                    {
  inputTagPFCandidates_ 
    = iConfig.getParameter<edm::InputTag>("PFCandidate");
  inputTagGsfElectrons_
    = iConfig.getParameter<edm::InputTag>("GsfElectrons");
  nameOutputPF_ 
    = iConfig.getParameter<std::string>("OutputPF");
  
  produces<reco::PFCandidateCollection>(nameOutputPF_);
  produces<edm::ValueMap<reco::PFCandidateRef> > (nameOutputPF_);
}
GsfElectronLinker::~GsfElectronLinker ( )

Definition at line 21 of file GsfElectronLinker.cc.

{;}

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.

{;}
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().

                                                                                  {  
  bool found = iEvent.getByLabel(tag, c);
  
  if(!found )
    {
      std::ostringstream  err;
      err<<" cannot get PFCandidates: "
         <<tag<<std::endl;
      edm::LogError("GsfElectronLinker")<<err.str();
    }
  return found;
  
}
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().

                                                                              {
  bool found = iEvent.getByLabel(tag, c);
  
  if(!found )
    {
      std::ostringstream  err;
      err<<" cannot get GsfElectrons: "
         <<tag<<std::endl;
      edm::LogError("GsfElectronLinker")<<err.str();
    }
  return found;

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

                                                                                        {
  unsigned nElectrons=electrons->size();
  std::vector<reco::PFCandidateRef> values;
  for(unsigned ielec=0;ielec<nElectrons;++ielec) {
    reco::GsfElectronRef gsfElecRef(electrons,ielec);
    std::map<reco::GsfElectronRef,unsigned>::const_iterator itcheck=electronCandidateMap_.find(gsfElecRef);
    if(itcheck==electronCandidateMap_.end()) {
      values.push_back(reco::PFCandidateRef());
    } else {
      values.push_back(reco::PFCandidateRef(pfHandle,itcheck->second));
    }
  }
  filler.insert(electrons,values.begin(),values.end());
}
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.

                                                                             {
  electronCandidateMap_.clear();
  std::auto_ptr<reco::PFCandidateCollection>
    pfCandidates_p(new reco::PFCandidateCollection);

  std::auto_ptr<edm::ValueMap<reco::PFCandidateRef> > 
    pfMap_p(new edm::ValueMap<reco::PFCandidateRef>());
  edm::ValueMap<reco::PFCandidateRef>::Filler pfMapFiller(*pfMap_p);

  edm::Handle<reco::PFCandidateCollection> pfCandidates;
  bool status=fetchCandidateCollection(pfCandidates, 
                                       inputTagPFCandidates_, 
                                       iEvent );

  edm::Handle<reco::GsfElectronCollection> gsfElectrons;
  status=fetchGsfElectronCollection(gsfElectrons,
                                    inputTagGsfElectrons_,
                                    iEvent );

  unsigned ncand=(status)?pfCandidates->size():0;

  for( unsigned i=0; i<ncand; ++i ) {
    edm::Ptr<reco::PFCandidate> candPtr(pfCandidates,i);
    reco::PFCandidate cand = (*pfCandidates)[i];    
    cand.setSourceCandidatePtr(candPtr);
    
    // if not an electron or not GsfTrackRef
    if( (cand.particleId()!=reco::PFCandidate::e) ) {
      pfCandidates_p->push_back(cand);
      continue; // Watch out ! Continue
    }
    
    // if it is an electron. Find the GsfElectron with the same GsfTrack
    const reco::GsfTrackRef & gsfTrackRef(cand.gsfTrackRef());
    GsfElectronEqual myEqual(gsfTrackRef);
    std::vector<reco::GsfElectron>::const_iterator itcheck=find_if(gsfElectrons->begin(),gsfElectrons->end(),myEqual);
    if(itcheck==gsfElectrons->end()) {
      std::ostringstream err;
      err << " Problem in GsfElectronLinker: no GsfElectron " << std::endl;
      edm::LogError("GsfElectronLinker") << err.str();
      continue; // Watch out ! Continue
    } 
    reco::GsfElectronRef electronRef(gsfElectrons,itcheck-gsfElectrons->begin());
    cand.setGsfElectronRef(electronRef);
    electronCandidateMap_[electronRef]=i;
    pfCandidates_p->push_back(cand);
  }  

  const edm::OrphanHandle<reco::PFCandidateCollection> pfCandidateRefProd = 
    iEvent.put(pfCandidates_p,nameOutputPF_);

  fillValueMap(gsfElectrons,pfCandidateRefProd,pfMapFiller);
  iEvent.put(pfMap_p,nameOutputPF_);
}

Member Data Documentation

map GsfElectron PFCandidate (index)

Definition at line 59 of file GsfElectronLinker.h.

Referenced by fillValueMap(), and produce().

Input GsfElectrons.

Definition at line 53 of file GsfElectronLinker.h.

Referenced by GsfElectronLinker(), and produce().

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