CMS 3D CMS Logo

PATPFParticleProducer.cc
Go to the documentation of this file.
1 
31 
32 #include <vector>
33 #include <memory>
34 
35 namespace pat {
36 
37  class LeptonLRCalc;
38 
40  public:
41  explicit PATPFParticleProducer(const edm::ParameterSet& iConfig);
42  ~PATPFParticleProducer() override;
43 
44  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
45 
46  private:
47  // configurables
52  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > > genMatchTokens_;
53  // tools
55 
58 
61 
64  };
65 
66 } // namespace pat
67 
68 using namespace pat;
69 
71  : userDataHelper_(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector()) {
72  // general configurables
73  pfCandidateToken_ = consumes<edm::View<reco::PFCandidate> >(iConfig.getParameter<edm::InputTag>("pfCandidateSource"));
74 
75  // MC matching configurables
76  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
77  if (addGenMatch_) {
78  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
79  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
81  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
82  } else {
84  iConfig.getParameter<std::vector<edm::InputTag> >("genParticleMatch"),
85  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection> >(tag); });
86  }
87  }
88 
89  // Efficiency configurables
90  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
91  if (addEfficiencies_) {
93  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
94  }
95 
96  // Resolution configurables
97  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
98  if (addResolutions_) {
100  }
101 
102  // Check to see if the user wants to add user data
103  useUserData_ = false;
104  if (iConfig.exists("userData")) {
105  useUserData_ = true;
106  }
107 
108  // produces vector of muons
109  produces<std::vector<PFParticle> >();
110 }
111 
113 
115  // Get the collection of PFCandidates from the event
118 
119  // prepare the MC matching
120  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchTokens_.size());
121  if (addGenMatch_) {
122  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
123  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
124  }
125  }
126 
131 
132  // loop over PFCandidates
133  std::vector<PFParticle>* patPFParticles = new std::vector<PFParticle>();
134  for (edm::View<reco::PFCandidate>::const_iterator itPFParticle = pfCandidates->begin();
135  itPFParticle != pfCandidates->end();
136  ++itPFParticle) {
137  // construct the PFParticle from the ref -> save ref to original object
138  unsigned int idx = itPFParticle - pfCandidates->begin();
139  edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);
140 
141  PFParticle aPFParticle(pfCandidatesRef);
142 
143  if (addGenMatch_) {
144  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
145  reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
146  aPFParticle.addGenParticleRef(genPFParticle);
147  }
148  if (embedGenMatch_)
149  aPFParticle.embedGenParticle();
150  }
151 
152  if (efficiencyLoader_.enabled()) {
153  efficiencyLoader_.setEfficiencies(aPFParticle, pfCandidatesRef);
154  }
155 
156  if (resolutionLoader_.enabled()) {
157  resolutionLoader_.setResolutions(aPFParticle);
158  }
159 
160  if (useUserData_) {
161  userDataHelper_.add(aPFParticle, iEvent, iSetup);
162  }
163 
164  // add sel to selected
165  patPFParticles->push_back(aPFParticle);
166  }
167 
168  // sort pfCandidates in pt
170 
171  // put genEvt object in Event
172  std::unique_ptr<std::vector<PFParticle> > ptr(patPFParticles);
173  iEvent.put(std::move(ptr));
174 }
175 
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
pat::PATUserDataHelper< pat::PFParticle >
mps_fire.i
i
Definition: mps_fire.py:428
GreaterByPt
Definition: PtComparator.h:24
pat::PATPFParticleProducer::PATPFParticleProducer
PATPFParticleProducer(const edm::ParameterSet &iConfig)
Definition: PATPFParticleProducer.cc:70
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PFCandidate.h
pat::PATPFParticleProducer::embedGenMatch_
bool embedGenMatch_
Definition: PATPFParticleProducer.cc:51
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATPFParticleProducer
Produces pat::PFParticle's.
Definition: PATPFParticleProducer.cc:39
pat::helper::EfficiencyLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: EfficiencyLoader.h:25
EDProducer.h
pat::PATPFParticleProducer::addResolutions_
bool addResolutions_
Definition: PATPFParticleProducer.cc:59
pat::PATObject::addGenParticleRef
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:751
PtComparator.h
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:171
pat::PATPFParticleProducer::pTComparator_
GreaterByPt< PFParticle > pTComparator_
Definition: PATPFParticleProducer.cc:54
Association.h
pat::PATPFParticleProducer::embedPFCandidate_
bool embedPFCandidate_
Definition: PATPFParticleProducer.cc:49
pat::PFParticle
Analysis-level class for reconstructed particles.
Definition: PFParticle.h:32
edm::Handle
Definition: AssociativeIterator.h:50
MultiIsolator.h
EfficiencyLoader.h
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.cc:50
pat::PATPFParticleProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATPFParticleProducer.cc:114
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
GenParticle.h
pat::PATPFParticleProducer::efficiencyLoader_
pat::helper::EfficiencyLoader efficiencyLoader_
Definition: PATPFParticleProducer.cc:57
MakerMacros.h
pat::PATPFParticleProducer::~PATPFParticleProducer
~PATPFParticleProducer() override
Definition: PATPFParticleProducer.cc:112
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
GenParticleFwd.h
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
KinResolutionsLoader.h
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
FileInPath.h
pat::PATPFParticleProducer::useUserData_
bool useUserData_
Definition: PATPFParticleProducer.cc:62
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:681
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ParameterSet
Definition: Functions.h:16
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
UserData.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:36
pat::PATPFParticleProducer::userDataHelper_
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
Definition: PATPFParticleProducer.cc:63
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
PFParticle.h
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
InputTag.h
pat::PATPFParticleProducer::genMatchTokens_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
Definition: PATPFParticleProducer.cc:52
eostools.move
def move(src, dest)
Definition: eostools.py:511
pat::PATPFParticleProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATPFParticleProducer.cc:60
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.cc:48
PATUserDataHelper.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
View.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
pat::PATObject::embedGenParticle
void embedGenParticle()
Definition: PATObject.h:768
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
pfParticleProducer_cfi.patPFParticles
patPFParticles
Definition: pfParticleProducer_cfi.py:3
PFCandidateFwd.h
pat::PATPFParticleProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATPFParticleProducer.cc:56