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 nStrip += strip_rdo.getGroupSize();
55 }
56 }
57 }
58
59 size_type const nCells = nPix + nStrip;
60
61 if (nCells == 0) {
62 ATH_MSG_DEBUG("no input hits");
63 return StatusCode::SUCCESS;
64 }
65
66 // ---- 2. Create the output cell buffer
67 auto host_copy = m_common.m_copiesTool->hostCopy(ctx);
68 traccc::edm::silicon_cell_collection::buffer traccc_cells_host_buffer{
69 nCells, m_common.m_hostMR->mr()};
70 host_copy->setup(traccc_cells_host_buffer)->wait();
71
72 // Create a device collection around the buffer.
73 traccc::edm::silicon_cell_collection::device cells{traccc_cells_host_buffer};
74
75 // ---- 3. Convert RDOs to traccc cells
76 // The traccc buffers are not default initialized: all members must be set.
77
78 size_type cell_index = 0;
79 uint64_t current_geometry_id = detray::geometry::identifier{}.value();
80 unsigned int current_det_cond_idx = -1;
81
82 // Convert Pixel RDOs
83 for (PixelRawDataContainerProxy module_rdo_container_proxy : pixel_rdo_container_collection_proxy) {
84 if (module_rdo_container_proxy.empty()) {
85 continue;
86 }
87 IdentifierHash const module_id_hash(module_rdo_container_proxy.identifyHash());
88 Identifier const module_id = m_common.m_pixelID->wafer_id(module_id_hash);
89 uint64_t const detray_geometry_id = m_common.m_athenaToDetray->at(module_id);
90 if (detray_geometry_id != current_geometry_id) {
91 current_geometry_id = detray_geometry_id;
92 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
93 }
94
95 for (PixelRawDataProxy pixel_rdo: module_rdo_container_proxy) {
96 float activation = 1.;
97 if (m_common.m_UsePixelToTForCellActivation) {
98 activation = static_cast<float>(pixel_rdo.getToT());
99 if (activation == 0.) {
100 ATH_MSG_ERROR("input data error: RDO must not have ToT=0; RDO index: "
101 << cell_index);
102 }
103 }
104
105 traccc::edm::silicon_cell cell = cells.at(cell_index++);
106 cell.channel0() = static_cast<uint32_t>(pixel_rdo.coordinates()[0]);
107 cell.channel1() = static_cast<uint32_t>(pixel_rdo.coordinates()[1]);
108 cell.module_index() = current_det_cond_idx;
109 cell.activation() = activation;
110 cell.time() = 0;
111 }
112 }
113
114 // Convert Strip RDOs
115 for (StripRawDataContainerProxy module_rdo_container_proxy : strip_rdo_container_collection_proxy) {
116 if (module_rdo_container_proxy.empty()) {
117 continue;
118 }
119 IdentifierHash const module_id_hash(module_rdo_container_proxy.identifyHash());
120 Identifier const module_id = m_common.m_stripID->wafer_id(module_id_hash);
121 uint64_t const detray_geometry_id = m_common.m_athenaToDetray->at(module_id);
122 if (detray_geometry_id != current_geometry_id) {
123 current_geometry_id = detray_geometry_id;
124 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
125 }
126
127 for (StripRawDataProxy strip_rdo: module_rdo_container_proxy) {
128
129 if (m_common.m_stripID->barrel_ec(module_id) == 0) {
130 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
131 traccc::edm::silicon_cell cell = cells.at(cell_index++);
132 cell.channel0() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
133 cell.channel1() = 0;
134 cell.module_index() = current_det_cond_idx;
135 cell.activation() = 1.;
136 cell.time() = 0;
137 }
138 } else {
139 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
140 traccc::edm::silicon_cell cell = cells.at(cell_index++);
141 cell.channel0() = 0;
142 cell.channel1() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
143 cell.module_index() = current_det_cond_idx;
144 cell.activation() = 1.;
145 cell.time() = 0;
146 }
147 }
148 }
149 }
150
151 if (m_common.m_CPUCellSorting) {
152 // ---- 4. Sort cells
153 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
154 m_common.sortCells(*host_copy, cells);
155
156 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
157 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
158 } else {
159 // In this case the GPU clusterization algorithm must be configured to sort
160 // the cells.
161
162 // ---- 4/5. Copy host -> device buffer and write to StoreGate ---------------
163 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
164 }
165
166 // ---- 6. Accounting
167 m_common.m_nPix += nPix;
168 m_common.m_nStrip += nStrip;
169 m_common.m_nCells += nCells;
170
171 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
172 << m_common.m_tracccCellsKey.key() << "'");
173 return StatusCode::SUCCESS;
174}
175
177{
178 ATH_MSG_DEBUG("Finalizing.");
179
180 ATH_CHECK(m_common.finalize());
181
182 return StatusCode::SUCCESS;
183}
184
185} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(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