1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
#include "CommonTools/Egamma/interface/ConversionTools.h"
#include "DataFormats/EgammaCandidates/interface/Conversion.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/Common/interface/RefToPtr.h"
#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/Math/interface/deltaR.h"
#include <TMath.h>
using namespace edm;
using namespace reco;
//--------------------------------------------------------------------------------------------------
bool ConversionTools::isGoodConversion(const Conversion &conv,
const math::XYZPoint &beamspot,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//Check if a given conversion candidate passes the conversion selection cuts
const reco::Vertex &vtx = conv.conversionVertex();
//vertex validity
if (!vtx.isValid())
return false;
//fit probability
if (TMath::Prob(vtx.chi2(), vtx.ndof()) < probMin)
return false;
//compute transverse decay length
math::XYZVector mom(conv.refittedPairMomentum());
double dbsx = vtx.x() - beamspot.x();
double dbsy = vtx.y() - beamspot.y();
double lxy = (mom.x() * dbsx + mom.y() * dbsy) / mom.rho();
//transverse decay length
if (lxy < lxyMin)
return false;
//loop through daughters to check nhitsbeforevtx
for (std::vector<uint8_t>::const_iterator it = conv.nHitsBeforeVtx().begin(); it != conv.nHitsBeforeVtx().end();
++it) {
if ((*it) > nHitsBeforeVtxMax)
return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(const reco::GsfElectron &ele,
const reco::Conversion &conv,
bool allowCkfMatch,
bool allowAmbiguousGsfMatch) {
//check if a given GsfElectron matches a given conversion (no quality cuts applied)
//matching is always attempted through the gsf track ref, and optionally attempted through the
//closest ctf track ref
const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
++it) {
if (ele.reco::GsfElectron::gsfTrack().isNonnull() && ele.reco::GsfElectron::gsfTrack().id() == it->id() &&
ele.reco::GsfElectron::gsfTrack().key() == it->key())
return true;
else if (allowCkfMatch && ele.reco::GsfElectron::closestCtfTrackRef().isNonnull() &&
ele.reco::GsfElectron::closestCtfTrackRef().id() == it->id() &&
ele.reco::GsfElectron::closestCtfTrackRef().key() == it->key())
return true;
if (allowAmbiguousGsfMatch) {
for (auto const &tk : ele.ambiguousGsfTracks()) {
if (tk.isNonnull() && tk.id() == it->id() && tk.key() == it->key())
return true;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(const reco::GsfElectronCore &eleCore,
const reco::Conversion &conv,
bool allowCkfMatch) {
//check if a given GsfElectronCore matches a given conversion (no quality cuts applied)
//matching is always attempted through the gsf track ref, and optionally attempted through the
//closest ctf track ref
for (const auto &trkRef : conv.tracks()) {
if (eleCore.gsfTrack().isNonnull() && eleCore.gsfTrack().id() == trkRef.id() &&
eleCore.gsfTrack().key() == trkRef.key())
return true;
else if (allowCkfMatch && eleCore.ctfTrack().isNonnull() && eleCore.ctfTrack().id() == trkRef.id() &&
eleCore.ctfTrack().key() == trkRef.key())
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(
const reco::SuperCluster &sc, const reco::Conversion &conv, float dRMax, float dEtaMax, float dPhiMax) {
//check if a given SuperCluster matches a given conversion (no quality cuts applied)
//matching is geometric between conversion momentum and vector joining conversion vertex
//to supercluster position
math::XYZVector mom(conv.refittedPairMomentum());
const math::XYZPoint &scpos(sc.position());
math::XYZPoint cvtx(conv.conversionVertex().position());
math::XYZVector cscvector = scpos - cvtx;
float dR = reco::deltaR(mom, cscvector);
float dEta = mom.eta() - cscvector.eta();
float dPhi = reco::deltaPhi(mom.phi(), cscvector.phi());
if (dR > dRMax)
return false;
if (dEta > dEtaMax)
return false;
if (dPhi > dPhiMax)
return false;
return true;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(const edm::RefToBase<reco::Track> &trk, const reco::Conversion &conv) {
//check if given track matches given conversion (matching by ref)
if (trk.isNull())
return false;
const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
++it) {
if (trk.id() == it->id() && trk.key() == it->key())
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(const reco::TrackRef &trk, const reco::Conversion &conv) {
//check if given track matches given conversion (matching by ref)
if (trk.isNull())
return false;
const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
++it) {
if (trk.id() == it->id() && trk.key() == it->key())
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::matchesConversion(const reco::GsfTrackRef &trk, const reco::Conversion &conv) {
//check if given track matches given conversion (matching by ref)
if (trk.isNull())
return false;
const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
++it) {
if (trk.id() == it->id() && trk.key() == it->key())
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::hasMatchedConversion(const reco::GsfElectron &ele,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
bool allowCkfMatch,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given electron candidate matches to at least one conversion candidate in the
//collection which also passes the selection cuts, optionally match with the closestckf track in
//in addition to just the gsf track (enabled in default arguments)
for (auto const &it : convCol) {
if (!matchesConversion(ele, it, allowCkfMatch))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::hasMatchedConversion(const reco::TrackRef &trk,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given track matches to at least one conversion candidate in the
//collection which also passes the selection cuts
if (trk.isNull())
return false;
for (auto const &it : convCol) {
if (!matchesConversion(trk, it))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::hasMatchedConversion(const reco::SuperCluster &sc,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
float dRMax,
float dEtaMax,
float dPhiMax,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given SuperCluster matches to at least one conversion candidate in the
//collection which also passes the selection cuts
for (auto const &it : convCol) {
if (!matchesConversion(sc, it))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
reco::Conversion const *ConversionTools::matchedConversion(const reco::GsfElectron &ele,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
bool allowCkfMatch,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given electron candidate matches to at least one conversion candidate in the
//collection which also passes the selection cuts, optionally match with the closestckf track in
//in addition to just the gsf track (enabled in default arguments)
//If multiple conversions are found, returned reference corresponds to minimum
//conversion radius
reco::Conversion const *match = nullptr;
double minRho = 999.;
for (auto const &it : convCol) {
float rho = it.conversionVertex().position().rho();
if (rho > minRho)
continue;
if (!matchesConversion(ele, it, allowCkfMatch))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
minRho = rho;
match = ⁢
}
return match;
}
//--------------------------------------------------------------------------------------------------
reco::Conversion const *ConversionTools::matchedConversion(const reco::GsfElectronCore &eleCore,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
bool allowCkfMatch,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given electron candidate matches to at least one conversion candidate in the
//collection which also passes the selection cuts, optionally match with the closestckf track in
//in addition to just the gsf track (enabled in default arguments)
//If multiple conversions are found, returned reference corresponds to minimum
//conversion radius
reco::Conversion const *match = nullptr;
double minRho = 999.;
for (auto const &it : convCol) {
float rho = it.conversionVertex().position().rho();
if (rho > minRho)
continue;
if (!matchesConversion(eleCore, it, allowCkfMatch))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
minRho = rho;
match = ⁢
}
return match;
}
//--------------------------------------------------------------------------------------------------
reco::Conversion const *ConversionTools::matchedConversion(const reco::TrackRef &trk,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given track matches to at least one conversion candidate in the
//collection which also passes the selection cuts
//If multiple conversions are found, returned reference corresponds to minimum
//conversion radius
reco::Conversion const *match = nullptr;
if (trk.isNull())
return match;
double minRho = 999.;
for (auto const &it : convCol) {
float rho = it.conversionVertex().position().rho();
if (rho > minRho)
continue;
if (!matchesConversion(trk, it))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
minRho = rho;
match = ⁢
}
return match;
}
//--------------------------------------------------------------------------------------------------
reco::Conversion const *ConversionTools::matchedConversion(const reco::SuperCluster &sc,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
float dRMax,
float dEtaMax,
float dPhiMax,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given SuperCluster matches to at least one conversion candidate in the
//collection which also passes the selection cuts
//If multiple conversions are found, returned reference corresponds to minimum
//conversion radius
reco::Conversion const *match = nullptr;
double minRho = 999.;
for (auto const &it : convCol) {
float rho = it.conversionVertex().position().rho();
if (rho > minRho)
continue;
if (!matchesConversion(sc, it, dRMax, dEtaMax, dPhiMax))
continue;
if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
minRho = rho;
match = ⁢
}
return match;
}
//--------------------------------------------------------------------------------------------------
bool ConversionTools::hasMatchedPromptElectron(const reco::SuperClusterRef &sc,
const reco::GsfElectronCollection &eleCol,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
bool allowCkfMatch,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
return !(matchedPromptElectron(sc, eleCol, convCol, beamspot, allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax) ==
nullptr);
}
//--------------------------------------------------------------------------------------------------
reco::GsfElectron const *ConversionTools::matchedPromptElectron(const reco::SuperClusterRef &sc,
const reco::GsfElectronCollection &eleCol,
const reco::ConversionCollection &convCol,
const math::XYZPoint &beamspot,
bool allowCkfMatch,
float lxyMin,
float probMin,
unsigned int nHitsBeforeVtxMax) {
//check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
//and not matching any conversion in the collection passing the quality cuts
reco::GsfElectron const *match = nullptr;
if (sc.isNull())
return match;
for (auto const &it : eleCol) {
//match electron to supercluster
if (it.superCluster() != sc)
continue;
//check expected inner hits
if (it.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > 0)
continue;
//check if electron is matching to a conversion
if (hasMatchedConversion(it, convCol, beamspot, allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax))
continue;
match = ⁢
}
return match;
}
//--------------------------------------------------------------------------------------------------
float ConversionTools::getVtxFitProb(const reco::Conversion *conv) {
if (conv != nullptr) {
const reco::Vertex &vtx = conv->conversionVertex();
if (vtx.isValid()) {
return TMath::Prob(vtx.chi2(), vtx.ndof());
}
}
return -1;
}
|