ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/plugins/PATPFParticleProducer.cc
Revision: 1.2
Committed: Tue Oct 20 17:42:58 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
State: FILE REMOVED
Log Message:
remove

File Contents

# Content
1 //
2 // $Id: PATPFParticleProducer.cc,v 1.1 2009/10/20 17:15:14 dgele Exp $
3 //
4
5 #include "PhysicsTools/PatAlgos/plugins/PATPFParticleProducer.h"
6
7 #include "FWCore/MessageLogger/interface/MessageLogger.h"
8 #include "FWCore/ParameterSet/interface/FileInPath.h"
9
10 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
11 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
12 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
13 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
14
15 #include "DataFormats/Common/interface/Association.h"
16
17 #include "TMath.h"
18
19 #include <vector>
20 #include <memory>
21
22
23 using namespace pat;
24
25
26 PATPFParticleProducer::PATPFParticleProducer(const edm::ParameterSet & iConfig) {
27 // general configurables
28 pfCandidateSrc_ = iConfig.getParameter<edm::InputTag>( "pfCandidateSource" );
29
30 // MC matching configurables
31 addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" );
32 if (addGenMatch_) {
33 embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" );
34 if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
35 genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
36 } else {
37 genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
38 }
39 }
40
41 // Efficiency configurables
42 addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
43 if (addEfficiencies_) {
44 efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
45 }
46
47 // Resolution configurables
48 addResolutions_ = iConfig.getParameter<bool>("addResolutions");
49 if (addResolutions_) {
50 resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
51 }
52
53
54 // produces vector of muons
55 produces<std::vector<PFParticle> >();
56
57 }
58
59
60 PATPFParticleProducer::~PATPFParticleProducer() {
61 }
62
63
64 void PATPFParticleProducer::produce(edm::Event & iEvent,
65 const edm::EventSetup & iSetup) {
66
67 // Get the collection of PFCandidates from the event
68 edm::Handle<edm::View<PFParticleType> > pfCandidates;
69
70 fetchCandidateCollection(pfCandidates,
71 pfCandidateSrc_,
72 iEvent );
73
74 // prepare the MC matching
75 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
76 if (addGenMatch_) {
77 for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
78 iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
79 }
80 }
81
82 if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
83 if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
84
85 // loop over PFCandidates
86 std::vector<PFParticle> * patPFParticles = new std::vector<PFParticle>();
87 for (edm::View<PFParticleType>::const_iterator
88 itPFParticle = pfCandidates->begin();
89 itPFParticle != pfCandidates->end();
90 ++itPFParticle) {
91
92 // construct the PFParticle from the ref -> save ref to original object
93 unsigned int idx = itPFParticle - pfCandidates->begin();
94 edm::RefToBase<PFParticleType> pfCandidatesRef = pfCandidates->refAt(idx);
95
96 PFParticle aPFParticle(pfCandidatesRef);
97
98 if (addGenMatch_) {
99 for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
100 reco::GenParticleRef genPFParticle = (*genMatches[i])[pfCandidatesRef];
101 aPFParticle.addGenParticleRef(genPFParticle);
102 }
103 if (embedGenMatch_) aPFParticle.embedGenParticle();
104 }
105
106 if (efficiencyLoader_.enabled()) {
107 efficiencyLoader_.setEfficiencies( aPFParticle, pfCandidatesRef );
108 }
109
110 if (resolutionLoader_.enabled()) {
111 resolutionLoader_.setResolutions(aPFParticle);
112 }
113
114 // add sel to selected
115 patPFParticles->push_back(aPFParticle);
116 }
117
118 // sort pfCandidates in pt
119 std::sort(patPFParticles->begin(), patPFParticles->end(), pTComparator_);
120
121 // put genEvt object in Event
122 std::auto_ptr<std::vector<PFParticle> > ptr(patPFParticles);
123 iEvent.put(ptr);
124
125 }
126
127 void
128 PATPFParticleProducer::fetchCandidateCollection( edm::Handle< edm::View<PFParticleType> >& c,
129 const edm::InputTag& tag,
130 const edm::Event& iEvent) const {
131
132 bool found = iEvent.getByLabel(tag, c);
133
134 if(!found ) {
135 std::ostringstream err;
136 err<<" cannot get PFCandidates: "
137 <<tag<<std::endl;
138 edm::LogError("PFCandidates")<<err.str();
139 throw cms::Exception( "MissingProduct", err.str());
140 }
141
142 }
143
144
145
146 #include "FWCore/Framework/interface/MakerMacros.h"
147
148 DEFINE_FWK_MODULE(PATPFParticleProducer);