ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkTools
TrkTruthCreatorTools
src
DecayInFlyTruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Andrei Gaponenko, 2008
6
7
#include "
TrkTruthCreatorTools/DecayInFlyTruthTrajectoryBuilder.h
"
8
9
#include "
TrkTruthData/TruthTrajectory.h
"
10
11
#include "
AtlasHepMC/GenParticle.h
"
12
#include "
AtlasHepMC/GenVertex.h
"
13
#include "
TruthUtils/HepMCHelpers.h
"
14
15
#include "
GeneratorObjects/HepMcParticleLink.h
"
16
#include "
AthContainers/DataVector.h
"
17
18
#include <stack>
19
#include <cmath>
20
namespace
Trk
{
21
22
//================================================================
23
DecayInFlyTruthTrajectoryBuilder::
24
DecayInFlyTruthTrajectoryBuilder
(
const
std::string&
type
,
25
const
std::string& name,
26
const
IInterface* parent)
27
:
AthAlgTool
(
type
,name,parent)
28
{
29
declareInterface<Trk::ITruthTrajectoryBuilder>(
this
);
30
}
31
32
33
//================================================================
34
StatusCode
DecayInFlyTruthTrajectoryBuilder::initialize
() {
35
return
StatusCode::SUCCESS;
36
}
37
38
//================================================================
39
void
DecayInFlyTruthTrajectoryBuilder::
40
buildTruthTrajectory
(
TruthTrajectory
*result,
const
HepMC::ConstGenParticlePtr
& input)
const
41
{
42
result->clear();
43
if
(input) {
44
HepMC::ConstGenParticlePtr
next
{
nullptr
};
45
HepMC::ConstGenParticlePtr
current = input;
46
47
// Extend trajectory outwards. The last particle should go at [0]
48
// in the TruthTrajectory, so we need to use a tmp storage while
49
// traversing the structure.
50
std::stack<HepMC::ConstGenParticlePtr> tmp;
51
while
( (
next
=
getDaughter
(current)) ) {
52
tmp.push(current =
next
);
53
}
54
55
// All particles in the TruthTrajectory will be from the same GenEvent
56
const
int
eventNumber = input->parent_event()->event_number();
57
58
// copy the outer half to result
59
while
(!tmp.empty()) {
60
result->emplace_back(tmp.top(), eventNumber,
HepMcParticleLink::IS_EVENTNUM
);
61
tmp.pop();
62
}
63
64
// The input particle itself
65
result->emplace_back(input, eventNumber,
HepMcParticleLink::IS_EVENTNUM
);
66
67
// Now continue towards the interaction point
68
while
( (
next
=
getMother
(current)) ) {
69
result->emplace_back(current =
next
, eventNumber,
HepMcParticleLink::IS_EVENTNUM
);
70
}
71
}
72
}
73
74
//================================================================
75
DecayInFlyTruthTrajectoryBuilder::MotherDaughter
76
DecayInFlyTruthTrajectoryBuilder::truthTrajectoryCuts
(
const
HepMC::ConstGenVertexPtr
& vtx)
77
{
78
HepMC::ConstGenParticlePtr
mother{
nullptr
};
79
HepMC::ConstGenParticlePtr
daughter{
nullptr
};
80
// only truth vertices with 1 incoming particle
81
// Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta).
82
//
83
// Require not more than 2 outgoing particles. Note that
84
// delta-rays for primary==electron is a special case, because we have two
85
// outgoing particles with the same PDG id. The "correct" one
86
// is that with the higher energy (NOT pt).
87
//
88
// allow 1 outgoing to cover possible vertexes from interaction in detector material
89
if
(vtx && (vtx->particles_in_size() == 1) && (vtx->particles_out_size() <= 2) ) {
90
91
mother = vtx->particles_in().front();
92
// Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2.
93
if
( mother &&
MC::isPhysical
(mother) ) {
94
95
int
num_passed_cuts = 0;
96
HepMC::ConstGenParticlePtr
passed_cuts{
nullptr
};
97
for
(
const
HepMC::ConstGenParticlePtr
& candidate: *vtx){
98
if
(candidate->pdg_id() == mother->pdg_id()) {
99
100
if
(passed_cuts &&
MC::isElectron
(mother)) {
// second negative electron is a special case
101
if
(candidate->momentum().e() > passed_cuts->momentum().e()) {
102
passed_cuts = candidate;
// don't increment num_passed_cuts, we are replacing chosen particle
103
}
104
}
105
else
{
106
passed_cuts = candidate;
107
++num_passed_cuts;
108
}
109
}
110
// allow pi/k->mu decay
111
else
if
(std::abs(candidate->pdg_id()) == 13){
112
passed_cuts = candidate;
113
++num_passed_cuts;
114
}
115
}
116
117
if
(num_passed_cuts==1) {
// disallow hadronic pi->N*pi etc.
118
daughter = std::move(passed_cuts);
119
}
120
}
121
}
122
123
return
std::make_pair(mother, daughter);
124
}
125
126
//================================================================
127
HepMC::ConstGenParticlePtr
DecayInFlyTruthTrajectoryBuilder::getDaughter
(
const
HepMC::ConstGenParticlePtr
& mother)
const
{
128
if
(mother) {
129
MotherDaughter
res
=
truthTrajectoryCuts
(mother->end_vertex());
130
if
(
res
.first == mother)
return
res
.second;
131
}
132
return
{
nullptr
};
133
}
134
135
//================================================================
136
HepMC::ConstGenParticlePtr
DecayInFlyTruthTrajectoryBuilder::getMother
(
const
HepMC::ConstGenParticlePtr
& daughter)
const
{
137
if
(daughter) {
138
MotherDaughter
res
=
truthTrajectoryCuts
(daughter->production_vertex());
139
if
(
res
.second == daughter)
return
res
.first;
140
}
141
return
{
nullptr
};
142
}
143
144
//================================================================
145
146
}
// namespace Trk
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
DecayInFlyTruthTrajectoryBuilder.h
GenParticle.h
GenVertex.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
HepMcParticleLink.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition
JetGroupProductTest.cxx:11
TruthTrajectory.h
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
HepMcParticleLink::IS_EVENTNUM
@ IS_EVENTNUM
Definition
HepMcParticleLink.h:79
Trk::DecayInFlyTruthTrajectoryBuilder::buildTruthTrajectory
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::ConstGenParticlePtr &input) const
Build a TruthTrajectory this particle belongs to.
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:40
Trk::DecayInFlyTruthTrajectoryBuilder::getDaughter
HepMC::ConstGenParticlePtr getDaughter(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:127
Trk::DecayInFlyTruthTrajectoryBuilder::initialize
virtual StatusCode initialize()
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:34
Trk::DecayInFlyTruthTrajectoryBuilder::getMother
HepMC::ConstGenParticlePtr getMother(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:136
Trk::DecayInFlyTruthTrajectoryBuilder::truthTrajectoryCuts
static MotherDaughter truthTrajectoryCuts(const HepMC::ConstGenVertexPtr &vtx)
Decides if the vertex connects two particles on the same TruthTrajectory.
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:76
Trk::DecayInFlyTruthTrajectoryBuilder::MotherDaughter
std::pair< HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr > MotherDaughter
Return type for the next method.
Definition
DecayInFlyTruthTrajectoryBuilder.h:39
Trk::DecayInFlyTruthTrajectoryBuilder::DecayInFlyTruthTrajectoryBuilder
DecayInFlyTruthTrajectoryBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Definition
DecayInFlyTruthTrajectoryBuilder.cxx:24
TruthTrajectory
A TruthTrajectory is a chain of charged MC particles connected through the mother-daughter relationsh...
Definition
TruthTrajectory.h:26
HepMC::ConstGenParticlePtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition
GenParticle.h:20
HepMC::ConstGenVertexPtr
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition
GenVertex.h:24
MC::isElectron
bool isElectron(const T &p)
Definition
HepMCHelpers.h:209
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition
HepMCHelpers.h:52
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition
FakeTrackBuilder.h:9
Trk::next
@ next
Definition
BinningData.h:35
type
Generated on
for ATLAS Offline Software by
1.17.0