ATLAS Offline Software
Loading...
Searching...
No Matches
ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
5
6// ATHENA
8
10
12#include "Acts/Geometry/TrackingGeometry.hpp"
13
14namespace ActsTrk {
16 AthCondAlgorithm(name, pSvcLocator) {}
17
19
26
27StatusCode ActsVolumeIdToDetectorElementCollectionMappingAlg::execute(const EventContext& ctx) const {
29 volumeIdTodetectorElementCollMap{m_volumeIdToDetectorElementCollMapKey, ctx};
30 if (volumeIdTodetectorElementCollMap.isValid()) {
31 return StatusCode::SUCCESS;
32 }
33
34 volumeIdTodetectorElementCollMap.addDependency (IOVInfiniteRange::infiniteTime());
35
36 const Acts::TrackingGeometry *acts_tracking_geometry=m_trackingGeometryTool->trackingGeometry().get();
37 ATH_CHECK( acts_tracking_geometry != nullptr);
38
39 std::unique_ptr<ActsTrk::ActsVolumeIdToDetectorElementCollectionMap>
40 volume_id_to_detector_element_collection_map = std::make_unique<ActsTrk::ActsVolumeIdToDetectorElementCollectionMap>();
41
42
43 std::unordered_map<unsigned long long, unsigned int> detector_element_to_volume_id;
44 createDetectorElementToVolumeIdMap(*acts_tracking_geometry,
45 detector_element_to_volume_id);
46
48 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> det_ele_col(det_ele_col_key,ctx);
49 ATH_CHECK(det_ele_col.isValid());
50 volumeIdTodetectorElementCollMap.addDependency(det_ele_col);
51 for (const InDetDD::SiDetectorElement *det_ele : *(det_ele_col.cptr())) {
52 unsigned int vol_id = detector_element_to_volume_id.at(det_ele->identify().get_compact());
53 volume_id_to_detector_element_collection_map->registerCollection(vol_id, det_ele_col.cptr());
54 }
55 }
56 if (msgLvl(MSG::DEBUG)) {
57 unsigned int vol_i=0;
58 for (unsigned char col_i : volume_id_to_detector_element_collection_map->collecionMap()) {
59 if (col_i>0) {
60 ATH_MSG_DEBUG("Mapping " << vol_i << " -> " << static_cast<unsigned int>(col_i)
61 << " : " << static_cast<const void *>(volume_id_to_detector_element_collection_map->collection(vol_i)));
62 }
63 ++vol_i;
64 }
65 }
66
67 ATH_CHECK( volumeIdTodetectorElementCollMap.record( std::move(volume_id_to_detector_element_collection_map) ) );
68
69 return StatusCode::SUCCESS;
70}
71
72void
74 std::unordered_map<unsigned long long,
75 unsigned int> &detector_element_to_volume_id)
76const
77{
78 struct Counter { unsigned int n_detector_elements{0};
79 unsigned int n_missing_detector_elements{0};
80 unsigned int n_wrong_type{0}; };
81 Counter counter {0u,0u,0u};
82 acts_tracking_geometry.visitSurfaces([&counter, &detector_element_to_volume_id](const Acts::Surface *surface_ptr) {
83 const auto* acts_detector_element = getActsDetectorElement(surface_ptr);
84 if (acts_detector_element) {
85 const auto*trk_detector_element = dynamic_cast<const Trk::TrkDetElementBase*>(acts_detector_element->upstreamDetectorElement());
86 if(trk_detector_element != nullptr) {
87 detector_element_to_volume_id.insert( std::make_pair( trk_detector_element->identify().get_compact(), surface_ptr->geometryId().volume()));
88 } else {
89 ++counter.n_wrong_type;
90 }
91 ++counter.n_detector_elements;
92 } else {
93 ++counter.n_missing_detector_elements;
94 }
95 }, true /*sensitive surfaces*/);
96
97 ATH_MSG_DEBUG( "Surfaces without associated detector elements " << counter.n_missing_detector_elements
98 << " (with " << counter.n_detector_elements << ")" );
99 if (counter.n_detector_elements==0) {
100 ATH_MSG_ERROR( "No surface with associated detector element" );
101 }
102 if (counter.n_wrong_type>0) {
103 ATH_MSG_WARNING( "Surfaces associated to detector elements not of type Trk::TrkDetElementBase :" << counter.n_wrong_type);
104 }
105}
106
107}
const ActsDetectorElement * getActsDetectorElement(const Acts::Surface &surf)
Attempts to retrieve the ActsDetectorElement associated to the passed ActsSurface.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void createDetectorElementToVolumeIdMap(const Acts::TrackingGeometry &acts_tracking_geometry, std::unordered_map< unsigned long long, unsigned int > &detector_element_to_volume_id) const
SG::ReadCondHandleKeyArray< InDetDD::SiDetectorElementCollection > m_detEleCollKeys
ActsVolumeIdToDetectorElementCollectionMappingAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< ActsTrk::ActsVolumeIdToDetectorElementCollectionMap > m_volumeIdToDetectorElementCollMapKey
bool msgLvl(const MSG::Level lvl) const
Base class for conditions algorithms.
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Class to hold geometrical description of a silicon detector element.
const_pointer_type cptr()
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
This is the base class for all tracking detector elements with read-out relevant information.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...