ATLAS Offline Software
Loading...
Searching...
No Matches
InDetToXAODSpacePointConversion.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
14
15namespace InDet {
16
18 ISvcLocator *pSvcLocator)
19 : AthReentrantAlgorithm(name, pSvcLocator)
20 {}
21
23 {
24 ATH_MSG_DEBUG("Initializing " << name() << " ...");
25
29
33
36
39
41 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
42 ATH_CHECK(detStore()->retrieve(m_stripID,"SCT_ID"));
43 }
44
45 return StatusCode::SUCCESS;
46 }
47
48 StatusCode InDetToXAODSpacePointConversion::execute(const EventContext& ctx) const
49 {
50 ATH_MSG_DEBUG("Executing " << name() << " ...");
51
52 // Cluster Containers if requested
53 std::unique_ptr< xAOD::PixelClusterContainer > pixel_cluster_xaod_container = std::make_unique< xAOD::PixelClusterContainer >();
54 std::unique_ptr< xAOD::PixelClusterAuxContainer > pixel_cluster_xaod_aux_container = std::make_unique< xAOD::PixelClusterAuxContainer >();
55 pixel_cluster_xaod_container->setStore( pixel_cluster_xaod_aux_container.get() );
56
57 std::unique_ptr< xAOD::StripClusterContainer > strip_cluster_xaod_container = std::make_unique< xAOD::StripClusterContainer >();
58 std::unique_ptr< xAOD::StripClusterAuxContainer > strip_cluster_xaod_aux_container = std::make_unique< xAOD::StripClusterAuxContainer >();
59 strip_cluster_xaod_container->setStore( strip_cluster_xaod_aux_container.get() );
60
61 // Convert
62 if (m_processPixel.value()) {
63 ATH_CHECK( convertPixel(ctx, pixel_cluster_xaod_container.get()) );
64 }
65
66 if (m_processStrip.value()) {
67 std::unordered_map<Identifier, std::size_t> mapClusters{};
69 strip_cluster_xaod_container.get(),
70 mapClusters) );
72 strip_cluster_xaod_container.get(),
73 mapClusters) );
74 }
75
76 // Save optional clusters
78 if (m_processPixel.value()) {
80 ATH_CHECK( pixel_cluster_xaod_handle.record( std::move(pixel_cluster_xaod_container),
81 std::move(pixel_cluster_xaod_aux_container) ) );
82 }
83
84 if (m_processStrip.value()) {
86 ATH_CHECK( strip_cluster_xaod_handle.record( std::move(strip_cluster_xaod_container),
87 std::move(strip_cluster_xaod_aux_container) ) );
88 }
89 }
90
91 return StatusCode::SUCCESS;
92 }
93
94 StatusCode InDetToXAODSpacePointConversion::convertPixel(const EventContext& ctx,
95 xAOD::PixelClusterContainer* cluster_xaod_container) const
96 {
97 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointCollection > > linkAcc("pixelSpacePointLink");
98
99 const InDetDD::SiDetectorElementCollection* pixElements = nullptr;
100 if (m_convertClusters) {
102 if (not pixelDetEleHandle.isValid()) {
103 ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
104 return StatusCode::FAILURE;
105 }
106 pixElements = pixelDetEleHandle.cptr();
107 }
108
109 // Input
111 ATH_CHECK( pixel_handle.isValid() );
112 const ::SpacePointContainer* pixel_container = pixel_handle.cptr();
113
114 // Output
115 std::unique_ptr< xAOD::SpacePointContainer > pixel_xaod_container = std::make_unique< xAOD::SpacePointContainer >(SG::VIEW_ELEMENTS, SG::ALWAYS_TRACK_INDICES);
116 std::unique_ptr< xAOD::SpacePointAuxContainer > pixel_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
117 pixel_xaod_container->setStore( pixel_xaod_aux_container.get() );
118
119 size_t nsp = 0;
120 for (const ::SpacePointCollection *spc : *pixel_container) {
121 nsp += spc->size();
122 }
124 pixel_xaod_container->push_new (nsp, [&pool](){return pool.nextElementPtr();});
125 size_t isp = 0;
126
127 // Conversion
128 for (const ::SpacePointCollection *spc : *pixel_container) {
129 for (const Trk::SpacePoint *sp : *spc) {
130 const InDet::PixelSpacePoint *indetSP = dynamic_cast<const InDet::PixelSpacePoint *>(sp);
131 if (!indetSP)[[unlikely]] continue;
132 xAOD::SpacePoint* pixel_sp = pixel_xaod_container->at (isp++);
134
135 // Also make cluster object, if requested
136 if (m_convertClusters) {
137 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
138 const InDet::PixelCluster* theCluster = dynamic_cast<const InDet::PixelCluster*>(clusterList.first);
139 if (theCluster == nullptr) {
140 ATH_MSG_FATAL("Cannot cast InDet::PixelCluster");
141 }
142
143 auto clusterId = clusterList.first->identify();
144 const InDetDD::SiDetectorElement *element = pixElements->getDetectorElement(m_pixelID->wafer_hash(m_pixelID->wafer_id(clusterId)));
145 if ( element == nullptr ) {
146 ATH_MSG_FATAL( "Invalid pixel detector element for cluster identifier " << clusterId );
147 return StatusCode::FAILURE;
148 }
149
150 xAOD::PixelCluster * pixelCl = new xAOD::PixelCluster();
151 cluster_xaod_container->push_back(pixelCl);
152 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster, *element, *pixelCl) );
153 pixel_sp->setMeasurements( {cluster_xaod_container->back()} );
154 }
155
156 // Add link to this space point
157 ElementLink< ::SpacePointCollection > link(indetSP, *spc);
158 linkAcc(*pixel_sp) = link;
159 }
160 }
161
162 // Store
164 ATH_CHECK( pixel_xaod_handle.record( std::move(pixel_xaod_container), std::move(pixel_xaod_aux_container) ) );
165
166 return StatusCode::SUCCESS;
167 }
168
169 StatusCode InDetToXAODSpacePointConversion::convertStrip(const EventContext& ctx,
170 xAOD::StripClusterContainer* cluster_xaod_container,
171 std::unordered_map<Identifier, std::size_t>& mapClusters) const
172 {
173 const InDetDD::SiDetectorElementCollection* stripElements = nullptr;
174 if (m_convertClusters) {
176 if (not stripDetEleHandle.isValid()) {
177 ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
178 return StatusCode::FAILURE;
179 }
180 stripElements = stripDetEleHandle.cptr();
181 }
182
183 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointCollection > > linkAcc("sctSpacePointLink");
184
185 // Input
187 ATH_CHECK( strip_handle.isValid() );
188 const ::SpacePointContainer* strip_container = strip_handle.cptr();
189
190 // Output
191 std::unique_ptr< xAOD::SpacePointContainer > strip_xaod_container = std::make_unique< xAOD::SpacePointContainer >();
192 std::unique_ptr< xAOD::SpacePointAuxContainer > strip_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
193 strip_xaod_container->setStore( strip_xaod_aux_container.get() );
194
195 strip_xaod_container->reserve(strip_container->size());
196 strip_xaod_aux_container->reserve(strip_container->size());
197
198 // Conversion
199 for (const ::SpacePointCollection *spc : *strip_container) {
200 for (const Trk::SpacePoint *sp : *spc) {
201 const InDet::SCT_SpacePoint *indetSP = static_cast<const InDet::SCT_SpacePoint *>(sp);
202
203 strip_xaod_container->push_back( new xAOD::SpacePoint() );
204 ATH_CHECK( TrackingUtilities::convertTrkToXaodStripSpacePoint(*indetSP, *strip_xaod_container->back()) );
205
206 // Also make cluster object, if requested
207 if (m_convertClusters) {
208 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
209 const InDet::SCT_Cluster* theCluster1 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.first);
210 const InDet::SCT_Cluster* theCluster2 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.second);
211 if (theCluster1 == nullptr or
212 theCluster2 == nullptr) {
213 ATH_MSG_FATAL("Cannot cast InDet::SCT_Cluster");
214 }
215
216 auto clusterId1 = clusterList.first->identify();
217 auto clusterId2 = clusterList.second->identify();
218 const InDetDD::SiDetectorElement *element1 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId1)));
219 const InDetDD::SiDetectorElement *element2 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId2)));
220 if ( element1 == nullptr ) {
221 ATH_MSG_FATAL( "Invalid strip detector element for cluster (1) identifiers " << clusterId1 );
222 return StatusCode::FAILURE;
223 }
224 if ( element2 == nullptr ) {
225 ATH_MSG_FATAL( "Invalid strip detector element for cluster (2) identifiers " << clusterId2 );
226 return StatusCode::FAILURE;
227 }
228 //tries to insert an entry with key clusterId. Returns false and does nothing if the key already exists.
229 auto insertEntry = [&mapClusters, cluster_xaod_container](const auto & clusterId)-> bool{
230 const auto & [p,inserted] = mapClusters.try_emplace(clusterId, cluster_xaod_container->size());
231 return inserted;
232 };
233 // if cluster is not there, add entry and add cluster to container
234 if (insertEntry(clusterId1)){
235 xAOD::StripCluster * stripCl1 = new xAOD::StripCluster();
236 cluster_xaod_container->push_back(stripCl1);
237 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster1, *element1, *stripCl1) );
238 }
239 if (insertEntry(clusterId2)) {
240 xAOD::StripCluster * stripCl2 = new xAOD::StripCluster();
241 cluster_xaod_container->push_back(stripCl2);
242 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster2, *element2, *stripCl2) );
243 }
244 // Get the clusters so that we can add a link to them
245 xAOD::StripCluster * stripCl1 = cluster_xaod_container->at(mapClusters[clusterId1]);
246 xAOD::StripCluster * stripCl2 = cluster_xaod_container->at(mapClusters[clusterId2]);
247 strip_xaod_container->back()->setMeasurements( {stripCl1, stripCl2} );
248 }
249
250 // Add link to this space point
251 ElementLink< ::SpacePointCollection > link(indetSP, *spc);
252 linkAcc(*strip_xaod_container->back()) = link;
253 }
254 }
255
256 // Store
258 ATH_CHECK( strip_xaod_handle.record( std::move(strip_xaod_container), std::move(strip_xaod_aux_container) ) );
259
260 return StatusCode::SUCCESS;
261 }
262
263
265 xAOD::StripClusterContainer* cluster_xaod_container,
266 std::unordered_map<Identifier, std::size_t>& mapClusters) const
267 {
268 const InDetDD::SiDetectorElementCollection* stripElements = nullptr;
269 if (m_convertClusters) {
271 if (not stripDetEleHandle.isValid()) {
272 ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
273 return StatusCode::FAILURE;
274 }
275 stripElements = stripDetEleHandle.cptr();
276 }
277
278 // Inputs
280 ATH_CHECK( strip_overlap_handle.isValid() );
281 const ::SpacePointOverlapCollection* strip_overlap_container = strip_overlap_handle.cptr();
282
283 // Outputs
284 std::unique_ptr< xAOD::SpacePointContainer > strip_overlap_xaod_container = std::make_unique< xAOD::SpacePointContainer >();
285 std::unique_ptr< xAOD::SpacePointAuxContainer > strip_overlap_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
286 strip_overlap_xaod_container->setStore( strip_overlap_xaod_aux_container.get() );
287
288 strip_overlap_xaod_container->reserve(strip_overlap_container->size());
289 strip_overlap_xaod_aux_container->reserve(strip_overlap_container->size());
290
291 // Conversion
292 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointOverlapCollection > > stripSpacePointLinkAcc("stripOverlapSpacePointLink");
293
294 for (const Trk::SpacePoint *sp : *strip_overlap_container) {
295 const InDet::SCT_SpacePoint *indetSP = dynamic_cast<const InDet::SCT_SpacePoint *>(sp);
296 if (not indetSP)[[unlikely]] {
297 continue;
298 }
299 strip_overlap_xaod_container->push_back( new xAOD::SpacePoint() );
300 ATH_CHECK( TrackingUtilities::convertTrkToXaodStripSpacePoint(*indetSP, *strip_overlap_xaod_container->back()) );
301
302 // Also make cluster object, if requested
303 if (m_convertClusters) {
304 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
305 const InDet::SCT_Cluster* theCluster1 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.first);
306 const InDet::SCT_Cluster* theCluster2 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.second);
307 if (theCluster1 == nullptr or
308 theCluster2 == nullptr) [[unlikely]]{
309 ATH_MSG_FATAL("Cannot cast InDet::SCT_Cluster");
310 }
311
312 auto clusterId1 = clusterList.first->identify();
313 auto clusterId2 = clusterList.second->identify();
314 const InDetDD::SiDetectorElement *element1 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId1)));
315 const InDetDD::SiDetectorElement *element2 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId2)));
316
317 if ( element1 == nullptr ) {
318 ATH_MSG_FATAL( "Invalid strip detector element for cluster (1) identifiers " << clusterId1 );
319 return StatusCode::FAILURE;
320 }
321 if ( element2 == nullptr ) {
322 ATH_MSG_FATAL( "Invalid strip detector element for cluster (2) identifiers " << clusterId2 );
323 return StatusCode::FAILURE;
324 }
325 //tries to insert an entry with key clusterId. Returns false and does nothing if the key already exists.
326 auto insertEntry = [&mapClusters, cluster_xaod_container](const auto & clusterId)-> bool{
327 const auto & [p,inserted] = mapClusters.try_emplace(clusterId, cluster_xaod_container->size());
328 return inserted;
329 };
330 if (insertEntry(clusterId1)) {
331 xAOD::StripCluster * stripCl1 = new xAOD::StripCluster();
332 cluster_xaod_container->push_back(stripCl1);
333 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster1, *element1, *stripCl1) );
334 }
335 if (insertEntry(clusterId2)) {
336 xAOD::StripCluster * stripCl2 = new xAOD::StripCluster();
337 cluster_xaod_container->push_back(stripCl2);
338 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster2, *element2, *stripCl2) );
339 }
340
341 xAOD::StripCluster * stripCl1 = cluster_xaod_container->at(mapClusters[clusterId1]);
342 xAOD::StripCluster * stripCl2 = cluster_xaod_container->at(mapClusters[clusterId2]);
343 strip_overlap_xaod_container->back()->setMeasurements( {stripCl1, stripCl2} );
344 }
345
346 ElementLink< ::SpacePointOverlapCollection > TrkLink(sp, *strip_overlap_container);
347 stripSpacePointLinkAcc( *strip_overlap_xaod_container->back() ) = TrkLink;
348 }
349
350 // Store
352 ATH_CHECK( strip_overlap_xaod_handle.record( std::move(strip_overlap_xaod_container), std::move(strip_overlap_xaod_aux_container) ) );
353
354 return StatusCode::SUCCESS;
355 }
356
357}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_FATAL(x,...)
static Double_t sp
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
const T * back() const
Access the last element in the collection as an rvalue.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
StatusCode convertPixel(const EventContext &ctx, xAOD::PixelClusterContainer *cluster_xaod_container) const
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsPixel
SG::ReadHandleKey< ::SpacePointContainer > m_inSpacepointsPixel
InDetToXAODSpacePointConversion(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_outClustersPixel
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsOverlap
StatusCode convertStrip(const EventContext &ctx, xAOD::StripClusterContainer *cluster_xaod_container, std::unordered_map< Identifier, std::size_t > &mapClusters) const
SG::ReadHandleKey< ::SpacePointContainer > m_inSpacepointsStrip
StatusCode convertStripOverlap(const EventContext &ctx, xAOD::StripClusterContainer *cluster_xaod_container, std::unordered_map< Identifier, std::size_t > &mapClusters) const
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
SG::ReadHandleKey< ::SpacePointOverlapCollection > m_inSpacepointsOverlap
SG::WriteHandleKey< xAOD::StripClusterContainer > m_outClustersStrip
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsStrip
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
A PixelSpacePoint is created from a PixelCluster.
An SCT_SpacePoint is created from two SCT_Cluster's from two different wafers.
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setMeasurements(std::vector< const xAOD::UncalibratedMeasurement * > &&value)
Sets the index of the measurements.
Primary Vertex Finder.
@ 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
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
StatusCode convertTrkToXaodPixelSpacePoint(const InDet::PixelSpacePoint &trkSpacePoint, xAOD::SpacePoint &xaodSpacePoint)
StatusCode convertInDetToXaodCluster(const InDet::PixelCluster &indetCluster, const InDetDD::SiDetectorElement &element, xAOD::PixelCluster &xaodCluster)
StatusCode convertTrkToXaodStripSpacePoint(const InDet::SCT_SpacePoint &trkSpacePoint, xAOD::SpacePoint &xaodSpacePoint)
Framework include files.
Definition libname.h:15
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
StripClusterContainer_v1 StripClusterContainer
Define the version of the strip cluster container.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
#define unlikely(x)