1 |
#include "../interface/ElectronAnalyzer.h"
|
2 |
|
3 |
using namespace std;
|
4 |
using namespace reco;
|
5 |
using namespace edm;
|
6 |
|
7 |
ElectronAnalyzer::ElectronAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):LeptonAnalyzer(producersNames, myConfig, verbosity)
|
8 |
{
|
9 |
useMC_ = myConfig.getUntrackedParameter<bool>("doElectronMC");
|
10 |
electronProducer_ = producersNames.getParameter<edm::InputTag>("electronProducer");
|
11 |
}
|
12 |
|
13 |
ElectronAnalyzer::~ElectronAnalyzer()
|
14 |
{
|
15 |
}
|
16 |
|
17 |
bool ElectronAnalyzer::process(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot, TClonesArray* rootElectrons, EcalClusterLazyTools* lazyTools)
|
18 |
{
|
19 |
|
20 |
unsigned int nElectrons=0;
|
21 |
|
22 |
bool doElectronID = true;
|
23 |
edm::Handle < std::vector <reco::GsfElectron> > recoElectrons;
|
24 |
const edm::ValueMap<float> * eidRobustLooseMap = 0;
|
25 |
const edm::ValueMap<float> * eidRobustTightMap = 0;
|
26 |
const edm::ValueMap<float> * eidRobustHighEnergyMap = 0;
|
27 |
const edm::ValueMap<float> * eidLooseMap = 0;
|
28 |
const edm::ValueMap<float> * eidTightMap = 0;
|
29 |
if( dataType_=="RECO" )
|
30 |
{
|
31 |
try
|
32 |
{
|
33 |
iEvent.getByLabel(electronProducer_, recoElectrons);
|
34 |
nElectrons = recoElectrons->size();
|
35 |
}
|
36 |
catch (cms::Exception& exception)
|
37 |
{
|
38 |
if ( !allowMissingCollection_ )
|
39 |
{
|
40 |
cout << " ##### ERROR IN ElectronAnalyzer::process => reco::GsfElectron collection is missing #####"<<endl;
|
41 |
throw exception;
|
42 |
}
|
43 |
if(verbosity_>1) cout << " ===> No reco::GsfElectron collection, skip electrons info" << endl;
|
44 |
return false;
|
45 |
}
|
46 |
|
47 |
// Electron identification
|
48 |
std::vector<edm::Handle<edm::ValueMap<float> > > electronIDmap(5);
|
49 |
try
|
50 |
{
|
51 |
iEvent.getByLabel( "eidRobustLoose", electronIDmap[0] );
|
52 |
eidRobustLooseMap = electronIDmap[0].product();
|
53 |
iEvent.getByLabel( "eidRobustTight", electronIDmap[1] );
|
54 |
eidRobustTightMap = electronIDmap[1].product();
|
55 |
iEvent.getByLabel( "eidRobustHighEnergy", electronIDmap[2] );
|
56 |
eidRobustHighEnergyMap = electronIDmap[2].product();
|
57 |
iEvent.getByLabel( "eidLoose", electronIDmap[3] );
|
58 |
eidLooseMap = electronIDmap[3].product();
|
59 |
iEvent.getByLabel( "eidTight", electronIDmap[4] );
|
60 |
eidTightMap = electronIDmap[4].product();
|
61 |
}
|
62 |
catch (cms::Exception& exception)
|
63 |
{
|
64 |
if ( !allowMissingCollection_ )
|
65 |
{
|
66 |
cout << " ##### ERROR IN ElectronAnalyzer::process => missing electronID #####"<<endl;
|
67 |
throw exception;
|
68 |
}
|
69 |
if(verbosity_>1) cout << " ===> missing electronID, skip electronID info" << endl;
|
70 |
doElectronID = false;
|
71 |
}
|
72 |
|
73 |
|
74 |
}
|
75 |
|
76 |
edm::Handle < std::vector <pat::Electron> > patElectrons;
|
77 |
if( dataType_=="PAT" )
|
78 |
{
|
79 |
try
|
80 |
{
|
81 |
iEvent.getByLabel(electronProducer_, patElectrons);
|
82 |
nElectrons = patElectrons->size();
|
83 |
}
|
84 |
catch (cms::Exception& exception)
|
85 |
{
|
86 |
if ( !allowMissingCollection_ )
|
87 |
{
|
88 |
cout << " ##### ERROR IN ElectronAnalyzer::process => pat::Electron collection is missing #####"<<endl;
|
89 |
throw exception;
|
90 |
}
|
91 |
if(verbosity_>1) cout << " ===> No pat::Electron collection, skip electrons info" << endl;
|
92 |
return false;
|
93 |
}
|
94 |
}
|
95 |
|
96 |
if(verbosity_>1) std::cout << " Number of electrons = " << nElectrons << " Label: " << electronProducer_.label() << " Instance: " << electronProducer_.instance() << std::endl;
|
97 |
|
98 |
for (unsigned int j=0; j<nElectrons; j++)
|
99 |
{
|
100 |
const reco::GsfElectron* electron = 0;
|
101 |
if( dataType_=="RECO" ) electron = &((*recoElectrons)[j]);
|
102 |
if( dataType_=="PAT" ) electron = (const reco::GsfElectron*) ( & ((*patElectrons)[j]) );
|
103 |
|
104 |
TRootElectron localElectron(
|
105 |
electron->px()
|
106 |
,electron->py()
|
107 |
,electron->pz()
|
108 |
,electron->energy()
|
109 |
,electron->vx()
|
110 |
,electron->vy()
|
111 |
,electron->vz()
|
112 |
,electron->pdgId()
|
113 |
,electron->charge()
|
114 |
);
|
115 |
|
116 |
// Variables from reco::GsfElectron
|
117 |
localElectron.setClassification(electron->classification());
|
118 |
localElectron.setCaloEnergy(electron->ecalEnergy());
|
119 |
localElectron.setCaloEnergyError(electron->ecalEnergyError());
|
120 |
if ( electron->trackMomentumAtVtx().Mag2()>0 ) localElectron.setTrackMomentum(sqrt(electron->trackMomentumAtVtx().Mag2()));
|
121 |
localElectron.setTrackMomentumError(electron->trackMomentumError());
|
122 |
localElectron.setHadOverEm(electron->hadronicOverEm());
|
123 |
localElectron.setDeltaEtaIn(electron->deltaEtaSuperClusterTrackAtVtx());
|
124 |
localElectron.setDeltaPhiIn(electron->deltaPhiSuperClusterTrackAtVtx());
|
125 |
localElectron.setEnergySuperClusterOverPin(electron->eSuperClusterOverP());
|
126 |
localElectron.setDeltaEtaOut(electron->deltaEtaSeedClusterTrackAtCalo());
|
127 |
localElectron.setDeltaPhiOut(electron->deltaPhiSeedClusterTrackAtCalo());
|
128 |
localElectron.setEnergySeedClusterOverPout(electron->eSeedClusterOverPout());
|
129 |
localElectron.setEnergyScaleCorrected(electron->isEnergyScaleCorrected());
|
130 |
localElectron.setMomentumCorrected(electron->isMomentumCorrected());
|
131 |
|
132 |
localElectron.setDr03TkSumPt(electron->dr03TkSumPt());
|
133 |
localElectron.setDr03EcalRecHitSumEt(electron->dr03EcalRecHitSumEt());
|
134 |
localElectron.setDr03HcalDepth1TowerSumEt(electron->dr03HcalDepth1TowerSumEt());
|
135 |
localElectron.setDr03HcalDepth2TowerSumEt(electron->dr03HcalDepth2TowerSumEt());
|
136 |
|
137 |
// Variables from reco::GsfTrack
|
138 |
reco::GsfTrackRef gsfTrack = electron->gsfTrack();
|
139 |
if ( gsfTrack.isNonnull() )
|
140 |
{
|
141 |
const reco::HitPattern& hit = gsfTrack->hitPattern();
|
142 |
localElectron.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
|
143 |
localElectron.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
|
144 |
|
145 |
if (vertexPoint_!=0)
|
146 |
{
|
147 |
const reco::TrackBase::Point point( vertexPoint_->x(), vertexPoint_->y(), vertexPoint_->z() );
|
148 |
localElectron.setD0( -1.*(gsfTrack->dxy(point)) );
|
149 |
localElectron.setDsz( gsfTrack->dsz(point) );
|
150 |
}
|
151 |
else
|
152 |
{
|
153 |
localElectron.setD0( -1.*(gsfTrack->dxy()) );
|
154 |
localElectron.setDsz( gsfTrack->dsz() );
|
155 |
}
|
156 |
|
157 |
// FIXME - Add Vertex error quadratically
|
158 |
localElectron.setD0Error(gsfTrack->d0Error());
|
159 |
localElectron.setDszError(gsfTrack->dszError());
|
160 |
|
161 |
localElectron.setNormalizedChi2(gsfTrack->normalizedChi2());
|
162 |
localElectron.setPtError(gsfTrack->ptError());
|
163 |
localElectron.setEtaError(gsfTrack->etaError());
|
164 |
localElectron.setPhiError(gsfTrack->phiError());
|
165 |
|
166 |
if(doPrimaryVertex_)
|
167 |
{
|
168 |
// FIXME - TSOS not working with gsfTrack ???
|
169 |
//const reco::TransientTrack transtrack = trackBuilder_->build( gsfTrack ) ;
|
170 |
//float sig3d = ip3DSignificance(transtrack);
|
171 |
//localElectron.setIP3DSignificance(sig3d);
|
172 |
}
|
173 |
}
|
174 |
|
175 |
// Variables from reco::SuperCluster
|
176 |
reco::SuperClusterRef superCluster = electron->superCluster();
|
177 |
//const reco::SuperCluster* sc = superCluster.get();
|
178 |
if ( superCluster.isNonnull() )
|
179 |
{
|
180 |
localElectron.setNbClusters(superCluster->clustersSize());
|
181 |
localElectron.setSuperClusterRawEnergy(superCluster->rawEnergy());
|
182 |
localElectron.setPreshowerEnergy(superCluster->preshowerEnergy());
|
183 |
localElectron.setCaloPosition(
|
184 |
superCluster->position().X()
|
185 |
,superCluster->position().Y()
|
186 |
,superCluster->position().Z()
|
187 |
);
|
188 |
|
189 |
// FIXME - associator supercluster <-> electron
|
190 |
//localElectron.setSCRef(superCluster->toto());
|
191 |
}
|
192 |
|
193 |
|
194 |
// Cluster Shape variables
|
195 |
// need reco::SuperCluster and reco::BasicCluster
|
196 |
if ( superCluster.isNonnull() )
|
197 |
{
|
198 |
edm::Ptr<reco::CaloCluster> seedBasicCluster = superCluster->seed();
|
199 |
if ( seedBasicCluster.isNonnull() ) localElectron.setClusterAlgo(seedBasicCluster->algo());
|
200 |
|
201 |
// dR of the cone centered on the reco::GsfElectron and containing all its basic clusters constituents
|
202 |
bool atLeastOneBC = false;
|
203 |
Float_t caloConeSize = 0;
|
204 |
for (reco::CaloCluster_iterator basicCluster = (*superCluster).clustersBegin(); basicCluster != (*superCluster).clustersEnd(); ++basicCluster )
|
205 |
{
|
206 |
atLeastOneBC = true;
|
207 |
Float_t dR = localElectron.DeltaR(TLorentzVector( (*basicCluster)->position().x(), (*basicCluster)->position().y(), (*basicCluster)->position().z(), 0. ) );
|
208 |
if (dR > caloConeSize) caloConeSize = dR;
|
209 |
}
|
210 |
if (! atLeastOneBC) caloConeSize = -999.;
|
211 |
localElectron.setCaloConeSize(caloConeSize);
|
212 |
|
213 |
// need reduced Ecal RecHits Collections for EcalClusterLazyTools
|
214 |
if ( seedBasicCluster.isNonnull() && lazyTools != 0 )
|
215 |
{
|
216 |
localElectron.setE2x2(lazyTools->e2x2(*seedBasicCluster));
|
217 |
localElectron.setE3x3(lazyTools->e3x3(*seedBasicCluster));
|
218 |
localElectron.setE5x5(lazyTools->e5x5(*seedBasicCluster));
|
219 |
localElectron.setEMax(lazyTools->eMax(*seedBasicCluster));
|
220 |
}
|
221 |
}
|
222 |
|
223 |
|
224 |
if( dataType_=="RECO" )
|
225 |
{
|
226 |
// Some specific methods requiring RECO / AOD format
|
227 |
// Do association to genParticle ?
|
228 |
// Isolation ?
|
229 |
|
230 |
// New 2.2.X electron ID
|
231 |
// Only Cut Based ID available by default (4 sequential cuts on H/E, DeltaEta, DeltaPhi, SigmaEtaEta)
|
232 |
// "Robust" ids (eidRobustLoose, eidRobustTight, eidRobustHighEnergy) corresponds to fixed threshold
|
233 |
// eidLoose and eidTight corresponds to the catagory based identification (E/p, fBrem)
|
234 |
if (doElectronID)
|
235 |
{
|
236 |
edm::Ref<reco::GsfElectronCollection> electronRef(recoElectrons,j);
|
237 |
if (eidRobustLooseMap) localElectron.setIDCutBasedFixedThresholdLoose( int( (*eidRobustLooseMap)[electronRef] ) );
|
238 |
if (eidRobustTightMap) localElectron.setIDCutBasedFixedThresholdTight( int( (*eidRobustTightMap)[electronRef] ) );
|
239 |
if (eidRobustHighEnergyMap) localElectron.setIDCutBasedFixedThresholdHighEnergy( int( (*eidRobustHighEnergyMap)[electronRef] ) );
|
240 |
if (eidLooseMap) localElectron.setIDCutBasedCategorizedLoose( int( (*eidLooseMap)[electronRef] ) );
|
241 |
if (eidTightMap) localElectron.setIDCutBasedCategorizedTight( int( (*eidTightMap)[electronRef] ) );
|
242 |
//localElectron.setIDLikelihood();
|
243 |
//localElectron.setIDNeuralNet();
|
244 |
}
|
245 |
// TODO
|
246 |
// Add iso
|
247 |
|
248 |
}
|
249 |
|
250 |
|
251 |
if( dataType_=="PAT" )
|
252 |
{
|
253 |
// Some specific methods to pat::Electron
|
254 |
const pat::Electron *patElectron = dynamic_cast<const pat::Electron*>(&*electron);
|
255 |
|
256 |
// Isolation
|
257 |
pair < Float_t, Int_t > trackerIso;
|
258 |
|
259 |
trackerIso = patElectron->trackIsoDeposit()->depositAndCountWithin(0.1);
|
260 |
localElectron.setIsoR01_sumPt(trackerIso.first);
|
261 |
localElectron.setIsoR01_nTracks(trackerIso.second);
|
262 |
|
263 |
trackerIso = patElectron->trackIsoDeposit()->depositAndCountWithin(0.2);
|
264 |
localElectron.setIsoR02_sumPt(trackerIso.first);
|
265 |
localElectron.setIsoR02_nTracks(trackerIso.second);
|
266 |
|
267 |
trackerIso = patElectron->trackIsoDeposit()->depositAndCountWithin(0.3);
|
268 |
localElectron.setIsoR03_sumPt(trackerIso.first);
|
269 |
localElectron.setIsoR03_nTracks(trackerIso.second);
|
270 |
localElectron.setIsoR03_emEt( patElectron->ecalIsoDeposit()->depositAndCountWithin(0.3).first );
|
271 |
localElectron.setIsoR03_hadEt( patElectron->hcalIsoDeposit()->depositAndCountWithin(0.3).first );
|
272 |
|
273 |
trackerIso = patElectron->trackIsoDeposit()->depositAndCountWithin(0.5);
|
274 |
localElectron.setIsoR05_sumPt(trackerIso.first );
|
275 |
localElectron.setIsoR05_nTracks(trackerIso.second);
|
276 |
localElectron.setIsoR05_emEt( patElectron->ecalIsoDeposit()->depositAndCountWithin(0.5).first );
|
277 |
localElectron.setIsoR05_hadEt( patElectron->hcalIsoDeposit()->depositAndCountWithin(0.5).first );
|
278 |
|
279 |
|
280 |
// Electron ID
|
281 |
|
282 |
// Old 2.1.X electron ID
|
283 |
/*
|
284 |
localElectron.setIDPTDRLoose(patElectron->leptonID("ptdrLoose"));
|
285 |
localElectron.setIDPTDRMedium(patElectron->leptonID("ptdrMedium"));
|
286 |
localElectron.setIDPTDRTight(patElectron->leptonID("ptdrTight"));
|
287 |
localElectron.setIDCutBasedLoose(patElectron->leptonID("loose"));
|
288 |
localElectron.setIDCutBasedRobust(patElectron->leptonID("robust"));
|
289 |
localElectron.setIDCutBasedTight(patElectron->leptonID("tight"));
|
290 |
localElectron.setIDLikelihood(patElectron->leptonID("likelihood"));
|
291 |
localElectron.setIDNeuralNet(patElectron->leptonID("neuralnet"));
|
292 |
*/
|
293 |
|
294 |
// New 2.2.X electron ID
|
295 |
// Only Cut Based ID available by default (4 sequential cuts on H/E, DeltaEta, DeltaPhi, SigmaEtaEta)
|
296 |
// "Robust" ids (eidRobustLoose, eidRobustTight, eidRobustHighEnergy) corresponds to fixed threshold
|
297 |
// eidLoose and eidTight corresponds to the catagory based identification (E/p, fBrem)
|
298 |
if ( patElectron->isElectronIDAvailable("eidRobustLoose") ) localElectron.setIDCutBasedFixedThresholdLoose(int(patElectron->electronID("eidRobustLoose")));
|
299 |
if ( patElectron->isElectronIDAvailable("eidRobustTight") ) localElectron.setIDCutBasedFixedThresholdTight(int(patElectron->electronID("eidRobustTight")));
|
300 |
if ( patElectron->isElectronIDAvailable("eidRobustHighEnergy") ) localElectron.setIDCutBasedFixedThresholdHighEnergy(int(patElectron->electronID("eidRobustHighEnergy")));
|
301 |
if ( patElectron->isElectronIDAvailable("eidLoose") ) localElectron.setIDCutBasedCategorizedLoose(int(patElectron->electronID("eidLoose")));
|
302 |
if ( patElectron->isElectronIDAvailable("eidTight") ) localElectron.setIDCutBasedCategorizedTight(int(patElectron->electronID("eidTight")));
|
303 |
if ( patElectron->isElectronIDAvailable("likelihood") ) localElectron.setIDLikelihood(patElectron->electronID("likelihood"));
|
304 |
if ( patElectron->isElectronIDAvailable("neuralnet") ) localElectron.setIDNeuralNet(patElectron->electronID("neuralnet"));
|
305 |
|
306 |
|
307 |
// Matched genParticle
|
308 |
if(useMC_)
|
309 |
{
|
310 |
// MC truth associator index
|
311 |
if ((patElectron->genParticleRef()).isNonnull()) {
|
312 |
localElectron.setGenParticleIndex((patElectron->genParticleRef()).index());
|
313 |
} else {
|
314 |
localElectron.setGenParticleIndex(-1);
|
315 |
}
|
316 |
}
|
317 |
|
318 |
}
|
319 |
|
320 |
new( (*rootElectrons)[j] ) TRootElectron(localElectron);
|
321 |
if(verbosity_>2) cout << " ["<< setw(3) << j << "] " << localElectron << endl;
|
322 |
}
|
323 |
|
324 |
return true;
|
325 |
}
|