ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
8
9namespace ActsTrk {
10
12 const std::string& name,
13 const IInterface* parent)
14 : AthAlgTool(type, name, parent) {}
15
17
18 // initialize all the conatiners needed
19 ATH_CHECK(m_pixelClustersKey.initialize());
21 ATH_CHECK(m_stripClustersKey.initialize());
23
24 return StatusCode::SUCCESS;
25}
26
27template <typename ClusterContainer>
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
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
65
67 pixelTruthAssociations{m_pixelTruthAssociationKey, ctx};
68
69 if (!pixelClusters.isValid()) {
70
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: "
80 return StatusCode::FAILURE;
81 }
82
83 addClusterToTruthTracks(*pixelClusters, *pixelTruthAssociations,
84 truthTracks);
85 }
86
88
91
93 stripTruthAssociations{m_stripTruthAssociationKey, ctx};
94
95 if (!stripClusters.isValid()) {
96
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: "
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
bool hit(const Container &ids, int pdgId)
SG::ReadHandleKey< xAOD::StripClusterContainer > m_stripClustersKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_pixelClustersKey
StatusCode buildTruthTracks(const EventContext &ctx, TruthTracks &truthTracks) const
Gaudi::Property< bool > m_useStripClusters
Gaudi::Property< bool > m_usePixelClusters
void addClusterToTruthTracks(const ClusterContainer &clusters, const MeasurementToTruthParticleAssociation &truthAssociations, TruthTracks &truthTracks) const
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_pixelTruthAssociationKey
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_stripTruthAssociationKey
TruthTrackBuilderTool(const std::string &type, const std::string &name, const IInterface *parent)
std::unordered_map< const xAOD::TruthParticle *, TruthHits > TruthTracks
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual bool isValid() override final
Can the handle be successfully dereferenced?
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.