ATLAS Offline Software
Loading...
Searching...
No Matches
RDOtoTracccCellConverterCommons.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
11#include <GaudiKernel/IMessageSvc.h>
12
13#include <algorithm>
14#include <cstddef>
15
16namespace ActsTrk {
17
20 : AthMessaging{"RDOtoTracccCellConverterCommons"}
21 , m_parent{parent}
22 , m_tracccCellsKey{&parent, "TracccCells", "", "Output traccc cell collection buffer"}
23 , m_hostMR{&parent, "HostMR", "", "The host memory resource tool to use"}
24 , m_deviceMR{&parent, "DeviceMR", "", "The device memory resource tool to use"}
25 , m_copiesTool{&parent, "CopiesTool", "", "Tool that provides host and device copy objects"}
26 , m_geoIdMappingObjectName{&parent, "GeoIdMappingObjectName", "",
27 "StoreGate name for the detray/acts/athena geo id mapping"}
28 , m_hostCondObjectName{&parent, "HostConditionsObjectName", "",
29 "Traccc host conditions object"}
30 , m_CPUCellSorting{&parent, "CPUCellSorting", false,
31 "Whether to sort traccc cells on CPU or GPU"}
32 , m_UsePixelToTForCellActivation{&parent, "UsePixelToTForCellActivation", true,
33 "Use Pixel hit time over threshold value to set traccc cell activation value, otherwise defaults to 1"}
34 , m_stripRDOTimeBinStr{&parent, "timeBins", "Allowed time bins pattern for Strip RDOs"}
35{
36}
37
39{
40 ATH_CHECK(m_parent.detStore()->retrieve(m_pixelID, "PixelID"));
41 ATH_CHECK(m_parent.detStore()->retrieve(m_stripID, "SCT_ID"));
42
43 ATH_CHECK(m_hostMR.retrieve());
44 ATH_CHECK(m_tracccCellsKey.initialize());
45 ATH_CHECK(m_copiesTool.retrieve());
46
47 ATH_CHECK(m_parent.detStore()->retrieve(m_geoIdMapping, m_geoIdMappingObjectName.value()));
48 ATH_CHECK(m_parent.detStore()->retrieve(m_hostCond, m_hostCondObjectName.value()));
49
51
52 return StatusCode::SUCCESS;
53}
54
56{
57 //TODO: change to DEBUG once we figure how to set the log level of this class
58 // from that of the parent class
59 ATH_MSG_INFO("Read total number of pixel hits = " << m_nPix
60 << ", total number of strip hits = " << m_nStrip
61 << " and created total number of traccc cells = " << m_nCells
62 );
63 return StatusCode::SUCCESS;
64}
65
66traccc::edm::silicon_cell_collection::buffer RDOtoTracccCellConverterCommons::sortCells(
67 vecmem::copy const & host_copy
68 , traccc::edm::silicon_cell_collection::device const & cells
69) const
70{
71 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer{
72 cells.size(), m_hostMR->mr()};
73 host_copy.setup(sorted_cells_host_buffer)->wait();
74 traccc::edm::silicon_cell_collection::device sorted_cells{sorted_cells_host_buffer};
75 sort_traccc_soa(sorted_cells, cells);
76 return sorted_cells_host_buffer;
77}
78
80 EventContext const & ctx
81 , traccc::edm::silicon_cell_collection::buffer const & cells
82) const
83{
84 auto device_copy = m_copiesTool->deviceCopy(ctx);
85 auto traccc_cells_gpu_buffer = std::make_unique<traccc::edm::silicon_cell_collection::buffer>(
86 cells.capacity(), m_deviceMR->mr());
87
88 // We ignore() the setup and wait() on the copy to allow parallelism.
89 device_copy->setup(*traccc_cells_gpu_buffer)->ignore();
90 (*device_copy)(cells, *traccc_cells_gpu_buffer)->wait();
91
92 auto outputTracccCells = SG::makeHandle(m_tracccCellsKey, ctx);
93 ATH_CHECK(outputTracccCells.record(std::move(traccc_cells_gpu_buffer)));
94 return StatusCode::SUCCESS;
95}
96
98 traccc::edm::silicon_cell_collection::device & sorted_cells
99 , traccc::edm::silicon_cell_collection::device const & cells
100 )
101{
102 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
103
104 std::vector<size_type> indices(cells.size());
105 std::iota(indices.begin(), indices.end(), 0u);
106
107 // Sort the indices according to the cells.
108 std::sort(indices.begin(), indices.end(),
109 [&](size_type lhs, size_type rhs) {
110 return cells.at(lhs) < cells.at(rhs);
111 });
112
113 // Fill an output container with the sorted cells.
114 size_type s = 0;
115 for (size_type i : indices) {
116 sorted_cells.at(s++) = cells.at(i);
117 }
118}
119
121{
122 static const size_t MAX_BINS = 2;
123 if (m_stripRDOTimeBinStr.size() > MAX_BINS) {
124 ATH_MSG_WARNING("Time bin string has excess characters");
125 }
126
127 for (size_t i = 0; i < MAX_BINS; ++i) {
128 switch (std::toupper(m_stripRDOTimeBinStr[i])) {
129 case 'X': m_stripRDOTimeBinBits[i] = -1; break;
130 case '0': m_stripRDOTimeBinBits[i] = 0; break;
131 case '1': m_stripRDOTimeBinBits[i] = 1; break;
132 default:
133 ATH_MSG_FATAL("Invalid time bin string: " << m_stripRDOTimeBinStr);
134 return StatusCode::FAILURE;
135 }
136 }
137 return StatusCode::SUCCESS;
138}
139
140bool RDOtoTracccCellConverterCommons::passTiming(const std::bitset<3>& timePattern) const
141{
142 // Convert the given timebin to a bit set and test each bit
143 // if bit is -1 (i.e. X) it always passes, otherwise require exact match of 0/1
144 // N.B. bitset has opposite order to the bit pattern we define
145 if (m_stripRDOTimeBinBits[0] != -1 and timePattern.test(2) != static_cast<bool>(m_stripRDOTimeBinBits[0])) return false;
146 if (m_stripRDOTimeBinBits[1] != -1 and timePattern.test(1) != static_cast<bool>(m_stripRDOTimeBinBits[1])) return false;
147 if (m_stripRDOTimeBinBits[2] != -1 and timePattern.test(0) != static_cast<bool>(m_stripRDOTimeBinBits[2])) return false;
148 return true;
149}
150
151} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
std::vector< std::vector< int64_t > > indices
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An algorithm that can be simultaneously executed in multiple threads.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
void sort_traccc_soa(traccc::edm::silicon_cell_collection::device &sorted_cells, traccc::edm::silicon_cell_collection::device const &cells)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
ToolHandle< AthDevice::IMemoryResourceTool > m_deviceMR
SG::WriteHandleKey< traccc::edm::silicon_cell_collection::buffer > m_tracccCellsKey
traccc::edm::silicon_cell_collection::buffer sortCells(vecmem::copy const &host_copy, traccc::edm::silicon_cell_collection::device const &cells) const
bool passTiming(const std::bitset< 3 > &timePattern) const
ToolHandle< AthDevice::ICopiesTool > m_copiesTool
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
const traccc::detector_conditions_description::host * m_hostCond
StatusCode copyToGpuAndRecordToSG(EventContext const &ctx, traccc::edm::silicon_cell_collection::buffer const &cells) const