1 |
loizides |
1.29 |
// $Id: FillerElectrons.cc,v 1.28 2009/03/10 15:56:01 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillerElectrons.h"
|
4 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
6 |
|
|
#include "DataFormats/TrackReco/interface/Track.h"
|
7 |
|
|
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
|
8 |
|
|
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
9 |
sixie |
1.11 |
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
|
10 |
|
|
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
|
11 |
|
|
#include "DataFormats/EgammaReco/interface/ClusterShape.h"
|
12 |
|
|
#include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
|
13 |
bendavid |
1.18 |
#include "DataFormats/Common/interface/RefToPtr.h"
|
14 |
sixie |
1.11 |
#include "RecoEgamma/EgammaIsolationAlgos/interface/ElectronTkIsolation.h"
|
15 |
|
|
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaEcalIsolation.h"
|
16 |
sixie |
1.14 |
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
|
17 |
bendavid |
1.19 |
#include "MitEdm/Producers/interface/RefToBaseToPtr.h"
|
18 |
loizides |
1.1 |
#include "MitAna/DataTree/interface/Track.h"
|
19 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
20 |
sixie |
1.12 |
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
|
21 |
|
|
#include "AnalysisDataFormats/Egamma/interface/ElectronID.h"
|
22 |
|
|
#include "AnalysisDataFormats/Egamma/interface/ElectronIDAssociation.h"
|
23 |
sixie |
1.13 |
#include "DataFormats/Common/interface/ValueMap.h"
|
24 |
|
|
|
25 |
loizides |
1.1 |
using namespace std;
|
26 |
|
|
using namespace edm;
|
27 |
|
|
using namespace mithep;
|
28 |
|
|
|
29 |
loizides |
1.5 |
//--------------------------------------------------------------------------------------------------
|
30 |
loizides |
1.28 |
FillerElectrons::FillerElectrons(const edm::ParameterSet &cfg, const char *name, bool active) :
|
31 |
|
|
BaseFiller(cfg,name,active),
|
32 |
loizides |
1.1 |
edmName_(Conf().getUntrackedParameter<string>("edmName","pixelMatchGsfElectrons")),
|
33 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkElectronBrn)),
|
34 |
loizides |
1.10 |
gsfTrackMapName_(Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
|
35 |
|
|
trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
|
36 |
sixie |
1.12 |
barrelEcalRecHitName_(Conf().getUntrackedParameter<string>("barrelEcalRecHitName","")),
|
37 |
|
|
endcapEcalRecHitName_(Conf().getUntrackedParameter<string>("endcapEcalRecHitName","")),
|
38 |
|
|
barrelSuperClusterName_(Conf().getUntrackedParameter<string>("barrelSuperClusterName", "")),
|
39 |
|
|
endcapSuperClusterName_(Conf().getUntrackedParameter<string>("endcapSuperClusterName", "")),
|
40 |
|
|
barrelBasicClusterName_(Conf().getUntrackedParameter<string>("barrelBasicClusterName", "")),
|
41 |
|
|
endcapBasicClusterName_(Conf().getUntrackedParameter<string>("endcapBasicClusterName", "")),
|
42 |
|
|
barrelSuperClusterMapName_(Conf().getUntrackedParameter<string>("barrelSuperClusterMapName","")),
|
43 |
|
|
endcapSuperClusterMapName_(Conf().getUntrackedParameter<string>("endcapSuperClusterMapName","")),
|
44 |
loizides |
1.16 |
eIDCutBasedTightName_(Conf().getUntrackedParameter<string>("eIDCutBasedTightName","eidTight")),
|
45 |
sixie |
1.13 |
eIDCutBasedLooseName_(Conf().getUntrackedParameter<string>("eIDCutBasedLooseName","eidLoose")),
|
46 |
sixie |
1.12 |
eIDLikelihoodName_(Conf().getUntrackedParameter<string>("eIDLikelihood","eidLikelihood")),
|
47 |
|
|
eIDNeuralNetName_(Conf().getUntrackedParameter<string>("eIDNeuralNet","eidNeuralNet")),
|
48 |
loizides |
1.16 |
isoTrackColName_(Conf().getUntrackedParameter<string>
|
49 |
|
|
("IsolationTrackCollectionName","generalTracks")),
|
50 |
|
|
isoCaloTowerColName_(Conf().getUntrackedParameter<string>
|
51 |
|
|
("IsolationCaloTowerCollectionName","towerMaker")),
|
52 |
|
|
ecalJurassicIsoName_(Conf().getUntrackedParameter<string>
|
53 |
|
|
("EcalJurassicIsolationName","eleIsoFromDepsEcalFromHits")),
|
54 |
|
|
hcalJurassicIsoName_(Conf().getUntrackedParameter<string>
|
55 |
|
|
("HcalJurassicIsolationName","eleIsoFromDepsHcalFromHits")),
|
56 |
peveraer |
1.17 |
trackerIsoName_(Conf().getUntrackedParameter<string>
|
57 |
|
|
("TrackerIsolationName","eleIsoFromDepsTk")),
|
58 |
bendavid |
1.19 |
gsfTrackAssocName_(Conf().getUntrackedParameter<string>("gsfTrackAssocName","")),
|
59 |
loizides |
1.8 |
electrons_(new mithep::ElectronArr(16)),
|
60 |
loizides |
1.10 |
gsfTrackMap_(0),
|
61 |
sixie |
1.11 |
trackerTrackMap_(0),
|
62 |
sixie |
1.12 |
barrelSuperClusterMap_(0),
|
63 |
|
|
endcapSuperClusterMap_(0)
|
64 |
loizides |
1.1 |
{
|
65 |
|
|
// Constructor.
|
66 |
|
|
}
|
67 |
|
|
|
68 |
loizides |
1.5 |
//--------------------------------------------------------------------------------------------------
|
69 |
loizides |
1.1 |
FillerElectrons::~FillerElectrons()
|
70 |
|
|
{
|
71 |
|
|
// Destructor.
|
72 |
loizides |
1.6 |
|
73 |
|
|
delete electrons_;
|
74 |
loizides |
1.1 |
}
|
75 |
|
|
|
76 |
loizides |
1.5 |
//--------------------------------------------------------------------------------------------------
|
77 |
loizides |
1.1 |
void FillerElectrons::BookDataBlock(TreeWriter &tws)
|
78 |
|
|
{
|
79 |
loizides |
1.10 |
// Add electron branch to our tree and get our maps.
|
80 |
loizides |
1.1 |
|
81 |
loizides |
1.29 |
tws.AddBranch(mitName_,&electrons_);
|
82 |
|
|
OS()->add<mithep::ElectronArr>(electrons_,mitName_);
|
83 |
loizides |
1.10 |
|
84 |
loizides |
1.29 |
if (!gsfTrackMapName_.empty()) {
|
85 |
|
|
gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
|
86 |
|
|
if (gsfTrackMap_)
|
87 |
|
|
AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
|
88 |
|
|
}
|
89 |
|
|
if (!trackerTrackMapName_.empty()) {
|
90 |
|
|
trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
|
91 |
|
|
if (trackerTrackMap_)
|
92 |
|
|
AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
|
93 |
|
|
}
|
94 |
|
|
if (!barrelSuperClusterMapName_.empty()) {
|
95 |
|
|
barrelSuperClusterMap_ = OS()->get<SuperClusterMap>(barrelSuperClusterMapName_);
|
96 |
|
|
if (barrelSuperClusterMap_)
|
97 |
|
|
AddBranchDep(mitName_,barrelSuperClusterMap_->GetBrName());
|
98 |
|
|
}
|
99 |
|
|
if (!endcapSuperClusterMapName_.empty()) {
|
100 |
|
|
endcapSuperClusterMap_ = OS()->get<SuperClusterMap>(endcapSuperClusterMapName_);
|
101 |
|
|
if (endcapSuperClusterMap_)
|
102 |
|
|
AddBranchDep(mitName_,endcapSuperClusterMap_->GetBrName());
|
103 |
|
|
}
|
104 |
loizides |
1.1 |
}
|
105 |
|
|
|
106 |
loizides |
1.5 |
//--------------------------------------------------------------------------------------------------
|
107 |
loizides |
1.29 |
void FillerElectrons::FillDataBlock(const edm::Event &event, const edm::EventSetup &setup)
|
108 |
loizides |
1.1 |
{
|
109 |
|
|
// Fill electrons from edm collection into our collection.
|
110 |
|
|
|
111 |
bendavid |
1.26 |
electrons_->Delete();
|
112 |
loizides |
1.1 |
|
113 |
sixie |
1.11 |
Handle<reco::GsfElectronCollection> hElectronProduct;
|
114 |
loizides |
1.7 |
GetProduct(edmName_, hElectronProduct, event);
|
115 |
loizides |
1.1 |
|
116 |
loizides |
1.29 |
// handles to get the electron ID information
|
117 |
sixie |
1.13 |
Handle<edm::ValueMap<float> > eidLooseMap;
|
118 |
|
|
GetProduct(eIDCutBasedLooseName_, eidLooseMap, event);
|
119 |
|
|
Handle<edm::ValueMap<float> > eidTightMap;
|
120 |
|
|
GetProduct(eIDCutBasedTightName_, eidTightMap, event);
|
121 |
|
|
Handle<edm::ValueMap<float> > eidLikelihoodMap;
|
122 |
|
|
GetProduct(eIDLikelihoodName_, eidLikelihoodMap, event);
|
123 |
bendavid |
1.19 |
|
124 |
loizides |
1.29 |
// get gsf track association map if needed
|
125 |
bendavid |
1.19 |
mitedm::TrackAssociation gsfAssociation;
|
126 |
|
|
if (trackerTrackMap_ && !gsfTrackAssocName_.empty()) {
|
127 |
|
|
Handle<mitedm::TrackAssociation> gsfAssociationProduct;
|
128 |
|
|
GetProduct(gsfTrackAssocName_, gsfAssociationProduct, event);
|
129 |
|
|
gsfAssociation = *(gsfAssociationProduct.product());
|
130 |
|
|
}
|
131 |
|
|
|
132 |
sixie |
1.11 |
const reco::GsfElectronCollection inElectrons = *(hElectronProduct.product());
|
133 |
loizides |
1.29 |
// loop over electrons
|
134 |
sixie |
1.11 |
for (reco::GsfElectronCollection::const_iterator iM = inElectrons.begin();
|
135 |
loizides |
1.1 |
iM != inElectrons.end(); ++iM) {
|
136 |
sixie |
1.13 |
|
137 |
loizides |
1.29 |
// the index and Ref are needed for the eID association Map
|
138 |
sixie |
1.13 |
unsigned int iElectron = iM - inElectrons.begin();
|
139 |
|
|
reco::GsfElectronRef eRef(hElectronProduct, iElectron);
|
140 |
|
|
|
141 |
loizides |
1.8 |
mithep::Electron *outElectron = electrons_->AddNew();
|
142 |
sixie |
1.12 |
|
143 |
loizides |
1.29 |
outElectron->SetESuperClusterOverP(iM->eSuperClusterOverP()) ;
|
144 |
|
|
outElectron->SetESeedClusterOverPout(iM->eSeedClusterOverPout()) ;
|
145 |
|
|
outElectron->SetPIn(iM->trackMomentumAtVtx().R()) ;
|
146 |
|
|
outElectron->SetPOut(iM->trackMomentumOut().R());
|
147 |
|
|
outElectron->SetDeltaEtaSuperClusterTrackAtVtx(iM->deltaEtaSuperClusterTrackAtVtx()) ;
|
148 |
|
|
outElectron->SetDeltaEtaSeedClusterTrackAtCalo(iM->deltaEtaSeedClusterTrackAtCalo()) ;
|
149 |
|
|
outElectron->SetDeltaPhiSuperClusterTrackAtVtx(iM->deltaPhiSuperClusterTrackAtVtx()) ;
|
150 |
|
|
outElectron->SetDeltaPhiSeedClusterTrackAtCalo(iM->deltaPhiSeedClusterTrackAtCalo()) ;
|
151 |
|
|
outElectron->SetHadronicOverEm(iM->hadronicOverEm()) ;
|
152 |
|
|
outElectron->SetIsEnergyScaleCorrected(iM->isEnergyScaleCorrected()) ;
|
153 |
|
|
outElectron->SetIsMomentumCorrected(iM->isMomentumCorrected()) ;
|
154 |
|
|
outElectron->SetNumberOfClusters(iM->numberOfClusters()) ;
|
155 |
|
|
outElectron->SetClassification(iM->classification()) ;
|
156 |
sixie |
1.11 |
|
157 |
loizides |
1.29 |
// shower shape variables
|
158 |
loizides |
1.16 |
EcalClusterLazyTools lazyTools(event, setup, edm::InputTag(barrelEcalRecHitName_),
|
159 |
|
|
edm::InputTag(endcapEcalRecHitName_));
|
160 |
|
|
outElectron->SetE33(lazyTools.e3x3(*(iM->superCluster()->seed())));
|
161 |
|
|
outElectron->SetE55(lazyTools.e5x5(*(iM->superCluster()->seed())));
|
162 |
|
|
std::vector<float> vCov = lazyTools.covariances(*(iM->superCluster()->seed()));
|
163 |
sixie |
1.12 |
outElectron->SetCovEtaEta(vCov[0]);
|
164 |
|
|
outElectron->SetCovEtaPhi(vCov[1]);
|
165 |
|
|
outElectron->SetCovPhiPhi(vCov[2]);
|
166 |
peveraer |
1.22 |
std::vector<float> vCov2 = lazyTools.localCovariances(*(iM->superCluster()->seed()));
|
167 |
|
|
outElectron->SetCoviEtaiEta(vCov2[0]);
|
168 |
sixie |
1.12 |
|
169 |
loizides |
1.29 |
// compute isolations
|
170 |
|
|
// get the barrel BasicClusters
|
171 |
sixie |
1.12 |
edm::Handle<reco::BasicClusterCollection> barrelBasicClusterHandle;
|
172 |
|
|
GetProduct(barrelBasicClusterName_, barrelBasicClusterHandle, event);
|
173 |
sixie |
1.11 |
const reco::BasicClusterCollection* barrelBasicClusters = barrelBasicClusterHandle.product();
|
174 |
|
|
|
175 |
loizides |
1.29 |
// get the endcap BasicClusters
|
176 |
sixie |
1.11 |
edm::Handle<reco::BasicClusterCollection> endcapBasicClusterHandle;
|
177 |
sixie |
1.12 |
GetProduct(endcapBasicClusterName_, endcapBasicClusterHandle, event);
|
178 |
sixie |
1.11 |
const reco::BasicClusterCollection* endcapBasicClusters = endcapBasicClusterHandle.product();
|
179 |
|
|
|
180 |
loizides |
1.29 |
// get the barrel SuperClusters
|
181 |
sixie |
1.12 |
edm::Handle<reco::SuperClusterCollection> barrelSuperClusterHandle;
|
182 |
|
|
GetProduct(barrelSuperClusterName_, barrelSuperClusterHandle, event);
|
183 |
|
|
const reco::SuperClusterCollection* barrelSuperClusters = barrelSuperClusterHandle.product();
|
184 |
|
|
|
185 |
loizides |
1.29 |
// get the endcap SuperClusters
|
186 |
sixie |
1.12 |
edm::Handle<reco::SuperClusterCollection> endcapSuperClusterHandle;
|
187 |
|
|
GetProduct(endcapSuperClusterName_, endcapSuperClusterHandle, event);
|
188 |
|
|
const reco::SuperClusterCollection* endcapSuperClusters = endcapSuperClusterHandle.product();
|
189 |
|
|
|
190 |
loizides |
1.29 |
// find out whether this electron super cluster is in the barrel or endcap
|
191 |
sixie |
1.12 |
bool isBarrel=false ;
|
192 |
|
|
if(barrelSuperClusterMap_->HasMit(iM->superCluster()))
|
193 |
|
|
isBarrel = true;
|
194 |
|
|
|
195 |
loizides |
1.29 |
// compute ECAL isolation
|
196 |
sixie |
1.11 |
double extRadius = 0.3;
|
197 |
|
|
double etLow = 0.0;
|
198 |
bendavid |
1.23 |
double ecalIsoValue = 0.0;
|
199 |
sixie |
1.12 |
if (!isBarrel) {
|
200 |
bendavid |
1.23 |
EgammaEcalIsolation myEcalIsolation(extRadius,etLow,endcapBasicClusters,endcapSuperClusters);
|
201 |
|
|
ecalIsoValue = myEcalIsolation.getEcalEtSum(&(*iM));
|
202 |
loizides |
1.16 |
} else {
|
203 |
bendavid |
1.23 |
EgammaEcalIsolation myEcalIsolation(extRadius,etLow,barrelBasicClusters,barrelSuperClusters);
|
204 |
|
|
ecalIsoValue = myEcalIsolation.getEcalEtSum(&(*iM));
|
205 |
sixie |
1.12 |
}
|
206 |
|
|
|
207 |
loizides |
1.29 |
// compute CaloTower isolation
|
208 |
sixie |
1.14 |
edm::Handle<CaloTowerCollection> caloTowers;
|
209 |
loizides |
1.16 |
GetProduct(isoCaloTowerColName_, caloTowers, event);
|
210 |
sixie |
1.14 |
extRadius = 0.3;
|
211 |
loizides |
1.16 |
etLow = 0.0;
|
212 |
sixie |
1.14 |
double intRadius = 0.02;
|
213 |
bendavid |
1.25 |
//int hcalDepth = -1; //-1 means we take all depths.
|
214 |
sixie |
1.14 |
EgammaTowerIsolation *myTowerIsolation =
|
215 |
bendavid |
1.25 |
new EgammaTowerIsolation (extRadius, intRadius, etLow, caloTowers.product());
|
216 |
sixie |
1.14 |
double towerIsoValue = myTowerIsolation->getTowerEtSum(&(*iM));
|
217 |
loizides |
1.29 |
outElectron->SetCaloTowerIsolation(towerIsoValue);
|
218 |
peveraer |
1.17 |
|
219 |
loizides |
1.29 |
// fill the isolation values
|
220 |
|
|
outElectron->SetCaloIsolation(ecalIsoValue) ;
|
221 |
peveraer |
1.17 |
|
222 |
loizides |
1.29 |
// get and fill Track isolation
|
223 |
peveraer |
1.17 |
Handle<edm::ValueMap<double> > eleIsoFromDepsTkValueMap;
|
224 |
|
|
GetProduct(trackerIsoName_, eleIsoFromDepsTkValueMap, event);
|
225 |
|
|
outElectron->SetTrackIsolation((*eleIsoFromDepsTkValueMap)[eRef]);
|
226 |
sixie |
1.11 |
|
227 |
loizides |
1.29 |
// get and fill Jurassic isolation values
|
228 |
sixie |
1.15 |
Handle<edm::ValueMap<double> > eleIsoFromDepsEcalFromHitsValueMap;
|
229 |
loizides |
1.16 |
GetProduct(ecalJurassicIsoName_, eleIsoFromDepsEcalFromHitsValueMap, event);
|
230 |
sixie |
1.15 |
Handle<edm::ValueMap<double> > eleIsoFromDepsHcalFromHitsValueMap;
|
231 |
loizides |
1.16 |
GetProduct(hcalJurassicIsoName_, eleIsoFromDepsHcalFromHitsValueMap, event);
|
232 |
sixie |
1.15 |
|
233 |
loizides |
1.27 |
outElectron->SetEcalJurassicIso((*eleIsoFromDepsEcalFromHitsValueMap)[eRef]);
|
234 |
loizides |
1.24 |
outElectron->SetHcalIsolation((*eleIsoFromDepsHcalFromHitsValueMap)[eRef]);
|
235 |
sixie |
1.15 |
|
236 |
loizides |
1.29 |
// make proper links to Tracks and Super Clusters
|
237 |
loizides |
1.1 |
if (gsfTrackMap_ && iM->gsfTrack().isNonnull())
|
238 |
bendavid |
1.18 |
outElectron->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iM->gsfTrack())));
|
239 |
loizides |
1.29 |
// make tracker track links, relinking from gsf track associations if configured and
|
240 |
|
|
// link is otherwise absent
|
241 |
bendavid |
1.19 |
if (trackerTrackMap_) {
|
242 |
|
|
if (iM->track().isNonnull())
|
243 |
|
|
outElectron->SetTrackerTrk(trackerTrackMap_->GetMit(refToPtr(iM->track())));
|
244 |
|
|
else if (!gsfTrackAssocName_.empty() && iM->gsfTrack().isNonnull()) {
|
245 |
|
|
reco::TrackBaseRef gsfRef(iM->gsfTrack());
|
246 |
|
|
std::vector<std::pair<reco::TrackBaseRef, double> > matchedTracks;
|
247 |
|
|
try {
|
248 |
|
|
matchedTracks = gsfAssociation[gsfRef];
|
249 |
|
|
}
|
250 |
|
|
catch (edm::Exception &ex) {
|
251 |
|
|
}
|
252 |
loizides |
1.29 |
// take the best match, but only if more than 50% of the hits came
|
253 |
|
|
// from the original gsf track
|
254 |
bendavid |
1.19 |
reco::TrackBaseRef trackerRef;
|
255 |
|
|
double rMax = 0.0;
|
256 |
bendavid |
1.20 |
for (uint imatch=0; imatch<matchedTracks.size(); ++imatch) {
|
257 |
bendavid |
1.19 |
std::pair<reco::TrackBaseRef, double> &match = matchedTracks.at(imatch);
|
258 |
|
|
double r = match.second;
|
259 |
loizides |
1.29 |
if (r>rMax && r>0.5) {
|
260 |
bendavid |
1.19 |
rMax = r;
|
261 |
|
|
trackerRef = match.first;
|
262 |
|
|
}
|
263 |
|
|
}
|
264 |
|
|
if (trackerRef.isNonnull())
|
265 |
|
|
outElectron->SetTrackerTrk(trackerTrackMap_->GetMit(mitedm::refToBaseToPtr(trackerRef)));
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
sixie |
1.12 |
if (barrelSuperClusterMap_ && endcapSuperClusterMap_ && iM->superCluster().isNonnull())
|
269 |
|
|
if(isBarrel) {
|
270 |
|
|
outElectron->SetSuperCluster(barrelSuperClusterMap_->GetMit(iM->superCluster()));
|
271 |
|
|
} else {
|
272 |
|
|
outElectron->SetSuperCluster(endcapSuperClusterMap_->GetMit(iM->superCluster()));
|
273 |
|
|
}
|
274 |
sixie |
1.13 |
|
275 |
loizides |
1.29 |
// fill Electron ID information
|
276 |
sixie |
1.13 |
outElectron->SetPassLooseID((*eidLooseMap)[eRef]);
|
277 |
|
|
outElectron->SetPassTightID((*eidTightMap)[eRef]);
|
278 |
|
|
outElectron->SetIDLikelihood((*eidLikelihoodMap)[eRef]);
|
279 |
sixie |
1.12 |
}
|
280 |
loizides |
1.1 |
electrons_->Trim();
|
281 |
|
|
}
|