ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
TruthPartonLevelAnalysisAlgorithms
Root
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
8
#include "
PartonHistory/PartonHistoryUtils.h
"
9
10
#include <cmath>
11
12
namespace
{
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.
15
const
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
25
namespace
CP
{
26
namespace
PartonHistoryUtils
{
27
31
32
bool
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
42
bool
hasParentPdgId
(
const
xAOD::TruthParticle
& p) {
43
// Checks if the parent of the given particle has a specific PDG ID.
44
return
hasParentPdgId
(p, p.pdgId());
45
}
46
47
bool
hasIdenticalChild
(
const
xAOD::TruthParticle
& p) {
48
// Checks if the given particle has at least one child with an identical PDG
49
// ID.
50
return
findIdenticalChild(p) !=
nullptr
;
51
}
52
53
bool
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
63
bool
hasParticleIdenticalParent
(
const
xAOD::TruthParticle
& p) {
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
74
bool
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
98
bool
isAfterFSR
(
const
xAOD::TruthParticle
& p) {
99
return
!
hasIdenticalChild
(p);
100
}
101
102
const
xAOD::TruthParticle
&
findAfterFSR
(
const
xAOD::TruthParticle
& p) {
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
114
bool
isBrokenTop
(
const
xAOD::TruthParticle
& p) {
115
// check if particle is a top without children.
116
return
(p.absPdgId() == 6 && p.nChildren() == 0);
117
}
118
119
bool
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
isQuark
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
PartonHistoryUtils.h
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
xAOD::TruthParticle_v1::uid
int uid() const
Unique ID.
CP::PartonHistoryUtils
Definition
PartonHistoryUtils.h:16
CP::PartonHistoryUtils::isQuarkFromPDF
bool isQuarkFromPDF(const xAOD::TruthParticle &particle)
Definition
PartonHistoryUtils.cxx:119
CP::PartonHistoryUtils::hasParentAbsPdgId
bool hasParentAbsPdgId(const xAOD::TruthParticle &particle, int absPdgId)
Definition
PartonHistoryUtils.cxx:53
CP::PartonHistoryUtils::hasIdenticalChild
bool hasIdenticalChild(const xAOD::TruthParticle &particle)
Definition
PartonHistoryUtils.cxx:47
CP::PartonHistoryUtils::isBrokenTop
bool isBrokenTop(const xAOD::TruthParticle &particle)
Looking for tops without children -> must be broken.
Definition
PartonHistoryUtils.cxx:114
CP::PartonHistoryUtils::hasParentPdgId
bool hasParentPdgId(const xAOD::TruthParticle &particle, int PdgId)
Definition
PartonHistoryUtils.cxx:32
CP::PartonHistoryUtils::findAfterFSR
const xAOD::TruthParticle & findAfterFSR(const xAOD::TruthParticle &particle)
Return particle after FSR (before the decay vertex).
Definition
PartonHistoryUtils.cxx:102
CP::PartonHistoryUtils::isChildOf
bool isChildOf(const xAOD::TruthParticle &parent, const xAOD::TruthParticle &potentialChild)
Definition
PartonHistoryUtils.cxx:74
CP::PartonHistoryUtils::isAfterFSR
bool isAfterFSR(const xAOD::TruthParticle &particle)
Determine whether particle is afterFSR.
Definition
PartonHistoryUtils.cxx:98
CP::PartonHistoryUtils::hasParticleIdenticalParent
bool hasParticleIdenticalParent(const xAOD::TruthParticle &particle)
Return true when any parent of the particle has the same pdgId as the particle.
Definition
PartonHistoryUtils.cxx:63
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
lumiFormat.i
int i
Definition
lumiFormat.py:85
python.utils.AtlRunQueryDQUtils.p
p
Definition
AtlRunQueryDQUtils.py:209
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
Generated on
for ATLAS Offline Software by
1.17.0