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
16 ATH_CHECK(m_pixelRDOKey.initialize());
17 ATH_CHECK(m_stripRDOKey.initialize());
18
19 ATH_MSG_DEBUG("Reading from Pixel RDO key: " << m_pixelRDOKey.key());
20 ATH_MSG_DEBUG("Reading from Strip RDO key: " << m_stripRDOKey.key());
21
25
26 return StatusCode::SUCCESS;
27}
28
29
30// Two boolean checks taken from ACTS StripClusteringTool
31
32bool RDOtoTracccCellConverterAlg::passTiming(const std::bitset<3>& timePattern) const {
33 // Convert the given timebin to a bit set and test each bit
34 // if bit is -1 (i.e. X) it always passes, other wise require exact match of 0/1
35 // N.B bitset has opposite order to the bit pattern we define
36 if (m_timeBinBits[0] != -1 and timePattern.test(2) != static_cast<bool>(m_timeBinBits[0])) return false;
37 if (m_timeBinBits[1] != -1 and timePattern.test(1) != static_cast<bool>(m_timeBinBits[1])) return false;
38 if (m_timeBinBits[2] != -1 and timePattern.test(0) != static_cast<bool>(m_timeBinBits[2])) return false;
39 return true;
40}
41
43{
44 for (size_t i = 0; i < m_timeBinStr.size(); i++) {
45 if (i >= 3) {
46 ATH_MSG_WARNING("Time bin string has excess characters");
47 break;
48 }
49 switch (std::toupper(m_timeBinStr[i])) {
50 case 'X': m_timeBinBits[i] = -1; break;
51 case '0': m_timeBinBits[i] = 0; break;
52 case '1': m_timeBinBits[i] = 1; break;
53 default:
54 ATH_MSG_FATAL("Invalid time bin string: " << m_timeBinStr);
55 return StatusCode::FAILURE;
56 }
57 }
58 return StatusCode::SUCCESS;
59}
60
61StatusCode RDOtoTracccCellConverterAlg::execute(const EventContext& ctx) const
62{
63 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
64
65 // ---- 0. Init
66 auto pixelRDOHandle = SG::makeHandle(m_pixelRDOKey, ctx);
67 ATH_CHECK(pixelRDOHandle.isValid());
68 auto stripRDOHandle = SG::makeHandle(m_stripRDOKey, ctx);
69 ATH_CHECK(stripRDOHandle.isValid());
70
71 // ---- 1. Count Pixel and Strip hits: creating the traccc SoA requires
72 // knowing their size upon creation.
73
74 size_type nPix = 0, nStrip = 0;
75
76 for (const auto* coll : *pixelRDOHandle) {
77 if (coll) {
78 nPix += coll->size();
79 }
80 }
81 for (const auto* coll : *stripRDOHandle) {
82 if (coll) {
83 for (const SCT_RDORawData* rdo : *coll) {
84 //Check type in debug build otherwise assume it is correct
85 assert(dynamic_cast<const SCT3_RawData*>(rdo)!=nullptr);
86 const SCT3_RawData* raw3 = static_cast<const SCT3_RawData*>(rdo);
87
88 std::bitset<3> timePattern(raw3->getTimeBin());
89 if (!passTiming(timePattern)) {
90 ATH_MSG_DEBUG("Strip failed timing check");
91 continue;
92 }
93 nStrip += rdo->getGroupSize();
94 }
95 }
96 }
97
98 ATH_MSG_DEBUG("Found " << nPix << " Pixel RDOs and " << nStrip
99 << " Strip RDOs, total " << (nPix + nStrip) << " RDOs");
100 size_type const nCells = nPix + nStrip;
101
102 if (nCells == 0) {
103 ATH_MSG_DEBUG("no input hits");
104 return StatusCode::SUCCESS;
105 }
106
107 // ---- 2. Create the output cell buffer.
108 auto host_copy = m_common.m_copiesTool->hostCopy(ctx);
109 traccc::edm::silicon_cell_collection::buffer traccc_cells_host_buffer{
110 nCells, m_common.m_hostMR->mr()};
111 host_copy->setup(traccc_cells_host_buffer)->wait();
112
113 // Create a "device" collection around the buffer to work on it
114 traccc::edm::silicon_cell_collection::device cells{traccc_cells_host_buffer};
115
116 // ---- 3. Convert RDOs to traccc cells
117 // The traccc buffers are not default initialized: all members must be set.
118
119 size_type cell_index = 0;
120 uint64_t current_geometry_id = detray::geometry::identifier{}.value();
121 unsigned int current_det_cond_idx = -1;
122
123 // Convert Pixel RDOs
124 for (const auto* coll : *pixelRDOHandle) {
125
126 for (const PixelRDORawData* rdo : *coll) {
127 const Identifier rdoId = rdo->identify();
129 m_pixelManager->getDetectorElement(rdoId);
130 if (!el) continue;
131 const Identifier modId = el->identify();
132 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
133 const uint64_t geoId = m_common.m_athenaToDetray->at(modId);
134
135 if (geoId != current_geometry_id) {
136 current_geometry_id = geoId;
137 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
138 }
139
140 float activation = 1.;
141 if (m_common.m_UsePixelToTForCellActivation) {
142 activation = static_cast<float>(rdo->getToT());
143 if (activation == 0.) {
144 ATH_MSG_ERROR("input data error: RDO must not have ToT=0; RDO index: "
145 << cell_index);
146 }
147 }
148
149 traccc::edm::silicon_cell cell = cells.at(cell_index++);
150 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex());
151 cell.channel1() = static_cast<uint32_t>(cellId.etaIndex());
152 cell.module_index() = current_det_cond_idx;
153 cell.activation() = activation;
154 cell.time() = 0;
155 }
156 }
157
158 // Convert Strip RDOs
159 for (const auto* coll : *stripRDOHandle) {
160 for (const SCT_RDORawData* rdo : *coll) {
161 //Check type in debug build otherwise assume it is correct
162 assert(dynamic_cast<const SCT3_RawData*>(rdo)!=nullptr);
163 const SCT3_RawData* raw3 = static_cast<const SCT3_RawData*>(rdo);
164
165 std::bitset<3> timePattern(raw3->getTimeBin());
166 if (!passTiming(timePattern)) {
167 ATH_MSG_DEBUG("Strip failed timing check");
168 continue;
169 }
170
171 const Identifier rdoId = rdo->identify();
173 m_stripManager->getDetectorElement(rdoId);
174 if (!el) continue;
175 const Identifier modId = el->identify();
176 const InDetDD::SiCellId cellId = el->cellIdFromIdentifier(rdoId);
177 const uint64_t geoId = m_common.m_athenaToDetray->at(modId);
178
179 if (geoId != current_geometry_id) {
180 current_geometry_id = geoId;
181 current_det_cond_idx = m_common.m_DetrayIdToDetDescrIndexMap.at(current_geometry_id);
182 }
183
184 if (m_common.m_stripID->barrel_ec(modId) == 0) {
185 for (int i = 0; i < rdo->getGroupSize(); ++i) {
186
187 traccc::edm::silicon_cell cell = cells.at(cell_index++);
188 cell.channel0() = static_cast<uint32_t>(cellId.phiIndex() + i);
189 cell.channel1() = 0;
190 cell.module_index() = current_det_cond_idx;
191 cell.activation() = 1.;
192 cell.time() = 0;
193
194 }
195 } else {
196 for (int i = 0; i < rdo->getGroupSize(); ++i) {
197
198 traccc::edm::silicon_cell cell = cells.at(cell_index++);
199 cell.channel0() = 0;
200 cell.channel1() = static_cast<uint32_t>(cellId.phiIndex() + i);
201 cell.module_index() = current_det_cond_idx;
202 cell.activation() = 1.;
203 cell.time() = 0;
204
205 }
206 }
207 }
208 }
209
210 // ---- 4. Sort cells
211 if (m_common.m_CPUCellSorting) {
212 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer =
213 m_common.sortCells(*host_copy, cells);
214
215 // ---- 5. Copy host -> device buffer and write to StoreGate ---------------
216 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, sorted_cells_host_buffer));
217 } else {
218 // In this case the GPU clusterization algorithm must be configured to sort
219 // the cells.
220
221 // ---- 4/5. Copy host -> device buffer and write to StoreGate
222 ATH_CHECK(m_common.copyToGpuAndRecordToSG(ctx, traccc_cells_host_buffer));
223 }
224
225 // ---- 6. Accounting
226 m_common.m_nPix += nPix;
227 m_common.m_nStrip += nStrip;
228 m_common.m_nCells += nCells;
229
230 ATH_MSG_DEBUG("Wrote " << nCells << " cells to '"
231 << m_common.m_tracccCellsKey.key() << "'");
232 return StatusCode::SUCCESS;
233}
234
236{
237 ATH_MSG_DEBUG("Finalizing.");
238
239 ATH_CHECK(m_common.finalize());
240
241 return StatusCode::SUCCESS;
242}
243
244} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
bool passTiming(const std::bitset< 3 > &timePattern) const
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())