ATLAS Offline Software
Loading...
Searching...
No Matches
GbtsSeedingTool.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#if defined(FLATTEN) && defined(__GNUC__)
6// Avoid warning in dbg build
7#pragma GCC optimize "-fno-var-tracking-assignments"
8#endif
9
10#include "src/GbtsSeedingTool.h"
11
13
14#include <algorithm>
15#include <fstream>
16#include <memory>
17#include <unordered_map>
18#include <utility>
19
20namespace ActsTrk {
21
23 const std::string& name,
24 const IInterface* parent)
25 : base_class(type, name, parent)
26 {}
27
29 ATH_CHECK(m_layerTool.retrieve());
30 ATH_MSG_DEBUG("Initializing " << name() << "...");
31
32 // Make the logger And Propagate to ACTS routines
33 m_logger = makeActsAthenaLogger(this, "Acts");
34
35 // etaMin,etaMax,zMin,zMax
36 m_internalRoi.emplace(-4.5, 4.5, m_minZ0.value(), m_maxZ0.value());
37
40
41 // The layer tool builds the GBTS layers, in dense layer index order, and
42 // knows which layer each module hash belongs to and what it is made of.
43 const std::vector<Acts::Experimental::GbtsLayerDescription>& layers =
44 m_layerTool->layerDescriptions();
45
46 m_pixelHashToLayer = &m_layerTool->pixelLayers();
47 m_stripHashToLayer = &m_layerTool->stripLayers();
48
50 ATH_MSG_ERROR("Neither pixel nor strip layers are enabled, there is "
51 "nothing to seed on.");
52 return StatusCode::FAILURE;
53 }
54
55 std::vector<Acts::Experimental::GbtsLayerConnection> connections;
56 float etaBinWidth = 0.0f;
57 ATH_CHECK(m_layerTool->readConnections(layers, connections, etaBinWidth, m_connectorInputFile.value(), m_usePixelLayers, m_useStripLayers));
58
59 // option that allows for adding custom eta binning (default is at 0.2)
60 if (m_etaBinWidthOverride.value() != 0.0f) {
61 etaBinWidth = m_etaBinWidthOverride.value();
62 }
63
64 // the layer pairs carry the tau ratio cut of the triplets they make
65 Acts::Experimental::GbtsAdaptiveTauRatioCuts tauRatioCuts;
66 tauRatioCuts.tauRatioCut = m_tauRatioCut;
67 tauRatioCuts.tauRatioCorr = m_useAdaptiveCuts ? m_tauRatioCorr.value() : 0.0f;
68 Acts::Experimental::assignAdaptiveTauRatioCuts(connections, layers, tauRatioCuts);
69
70 // the cluster width cuts are the only user of the tau lookup table
71 if (m_finderCfg.useClusterWidthCuts) {
73 }
74
75 // create geoemtry object that holds allowed pairing of allowed eta regions in each layer
76 // holds all geometry information (m_layergeomtry and connection table)
77 auto gbtsGeo = std::make_shared<Acts::Experimental::GbtsGeometry>(
78 layers, connections, etaBinWidth, Acts::Experimental::GbtsZ0Range{}, logger());
79
80 m_finder = Acts::Experimental::GraphBasedTrackSeeder(
81 Acts::Experimental::GraphBasedTrackSeeder::DerivedConfig(m_finderCfg),
82 gbtsGeo, logger().cloneWithSuffix("gbtsFinder"));
83
84 m_graphBuilder.emplace(m_graphCfg, gbtsGeo,
85 logger().cloneWithSuffix("gbtsGraphBuilder"));
86
87 m_filter = Acts::Experimental::GbtsTrackingFilter(m_filterCfg, gbtsGeo);
88
89 return StatusCode::SUCCESS;
90 }
91
94 const EventContext& ctx,
95 const std::vector<const xAOD::SpacePointContainer*>& spacePointCollections,
96 const Eigen::Vector3f& beamSpotPos, float bFieldInZ,
97 ActsTrk::SeedContainer& seedContainer) const
98 {
99 // to avoid compile issues with unused veriables
100 (void) ctx;
101
102 const Acts::Experimental::GraphBasedTrackSeeder::Options options{
103 .bFieldInZ = bFieldInZ};
104
105
106 std::vector<const xAOD::SpacePoint*> tmpSpacePoints;
107
108 // add spacepoint pointers to singel container, this makes indexing them easier
109 for (const xAOD::SpacePointContainer* spacePoints : spacePointCollections) {
110 for (const xAOD::SpacePoint* sp : *spacePoints) {
111 tmpSpacePoints.emplace_back(sp);
112 }
113 }
114
115
116 // create the node storage and fill it from the xAOD space points
117 Acts::Experimental::GbtsNodeStorage nodeStorage = m_finder->makeNodeStorage();
118
119 // node positions are relative to the beam spot in x and y if the correction is on
120 const float offsetX = m_beamSpotCorrection ? beamSpotPos[0] : 0.0f;
121 const float offsetY = m_beamSpotCorrection ? beamSpotPos[1] : 0.0f;
122
123 std::size_t nPixelNodes = 0;
124 std::size_t nStripNodes = 0;
125
126 // space points GBTS has no layer for, counted rather than reported per
127 // space point: the loop runs over the whole event
128 std::size_t nUnmappedHashes = 0;
129 std::size_t nUngroupedModules = 0;
130
131 // add spacepoints to node storage
132 for(std::size_t idx = 0; idx < tmpSpacePoints.size(); ++idx){
133 // obtain module hash for spacepoint
134 const xAOD::SpacePoint* sp = tmpSpacePoints[idx];
135 const std::vector<xAOD::DetectorIDHashType>& elementlist = sp->elementIdList();
136
137 // a strip space point is made of one cluster on each side of a stereo pair
138 const bool isPixel(elementlist.size() == 1);
139
140 if (isPixel ? !m_usePixelLayers : !m_useStripLayers) {
141 continue;
142 }
143
144 const std::vector<short>& hashToLayer =
146 const auto hash = static_cast<std::size_t>(elementlist[0]);
147 if (hash >= hashToLayer.size()) [[unlikely]] {
148 ++nUnmappedHashes;
149 continue;
150 }
151
152 const short layer = hashToLayer[hash];
153 if (layer == IGbtsLayerTool::kNoLayer) {
154 // a wafer GBTS does not group into any of its layers
155 ++nUngroupedModules;
156 continue;
157 }
158
159 float clusterWidth = 0.0f;
160 float localPositionY = 0.0f;
161 if (m_finderCfg.useClusterWidthCuts && isPixel) {
162 assert(dynamic_cast<const xAOD::PixelCluster*>(sp->measurements().front())!=nullptr);
163 const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(sp->measurements().front());
164 clusterWidth = pCL->widthInEta();
165 localPositionY = pCL->localPosition<2>().y();
166 }
167
168 // the stereo pair of a strip space point, for the strip calibration in GBTS
169 Acts::OuterStripSpacePointCalibrationDetails stripDetails{};
170 const Acts::OuterStripSpacePointCalibrationDetails* strip = nullptr;
171 if (!isPixel) {
172 // topStripCenter is global, the node frame shifts only x and y
173 Eigen::Map<Eigen::Vector3f>(stripDetails.outerCenter.data()) =
174 sp->topStripCenter() - Eigen::Vector3f(offsetX, offsetY, 0.0f);
175 Eigen::Map<Eigen::Vector3f>(stripDetails.innerToOuterSeparation.data()) =
176 sp->stripCenterDistance();
177 Eigen::Map<Eigen::Vector3f>(stripDetails.outerHalfVector.data()) =
178 sp->topHalfStripLength() * sp->topStripDirection();
179 Eigen::Map<Eigen::Vector3f>(stripDetails.innerHalfVector.data()) =
180 sp->bottomHalfStripLength() * sp->bottomStripDirection();
181 strip = &stripDetails;
182 }
183
184 const float x = static_cast<float>(sp->x()) - offsetX;
185 const float y = static_cast<float>(sp->y()) - offsetY;
186 const std::optional<std::uint32_t> bin = nodeStorage.insert(
187 static_cast<Acts::SpacePointIndex>(idx), x, y,
188 static_cast<float>(sp->z()), std::hypot(x, y), std::atan2(y, x),
189 static_cast<Acts::Experimental::GbtsLayerIndex>(layer), clusterWidth,
190 localPositionY, strip);
191
192 if (bin.has_value()) {
193 ++(isPixel ? nPixelNodes : nStripNodes);
194 }
195 }
196
197 ATH_MSG_DEBUG("Inserted " << nPixelNodes << " pixel and " << nStripNodes
198 << " strip nodes; the graph "
199 << (nodeStorage.hasStrips() ? "carries" : "does not carry")
200 << " stereo pairs");
201
202 if (nUnmappedHashes != 0) [[unlikely]] {
203 ATH_MSG_WARNING(nUnmappedHashes << " space points sit on a wafer hash "
204 "outside the GBTS layer map and were dropped");
205 }
206 if (nUngroupedModules != 0) {
207 ATH_MSG_DEBUG(nUngroupedModules << " space points sit on a wafer GBTS "
208 "does not group into a layer");
209 }
210
211 // order the nodes and build the derived per-node data
212 nodeStorage.finalize();
213
214 ATH_MSG_VERBOSE("Spacepoints successfully added to node storage");
215
216 Acts::SeedContainer seeds;
217 m_finder->createSeeds(nodeStorage, m_internalRoi.value(), *m_graphBuilder,
218 *m_filter, options, seeds);
219
220 // add seeds to the output container
221 seedContainer.reserve(seedContainer.size() + seeds.size(), 7.0f);
222 for (auto seed : seeds) {
223 seedContainer.push_back(
224 seed.asConst(),
225 [&](const Acts::SpacePointIndex spIndex) {
226 return tmpSpacePoints[spIndex];
227 });
228 }
229
230 ATH_MSG_VERBOSE("Number of seeds created is " << seedContainer.size());
231 return StatusCode::SUCCESS;
232 }
233
235 Acts::Experimental::GbtsTauLookupTable& tauLookupTable) const
236 {
237 std::ifstream lutStream(m_lutFile.value());
238 if (!lutStream.is_open()) {
239 ATH_MSG_ERROR("Cannot open the GBTS tau lookup table " << m_lutFile.value());
240 return StatusCode::FAILURE;
241 }
242
243 tauLookupTable.clear();
244
245 // the width is dropped: a row is located by index, one row per
246 // tauLutBinWidth of cluster width, never searched
247 float clusterWidth = 0.0f;
248 Acts::Experimental::GbtsTauBounds bounds;
249 while (lutStream >> clusterWidth >> bounds.minTau >> bounds.maxTau >>
250 bounds.minTauNearEdge >> bounds.maxTauNearEdge) {
251 tauLookupTable.push_back(bounds);
252 }
253
254 if (!lutStream.eof()) {
255 // ended on a parse error, not on a clean end of file
256 ATH_MSG_ERROR("Malformed GBTS tau lookup table " << m_lutFile.value());
257 return StatusCode::FAILURE;
258 }
259 if (tauLookupTable.empty()) {
260 ATH_MSG_ERROR("The GBTS tau lookup table " << m_lutFile.value() << " is empty");
261 return StatusCode::FAILURE;
262 }
263
264 ATH_MSG_DEBUG("Read " << tauLookupTable.size() << " rows of the GBTS tau lookup table "
265 << m_lutFile.value());
266
267 return StatusCode::SUCCESS;
268 }
269
271 m_finderCfg.useClusterWidthCuts = m_useML;
272 m_graphCfg.matchBeforeCreate = m_matchBeforeCreate;
273 m_graphCfg.minPt = m_minPt;
274 m_finderCfg.nMaxPhiSlice = m_nMaxPhiSlice;
275 m_graphCfg.useEtaBinning = m_useEtaBinning;
276 m_graphCfg.doubletFilterRZ = m_doubletFilterRZ;
277 m_graphCfg.minDeltaRadius = m_minDeltaRadius;
278 m_graphCfg.maxEdgesPerSP = m_maxEdgesPerSP;
279 m_graphCfg.tauRatioCut = m_tauRatioCut;
280 m_graphCfg.tauRatioPrecut = m_tauRatioPrecut;
281 m_finderCfg.hitShareThreshold = m_hitShareThreshold;
282 m_finderCfg.maxEndcapClusterWidth = m_maxEndcapClusterwidth;
283 m_graphCfg.d0Max = m_d0Max;
284
285 //use roi for pixel and given value for strip
286 m_graphCfg.maxZ0 = m_maxZ0.value();
287 m_graphCfg.minZ0 = m_minZ0.value();
288
289 m_graphCfg.validateTriplets = m_validateTriplets;
290 m_finderCfg.addTriplets = m_addTriplets;
291 m_finderCfg.maxAbsEtaAddTriplets = m_maxEtaAddTriplets;
292 m_graphCfg.cutDPhiMax = m_cutDPhiMax;
293 m_graphCfg.cutDCurvMax = m_cutDCurvMax;
294 m_graphCfg.maxOuterRadius = m_maxOuterRadius;
295
296 // The seeder no longer recognises an LRT mode, so spell out what it used
297 // to imply: a triplet with no confirmation.
298 if (m_LRTmode) {
299 m_finderCfg.minSeedLevel = 2;
300 }
301
302 m_filterCfg.sigmaMS = m_sigmaMS;
303 m_filterCfg.radLen = m_radLen;
304 m_filterCfg.sigmaX = m_sigmaX;
305 m_filterCfg.sigmaY = m_sigmaY;
306 m_filterCfg.weightX = m_weightX;
307 m_filterCfg.weightY = m_weightY;
308 m_filterCfg.maxDChi2X = m_maxDChi2X;
309 m_filterCfg.maxDChi2Y = m_maxDChi2Y;
310 m_filterCfg.addHit = m_addHit;
311 m_filterCfg.maxCurvature = m_maxCurvature;
313
314 return StatusCode::SUCCESS;
315 }
316
317 // called in initialise, used to make sure all config settings look sensible
319 ATH_MSG_DEBUG("===== GBTS finder config =====");
320 ATH_MSG_DEBUG( "beamSpotCorrection: " << m_beamSpotCorrection.value());
321 ATH_MSG_DEBUG( "connectorInputFile: " << m_connectorInputFile.value());
322 ATH_MSG_DEBUG( "lutInputFile: " << m_lutFile.value());
323 ATH_MSG_DEBUG( "LRTmode: " << m_LRTmode.value());
324 ATH_MSG_DEBUG( "useStripConnections: " << m_stripConnections.value());
325 ATH_MSG_DEBUG( "useClusterWidthCuts: " << m_finderCfg.useClusterWidthCuts);
326 ATH_MSG_DEBUG( "matchBeforeCreate: " << m_graphCfg.matchBeforeCreate);
327 ATH_MSG_DEBUG( "minSeedLevel: " << static_cast<unsigned>(m_finderCfg.minSeedLevel));
328 ATH_MSG_DEBUG( "tauRatioPrecut: " << m_graphCfg.tauRatioPrecut);
329 ATH_MSG_DEBUG( "tauRatioCut: " << m_graphCfg.tauRatioCut);
330 ATH_MSG_DEBUG( "tauRatioCorr: " << m_tauRatioCorr.value());
331 ATH_MSG_DEBUG( "etaBinWidthOverride: " << m_etaBinWidthOverride.value());
332 ATH_MSG_DEBUG( "nMaxPhiSlice: " << m_finderCfg.nMaxPhiSlice);
333 ATH_MSG_DEBUG( "minPt: " << m_graphCfg.minPt);
334 ATH_MSG_DEBUG( "useEtaBinning: " << m_graphCfg.useEtaBinning);
335 ATH_MSG_DEBUG( "doubletFilterRZ: " << m_graphCfg.doubletFilterRZ);
336 ATH_MSG_DEBUG( "maxEdgesPerSP: " << m_graphCfg.maxEdgesPerSP);
337 ATH_MSG_DEBUG( "minDeltaRadius: " << m_graphCfg.minDeltaRadius);
338 ATH_MSG_DEBUG( "hitShareThreshold: " << m_finderCfg.hitShareThreshold);
339 ATH_MSG_DEBUG( "maxEndcapClusterWidth: " << m_finderCfg.maxEndcapClusterWidth);
340 ATH_MSG_DEBUG( "d0Max: " << m_graphCfg.d0Max);
341 ATH_MSG_DEBUG("maxZ0: " << m_graphCfg.maxZ0);
342 ATH_MSG_DEBUG("minZ0: " << m_graphCfg.minZ0);
343 ATH_MSG_DEBUG( "validateTriplets: " << m_graphCfg.validateTriplets);
344 ATH_MSG_DEBUG( "useAdaptiveCuts: " << m_useAdaptiveCuts.value());
345 ATH_MSG_DEBUG( "addTriplets: " << m_finderCfg.addTriplets);
346 ATH_MSG_DEBUG( "maxEtaAddTriplets: " << m_finderCfg.maxAbsEtaAddTriplets);
347 ATH_MSG_DEBUG("cutDphiMax: " << m_graphCfg.cutDPhiMax);
348 ATH_MSG_DEBUG("cutDCurvMax: " << m_graphCfg.cutDCurvMax);
349 ATH_MSG_DEBUG("maxOuterRadius: " << m_graphCfg.maxOuterRadius);
350
351 ATH_MSG_DEBUG("===== GBTS filter config =====");
352 ATH_MSG_DEBUG( "sigmaMS: " << m_filterCfg.sigmaMS);
353 ATH_MSG_DEBUG( "radLen: " << m_filterCfg.radLen);
354 ATH_MSG_DEBUG( "sigmaX: " << m_filterCfg.sigmaX);
355 ATH_MSG_DEBUG( "sigmaY: " << m_filterCfg.sigmaY);
356 ATH_MSG_DEBUG( "weightX: " << m_filterCfg.weightX);
357 ATH_MSG_DEBUG( "weightY: " << m_filterCfg.weightY);
358 ATH_MSG_DEBUG( "maxDChi2X: " << m_filterCfg.maxDChi2X);
359 ATH_MSG_DEBUG( "maxDChi2Y: " << m_filterCfg.maxDChi2Y);
360 ATH_MSG_DEBUG( "addHit: " << m_filterCfg.addHit);
361 ATH_MSG_DEBUG( "maxCurvature: " << m_filterCfg.maxCurvature);
362 ATH_MSG_DEBUG( "filterMaxZ0: " << m_filterCfg.maxZ0);
363}
364
365} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
static Double_t sp
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition Logger.cxx:64
#define y
#define x
Gaudi::Property< bool > m_doubletFilterRZ
Gaudi::Property< float > m_maxZ0
Gaudi::Property< float > m_maxEtaAddTriplets
Gaudi::Property< float > m_filterMaxZ0
Gaudi::Property< float > m_minPt
Gaudi::Property< bool > m_useAdaptiveCuts
Gaudi::Property< bool > m_usePixelLayers
Which technologies this instance seeds on.
Gaudi::Property< float > m_maxDChi2X
Acts::Experimental::GbtsGraphBuilder::Config m_graphCfg
steering for doublet graph building
Gaudi::Property< float > m_weightX
std::optional< Acts::Experimental::GbtsGraphBuilder > m_graphBuilder
the doublet graph builder
Gaudi::Property< float > m_sigmaMS
virtual StatusCode initialize() override
Gaudi::Property< float > m_cutDPhiMax
Gaudi::Property< bool > m_validateTriplets
Gaudi::Property< float > m_sigmaY
Gaudi::Property< float > m_maxEdgesPerSP
Gaudi::Property< bool > m_LRTmode
StatusCode readTauLookupTable(Acts::Experimental::GbtsTauLookupTable &tauLookupTable) const
Reads the tau lookup table the cluster width cuts need: per line a cluster width, the bulk tau bounds...
std::optional< Acts::Experimental::GbtsRoiDescriptor > m_internalRoi
region of interest for pixel seeding
Gaudi::Property< float > m_addHit
std::unique_ptr< const Acts::Logger > m_logger
logging instance
Gaudi::Property< bool > m_stripConnections
StatusCode createSeeds(const EventContext &ctx, const std::vector< const xAOD::SpacePointContainer * > &spacePointCollections, const Eigen::Vector3f &beamSpotPos, float bFieldInZ, ActsTrk::SeedContainer &seedContainer) const override
Gaudi::Property< float > m_nMaxPhiSlice
Gaudi::Property< float > m_maxCurvature
Gaudi::Property< bool > m_useStripLayers
Gaudi::Property< float > m_maxOuterRadius
Gaudi::Property< float > m_etaBinWidthOverride
Gaudi::Property< float > m_minZ0
const Acts::Logger & logger() const
Private access to the logger.
Acts::Experimental::GbtsTrackingFilter::Config m_filterCfg
steering for track filter
void printGbtsConfig() const
prints all current config settings used either with default settings or properties changed by the gau...
Gaudi::Property< float > m_maxDChi2Y
Gaudi::Property< std::string > m_connectorInputFile
Acts::Experimental::GraphBasedTrackSeeder::Config m_finderCfg
steering for seeding algorithm
Gaudi::Property< float > m_cutDCurvMax
Gaudi::Property< bool > m_useML
Gaudi::Property< float > m_minDeltaRadius
std::optional< Acts::Experimental::GbtsTrackingFilter > m_filter
the seed filter
Gaudi::Property< float > m_tauRatioPrecut
Gaudi::Property< bool > m_useEtaBinning
Gaudi::Property< bool > m_matchBeforeCreate
std::optional< Acts::Experimental::GraphBasedTrackSeeder > m_finder
the actual seed fining algorithm
StatusCode prepareConfiguration()
sets configs based on gaudi properties defined below
ToolHandle< IGbtsLayerTool > m_layerTool
Builds the GBTS layers out of the ITk readout geometry.
Gaudi::Property< float > m_maxEndcapClusterwidth
Gaudi::Property< float > m_tauRatioCorr
Gaudi::Property< float > m_hitShareThreshold
Gaudi::Property< float > m_sigmaX
Gaudi::Property< bool > m_beamSpotCorrection
const std::vector< short > * m_stripHashToLayer
Wafer hash to dense GBTS layer index, one map per technology.
Gaudi::Property< float > m_weightY
Gaudi::Property< float > m_tauRatioCut
Gaudi::Property< float > m_d0Max
Gaudi::Property< bool > m_addTriplets
Gaudi::Property< std::string > m_lutFile
const std::vector< short > * m_pixelHashToLayer
GbtsSeedingTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< float > m_radLen
static constexpr short kNoLayer
Value stored in the hash maps for a module GBTS does not use.
float widthInEta() const
Returns the width of the cluster in phi (x) and eta (y) directions, respectively.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
#define ATH_FLATTEN
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
#define unlikely(x)
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
void reserve(std::size_t size, float averageSpacePoints=3) noexcept
std::size_t size() const noexcept