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

Public Member Functions

 PATPFParticleProducer (const edm::ParameterSet &iConfig)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 ~PATPFParticleProducer ()
 
- 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

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

Private Attributes

bool addEfficiencies_
 
bool addGenMatch_
 
bool addResolutions_
 
pat::helper::EfficiencyLoader efficiencyLoader_
 
bool embedGenMatch_
 
bool embedPFCandidate_
 
std::vector< edm::InputTaggenMatchSrc_
 
edm::InputTag pfCandidateSrc_
 
GreaterByPt< PFParticlepTComparator_
 
pat::helper::KinResolutionsLoader resolutionLoader_
 

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)
 
static void prevalidate (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

Produces pat::PFParticle's.

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

Author
Steven Lowette, Roger Wolf
Version
Id:
PATPFParticleProducer.h,v 1.7 2010/02/20 21:00:26 wmtan Exp

Definition at line 41 of file PATPFParticleProducer.h.

Constructor & Destructor Documentation

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

Definition at line 26 of file PATPFParticleProducer.cc.

References addEfficiencies_, addGenMatch_, addResolutions_, efficiencyLoader_, embedGenMatch_, edm::ParameterSet::existsAs(), genMatchSrc_, edm::ParameterSet::getParameter(), pfCandidateSrc_, and resolutionLoader_.

26  {
27  // general configurables
28  pfCandidateSrc_ = iConfig.getParameter<edm::InputTag>( "pfCandidateSource" );
29 
30  // MC matching configurables
31  addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" );
32  if (addGenMatch_) {
33  embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" );
34  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
35  genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
36  } else {
37  genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
38  }
39  }
40 
41  // Efficiency configurables
42  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
43  if (addEfficiencies_) {
45  }
46 
47  // Resolution configurables
48  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
49  if (addResolutions_) {
51  }
52 
53 
54 
55  // produces vector of muons
56  produces<std::vector<PFParticle> >();
57 
58 }
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:187
pat::helper::KinResolutionsLoader resolutionLoader_
std::vector< edm::InputTag > genMatchSrc_
pat::helper::EfficiencyLoader efficiencyLoader_
PATPFParticleProducer::~PATPFParticleProducer ( )

Definition at line 61 of file PATPFParticleProducer.cc.

61  {
62 }

Member Function Documentation

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

Definition at line 129 of file PATPFParticleProducer.cc.

References trackerHits::c, edm::hlt::Exception, newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by produce().

131  {
132 
133  bool found = iEvent.getByLabel(tag, c);
134 
135  if(!found ) {
136  std::ostringstream err;
137  err<<" cannot get PFCandidates: "
138  <<tag<<std::endl;
139  edm::LogError("PFCandidates")<<err.str();
140  throw cms::Exception( "MissingProduct", err.str());
141  }
142 
143 }
int iEvent
Definition: GenABIO.cc:243
void PATPFParticleProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 65 of file PATPFParticleProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::helper::EfficiencyLoader::enabled(), pat::helper::KinResolutionsLoader::enabled(), fetchCandidateCollection(), genMatchSrc_, edm::Event::getByLabel(), i, j, n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), pfParticleProducer_cfi::patPFParticles, reco::tau::pfCandidates(), pfCandidateSrc_, pTComparator_, edm::Event::put(), resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::helper::KinResolutionsLoader::setResolutions(), and python.multivaluedict::sort().

66  {
67 
68  // Get the collection of PFCandidates from the event
70 
71  fetchCandidateCollection(pfCandidates,
73  iEvent );
74 
75  // prepare the MC matching
76  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
77  if (addGenMatch_) {
78  for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
79  iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
80  }
81  }
82 
84  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
85 
86  // loop over PFCandidates
87  std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
89  itPFParticle = pfCandidates->begin();
90  itPFParticle != pfCandidates->end();
91  ++itPFParticle) {
92 
93  // construct the PFParticle from the ref -> save ref to original object
94  unsigned int idx = itPFParticle - pfCandidates->begin();
95  edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);
96 
97  PFParticle aPFParticle(pfCandidatesRef);
98 
99  if (addGenMatch_) {
100  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
101  reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
102  aPFParticle.addGenParticleRef(genPFParticle);
103  }
104  if (embedGenMatch_) aPFParticle.embedGenParticle();
105  }
106 
107  if (efficiencyLoader_.enabled()) {
108  efficiencyLoader_.setEfficiencies( aPFParticle, pfCandidatesRef );
109  }
110 
111  if (resolutionLoader_.enabled()) {
112  resolutionLoader_.setResolutions(aPFParticle);
113  }
114 
115  // add sel to selected
116  patPFParticles->push_back(aPFParticle);
117  }
118 
119  // sort pfCandidates in pt
120  std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
121 
122  // put genEvt object in Event
123  std::auto_ptr<std::vector<PFParticle> > ptr(patPFParticles);
124  iEvent.put(ptr);
125 
126 }
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
pat::helper::KinResolutionsLoader resolutionLoader_
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
std::vector< edm::InputTag > genMatchSrc_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
pat::helper::EfficiencyLoader efficiencyLoader_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:37
void fetchCandidateCollection(edm::Handle< edm::View< reco::PFCandidate > > &c, const edm::InputTag &tag, const edm::Event &iSetup) const
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
GreaterByPt< PFParticle > pTComparator_

Member Data Documentation

bool pat::PATPFParticleProducer::addEfficiencies_
private

Definition at line 65 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

bool pat::PATPFParticleProducer::addGenMatch_
private

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::addResolutions_
private

Definition at line 68 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

pat::helper::EfficiencyLoader pat::PATPFParticleProducer::efficiencyLoader_
private

Definition at line 66 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedGenMatch_
private

Definition at line 60 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedPFCandidate_
private

Definition at line 58 of file PATPFParticleProducer.h.

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

Definition at line 61 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

edm::InputTag pat::PATPFParticleProducer::pfCandidateSrc_
private

Definition at line 57 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

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

Definition at line 63 of file PATPFParticleProducer.h.

Referenced by produce().

pat::helper::KinResolutionsLoader pat::PATPFParticleProducer::resolutionLoader_
private

Definition at line 69 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().