CMS 3D CMS Logo

pat::PATPFParticleProducer Class Reference

Produces pat::PFParticle's. More...

#include <PhysicsTools/PatAlgos/interface/PATPFParticleProducer.h>

Inheritance diagram for pat::PATPFParticleProducer:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PATPFParticleProducer (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 ~PATPFParticleProducer ()

Private Member Functions

void fetchCandidateCollection (edm::Handle< edm::View< PFParticleType > > &c, const edm::InputTag &tag, const edm::Event &iSetup) const

Private Attributes

bool addGenMatch_
bool embedGenMatch_
bool embedPFCandidate_
std::vector< edm::InputTaggenMatchSrc_
edm::InputTag pfCandidateSrc_
GreaterByPt< PFParticlepTComparator_


Detailed Description

Produces pat::PFParticle's.

The PATPFParticleProducer produces analysis-level pat::PFParticle's starting from a collection of objects of PFParticleType.

Author:
Steven Lowette, Roger Wolf
Version:
Id
PATPFParticleProducer.h,v 1.2.4.1 2008/11/25 15:39:40 gpetrucc Exp

Definition at line 40 of file PATPFParticleProducer.h.


Constructor & Destructor Documentation

PATPFParticleProducer::PATPFParticleProducer ( const edm::ParameterSet iConfig  )  [explicit]

Definition at line 26 of file PATPFParticleProducer.cc.

References addGenMatch_, embedGenMatch_, edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), and pfCandidateSrc_.

00026                                                                             {
00027   // general configurables
00028   pfCandidateSrc_ = iConfig.getParameter<edm::InputTag>( "pfCandidateSource" );
00029  
00030   // MC matching configurables
00031   addGenMatch_   = iConfig.getParameter<bool>         ( "addGenMatch" );
00032   if (addGenMatch_) {
00033       embedGenMatch_ = iConfig.getParameter<bool>         ( "embedGenMatch" );
00034       if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
00035           genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
00036       } else {
00037           genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
00038       }
00039   }
00040 
00041 
00042   // produces vector of muons
00043   produces<std::vector<PFParticle> >();
00044 
00045 }

PATPFParticleProducer::~PATPFParticleProducer (  ) 

Definition at line 48 of file PATPFParticleProducer.cc.

00048                                               {
00049 }


Member Function Documentation

void PATPFParticleProducer::fetchCandidateCollection ( edm::Handle< edm::View< PFParticleType > > &  c,
const edm::InputTag tag,
const edm::Event iSetup 
) const [private]

Definition at line 105 of file PATPFParticleProducer.cc.

References c, lat::endl(), err, Exception, and edm::Event::getByLabel().

Referenced by produce().

00107                                                                                {
00108   
00109   bool found = iEvent.getByLabel(tag, c);
00110   
00111   if(!found ) {
00112     std::ostringstream  err;
00113     err<<" cannot get PFCandidates: "
00114        <<tag<<std::endl;
00115     edm::LogError("PFCandidates")<<err.str();
00116     throw cms::Exception( "MissingProduct", err.str());
00117   }
00118   
00119 }

void PATPFParticleProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 52 of file PATPFParticleProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), fetchCandidateCollection(), genMatchSrc_, edm::Event::getByLabel(), i, j, n, pfCandidateSrc_, pTComparator_, ptr, edm::Event::put(), and python::multivaluedict::sort().

00053                                                                   {
00054 
00055   // Get the collection of PFCandidates from the event
00056   edm::Handle<edm::View<PFParticleType> > pfCandidates;
00057 
00058   fetchCandidateCollection(pfCandidates, 
00059                            pfCandidateSrc_, 
00060                            iEvent );
00061 
00062   // prepare the MC matching
00063   std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
00064   if (addGenMatch_) {
00065         for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
00066             iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
00067         }
00068   }
00069 
00070   // loop over PFCandidates
00071   std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
00072   for (edm::View<PFParticleType>::const_iterator 
00073          itPFParticle = pfCandidates->begin(); 
00074        itPFParticle != pfCandidates->end(); 
00075        ++itPFParticle) {
00076 
00077     // construct the PFParticle from the ref -> save ref to original object
00078     unsigned int idx = itPFParticle - pfCandidates->begin();
00079     edm::RefToBase<PFParticleType> pfCandidatesRef = pfCandidates->refAt(idx);
00080 
00081     PFParticle aPFParticle(pfCandidatesRef);
00082 
00083     if (addGenMatch_) {
00084       for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
00085           reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
00086           aPFParticle.addGenParticleRef(genPFParticle);
00087       }
00088       if (embedGenMatch_) aPFParticle.embedGenParticle();
00089     }
00090 
00091     // add sel to selected
00092     patPFParticles->push_back(aPFParticle);
00093   }
00094 
00095   // sort pfCandidates in pt
00096   std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
00097 
00098   // put genEvt object in Event
00099   std::auto_ptr<std::vector<PFParticle> > ptr(patPFParticles);
00100   iEvent.put(ptr);
00101 
00102 }


Member Data Documentation

bool pat::PATPFParticleProducer::addGenMatch_ [private]

Definition at line 58 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedGenMatch_ [private]

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedPFCandidate_ [private]

Definition at line 57 of file PATPFParticleProducer.h.

std::vector<edm::InputTag> pat::PATPFParticleProducer::genMatchSrc_ [private]

Definition at line 60 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

edm::InputTag pat::PATPFParticleProducer::pfCandidateSrc_ [private]

Definition at line 56 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

GreaterByPt<PFParticle> pat::PATPFParticleProducer::pTComparator_ [private]

Definition at line 62 of file PATPFParticleProducer.h.

Referenced by produce().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:49:44 2009 for CMSSW by  doxygen 1.5.4