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
11
13
14namespace CP {
15namespace PartonHistoryUtils {
16
20
21bool hasParentPdgId(const xAOD::TruthParticle* p, int pdgId) {
22 // Checks if the particle or its parent are nullptr.
23 if (!p || !p->parent(0)) {
24 return false;
25 }
26 // Checks if the parent of the given particle has a specific PDG ID.
27 return p->parent(0)->pdgId() == pdgId;
28}
29
31 // Checks if the parent of the given particle has a specific PDG ID.
32 return hasParentPdgId(p, p->pdgId());
33}
34
36 // Checks if the given particle has at least one child with an identical PDG
37 // ID.
38 bool check = false;
39 for (size_t i = 0; i < p->nChildren(); i++) {
40 if (p->child(i) && p->child(i)->pdgId() == p->pdgId())
41 check = true;
42 }
43 return check;
44}
45
46bool hasParentAbsPdgId(const xAOD::TruthParticle* p, int absPdgId) {
47 // Checks if the parent of the given particle has a specific absolute PDG ID.
48 return p->parent(0) && p->parent(0)->absPdgId() == absPdgId;
49}
50
52 // Checks if particle and any of ity parents are identical.
53 bool skipit(false);
54 for (size_t i = 0; i < p->nParents(); i++) {
55 const xAOD::TruthParticle* parent = p->parent(i);
56 if (parent && parent->pdgId() == p->pdgId()) {
57 skipit = true;
58 break;
59 } // if
60 } // for
61 return skipit;
62}
63
64bool isChildOf(const xAOD::TruthParticle* parent,
65 const xAOD::TruthParticle* child) {
66 // Checks if child is child of parent.
67 if (!(parent && child))
68 return false;
69 if (parent->uid() == child->uid()) {
70 return true;
71 }
72 // Loop through all children of the parent
73 for (size_t i = 0; i < parent->nChildren(); ++i) {
74 // Recursively check if child is a child of the current child
75 if (isChildOf(parent->child(i), child)) {
76 return true;
77 }
78 }
79 // If child is not found in the children or their descendants, return
80 // false
81 return false;
82}
83
87
89 bool isAfter = true;
90 for (size_t j = 0; j < p->nChildren(); j++) {
91 if (p->child(j) && p->child(j)->pdgId() == p->pdgId())
92 isAfter = false;
93 }
94 return isAfter;
95}
96
98 bool isAfter(false);
99 const int pdgId = p->pdgId();
100 int i = 0;
101 while (!isAfter) {
102 i = 0;
103 for (size_t j = 0; j < p->nChildren(); j++) {
104 const xAOD::TruthParticle* tmp_children = p->child(j);
105 if (tmp_children && tmp_children->pdgId() == pdgId) {
106 p = p->child(j);
107 i++;
108 break;
109 } // if
110 } // for
111 if (i == 0)
112 isAfter = true;
113 } // while
114 return p;
115}
116
120
122 // check if particle is a top without children.
123 return (p->pdgId() == 6 && p->nChildren() == 0);
124}
125
126std::string getretrievalstring(const std::string& parent,
127 const std::string& suffix,
128 const std::string& postfix) {
129 std::string baseprefix = "MC_";
130 return baseprefix + (parent.empty() ? "" : parent + "_") + suffix + postfix;
131}
132
133} // namespace PartonHistoryUtils
134} // namespace CP
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 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.