1 |
dgele |
1.1 |
//
|
2 |
|
|
// $Id: PATGenericParticleProducer.cc,v 1.8.4.2 2009/04/30 09:11:46 gpetrucc Exp $
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
#include "PhysicsTools/PatAlgos/plugins/PATGenericParticleProducer.h"
|
6 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
7 |
|
|
#include "DataFormats/Common/interface/View.h"
|
8 |
|
|
#include <memory>
|
9 |
|
|
|
10 |
|
|
using namespace pat;
|
11 |
|
|
|
12 |
|
|
PATGenericParticleProducer::PATGenericParticleProducer(const edm::ParameterSet & iConfig) :
|
13 |
|
|
isolator_(iConfig.exists("isolation") ? iConfig.getParameter<edm::ParameterSet>("isolation") : edm::ParameterSet(), false),
|
14 |
|
|
userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
|
15 |
|
|
{
|
16 |
|
|
// initialize the configurables
|
17 |
|
|
src_ = iConfig.getParameter<edm::InputTag>( "src" );
|
18 |
|
|
|
19 |
|
|
// RECO embedding
|
20 |
|
|
embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
|
21 |
|
|
embedGsfTrack_ = iConfig.getParameter<bool>( "embedGsfTrack" );
|
22 |
|
|
embedStandalone_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
|
23 |
|
|
embedCombined_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
|
24 |
|
|
embedSuperCluster_ = iConfig.getParameter<bool>( "embedSuperCluster" );
|
25 |
|
|
embedTracks_ = iConfig.getParameter<bool>( "embedMultipleTracks" );
|
26 |
|
|
embedCaloTower_ = iConfig.getParameter<bool>( "embedCaloTower" );
|
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")) {
|
33 |
|
|
genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
|
34 |
|
|
} else {
|
35 |
|
|
genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
|
36 |
|
|
}
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
// Trigger matching configurables
|
40 |
|
|
addTrigMatch_ = iConfig.getParameter<bool>( "addTrigMatch" );
|
41 |
|
|
trigPrimSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "trigPrimMatch" );
|
42 |
|
|
|
43 |
|
|
// quality
|
44 |
|
|
addQuality_ = iConfig.getParameter<bool>("addQuality");
|
45 |
|
|
qualitySrc_ = iConfig.getParameter<edm::InputTag>("qualitySource");
|
46 |
|
|
|
47 |
|
|
// produces vector of particles
|
48 |
|
|
produces<std::vector<GenericParticle> >();
|
49 |
|
|
|
50 |
|
|
if (iConfig.exists("isoDeposits")) {
|
51 |
|
|
edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
|
52 |
|
|
if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
|
53 |
|
|
if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
|
54 |
|
|
if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));
|
55 |
|
|
if (depconf.exists("user")) {
|
56 |
|
|
std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
|
57 |
|
|
std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
|
58 |
|
|
int key = UserBaseIso;
|
59 |
|
|
for ( ; it != ed; ++it, ++key) {
|
60 |
|
|
isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
// Efficiency configurables
|
66 |
|
|
addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
|
67 |
|
|
if (addEfficiencies_) {
|
68 |
|
|
efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"));
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
// Resolution configurables
|
72 |
|
|
addResolutions_ = iConfig.getParameter<bool>("addResolutions");
|
73 |
|
|
if (addResolutions_) {
|
74 |
|
|
resolutionLoader_ = pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"));
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
if (iConfig.exists("vertexing")) {
|
78 |
|
|
vertexingHelper_ = pat::helper::VertexingHelper(iConfig.getParameter<edm::ParameterSet>("vertexing"));
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
// Check to see if the user wants to add user data
|
82 |
|
|
useUserData_ = false;
|
83 |
|
|
if ( iConfig.exists("userData") ) {
|
84 |
|
|
useUserData_ = true;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
PATGenericParticleProducer::~PATGenericParticleProducer() {
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void PATGenericParticleProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
|
92 |
|
|
// Get the vector of GenericParticle's from the event
|
93 |
|
|
edm::Handle<edm::View<reco::Candidate> > cands;
|
94 |
|
|
iEvent.getByLabel(src_, cands);
|
95 |
|
|
|
96 |
|
|
// prepare isolation
|
97 |
|
|
if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
|
98 |
|
|
|
99 |
|
|
if (efficiencyLoader_.enabled()) efficiencyLoader_.newEvent(iEvent);
|
100 |
|
|
if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
|
101 |
|
|
if (vertexingHelper_.enabled()) vertexingHelper_.newEvent(iEvent,iSetup);
|
102 |
|
|
|
103 |
|
|
// prepare IsoDeposits
|
104 |
|
|
std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size());
|
105 |
|
|
for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
|
106 |
|
|
iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
// prepare the MC matching
|
110 |
|
|
std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
|
111 |
|
|
if (addGenMatch_) {
|
112 |
|
|
for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
|
113 |
|
|
iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
// prepare the quality
|
118 |
|
|
edm::Handle<edm::ValueMap<float> > qualities;
|
119 |
|
|
if (addQuality_) iEvent.getByLabel(qualitySrc_, qualities);
|
120 |
|
|
|
121 |
|
|
// loop over cands
|
122 |
|
|
std::vector<GenericParticle> * PATGenericParticles = new std::vector<GenericParticle>();
|
123 |
|
|
for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end(); itGenericParticle++) {
|
124 |
|
|
// construct the GenericParticle from the ref -> save ref to original object
|
125 |
|
|
unsigned int idx = itGenericParticle - cands->begin();
|
126 |
|
|
edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);
|
127 |
|
|
|
128 |
|
|
PATGenericParticles->push_back(GenericParticle(candRef));
|
129 |
|
|
GenericParticle & aGenericParticle = PATGenericParticles->back();
|
130 |
|
|
|
131 |
|
|
// embed RECO
|
132 |
|
|
if (embedTrack_) aGenericParticle.embedTrack();
|
133 |
|
|
if (embedGsfTrack_) aGenericParticle.embedGsfTrack();
|
134 |
|
|
if (embedTracks_) aGenericParticle.embedTracks();
|
135 |
|
|
if (embedStandalone_) aGenericParticle.embedStandalone();
|
136 |
|
|
if (embedCombined_) aGenericParticle.embedCombined();
|
137 |
|
|
if (embedSuperCluster_) aGenericParticle.embedSuperCluster();
|
138 |
|
|
if (embedCaloTower_) aGenericParticle.embedCaloTower();
|
139 |
|
|
|
140 |
|
|
// matches to fired trigger primitives
|
141 |
|
|
if ( addTrigMatch_ ) {
|
142 |
|
|
for ( size_t i = 0; i < trigPrimSrc_.size(); ++i ) {
|
143 |
|
|
edm::Handle<edm::Association<TriggerPrimitiveCollection> > trigMatch;
|
144 |
|
|
iEvent.getByLabel(trigPrimSrc_[i], trigMatch);
|
145 |
|
|
TriggerPrimitiveRef trigPrim = (*trigMatch)[candRef];
|
146 |
|
|
if ( trigPrim.isNonnull() && trigPrim.isAvailable() ) {
|
147 |
|
|
aGenericParticle.addTriggerMatch(*trigPrim);
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
// isolation
|
153 |
|
|
if (isolator_.enabled()) {
|
154 |
|
|
isolator_.fill(*cands, idx, isolatorTmpStorage_);
|
155 |
|
|
typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
|
156 |
|
|
// better to loop backwards, so the vector is resized less times
|
157 |
|
|
for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
|
158 |
|
|
aGenericParticle.setIsolation(it->first, it->second);
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
// isodeposit
|
163 |
|
|
for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
|
164 |
|
|
aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
// store the match to the generated final state muons
|
168 |
|
|
if (addGenMatch_) {
|
169 |
|
|
for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
|
170 |
|
|
reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
|
171 |
|
|
aGenericParticle.addGenParticleRef(genGenericParticle);
|
172 |
|
|
}
|
173 |
|
|
if (embedGenMatch_) aGenericParticle.embedGenParticle();
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
if (addQuality_) {
|
177 |
|
|
aGenericParticle.setQuality( (*qualities)[candRef] );
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
if (efficiencyLoader_.enabled()) {
|
181 |
|
|
efficiencyLoader_.setEfficiencies( aGenericParticle, candRef );
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
if (resolutionLoader_.enabled()) {
|
185 |
|
|
resolutionLoader_.setResolutions(aGenericParticle);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
if (vertexingHelper_.enabled()) {
|
189 |
|
|
aGenericParticle.setVertexAssociation( vertexingHelper_(candRef) );
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
if ( useUserData_ ) {
|
193 |
|
|
userDataHelper_.add( aGenericParticle, iEvent, iSetup );
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
// PATGenericParticles->push_back(aGenericParticle); // NOOOOO!!!!
|
197 |
|
|
// We have already pushed_back this generic particle in the collection
|
198 |
|
|
// (we first push an empty particle and then fill it, to avoid useless copies)
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
// sort GenericParticles in ET
|
202 |
|
|
std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);
|
203 |
|
|
|
204 |
|
|
// put genEvt object in Event
|
205 |
|
|
std::auto_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
|
206 |
|
|
iEvent.put(myGenericParticles);
|
207 |
|
|
if (isolator_.enabled()) isolator_.endEvent();
|
208 |
|
|
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
212 |
|
|
|
213 |
|
|
DEFINE_FWK_MODULE(PATGenericParticleProducer);
|