1 |
bendavid |
1.9 |
// $Id: FillerPFCandidates.cc,v 1.8 2010/03/29 09:34:05 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
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 |
loizides |
1.3 |
#include "MitAna/DataTree/interface/Names.h"
|
12 |
|
|
#include "MitAna/DataTree/interface/PFCandidateCol.h"
|
13 |
bendavid |
1.1 |
#include "MitAna/DataTree/interface/Track.h"
|
14 |
loizides |
1.3 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
15 |
bendavid |
1.1 |
|
16 |
|
|
using namespace std;
|
17 |
|
|
using namespace edm;
|
18 |
|
|
using namespace mithep;
|
19 |
|
|
|
20 |
|
|
//--------------------------------------------------------------------------------------------------
|
21 |
loizides |
1.2 |
FillerPFCandidates::FillerPFCandidates(const edm::ParameterSet &cfg,
|
22 |
|
|
const char *name, bool active) :
|
23 |
bendavid |
1.1 |
BaseFiller(cfg,name,active),
|
24 |
|
|
edmName_(Conf().getUntrackedParameter<string>("edmName","particleFlow")),
|
25 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkPFCandidatesBrn)),
|
26 |
|
|
trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
|
27 |
|
|
gsfTrackMapName_(Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
|
28 |
|
|
muonMapName_(Conf().getUntrackedParameter<string>("muonMapName","")),
|
29 |
|
|
conversionMapName_(Conf().getUntrackedParameter<string>("conversionMapName","")),
|
30 |
|
|
pfCandMapName_(Conf().getUntrackedParameter<string>("pfCandMapName","")),
|
31 |
|
|
trackerTrackMap_(0),
|
32 |
|
|
gsfTrackMap_(0),
|
33 |
|
|
muonMap_(0),
|
34 |
|
|
conversionMap_(0),
|
35 |
|
|
pfCandMap_(new mithep::PFCandidateMap),
|
36 |
|
|
pfCands_(new mithep::PFCandidateArr(16))
|
37 |
|
|
{
|
38 |
|
|
// Constructor.
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
//--------------------------------------------------------------------------------------------------
|
42 |
loizides |
1.2 |
FillerPFCandidates::~FillerPFCandidates()
|
43 |
|
|
{
|
44 |
|
|
// Destructor.
|
45 |
|
|
|
46 |
bendavid |
1.1 |
delete pfCands_;
|
47 |
|
|
delete pfCandMap_;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
//--------------------------------------------------------------------------------------------------
|
51 |
bendavid |
1.5 |
void FillerPFCandidates::BookDataBlock(TreeWriter &tws)
|
52 |
loizides |
1.2 |
{
|
53 |
|
|
// Add particle-flow candidate branch to tree and get pointers to maps.
|
54 |
|
|
|
55 |
|
|
tws.AddBranch(mitName_,&pfCands_);
|
56 |
|
|
OS()->add<mithep::PFCandidateArr>(pfCands_,mitName_);
|
57 |
|
|
|
58 |
|
|
if (!trackerTrackMapName_.empty()) {
|
59 |
|
|
trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
|
60 |
|
|
if (trackerTrackMap_)
|
61 |
|
|
AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
|
62 |
|
|
}
|
63 |
|
|
if (!gsfTrackMapName_.empty()) {
|
64 |
|
|
gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
|
65 |
|
|
if (gsfTrackMap_)
|
66 |
|
|
AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
|
67 |
|
|
}
|
68 |
|
|
if (!muonMapName_.empty()) {
|
69 |
|
|
muonMap_ = OS()->get<MuonMap>(muonMapName_);
|
70 |
|
|
if (muonMap_)
|
71 |
|
|
AddBranchDep(mitName_,muonMap_->GetBrName());
|
72 |
|
|
}
|
73 |
|
|
if (!conversionMapName_.empty()) {
|
74 |
|
|
conversionMap_ = OS()->get<ConversionMap>(conversionMapName_);
|
75 |
|
|
if (conversionMap_)
|
76 |
|
|
AddBranchDep(mitName_,conversionMap_->GetBrName());
|
77 |
|
|
}
|
78 |
|
|
if (!pfCandMapName_.empty()) {
|
79 |
|
|
pfCandMap_->SetBrName(mitName_);
|
80 |
|
|
OS()->add<PFCandidateMap>(pfCandMap_,pfCandMapName_);
|
81 |
|
|
}
|
82 |
bendavid |
1.1 |
}
|
83 |
|
|
|
84 |
|
|
//--------------------------------------------------------------------------------------------------
|
85 |
|
|
void FillerPFCandidates::FillDataBlock(const edm::Event &event,
|
86 |
loizides |
1.2 |
const edm::EventSetup &setup)
|
87 |
bendavid |
1.1 |
{
|
88 |
|
|
// Fill muon information.
|
89 |
|
|
|
90 |
|
|
pfCands_->Delete();
|
91 |
|
|
pfCandMap_->Reset();
|
92 |
|
|
|
93 |
|
|
Handle<reco::PFCandidateCollection> hPfCandProduct;
|
94 |
|
|
GetProduct(edmName_, hPfCandProduct, event);
|
95 |
|
|
const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
|
96 |
|
|
|
97 |
loizides |
1.2 |
for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
|
98 |
|
|
iP != inPfCands.end(); ++iP) {
|
99 |
bendavid |
1.1 |
mithep::PFCandidate *outPfCand = pfCands_->Allocate();
|
100 |
|
|
new (outPfCand) mithep::PFCandidate(iP->px(),iP->py(),iP->pz(),iP->energy());
|
101 |
|
|
|
102 |
loizides |
1.2 |
// fill variables
|
103 |
bendavid |
1.1 |
outPfCand->SetCharge(iP->charge());
|
104 |
|
|
outPfCand->SetEECal(iP->ecalEnergy());
|
105 |
|
|
outPfCand->SetEHCal(iP->hcalEnergy());
|
106 |
|
|
outPfCand->SetEECalRaw(iP->rawEcalEnergy());
|
107 |
|
|
outPfCand->SetEHCalRaw(iP->rawHcalEnergy());
|
108 |
|
|
outPfCand->SetEPS1(iP->pS1Energy());
|
109 |
|
|
outPfCand->SetEPS2(iP->pS2Energy());
|
110 |
|
|
outPfCand->SetPError(iP->deltaP());
|
111 |
|
|
outPfCand->SetMvaEPi(iP->mva_e_pi());
|
112 |
|
|
outPfCand->SetMvaEMu(iP->mva_e_mu());
|
113 |
|
|
outPfCand->SetMvaPiMu(iP->mva_pi_mu());
|
114 |
|
|
outPfCand->SetMvaGamma(iP->mva_nothing_gamma());
|
115 |
|
|
outPfCand->SetMvaNeutralH(iP->mva_nothing_nh());
|
116 |
|
|
outPfCand->SetMvaGammaNeutralH(iP->mva_gamma_nh());
|
117 |
|
|
outPfCand->SetEtaECal(iP->positionAtECALEntrance().eta());
|
118 |
|
|
outPfCand->SetPhiECal(iP->positionAtECALEntrance().eta());
|
119 |
|
|
|
120 |
loizides |
1.2 |
// fill source vertex
|
121 |
bendavid |
1.1 |
outPfCand->SetVertex(iP->vertex().x(),iP->vertex().y(),iP->vertex().z());
|
122 |
|
|
|
123 |
loizides |
1.2 |
// fill pf type enum
|
124 |
bendavid |
1.1 |
if (iP->particleId()==reco::PFCandidate::X)
|
125 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eX);
|
126 |
|
|
else if (iP->particleId()==reco::PFCandidate::h)
|
127 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eHadron);
|
128 |
|
|
else if (iP->particleId()==reco::PFCandidate::e)
|
129 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eElectron);
|
130 |
|
|
else if (iP->particleId()==reco::PFCandidate::mu)
|
131 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eMuon);
|
132 |
|
|
else if (iP->particleId()==reco::PFCandidate::gamma)
|
133 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eGamma);
|
134 |
|
|
else if (iP->particleId()==reco::PFCandidate::h0)
|
135 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eNeutralHadron);
|
136 |
|
|
else if (iP->particleId()==reco::PFCandidate::h_HF)
|
137 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eHadronHF);
|
138 |
|
|
else if (iP->particleId()==reco::PFCandidate::egamma_HF)
|
139 |
|
|
outPfCand->SetPFType(mithep::PFCandidate::eEGammaHF);
|
140 |
|
|
|
141 |
loizides |
1.2 |
// fill pf flags bitmask
|
142 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eNormal,
|
143 |
|
|
iP->flag(reco::PFCandidate::NORMAL));
|
144 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMPhiSModules,
|
145 |
|
|
iP->flag(reco::PFCandidate::E_PHI_SMODULES));
|
146 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMEta0,
|
147 |
|
|
iP->flag(reco::PFCandidate::E_ETA_0));
|
148 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMEtaModules,
|
149 |
|
|
iP->flag(reco::PFCandidate::E_ETA_MODULES));
|
150 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMBarrelEndcap,
|
151 |
|
|
iP->flag(reco::PFCandidate::E_BARREL_ENDCAP));
|
152 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMPreshowerEdge,
|
153 |
|
|
iP->flag(reco::PFCandidate::E_PRESHOWER_EDGE));
|
154 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMPreshower,
|
155 |
|
|
iP->flag(reco::PFCandidate::E_PRESHOWER));
|
156 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eEMEndCapEdge,
|
157 |
|
|
iP->flag(reco::PFCandidate::E_ENDCAP_EDGE));
|
158 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eHEta0,
|
159 |
|
|
iP->flag(reco::PFCandidate::H_ETA_0));
|
160 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eHBarrelEndcap,
|
161 |
|
|
iP->flag(reco::PFCandidate::H_BARREL_ENDCAP));
|
162 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eHEndcapVFCal,
|
163 |
|
|
iP->flag(reco::PFCandidate::H_ENDCAP_VFCAL));
|
164 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eHVFCalEdge,
|
165 |
|
|
iP->flag(reco::PFCandidate::H_VFCAL_EDGE));
|
166 |
bendavid |
1.9 |
outPfCand->SetFlag(mithep::PFCandidate::eToDispVtx,
|
167 |
|
|
iP->flag(reco::PFCandidate::T_TO_DISP));
|
168 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eFromDispVtx,
|
169 |
|
|
iP->flag(reco::PFCandidate::T_FROM_DISP));
|
170 |
loizides |
1.2 |
outPfCand->SetFlag(mithep::PFCandidate::eFromV0,
|
171 |
|
|
iP->flag(reco::PFCandidate::T_FROM_V0));
|
172 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eFromGammaConv,
|
173 |
|
|
iP->flag(reco::PFCandidate::T_FROM_GAMMACONV));
|
174 |
|
|
outPfCand->SetFlag(mithep::PFCandidate::eToConversion,
|
175 |
|
|
iP->flag(reco::PFCandidate::GAMMA_TO_GAMMACONV));
|
176 |
bendavid |
1.1 |
|
177 |
loizides |
1.2 |
// fill references to other branches
|
178 |
bendavid |
1.1 |
if (trackerTrackMap_ && iP->trackRef().isNonnull())
|
179 |
|
|
outPfCand->SetTrackerTrk(trackerTrackMap_->GetMit(refToPtr(iP->trackRef())));
|
180 |
|
|
if (gsfTrackMap_ && iP->gsfTrackRef().isNonnull())
|
181 |
|
|
outPfCand->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iP->gsfTrackRef())));
|
182 |
|
|
if (muonMap_ && iP->muonRef().isNonnull())
|
183 |
|
|
outPfCand->SetMuon(muonMap_->GetMit(refToPtr(iP->muonRef())));
|
184 |
|
|
if (conversionMap_ && iP->conversionRef().isNonnull())
|
185 |
|
|
outPfCand->SetConversion(conversionMap_->GetMit(iP->conversionRef()));
|
186 |
|
|
|
187 |
loizides |
1.2 |
// add to exported pf candidate map
|
188 |
bendavid |
1.1 |
reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
|
189 |
|
|
pfCandMap_->Add(thePtr, outPfCand);
|
190 |
|
|
|
191 |
|
|
}
|
192 |
|
|
pfCands_->Trim();
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
//--------------------------------------------------------------------------------------------------
|
196 |
|
|
void FillerPFCandidates::ResolveLinks(const edm::Event &event,
|
197 |
loizides |
1.2 |
const edm::EventSetup &setup)
|
198 |
bendavid |
1.1 |
{
|
199 |
loizides |
1.2 |
// Resolve and fill mother-daughter links.
|
200 |
bendavid |
1.1 |
|
201 |
|
|
Handle<reco::PFCandidateCollection> hPfCandProduct;
|
202 |
|
|
GetProduct(edmName_, hPfCandProduct, event);
|
203 |
|
|
const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
|
204 |
|
|
|
205 |
loizides |
1.2 |
// loop through pf candidates and resolve mother-daughter links
|
206 |
|
|
for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
|
207 |
|
|
iP != inPfCands.end(); ++iP) {
|
208 |
|
|
|
209 |
bendavid |
1.1 |
reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
|
210 |
|
|
mithep::PFCandidate *outPfCand = pfCandMap_->GetMit(thePtr);
|
211 |
|
|
|
212 |
loizides |
1.2 |
// fill mother-daughter links
|
213 |
bendavid |
1.1 |
const reco::CandidatePtr motherCandPtr = iP->sourceCandidatePtr(0);
|
214 |
|
|
const reco::PFCandidatePtr motherPtr(motherCandPtr);
|
215 |
|
|
if (motherCandPtr.isNonnull()) {
|
216 |
|
|
mithep::PFCandidate *mother = pfCandMap_->GetMit(motherPtr);
|
217 |
|
|
outPfCand->SetMother(mother);
|
218 |
|
|
mother->AddDaughter(outPfCand);
|
219 |
|
|
}
|
220 |
|
|
}
|
221 |
|
|
}
|