CMS 3D CMS Logo

List of all members | Public 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::stream::EDProducer<>

Public Member Functions

 PATPFParticleProducer (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~PATPFParticleProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Attributes

bool addEfficiencies_
 
bool addGenMatch_
 
bool addResolutions_
 
pat::helper::EfficiencyLoader efficiencyLoader_
 
bool embedGenMatch_
 
bool embedPFCandidate_
 
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
 
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandidateToken_
 
GreaterByPt< PFParticlepTComparator_
 
pat::helper::KinResolutionsLoader resolutionLoader_
 
pat::PATUserDataHelper< pat::PFParticleuserDataHelper_
 
bool useUserData_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

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.8 2012/05/26 10:42:53 gpetrucc Exp

Definition at line 41 of file PATPFParticleProducer.h.

Constructor & Destructor Documentation

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

Definition at line 23 of file PATPFParticleProducer.cc.

References addEfficiencies_, addGenMatch_, addResolutions_, efficiencyLoader_, embedGenMatch_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), genMatchTokens_, edm::ParameterSet::getParameter(), pfCandidateToken_, resolutionLoader_, GlobalPosition_Frontier_DevDB_cff::tag, useUserData_, and edm::vector_transform().

24  : userDataHelper_(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector()) {
25  // general configurables
26  pfCandidateToken_ = consumes<edm::View<reco::PFCandidate> >(iConfig.getParameter<edm::InputTag>("pfCandidateSource"));
27 
28  // MC matching configurables
29  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
30  if (addGenMatch_) {
31  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
32  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
34  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
35  } else {
37  iConfig.getParameter<std::vector<edm::InputTag> >("genParticleMatch"),
38  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection> >(tag); });
39  }
40  }
41 
42  // Efficiency configurables
43  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
44  if (addEfficiencies_) {
46  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
47  }
48 
49  // Resolution configurables
50  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
51  if (addResolutions_) {
53  }
54 
55  // Check to see if the user wants to add user data
56  useUserData_ = false;
57  if (iConfig.exists("userData")) {
58  useUserData_ = true;
59  }
60 
61  // produces vector of muons
62  produces<std::vector<PFParticle> >();
63 }
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:160
pat::helper::KinResolutionsLoader resolutionLoader_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
bool exists(std::string const &parameterName) const
checks if a parameter exists
pat::helper::EfficiencyLoader efficiencyLoader_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandidateToken_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
PATPFParticleProducer::~PATPFParticleProducer ( )
override

Definition at line 65 of file PATPFParticleProducer.cc.

65 {}

Member Function Documentation

void PATPFParticleProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 67 of file PATPFParticleProducer.cc.

References addGenMatch_, pat::PATObject< ObjectType >::addGenParticleRef(), DEFINE_FWK_MODULE, efficiencyLoader_, embedGenMatch_, pat::PATObject< ObjectType >::embedGenParticle(), pat::helper::EfficiencyLoader::enabled(), pat::helper::KinResolutionsLoader::enabled(), genMatchTokens_, edm::Event::getByToken(), mps_fire::i, training_settings::idx, dqmiolumiharvest::j, eostools::move(), dqmiodumpmetadata::n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), pfParticleProducer_cfi::patPFParticles, zmumugammaAnalyzer_cfi::pfCandidates, pfCandidateToken_, pTComparator_, edm::Event::put(), resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::helper::KinResolutionsLoader::setResolutions(), userDataHelper_, and useUserData_.

67  {
68  // Get the collection of PFCandidates from the event
70  iEvent.getByToken(pfCandidateToken_, pfCandidates);
71 
72  // prepare the MC matching
73  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchTokens_.size());
74  if (addGenMatch_) {
75  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
76  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
77  }
78  }
79 
83  resolutionLoader_.newEvent(iEvent, iSetup);
84 
85  // loop over PFCandidates
86  std::vector<PFParticle>* patPFParticles = new std::vector<PFParticle>();
87  for (edm::View<reco::PFCandidate>::const_iterator itPFParticle = pfCandidates->begin();
88  itPFParticle != pfCandidates->end();
89  ++itPFParticle) {
90  // construct the PFParticle from the ref -> save ref to original object
91  unsigned int idx = itPFParticle - pfCandidates->begin();
92  edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);
93 
94  PFParticle aPFParticle(pfCandidatesRef);
95 
96  if (addGenMatch_) {
97  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
98  reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
99  aPFParticle.addGenParticleRef(genPFParticle);
100  }
101  if (embedGenMatch_)
102  aPFParticle.embedGenParticle();
103  }
104 
105  if (efficiencyLoader_.enabled()) {
106  efficiencyLoader_.setEfficiencies(aPFParticle, pfCandidatesRef);
107  }
108 
109  if (resolutionLoader_.enabled()) {
110  resolutionLoader_.setResolutions(aPFParticle);
111  }
112 
113  if (useUserData_) {
114  userDataHelper_.add(aPFParticle, iEvent, iSetup);
115  }
116 
117  // add sel to selected
118  patPFParticles->push_back(aPFParticle);
119  }
120 
121  // sort pfCandidates in pt
122  std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
123 
124  // put genEvt object in Event
125  std::unique_ptr<std::vector<PFParticle> > ptr(patPFParticles);
126  iEvent.put(std::move(ptr));
127 }
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
pat::helper::KinResolutionsLoader resolutionLoader_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
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
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
pat::helper::EfficiencyLoader efficiencyLoader_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandidateToken_
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:32
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
def move(src, dest)
Definition: eostools.py:511
GreaterByPt< PFParticle > pTComparator_

Member Data Documentation

bool pat::PATPFParticleProducer::addEfficiencies_
private

Definition at line 58 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

bool pat::PATPFParticleProducer::addGenMatch_
private

Definition at line 52 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::addResolutions_
private

Definition at line 61 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

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

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedGenMatch_
private

Definition at line 53 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedPFCandidate_
private

Definition at line 51 of file PATPFParticleProducer.h.

std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > > pat::PATPFParticleProducer::genMatchTokens_
private

Definition at line 54 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

edm::EDGetTokenT<edm::View<reco::PFCandidate> > pat::PATPFParticleProducer::pfCandidateToken_
private

Definition at line 50 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

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

Definition at line 56 of file PATPFParticleProducer.h.

Referenced by produce().

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

Definition at line 62 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

pat::PATUserDataHelper<pat::PFParticle> pat::PATPFParticleProducer::userDataHelper_
private

Definition at line 65 of file PATPFParticleProducer.h.

Referenced by produce().

bool pat::PATPFParticleProducer::useUserData_
private

Definition at line 64 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().