ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFCandidates.cc
Revision: 1.14.2.1
Committed: Fri May 31 22:58:45 2013 UTC (11 years, 11 months ago) by pharris
Content type: text/plain
Branch: Mit_025c_branch
CVS Tags: Mit_025c_branch1
Changes since 1.14: +40 -2 lines
Log Message:
updated 42X for Tau

File Contents

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