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