ATLAS Offline Software
Loading...
Searching...
No Matches
RDOtoTracccCellConverterAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
10#include "traccc/io/csv/cell.hpp"
11
12#include <algorithm>
13#include <stdexcept>
14
15// Comparator for sorting cells by module index then channel
17 bool operator()(const traccc::io::csv::cell& lhs,
18 const traccc::io::csv::cell& rhs) const {
19 if (lhs.geometry_id != rhs.geometry_id)
20 return lhs.geometry_id < rhs.geometry_id;
21 if (lhs.channel1 != rhs.channel1)
22 return lhs.channel1 < rhs.channel1;
23 return lhs.channel0 < rhs.channel0;
24 }
25};
26
27namespace ActsTrk {
28
30{
31 ATH_MSG_DEBUG("Initializing.");
32
33 ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
34 ATH_CHECK(m_pixelRDOKey.initialize());
35
36 ATH_CHECK(detStore()->retrieve(m_stripID, "SCT_ID"));
37 ATH_CHECK(m_stripRDOKey.initialize());
38
39 ATH_CHECK(detStore()->retrieve(m_pixelManager));
40 ATH_CHECK(detStore()->retrieve(m_stripManager));
41
42 ATH_CHECK(m_hostMR.retrieve());
43 ATH_CHECK(m_tracccCellsKey.initialize());
44 ATH_CHECK(m_copy.retrieve());
45
46 m_athenaToDetray = &m_detDescSvc->athenaToDetrayMap();
47 ATH_CHECK(detStore()->retrieve(m_hostCond, "TracccHostConditionsConfig"));
48
49 const auto& gids = m_hostCond->geometry_id();
50 m_DetrayIdToDetDescrIndexMap.reserve(gids.size());
51 for (unsigned int i = 0; i < gids.size(); ++i) {
52 m_DetrayIdToDetDescrIndexMap[gids[i].value()] = i;
53 }
54 ATH_MSG_INFO("Built detray→detcond map with "
55 << m_DetrayIdToDetDescrIndexMap.size() << " entries");
56
57 return StatusCode::SUCCESS;
58}
59
60StatusCode RDOtoTracccCellConverterAlg::execute(const EventContext& ctx) const
61{
62
63 // ---- 1. Read RDOs from StoreGate ----------------------------------------
64 std::vector<const InDetRawDataCollection<PixelRDORawData>*> pixel_rdos;
65 std::vector<const InDetRawDataCollection<SCT_RDORawData>*> strip_rdos;
66 {
67 auto pixelRDOHandle = SG::makeHandle(m_pixelRDOKey, ctx);
68 ATH_CHECK(pixelRDOHandle.isValid());
69 pixel_rdos.reserve(pixelRDOHandle->fullSize());
70 for (const auto* col : *pixelRDOHandle) {
71 if (col) pixel_rdos.push_back(col);
72 }
73
74 auto stripRDOHandle = SG::makeHandle(m_stripRDOKey, ctx);
75 ATH_CHECK(stripRDOHandle.isValid());
76 strip_rdos.reserve(stripRDOHandle->fullSize());
77 for (const auto* col : *stripRDOHandle) {
78 if (col) strip_rdos.push_back(col);
79 }
80 }
81
82 // ---- 2. Convert RDOs to AoS cells ---------------------------------------
83 int nPix = 0, nStrip = 0;
84 std::vector<traccc::io::csv::cell> cells_aos;
85
86 // 8 here is for the time being a placeholder
87 // the user will need to provde the correct cell activation values and time
88
89 float staticToTValue = 8.f;
90 float staticTimeStampValue = 1.f;
91
92 ATH_MSG_DEBUG("Reading pixel hits");
93 for (const auto* coll : pixel_rdos) {
94 for (const PixelRDORawData* rdo : *coll) {
95 const Identifier rdoId = rdo->identify();
97 m_pixelManager->getDetectorElement(rdoId);
98 if (!el) continue;
99 const Identifier modId = el->identify();
100 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
101 const uint64_t geoId = m_athenaToDetray->at(modId);
102
103 cells_aos.push_back({geoId, 0,
104 static_cast<uint32_t>(cellId.phiIndex()),
105 static_cast<uint32_t>(cellId.etaIndex()),
106 staticTimeStampValue, static_cast<float>(rdo->getToT())});
107 ++nPix;
108 }
109 }
110 ATH_MSG_DEBUG("Read " << nPix << " pixel hits");
111
112 ATH_MSG_DEBUG("Reading strip hits");
113 for (const auto* coll : strip_rdos) {
114 for (const SCT_RDORawData* rdo : *coll) {
115 const Identifier rdoId = rdo->identify();
117 m_stripManager->getDetectorElement(rdoId);
118 if (!el) continue;
119 const Identifier modId = el->identify();
120 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
121 const uint64_t geoId = m_athenaToDetray->at(modId);
122
123 if (m_stripID->barrel_ec(modId) == 0) {
124 for (int i = 0; i < rdo->getGroupSize(); ++i) {
125 cells_aos.push_back({geoId, 0,
126 static_cast<uint32_t>(cellId.phiIndex() + i), 0, staticTimeStampValue, staticToTValue});
127 ++nStrip;
128 }
129 } else {
130 for (int i = 0; i < rdo->getGroupSize(); ++i) {
131 cells_aos.push_back({geoId, 0, 0,
132 static_cast<uint32_t>(cellId.phiIndex() + i), staticTimeStampValue, staticToTValue});
133 ++nStrip;
134 }
135 }
136 }
137 }
138 ATH_MSG_DEBUG("Read " << nStrip << " strip hits");
139
140 if (cells_aos.empty()) {
141 ATH_MSG_DEBUG("Created traccc cells: 0");
142 return StatusCode::SUCCESS;
143 }
144
145 // ---- 3. Sort cells -------------------------------------------------------
146 std::sort(cells_aos.begin(), cells_aos.end(), cell_order_module_indices{});
147
148 // ---- 4. Convert to traccc cell collection (host collection) ---------------------
149 // Build the host collection using the memory resource from the tool
150 traccc::edm::silicon_cell_collection::host cells_soa{m_hostMR->mr()};
151
152 uint64_t current_geometry_id = cells_aos[0].geometry_id;
153 unsigned int current_det_cond_idx = m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
154
155 for (const auto& cell : cells_aos) {
156 if (cell.geometry_id != current_geometry_id) {
157 current_geometry_id = cell.geometry_id;
158 current_det_cond_idx = m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
159 }
160 cells_soa.push_back({cell.channel0, cell.channel1, cell.value,
161 cell.timestamp, current_det_cond_idx});
162 }
163 ATH_MSG_DEBUG("Created traccc cells: " << cells_soa.size());
164
165 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
166 auto copy = m_copy->copy(ctx);
167 auto traccc_cells_buffer = std::make_unique<traccc::edm::silicon_cell_collection::buffer>(
168 static_cast<unsigned int>(cells_soa.size()), m_deviceMR->mr());
169 copy->setup(*traccc_cells_buffer)->wait();
170 (*copy)(vecmem::get_data(cells_soa), *traccc_cells_buffer)->wait();
171
172 ATH_MSG_DEBUG("Creating " << copy->get_size(*traccc_cells_buffer) << " cells.");
173
174 auto outputTracccCells = SG::makeHandle(m_tracccCellsKey, ctx);
175 ATH_CHECK(outputTracccCells.record(std::move(traccc_cells_buffer)));
176
177 m_nPix += nPix;
178 m_nStrip += nStrip;
179 m_nCells += cells_soa.size();
180
181 ATH_MSG_DEBUG("Wrote " << cells_soa.size() << " cells to '"
182 << m_tracccCellsKey.key() << "'");
183
184 return StatusCode::SUCCESS;
185}
186
188{
189 ATH_MSG_DEBUG("Finalizing.");
190
191 ATH_MSG_DEBUG("Read total number of pixel hits = " << m_nPix
192 << ", total number of strip hits = " << m_nStrip
193 << " and created total number of traccc cells = " << m_nCells);
194
195 return StatusCode::SUCCESS;
196}
197
198} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const std::unordered_map< Identifier, uint64_t > * m_athenaToDetray
SG::WriteHandleKey< traccc::edm::silicon_cell_collection::buffer > m_tracccCellsKey
ServiceHandle< ActsTrk::IActsDeviceDetectorDescriptionProviderSvc > m_detDescSvc
const traccc::detector_conditions_description::host * m_hostCond
const InDetDD::PixelDetectorManager * m_pixelManager
const InDetDD::SCT_DetectorManager * m_stripManager
std::unordered_map< uint64_t, unsigned int > m_DetrayIdToDetDescrIndexMap
SG::ReadHandleKey< PixelRDO_Container > m_pixelRDOKey
SG::ReadHandleKey< SCT_RDO_Container > m_stripRDOKey
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
ToolHandle< AthDevice::ICopyTool > m_copy
ToolHandle< AthDevice::IMemoryResourceTool > m_deviceMR
const ServiceHandle< StoreGateSvc > & detStore() const
Identifier for the strip or pixel cell.
Definition SiCellId.h:29
int phiIndex() const
Get phi index. Equivalent to strip().
Definition SiCellId.h:122
int etaIndex() const
Get eta index.
Definition SiCellId.h:114
Class to hold geometrical description of a silicon detector element.
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())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
bool operator()(const traccc::io::csv::cell &lhs, const traccc::io::csv::cell &rhs) const