ATLAS Offline Software
DetectorElementToActsGeometryIdMappingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 using namespace ActsTrk;
21  AthReentrantAlgorithm(name, pSvcLocator) {}
22 
24 
28  return StatusCode::SUCCESS;
29 }
30 
33  detectorElementToGeometryIdMap{m_detectorElementToGeometryIdMapKey, ctx};
34  if (detectorElementToGeometryIdMap.isValid()) {
35  return StatusCode::SUCCESS;
36  }
37  detectorElementToGeometryIdMap.addDependency (IOVInfiniteRange::infiniteTime());
38 
39  const Acts::TrackingGeometry *acts_tracking_geometry=m_trackingGeometryTool->trackingGeometry().get();
40  ATH_CHECK( acts_tracking_geometry != nullptr);
41 
42  std::unique_ptr<DetectorElementToActsGeometryIdMap>
43  detector_element_to_geoid = std::make_unique<DetectorElementToActsGeometryIdMap>();
44  createDetectorElementToGeoIdMap(*acts_tracking_geometry,
45  *detector_element_to_geoid);
46  ATH_CHECK( detectorElementToGeometryIdMap.record( std::move(detector_element_to_geoid) ) );
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 namespace {
52  template <typename T_EnumClass>
53  constexpr std::size_t maxType();
54 
55  template <> constexpr std::size_t maxType<ActsTrk::DetectorType>() { return to_underlying(ActsTrk::DetectorType::UnDefined); }
56  template <> [[maybe_unused]] constexpr std::size_t maxType<xAOD::UncalibMeasType>() { return to_underlying(xAOD::UncalibMeasType::nTypes); }
57 
58  template <typename T_EnumClass>
59  constexpr unsigned char toChar(T_EnumClass value) {
60  assert( sizeof(T_EnumClass) <= sizeof(std::size_t));
61  assert( static_cast<std::size_t>(to_underlying(value)) < static_cast<std::size_t>(std::numeric_limits<unsigned char>::max())
62  && static_cast<std::size_t>(to_underlying(value)) <= maxType<T_EnumClass>() );
63  return static_cast<unsigned char>(to_underlying(value));
64  }
65 
66  constexpr std::array<unsigned char, maxType<ActsTrk::DetectorType>()> makeMeasurementTypeMap() {
67  std::array<unsigned char, maxType<ActsTrk::DetectorType>()> measurement_type_map;
68  std::fill(measurement_type_map.begin(),measurement_type_map.end(), toChar(xAOD::UncalibMeasType::nTypes));
69  static_assert( to_underlying(xAOD::UncalibMeasType::nTypes) == 8 + 1 /* Other */ ); //otherwise some types are not included in this map
70  measurement_type_map[toChar(ActsTrk::DetectorType::Pixel)]=toChar(xAOD::UncalibMeasType::PixelClusterType);
71  measurement_type_map[toChar(ActsTrk::DetectorType::Sct)]=toChar(xAOD::UncalibMeasType::StripClusterType);
72  measurement_type_map[toChar(ActsTrk::DetectorType::Mdt)]=toChar(xAOD::UncalibMeasType::MdtDriftCircleType);
73  measurement_type_map[toChar(ActsTrk::DetectorType::Rpc)]=toChar(xAOD::UncalibMeasType::RpcStripType);
74  measurement_type_map[toChar(ActsTrk::DetectorType::Tgc)]=toChar(xAOD::UncalibMeasType::TgcStripType);
75  measurement_type_map[toChar(ActsTrk::DetectorType::Mm)]=toChar(xAOD::UncalibMeasType::MMClusterType);
76  measurement_type_map[toChar(ActsTrk::DetectorType::sTgc)]=toChar(xAOD::UncalibMeasType::sTgcStripType);
77  measurement_type_map[toChar(ActsTrk::DetectorType::Hgtd)]=toChar(xAOD::UncalibMeasType::HGTDClusterType);
78  return measurement_type_map;
79  }
80 }
81 
82 void DetectorElementToActsGeometryIdMappingAlg::createDetectorElementToGeoIdMap(const Acts::TrackingGeometry &acts_tracking_geometry,
83  DetectorElementToActsGeometryIdMap &detector_element_to_geoid)
84 const
85 {
86  // create map from
87  static constexpr std::array<unsigned char, maxType<ActsTrk::DetectorType>()> detector_to_measurement_type = makeMeasurementTypeMap();
88 
89  using Counter = struct { unsigned int n_detector_elements, n_missing_detector_elements, n_wrong_type; };
90  Counter counter {0u,0u,0u};
91  acts_tracking_geometry.visitSurfaces([&counter, &detector_element_to_geoid](const Acts::Surface *surface_ptr) {
92  if (!surface_ptr) return;
93  const Acts::Surface &surface = *surface_ptr;
94  const Acts::DetectorElementBase*detector_element = surface.associatedDetectorElement();
95  if (detector_element) {
96  const ActsDetectorElement *acts_detector_element = dynamic_cast<const ActsDetectorElement*>(detector_element);
97  if (acts_detector_element) {
99  meas_type = static_cast<xAOD::UncalibMeasType>(detector_to_measurement_type.at(to_underlying(acts_detector_element->detectorType())));
100  const auto*trk_detector_element = dynamic_cast<const Trk::TrkDetElementBase*>(acts_detector_element->upstreamDetectorElement());
101  if(trk_detector_element != nullptr) {
102  detector_element_to_geoid.insert( std::make_pair( makeDetectorElementKey(meas_type, trk_detector_element->identifyHash()),
103  DetectorElementToActsGeometryIdMap::makeValue(surface.geometryId())) );
104  }
105  else {
106  ++counter.n_wrong_type;
107  }
108  }
109  else {
110  ++counter.n_wrong_type;
111  }
112  ++counter.n_detector_elements;
113  }
114  else {
115  ++counter.n_missing_detector_elements;
116  }
117  }, true /*sensitive surfaces*/);
118 
119  ATH_MSG_INFO( "Surfaces without associated detector elements " << counter.n_missing_detector_elements
120  << " (with " << counter.n_detector_elements << ")" );
121  if (counter.n_detector_elements==0) {
122  ATH_MSG_ERROR( "No surface with associated detector element" );
123  }
124  if (counter.n_wrong_type>0) {
125  ATH_MSG_WARNING( "Surfaces associated to detector elements not of type Trk::TrkDetElementBase :" << counter.n_wrong_type);
126  }
127 }
128 
xAOD::UncalibMeasType::HGTDClusterType
@ HGTDClusterType
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsTrk::DetectorElementToActsGeometryIdMap
Definition: DetectorElementToActsGeometryIdMap.h:31
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::~DetectorElementToActsGeometryIdMappingAlg
virtual ~DetectorElementToActsGeometryIdMappingAlg()
ActsGeometryContext.h
ActsTrk::detail::to_underlying
constexpr std::underlying_type< T_EnumClass >::type to_underlying(T_EnumClass an_enum)
Helper to convert class enum into an integer.
Definition: HitSummaryDataUtils.h:25
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
ActsTrk::DetectorType::UnDefined
@ UnDefined
Small Thing Gap chambers (NSW)
xAOD::UncalibMeasType::MMClusterType
@ MMClusterType
ActsTrk::DetectorType::Tgc
@ Tgc
Resitive Plate Chambers.
ActsDetectorElement::upstreamDetectorElement
const GeoVDetectorElement * upstreamDetectorElement() const
Returns the underllying GeoModel detectorelement that this one is based on.
Definition: ActsDetectorElement.cxx:288
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::DetectorElementToActsGeometryIdMappingAlg
DetectorElementToActsGeometryIdMappingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DetectorElementToActsGeometryIdMappingAlg.cxx:20
ActsDetectorElement::detectorType
DetectorType detectorType() const override final
Detector type.
Definition: ActsDetectorElement.cxx:291
athena.value
value
Definition: athena.py:124
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
ActsTrk::DetectorType::Sct
@ Sct
ActsTrk::DetectorType::sTgc
@ sTgc
Micromegas (NSW)
xAOD::UncalibMeasType::sTgcStripType
@ sTgcStripType
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::m_detectorElementToGeometryIdMapKey
SG::WriteCondHandleKey< ActsTrk::DetectorElementToActsGeometryIdMap > m_detectorElementToGeometryIdMapKey
Definition: DetectorElementToActsGeometryIdMappingAlg.h:31
DetectorElementToActsGeometryIdMappingAlg.h
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::m_trackingGeometryTool
ToolHandle< IActsTrackingGeometryTool > m_trackingGeometryTool
Definition: DetectorElementToActsGeometryIdMappingAlg.h:28
xAOD::UncalibMeasType::TgcStripType
@ TgcStripType
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsTrk::DetectorType::Pixel
@ Pixel
Inner detector legacy.
ActsTrk::DetectorType::Mm
@ Mm
Maybe not needed in the migration.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
WriteCondHandle.h
ActsTrk::makeDetectorElementKey
DetectorElementKey makeDetectorElementKey(xAOD::UncalibMeasType meas_type, unsigned int identifier_hash)
Definition: DetectorElementToActsGeometryIdMap.h:23
ActsTrk::DetectorElementToActsGeometryIdMap::makeValue
static const Acts::GeometryIdentifier & makeValue(const Acts::GeometryIdentifier &geo_id)
Definition: DetectorElementToActsGeometryIdMap.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsDetectorElement
Definition: ActsDetectorElement.h:42
ActsDetectorElement.h
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
xAOD::UncalibMeasType::nTypes
@ nTypes
IOVInfiniteRange.h
ActsTrk::DetectorType::Mdt
@ Mdt
MuonSpectrometer.
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::initialize
StatusCode initialize() override
Definition: DetectorElementToActsGeometryIdMappingAlg.cxx:25
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::createDetectorElementToGeoIdMap
void createDetectorElementToGeoIdMap(const Acts::TrackingGeometry &acts_tracking_geometry, DetectorElementToActsGeometryIdMap &detector_element_to_geoid) const
Definition: DetectorElementToActsGeometryIdMappingAlg.cxx:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::DetectorElementToActsGeometryIdMappingAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: DetectorElementToActsGeometryIdMappingAlg.cxx:31
ActsTrk::DetectorType::Hgtd
@ Hgtd
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:24
ActsTrk::DetectorType::Rpc
@ Rpc
Monitored Drift Tubes.
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
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
xAOD::UncalibMeasType::RpcStripType
@ RpcStripType
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType