1 |
lethuill |
1.2 |
#include "../interface/ElectronAnalyzer.h"
|
2 |
lethuill |
1.1 |
|
3 |
|
|
using namespace std;
|
4 |
|
|
using namespace reco;
|
5 |
|
|
using namespace edm;
|
6 |
|
|
|
7 |
lethuill |
1.10 |
ElectronAnalyzer::ElectronAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):LeptonAnalyzer(producersNames, myConfig, verbosity)
|
8 |
lethuill |
1.1 |
{
|
9 |
lethuill |
1.10 |
useMC_ = myConfig.getUntrackedParameter<bool>("doElectronMC");
|
10 |
|
|
electronProducer_ = producersNames.getParameter<edm::InputTag>("electronProducer");
|
11 |
lethuill |
1.1 |
}
|
12 |
|
|
|
13 |
|
|
ElectronAnalyzer::~ElectronAnalyzer()
|
14 |
|
|
{
|
15 |
|
|
}
|
16 |
|
|
|
17 |
lethuill |
1.10 |
bool ElectronAnalyzer::process(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot, TClonesArray* rootElectrons, EcalClusterLazyTools* lazyTools)
|
18 |
lethuill |
1.1 |
{
|
19 |
lethuill |
1.10 |
|
20 |
|
|
unsigned int nElectrons=0;
|
21 |
|
|
|
22 |
lethuill |
1.11 |
bool doElectronID = true;
|
23 |
lethuill |
1.10 |
edm::Handle < std::vector <reco::GsfElectron> > recoElectrons;
|
24 |
lethuill |
1.11 |
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 |
lethuill |
1.10 |
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 |
lethuill |
1.11 |
|
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 |
|
|
// FIXME - Robust High Energy electronID not available by default in 2.2.X
|
56 |
|
|
//iEvent.getByLabel( "eidRobustHighEnergy", electronIDmap[2] );
|
57 |
|
|
//eidRobustHighEnergyMap = electronIDmap[2].product();
|
58 |
|
|
iEvent.getByLabel( "eidLoose", electronIDmap[3] );
|
59 |
|
|
eidLooseMap = electronIDmap[3].product();
|
60 |
|
|
iEvent.getByLabel( "eidTight", electronIDmap[4] );
|
61 |
|
|
eidTightMap = electronIDmap[4].product();
|
62 |
|
|
}
|
63 |
|
|
catch (cms::Exception& exception)
|
64 |
|
|
{
|
65 |
|
|
if ( !allowMissingCollection_ )
|
66 |
|
|
{
|
67 |
|
|
cout << " ##### ERROR IN ElectronAnalyzer::process => missing electronID #####"<<endl;
|
68 |
|
|
throw exception;
|
69 |
|
|
}
|
70 |
|
|
if(verbosity_>1) cout << " ===> missing electronID, skip electronID info" << endl;
|
71 |
|
|
doElectronID = false;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
|
75 |
lethuill |
1.10 |
}
|
76 |
|
|
|
77 |
|
|
edm::Handle < std::vector <pat::Electron> > patElectrons;
|
78 |
|
|
if( dataType_=="PAT" )
|
79 |
|
|
{
|
80 |
|
|
try
|
81 |
|
|
{
|
82 |
|
|
iEvent.getByLabel(electronProducer_, patElectrons);
|
83 |
|
|
nElectrons = patElectrons->size();
|
84 |
|
|
}
|
85 |
|
|
catch (cms::Exception& exception)
|
86 |
|
|
{
|
87 |
|
|
if ( !allowMissingCollection_ )
|
88 |
|
|
{
|
89 |
|
|
cout << " ##### ERROR IN ElectronAnalyzer::process => pat::Electron collection is missing #####"<<endl;
|
90 |
|
|
throw exception;
|
91 |
|
|
}
|
92 |
|
|
if(verbosity_>1) cout << " ===> No pat::Electron collection, skip electrons info" << endl;
|
93 |
|
|
return false;
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
if(verbosity_>1) std::cout << " Number of electrons = " << nElectrons << " Label: " << electronProducer_.label() << " Instance: " << electronProducer_.instance() << std::endl;
|
98 |
|
|
|
99 |
|
|
for (unsigned int j=0; j<nElectrons; j++)
|
100 |
|
|
{
|
101 |
|
|
const reco::GsfElectron* electron = 0;
|
102 |
|
|
if( dataType_=="RECO" ) electron = &((*recoElectrons)[j]);
|
103 |
|
|
if( dataType_=="PAT" ) electron = (const reco::GsfElectron*) ( & ((*patElectrons)[j]) );
|
104 |
|
|
|
105 |
|
|
TRootElectron localElectron(
|
106 |
|
|
electron->px()
|
107 |
|
|
,electron->py()
|
108 |
|
|
,electron->pz()
|
109 |
|
|
,electron->energy()
|
110 |
|
|
,electron->vx()
|
111 |
|
|
,electron->vy()
|
112 |
|
|
,electron->vz()
|
113 |
|
|
,electron->pdgId()
|
114 |
|
|
,electron->charge()
|
115 |
|
|
);
|
116 |
|
|
|
117 |
|
|
// Variables from reco::GsfElectron
|
118 |
|
|
localElectron.setClassification(electron->classification());
|
119 |
|
|
localElectron.setCaloEnergy(electron->caloEnergy());
|
120 |
|
|
localElectron.setCaloEnergyError(electron->caloEnergyError());
|
121 |
|
|
if ( electron->trackMomentumAtVtx().Mag2()>0 ) localElectron.setTrackMomentum(sqrt(electron->trackMomentumAtVtx().Mag2()));
|
122 |
|
|
localElectron.setTrackMomentumError(electron->trackMomentumError());
|
123 |
|
|
localElectron.setHadOverEm(electron->hadronicOverEm());
|
124 |
|
|
localElectron.setDeltaEtaIn(electron->deltaEtaSuperClusterTrackAtVtx());
|
125 |
|
|
localElectron.setDeltaPhiIn(electron->deltaPhiSuperClusterTrackAtVtx());
|
126 |
|
|
localElectron.setEnergySuperClusterOverPin(electron->eSuperClusterOverP());
|
127 |
|
|
localElectron.setDeltaEtaOut(electron->deltaEtaSeedClusterTrackAtCalo());
|
128 |
|
|
localElectron.setDeltaPhiOut(electron->deltaPhiSeedClusterTrackAtCalo());
|
129 |
|
|
localElectron.setEnergySeedClusterOverPout(electron->eSeedClusterOverPout());
|
130 |
|
|
localElectron.setEnergyScaleCorrected(electron->isEnergyScaleCorrected());
|
131 |
|
|
localElectron.setMomentumCorrected(electron->isMomentumCorrected());
|
132 |
|
|
|
133 |
|
|
// Variables from reco::GsfTrack
|
134 |
|
|
reco::GsfTrackRef gsfTrack = electron->gsfTrack();
|
135 |
|
|
if ( gsfTrack.isNonnull() )
|
136 |
|
|
{
|
137 |
|
|
const reco::HitPattern& hit = gsfTrack->hitPattern();
|
138 |
|
|
localElectron.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
|
139 |
|
|
localElectron.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
|
140 |
|
|
|
141 |
|
|
if (doBeamSpot_)
|
142 |
|
|
{
|
143 |
|
|
if ( rootBeamSpot->sigmaZ() > 0. ) // Check beam spot was correctly initialised
|
144 |
|
|
{
|
145 |
|
|
const reco::TrackBase::Point point( rootBeamSpot->x(), rootBeamSpot->y(), rootBeamSpot->z() );
|
146 |
|
|
localElectron.setD0( -1.*(gsfTrack->dxy(point)) );
|
147 |
|
|
localElectron.setDsz( gsfTrack->dsz(point) );
|
148 |
|
|
}
|
149 |
|
|
else
|
150 |
|
|
{
|
151 |
|
|
localElectron.setD0( -1.*(gsfTrack->dxy()) );
|
152 |
|
|
localElectron.setDsz( gsfTrack->dsz() );
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
else
|
156 |
|
|
{
|
157 |
|
|
localElectron.setD0( -1.*(gsfTrack->dxy()) );
|
158 |
|
|
localElectron.setDsz( gsfTrack->dsz() );
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
localElectron.setD0Error(gsfTrack->d0Error());
|
162 |
|
|
localElectron.setDszError(gsfTrack->dszError());
|
163 |
|
|
|
164 |
|
|
localElectron.setNormalizedChi2(gsfTrack->normalizedChi2());
|
165 |
|
|
localElectron.setPtError(gsfTrack->ptError());
|
166 |
|
|
localElectron.setEtaError(gsfTrack->etaError());
|
167 |
|
|
localElectron.setPhiError(gsfTrack->phiError());
|
168 |
|
|
|
169 |
|
|
if(doPrimaryVertex_)
|
170 |
|
|
{
|
171 |
|
|
// FIXME - TSOS not working with gsfTrack ???
|
172 |
|
|
//const reco::TransientTrack transtrack = trackBuilder_->build( gsfTrack ) ;
|
173 |
|
|
//float sig3d = ip3DSignificance(transtrack);
|
174 |
|
|
//localElectron.setIP3DSignificance(sig3d);
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
// Variables from reco::SuperCluster
|
179 |
|
|
reco::SuperClusterRef superCluster = electron->superCluster();
|
180 |
|
|
//const reco::SuperCluster* sc = superCluster.get();
|
181 |
|
|
if ( superCluster.isNonnull() )
|
182 |
|
|
{
|
183 |
|
|
localElectron.setNbClusters(superCluster->clustersSize());
|
184 |
|
|
localElectron.setSuperClusterRawEnergy(superCluster->rawEnergy());
|
185 |
|
|
localElectron.setPreshowerEnergy(superCluster->preshowerEnergy());
|
186 |
|
|
localElectron.setCaloPosition(
|
187 |
|
|
superCluster->position().X()
|
188 |
|
|
,superCluster->position().Y()
|
189 |
|
|
,superCluster->position().Z()
|
190 |
|
|
);
|
191 |
|
|
|
192 |
|
|
// FIXME - associator supercluster <-> electron
|
193 |
|
|
//localElectron.setSCRef(superCluster->toto());
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
// Cluster Shape variables
|
198 |
|
|
// need reco::SuperCluster and reco::BasicCluster
|
199 |
|
|
if ( superCluster.isNonnull() )
|
200 |
|
|
{
|
201 |
|
|
reco::BasicClusterRef seedBasicCluster = superCluster->seed();
|
202 |
|
|
if ( seedBasicCluster.isNonnull() ) localElectron.setClusterAlgo(seedBasicCluster->algo());
|
203 |
|
|
|
204 |
|
|
// dR of the cone centered on the reco::GsfElectron and containing all its basic clusters constituents
|
205 |
|
|
bool atLeastOneBC = false;
|
206 |
|
|
Float_t caloConeSize = 0;
|
207 |
|
|
for (reco::basicCluster_iterator basicCluster = (*superCluster).clustersBegin(); basicCluster != (*superCluster).clustersEnd(); ++basicCluster )
|
208 |
|
|
{
|
209 |
|
|
atLeastOneBC = true;
|
210 |
|
|
Float_t dR = localElectron.DeltaR(TLorentzVector( (*basicCluster)->position().x(), (*basicCluster)->position().y(), (*basicCluster)->position().z(), 0. ) );
|
211 |
|
|
if (dR > caloConeSize) caloConeSize = dR;
|
212 |
|
|
}
|
213 |
|
|
if (! atLeastOneBC) caloConeSize = -999.;
|
214 |
|
|
localElectron.setCaloConeSize(caloConeSize);
|
215 |
|
|
|
216 |
|
|
// need reduced Ecal RecHits Collections for EcalClusterLazyTools
|
217 |
|
|
if ( seedBasicCluster.isNonnull() && lazyTools != 0 )
|
218 |
|
|
{
|
219 |
|
|
localElectron.setE2x2(lazyTools->e2x2(*seedBasicCluster));
|
220 |
|
|
localElectron.setE3x3(lazyTools->e3x3(*seedBasicCluster));
|
221 |
|
|
localElectron.setE5x5(lazyTools->e5x5(*seedBasicCluster));
|
222 |
|
|
localElectron.setEMax(lazyTools->eMax(*seedBasicCluster));
|
223 |
|
|
}
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
if( dataType_=="RECO" )
|
228 |
|
|
{
|
229 |
|
|
// Some specific methods requiring RECO / AOD format
|
230 |
|
|
// Do association to genParticle ?
|
231 |
lethuill |
1.11 |
// Isolation ?
|
232 |
lethuill |
1.10 |
|
233 |
lethuill |
1.11 |
// New 2.2.X electron ID
|
234 |
|
|
// Only Cut Based ID available by default (4 sequential cuts on H/E, DeltaEta, DeltaPhi, SigmaEtaEta)
|
235 |
|
|
// "Robust" ids (eidRobustLoose, eidRobustTight, eidRobustHighEnergy) corresponds to fixed threshold
|
236 |
|
|
// eidLoose and eidTight corresponds to the catagory based identification (E/p, fBrem)
|
237 |
|
|
if (doElectronID)
|
238 |
|
|
{
|
239 |
|
|
edm::Ref<reco::GsfElectronCollection> electronRef(recoElectrons,j);
|
240 |
|
|
if (eidRobustLooseMap) localElectron.setIDCutBasedFixedThresholdLoose( int( (*eidRobustLooseMap)[electronRef] ) );
|
241 |
|
|
if (eidRobustTightMap) localElectron.setIDCutBasedFixedThresholdTight( int( (*eidRobustTightMap)[electronRef] ) );
|
242 |
|
|
if (eidRobustHighEnergyMap) localElectron.setIDCutBasedFixedThresholdHighEnergy( int( (*eidRobustHighEnergyMap)[electronRef] ) );
|
243 |
|
|
if (eidLooseMap) localElectron.setIDCutBasedCategorizedLoose( int( (*eidLooseMap)[electronRef] ) );
|
244 |
|
|
if (eidTightMap) localElectron.setIDCutBasedCategorizedTight( int( (*eidTightMap)[electronRef] ) );
|
245 |
|
|
//localElectron.setIDLikelihood();
|
246 |
|
|
//localElectron.setIDNeuralNet();
|
247 |
|
|
}
|
248 |
lethuill |
1.10 |
}
|
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->trackerIsoDeposit()->depositAndCountWithin(0.1);
|
260 |
|
|
localElectron.setIsoR01_sumPt(trackerIso.first);
|
261 |
|
|
localElectron.setIsoR01_nTracks(trackerIso.second);
|
262 |
|
|
|
263 |
|
|
trackerIso = patElectron->trackerIsoDeposit()->depositAndCountWithin(0.2);
|
264 |
|
|
localElectron.setIsoR02_sumPt(trackerIso.first);
|
265 |
|
|
localElectron.setIsoR02_nTracks(trackerIso.second);
|
266 |
|
|
|
267 |
|
|
trackerIso = patElectron->trackerIsoDeposit()->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->trackerIsoDeposit()->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 |
lethuill |
1.11 |
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->leptonID("likelihood"));
|
304 |
|
|
if ( patElectron->isElectronIDAvailable("neuralnet") ) localElectron.setIDNeuralNet(patElectron->leptonID("neuralnet"));
|
305 |
lethuill |
1.10 |
|
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 |
lethuill |
1.1 |
}
|