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 traccc::edm::silicon_cell cell = cells.at(cell_index++);
97 cell.channel0() = static_cast<uint32_t>(pixel_rdo.coordinates()[0]);
98 cell.channel1() = static_cast<uint32_t>(pixel_rdo.coordinates()[1]);
99 cell.module_index() = current_det_cond_idx;
100 cell.activation() = m_common.m_UsePixelToTForCellActivation ?
101 static_cast<float>(pixel_rdo.getToT()) : 1.;
102 cell.time() = 0;
103 }
104 }
105
106 // Convert Strip RDOs
107 for (StripRawDataContainerProxy module_rdo_container_proxy : strip_rdo_container_collection_proxy) {
108 if (module_rdo_container_proxy.empty()) {
109 continue;
110 }
111 IdentifierHash const module_id_hash(module_rdo_container_proxy.identifyHash());
112 Identifier const module_id = m_common.m_stripID->wafer_id(module_id_hash);
113 uint64_t const detray_geometry_id = m_common.m_athenaToDetray->at(module_id);
114 if (detray_geometry_id != current_geometry_id) {
115 current_geometry_id = detray_geometry_id;
116 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
117 }
118
119 for (StripRawDataProxy strip_rdo: module_rdo_container_proxy) {
120
121 if (m_common.m_stripID->barrel_ec(module_id) == 0) {
122 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
123 traccc::edm::silicon_cell cell = cells.at(cell_index++);
124 cell.channel0() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
125 cell.channel1() = 0;
126 cell.module_index() = current_det_cond_idx;
127 cell.activation() = 1.;
128 cell.time() = 0;
129 }
130 } else {
131 for (int i = 0; i < strip_rdo.getGroupSize(); ++i) {
132 traccc::edm::silicon_cell cell = cells.at(cell_index++);
133 cell.channel0() = 0;
134 cell.channel1() = static_cast<uint32_t>(strip_rdo.coordinates()[0] + i);
135 cell.module_index() = current_det_cond_idx;
136 cell.activation() = 1.;
137 cell.time() = 0;
138 }
139 }
140 }
141 }
142
143 if (m_common.m_CPUCellSorting) {
144 // ---- 4. Sort cells
145 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
146 m_common.sortCells(*host_copy, cells);
147
148 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
149 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
150 } else {
151 // In this case the GPU clusterization algorithm must be configured to sort
152 // the cells.
153
154 // ---- 4/5. Copy host -> device buffer and write to StoreGate ---------------
155 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
156 }
157
158 // ---- 6. Accounting
159 m_common.m_nPix += nPix;
160 m_common.m_nStrip += nStrip;
161 m_common.m_nCells += nCells;
162
163 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
164 << m_common.m_tracccCellsKey.key() << "'");
165 return StatusCode::SUCCESS;
166}
167
169{
170 ATH_MSG_DEBUG("Finalizing.");
171
172 ATH_CHECK(m_common.finalize());
173
174 return StatusCode::SUCCESS;
175}
176
177} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#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