ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkTools
TrkTruthCreatorTools
src
ElasticTruthTrajectoryBuilder.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/ElasticTruthTrajectoryBuilder.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
20
namespace
Trk
{
21
22
//================================================================
23
ElasticTruthTrajectoryBuilder::
24
ElasticTruthTrajectoryBuilder
(
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
ElasticTruthTrajectoryBuilder::initialize
() {
35
return
StatusCode::SUCCESS;
36
}
37
38
//================================================================
39
void
ElasticTruthTrajectoryBuilder::
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
ElasticTruthTrajectoryBuilder::MotherDaughter
76
ElasticTruthTrajectoryBuilder::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
if
(vtx && (vtx->particles_in_size() == 1)) {
82
mother = vtx->particles_in().front();
83
// Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2.
84
if
( mother &&
MC::isPhysical
(mother) ) {
85
86
// Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta).
87
//
88
// Require not more than 2 outgoing particles. Note that
89
// delta-rays for primary==electron is a special case, because we have two
90
// outgoing particles with the same PDG id. The "correct" one
91
// is that with the higher energy (NOT pt).
92
//
93
// allow 1 outgoing to cover possible vertexes from interaction in detector material
94
if
(vtx->particles_out_size() <= 2) {
95
int
num_passed_cuts = 0;
96
HepMC::ConstGenParticlePtr
passed_cuts{
nullptr
};
97
for
(
const
auto
& 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
}
else
{
105
passed_cuts = candidate;
106
++num_passed_cuts;
107
}
108
}
109
}
110
111
if
(num_passed_cuts==1) {
// disallow hadronic pi->N*pi etc.
112
daughter = std::move(passed_cuts);
113
}
114
115
}
116
}
117
}
118
119
return
std::make_pair(mother, daughter);
120
}
121
122
//================================================================
123
HepMC::ConstGenParticlePtr
ElasticTruthTrajectoryBuilder::getDaughter
(
const
HepMC::ConstGenParticlePtr
& mother)
const
{
124
if
(mother) {
125
MotherDaughter
res
=
truthTrajectoryCuts
(mother->end_vertex());
126
if
(
res
.first == mother)
return
res
.second;
127
}
128
return
{
nullptr
};
129
}
130
131
//================================================================
132
HepMC::ConstGenParticlePtr
ElasticTruthTrajectoryBuilder::getMother
(
const
HepMC::ConstGenParticlePtr
& daughter)
const
{
133
if
(daughter) {
134
MotherDaughter
res
=
truthTrajectoryCuts
(daughter->production_vertex());
135
if
(
res
.second == daughter)
return
res
.first;
136
}
137
return
{
nullptr
};
138
}
139
140
//================================================================
141
142
}
// namespace Trk
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
ElasticTruthTrajectoryBuilder.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::ElasticTruthTrajectoryBuilder::ElasticTruthTrajectoryBuilder
ElasticTruthTrajectoryBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Definition
ElasticTruthTrajectoryBuilder.cxx:24
Trk::ElasticTruthTrajectoryBuilder::truthTrajectoryCuts
static MotherDaughter truthTrajectoryCuts(const HepMC::ConstGenVertexPtr &vtx)
Decides if the vertex connects two particles on the same TruthTrajectory.
Definition
ElasticTruthTrajectoryBuilder.cxx:76
Trk::ElasticTruthTrajectoryBuilder::initialize
virtual StatusCode initialize()
Definition
ElasticTruthTrajectoryBuilder.cxx:34
Trk::ElasticTruthTrajectoryBuilder::getMother
HepMC::ConstGenParticlePtr getMother(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
Definition
ElasticTruthTrajectoryBuilder.cxx:132
Trk::ElasticTruthTrajectoryBuilder::buildTruthTrajectory
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::ConstGenParticlePtr &input) const
Build a TruthTrajectory this particle belongs to.
Definition
ElasticTruthTrajectoryBuilder.cxx:40
Trk::ElasticTruthTrajectoryBuilder::MotherDaughter
std::pair< HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr > MotherDaughter
Return type for the next method.
Definition
ElasticTruthTrajectoryBuilder.h:39
Trk::ElasticTruthTrajectoryBuilder::getDaughter
HepMC::ConstGenParticlePtr getDaughter(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
Definition
ElasticTruthTrajectoryBuilder.cxx:123
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