ATLAS Offline Software
Loading...
Searching...
No Matches
PartonHistoryUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9
10namespace CP {
11namespace PartonHistoryUtils {
12
16
17bool hasParentPdgId(const xAOD::TruthParticle* p, int pdgId) {
18 // Checks if the particle or its parent are nullptr.
19 if (!p || !p->parent(0)) {
20 return false;
21 }
22 // Checks if the parent of the given particle has a specific PDG ID.
23 return p->parent(0)->pdgId() == pdgId;
24}
25
27 // Checks if the parent of the given particle has a specific PDG ID.
28 return hasParentPdgId(p, p->pdgId());
29}
30
32 // Checks if the given particle has at least one child with an identical PDG
33 // ID.
34 bool check = false;
35 for (size_t i = 0; i < p->nChildren(); i++) {
36 if (p->child(i) && p->child(i)->pdgId() == p->pdgId())
37 check = true;
38 }
39 return check;
40}
41
42bool hasParentAbsPdgId(const xAOD::TruthParticle* p, int absPdgId) {
43 // Checks if the parent of the given particle has a specific absolute PDG ID.
44 return p->parent(0) && p->parent(0)->absPdgId() == absPdgId;
45}
46
48 // Checks if particle and any of ity parents are identical.
49 bool skipit(false);
50 for (size_t i = 0; i < p->nParents(); i++) {
51 const xAOD::TruthParticle* parent = p->parent(i);
52 if (parent && parent->pdgId() == p->pdgId()) {
53 skipit = true;
54 break;
55 } // if
56 } // for
57 return skipit;
58}
59
60bool isChildOf(const xAOD::TruthParticle* parent,
61 const xAOD::TruthParticle* child) {
62 // Checks if child is child of parent.
63 if (!(parent && child))
64 return false;
65 if (parent->uid() == child->uid()) {
66 return true;
67 }
68 // Loop through all children of the parent
69 for (size_t i = 0; i < parent->nChildren(); ++i) {
70 // Recursively check if child is a child of the current child
71 if (isChildOf(parent->child(i), child)) {
72 return true;
73 }
74 }
75 // If child is not found in the children or their descendants, return
76 // false
77 return false;
78}
79
83
85 bool isAfter = true;
86 for (size_t j = 0; j < p->nChildren(); j++) {
87 if (p->child(j) && p->child(j)->pdgId() == p->pdgId())
88 isAfter = false;
89 }
90 return isAfter;
91}
92
94 bool isAfter(false);
95 const int pdgId = p->pdgId();
96 int i = 0;
97 while (!isAfter) {
98 i = 0;
99 for (size_t j = 0; j < p->nChildren(); j++) {
100 const xAOD::TruthParticle* tmp_children = p->child(j);
101 if (tmp_children && tmp_children->pdgId() == pdgId) {
102 p = p->child(j);
103 i++;
104 break;
105 } // if
106 } // for
107 if (i == 0)
108 isAfter = true;
109 } // while
110 return p;
111}
112
116
118 // check if particle is a top without children.
119 return (p->pdgId() == 6 && p->nChildren() == 0);
120}
121
122std::string getretrievalstring(const std::string& parent,
123 const std::string& suffix,
124 const std::string& postfix) {
125 std::string baseprefix = "MC_";
126 return baseprefix + (parent.empty() ? "" : parent + "_") + suffix + postfix;
127}
128
129bool isQuarkFromPDF(const xAOD::TruthParticle* particle) {
130 // In principle we could use some status codes here, e.g. 31/41/42/53/61 for
131 // Pythia 8. But that is not guaranteed to be compatible across generators,
132 // so instead we just check if it's a massless quark.
133 bool isQuark = 1 <= particle->absPdgId() && particle->absPdgId() <= 5;
134 bool isMassless = particle->m() == 0;
135 return isQuark && isMassless;
136}
137
138
139} // namespace PartonHistoryUtils
140} // 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:167
int pdgId() const
PDG ID code.
int uid() const
Unique ID.
bool hasIdenticalChild(const xAOD::TruthParticle *particle)
bool hasParticleIdenticalParent(const xAOD::TruthParticle *particle)
Return true when particle is a top before FSR.
bool isQuarkFromPDF(const xAOD::TruthParticle *particle)
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.
std::string getretrievalstring(const std::string &parent, const std::string &suffix, const std::string &postfix)
bool isBrokenTop(const xAOD::TruthParticle *particle)
Looking for tops without children -> must be broken.
bool hasParentAbsPdgId(const xAOD::TruthParticle *particle, int absPdgId)
Select isolated Photons, Electrons and Muons.
TruthParticle_v1 TruthParticle
Typedef to implementation.