ATLAS Offline Software
Loading...
Searching...
No Matches
TruthClassificationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
10
13
14#include <set>
15
16namespace
17{
18 bool isInSet(int origin, const std::set<int> &s)
19 {
20 return s.find(origin) != s.end();
21 }
22}
23
24
26 : asg::AsgTool(type)
27{
28 declareProperty ("separateChargeFlipElectrons", m_separateChargeFlipElectrons, "separate prompt charge-flipped electrons");
29 declareProperty ("separateChargeFlipMuons", m_separateChargeFlipMuons, "separate prompt charge-flipped muons");
30 declareProperty ("useTruthParticleDecorations", m_useTruthParticleDecorations, "use truth particle decorations");
31 declareProperty ("separateConversionTypes", m_separateConversionTypes, "split electrons from photon conversions into material and internal conversions");
32}
33
34
36 unsigned int &classification) const
37{
38 Truth::Type type = Truth::Type::Unknown;
39 ANA_CHECK(classify(particle, type));
40 classification = static_cast<int>(type);
41 return StatusCode::SUCCESS;
42}
43
44
46 Truth::Type &classification) const
47{
48 const xAOD::TruthParticle *truthParticle = dynamic_cast<const xAOD::TruthParticle *> (&particle);
49 if (dynamic_cast<const xAOD::Electron *> (&particle) || (truthParticle != nullptr && MC::isElectron(truthParticle)))
50 {
51 ANA_CHECK(classifyElectron(particle, classification));
52 if (m_separateConversionTypes && classification == Truth::Type::PromptPhotonConversion)
53 {
54 splitPromptPhotonConversion(particle, classification);
55 }
56 }
57 else if (dynamic_cast<const xAOD::Muon *> (&particle) || (truthParticle != nullptr && MC::isMuon(truthParticle)))
58 {
59 ANA_CHECK(classifyMuon(particle, classification));
60 }
61 else
62 {
63 ANA_MSG_ERROR("Only electrons and muons are supported.");
64 return StatusCode::FAILURE;
65 }
66
67 return StatusCode::SUCCESS;
68}
69
70
72 Truth::Type &classification) const
73{
74
75
76 // Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
77 const xAOD::TruthParticle *truthParticle = dynamic_cast<const xAOD::TruthParticle *> (&electron);
78 bool isTruthParticle{};
79 if (truthParticle == nullptr)
80 {
81 // need to find the truth particle
82 truthParticle = xAOD::TruthHelpers::getTruthParticle(electron);
83 }
84 else
85 {
86 isTruthParticle = true;
87 }
88
89 if (!m_truthPdgId.isAvailable(electron) && !isTruthParticle)
90 {
91 ANA_MSG_ERROR("Electron does not have the 'truthPdgId' decoration.");
92 return StatusCode::FAILURE;
93 }
94
95 if (!m_firstMotherTruthType.isAvailable(electron)
96 || !m_firstMotherTruthOrigin.isAvailable(electron)
97 || !m_firstMotherPdgId.isAvailable(electron))
98 {
99 ANA_MSG_ERROR("Electron does not have one or more 'firstEgMother' decorations.");
100 return StatusCode::FAILURE;
101 }
102
103 int type = isTruthParticle ? m_classifierParticleType(electron) : m_truthType(electron);
104 int origin = isTruthParticle ? m_classifierParticleOrigin(electron) : m_truthOrigin(electron);
105 int pdgId = isTruthParticle && truthParticle != nullptr ? truthParticle->pdgId() : m_truthPdgId(electron);
106 if (m_useTruthParticleDecorations && !isTruthParticle && truthParticle != nullptr)
107 {
108 type = m_classifierParticleType(*truthParticle);
109 origin = m_classifierParticleOrigin(*truthParticle);
110 }
111
112 int firstMotherType = m_firstMotherTruthType(electron);
113 int firstMotherOrigin = m_firstMotherTruthOrigin(electron);
114 int firstMotherPdgId = m_firstMotherPdgId(electron);
115 // not in the smart slimming list, thus only in few derivations
116 int lastMotherType = m_lastMotherTruthType.isAvailable(electron) ? m_lastMotherTruthType(electron) : -1;
117 int lastMotherOrigin = m_lastMotherTruthOrigin.isAvailable(electron) ? m_lastMotherTruthOrigin(electron) : -1;
118 int lastMotherPdgId = m_lastMotherPdgId.isAvailable(electron) ? m_lastMotherPdgId(electron) : -1;
119 // fallback recorations
120 int fallbackType{-1};
121 if (m_fallbackTruthType.isAvailable(electron) && m_fallbackDR.isAvailable(electron))
122 {
123 fallbackType = m_fallbackDR(electron) < 0.05 ? m_fallbackTruthType(electron) : -1;
124 }
125
126 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
127 // Prompt Photon Conversions
128 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
129
130 // gamma -> e+ e-
133 && firstMotherType == MCTruthPartClassifier::IsoPhoton && firstMotherOrigin == MCTruthPartClassifier::PromptPhot)
134 {
135 classification = Truth::Type::PromptPhotonConversion;
136 return StatusCode::SUCCESS;
137 }
138
139 // H -> gamma gamma, gamma -> e+ e-
141 && firstMotherType == MCTruthPartClassifier::IsoPhoton && firstMotherOrigin == MCTruthPartClassifier::Higgs)
142 {
143 classification = Truth::Type::PromptPhotonConversion;
144 return StatusCode::SUCCESS;
145 }
146
147 // bkg electrons from bkg photons
149 && firstMotherType == MCTruthPartClassifier::UnknownPhoton && firstMotherOrigin == MCTruthPartClassifier::NonDefined)
150 {
151 classification = Truth::Type::PromptPhotonConversion;
152 return StatusCode::SUCCESS;
153 }
154
155 // bkg photon from UndrPhot; (Here there is a generator level photon (not gen electron ) that later converts)
158 && firstMotherType == MCTruthPartClassifier::BkgPhoton && firstMotherOrigin == MCTruthPartClassifier::UndrPhot)
159 {
160 classification = Truth::Type::PromptPhotonConversion;
161 return StatusCode::SUCCESS;
162 }
163
164 // type = 16 and origin = 38 (again, this is a photon)
166 {
167 classification = Truth::Type::PromptPhotonConversion;
168 return StatusCode::SUCCESS;
169 }
170
171 // Is an isolated photon
172 if (type == MCTruthPartClassifier::IsoPhoton && pdgId == 22)
173 {
174 classification = Truth::Type::PromptPhotonConversion;
175 return StatusCode::SUCCESS;
176 }
177
178 // electrons from ElMagProc
179 // when FSR, a better classification can be made with the fall back vars
181 && firstMotherType == MCTruthPartClassifier::UnknownPhoton && firstMotherOrigin == MCTruthPartClassifier::NonDefined)
182 {
183 classification = Truth::Type::PromptPhotonConversion;
184 return StatusCode::SUCCESS;
185 }
187 && firstMotherType == MCTruthPartClassifier::NonIsoPhoton && firstMotherOrigin == MCTruthPartClassifier::FSRPhot)
188 {
189 classification = Truth::Type::PromptPhotonConversion;
190 return StatusCode::SUCCESS;
191 }
192
193 // TODO: Message from Otilia: """
194 // but it's not clear if these electrons are really
195 // "fakes" or they should go in the real category (we don't know from where
196 // this photon is coming...). I would say more truth studies should be done.
197 // """
198 // Hence the warning message...
200 && firstMotherType == MCTruthPartClassifier::Unknown && firstMotherOrigin == MCTruthPartClassifier::ZBoson)
201 {
202 ANA_MSG_WARNING("Electron identified as from a PromptPhotonConversion, "
203 "but this type of electron needs further study!");
204 classification = Truth::Type::PromptPhotonConversion;
205 return StatusCode::SUCCESS;
206 }
207
208 // when always a photon (last mum is a photon, even if the truth PDG is 11 and first mum PDG is 11 ):
209 // very likely these are internal conversions; last_mum_pdgId == 22 important as the cases with last_mum_pdgId == 11 were found to be quite often close to a true electron
212 && std::abs(firstMotherPdgId) == 11 && std::abs(pdgId) == 11)
213 { // electron
214 if(lastMotherType == -1 || (lastMotherType == MCTruthPartClassifier::GenParticle && (lastMotherPdgId == 22 || std::abs(lastMotherPdgId) == 11)))
215 {
216 // lastMotherType == -1 ==> when the last mother info is not stored in the derivations
217 classification = Truth::Type::PromptPhotonConversion;
218 return StatusCode::SUCCESS;
219 }
220 }
221
222
223 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
224 // Is muon reco as electron or ele radiated by muons
225 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
226
228 && (origin == MCTruthPartClassifier::Mu || firstMotherOrigin == MCTruthPartClassifier::Mu))
229 {
230 classification = Truth::Type::ElectronFromMuon;
231 return StatusCode::SUCCESS;
232 }
233
235 {
236 classification = Truth::Type::ElectronFromMuon;
237 return StatusCode::SUCCESS;
238 }
239
241 classification = Truth::Type::ElectronFromMuon;
242 return StatusCode::SUCCESS;
243 }
244
245
246 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
247 // Tau decays
248 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
249
250 // Non-isolated electron/photon from tau decay
253 {
254 classification = Truth::Type::TauDecay;
255 return StatusCode::SUCCESS;
256 }
257
258 // tau -> tau gamma, gamma -> e+ e-, etc
259 if ((firstMotherType == MCTruthPartClassifier::NonIsoElectron || firstMotherType == MCTruthPartClassifier::NonIsoPhoton)
260 && firstMotherOrigin == MCTruthPartClassifier::TauLep)
261 {
262 classification = Truth::Type::TauDecay;
263 return StatusCode::SUCCESS;
264 }
265
266
267 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
268 // Light hadron sources
269 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
270
272 {
273 classification = Truth::Type::LightFlavorDecay;
274 return StatusCode::SUCCESS;
275 }
276
277 if (firstMotherType == MCTruthPartClassifier::BkgElectron)
278 {
280 && (hasLightHadronOrigin(origin) || hasLightHadronOrigin(firstMotherOrigin)))
281 {
282 classification = Truth::Type::LightFlavorDecay;
283 return StatusCode::SUCCESS;
284 }
285 }
286
288 {
289 if (origin == MCTruthPartClassifier::DalitzDec || firstMotherOrigin == MCTruthPartClassifier::DalitzDec) {
290 classification = Truth::Type::LightFlavorDecay;
291 return StatusCode::SUCCESS;
292 }
293 if (hasLightHadronOrigin(origin) || hasLightHadronOrigin(firstMotherOrigin)) {
294 classification = Truth::Type::LightFlavorDecay;
295 return StatusCode::SUCCESS;
296 }
297 }
298
300 && (hasLightHadronOrigin(origin) || hasLightHadronOrigin(firstMotherOrigin)))
301 {
302 classification = Truth::Type::LightFlavorDecay;
303 return StatusCode::SUCCESS;
304 }
305
306
307 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
308 // From B hadron
309 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
310
311 if (hasBHadronOrigin(origin) || hasBHadronOrigin(firstMotherOrigin))
312 {
313 classification = Truth::Type::BHadronDecay;
314 return StatusCode::SUCCESS;
315 }
316
317 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
318 // From C hadron
319 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
320
321 if (type != MCTruthPartClassifier::IsoElectron && (hasCHadronOrigin(origin) || hasCHadronOrigin(firstMotherOrigin)))
322 {
323 classification = Truth::Type::CHadronDecay;
324 return StatusCode::SUCCESS;
325 }
326
327
328 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
329 // Prompt / Isolated electrons
330 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
331
332 if (isPromptElectron(electron, isTruthParticle, truthParticle))
333 {
334 if (m_separateChargeFlipElectrons && isChargeFlipElectron(electron, isTruthParticle, truthParticle))
335 {
336 classification = Truth::Type::ChargeFlipIsoElectron;
337 return StatusCode::SUCCESS;
338 }
339
340 classification = Truth::Type::IsoElectron;
341 return StatusCode::SUCCESS;
342 }
343
344
345 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
346 // Unknown & known Unknown
347 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
348
349 // TODO: See if we want this or not. Now we check if this is something we are
350 // able to classify or not. Note that this might be a bit dangerous because
351 // the reasons for not having origin and status codes might be complex. The
352 // main idea is to weed out things we don't have a hope of classifying due to
353 // missing or unknown information.
354 static const SG::ConstAccessor<int> statusAcc("status");
355 bool stable = (truthParticle != nullptr && statusAcc.isAvailable(*truthParticle)) ? MC::isStable(truthParticle) : false;
356
357
358 if (origin == MCTruthPartClassifier::NonDefined && firstMotherOrigin == MCTruthPartClassifier::NonDefined)
359 {
360 if (!stable)
361 {
363 {
364 classification = Truth::Type::KnownUnknown;
365 return StatusCode::SUCCESS;
366 }
367 } else {
370 {
371 classification = Truth::Type::KnownUnknown;
372 return StatusCode::SUCCESS;
373 }
374
376 {
377 classification = Truth::Type::KnownUnknown;
378 return StatusCode::SUCCESS;
379 }
380 }
381 }
382
383 // non-iso photons with no info available to classify
385 && firstMotherType == 0 && firstMotherOrigin == 0 && firstMotherPdgId == 0)
386 {
387 if (lastMotherType == -1 || (lastMotherType == 0 && lastMotherOrigin == 0 && lastMotherPdgId == 0))
388 { // last_firstMotherType == -1 ==> when the last_mum info is not stored in the derivations
389 classification = Truth::Type::KnownUnknown;
390 return StatusCode::SUCCESS;
391 }
392 }
393
394 ANA_MSG_WARNING("Electron type unknown: type = " << type << ", origin = " << origin);
395
396 // debug printout
397 if (truthParticle != nullptr)
398 {
399 const xAOD::TruthParticle *parent = truthParticle;
400 ATH_MSG_DEBUG("Unknown particle decay chain (approximate):");
401 std::string out = "\t";
402 while (parent != nullptr)
403 {
404 out.append(std::to_string(parent->pdgId()));
405 parent = parent->parent(0); //AV: Note the ambiguity: only the first particle is considered.
406 if (parent) out.append(" -> ");
407 }
408 ATH_MSG_DEBUG(out);
409 }
410
411 classification = Truth::Type::Unknown;
412 return StatusCode::SUCCESS;
413}
414
415
417 Truth::Type &classification) const
418{
419
420
421 // Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
422 const xAOD::TruthParticle *truthParticle
423 = dynamic_cast<const xAOD::TruthParticle *> (&muon);
424 bool isTruthParticle{};
425 if (truthParticle == nullptr)
426 {
427 // need to find the truth particle
428 truthParticle = xAOD::TruthHelpers::getTruthParticle(muon);
429 }
430 else
431 {
432 isTruthParticle = true;
433 }
434
435 int type = isTruthParticle ? m_classifierParticleType(muon) : m_truthType(muon);
436 int origin = isTruthParticle ? m_classifierParticleOrigin(muon) : m_truthOrigin(muon);
437 if (m_useTruthParticleDecorations && !isTruthParticle && truthParticle != nullptr)
438 {
439 type = m_classifierParticleType(*truthParticle);
440 origin = m_classifierParticleOrigin(*truthParticle);
441 }
442
443 // fallback recorations
444 int fallbackType{-1};
445 if (m_fallbackTruthType.isAvailable(muon) && m_fallbackDR.isAvailable(muon))
446 {
447 fallbackType = m_fallbackDR(muon) < 0.05 ? m_fallbackTruthType(muon) : -1;
448 }
449
450 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
451 // muons from taus
452 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
453
455 {
456 classification = Truth::Type::TauDecay;
457 return StatusCode::SUCCESS;
458 }
459
460
461 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
462 // Photon conversions (gamma -> mu+ mu-)
463 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
464
465 // Muon analogue of the electron PromptPhotonConversion rules. Without it these muons
466 // (BkgMuon, PhotonConv) matched no rule and ended up as Unknown, while the
467 // MCTruthClassifier-based isPrompt flag counts them as prompt.
469 {
470 classification = Truth::Type::PromptPhotonConversion;
471 return StatusCode::SUCCESS;
472 }
473
474
475 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
476 // Light hadron sources
477 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
478
480 {
481 classification = Truth::Type::LightFlavorDecay;
482 return StatusCode::SUCCESS;
483 }
484
486 {
487 classification = Truth::Type::LightFlavorDecay;
488 return StatusCode::SUCCESS;
489 }
490
491
492 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
493 // From B hadron
494 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
495
496 if (hasBHadronOrigin(origin))
497 {
498 classification = Truth::Type::BHadronDecay;
499 return StatusCode::SUCCESS;
500 }
501
502 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
503 // From C hadron
504 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
505
507 {
508 classification = Truth::Type::CHadronDecay;
509 return StatusCode::SUCCESS;
510 }
511
512
513 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
514 // prompt muons
515 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
516 // Check if the type of muon is IsoMuon(6) and whether the origin
517 // of the muon is from a prompt source
518 static const std::set<int> promptOrigin({
519 MCTruthPartClassifier::SingleMuon, // Single muon (origin = 2) from muon twiki
527 MCTruthPartClassifier::CCbarMeson, // PromptQuarkoniumDecay
532 });
533 if (type == MCTruthPartClassifier::IsoMuon && isInSet(origin, promptOrigin))
534 {
535 //separate charge-flip muons
536 if (m_separateChargeFlipMuons && isChargeFlipMuon(muon, isTruthParticle, truthParticle))
537 {
538 classification = Truth::Type::ChargeFlipMuon;
539 return StatusCode::SUCCESS;
540 }
541 classification = Truth::Type::PromptMuon;
542 return StatusCode::SUCCESS;
543 }
544
545
546 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
547 // Known Unknown
548 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
549
551 {
552 classification = Truth::Type::KnownUnknown;
553 return StatusCode::SUCCESS;
554 }
555
556 static const SG::ConstAccessor<int> statusAcc("status");
557 bool stable = (truthParticle != nullptr && statusAcc.isAvailable(*truthParticle)) ? MC::isStable(truthParticle) : false;
558
559 if (!stable) {
561 { // Data
562 classification = Truth::Type::KnownUnknown;
563 return StatusCode::SUCCESS;
564 }
565 if (type == -99999 && origin == -99999)
566 { // MC - no status = 1 truth particle associated with the primary track
567 classification = Truth::Type::KnownUnknown;
568 return StatusCode::SUCCESS;
569 }
570 }
571
572 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
573 // NonMuonlike
574 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
575 // Check if the type of muon is related to electrons, ie IsoElectron (2) or NonIsoElectron (3) or BkgElectron (4)
577 {
578 classification = Truth::Type::NonMuonlike;
579 return StatusCode::SUCCESS;
580 }
581
582 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
583 // TauLike, BHadLike, CHadLike
584 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
585 // Check if the matched parent of truth muon fall into these 3 xxxLike
586 // Only truth muon with one matched parent is considered
587 // If parent is tau, the muons is TauLike
588 // If parent is bhadron/b quark, the muons is BHadLike
589 // If parent is chadron/c quark, the muons is CHadLike
591 if( truthParticle != nullptr && truthParticle->nParents() == 1 && truthParticle->parent(0) != nullptr){
592 const xAOD::TruthParticle *parent = truthParticle->parent(0);
593 int parent_pdgid = parent->pdgId();
594 if(parent->isTau()){
595 classification = Truth::Type::TauDecayLike;
596 ATH_MSG_WARNING("Muon type taudecaylike: type = " << type << ", origin = " << origin << ", parent = " << parent_pdgid) ;
597 return StatusCode::SUCCESS;
598 }
599 if(parent->isBottomHadron() || parent->hasBottom()){
600 classification = Truth::Type::BHadronDecayLike;
601 ATH_MSG_WARNING("Muon type bhadrondecaylike: type = " << type << ", origin = " << origin << ", parent = " << parent_pdgid) ;
602 return StatusCode::SUCCESS;
603 }
604 if(parent->isCharmHadron() || parent->hasCharm()){
605 if( (parent_pdgid / 1000) % 10 != 0 || (parent_pdgid / 100) % 10 != 4 || (parent_pdgid / 10) % 10 != 4){ // to exclude ccbarmeson
606 classification = Truth::Type::CHadronDecayLike;
607 ATH_MSG_WARNING("Muon type chadrondecaylike: type = " << type << ", origin = " << origin << ", parent = " << parent_pdgid) ;
608 return StatusCode::SUCCESS;
609 }
610 }
611 }
612 }
613
614 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
615 // Unknown
616 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
617 classification = Truth::Type::Unknown;
618 ATH_MSG_WARNING("Muon type unknown: type = " << type << ", origin = " << origin) ;
619
620 return StatusCode::SUCCESS;
622}
623
625 Truth::Type &classification) const
626{
627 // Only called for electrons already classified as PromptPhotonConversion,
628 // so the 'firstEgMother' decorations are known to be available.
629 const xAOD::TruthParticle *truthParticle = dynamic_cast<const xAOD::TruthParticle *> (&electron);
630 const bool isTruthParticle = truthParticle != nullptr;
631 if (!isTruthParticle)
632 {
633 truthParticle = xAOD::TruthHelpers::getTruthParticle(electron);
634 }
635
636 int type = isTruthParticle ? m_classifierParticleType(electron) : m_truthType(electron);
637 int origin = isTruthParticle ? m_classifierParticleOrigin(electron) : m_truthOrigin(electron);
638 if (m_useTruthParticleDecorations && !isTruthParticle && truthParticle != nullptr)
639 {
640 type = m_classifierParticleType(*truthParticle);
641 origin = m_classifierParticleOrigin(*truthParticle);
642 }
643
644 const int firstMotherType = m_firstMotherTruthType(electron);
645 const int firstMotherOrigin = m_firstMotherTruthOrigin(electron);
646
647 // Internal conversion (gamma* -> e+ e-): the first non-Geant mother is itself
648 // a generator-level electron from a photon conversion, i.e. the pair was
649 // produced by the generator rather than in the detector material.
651 && firstMotherType == MCTruthPartClassifier::BkgElectron && firstMotherOrigin == MCTruthPartClassifier::PhotonConv)
652 {
653 classification = Truth::Type::InternalConversion;
654 return;
655 }
656
657 // Material conversion: a Geant4 electron (from a conversion or another
658 // electromagnetic process in the material) whose first non-Geant mother is
659 // a real generator-level photon.
662 && (firstMotherType == MCTruthPartClassifier::UnknownPhoton || firstMotherType == MCTruthPartClassifier::IsoPhoton
663 || firstMotherType == MCTruthPartClassifier::NonIsoPhoton || firstMotherType == MCTruthPartClassifier::BkgPhoton))
664 {
665 classification = Truth::Type::MaterialConversion;
666 return;
667 }
668
669 // Otherwise (e.g. the reconstructed electron is matched to a photon, or the
670 // mother is not identified) keep the generic PromptPhotonConversion class.
671}
672
674 bool isTruthParticle,
675 const xAOD::TruthParticle *truthParticle) const
676{
677
678
679 int type = isTruthParticle ? m_classifierParticleType(electron) : m_truthType(electron);
680 int origin = isTruthParticle ? m_classifierParticleOrigin(electron) : m_truthOrigin(electron);
681 if (m_useTruthParticleDecorations && !isTruthParticle && truthParticle != nullptr)
682 {
683 type = m_classifierParticleType(*truthParticle);
684 origin = m_classifierParticleOrigin(*truthParticle);
685 }
686
687 // Electron is IsoElectron - return true
689 {
690 return true;
691 }
692
693 int pdgId = isTruthParticle ? truthParticle->pdgId() : m_truthPdgId(electron);
694 int firstMotherType = m_firstMotherTruthType(electron);
695 int firstMotherOrigin = m_firstMotherTruthOrigin(electron);
696
697 // Adding these cases from ElectronEfficiencyHelpers
698 if (firstMotherType == MCTruthPartClassifier::IsoElectron && std::abs(m_firstMotherPdgId(electron)) == 11)
699 {
700 return true;
701 }
702
703 // FSR photons from electrons
704 if (origin == MCTruthPartClassifier::FSRPhot && type == MCTruthPartClassifier::NonIsoPhoton && std::abs(pdgId) == 11)
705 {
706 return true;
707 }
708
710 && firstMotherType == MCTruthPartClassifier::NonIsoPhoton && firstMotherOrigin == MCTruthPartClassifier::FSRPhot
711 && std::abs(pdgId) == 11)
712 {
713 return true;
714 }
715
716 // If we reach here then it is not a prompt electron
717 return false;
718}
719
720
722 bool isTruthParticle,
723 const xAOD::TruthParticle *truthParticle) const
724{
725
726
727 int type = isTruthParticle ? m_classifierParticleType(electron) : m_truthType(electron);
728 int origin = isTruthParticle ? m_classifierParticleOrigin(electron) : m_truthOrigin(electron);
729 int pdgId = isTruthParticle && truthParticle ? truthParticle->pdgId() : m_truthPdgId(electron);
730 if (m_useTruthParticleDecorations && !isTruthParticle && truthParticle != nullptr)
731 {
732 type = m_classifierParticleType(*truthParticle);
733 origin = m_classifierParticleOrigin(*truthParticle);
734 }
735
736 int firstMotherType = m_firstMotherTruthType(electron);
737 int firstMotherOrigin = m_firstMotherTruthOrigin(electron);
738 int firstMotherPdgId = m_firstMotherPdgId(electron);
739
740 // not consider FSR photons from electrons (the photon has no charge)
741 if (origin == MCTruthPartClassifier::FSRPhot && type == MCTruthPartClassifier::NonIsoPhoton && std::abs(pdgId) == 11)
742 {
743 return false;
744 }
746 && firstMotherType == MCTruthPartClassifier::NonIsoPhoton && firstMotherOrigin == MCTruthPartClassifier::FSRPhot
747 && std::abs(pdgId) == 11)
748 {
749 return false;
750 }
751
752 // bkg electrons with no additional info to help us classify them FSR -- not in the charge flip category
754 && firstMotherType == MCTruthPartClassifier::BkgElectron && firstMotherOrigin == MCTruthPartClassifier::PhotonConv
755 && std::abs(pdgId) == 11)
756 {
757 return false;
758 }
759
760 if (isTruthParticle)
761 {
762 if (truthParticle && truthParticle->charge() != 0)
763 {
764 return (firstMotherPdgId * truthParticle->charge()) > 0;
765 }
766 }
767 else
768 {
769 const xAOD::Electron &xAODElectron = *static_cast<const xAOD::Electron *> (&electron);
770 if (xAODElectron.charge() != 0)
771 {
772 return (firstMotherPdgId * xAODElectron.charge()) > 0;
773 }
774 }
775
776 return (firstMotherPdgId * (-pdgId)) > 0;
777}
778
779
781 bool isTruthParticle,
782 const xAOD::TruthParticle *truthParticle) const
783{
784 if (isTruthParticle)
785 {
786 return false;
787 }
788
789 if (truthParticle != nullptr && xAOD::P4Helpers::isInDeltaR(*truthParticle, muon, 0.025))
790 {
791 const xAOD::Muon &xAODMuon = *static_cast<const xAOD::Muon *> (&muon);
792 return (truthParticle->charge() * xAODMuon.charge()) < 0;
793 }
794
795 ANA_MSG_DEBUG("Cannot find associated truth-particle... assuming muon has correct charge");
796 return false;
797}
798
799
801{
802 static const std::set<int> b_hadrons({
806 });
807 return b_hadrons.contains(origin);
808}
809
810
812 static const std::set<int> c_hadrons({
817 });
818 return c_hadrons.contains(origin);
819}
820
821
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_DEBUG(xmsg,...)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
ATLAS-specific HepMC functions.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
const SG::ConstAccessor< int > m_truthPdgId
bool m_separateChargeFlipElectrons
separately store charge-flip electrons/muons
const SG::ConstAccessor< int > m_lastMotherTruthOrigin
const SG::ConstAccessor< int > m_truthType
StatusCode classifyElectron(const xAOD::IParticle &electron, Truth::Type &classification) const
electron classification helper
const SG::ConstAccessor< float > m_fallbackDR
const SG::ConstAccessor< int > m_firstMotherTruthType
bool hasCHadronOrigin(int origin) const
a helper to check if the origin is a c-hadron
const SG::ConstAccessor< int > m_lastMotherPdgId
bool m_separateConversionTypes
split electron photon conversions into material and internal conversions
const SG::ConstAccessor< unsigned int > m_classifierParticleType
StatusCode classifyMuon(const xAOD::IParticle &muon, Truth::Type &classification) const
muon classification helper
const SG::ConstAccessor< int > m_fallbackTruthType
const SG::ConstAccessor< int > m_firstMotherPdgId
virtual StatusCode classify(const xAOD::IParticle &particle, unsigned int &classification) const override
classify and return unsigned int
bool isChargeFlipElectron(const xAOD::IParticle &electron, bool isTruthParticle, const xAOD::TruthParticle *truthParticle) const
a helper to check if an electron has an incorrectly reconstructed charge
bool hasBHadronOrigin(int origin) const
a helper to check if the origin is a b-hadron
TruthClassificationTool(const std::string &type)
bool isPromptElectron(const xAOD::IParticle &electron, bool isTruthParticle, const xAOD::TruthParticle *truthParticle) const
a helper to check if an electron is prompt
const SG::ConstAccessor< int > m_firstMotherTruthOrigin
bool isChargeFlipMuon(const xAOD::IParticle &muon, bool isTruthParticle, const xAOD::TruthParticle *truthParticle) const
a helper to check if a muon has an incorrectly reconstructed charge
const SG::ConstAccessor< int > m_truthOrigin
void splitPromptPhotonConversion(const xAOD::IParticle &electron, Truth::Type &classification) const
split a PromptPhotonConversion electron into material or internal conversion (left unchanged if this ...
bool hasLightHadronOrigin(int origin) const
a helper to check if the origin is a light hadron
bool m_useTruthParticleDecorations
use truth particle decorations
const SG::ConstAccessor< unsigned int > m_classifierParticleOrigin
const SG::ConstAccessor< int > m_lastMotherTruthType
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
float charge() const
Obtain the charge of the object.
Class providing the definition of the 4-vector interface.
float charge() const
int pdgId() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
double charge() const
Physical charge.
size_t nParents() const
Number of parents of this particle.
@ BottomMeson
Decay of an open-bottom meson.
@ ElMagProc
Electromagnetic or nuclear material process: bremsstrahlung/pair production in the detector,...
@ LightBaryon
Decay of a light (u, d only) baryon.
@ SUSY
Decay of a SUSY particle.
@ UndrPhot
"Underlying" photon: radiated from a quark or gluon in the parton shower/underlying event
@ JPsi
Decay of a J/psi.
@ ZBoson
Z boson (or Z/gamma*) decay (including Sherpa Z records and Z+gamma).
@ BBbarMeson
Decay of a hidden-bottom meson.
@ PromptPhot
Prompt (direct) photon of the hard process, e.g. Pythia8 gamma+jet.
@ StrangeMeson
Decay of a meson containing s quark (e.g. kaon).
@ DiBoson
Two-boson (WW, WZ, ZZ) production recorded without explicit bosons: four leptons/neutrinos in the har...
@ Higgs
Higgs boson decay (SM Higgs, PDG 25).
@ CharmedBaryon
Decay of a charmed baryon.
@ StrangeBaryon
Decay of a strange baryon.
@ LightMeson
Decay of a light (u, d only) meson.
@ HiggsMSSM
Decay of an extra (MSSM/2HDM) Higgs boson: H (35), A (36) or H+ (37).
@ BottomBaryon
Decay of a bottom baryon.
@ PhotonConv
Photon conversion (gamma -> e+ e-, or gamma -> mu+ mu- for muons).
@ TauLep
Decay (or radiation) of a tau lepton that is not itself prompt.
@ KaonDecay
Muon from K -> mu nu in flight.
@ FSRPhot
Final-state radiation photon, e.g. from the leptons of W/Z/H decays or from Photos.
@ WBoson
W boson decay (including Sherpa W records and W+gamma).
@ Mu
Decay (or radiation) of a muon.
@ NonDefined
Origin could not be determined (no production vertex, no ancestor, or particle not classified).
@ PiZero
Photon from a pi0 decay.
@ CharmedMeson
Decay of an open-charm meson.
@ CCbarMeson
Decay of a hidden-charm meson other than J/psi.
@ top
Decay of a top quark (including through W).
@ DalitzDec
Dalitz decay of a pi0 (pi0 -> gamma e+ e-, or pi0 -> e+ e- e+ e-).
@ HeavyBoson
Decay of a heavy gauge boson Z', Z'', W'+ (PDG 32, 33, 34), or a KK graviton (5100039) in the photon ...
@ SingleMuon
Single-muon particle gun.
@ PionDecay
Muon from pi -> mu nu in flight.
@ MultiBoson
Three or more bosons (VVV, 4-top with leptonic W decays): six or eight leptons/neutrinos in the hard-...
@ Unknown
Not classified: not a lepton, photon, neutrino or hadron (e.g. a quark, a gluon, a boson),...
@ IsoPhoton
Isolated (prompt) photon: from W/Z/H/BSM decay, a hard-process prompt photon, or a single-photon gun.
@ UnknownMuon
Muon with undefined origin.
@ NonIsoPhoton
Non-isolated photon: initial/final-state radiation, or from tau, muon or right-handed neutrino/W_R de...
@ BkgPhoton
Background photon: bremsstrahlung, pi0 decay, hadron decay, nuclear reaction, underlying-event photon...
@ NonIsoMuon
Non-isolated muon from J/psi, B/D hadron, tau or quark weak decay.
@ BkgMuon
Background muon: pion/kaon decay in flight and other remaining cases.
@ IsoElectron
Isolated (prompt) electron, e.g. from W/Z/H/top/BSM decay, or a single-electron particle gun.
@ IsoMuon
Isolated (prompt) muon.
@ NonIsoElectron
Non-isolated electron from J/psi, B/D hadron, tau, muon or quark weak decay.
@ GenParticle
Generator-level intermediate particle (decayed, or otherwise not a final-state candidate) that is not...
@ UnknownPhoton
Photon with undefined origin.
@ UnknownElectron
Electron with undefined origin (no production vertex, or origin could not be traced).
@ Hadron
Any hadron (neither the beam nor a nuclear fragment); the origin is not studied further.
@ BkgElectron
Background electron: photon conversion, Dalitz decay, material interaction, light-hadron decay,...
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isMuon(const T &p)
Type
truth classification type enum
bool isInDeltaR(const xAOD::IParticle &p1, const xAOD::IParticle &p2, double dR, bool useRapidity=true)
Check if 2 xAOD::IParticle are in a cone.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
Definition Muon.h:13
Electron_v1 Electron
Definition of the current "egamma version".
Definition Electron.h:17