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*/
7#include <optional>
8
9namespace ActsTrk {
10
12
14{
15 ATH_MSG_DEBUG("Initializing");
16
17 ATH_CHECK(m_common.initialize());
18
19 ATH_CHECK(m_pixelRDOKey.initialize());
20 ATH_CHECK(m_stripRDOKey.initialize());
21
22 ATH_MSG_DEBUG("Reading from Pixel RDO key: " << m_pixelRDOKey.key());
23 ATH_MSG_DEBUG("Reading from Strip RDO key: " << m_stripRDOKey.key());
24
27
28 return StatusCode::SUCCESS;
29}
30
31StatusCode RDOtoTracccCellConverterAlg::execute(const EventContext& ctx) const
32{
33 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
34
35 // ---- 0. Init
36 auto pixelRDOHandle = SG::makeHandle(m_pixelRDOKey, ctx);
37 ATH_CHECK(pixelRDOHandle.isValid());
38 auto stripRDOHandle = SG::makeHandle(m_stripRDOKey, ctx);
39 ATH_CHECK(stripRDOHandle.isValid());
40
41 // ---- 1. Count Pixel and Strip hits: creating the traccc SoA requires
42 // knowing their size upon creation.
43
44 size_type nPix = 0, nStrip = 0;
45
46 for (const auto* coll : *pixelRDOHandle) {
47 if (coll) {
48 nPix += coll->size();
49 }
50 }
51 for (const auto* coll : *stripRDOHandle) {
52 if (coll) {
53 for (const SCT_RDORawData* rdo : *coll) {
54 //Check type in debug build otherwise assume it is correct
55 assert(dynamic_cast<const SCT3_RawData*>(rdo)!=nullptr);
56 const SCT3_RawData* raw3 = static_cast<const SCT3_RawData*>(rdo);
57
58 std::bitset<3> timePattern(raw3->getTimeBin());
59 if (!m_common.passTiming(timePattern)) {
60 ATH_MSG_DEBUG("Strip failed timing check");
61 continue;
62 }
63 nStrip += rdo->getGroupSize();
64 }
65 }
66 }
67
68 ATH_MSG_DEBUG("Found " << nPix << " Pixel RDOs and " << nStrip
69 << " Strip RDOs, total " << (nPix + nStrip) << " RDOs");
70 size_type const nCells = nPix + nStrip;
71
72
73 // ---- 2. Create the output cell buffer.
74 auto host_copy = m_common.m_copiesTool->hostCopy(ctx);
75 traccc::edm::silicon_cell_collection::buffer traccc_cells_host_buffer{
76 nCells, m_common.m_hostMR->mr()};
77 host_copy->setup(traccc_cells_host_buffer)->wait();
78
79 if (nCells == 0) {
80 ATH_MSG_DEBUG("no input hits — writing empty cell collection");
81 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
82 return StatusCode::SUCCESS;
83 }
84
85 // Create a "device" collection around the buffer to work on it
86 traccc::edm::silicon_cell_collection::device cells{traccc_cells_host_buffer};
87
88 // ---- 3. Convert RDOs to traccc cells
89 // The traccc buffers are not default initialized: all members must be set.
90
91 size_type cell_index = 0;
92 uint64_t current_geometry_id = detray::geometry::identifier{}.value();
93 unsigned int current_det_cond_idx = -1;
94
95 // Convert Pixel RDOs
96 for (const auto* coll : *pixelRDOHandle) {
97
98 for (const PixelRDORawData* rdo : *coll) {
99 const Identifier rdoId = rdo->identify();
101 m_pixelManager->getDetectorElement(rdoId);
102 if (!el) continue;
103 const Identifier modId = el->identify();
104 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
105 const std::optional<detray_id_type> geoIdOpt = m_common.m_geoIdMapping->athenaToDetray(modId);
106 if (!geoIdOpt.has_value()) {
107 ATH_MSG_FATAL("No detray id found for Athena identifier " << modId);
108 return StatusCode::FAILURE;
109 }
110 const detray_id_type geoId = *geoIdOpt;
111
112 if (geoId != current_geometry_id) {
113 current_geometry_id = geoId;
114 std::optional<unsigned int> det_cond_idx_opt =
115 m_common.m_geoIdMapping->detrayToDetDescIndex(current_geometry_id);
116 if (!det_cond_idx_opt.has_value()) {
117 ATH_MSG_FATAL("No detector conditions index found for detray identifier " << current_geometry_id);
118 return StatusCode::FAILURE;
119 }
120 current_det_cond_idx = det_cond_idx_opt.value();
121 }
122
123 float activation = 1.;
124 if (m_common.m_UsePixelToTForCellActivation) {
125 activation = static_cast<float>(rdo->getToT());
126 if (activation == 0.) {
127 ATH_MSG_ERROR("input data error: RDO must not have ToT=0; RDO index: "
128 << cell_index);
129 }
130 }
131
132 traccc::edm::silicon_cell cell = cells.at(cell_index++);
133 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex());
134 cell.channel1() = static_cast<uint32_t>(cellId.etaIndex());
135 cell.module_index() = current_det_cond_idx;
136 cell.activation() = activation;
137 cell.time() = 0;
138 }
139 }
140
141 // Convert Strip RDOs
142 for (const auto* coll : *stripRDOHandle) {
143 for (const SCT_RDORawData* rdo : *coll) {
144 //Check type in debug build otherwise assume it is correct
145 assert(dynamic_cast<const SCT3_RawData*>(rdo)!=nullptr);
146 const SCT3_RawData* raw3 = static_cast<const SCT3_RawData*>(rdo);
147
148 std::bitset<3> timePattern(raw3->getTimeBin());
149 if (!m_common.passTiming(timePattern)) {
150 ATH_MSG_DEBUG("Strip failed timing check");
151 continue;
152 }
153
154 const Identifier rdoId = rdo->identify();
156 m_stripManager->getDetectorElement(rdoId);
157 if (!el) continue;
158 const Identifier modId = el->identify();
159 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
160 const std::optional<detray_id_type> geoIdOpt = m_common.m_geoIdMapping->athenaToDetray(modId);
161 if (!geoIdOpt.has_value()) {
162 ATH_MSG_FATAL("No detray id found for Athena identifier " << modId);
163 return StatusCode::FAILURE;
164 }
165 const detray_id_type geoId = *geoIdOpt;
166
167 if (geoId != current_geometry_id) {
168 current_geometry_id = geoId;
169 std::optional<unsigned int> det_cond_idx_opt =
170 m_common.m_geoIdMapping->detrayToDetDescIndex(current_geometry_id);
171 if (!det_cond_idx_opt.has_value()) {
172 ATH_MSG_FATAL("No detector conditions index found for detray identifier " << current_geometry_id);
173 return StatusCode::FAILURE;
174 }
175 current_det_cond_idx = det_cond_idx_opt.value();
176 }
177
178 if (m_common.m_stripID->barrel_ec(modId) == 0) {
179 for (int i = 0; i < rdo->getGroupSize(); ++i) {
180
181 traccc::edm::silicon_cell cell = cells.at(cell_index++);
182 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex() + i);
183 cell.channel1() = 0;
184 cell.module_index() = current_det_cond_idx;
185 cell.activation() = 1.;
186 cell.time() = 0;
187
188 }
189 } else {
190 for (int i = 0; i < rdo->getGroupSize(); ++i) {
191
192 traccc::edm::silicon_cell cell = cells.at(cell_index++);
193 cell.channel0() = 0;
194 cell.channel1() = static_cast<uint32_t>(cellId.phiIndex() + i);
195 cell.module_index() = current_det_cond_idx;
196 cell.activation() = 1.;
197 cell.time() = 0;
198
199 }
200 }
201 }
202 }
203
204 // ---- 4. Sort cells
205 if (m_common.m_CPUCellSorting) {
206 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
207 m_common.sortCells(*host_copy, cells);
208
209 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
210 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
211 } else {
212 // In this case the GPU clusterization algorithm must be configured to sort
213 // the cells.
214
215 // ---- 4/5. Copy host -> device buffer and write to StoreGate
216 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
217 }
218
219 // ---- 6. Accounting
220 m_common.m_nPix += nPix;
221 m_common.m_nStrip += nStrip;
222 m_common.m_nCells += nCells;
223
224 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
225 << m_common.m_tracccCellsKey.key() << "'");
226 return StatusCode::SUCCESS;
227}
228
230{
231 ATH_MSG_DEBUG("Finalizing.");
232
233 ATH_CHECK(m_common.finalize());
234
235 return StatusCode::SUCCESS;
236}
237
238} // 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_FATAL(x,...)
Handle class for reading from StoreGate.
const InDetDD::PixelDetectorManager * m_pixelManager
const InDetDD::SCT_DetectorManager * m_stripManager
SG::ReadHandleKey< PixelRDO_Container > m_pixelRDOKey
Gaudi::Property< std::string > m_pixelManagerKey
SG::ReadHandleKey< SCT_RDO_Container > m_stripRDOKey
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< std::string > m_stripManagerKey
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.
int getTimeBin() const
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
GeometryIdMapping::detray_id_type detray_id_type
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())