ATLAS Offline Software
Loading...
Searching...
No Matches
DeviceGBTSSeedingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
8
9// traccc EDM
10#include "traccc/edm/silicon_cell_collection.hpp"
11#include "traccc/edm/measurement_collection.hpp"
15
17
18// vecmem
19#include "vecmem/memory/memory_resource.hpp"
20
21// ACTS logging
22#include "ActsInterop/Logger.h"
23
24#include <fstream>
25#include <memory>
26#include <cstdint>
27#include <unordered_map>
28#include <algorithm>
29#include <vector>
30
31namespace ActsTrk {
32
33// -----------------------------------------------------------------------
35{
36 ATH_MSG_DEBUG("Initializing " << name());
37
39 ATH_CHECK(m_inputPixelSPKey.initialize());
40 ATH_CHECK(m_inputMeasKey.initialize());
41 ATH_CHECK(m_outputPixelSeedsKey.initialize());
43
44 ATH_CHECK(detStore()->retrieve(m_pixelManager, "ITkPixel"));
45 ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID") );
46 ATH_CHECK(m_layerNumberTool.retrieve());
48
49 ATH_MSG_DEBUG("Successfully initialized");
50 return StatusCode::SUCCESS;
51}
52
53StatusCode DeviceGBTSSeedingAlg::execute(const EventContext& ctx) const
54{
55 ATH_MSG_DEBUG("Executing device GBTS seeding.");
56
57 // ---- 1. Read input traccc measurements from StoreGate --------------------------------
58 auto inputTracccPixelSpacepoints = SG::makeHandle(m_inputPixelSPKey, ctx);
59 ATH_CHECK(inputTracccPixelSpacepoints.isValid());
60 ATH_MSG_DEBUG("Read traccc spacepoints from '"
61 << inputTracccPixelSpacepoints.key() << "'");
62
63 auto inputTracccMeasurements = SG::makeHandle(m_inputMeasKey, ctx);
64 ATH_CHECK(inputTracccMeasurements.isValid());
65 ATH_MSG_DEBUG("Read traccc measurements from '"
66 << inputTracccMeasurements.key() << "'");
67
68 // ---- 2. Get traccc seeding alg ---------------------------------------------
69 auto seeding_alg = m_seedingAlgProviderTool->getGBTSAlgorithm(ctx, m_gbts_config);
70
71 // ---- 3. Run traccc pixel seed formation ---------------------------------------------
72 traccc::edm::seed_collection::buffer pixel_seeds_gpu_buffer = (*seeding_alg)(*inputTracccPixelSpacepoints, *inputTracccMeasurements);
73
74 ATH_MSG_DEBUG("Reconstructed " << seeding_alg.copy().get_size(pixel_seeds_gpu_buffer) << " pixel seeds.");
75
76 // ---- 4. Write output traccc seeds to StoreGate -------------------------
77 auto outputTracccPixelSeeds = SG::makeHandle(m_outputPixelSeedsKey, ctx);
78 ATH_CHECK(outputTracccPixelSeeds.record(
79 std::make_unique<traccc::edm::seed_collection::buffer>(
80 std::move(pixel_seeds_gpu_buffer))));
81 ATH_MSG_DEBUG("Wrote spacepoint buffer to '" << m_outputPixelSeedsKey.key() << "'");
82
83 return StatusCode::SUCCESS;
84}
85
87{
88
89 // traccc-gbts defaults are ITk tuned
90 // get layer linking scheme from the athena tools
91 std::string conn_fileName =
93 if (conn_fileName.empty()) {
94 ATH_MSG_FATAL("Cannot find layer connections file for GBTS "
95 << conn_fileName);
96 return StatusCode::FAILURE;
97 }
98 std::ifstream ifs(conn_fileName.c_str());
99 std::unique_ptr<GNN_FASTRACK_CONNECTOR> gbts_connector =
100 std::make_unique<GNN_FASTRACK_CONNECTOR>(ifs, false);
101 ATH_MSG_INFO("Layer connections are initialized from file for GBTS "
102 << conn_fileName);
103
104 const std::vector<Acts::Experimental::GbtsLayerDescription>& layerDescs =
105 m_layerNumberTool->layerDescriptions();
106
107 std::vector<TrigInDetSiLayer> layerGeometry;
108 layerGeometry.reserve(layerDescs.size());
109 for (const auto& layer : layerDescs) {
110 TrigInDetSiLayer converted;
111 converted.m_subdet = layer.id;
112 converted.m_type =
113 (layer.type == Acts::Experimental::GbtsLayerType::Endcap) ? 1 : 0;
114 converted.m_refCoord = layer.refCoord;
115 converted.m_minBound = layer.minBound;
116 converted.m_maxBound = layer.maxBound;
117 layerGeometry.push_back(converted);
118 }
119
120 std::unique_ptr<TrigFTF_GNN_Geometry> GBTS_geo =
121 std::make_unique<TrigFTF_GNN_Geometry>(layerGeometry, gbts_connector);
122
123 traccc::device::gbts_layerInfo layerInfo;
124 // convert save and convert layer info to SoA
125 layerInfo.reserve(GBTS_geo->num_layers());
126
127 for (unsigned int index = 0; index < GBTS_geo->num_layers(); ++index) {
128 const TrigFTF_GNN_Layer* layer =
129 GBTS_geo->getTrigFTF_GNN_LayerByIndex(index);
130 // pixel barrel=0 pixel endcap=1 pixel inc. barrel=2 strip=3
131 int vol_id =
132 (layer->m_layer.m_subdet - (layer->m_layer.m_subdet % 1000)) / 1000;
133 int is_inc_barrel = (vol_id == 97) | (vol_id == 95) | (vol_id == 93) |
134 (vol_id == 77) | (vol_id == 75) | (vol_id == 73);
135 char type = (layer->m_layer.m_type != 0) + is_inc_barrel;
136 if (layer->m_layer.m_subdet <= 20000) {
137 type = 3;
138 }
139 // eta prediction cut occurs for type=0 and cluster width cut for type=1
140 layerInfo.addLayer(type, layer->m_bins[0], layer->num_bins(),
141 layer->m_minEta, layer->m_etaBin);
142 }
143
144 const std::vector<short>& pixel_h2l = m_layerNumberTool->pixelLayers();
145
146 std::vector<std::pair<std::uint64_t, short>> identifierBinning;
147 identifierBinning.reserve(m_idMapping->size());
148
149 // construct identifier -> layer table
150 IdContext pixel_context = m_pixelID->wafer_context();
151 for (const auto& [detrayId, compactId] : m_idMapping->detrayToAthenaMap()) {
152 Identifier athenaId(compactId);
153 if (m_pixelManager->identifierBelongs(athenaId)) {
154 IdentifierHash idHash{};//default c'tor produces detectable invalid hash
155 int rc = m_pixelID->get_hash(athenaId, idHash, &pixel_context); //rc=0 is ok
156 if (rc!=0)[[unlikely]] continue;
157 const short layer = pixel_h2l.at(static_cast<int>(idHash));
158 if (layer == IGbtsLayerTool::kNoLayer) [[unlikely]] continue;
159 identifierBinning.push_back(std::make_pair(
160 detrayId, pixel_h2l.at(static_cast<int>(idHash))));
161 }
162 }
163 ATH_MSG_INFO(identifierBinning.size() << " identifiers with a layer");
164
165 std::vector<std::pair<unsigned int, std::vector<unsigned int>>> binGroups;
166 {
167 const auto & rawBinGroups = GBTS_geo->bin_groups();
168 binGroups.reserve(rawBinGroups.size());
169 for (const auto& p : rawBinGroups) {
170 binGroups.emplace_back(static_cast<unsigned int>(p.first),
171 std::vector<unsigned int>(p.second.begin(), p.second.end()));
172 }
173 }
174
175 for (auto& pair : binGroups) {
176 bool barrel = (pair.first <= 83); // unsigned, so `0 <= pair.first` is always true — dropped
177 if (barrel) {
178 pair.second.push_back(pair.first);
179 }
180 }
181
182 // traccc::gbts_seedfinder_config gbts_config;
183 if (!m_gbts_config.setLinkingScheme(binGroups, std::move(layerInfo), identifierBinning,
184 900.0f, makeActsAthenaLogger(this, "GBTSConfig")))
185 return StatusCode::FAILURE;
186
187 return StatusCode::SUCCESS;
188}
189
190
191} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
static Double_t rc
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
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
SG::ReadHandleKey< traccc::edm::measurement_collection::const_view > m_inputMeasKey
SG::WriteHandleKey< traccc::edm::seed_collection::buffer > m_outputPixelSeedsKey
ToolHandle< IGbtsLayerTool > m_layerNumberTool
const ActsTrk::GeometryIdMapping * m_idMapping
ToolHandle< IDeviceSeedingAlgProviderTool > m_seedingAlgProviderTool
SG::ReadHandleKey< traccc::edm::spacepoint_collection::const_view > m_inputPixelSPKey
const InDetDD::PixelDetectorManager * m_pixelManager
traccc::gbts_seedfinder_config m_gbts_config
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
virtual StatusCode initialize() override
Function initializing the algorithm.
Gaudi::Property< std::string > m_geoIdMappingObjectName
Gaudi::Property< std::string > m_connectionFileName
static constexpr short kNoLayer
Value stored in the hash maps for a module GBTS does not use.
const ServiceHandle< StoreGateSvc > & detStore() const
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
STL class.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition index.py:1
#define unlikely(x)