126 {
127 SG::ReadHandle<xAOD::EventInfo> eventInfo(
m_eventInfo);
128
131
132 SG::ReadHandle<xAOD::TruthParticleContainer> TruthMuons(
m_truthMuons);
133 if (!TruthMuons.isPresent()) {
135 return StatusCode::SUCCESS;
136 }
137 if (!TruthMuons.isValid()) {
139 return StatusCode::FAILURE;
140 }
142 typedef ElementLink<xAOD::MuonContainer>
MuonLink;
143
144 static const SG::ConstAccessor<int> truthTypeAcc("truthType");
145 static const SG::ConstAccessor<int> truthOriginAcc("truthOrigin");
146 static const SG::ConstAccessor<MuonLink> recoMuonLinkAcc("recoMuonLink");
147
149
150 static const SG::ConstAccessor<uint8_t> nprecLayersAcc("nprecLayers");
151
152 for (const auto truthMu : *TruthMuons) {
154 const int theType = truthTypeAcc(*truthMu);
155 const int theOrigin = truthOriginAcc(*truthMu);
156 ATH_MSG_VERBOSE(
"Truth muon: pt " << truthMu->pt() <<
" eta " << truthMu->eta());
157 ATH_MSG_VERBOSE(
"first loop: type " << theType <<
" origin " << theOrigin);
158 if (truthMu->pt() < 2000. || std::abs(truthMu->eta()) > 2.8) continue;
159 if (std::abs(truthMu->eta()) > 2.5)
160 ATH_MSG_VERBOSE(
" SA |eta| > 2.5 muon with truth prec layers " << (
int)nprecLayersAcc(*truthMu));
161
162 if (std::abs(truthMu->eta()) > 2.5 && (int)nprecLayersAcc(*truthMu) < 2) continue;
163 if (theType != 6 && theType != 7) continue;
164 if (theOrigin == 0 || theOrigin > 17) continue;
165 bool insideID = false;
166 if (std::abs(truthMu->eta()) < 2.0) insideID = true;
167 ATH_MSG_VERBOSE(
"Accepted Truth muon: pt " << truthMu->pt() <<
" eta " << truthMu->eta());
168
172 if (insideID)
174 if (insideID)
175 for (
int n = 7;
n < 11;
n++)
m_ntruth[n] += 1;
176
177 if (truthMu->pt() > 5000.) {
181 if (insideID)
183 if (insideID)
185 }
186
187 if (truthMu->pt() > 10000.) {
191 if (insideID)
193 if (insideID)
195 }
196
197 if (recoMuonLinkAcc.isAvailable(*truthMu)) {
198 link = recoMuonLinkAcc(*truthMu);
201 bool loose = false;
202 bool medium = false;
203 bool tight = false;
204 if (((*link)->quality() <= xAOD::Muon_v1::Loose)) loose = true;
205 if (((*link)->quality() <= xAOD::Muon_v1::Medium)) medium = true;
206 if (((*link)->quality() <= xAOD::Muon_v1::Tight)) tight = true;
208 if (insideID) {
210 if (tp) {
211 } else
213
214
216 if (truthMu->pt() > 5000.)
m_ntruth5[6] += 1;
217 if (truthMu->pt() > 10000.)
m_ntruth10[6] += 1;
218
219 bool passesIDcuts =
passID(tp,
true);
220 ATH_MSG_VERBOSE(
" all authors " << (*link)->allAuthors() <<
" passesIDcuts " << passesIDcuts);
221 if (passesIDcuts != (*link)->passesIDCuts()) {
222 ATH_MSG_DEBUG(
" PROBLEM passedIDcuts from xAOD muon: " << (*link)->passesIDCuts()
223 << " BUT MuonPerformancAlg code gives " << passesIDcuts);
224 }
225
226 passesIDcuts = (*link)->passesIDCuts();
227 if (passesIDcuts) {
228 if (nprecLayersAcc(*truthMu) > 0) {
230 if (truthMu->pt() > 5000.)
m_ntruth5[11] += 1;
231 if (truthMu->pt() > 10000.)
m_ntruth10[11] += 1;
232 }
233 if (loose) {
235 } else
236 print(
" Muon not found by Loose ", truthMu);
237 if (medium) {
239 } else if (loose)
240 print(
" Muon not found by Medium ", truthMu);
241 if (tight) {
243 } else if (medium)
244 print(
" Muon not found by Tight ", truthMu);
246 if (truthMu->pt() > 5000.) {
251 }
252 if (truthMu->pt() > 10000.) {
257 }
258
259 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8)) {
261 if (truthMu->pt() > 5000.)
m_nfound5[5] += 1;
262 if (truthMu->pt() > 10000.)
m_nfound10[5] += 1;
263 } else
264 print(
" Muon not found by CaloTag and Calolikelihood ", truthMu);
265
266 if (((*link)->allAuthors() & 32)) {
268 if (truthMu->pt() > 5000.)
m_nfound5[7] += 1;
269 if (truthMu->pt() > 10000.)
m_nfound10[7] += 1;
270 } else if (!((*link)->allAuthors() & 2))
271 print(
" Muon not found by MuidSA ", truthMu);
272
273 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16)) {
275 if (truthMu->pt() > 5000.)
m_nfound5[4] += 1;
276 if (truthMu->pt() > 10000.)
m_nfound10[4] += 1;
277 } else
278 print(
" Muon not found by MuTagIMO ", truthMu);
279
280 if (((*link)->allAuthors() & 64)) {
282 if (truthMu->pt() > 5000.)
m_nfound5[3] += 1;
283 if (truthMu->pt() > 10000.)
m_nfound10[3] += 1;
284 } else
285 print(
" Muon not found by MuGirl ", truthMu);
286
287 if (((*link)->allAuthors() & 2)) {
289 if (truthMu->pt() > 5000.)
m_nfound5[2] += 1;
290 if (truthMu->pt() > 10000.)
m_nfound10[2] += 1;
291 } else
292 print(
" Muon not found by MuidCo ", truthMu);
293
294 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
295 (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
297 if (truthMu->pt() > 5000.)
m_nfound5[1] += 1;
298 if (truthMu->pt() > 10000.)
m_nfound10[1] += 1;
299 if (nprecLayersAcc(*truthMu) > 0) {
301 if (truthMu->pt() > 5000.)
m_nfound5[11] += 1;
302 if (truthMu->pt() > 10000.)
m_nfound10[11] += 1;
303 }
304 } else
305 print(
" Combined Muon not found ", truthMu);
306 } else {
307
308 if (((*link)->allAuthors() & 32) || (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
310 if (truthMu->pt() > 5000.)
m_nfound5[7] += 1;
311 if (truthMu->pt() > 10000.)
m_nfound10[7] += 1;
312 } else
313 print(
" SA (CB) Muon not found ", truthMu);
314 }
315 }
316
317 else if (!insideID) {
318 if ((((*link)->allAuthors() & 32)) || ((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4)) {
320 if (truthMu->pt() > 5000.)
m_nfound5[0] += 1;
321 if (truthMu->pt() > 10000.)
m_nfound10[0] += 1;
322 } else
323 print(
" Muon not found by MuidSA endcap ", truthMu);
324 if (loose) {
326 if (truthMu->pt() > 5000.)
m_nfound5[10] += 1;
327 if (truthMu->pt() > 10000.)
m_nfound10[10] += 1;
328 } else
329 print(
" Muon not found by Loose endcap ", truthMu);
330 if (medium) {
332 if (truthMu->pt() > 5000.)
m_nfound5[9] += 1;
333 if (truthMu->pt() > 10000.)
m_nfound10[9] += 1;
334 } else if (loose)
335 print(
" Muon not found by Medium endcap ", truthMu);
336 }
337 } else {
338 print(
" No link Muon not found by CaloTag and Calolikelihood ", truthMu);
339 print(
" No link Muon not found by MuidSA ", truthMu);
340 print(
" No link Muon not found by MuTagIMO ", truthMu);
341 print(
" No link Muon not found by MuGirl ", truthMu);
342 print(
" No link Muon not found by MuidCo ", truthMu);
343 print(
" No link Combined Muon not found ", truthMu);
344 }
345 }
346 }
347
348 for (const auto truthMu : *TruthMuons) {
350 if (truthMu->pt() < 2000. || std::abs(truthMu->eta()) > 3.) continue;
351 const int theType = truthTypeAcc(*truthMu);
352 const int theOrigin = truthOriginAcc(*truthMu);
353 if (theType != 6 && theType != 7) continue;
354 if (theOrigin == 0 || theOrigin > 17) continue;
355 if (std::abs(truthMu->eta()) > 2.5 && (int)nprecLayersAcc(*truthMu) < 2) continue;
356 bool insideID = false;
357 if (recoMuonLinkAcc.isAvailable(*truthMu)) {
358 link = recoMuonLinkAcc(*truthMu);
361 if (tp) {
362 if ((*link)->pt() < 2000. || std::abs((*link)->eta()) > 2.8) continue;
363 if (std::abs((*link)->eta()) < 2.0) insideID = true;
364 bool loose = false;
365 bool medium = false;
366 bool tight = false;
367 if (((*link)->quality() == xAOD::Muon_v1::Loose)) loose = true;
368 if (((*link)->quality() == xAOD::Muon_v1::Medium)) loose = true;
369 if (((*link)->quality() == xAOD::Muon_v1::Tight)) loose = true;
370 if (((*link)->quality() == xAOD::Muon_v1::Medium)) medium = true;
371 if (((*link)->quality() == xAOD::Muon_v1::Tight)) medium = true;
372 if (((*link)->quality() == xAOD::Muon_v1::Tight)) tight = true;
373 if (insideID) {
374 bool passesIDcuts =
passID(tp,
false);
375
376 passesIDcuts = (*link)->passesIDCuts();
377 if (passesIDcuts) {
382 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr[5] += 1;
383 if (((*link)->allAuthors() & 32))
m_nfoundr[7] += 1;
384 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr[4] += 1;
385 if (((*link)->allAuthors() & 64))
m_nfoundr[3] += 1;
386 if (((*link)->allAuthors() & 2))
m_nfoundr[2] += 1;
387 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
388 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
390 if ((*link)->pt() > 5000.) {
395 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr5[5] += 1;
396 if (((*link)->allAuthors() & 32))
m_nfoundr5[7] += 1;
397 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr5[4] += 1;
398 if (((*link)->allAuthors() & 64))
m_nfoundr5[3] += 1;
399 if (((*link)->allAuthors() & 2))
m_nfoundr5[2] += 1;
400 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
401 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
403 }
404 if ((*link)->pt() > 10000.) {
409 if (((*link)->allAuthors() & 64 * 4) || ((*link)->allAuthors() & 64 * 8))
m_nfoundr10[5] += 1;
410 if (((*link)->allAuthors() & 32))
m_nfoundr10[7] += 1;
411 if (((*link)->allAuthors() & 8) || ((*link)->allAuthors() & 16))
m_nfoundr10[4] += 1;
412 if (((*link)->allAuthors() & 64))
m_nfoundr10[3] += 1;
413 if (((*link)->allAuthors() & 2))
m_nfoundr10[2] += 1;
414 if (((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4) ||
415 (*link)->muonType() == xAOD::Muon::MuonType::Combined)
417 }
418 } else {
419 if (((*link)->allAuthors() & 32) || (*link)->muonType() == xAOD::Muon::MuonType::Combined) {
421 if ((*link)->pt() > 5000.)
m_nfoundr5[7] += 1;
423 }
424 }
425 } else if (!insideID) {
426 if ((((*link)->allAuthors() & 32)) || ((*link)->allAuthors() & 2) || ((*link)->allAuthors() & 4)) {
428 if ((*link)->pt() > 5000.)
m_nfoundr5[0] += 1;
430 }
433 if ((*link)->pt() > 5000.) {
436 }
437 if ((*link)->pt() > 10000.) {
440 }
441 }
442 } else
444 }
445 }
446 }
447
449
450 if (!Muons.isValid()) {
452 return StatusCode::FAILURE;
453 }
455
456 for (const auto mu : *Muons) {
457 if (
mu->pt() < 2000. || std::abs(
mu->eta()) > 2.8)
continue;
459
460 if (tp) {
461 ElementLink<xAOD::TruthParticleContainer> truthLink;
462 bool passesIDcuts =
passID(tp,
false);
463
464 passesIDcuts =
mu->passesIDCuts();
465
466 bool insideID = false;
467 if (std::abs(
mu->eta()) < 2.0) insideID =
true;
468 static const SG::ConstAccessor<ElementLink<xAOD::TruthParticleContainer> >
469 truthParticleLinkAcc ("truthParticleLink");
470 if (truthParticleLinkAcc.isAvailable(*tp))
471 truthLink = truthParticleLinkAcc(*tp);
472 bool fake = true;
474 if (
selectPdg((*truthLink)->pdgId())) fake =
false;
475 }
476 bool loose = false;
477 bool medium = false;
478 bool tight = false;
479 if (
mu->quality() == xAOD::Muon_v1::Loose) loose =
true;
480 if (
mu->quality() == xAOD::Muon_v1::Medium) loose =
true;
481 if (
mu->quality() == xAOD::Muon_v1::Tight) loose =
true;
482 if (
mu->quality() == xAOD::Muon_v1::Medium) medium =
true;
483 if (
mu->quality() == xAOD::Muon_v1::Tight) medium =
true;
484 if (
mu->quality() == xAOD::Muon_v1::Tight) tight =
true;
485 if (insideID) {
486 if (passesIDcuts) {
491 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco[5] += 1;
492 if ((
mu->allAuthors() & 32))
m_nreco[7] += 1;
493 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco[4] += 1;
494 if ((
mu->allAuthors() & 64))
m_nreco[3] += 1;
495 if ((
mu->allAuthors() & 2))
m_nreco[2] += 1;
496 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
498 if (
mu->pt() > 5000.) {
503 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco5[5] += 1;
504 if ((
mu->allAuthors() & 32))
m_nreco5[7] += 1;
505 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco5[4] += 1;
506 if ((
mu->allAuthors() & 64))
m_nreco5[3] += 1;
508 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
510 }
511 if (
mu->pt() > 10000.) {
516 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
m_nreco10[5] += 1;
518 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
m_nreco10[4] += 1;
521 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
523 }
524 if (fake) {
525 if ((
mu->quality() == xAOD::Muon_v1::Loose))
print(
" Fake muon found by Loose ", mu);
526 if ((
mu->quality() == xAOD::Muon_v1::Medium))
print(
" Fake muon found by Medium ", mu);
527 if ((
mu->quality() == xAOD::Muon_v1::Tight))
print(
" Fake muon found by Tight ", mu);
528 if ((
mu->allAuthors() & 64 * 4) || (
mu->allAuthors() & 64 * 8))
529 print(
" Fake muon found by CaloTag and Calolikelihood ", mu);
530 if ((
mu->allAuthors() & 32))
print(
" Fake muon found by MuidSA ", mu);
531 if ((
mu->allAuthors() & 8) || (
mu->allAuthors() & 16))
print(
" Fake muon found by MuTagIMO ", mu);
532 if ((
mu->allAuthors() & 64))
print(
" Fake muon found by MuGirl ", mu);
533 if ((
mu->allAuthors() & 2))
print(
" Fake muon found by MuidCo ", mu);
534 if ((
mu->allAuthors() & 2) || (
mu->allAuthors() & 4) ||
mu->muonType() == xAOD::Muon::MuonType::Combined)
535 print(
" Fake Combined muon ", mu);
536 }
537 } else {
538 if ((
mu->allAuthors() & 32) ||
mu->muonType() == xAOD::Muon::MuonType::Combined) {
540 if (fake)
print(
" Fake muon found by MuidSA with no ID", mu);
543 }
544 }
545 } else if (!insideID) {
548 if (loose && fake)
print(
" Fake muon found by Loose Endcap ", mu);
549 if (medium && fake && !loose)
print(
" Fake muon found by Medium Endcap ", mu);
550 if (tight && !medium && fake)
print(
" Fake muon found by Tight Endcap ", mu);
551 if (
mu->pt() > 5000.) {
554 }
555 if (
mu->pt() > 10000.) {
558 }
559 if (((
mu->allAuthors() & 32)) || (
mu->allAuthors() & 2) || (
mu->allAuthors() & 4)) {
561 if (fake)
print(
" Fake muon found by MuidSA Endcap ", mu);
564 }
565 }
566 }
567 }
568
569 return StatusCode::SUCCESS;
570}
#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: