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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
//
//
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonSelectors.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/Common/interface/RefToPtr.h"
#include <limits>
using namespace pat;
/// default constructor
Muon::Muon()
: Lepton<reco::Muon>(),
embeddedMuonBestTrack_(false),
embeddedTunePMuonBestTrack_(false),
embeddedTrack_(false),
embeddedStandAloneMuon_(false),
embeddedCombinedMuon_(false),
embeddedTCMETMuonCorrs_(false),
embeddedCaloMETMuonCorrs_(false),
embeddedPickyMuon_(false),
embeddedTpfmsMuon_(false),
embeddedDytMuon_(false),
embeddedPFCandidate_(false),
pfCandidateRef_(),
cachedNormChi2_(false),
normChi2_(0.0),
cachedNumberOfValidHits_(false),
numberOfValidHits_(0),
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
inverseBetaErr_(0) {
initImpactParameters();
initSimInfo();
}
/// constructor from reco::Muon
Muon::Muon(const reco::Muon& aMuon)
: Lepton<reco::Muon>(aMuon),
embeddedMuonBestTrack_(false),
embeddedTunePMuonBestTrack_(false),
embeddedTrack_(false),
embeddedStandAloneMuon_(false),
embeddedCombinedMuon_(false),
embeddedTCMETMuonCorrs_(false),
embeddedCaloMETMuonCorrs_(false),
embeddedPickyMuon_(false),
embeddedTpfmsMuon_(false),
embeddedDytMuon_(false),
embeddedPFCandidate_(false),
pfCandidateRef_(),
cachedNormChi2_(false),
normChi2_(0.0),
cachedNumberOfValidHits_(false),
numberOfValidHits_(0),
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
inverseBetaErr_(0) {
initImpactParameters();
initSimInfo();
}
/// constructor from ref to reco::Muon
Muon::Muon(const edm::RefToBase<reco::Muon>& aMuonRef)
: Lepton<reco::Muon>(aMuonRef),
embeddedMuonBestTrack_(false),
embeddedTunePMuonBestTrack_(false),
embeddedTrack_(false),
embeddedStandAloneMuon_(false),
embeddedCombinedMuon_(false),
embeddedTCMETMuonCorrs_(false),
embeddedCaloMETMuonCorrs_(false),
embeddedPickyMuon_(false),
embeddedTpfmsMuon_(false),
embeddedDytMuon_(false),
embeddedPFCandidate_(false),
pfCandidateRef_(),
cachedNormChi2_(false),
normChi2_(0.0),
cachedNumberOfValidHits_(false),
numberOfValidHits_(0),
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
inverseBetaErr_(0) {
initImpactParameters();
initSimInfo();
}
/// constructor from ref to reco::Muon
Muon::Muon(const edm::Ptr<reco::Muon>& aMuonRef)
: Lepton<reco::Muon>(aMuonRef),
embeddedMuonBestTrack_(false),
embeddedTunePMuonBestTrack_(false),
embeddedTrack_(false),
embeddedStandAloneMuon_(false),
embeddedCombinedMuon_(false),
embeddedTCMETMuonCorrs_(false),
embeddedCaloMETMuonCorrs_(false),
embeddedPickyMuon_(false),
embeddedTpfmsMuon_(false),
embeddedDytMuon_(false),
embeddedPFCandidate_(false),
pfCandidateRef_(),
cachedNormChi2_(false),
normChi2_(0.0),
cachedNumberOfValidHits_(false),
numberOfValidHits_(0),
pfEcalEnergy_(0),
jetPtRatio_(0),
jetPtRel_(0),
mvaIDValue_(0),
softMvaValue_(0),
inverseBeta_(0),
inverseBetaErr_(0) {
initImpactParameters();
initSimInfo();
}
/// destructor
Muon::~Muon() {}
std::ostream& reco::operator<<(std::ostream& out, const pat::Muon& obj) {
if (!out)
return out;
out << "\tpat::Muon: ";
out << std::setiosflags(std::ios::right);
out << std::setiosflags(std::ios::fixed);
out << std::setprecision(3);
out << " E/pT/eta/phi " << obj.energy() << "/" << obj.pt() << "/" << obj.eta() << "/" << obj.phi();
return out;
}
// initialize impact parameter container vars
void Muon::initImpactParameters() {
std::fill(ip_, ip_ + IpTypeSize, 0.0f);
std::fill(eip_, eip_ + IpTypeSize, 0.0f);
cachedIP_ = 0;
}
// initialize impact parameter container vars
void Muon::initSimInfo() {
simType_ = reco::MuonSimType::Unknown;
simExtType_ = reco::ExtendedMuonSimType::ExtUnknown;
simFlavour_ = 0;
simHeaviestMotherFlavour_ = 0;
simPdgId_ = 0;
simMotherPdgId_ = 0;
simBX_ = 999;
simTpEvent_ = 0;
simProdRho_ = 0.0;
simProdZ_ = 0.0;
simPt_ = 0.0;
simEta_ = 0.0;
simPhi_ = 0.0;
simMatchQuality_ = 0.0;
}
/// reference to Track reconstructed in the tracker only (reimplemented from reco::Muon)
reco::TrackRef Muon::track() const {
if (embeddedTrack_) {
return reco::TrackRef(&track_, 0);
} else {
return reco::Muon::innerTrack();
}
}
/// reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon)
reco::TrackRef Muon::standAloneMuon() const {
if (embeddedStandAloneMuon_) {
return reco::TrackRef(&standAloneMuon_, 0);
} else {
return reco::Muon::outerTrack();
}
}
/// reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon)
reco::TrackRef Muon::combinedMuon() const {
if (embeddedCombinedMuon_) {
return reco::TrackRef(&combinedMuon_, 0);
} else {
return reco::Muon::globalTrack();
}
}
/// reference to Track reconstructed using hits in the tracker + "good" muon hits
reco::TrackRef Muon::pickyTrack() const {
if (embeddedPickyMuon_) {
return reco::TrackRef(&pickyMuon_, 0);
} else {
return reco::Muon::pickyTrack();
}
}
/// reference to Track reconstructed using hits in the tracker + info from the first muon station that has hits
reco::TrackRef Muon::tpfmsTrack() const {
if (embeddedTpfmsMuon_) {
return reco::TrackRef(&tpfmsMuon_, 0);
} else {
return reco::Muon::tpfmsTrack();
}
}
/// reference to Track reconstructed using hits in the tracker + info from the first muon station that has hits
reco::TrackRef Muon::dytTrack() const {
if (embeddedDytMuon_) {
return reco::TrackRef(&dytMuon_, 0);
} else {
return reco::Muon::dytTrack();
}
}
/// reference to Track giving best momentum (global PFlow algo)
reco::TrackRef Muon::muonBestTrack() const {
if (!muonBestTrack_.empty()) {
return reco::TrackRef(&muonBestTrack_, 0);
} else {
return reco::Muon::muonBestTrack();
}
}
/// reference to Track giving best momentum (muon only)
reco::TrackRef Muon::tunePMuonBestTrack() const {
if (!tunePMuonBestTrack_.empty()) {
return reco::TrackRef(&tunePMuonBestTrack_, 0);
} else if (muonBestTrackType() == tunePMuonBestTrackType()) {
return muonBestTrack();
} else {
return reco::Muon::tunePMuonBestTrack();
}
}
/// reference to the source IsolatedPFCandidates
reco::PFCandidateRef Muon::pfCandidateRef() const {
if (embeddedPFCandidate_) {
return reco::PFCandidateRef(&pfCandidate_, 0);
} else {
return pfCandidateRef_;
}
}
/// reference to the parent PF candidate for use in TopProjector
reco::CandidatePtr Muon::sourceCandidatePtr(size_type i) const {
if (pfCandidateRef_.isNonnull() && i == 0)
return reco::CandidatePtr(edm::refToPtr(pfCandidateRef_));
if (refToOrig_.isNonnull() && pfCandidateRef_.isNonnull() && i == 1)
return refToOrig_;
if (refToOrig_.isNonnull() && !pfCandidateRef_.isNonnull() && i == 0)
return refToOrig_;
return reco::CandidatePtr();
}
/// embed the Track selected to be the best measurement of the muon parameters
void Muon::embedMuonBestTrack(bool force) {
muonBestTrack_.clear();
embeddedMuonBestTrack_ = false;
bool alreadyEmbedded = false;
if (!force) {
switch (muonBestTrackType()) {
case None:
alreadyEmbedded = true;
break;
case InnerTrack:
if (embeddedTrack_)
alreadyEmbedded = true;
break;
case OuterTrack:
if (embeddedStandAloneMuon_)
alreadyEmbedded = true;
break;
case CombinedTrack:
if (embeddedCombinedMuon_)
alreadyEmbedded = true;
break;
case TPFMS:
if (embeddedTpfmsMuon_)
alreadyEmbedded = true;
break;
case Picky:
if (embeddedPickyMuon_)
alreadyEmbedded = true;
break;
case DYT:
if (embeddedDytMuon_)
alreadyEmbedded = true;
break;
}
}
if (force || !alreadyEmbedded) {
muonBestTrack_.push_back(*reco::Muon::muonBestTrack());
embeddedMuonBestTrack_ = true;
}
}
/// embed the Track selected to be the best measurement of the muon parameters
void Muon::embedTunePMuonBestTrack(bool force) {
tunePMuonBestTrack_.clear();
bool alreadyEmbedded = false;
embeddedTunePMuonBestTrack_ = false;
if (!force) {
switch (tunePMuonBestTrackType()) {
case None:
alreadyEmbedded = true;
break;
case InnerTrack:
if (embeddedTrack_)
alreadyEmbedded = true;
break;
case OuterTrack:
if (embeddedStandAloneMuon_)
alreadyEmbedded = true;
break;
case CombinedTrack:
if (embeddedCombinedMuon_)
alreadyEmbedded = true;
break;
case TPFMS:
if (embeddedTpfmsMuon_)
alreadyEmbedded = true;
break;
case Picky:
if (embeddedPickyMuon_)
alreadyEmbedded = true;
break;
case DYT:
if (embeddedDytMuon_)
alreadyEmbedded = true;
break;
}
if (muonBestTrackType() == tunePMuonBestTrackType()) {
if (embeddedMuonBestTrack_)
alreadyEmbedded = true;
}
}
if (force || !alreadyEmbedded) {
tunePMuonBestTrack_.push_back(*reco::Muon::tunePMuonBestTrack());
embeddedTunePMuonBestTrack_ = true;
}
}
/// embed the Track reconstructed in the tracker only
void Muon::embedTrack() {
track_.clear();
if (reco::Muon::innerTrack().isNonnull()) {
track_.push_back(*reco::Muon::innerTrack());
embeddedTrack_ = true;
}
}
/// embed the Track reconstructed in the muon detector only
void Muon::embedStandAloneMuon() {
standAloneMuon_.clear();
if (reco::Muon::outerTrack().isNonnull()) {
standAloneMuon_.push_back(*reco::Muon::outerTrack());
embeddedStandAloneMuon_ = true;
}
}
/// embed the Track reconstructed in both tracked and muon detector
void Muon::embedCombinedMuon() {
combinedMuon_.clear();
if (reco::Muon::globalTrack().isNonnull()) {
combinedMuon_.push_back(*reco::Muon::globalTrack());
embeddedCombinedMuon_ = true;
}
}
// recursively look for reassociated TrackExtraRefs in the edm::Associations and rekey
void Muon::rekeyEmbeddedTracks(std::vector<edm::Handle<edm::Association<reco::TrackExtraCollection>>> const& assocs) {
auto rekey = [&assocs](reco::Track& track) {
reco::TrackExtraRef trackExtra = track.extra();
for (auto const& assoc : assocs) {
if (!assoc->contains(trackExtra.id())) {
continue;
}
reco::TrackExtraRef const& trackExtraOut = (*assoc)[trackExtra];
if (trackExtraOut.isNonnull()) {
trackExtra = trackExtraOut;
}
}
track.setExtra(trackExtra);
};
for (reco::Track& track : muonBestTrack_) {
rekey(track);
}
for (reco::Track& track : tunePMuonBestTrack_) {
rekey(track);
}
for (reco::Track& track : track_) {
rekey(track);
}
for (reco::Track& track : standAloneMuon_) {
rekey(track);
}
for (reco::Track& track : combinedMuon_) {
rekey(track);
}
for (reco::Track& track : pickyMuon_) {
rekey(track);
}
for (reco::Track& track : tpfmsMuon_) {
rekey(track);
}
for (reco::Track& track : dytMuon_) {
rekey(track);
}
}
/// embed the MuonMETCorrectionData for muon corrected caloMET
void Muon::embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
caloMETMuonCorrs_.clear();
caloMETMuonCorrs_.push_back(t);
embeddedCaloMETMuonCorrs_ = true;
}
/// embed the MuonMETCorrectionData for tcMET
void Muon::embedTcMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
tcMETMuonCorrs_.clear();
tcMETMuonCorrs_.push_back(t);
embeddedTCMETMuonCorrs_ = true;
}
/// embed the picky Track
void Muon::embedPickyMuon() {
pickyMuon_.clear();
reco::TrackRef tk = reco::Muon::pickyTrack();
if (tk.isNonnull()) {
pickyMuon_.push_back(*tk);
embeddedPickyMuon_ = true;
}
}
/// embed the tpfms Track
void Muon::embedTpfmsMuon() {
tpfmsMuon_.clear();
reco::TrackRef tk = reco::Muon::tpfmsTrack();
if (tk.isNonnull()) {
tpfmsMuon_.push_back(*tk);
embeddedTpfmsMuon_ = true;
}
}
/// embed the dyt Track
void Muon::embedDytMuon() {
dytMuon_.clear();
reco::TrackRef tk = reco::Muon::dytTrack();
if (tk.isNonnull()) {
dytMuon_.push_back(*tk);
embeddedDytMuon_ = true;
}
}
/// Add extra timing information
void Muon::readTimeExtra(const reco::MuonTimeExtra& t) {
inverseBeta_ = t.inverseBeta();
inverseBetaErr_ = t.inverseBetaErr();
}
/// embed the IsolatedPFCandidate pointed to by pfCandidateRef_
void Muon::embedPFCandidate() {
pfCandidate_.clear();
if (pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
pfCandidate_.push_back(*pfCandidateRef_);
embeddedPFCandidate_ = true;
}
}
bool Muon::muonID(const std::string& name) const {
muon::SelectionType st = muon::selectionTypeFromString(name);
return muon::isGoodMuon(*this, st);
}
/// Norm chi2 gives the normalized chi2 of the global track.
/// The user can choose to cache this info so they can drop the
/// global track, or they can use the track itself if it is present
/// in the event.
double Muon::normChi2() const {
if (cachedNormChi2_) {
return normChi2_;
} else {
reco::TrackRef t = globalTrack();
return t->chi2() / t->ndof();
}
}
/// numberOfValidHits returns the number of valid hits on the global track.
/// The user can choose to cache this info so they can drop the
/// global track, or they can use the track itself if it is present
/// in the event.
unsigned int Muon::numberOfValidHits() const {
if (cachedNumberOfValidHits_) {
return numberOfValidHits_;
} else {
reco::TrackRef t = innerTrack();
return t->numberOfValidHits();
}
}
// embed various impact parameters with errors
// IpType defines the type of the impact parameter
double Muon::dB(IpType type_) const {
// more IP types (new)
if (cachedIP_ & (1 << int(type_))) {
return ip_[type_];
} else {
return std::numeric_limits<double>::max();
}
}
// embed various impact parameters with errors
// IpType defines the type of the impact parameter
double Muon::edB(IpType type_) const {
// more IP types (new)
if (cachedIP_ & (1 << int(type_))) {
return eip_[type_];
} else {
return std::numeric_limits<double>::max();
}
}
double Muon::segmentCompatibility(reco::Muon::ArbitrationType arbitrationType) const {
return muon::segmentCompatibility(*this, arbitrationType);
}
// Selectors
bool Muon::isTightMuon(const reco::Vertex& vtx) const { return muon::isTightMuon(*this, vtx); }
bool Muon::isLooseMuon() const { return muon::isLooseMuon(*this); }
bool Muon::isMediumMuon() const { return muon::isMediumMuon(*this); }
bool Muon::isSoftMuon(const reco::Vertex& vtx) const { return muon::isSoftMuon(*this, vtx); }
bool Muon::isHighPtMuon(const reco::Vertex& vtx) const { return muon::isHighPtMuon(*this, vtx); }
|