ATLAS Offline Software
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
11 #include "StoreGate/ReadHandle.h"
12 #include "StoreGate/WriteHandle.h"
13 
15 
17 #include "Acts/Geometry/TrackingGeometry.hpp"
18 
19 namespace ActsTrk {
21  AthReentrantAlgorithm(name, pSvcLocator) {}
22 
24 
27  ATH_CHECK(m_detEleCollKeys.initialize());
29  return StatusCode::SUCCESS;
30 }
31 
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 
77 void
79  std::unordered_map<unsigned long long,
80  unsigned int> &detector_element_to_volume_id)
81 const
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 }
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::ActsVolumeIdToDetectorElementCollectionMappingAlg
ActsVolumeIdToDetectorElementCollectionMappingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx:20
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::createDetectorElementToVolumeIdMap
void createDetectorElementToVolumeIdMap(const Acts::TrackingGeometry &acts_tracking_geometry, std::unordered_map< unsigned long long, unsigned int > &detector_element_to_volume_id) const
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx:78
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::m_volumeIdToDetectorElementCollMapKey
SG::WriteCondHandleKey< ActsTrk::ActsVolumeIdToDetectorElementCollectionMap > m_volumeIdToDetectorElementCollMapKey
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.h:37
ActsGeometryContext.h
ActsTrk::ActsVolumeIdToDetectorElementCollectionMap::collecionMap
const std::array< unsigned char, 256 > & collecionMap() const
Definition: ActsVolumeIdToDetectorElementCollectionMap.h:36
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx:32
ActsDetectorElement::upstreamDetectorElement
const GeoVDetectorElement * upstreamDetectorElement() const
Returns the underllying GeoModel detectorelement that this one is based on.
Definition: ActsDetectorElement.cxx:286
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::m_trackingGeometryTool
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.h:31
ActsTrk::ActsVolumeIdToDetectorElementCollectionMap::registerCollection
void registerCollection(unsigned int volume_id, const InDetDD::SiDetectorElementCollection *collection)
Definition: ActsVolumeIdToDetectorElementCollectionMap.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteCondHandle.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsDetectorElement
Definition: ActsDetectorElement.h:44
ActsDetectorElement.h
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::initialize
StatusCode initialize() override
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.cxx:25
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection >
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::m_detEleCollKeys
SG::ReadCondHandleKeyArray< InDetDD::SiDetectorElementCollection > m_detEleCollKeys
Definition: ActsVolumeIdToDetectorElementCollectionMappingAlg.h:34
ActsTrk::ActsVolumeIdToDetectorElementCollectionMappingAlg::~ActsVolumeIdToDetectorElementCollectionMappingAlg
virtual ~ActsVolumeIdToDetectorElementCollectionMappingAlg()
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
IOVInfiniteRange::infiniteTime
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Definition: IOVInfiniteRange.h:47
ReadHandle.h
Handle class for reading from StoreGate.
test_pyathena.counter
counter
Definition: test_pyathena.py:15
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
ActsTrk::ActsVolumeIdToDetectorElementCollectionMap::collection
const InDetDD::SiDetectorElementCollection * collection(unsigned int volume_id) const
Definition: ActsVolumeIdToDetectorElementCollectionMap.h:33
ActsVolumeIdToDetectorElementCollectionMappingAlg.h
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:71