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*/
6
7namespace ActsTrk {
8
10{
11 ATH_MSG_DEBUG("Initializing");
12
13 ATH_CHECK(m_common.initialize());
14
15 ATH_CHECK(m_pixelRDOKey.initialize());
16 ATH_CHECK(m_stripRDOKey.initialize());
17
20
21 return StatusCode::SUCCESS;
22}
23
24StatusCode RDOtoTracccCellConverterAlg::execute(const EventContext& ctx) const
25{
26 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
27
28 // ---- 0. Init
29 auto pixelRDOHandle = SG::makeHandle(m_pixelRDOKey, ctx);
30 ATH_CHECK(pixelRDOHandle.isValid());
31 auto stripRDOHandle = SG::makeHandle(m_stripRDOKey, ctx);
32 ATH_CHECK(stripRDOHandle.isValid());
33
34 // ---- 1. Count Pixel and Strip hits: creating the traccc SoA requires
35 // knowing their size upon creation.
36
37 size_type nPix = 0, nStrip = 0;
38
39 for (const auto* coll : *pixelRDOHandle) {
40 if (coll) {
41 nPix += coll->size();
42 }
43 }
44 for (const auto* coll : *stripRDOHandle) {
45 if (coll) {
46 for (const SCT_RDORawData* rdo : *coll) {
47 nStrip += rdo->getGroupSize();
48 }
49 }
50 }
51
52 size_type const nCells = nPix + nStrip;
53
54 if (nCells == 0) {
55 ATH_MSG_DEBUG("no input hits");
56 return StatusCode::SUCCESS;
57 }
58
59 // ---- 2. Create the output cell buffer.
60 auto host_copy = m_common.m_copiesTool->hostCopy(ctx);
61 traccc::edm::silicon_cell_collection::buffer traccc_cells_host_buffer{
62 nCells, m_common.m_hostMR->mr()};
63 host_copy->setup(traccc_cells_host_buffer)->wait();
64
65 // Create a "device" collection around the buffer to work on it
66 traccc::edm::silicon_cell_collection::device cells{traccc_cells_host_buffer};
67
68 // ---- 3. Convert RDOs to traccc cells
69 // The traccc buffers are not default initialized: all members must be set.
70
71 size_type cell_index = 0;
72 uint64_t current_geometry_id = detray::geometry::identifier{}.value();
73 unsigned int current_det_cond_idx = -1;
74
75 // Convert Pixel RDOs
76 for (const auto* coll : *pixelRDOHandle) {
77
78 for (const PixelRDORawData* rdo : *coll) {
79 const Identifier rdoId = rdo->identify();
81 m_pixelManager->getDetectorElement(rdoId);
82 if (!el) continue;
83 const Identifier modId = el->identify();
84 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
85 const uint64_t geoId = m_common.m_athenaToDetray->at(modId);
86
87 if (geoId != current_geometry_id) {
88 current_geometry_id = geoId;
89 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
90 }
91
92 float activation = 1.;
93 if (m_common.m_UsePixelToTForCellActivation) {
94 activation = static_cast<float>(rdo->getToT());
95 if (activation == 0.) {
96 ATH_MSG_ERROR("input data error: RDO must not have ToT=0; RDO index: "
97 << cell_index);
98 }
99 }
100
101 traccc::edm::silicon_cell cell = cells.at(cell_index++);
102 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex());
103 cell.channel1() = static_cast<uint32_t>(cellId.etaIndex());
104 cell.module_index() = current_det_cond_idx;
105 cell.activation() = activation;
106 cell.time() = 0;
107 }
108 }
109
110 // Convert Strip RDOs
111 for (const auto* coll : *stripRDOHandle) {
112 for (const SCT_RDORawData* rdo : *coll) {
113 const Identifier rdoId = rdo->identify();
115 m_stripManager->getDetectorElement(rdoId);
116 if (!el) continue;
117 const Identifier modId = el->identify();
118 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
119 const uint64_t geoId = m_common.m_athenaToDetray->at(modId);
120
121 if (geoId != current_geometry_id) {
122 current_geometry_id = geoId;
123 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
124 }
125
126 if (m_common.m_stripID->barrel_ec(modId) == 0) {
127 for (int i = 0; i < rdo->getGroupSize(); ++i) {
128 traccc::edm::silicon_cell cell = cells.at(cell_index++);
129 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex() + i);
130 cell.channel1() = 0;
131 cell.module_index() = current_det_cond_idx;
132 cell.activation() = 1.;
133 cell.time() = 0;
134 }
135 } else {
136 for (int i = 0; i < rdo->getGroupSize(); ++i) {
137 traccc::edm::silicon_cell cell = cells.at(cell_index++);
138 cell.channel0() = 0;
139 cell.channel1() = static_cast<uint32_t>(cellId.phiIndex() + i);
140 cell.module_index() = current_det_cond_idx;
141 cell.activation() = 1.;
142 cell.time() = 0;
143 }
144 }
145 }
146 }
147
148 // ---- 4. Sort cells
149 if (m_common.m_CPUCellSorting) {
150 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
151 m_common.sortCells(*host_copy, cells);
152
153 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
154 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
155 } else {
156 // In this case the GPU clusterization algorithm must be configured to sort
157 // the cells.
158
159 // ---- 4/5. Copy host -> device buffer and write to StoreGate
160 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
161 }
162
163 // ---- 6. Accounting
164 m_common.m_nPix += nPix;
165 m_common.m_nStrip += nStrip;
166 m_common.m_nCells += nCells;
167
168 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
169 << m_common.m_tracccCellsKey.key() << "'");
170 return StatusCode::SUCCESS;
171}
172
174{
175 ATH_MSG_DEBUG("Finalizing.");
176
177 ATH_CHECK(m_common.finalize());
178
179 return StatusCode::SUCCESS;
180}
181
182} // 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.
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.
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())