ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFCandidates.cc
Revision: 1.14.2.2
Committed: Fri Jun 14 19:34:40 2013 UTC (11 years, 10 months ago) by paus
Content type: text/plain
Branch: Mit_025c_branch
CVS Tags: Mit_025c_branch2
Changes since 1.14.2.1: +46 -55 lines
Log Message:
PrepareForBackportVersion3.

File Contents

# Content
1 // $Id: FillerPFCandidates.cc,v 1.14.2.1 2013/05/31 22:58:45 pharris Exp $
2
3 #include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
4 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
5 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
6 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
7 #include "DataFormats/MuonReco/interface/Muon.h"
8 #include "DataFormats/MuonReco/interface/MuonFwd.h"
9 #include "DataFormats/Common/interface/RefToPtr.h"
10 #include "MitAna/DataTree/interface/Muon.h"
11 #include "MitAna/DataTree/interface/Names.h"
12 #include "MitAna/DataTree/interface/PFCandidateCol.h"
13 #include "MitAna/DataTree/interface/Track.h"
14 #include "MitProd/ObjectService/interface/ObjectService.h"
15
16 using namespace std;
17 using namespace edm;
18 using namespace mithep;
19
20 //--------------------------------------------------------------------------------------------------
21 FillerPFCandidates::FillerPFCandidates(const edm::ParameterSet &cfg,
22 const char *name, bool active) :
23 BaseFiller (cfg,name,active),
24 edmName_ (Conf().getUntrackedParameter<string>("edmName","particleFlow")),
25 mitName_ (Conf().getUntrackedParameter<string>("mitName",Names::gkPFCandidatesBrn)),
26 trackerTrackMapNames_ (Conf().exists("trackerTrackMapNames") ?
27 Conf().getUntrackedParameter<vector<string> >("trackerTrackMapNames") :
28 vector<string>()),
29 gsfTrackMapName_ (Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
30 muonMapName_ (Conf().getUntrackedParameter<string>("muonMapName","")),
31 barrelSuperClusterMapName_ (Conf().getUntrackedParameter<string>("barrelSuperClusterMapName","")),
32 endcapSuperClusterMapName_ (Conf().getUntrackedParameter<string>("endcapSuperClusterMapName","")),
33 pfElectronSuperClusterMapName_(Conf().getUntrackedParameter<string>("pfElectronSuperClusterMapName","")),
34 conversionMapName_ (Conf().getUntrackedParameter<string>("conversionMapName","")),
35 pfCandMapName_ (Conf().getUntrackedParameter<string>("pfCandMapName","")),
36 allowMissingTrackRef_ (Conf().getUntrackedParameter<bool>("allowMissingTrackRef",false)),
37 gsfTrackMap_ (0),
38 muonMap_ (0),
39 barrelSuperClusterMap_ (0),
40 endcapSuperClusterMap_ (0),
41 pfElectronSuperClusterMap_ (0),
42 conversionMap_ (0),
43 pfCandMap_ (new mithep::PFCandidateMap),
44 pfCands_ (new mithep::PFCandidateArr(16))
45 {
46 // Constructor.
47 }
48
49 //--------------------------------------------------------------------------------------------------
50 FillerPFCandidates::~FillerPFCandidates()
51 {
52 // Destructor.
53
54 delete pfCands_;
55 delete pfCandMap_;
56 }
57
58 //--------------------------------------------------------------------------------------------------
59 void FillerPFCandidates::BookDataBlock(TreeWriter &tws)
60 {
61 // Add particle-flow candidate branch to tree and get pointers to maps.
62
63 tws.AddBranch(mitName_,&pfCands_);
64 OS()->add<mithep::PFCandidateArr>(pfCands_,mitName_);
65
66 // if (!trackerTrackMapName_.empty()) {
67 // trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
68 // if (trackerTrackMap_)
69 // AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
70 // }
71
72 for (std::vector<std::string>::const_iterator bmapName = trackerTrackMapNames_.begin();
73 bmapName!=trackerTrackMapNames_.end(); ++bmapName) {
74 if (!bmapName->empty()) {
75 const TrackMap *map = OS()->get<TrackMap>(*bmapName);
76 if (map) {
77 trackerTrackMaps_.push_back(map);
78 AddBranchDep(mitName_,map->GetBrName());
79 }
80 }
81 }
82
83 if (!gsfTrackMapName_.empty()) {
84 gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
85 if (gsfTrackMap_)
86 AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
87 }
88 if (!muonMapName_.empty()) {
89 muonMap_ = OS()->get<MuonMap>(muonMapName_);
90 if (muonMap_)
91 AddBranchDep(mitName_,muonMap_->GetBrName());
92 }
93 if (!barrelSuperClusterMapName_.empty()) {
94 barrelSuperClusterMap_ = OS()->get<SuperClusterMap>(barrelSuperClusterMapName_);
95 if (barrelSuperClusterMap_)
96 AddBranchDep(mitName_,barrelSuperClusterMap_->GetBrName());
97 }
98 if (!endcapSuperClusterMapName_.empty()) {
99 endcapSuperClusterMap_ = OS()->get<SuperClusterMap>(endcapSuperClusterMapName_);
100 if (endcapSuperClusterMap_)
101 AddBranchDep(mitName_,endcapSuperClusterMap_->GetBrName());
102 }
103 if (!pfElectronSuperClusterMapName_.empty()) {
104 pfElectronSuperClusterMap_ = OS()->get<SuperClusterMap>(pfElectronSuperClusterMapName_);
105 if (pfElectronSuperClusterMap_)
106 AddBranchDep(mitName_,pfElectronSuperClusterMap_->GetBrName());
107 }
108 if (!conversionMapName_.empty()) {
109 conversionMap_ = OS()->get<ConversionMap>(conversionMapName_);
110 if (conversionMap_)
111 AddBranchDep(mitName_,conversionMap_->GetBrName());
112 }
113 if (!pfCandMapName_.empty()) {
114 pfCandMap_->SetBrName(mitName_);
115 OS()->add<PFCandidateMap>(pfCandMap_,pfCandMapName_);
116 }
117 }
118
119 //--------------------------------------------------------------------------------------------------
120 void FillerPFCandidates::FillDataBlock(const edm::Event &event,
121 const edm::EventSetup &setup)
122 {
123 // Fill muon information.
124
125 pfCands_->Delete();
126 pfCandMap_->Reset();
127
128 Handle<reco::PFCandidateCollection> hPfCandProduct;
129 GetProduct(edmName_, hPfCandProduct, event);
130 const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
131
132 for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
133 iP != inPfCands.end(); ++iP) {
134 mithep::PFCandidate *outPfCand = pfCands_->Allocate();
135 new (outPfCand) mithep::PFCandidate(iP->px(),iP->py(),iP->pz(),iP->energy());
136
137 // fill variables
138 outPfCand->SetCharge(iP->charge());
139 outPfCand->SetEECal(iP->ecalEnergy());
140 outPfCand->SetEHCal(iP->hcalEnergy());
141 outPfCand->SetEECalRaw(iP->rawEcalEnergy());
142 outPfCand->SetEHCalRaw(iP->rawHcalEnergy());
143 outPfCand->SetEPS1(iP->pS1Energy());
144 outPfCand->SetEPS2(iP->pS2Energy());
145 outPfCand->SetPError(iP->deltaP());
146 outPfCand->SetMvaEPi(iP->mva_e_pi());
147 outPfCand->SetMvaEMu(iP->mva_e_mu());
148 outPfCand->SetMvaPiMu(iP->mva_pi_mu());
149 outPfCand->SetMvaGamma(iP->mva_nothing_gamma());
150 outPfCand->SetMvaNeutralH(iP->mva_nothing_nh());
151 outPfCand->SetMvaGammaNeutralH(iP->mva_gamma_nh());
152 outPfCand->SetEtaECal(iP->positionAtECALEntrance().eta());
153 outPfCand->SetPhiECal(iP->positionAtECALEntrance().phi());
154
155 // fill source vertex
156 outPfCand->SetVertex(iP->vertex().x(),iP->vertex().y(),iP->vertex().z());
157
158 // fill pf type enum
159 if (iP->particleId()==reco::PFCandidate::X)
160 outPfCand->SetPFType(mithep::PFCandidate::eX);
161 else if (iP->particleId()==reco::PFCandidate::h)
162 outPfCand->SetPFType(mithep::PFCandidate::eHadron);
163 else if (iP->particleId()==reco::PFCandidate::e)
164 outPfCand->SetPFType(mithep::PFCandidate::eElectron);
165 else if (iP->particleId()==reco::PFCandidate::mu)
166 outPfCand->SetPFType(mithep::PFCandidate::eMuon);
167 else if (iP->particleId()==reco::PFCandidate::gamma)
168 outPfCand->SetPFType(mithep::PFCandidate::eGamma);
169 else if (iP->particleId()==reco::PFCandidate::h0)
170 outPfCand->SetPFType(mithep::PFCandidate::eNeutralHadron);
171 else if (iP->particleId()==reco::PFCandidate::h_HF)
172 outPfCand->SetPFType(mithep::PFCandidate::eHadronHF);
173 else if (iP->particleId()==reco::PFCandidate::egamma_HF)
174 outPfCand->SetPFType(mithep::PFCandidate::eEGammaHF);
175
176 // fill pf flags bitmask
177 outPfCand->SetFlag(mithep::PFCandidate::eNormal,
178 iP->flag(reco::PFCandidate::NORMAL));
179 outPfCand->SetFlag(mithep::PFCandidate::eEMPhiSModules,
180 iP->flag(reco::PFCandidate::E_PHI_SMODULES));
181 outPfCand->SetFlag(mithep::PFCandidate::eEMEta0,
182 iP->flag(reco::PFCandidate::E_ETA_0));
183 outPfCand->SetFlag(mithep::PFCandidate::eEMEtaModules,
184 iP->flag(reco::PFCandidate::E_ETA_MODULES));
185 outPfCand->SetFlag(mithep::PFCandidate::eEMBarrelEndcap,
186 iP->flag(reco::PFCandidate::E_BARREL_ENDCAP));
187 outPfCand->SetFlag(mithep::PFCandidate::eEMPreshowerEdge,
188 iP->flag(reco::PFCandidate::E_PRESHOWER_EDGE));
189 outPfCand->SetFlag(mithep::PFCandidate::eEMPreshower,
190 iP->flag(reco::PFCandidate::E_PRESHOWER));
191 outPfCand->SetFlag(mithep::PFCandidate::eEMEndCapEdge,
192 iP->flag(reco::PFCandidate::E_ENDCAP_EDGE));
193 outPfCand->SetFlag(mithep::PFCandidate::eHEta0,
194 iP->flag(reco::PFCandidate::H_ETA_0));
195 outPfCand->SetFlag(mithep::PFCandidate::eHBarrelEndcap,
196 iP->flag(reco::PFCandidate::H_BARREL_ENDCAP));
197 outPfCand->SetFlag(mithep::PFCandidate::eHEndcapVFCal,
198 iP->flag(reco::PFCandidate::H_ENDCAP_VFCAL));
199 outPfCand->SetFlag(mithep::PFCandidate::eHVFCalEdge,
200 iP->flag(reco::PFCandidate::H_VFCAL_EDGE));
201 outPfCand->SetFlag(mithep::PFCandidate::eToDispVtx,
202 iP->flag(reco::PFCandidate::T_TO_DISP));
203 outPfCand->SetFlag(mithep::PFCandidate::eFromDispVtx,
204 iP->flag(reco::PFCandidate::T_FROM_DISP));
205 outPfCand->SetFlag(mithep::PFCandidate::eFromV0,
206 iP->flag(reco::PFCandidate::T_FROM_V0));
207 outPfCand->SetFlag(mithep::PFCandidate::eFromGammaConv,
208 iP->flag(reco::PFCandidate::T_FROM_GAMMACONV));
209 outPfCand->SetFlag(mithep::PFCandidate::eToConversion,
210 iP->flag(reco::PFCandidate::GAMMA_TO_GAMMACONV));
211
212 //printf("pf type = %i\n",iP->particleId());
213
214 // fill references to other branches
215 if (iP->trackRef().isNonnull()) {
216 //printf("track: process = %i, product = %i, algo = %i, highPurity = %i\n",iP->trackRef().id().processIndex(),iP->trackRef().id().productIndex(),iP->trackRef()->algo(),iP->trackRef()->quality(reco::TrackBase::highPurity));
217 const mithep::Track *thetrack = getMitTrack(refToPtr(iP->trackRef()),allowMissingTrackRef_);
218 outPfCand->SetTrackerTrk(thetrack);
219 }
220 if (gsfTrackMap_ && iP->gsfTrackRef().isNonnull())
221 outPfCand->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iP->gsfTrackRef())));
222 if (muonMap_ && iP->muonRef().isNonnull())
223 outPfCand->SetMuon(muonMap_->GetMit(refToPtr(iP->muonRef())));
224 if (barrelSuperClusterMap_ && endcapSuperClusterMap_ && pfElectronSuperClusterMap_ && iP->superClusterRef().isNonnull()) {
225 if (barrelSuperClusterMap_->HasMit(iP->superClusterRef()))
226 outPfCand->SetSCluster(barrelSuperClusterMap_->GetMit(iP->superClusterRef()));
227 else if (endcapSuperClusterMap_->HasMit(iP->superClusterRef()))
228 outPfCand->SetSCluster(endcapSuperClusterMap_->GetMit(iP->superClusterRef()));
229 else if ( pfElectronSuperClusterMap_->HasMit(iP->superClusterRef()))
230 outPfCand->SetSCluster(pfElectronSuperClusterMap_->GetMit(iP->superClusterRef()));
231 }
232 if (conversionMap_ && iP->conversionRef().isNonnull())
233 outPfCand->SetConversion(conversionMap_->GetMit(iP->conversionRef()));
234
235 // add to exported pf candidate map
236 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
237 pfCandMap_->Add(thePtr, outPfCand);
238
239 }
240 pfCands_->Trim();
241 }
242
243 //--------------------------------------------------------------------------------------------------
244 void FillerPFCandidates::ResolveLinks(const edm::Event &event,
245 const edm::EventSetup &setup)
246 {
247 // Resolve and fill mother-daughter links.
248
249 Handle<reco::PFCandidateCollection> hPfCandProduct;
250 GetProduct(edmName_, hPfCandProduct, event);
251 const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
252
253 // loop through pf candidates and resolve mother-daughter links
254 for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
255 iP != inPfCands.end(); ++iP) {
256
257 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
258 mithep::PFCandidate *outPfCand = pfCandMap_->GetMit(thePtr);
259
260 // fill mother-daughter links
261 // const reco::CandidatePtr motherCandPtr = iP->sourceCandidatePtr(0);
262 // const reco::PFCandidatePtr motherPtr(motherCandPtr);
263 // if (motherCandPtr.isNonnull()) {
264 // mithep::PFCandidate *mother = pfCandMap_->GetMit(motherPtr);
265 // outPfCand->SetMother(mother);
266 // mother->AddDaughter(outPfCand);
267 // }
268 }
269 }
270
271 //--------------------------------------------------------------------------------------------------
272 const mithep::Track *FillerPFCandidates::getMitTrack(mitedm::TrackPtr ptr, bool allowmissing) const
273 {
274 // Return our particle referenced by the edm pointer.
275
276 mithep::Track *mitPart = 0;
277 for (std::vector<const mithep::TrackMap*>::const_iterator bmap = trackerTrackMaps_.begin();
278 bmap!=trackerTrackMaps_.end(); ++bmap) {
279 const mithep::TrackMap *theMap = *bmap;
280 if (theMap->HasMit(ptr)) {
281 mitPart = theMap->GetMit(ptr);
282 return mitPart;
283 }
284 }
285
286 if (!mitPart && !allowmissing)
287 throw edm::Exception(edm::errors::Configuration, "FillerPFCandidates::FillDataBlock()\n")
288 << "Error! MITHEP Object "
289 << "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
290
291 return mitPart;
292 }