1 |
// $Id: FillerPFCandidates.cc,v 1.13 2011/09/28 16:50:07 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 (conversionMap_ && iP->conversionRef().isNonnull())
|
204 |
outPfCand->SetConversion(conversionMap_->GetMit(iP->conversionRef()));
|
205 |
|
206 |
// add to exported pf candidate map
|
207 |
reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
|
208 |
pfCandMap_->Add(thePtr, outPfCand);
|
209 |
|
210 |
}
|
211 |
pfCands_->Trim();
|
212 |
}
|
213 |
|
214 |
//--------------------------------------------------------------------------------------------------
|
215 |
void FillerPFCandidates::ResolveLinks(const edm::Event &event,
|
216 |
const edm::EventSetup &setup)
|
217 |
{
|
218 |
// Resolve and fill mother-daughter links.
|
219 |
|
220 |
Handle<reco::PFCandidateCollection> hPfCandProduct;
|
221 |
GetProduct(edmName_, hPfCandProduct, event);
|
222 |
const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
|
223 |
|
224 |
// loop through pf candidates and resolve mother-daughter links
|
225 |
for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
|
226 |
iP != inPfCands.end(); ++iP) {
|
227 |
|
228 |
reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
|
229 |
mithep::PFCandidate *outPfCand = pfCandMap_->GetMit(thePtr);
|
230 |
|
231 |
// fill mother-daughter links
|
232 |
// const reco::CandidatePtr motherCandPtr = iP->sourceCandidatePtr(0);
|
233 |
// const reco::PFCandidatePtr motherPtr(motherCandPtr);
|
234 |
// if (motherCandPtr.isNonnull()) {
|
235 |
// mithep::PFCandidate *mother = pfCandMap_->GetMit(motherPtr);
|
236 |
// outPfCand->SetMother(mother);
|
237 |
// mother->AddDaughter(outPfCand);
|
238 |
// }
|
239 |
}
|
240 |
}
|
241 |
|
242 |
//--------------------------------------------------------------------------------------------------
|
243 |
const mithep::Track *FillerPFCandidates::getMitTrack(mitedm::TrackPtr ptr, bool allowmissing) const
|
244 |
{
|
245 |
// Return our particle referenced by the edm pointer.
|
246 |
|
247 |
mithep::Track *mitPart = 0;
|
248 |
for (std::vector<const mithep::TrackMap*>::const_iterator bmap = trackerTrackMaps_.begin();
|
249 |
bmap!=trackerTrackMaps_.end(); ++bmap) {
|
250 |
const mithep::TrackMap *theMap = *bmap;
|
251 |
if (theMap->HasMit(ptr)) {
|
252 |
mitPart = theMap->GetMit(ptr);
|
253 |
return mitPart;
|
254 |
}
|
255 |
}
|
256 |
|
257 |
if (!mitPart && !allowmissing)
|
258 |
throw edm::Exception(edm::errors::Configuration, "FillerPFCandidates::FillDataBlock()\n")
|
259 |
<< "Error! MITHEP Object "
|
260 |
<< "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
|
261 |
|
262 |
return mitPart;
|
263 |
} |