128 {
129 const EventContext& ctx = Gaudi::Hive::currentContext();
130 SG::ReadHandle<xAOD::EventInfo> eventInfo(
m_eventInfo, ctx);
131
134
135 SG::ReadHandle<xAOD::TruthParticleContainer> TruthMuons(
m_truthMuons, ctx);
136 if (!TruthMuons.isPresent()) {
138 return StatusCode::SUCCESS;
139 }
140 if (!TruthMuons.isValid()) {
142 return StatusCode::FAILURE;
143 }
145 typedef ElementLink<xAOD::MuonContainer>
MuonLink;
146
147 static const SG::ConstAccessor<int> truthTypeAcc("truthType");
148 static const SG::ConstAccessor<int> truthOriginAcc("truthOrigin");
149 static const SG::ConstAccessor<unsigned int> truthClassificationAcc("truthClassification");
150 static const SG::ConstAccessor<MuonLink> recoMuonLinkAcc("recoMuonLink");
151
153
154 static const SG::ConstAccessor<uint8_t> nprecLayersAcc("nprecLayers");
155
156 for (const auto truthMu : *TruthMuons) {
158 const int theType = truthTypeAcc(*truthMu);
159 const int theOrigin = truthOriginAcc(*truthMu);
160 const unsigned int theClassification = truthClassificationAcc(*truthMu);
161 ATH_MSG_VERBOSE(
"Truth muon: pt " << truthMu->pt() <<
" eta " << truthMu->eta());
162 ATH_MSG_VERBOSE(
"first loop: type " << theType <<
" origin " << theOrigin <<
" classification " << theClassification);
163 if (truthMu->pt() < 2000. || std::abs(truthMu->eta()) > 2.8) continue;
164 if (std::abs(truthMu->eta()) > 2.5)
165 ATH_MSG_VERBOSE(
" SA |eta| > 2.5 muon with truth prec layers " << (
int)nprecLayersAcc(*truthMu));
166
167 if (std::abs(truthMu->eta()) > 2.5 && (int)nprecLayersAcc(*truthMu) < 2) continue;
168 if (theType != 6 && theType != 7) continue;
169 if (theOrigin == 0 || theOrigin > 17) continue;
170 bool insideID = false;
171 if (std::abs(truthMu->eta()) < 2.0) insideID = true;
172 ATH_MSG_VERBOSE(
"Accepted Truth muon: pt " << truthMu->pt() <<
" eta " << truthMu->eta());
173
177 if (insideID)
179 if (insideID)
180 for (
int n = 7;
n < 11;
n++)
m_ntruth[n] += 1;
181
182 if (truthMu->pt() > 5000.) {
186 if (insideID)
188 if (insideID)
190 }
191
192 if (truthMu->pt() > 10000.) {
196 if (insideID)
198 if (insideID)
200 }
201
202 if (recoMuonLinkAcc.isAvailable(*truthMu)) {
203 link = recoMuonLinkAcc(*truthMu);
206 bool loose = false;
207 bool medium = false;
208 bool tight = false;
209 if (((*link)->quality() <= xAOD::Muon_v1::Loose)) loose = true;
210 if (((*link)->quality() <= xAOD::Muon_v1::Medium)) medium = true;
211 if (((*link)->quality() <= xAOD::Muon_v1::Tight)) tight = true;
213 if (insideID) {
215 if (tp) {
216 } else
218
219
221 if (truthMu->pt() > 5000.)
m_ntruth5[6] += 1;
222 if (truthMu->pt() > 10000.)
m_ntruth10[6] += 1;
223
224 bool passesIDcuts =
passID(tp,
true);
225 ATH_MSG_VERBOSE(
" all authors " << (*link)->allAuthors() <<
" passesIDcuts " << passesIDcuts);
226 if (passesIDcuts != (*link)->passesIDCuts()) {
227 ATH_MSG_DEBUG(
" PROBLEM passedIDcuts from xAOD muon: " << (*link)->passesIDCuts()
228 << " BUT MuonPerformancAlg code gives " << passesIDcuts);
229 }
230
231 passesIDcuts = (*link)->passesIDCuts();
232 if (passesIDcuts) {
233 if (nprecLayersAcc(*truthMu) > 0) {
235 if (truthMu->pt() > 5000.)
m_ntruth5[11] += 1;
236 if (truthMu->pt() > 10000.)
m_ntruth10[11] += 1;
237 }
238 if (loose) {
240 } else
241 print(
" Muon not found by Loose ", truthMu);
242 if (medium) {
244 } else if (loose)
245 print(
" Muon not found by Medium ", truthMu);
246 if (tight) {
248 } else if (medium)
249 print(
" Muon not found by Tight ", truthMu);
251 if (truthMu->pt() > 5000.) {
256 }
257 if (truthMu->pt() > 10000.) {
262 }
263
264 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8)) {
266 if (truthMu->pt() > 5000.)
m_nfound5[5] += 1;
267 if (truthMu->pt() > 10000.)
m_nfound10[5] += 1;
268 } else
269 print(
" Muon not found by CaloTag and Calolikelihood ", truthMu);
270
271 if (((*link)->allAuthors() & 32)) {
273 if (truthMu->pt() > 5000.)
m_nfound5[7] += 1;
274 if (truthMu->pt() > 10000.)
m_nfound10[7] += 1;
275 } else if (!((*link)->allAuthors() & 2))
276 print(
" Muon not found by MuidSA ", truthMu);
277
278 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16)) {
280 if (truthMu->pt() > 5000.)
m_nfound5[4] += 1;
281 if (truthMu->pt() > 10000.)
m_nfound10[4] += 1;
282 } else
283 print(
" Muon not found by MuTagIMO ", truthMu);
284
285 if (((*link)->allAuthors() & 64)) {
287 if (truthMu->pt() > 5000.)
m_nfound5[3] += 1;
288 if (truthMu->pt() > 10000.)
m_nfound10[3] += 1;
289 } else
290 print(
" Muon not found by MuGirl ", truthMu);
291
292 if (((*link)->allAuthors() & 2)) {
294 if (truthMu->pt() > 5000.)
m_nfound5[2] += 1;
295 if (truthMu->pt() > 10000.)
m_nfound10[2] += 1;
296 } else
297 print(
" Muon not found by MuidCo ", truthMu);
298
299 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
300 (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
302 if (truthMu->pt() > 5000.)
m_nfound5[1] += 1;
303 if (truthMu->pt() > 10000.)
m_nfound10[1] += 1;
304 if (nprecLayersAcc(*truthMu) > 0) {
306 if (truthMu->pt() > 5000.)
m_nfound5[11] += 1;
307 if (truthMu->pt() > 10000.)
m_nfound10[11] += 1;
308 }
309 } else
310 print(
" Combined Muon not found ", truthMu);
311 } else {
312
313 if (((*link)->allAuthors() & 32) || (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
315 if (truthMu->pt() > 5000.)
m_nfound5[7] += 1;
316 if (truthMu->pt() > 10000.)
m_nfound10[7] += 1;
317 } else
318 print(
" SA (CB) Muon not found ", truthMu);
319 }
320 }
321
322 else if (!insideID) {
323 if ((((*link)->allAuthors() & 32)) || ((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4)) {
325 if (truthMu->pt() > 5000.)
m_nfound5[0] += 1;
326 if (truthMu->pt() > 10000.)
m_nfound10[0] += 1;
327 } else
328 print(
" Muon not found by MuidSA endcap ", truthMu);
329 if (loose) {
331 if (truthMu->pt() > 5000.)
m_nfound5[10] += 1;
332 if (truthMu->pt() > 10000.)
m_nfound10[10] += 1;
333 } else
334 print(
" Muon not found by Loose endcap ", truthMu);
335 if (medium) {
337 if (truthMu->pt() > 5000.)
m_nfound5[9] += 1;
338 if (truthMu->pt() > 10000.)
m_nfound10[9] += 1;
339 } else if (loose)
340 print(
" Muon not found by Medium endcap ", truthMu);
341 }
342 } else {
343 print(
" No link Muon not found by CaloTag and Calolikelihood ", truthMu);
344 print(
" No link Muon not found by MuidSA ", truthMu);
345 print(
" No link Muon not found by MuTagIMO ", truthMu);
346 print(
" No link Muon not found by MuGirl ", truthMu);
347 print(
" No link Muon not found by MuidCo ", truthMu);
348 print(
" No link Combined Muon not found ", truthMu);
349 }
350 }
351 }
352
353 for (const auto truthMu : *TruthMuons) {
355 if (truthMu->pt() < 2000. || std::abs(truthMu->eta()) > 3.) continue;
356 const int theType = truthTypeAcc(*truthMu);
357 const int theOrigin = truthOriginAcc(*truthMu);
358 if (theType != 6 && theType != 7) continue;
359 if (theOrigin == 0 || theOrigin > 17) continue;
360 if (std::abs(truthMu->eta()) > 2.5 && (int)nprecLayersAcc(*truthMu) < 2) continue;
361 bool insideID = false;
362 if (recoMuonLinkAcc.isAvailable(*truthMu)) {
363 link = recoMuonLinkAcc(*truthMu);
366 if (tp) {
367 if ((*link)->pt() < 2000. || std::abs((*link)->eta()) > 2.8) continue;
368 if (std::abs((*link)->eta()) < 2.0) insideID = true;
369 bool loose = false;
370 bool medium = false;
371 bool tight = false;
372 if (((*link)->quality() == xAOD::Muon_v1::Loose)) loose = true;
373 if (((*link)->quality() == xAOD::Muon_v1::Medium)) loose = true;
374 if (((*link)->quality() == xAOD::Muon_v1::Tight)) loose = true;
375 if (((*link)->quality() == xAOD::Muon_v1::Medium)) medium = true;
376 if (((*link)->quality() == xAOD::Muon_v1::Tight)) medium = true;
377 if (((*link)->quality() == xAOD::Muon_v1::Tight)) tight = true;
378 if (insideID) {
379 bool passesIDcuts =
passID(tp,
false);
380
381 passesIDcuts = (*link)->passesIDCuts();
382 if (passesIDcuts) {
387 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr[5] += 1;
388 if (((*link)->allAuthors() & 32))
m_nfoundr[7] += 1;
389 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr[4] += 1;
390 if (((*link)->allAuthors() & 64))
m_nfoundr[3] += 1;
391 if (((*link)->allAuthors() & 2))
m_nfoundr[2] += 1;
392 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
393 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
395 if ((*link)->pt() > 5000.) {
400 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr5[5] += 1;
401 if (((*link)->allAuthors() & 32))
m_nfoundr5[7] += 1;
402 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr5[4] += 1;
403 if (((*link)->allAuthors() & 64))
m_nfoundr5[3] += 1;
404 if (((*link)->allAuthors() & 2))
m_nfoundr5[2] += 1;
405 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
406 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
408 }
409 if ((*link)->pt() > 10000.) {
414 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr10[5] += 1;
415 if (((*link)->allAuthors() & 32))
m_nfoundr10[7] += 1;
416 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr10[4] += 1;
417 if (((*link)->allAuthors() & 64))
m_nfoundr10[3] += 1;
418 if (((*link)->allAuthors() & 2))
m_nfoundr10[2] += 1;
419 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
420 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
422 }
423 } else {
424 if (((*link)->allAuthors() & 32) || (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
426 if ((*link)->pt() > 5000.)
m_nfoundr5[7] += 1;
428 }
429 }
430 } else if (!insideID) {
431 if ((((*link)->allAuthors() & 32)) || ((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4)) {
433 if ((*link)->pt() > 5000.)
m_nfoundr5[0] += 1;
435 }
438 if ((*link)->pt() > 5000.) {
441 }
442 if ((*link)->pt() > 10000.) {
445 }
446 }
447 } else
449 }
450 }
451 }
452
454
455 if (!Muons.isValid()) {
457 return StatusCode::FAILURE;
458 }
460
461 for (const auto mu : *Muons) {
462 if (
mu->pt() < 2000. || std::abs(
mu->eta()) > 2.8)
continue;
464
465 if (tp) {
466 ElementLink<xAOD::TruthParticleContainer> truthLink;
467 bool passesIDcuts =
passID(tp,
false);
468
469 passesIDcuts =
mu->passesIDCuts();
470
471 bool insideID = false;
472 if (std::abs(
mu->eta()) < 2.0) insideID =
true;
473 static const SG::ConstAccessor<ElementLink<xAOD::TruthParticleContainer> >
474 truthParticleLinkAcc ("truthParticleLink");
475 if (truthParticleLinkAcc.isAvailable(*tp))
476 truthLink = truthParticleLinkAcc(*tp);
477 bool fake = true;
479 if (
selectPdg((*truthLink)->pdgId())) fake =
false;
480 }
481 bool loose = false;
482 bool medium = false;
483 bool tight = false;
484 if (
mu->quality() == xAOD::Muon_v1::Loose) loose =
true;
485 if (
mu->quality() == xAOD::Muon_v1::Medium) loose =
true;
486 if (
mu->quality() == xAOD::Muon_v1::Tight) loose =
true;
487 if (
mu->quality() == xAOD::Muon_v1::Medium) medium =
true;
488 if (
mu->quality() == xAOD::Muon_v1::Tight) medium =
true;
489 if (
mu->quality() == xAOD::Muon_v1::Tight) tight =
true;
490 if (insideID) {
491 if (passesIDcuts) {
496 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco[5] += 1;
497 if ((
mu->allAuthors() & 32))
m_nreco[7] += 1;
498 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco[4] += 1;
499 if ((
mu->allAuthors() & 64))
m_nreco[3] += 1;
500 if ((
mu->allAuthors() & 2))
m_nreco[2] += 1;
501 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
503 if (
mu->pt() > 5000.) {
508 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco5[5] += 1;
509 if ((
mu->allAuthors() & 32))
m_nreco5[7] += 1;
510 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco5[4] += 1;
511 if ((
mu->allAuthors() & 64))
m_nreco5[3] += 1;
513 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
515 }
516 if (
mu->pt() > 10000.) {
521 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco10[5] += 1;
523 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco10[4] += 1;
526 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
528 }
529 if (fake) {
530 if ((
mu->quality() == xAOD::Muon_v1::Loose))
print(
" Fake muon found by Loose ", mu);
531 if ((
mu->quality() == xAOD::Muon_v1::Medium))
print(
" Fake muon found by Medium ", mu);
532 if ((
mu->quality() == xAOD::Muon_v1::Tight))
print(
" Fake muon found by Tight ", mu);
533 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
534 print(
" Fake muon found by CaloTag and Calolikelihood ", mu);
535 if ((
mu->allAuthors() & 32))
print(
" Fake muon found by MuidSA ", mu);
536 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
print(
" Fake muon found by MuTagIMO ", mu);
537 if ((
mu->allAuthors() & 64))
print(
" Fake muon found by MuGirl ", mu);
538 if ((
mu->allAuthors() & 2))
print(
" Fake muon found by MuidCo ", mu);
539 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
540 print(
" Fake Combined muon ", mu);
541 }
542 } else {
543 if ((
mu->allAuthors() & 32) ||
mu->muonType() == xAOD::Muon::MuonType::Combined) {
545 if (fake)
print(
" Fake muon found by MuidSA with no ID", mu);
548 }
549 }
550 } else if (!insideID) {
553 if (loose && fake)
print(
" Fake muon found by Loose Endcap ", mu);
554 if (medium && fake && !loose)
print(
" Fake muon found by Medium Endcap ", mu);
555 if (tight && !medium && fake)
print(
" Fake muon found by Tight Endcap ", mu);
556 if (
mu->pt() > 5000.) {
559 }
560 if (
mu->pt() > 10000.) {
563 }
564 if (((
mu->allAuthors() & 32)) || (
mu->allAuthors() & 2) || (
mu->allAuthors() & 4)) {
566 if (fake)
print(
" Fake muon found by MuidSA Endcap ", mu);
569 }
570 }
571 }
572 }
573
574 return StatusCode::SUCCESS;
575}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
ElementLink< xAOD::MuonContainer > MuonLink
bool isValid() const
Test to see if the link can be dereferenced.
TrackParticle_v1 TrackParticle
Reference the current persistent version: