ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsTruth
src
TruthTrackBuilderTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TruthTrackBuilderTool.h
"
6
7
#include "
xAODTruth/TruthVertex.h
"
8
9
namespace
ActsTrk
{
10
11
TruthTrackBuilderTool::TruthTrackBuilderTool
(
const
std::string&
type
,
12
const
std::string& name,
13
const
IInterface* parent)
14
:
AthAlgTool
(
type
, name, parent) {}
15
16
StatusCode
TruthTrackBuilderTool::initialize
() {
17
18
// initialize all the conatiners needed
19
ATH_CHECK
(
m_pixelClustersKey
.initialize());
20
ATH_CHECK
(
m_pixelTruthAssociationKey
.initialize());
21
ATH_CHECK
(
m_stripClustersKey
.initialize());
22
ATH_CHECK
(
m_stripTruthAssociationKey
.initialize());
23
24
return
StatusCode::SUCCESS;
25
}
26
27
template
<
typename
ClusterContainer>
28
void
TruthTrackBuilderTool::addClusterToTruthTracks
(
29
const
ClusterContainer& clusters,
30
const
MeasurementToTruthParticleAssociation
& truthAssociations,
31
TruthTracks
& truthTracks)
const
{
32
33
for
(
const
auto
* cluster : clusters) {
34
35
const
auto
& matchedTruthParticles = truthAssociations.at(cluster->index());
36
37
// if no truth particles for cluster, skip
38
if
(matchedTruthParticles.empty()) {
39
ATH_MSG_WARNING
(
"empty truth particle vector for cluster, skipping"
);
40
continue
;
41
}
42
43
// only taking leading order truth particle
44
// (most likely to be the correct truth match as it has largest depsoit in
45
// cluster)
46
const
xAOD::TruthParticle
* truthParticle = matchedTruthParticles.front();
47
48
// obtain global position of cluster before upcasting (makes sorting easier)
49
const
auto
& globalPosition = cluster->globalPosition();
50
TruthHit
hit
{cluster, globalPosition};
51
52
truthTracks[truthParticle].push_back(
hit
);
53
}
54
}
55
56
StatusCode
TruthTrackBuilderTool::buildTruthTracks
(
57
const
EventContext& ctx,
TruthTracks
& truthTracks)
const
{
58
59
// obtain truth map and clusters
60
// for every cluster, obtain its truth particle and add to map
61
// This can be optional for both pixel and strip clusters
62
if
(
m_usePixelClusters
) {
63
SG::ReadHandle<xAOD::PixelClusterContainer>
pixelClusters{
64
m_pixelClustersKey
, ctx};
65
66
SG::ReadHandle<MeasurementToTruthParticleAssociation>
67
pixelTruthAssociations{
m_pixelTruthAssociationKey
, ctx};
68
69
if
(!pixelClusters.
isValid
()) {
70
71
ATH_MSG_ERROR
(
72
"Could not read pixel clusters: "
<<
m_pixelClustersKey
.key());
73
return
StatusCode::FAILURE;
74
}
75
76
if
(!pixelTruthAssociations.
isValid
()) {
77
78
ATH_MSG_ERROR
(
"Could not read pixel truth associations: "
79
<<
m_pixelTruthAssociationKey
.key());
80
return
StatusCode::FAILURE;
81
}
82
83
addClusterToTruthTracks
(*pixelClusters, *pixelTruthAssociations,
84
truthTracks);
85
}
86
87
if
(
m_useStripClusters
) {
88
89
SG::ReadHandle<xAOD::StripClusterContainer>
stripClusters{
90
m_stripClustersKey
, ctx};
91
92
SG::ReadHandle<MeasurementToTruthParticleAssociation>
93
stripTruthAssociations{
m_stripTruthAssociationKey
, ctx};
94
95
if
(!stripClusters.
isValid
()) {
96
97
ATH_MSG_ERROR
(
98
"Could not read strip clusters: "
<<
m_stripClustersKey
.key());
99
return
StatusCode::FAILURE;
100
}
101
102
if
(!stripTruthAssociations.
isValid
()) {
103
104
ATH_MSG_ERROR
(
"Could not read strip truth associations: "
105
<<
m_stripTruthAssociationKey
.key());
106
return
StatusCode::FAILURE;
107
}
108
109
addClusterToTruthTracks
(*stripClusters, *stripTruthAssociations,
110
truthTracks);
111
}
112
113
// reorder clusters for each associated truth particle
114
// This is done by ordering by distance away from truth particle production
115
// vertex (assuming small bending)
116
for
(
auto
it = truthTracks.begin(); it != truthTracks.end();) {
117
118
auto
& [truthParticle, truthClusters] = *it;
119
120
if
(truthParticle ==
nullptr
|| !truthParticle->hasProdVtx()) {
121
122
ATH_MSG_WARNING
(
123
"Truth particle does not have a production vertex, erasing"
);
124
it = truthTracks.erase(it);
125
continue
;
126
}
127
128
const
xAOD::TruthVertex
* vertex = truthParticle->prodVtx();
129
const
Vector3
vertexPosition{vertex->x(), vertex->y(), vertex->z()};
130
std::sort
(truthClusters.begin(), truthClusters.end(),
131
[&vertexPosition](
const
TruthHit
& firstCluster,
132
const
TruthHit
& secondCluster) {
133
const Vector3 firstClusterDis =
134
firstCluster.globalPosition - vertexPosition;
135
const Vector3 secondClusterDis =
136
secondCluster.globalPosition - vertexPosition;
137
138
const float firstClusterNorm = firstClusterDis.squaredNorm();
139
const float secondClusterNorm = secondClusterDis.squaredNorm();
140
141
return firstClusterNorm < secondClusterNorm;
142
});
143
144
++it;
145
}
146
147
return
StatusCode::SUCCESS;
148
}
149
150
}
// namespace ActsTrk
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
TruthTrackBuilderTool.h
TruthVertex.h
ActsTrk::MeasurementToTruthParticleAssociation
Definition
MeasurementToTruthParticleAssociation.h:18
ActsTrk::TruthTrackBuilderTool::m_stripClustersKey
SG::ReadHandleKey< xAOD::StripClusterContainer > m_stripClustersKey
Definition
TruthTrackBuilderTool.h:56
ActsTrk::TruthTrackBuilderTool::m_pixelClustersKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClustersKey
Definition
TruthTrackBuilderTool.h:47
ActsTrk::TruthTrackBuilderTool::buildTruthTracks
StatusCode buildTruthTracks(const EventContext &ctx, TruthTracks &truthTracks) const
Definition
TruthTrackBuilderTool.cxx:56
ActsTrk::TruthTrackBuilderTool::m_useStripClusters
Gaudi::Property< bool > m_useStripClusters
Definition
TruthTrackBuilderTool.h:68
ActsTrk::TruthTrackBuilderTool::m_usePixelClusters
Gaudi::Property< bool > m_usePixelClusters
Definition
TruthTrackBuilderTool.h:66
ActsTrk::TruthTrackBuilderTool::initialize
StatusCode initialize() override
Definition
TruthTrackBuilderTool.cxx:16
ActsTrk::TruthTrackBuilderTool::addClusterToTruthTracks
void addClusterToTruthTracks(const ClusterContainer &clusters, const MeasurementToTruthParticleAssociation &truthAssociations, TruthTracks &truthTracks) const
Definition
TruthTrackBuilderTool.cxx:28
ActsTrk::TruthTrackBuilderTool::m_pixelTruthAssociationKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_pixelTruthAssociationKey
Definition
TruthTrackBuilderTool.h:51
ActsTrk::TruthTrackBuilderTool::m_stripTruthAssociationKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_stripTruthAssociationKey
Definition
TruthTrackBuilderTool.h:60
ActsTrk::TruthTrackBuilderTool::TruthTrackBuilderTool
TruthTrackBuilderTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition
TruthTrackBuilderTool.cxx:11
ActsTrk::TruthTrackBuilderTool::Vector3
Eigen::Vector3f Vector3
Definition
TruthTrackBuilderTool.h:23
ActsTrk::TruthTrackBuilderTool::TruthTracks
std::unordered_map< const xAOD::TruthParticle *, TruthHits > TruthTracks
Definition
TruthTrackBuilderTool.h:32
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition
MdtCalibInput.h:31
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition
TruthVertex.h:15
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
ActsTrk::TruthTrackBuilderTool::TruthHit
Definition
TruthTrackBuilderTool.h:25
type
Generated on
for ATLAS Offline Software by
1.17.0