CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATPFParticleProducer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATPFParticleProducer.cc,v 1.6 2012/05/26 10:42:53 gpetrucc Exp $
3 //
4 
6 
9 
14 
16 
17 #include "TMath.h"
18 
19 #include <vector>
20 #include <memory>
21 
22 
23 using namespace pat;
24 
25 
27  userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
28 {
29  // general configurables
30  pfCandidateSrc_ = iConfig.getParameter<edm::InputTag>( "pfCandidateSource" );
31 
32  // MC matching configurables
33  addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" );
34  if (addGenMatch_) {
35  embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" );
36  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
37  genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
38  } else {
39  genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
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 }
65 
66 
68 }
69 
70 
72  const edm::EventSetup & iSetup) {
73 
74  // Get the collection of PFCandidates from the event
76 
77  fetchCandidateCollection(pfCandidates,
79  iEvent );
80 
81  // prepare the MC matching
82  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
83  if (addGenMatch_) {
84  for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
85  iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
86  }
87  }
88 
90  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
91 
92  // loop over PFCandidates
93  std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
95  itPFParticle = pfCandidates->begin();
96  itPFParticle != pfCandidates->end();
97  ++itPFParticle) {
98 
99  // construct the PFParticle from the ref -> save ref to original object
100  unsigned int idx = itPFParticle - pfCandidates->begin();
101  edm::RefToBase<reco::PFCandidate> pfCandidatesRef = pfCandidates->refAt(idx);
102 
103  PFParticle aPFParticle(pfCandidatesRef);
104 
105  if (addGenMatch_) {
106  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
107  reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
108  aPFParticle.addGenParticleRef(genPFParticle);
109  }
110  if (embedGenMatch_) aPFParticle.embedGenParticle();
111  }
112 
113  if (efficiencyLoader_.enabled()) {
114  efficiencyLoader_.setEfficiencies( aPFParticle, pfCandidatesRef );
115  }
116 
117  if (resolutionLoader_.enabled()) {
118  resolutionLoader_.setResolutions(aPFParticle);
119  }
120 
121  if ( useUserData_ ) {
122  userDataHelper_.add( aPFParticle, iEvent, iSetup );
123  }
124 
125 
126  // add sel to selected
127  patPFParticles->push_back(aPFParticle);
128  }
129 
130  // sort pfCandidates in pt
131  std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
132 
133  // put genEvt object in Event
134  std::auto_ptr<std::vector<PFParticle> > ptr(patPFParticles);
135  iEvent.put(ptr);
136 
137 }
138 
139 void
141  const edm::InputTag& tag,
142  const edm::Event& iEvent) const {
143 
144  bool found = iEvent.getByLabel(tag, c);
145 
146  if(!found ) {
147  std::ostringstream err;
148  err<<" cannot get PFCandidates: "
149  <<tag<<std::endl;
150  edm::LogError("PFCandidates")<<err.str();
151  throw cms::Exception( "MissingProduct", err.str());
152  }
153 
154 }
155 
156 
157 
159 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
PATPFParticleProducer(const edm::ParameterSet &iConfig)
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_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
void embedGenParticle()
Definition: PATObject.h:675
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
pat::helper::EfficiencyLoader efficiencyLoader_
Produces pat::PFParticle&#39;s.
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:659
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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
pat::PATUserDataHelper< pat::PFParticle > userDataHelper_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
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_