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::PATPFParticleProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 23 of file PATPFParticleProducer.cc.

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 }

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

◆ ~PATPFParticleProducer()

PATPFParticleProducer::~PATPFParticleProducer ( )
override

Definition at line 65 of file PATPFParticleProducer.cc.

65 {}

Member Function Documentation

◆ produce()

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

Definition at line 67 of file PATPFParticleProducer.cc.

67  {
68  // Get the collection of PFCandidates from the event
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 
84 
85  // loop over PFCandidates
86  std::vector<PFParticle>* patPFParticles = new std::vector<PFParticle>();
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 }

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

Member Data Documentation

◆ addEfficiencies_

bool pat::PATPFParticleProducer::addEfficiencies_
private

Definition at line 58 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

◆ addGenMatch_

bool pat::PATPFParticleProducer::addGenMatch_
private

Definition at line 52 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

◆ addResolutions_

bool pat::PATPFParticleProducer::addResolutions_
private

Definition at line 61 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

◆ efficiencyLoader_

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

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

◆ embedGenMatch_

bool pat::PATPFParticleProducer::embedGenMatch_
private

Definition at line 53 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

◆ embedPFCandidate_

bool pat::PATPFParticleProducer::embedPFCandidate_
private

Definition at line 51 of file PATPFParticleProducer.h.

◆ genMatchTokens_

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

◆ pfCandidateToken_

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

Definition at line 50 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

◆ pTComparator_

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

Definition at line 56 of file PATPFParticleProducer.h.

Referenced by produce().

◆ resolutionLoader_

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

Definition at line 62 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

◆ userDataHelper_

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

Definition at line 65 of file PATPFParticleProducer.h.

Referenced by produce().

◆ useUserData_

bool pat::PATPFParticleProducer::useUserData_
private

Definition at line 64 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::PATPFParticleProducer::embedGenMatch_
bool embedGenMatch_
Definition: PATPFParticleProducer.h:53
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
pat::helper::EfficiencyLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: EfficiencyLoader.h:25
pat::PATPFParticleProducer::addResolutions_
bool addResolutions_
Definition: PATPFParticleProducer.h:61
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
pat::PATPFParticleProducer::pTComparator_
GreaterByPt< PFParticle > pTComparator_
Definition: PATPFParticleProducer.h:56
pat::PFParticle
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:32
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
pat::helper::KinResolutionsLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: KinResolutionsLoader.h:27
edm::Ref< GenParticleCollection >
pat::PATPFParticleProducer::addGenMatch_
bool addGenMatch_
Definition: PATPFParticleProducer.h:52
pat::PATPFParticleProducer::efficiencyLoader_
pat::helper::EfficiencyLoader efficiencyLoader_
Definition: PATPFParticleProducer.h:59
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
pat::PATUserDataHelper::add
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
Definition: PATUserDataHelper.h:114
pat::helper::EfficiencyLoader::newEvent
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
Definition: EfficiencyLoader.cc:21
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
edm::vector_transform
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::PATPFParticleProducer::useUserData_
bool useUserData_
Definition: PATPFParticleProducer.h:64
pat::helper::KinResolutionsLoader::setResolutions
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: KinResolutionsLoader.h:49
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
edm::ParameterSet
Definition: ParameterSet.h:36
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PATPFParticleProducer::userDataHelper_
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
Definition: PATPFParticleProducer.h:65
edm::Association
Definition: Association.h:18
pat::helper::KinResolutionsLoader::newEvent
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
Definition: KinResolutionsLoader.cc:27
pat::PATPFParticleProducer::genMatchTokens_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
Definition: PATPFParticleProducer.h:54
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
pat::PATPFParticleProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATPFParticleProducer.h:62
pat::helper::EfficiencyLoader::setEfficiencies
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: EfficiencyLoader.h:41
pat::PATPFParticleProducer::pfCandidateToken_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandidateToken_
Definition: PATPFParticleProducer.h:50
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::InputTag
Definition: InputTag.h:15
pfParticleProducer_cfi.patPFParticles
patPFParticles
Definition: pfParticleProducer_cfi.py:3
pat::PATPFParticleProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATPFParticleProducer.h:58