ATLAS Offline Software
Loading...
Searching...
No Matches
PartonHistoryUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9
10#include <cmath>
11
12namespace {
13// Returns the first child with the same PDG ID as p, or nullptr if none.
14// A broken truth link within nChildren() is treated like a missing child.
15const xAOD::TruthParticle* findIdenticalChild(const xAOD::TruthParticle& p) {
16 for (size_t i = 0; i < p.nChildren(); i++) {
17 const xAOD::TruthParticle* child = p.child(i);
18 if (child && child->pdgId() == p.pdgId())
19 return child;
20 }
21 return nullptr;
22}
23} // namespace
24
25namespace CP {
26namespace PartonHistoryUtils {
27
31
32bool hasParentPdgId(const xAOD::TruthParticle& p, int pdgId) {
33 // No parent recorded, or a broken truth link to it, is treated as "no
34 // parent".
35 if (p.nParents() == 0)
36 return false;
37 const xAOD::TruthParticle* parent = p.parent(0);
38 // Checks if the parent of the given particle has a specific PDG ID.
39 return parent && parent->pdgId() == pdgId;
40}
41
43 // Checks if the parent of the given particle has a specific PDG ID.
44 return hasParentPdgId(p, p.pdgId());
45}
46
48 // Checks if the given particle has at least one child with an identical PDG
49 // ID.
50 return findIdenticalChild(p) != nullptr;
51}
52
53bool hasParentAbsPdgId(const xAOD::TruthParticle& p, int absPdgId) {
54 // No parent recorded, or a broken truth link to it, is treated as "no
55 // parent".
56 if (p.nParents() == 0)
57 return false;
58 const xAOD::TruthParticle* parent = p.parent(0);
59 // Checks if the parent of the given particle has a specific absolute PDG ID.
60 return parent && parent->absPdgId() == absPdgId;
61}
62
64 // Checks if particle and any of its parents are identical. A broken
65 // parent truth link is treated as "not identical".
66 for (size_t i = 0; i < p.nParents(); i++) {
67 const xAOD::TruthParticle* parent = p.parent(i);
68 if (parent && parent->pdgId() == p.pdgId())
69 return true;
70 } // for
71 return false;
72}
73
74bool isChildOf(const xAOD::TruthParticle& parent,
75 const xAOD::TruthParticle& child) {
76 // Checks if child is child of parent.
77 if (parent.uid() == child.uid()) {
78 return true;
79 }
80 // Loop through all children of the parent
81 for (size_t i = 0; i < parent.nChildren(); ++i) {
82 const xAOD::TruthParticle* c = parent.child(i);
83 // A broken child truth link is treated as "not this child" and skipped.
84 // Recursively check if child is a child of the current child
85 if (c && isChildOf(*c, child)) {
86 return true;
87 }
88 }
89 // If child is not found in the children or their descendants, return
90 // false
91 return false;
92}
93
97
99 return !hasIdenticalChild(p);
100}
101
103 // Follow the chain of identical children down to the last copy.
104 const xAOD::TruthParticle* current = &p;
105 while (const xAOD::TruthParticle* child = findIdenticalChild(*current))
106 current = child;
107 return *current;
108}
109
113
115 // check if particle is a top without children.
116 return (p.absPdgId() == 6 && p.nChildren() == 0);
117}
118
119bool isQuarkFromPDF(const xAOD::TruthParticle& particle) {
120 // In principle we could use some status codes here, e.g. 31/41/42/53/61 for
121 // Pythia 8. But that is not guaranteed to be compatible across generators,
122 // so instead we just check if it's a massless quark.
123 bool isQuark = 1 <= particle.absPdgId() && particle.absPdgId() <= 5;
124 bool isMassless = particle.m() == 0;
125 return isQuark && isMassless;
126}
127
128
129} // namespace PartonHistoryUtils
130} // namespace CP
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to do ...
Definition AtlasPID.h:173
int pdgId() const
PDG ID code.
int uid() const
Unique ID.
bool isQuarkFromPDF(const xAOD::TruthParticle &particle)
bool hasParentAbsPdgId(const xAOD::TruthParticle &particle, int absPdgId)
bool hasIdenticalChild(const xAOD::TruthParticle &particle)
bool isBrokenTop(const xAOD::TruthParticle &particle)
Looking for tops without children -> must be broken.
bool hasParentPdgId(const xAOD::TruthParticle &particle, int PdgId)
const xAOD::TruthParticle & findAfterFSR(const xAOD::TruthParticle &particle)
Return particle after FSR (before the decay vertex).
bool isChildOf(const xAOD::TruthParticle &parent, const xAOD::TruthParticle &potentialChild)
bool isAfterFSR(const xAOD::TruthParticle &particle)
Determine whether particle is afterFSR.
bool hasParticleIdenticalParent(const xAOD::TruthParticle &particle)
Return true when any parent of the particle has the same pdgId as the particle.
Select isolated Photons, Electrons and Muons.
TruthParticle_v1 TruthParticle
Typedef to implementation.