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<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PATPFParticleProducer (const edm::ParameterSet &iConfig)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~PATPFParticleProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

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
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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 43 of file PATPFParticleProducer.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file PATPFParticleProducer.cc.

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

25  :
27 {
28  // general configurables
29  pfCandidateToken_ = consumes<edm::View<reco::PFCandidate> >(iConfig.getParameter<edm::InputTag>( "pfCandidateSource" ));
30 
31  // MC matching configurables
32  addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" );
33  if (addGenMatch_) {
34  embedGenMatch_ = iConfig.getParameter<bool>( "embedGenMatch" );
35  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
37  }
38  else {
39  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
40  }
41  }
42 
43  // Efficiency configurables
44  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
45  if (addEfficiencies_) {
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 
64 }
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:186
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
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
pat::helper::EfficiencyLoader efficiencyLoader_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandidateToken_
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
PATPFParticleProducer::~PATPFParticleProducer ( )

Definition at line 67 of file PATPFParticleProducer.cc.

67  {
68 }

Member Function Documentation

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

Definition at line 71 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, eostools::move(), gen::n, pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), pfParticleProducer_cfi::patPFParticles, slimmedMuons_cfi::pfCandidates, pfCandidateToken_, pTComparator_, edm::Event::put(), resolutionLoader_, pat::helper::EfficiencyLoader::setEfficiencies(), pat::helper::KinResolutionsLoader::setResolutions(), userDataHelper_, and useUserData_.

72  {
73 
74  // Get the collection of PFCandidates from the event
76  iEvent.getByToken(pfCandidateToken_, pfCandidates);
77 
78  // prepare the MC matching
79  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchTokens_.size());
80  if (addGenMatch_) {
81  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
82  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
83  }
84  }
85 
87  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
88 
89  // loop over PFCandidates
90  std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
92  itPFParticle = pfCandidates->begin();
93  itPFParticle != pfCandidates->end();
94  ++itPFParticle) {
95 
96  // construct the PFParticle from the ref -> save ref to original object
97  unsigned int idx = itPFParticle - pfCandidates->begin();
98  edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);
99 
100  PFParticle aPFParticle(pfCandidatesRef);
101 
102  if (addGenMatch_) {
103  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
104  reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
105  aPFParticle.addGenParticleRef(genPFParticle);
106  }
107  if (embedGenMatch_) aPFParticle.embedGenParticle();
108  }
109 
110  if (efficiencyLoader_.enabled()) {
111  efficiencyLoader_.setEfficiencies( aPFParticle, pfCandidatesRef );
112  }
113 
114  if (resolutionLoader_.enabled()) {
115  resolutionLoader_.setResolutions(aPFParticle);
116  }
117 
118  if ( useUserData_ ) {
119  userDataHelper_.add( aPFParticle, iEvent, iSetup );
120  }
121 
122 
123  // add sel to selected
124  patPFParticles->push_back(aPFParticle);
125  }
126 
127  // sort pfCandidates in pt
128  std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
129 
130  // put genEvt object in Event
131  std::unique_ptr<std::vector<PFParticle> > ptr(patPFParticles);
132  iEvent.put(std::move(ptr));
133 
134 }
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:127
pat::helper::KinResolutionsLoader resolutionLoader_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
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:35
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:510
GreaterByPt< PFParticle > pTComparator_

Member Data Documentation

bool pat::PATPFParticleProducer::addEfficiencies_
private

Definition at line 63 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

bool pat::PATPFParticleProducer::addGenMatch_
private

Definition at line 57 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::addResolutions_
private

Definition at line 66 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer().

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

Definition at line 64 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedGenMatch_
private

Definition at line 58 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

bool pat::PATPFParticleProducer::embedPFCandidate_
private

Definition at line 56 of file PATPFParticleProducer.h.

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

Definition at line 59 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

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

Definition at line 55 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

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

Definition at line 61 of file PATPFParticleProducer.h.

Referenced by produce().

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

Definition at line 67 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().

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

Definition at line 70 of file PATPFParticleProducer.h.

Referenced by produce().

bool pat::PATPFParticleProducer::useUserData_
private

Definition at line 69 of file PATPFParticleProducer.h.

Referenced by PATPFParticleProducer(), and produce().