ATLAS Offline Software
Loading...
Searching...
No Matches
ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
5
6// PACKAGE
8
9// ATHENA
13
15
17#include "Acts/Geometry/TrackingGeometry.hpp"
18
19namespace ActsTrk {
21 AthCondAlgorithm(name, pSvcLocator) {}
22
24
31
32StatusCode ActsVolumeIdToDetectorElementCollectionMappingAlg::execute(const EventContext& ctx) const {
34 volumeIdTodetectorElementCollMap{m_volumeIdToDetectorElementCollMapKey, ctx};
35 if (volumeIdTodetectorElementCollMap.isValid()) {
36 return StatusCode::SUCCESS;
37 }
38
39 volumeIdTodetectorElementCollMap.addDependency (IOVInfiniteRange::infiniteTime());
40
41 const Acts::TrackingGeometry *acts_tracking_geometry=m_trackingGeometryTool->trackingGeometry().get();
42 ATH_CHECK( acts_tracking_geometry != nullptr);
43
44 std::unique_ptr<ActsTrk::ActsVolumeIdToDetectorElementCollectionMap>
45 volume_id_to_detector_element_collection_map = std::make_unique<ActsTrk::ActsVolumeIdToDetectorElementCollectionMap>();
46
47
48 std::unordered_map<unsigned long long, unsigned int> detector_element_to_volume_id;
49 createDetectorElementToVolumeIdMap(*acts_tracking_geometry,
50 detector_element_to_volume_id);
51
53 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> det_ele_col(det_ele_col_key,ctx);
54 ATH_CHECK(det_ele_col.isValid());
55 volumeIdTodetectorElementCollMap.addDependency(det_ele_col);
56 for (const InDetDD::SiDetectorElement *det_ele : *(det_ele_col.cptr())) {
57 unsigned int vol_id = detector_element_to_volume_id.at(det_ele->identify().get_compact());
58 volume_id_to_detector_element_collection_map->registerCollection(vol_id, det_ele_col.cptr());
59 }
60 }
61 if (msgLvl(MSG::DEBUG)) {
62 unsigned int vol_i=0;
63 for (unsigned char col_i : volume_id_to_detector_element_collection_map->collecionMap()) {
64 if (col_i>0) {
65 ATH_MSG_DEBUG("Mapping " << vol_i << " -> " << static_cast<unsigned int>(col_i)
66 << " : " << static_cast<const void *>(volume_id_to_detector_element_collection_map->collection(vol_i)));
67 }
68 ++vol_i;
69 }
70 }
71
72 ATH_CHECK( volumeIdTodetectorElementCollMap.record( std::move(volume_id_to_detector_element_collection_map) ) );
73
74 return StatusCode::SUCCESS;
75}
76
77void
79 std::unordered_map<unsigned long long,
80 unsigned int> &detector_element_to_volume_id)
81const
82{
83 using Counter = struct { unsigned int n_detector_elements, n_missing_detector_elements, n_wrong_type; };
84 Counter counter {0u,0u,0u};
85 acts_tracking_geometry.visitSurfaces([&counter, &detector_element_to_volume_id](const Acts::Surface *surface_ptr) {
86 if (!surface_ptr) return;
87 const Acts::Surface &surface = *surface_ptr;
88 const Acts::DetectorElementBase*detector_element = surface.associatedDetectorElement();
89 if (detector_element) {
90 const ActsDetectorElement *acts_detector_element = dynamic_cast<const ActsDetectorElement*>(detector_element);
91 if (acts_detector_element) {
92 const auto*trk_detector_element = dynamic_cast<const Trk::TrkDetElementBase*>(acts_detector_element->upstreamDetectorElement());
93 if(trk_detector_element != nullptr) {
94 detector_element_to_volume_id.insert( std::make_pair( trk_detector_element->identify().get_compact(), surface.geometryId().volume()));
95 }
96 else {
97 ++counter.n_wrong_type;
98 }
99 }
100 else {
101 ++counter.n_wrong_type;
102 }
103 ++counter.n_detector_elements;
104 }
105 else {
106 ++counter.n_missing_detector_elements;
107 }
108 }, true /*sensitive surfaces*/);
109
110 ATH_MSG_DEBUG( "Surfaces without associated detector elements " << counter.n_missing_detector_elements
111 << " (with " << counter.n_detector_elements << ")" );
112 if (counter.n_detector_elements==0) {
113 ATH_MSG_ERROR( "No surface with associated detector element" );
114 }
115 if (counter.n_wrong_type>0) {
116 ATH_MSG_WARNING( "Surfaces associated to detector elements not of type Trk::TrkDetElementBase :" << counter.n_wrong_type);
117 }
118}
119
120}
#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)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const GeoVDetectorElement * upstreamDetectorElement() const
Returns the underllying GeoModel detectorelement that this one is based on.
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...