ATLAS Offline Software
Loading...
Searching...
No Matches
PhaseIIRDOtoTracccCellConverterAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
6
7namespace ActsTrk {
8
10{
11 ATH_MSG_DEBUG("Initializing");
12
13 ATH_CHECK(m_common.initialize());
14
15 ATH_CHECK(m_ph2PixelRDOKey.initialize());
16 ATH_CHECK(m_ph2StripRDOKey.initialize());
17
18 return StatusCode::SUCCESS;
19}
20
21StatusCode PhaseIIRDOtoTracccCellConverterAlg::execute(const EventContext& ctx) const
22{
23 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
24 using PixelRawDataContainerProxy = PhaseII::PixelRawDataTypeTraits<>::RawDataContainerProxy;
26 using StripRawDataContainerProxy = PhaseII::StripRawDataTypeTraits<>::RawDataContainerProxy;
28
29 // ---- 0. Init
30 auto ph2PixelRDOHandle = SG::makeHandle(m_ph2PixelRDOKey, ctx);
31 ATH_CHECK(ph2PixelRDOHandle.isValid());
32 auto ph2StripRDOHandle = SG::makeHandle(m_ph2StripRDOKey, ctx);
33 ATH_CHECK(ph2StripRDOHandle.isValid());
34
35 // ---- 1. Count Pixel and Strip hits: creating the traccc SoA requires
36 // knowing their size upon creation.
37
38 size_type nPix = 0, nStrip = 0;
39
40 // Pixels
41 auto pixel_rdo_container_collection_proxy = PhaseII::makeRawDataCollectionProxy(*ph2PixelRDOHandle);
42 for (PixelRawDataContainerProxy module_rdo_container_proxy : pixel_rdo_container_collection_proxy) {
43 if (!module_rdo_container_proxy.empty()) {
44 nPix += module_rdo_container_proxy.size();
45 }
46 }
47
48 // Strips
49 auto strip_rdo_container_collection_proxy = PhaseII::makeRawDataCollectionProxy(*ph2StripRDOHandle);
50
51 for (StripRawDataContainerProxy module_rdo_container_proxy : strip_rdo_container_collection_proxy) {
52 if (!module_rdo_container_proxy.empty()) {
53 for (StripRawDataProxy strip_rdo: module_rdo_container_proxy) {
54 if (!m_common.passTiming(strip_rdo.getTimeBin())) {
55 ATH_MSG_DEBUG("Strip failed timing check");
56 continue;
57 }
58 nStrip += strip_rdo.getGroupSize();
59 }
60 }
61 }
62
63 size_type const nCells = nPix + nStrip;
64
65 // ---- 2. Create the output cell buffer
66 auto host_copy = m_common.m_copiesTool->hostCopy(ctx);
67 traccc::edm::silicon_cell_collection::buffer traccc_cells_host_buffer{
68 nCells, m_common.m_hostMR->mr()};
69 host_copy->setup(traccc_cells_host_buffer)->wait();
70
71 if (nCells == 0) {
72 ATH_MSG_DEBUG("no input hits — writing empty cell collection");
73 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
74 return StatusCode::SUCCESS;
75 }
76
77 // Create a device collection around the buffer.
78 traccc::edm::silicon_cell_collection::device cells{traccc_cells_host_buffer};
79
80 // ---- 3. Convert RDOs to traccc cells
81 // The traccc buffers are not default initialized: all members must be set.
82
83 size_type cell_index = 0;
84 uint64_t current_geometry_id = detray::geometry::identifier{}.value();
85 unsigned int current_det_cond_idx = -1;
86
87 // Convert Pixel RDOs
88 for (PixelRawDataContainerProxy module_rdo_container_proxy : pixel_rdo_container_collection_proxy) {
89 if (module_rdo_container_proxy.empty()) {
90 continue;
91 }
92 IdentifierHash const module_id_hash(module_rdo_container_proxy.identifyHash());
93 Identifier const module_id = m_common.m_pixelID->wafer_id(module_id_hash);
94 uint64_t const detray_geometry_id = m_common.m_athenaToDetray->at(module_id);
95 if (detray_geometry_id != current_geometry_id) {
96 current_geometry_id = detray_geometry_id;
97 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
98 }
99
100 for (PixelRawDataProxy pixel_rdo: module_rdo_container_proxy) {
101 float activation = 1.;
102 if (m_common.m_UsePixelToTForCellActivation) {
103 activation = static_cast<float>(pixel_rdo.getToT());
104 if (activation == 0.) {
105 ATH_MSG_ERROR("input data error: RDO must not have ToT=0; RDO index: "
106 << cell_index);
107 }
108 }
109
110 traccc::edm::silicon_cell cell = cells.at(cell_index++);
111 cell.channel0() = static_cast<uint32_t>(pixel_rdo.coordinates()[0]);
112 cell.channel1() = static_cast<uint32_t>(pixel_rdo.coordinates()[1]);
113 cell.module_index() = current_det_cond_idx;
114 cell.activation() = activation;
115 cell.time() = 0;
116 }
117 }
118
119 // Convert Strip RDOs
120 for (StripRawDataContainerProxy module_rdo_container_proxy : strip_rdo_container_collection_proxy) {
121 if (module_rdo_container_proxy.empty()) {
122 continue;
123 }
124 IdentifierHash const module_id_hash(module_rdo_container_proxy.identifyHash());
125 Identifier const module_id = m_common.m_stripID->wafer_id(module_id_hash);
126 uint64_t const detray_geometry_id = m_common.m_athenaToDetray->at(module_id);
127 if (detray_geometry_id != current_geometry_id) {
128 current_geometry_id = detray_geometry_id;
129 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
130 }
131
132 for (StripRawDataProxy strip_rdo: module_rdo_container_proxy) {
133 if (!m_common.passTiming(strip_rdo.getTimeBin())) {
134 ATH_MSG_DEBUG("Strip failed timing check");
135 continue;
136 }
137
138 if (m_common.m_stripID->barrel_ec(module_id) == 0) {
139 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
140 traccc::edm::silicon_cell cell = cells.at(cell_index++);
141 cell.channel0() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
142 cell.channel1() = 0;
143 cell.module_index() = current_det_cond_idx;
144 cell.activation() = 1.;
145 cell.time() = 0;
146 }
147 } else {
148 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
149 traccc::edm::silicon_cell cell = cells.at(cell_index++);
150 cell.channel0() = 0;
151 cell.channel1() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
152 cell.module_index() = current_det_cond_idx;
153 cell.activation() = 1.;
154 cell.time() = 0;
155 }
156 }
157 }
158 }
159
160 if (m_common.m_CPUCellSorting) {
161 // ---- 4. Sort cells
162 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
163 m_common.sortCells(*host_copy, cells);
164
165 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
166 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
167 } else {
168 // In this case the GPU clusterization algorithm must be configured to sort
169 // the cells.
170
171 // ---- 4/5. Copy host -> device buffer and write to StoreGate ---------------
172 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
173 }
174
175 // ---- 6. Accounting
176 m_common.m_nPix += nPix;
177 m_common.m_nStrip += nStrip;
178 m_common.m_nCells += nCells;
179
180 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
181 << m_common.m_tracccCellsKey.key() << "'");
182 return StatusCode::SUCCESS;
183}
184
186{
187 ATH_MSG_DEBUG("Finalizing.");
188
189 ATH_CHECK(m_common.finalize());
190
191 return StatusCode::SUCCESS;
192}
193
194} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
Handle class for reading from StoreGate.
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< PhaseIIStripRawDataContainer > m_ph2StripRDOKey
SG::ReadHandleKey< PhaseIIPixelRawDataContainer > m_ph2PixelRDOKey
This is a "hash" representation of an Identifier.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
auto makeRawDataCollectionProxy(const T_RawDataContainerCollection &collection)
Create the top level container proxy for an RDO container collection (read only).
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
typename RawData::details::traits< ContainerNonConst >::template RawDataProxy< accessPolicy > RawDataProxy
PhaseII::RawDataContainerProxy< typename Utils::ContainerAccessHelper< T_RawDataContainer, accessPolicy >::ContainerType, RawDataProxy > RawDataContainerProxy