ATLAS Offline Software
Loading...
Searching...
No Matches
TracccMeasurementConverterAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
8
12
13#include "TrkSurfaces/Surface.h"
14
15#include <stdexcept>
16
17namespace ActsTrk {
18
20{
21 ATH_MSG_DEBUG("Initializing.");
22
23 ATH_CHECK(m_hostMR.retrieve());
24 ATH_CHECK(m_copy.retrieve());
25
26 ATH_CHECK(m_inputMeasKey.initialize());
27 ATH_CHECK(m_outputPixelKey.initialize());
28 ATH_CHECK(m_outputStripKey.initialize());
29
30 ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
31 ATH_CHECK(detStore()->retrieve(m_stripID, "SCT_ID"));
32 ATH_CHECK(detStore()->retrieve(m_pixelManager));
33 ATH_CHECK(detStore()->retrieve(m_stripManager));
34
35 m_detrayToAthena = &m_detDescSvc->detrayToAthenaMap();
36
37 ATH_MSG_DEBUG("Successfully initialized");
38 return StatusCode::SUCCESS;
39}
40
41StatusCode TracccMeasurementConverterAlg::execute(const EventContext& ctx) const
42{
43 // ---- Read input ----
45 measurements{m_inputMeasKey, ctx};
46 ATH_CHECK(measurements.isValid());
47
48 auto copy = m_copy->copy(ctx);
49 traccc::edm::measurement_collection::host meas_host{m_hostMR->mr()};
50 (*copy)(*measurements, meas_host)->wait();
51 ATH_MSG_DEBUG("Copied " << meas_host.size() << " measurements.");
52
53 // ---- Count pixel vs strip ----
54 int n_pixels = 0;
55 int n_strips = 0;
56 for (std::size_t i = 0; i < meas_host.size(); ++i) {
57 if (meas_host[i].dimensions() == 2u) ++n_pixels;
58 else ++n_strips;
59 }
60
61 // ---- Create output containers ----
62 DataPool<xAOD::PixelCluster> pixel_pool(ctx);
63 DataPool<xAOD::StripCluster> strip_pool(ctx);
64
65 auto pixel_cont = std::make_unique<xAOD::PixelClusterContainer>(
67 auto pixel_aux = std::make_unique<xAOD::PixelClusterAuxContainer>();
68 auto strip_cont = std::make_unique<xAOD::StripClusterContainer>(
70 auto strip_aux = std::make_unique<xAOD::StripClusterAuxContainer>();
71
72 pixel_pool.reserve(n_pixels);
73 strip_pool.reserve(n_strips);
74
75 pixel_cont->push_new(n_pixels,
76 [&pixel_pool]() { return pixel_pool.nextElementPtr(); });
77 strip_cont->push_new(n_strips,
78 [&strip_pool]() { return strip_pool.nextElementPtr(); });
79
80 pixel_aux->resize(pixel_cont->size());
81 strip_aux->resize(strip_cont->size());
82
83 pixel_cont->setStore(pixel_aux.get());
84 strip_cont->setStore(strip_aux.get());
85
86 // ---- Convert ----
87 auto pixItr = pixel_cont->begin();
88 auto stripItr = strip_cont->begin();
89
90 size_t pixel_idx = 0;
91 size_t strip_idx = 0;
92
93 for (std::size_t i = 0; i < meas_host.size(); ++i) {
94 const auto& meas = meas_host[i];
95 const uint64_t detrayId = meas.surface_link().value();
96 const Identifier athenaId = m_detrayToAthena->at(detrayId);
97
98 if (meas.dimensions() == 2u) {
99 // ---- Pixel ----
100 xAOD::PixelCluster* xaod_pcl = *pixItr; ++pixItr;
101
102 const IdentifierHash pixHash = m_pixelID->wafer_hash(athenaId);
103 const InDetDD::SiDetectorElement* pDE =
104 m_pixelManager->getDetectorElement(pixHash);
105
106 const Amg::Vector2D localPos(meas.local_position()[0],
107 meas.local_position()[1]);
108 const Amg::Vector3D gp = pDE->globalPosition(localPos);
109
110 Eigen::Matrix<float, 2, 1> localPosition(localPos.x(), localPos.y());
111 Eigen::Matrix<float, 2, 2> localCovariance =
112 Eigen::Matrix<float, 2, 2>::Zero();
113 localCovariance(0, 0) = meas.local_variance()[0];
114 localCovariance(1, 1) = meas.local_variance()[1];
115
116 const Identifier hitId(athenaId.get_compact() + pixel_idx + strip_idx);
117
118 xaod_pcl->setMeasurement<2>(pixHash, localPosition, localCovariance);
119 xaod_pcl->globalPosition() =
120 Eigen::Matrix<float, 3, 1>(gp.x(), gp.y(), gp.z());
121 xaod_pcl->setIdentifier(hitId.get_compact());
122 xaod_pcl->setWidthInEta(meas.diameter());
123
124 ++pixel_idx;
125
126 } else {
127 // ---- Strip ----
128 xAOD::StripCluster* xaod_scl = *stripItr; ++stripItr;
129
130 const IdentifierHash stripHash = m_stripID->wafer_hash(athenaId);
131 const InDetDD::SiDetectorElement* pDE =
132 m_stripManager->getDetectorElement(stripHash);
133
134 Eigen::Matrix<float, 1, 1> localPosition = Eigen::Matrix<float, 1, 1>::Zero();
135 Eigen::Matrix<float, 1, 1> localCovariance = Eigen::Matrix<float, 1, 1>::Zero();
136
137 if (pDE->isBarrel()) {
138 localPosition(0, 0) = meas.local_position()[0];
139 localCovariance(0, 0) = meas.local_variance()[0];
140 } else {
141 localPosition(0, 0) = meas.local_position()[1];
142 localCovariance(0, 0) = meas.local_variance()[1];
143 }
144
145 const Identifier hitId(athenaId.get_compact() + pixel_idx + strip_idx);
146
147 xaod_scl->setMeasurement<1>(stripHash, localPosition, localCovariance);
148 xaod_scl->setIdentifierHash(stripHash);
149 xaod_scl->setIdentifier(hitId.get_compact());
150 ++strip_idx;
151 }
152 }
153
154 ATH_MSG_DEBUG("Converted " << pixel_idx << " pixel clusters, "
155 << strip_idx << " strip clusters");
156
157 m_nMeas += meas_host.size();
158 m_nPix += pixel_idx;
159 m_nStrip += strip_idx;
160
161 // ---- Write outputs ----
163 ATH_CHECK(pixelHandle.record(std::move(pixel_cont), std::move(pixel_aux)));
164
166 ATH_CHECK(stripHandle.record(std::move(strip_cont), std::move(strip_aux)));
167
168 return StatusCode::SUCCESS;
169}
170
172{
173 ATH_MSG_DEBUG("Finalizing.");
174
175 ATH_MSG_DEBUG("Received total number of measurements = " << m_nMeas
176 << ", of which pixel clusters = " << m_nPix
177 << " and strip clusters = " << m_nStrip);
178
179 ATH_MSG_DEBUG("Successfully finalized");
180 return StatusCode::SUCCESS;
181}
182
183} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
SG::ReadHandleKey< traccc::edm::measurement_collection::buffer > m_inputMeasKey
SG::WriteHandleKey< xAOD::StripClusterContainer > m_outputStripKey
ServiceHandle< ActsTrk::IDeviceDetectorDescriptionProviderSvc > m_detDescSvc
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
const std::unordered_map< uint64_t, Identifier > * m_detrayToAthena
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_outputPixelKey
const InDetDD::SCT_DetectorManager * m_stripManager
const InDetDD::PixelDetectorManager * m_pixelManager
virtual StatusCode execute(const EventContext &ctx) const override
const ServiceHandle< StoreGateSvc > & detStore() const
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
void reserve(unsigned int size)
Set the desired capacity.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Class to hold geometrical description of a silicon detector element.
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the pixel cluster.
void setWidthInEta(float widthInEta)
Sets the width of the cluster in eta (y) direction.
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
void setIdentifierHash(const DetectorIDHashType idHash)
Sets the IdentifierHash of the measurement (corresponds to the detector element IdentifierHash).
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
@ ALWAYS_TRACK_INDICES
Always track indices, regardless of the setting of the ownership policy.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.