ATLAS Offline Software
ActsTrackingGeometryTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "Acts/Geometry/TrackingGeometry.hpp"
10 
11 
12 using namespace ActsTrk;
13 
15  ATH_MSG_DEBUG(name() << " initializing");
16  if (parent() != toolSvc()) {
17  ATH_MSG_ERROR("The tool is initialized as a private tool but should be public");
18  return StatusCode::FAILURE;
19  }
20  ATH_CHECK(m_trackingGeometrySvc.retrieve());
21  ATH_CHECK(m_rchk.initialize());
22  m_detIdMap = createDetectorElementToGeoIdMap();
23  if (!m_detIdMap) {
24  return StatusCode::FAILURE;
25  }
26  return StatusCode::SUCCESS;
27 }
28 
29 std::shared_ptr<const Acts::TrackingGeometry> ActsTrackingGeometryTool::trackingGeometry() const {
30  return m_trackingGeometrySvc->trackingGeometry();
31 }
33  return m_detIdMap.get();
34 }
35 
36 const GeometryContext& ActsTrackingGeometryTool::getGeometryContext(const EventContext& ctx) const {
37  ATH_MSG_DEBUG("Creating alignment context for event");
38  const GeometryContext* geoCtx{nullptr};
39  if (!SG::get(geoCtx, m_rchk, ctx).isSuccess()) {
40  ATH_MSG_ERROR("Creating alignment context failed: read cond handle invalid!");
41  }
42  return *geoCtx;
43 }
44 
46  return m_trackingGeometrySvc->getNominalContext();
47 }
48 
49 
50 std::unique_ptr<ActsTrk::DetectorElementToActsGeometryIdMap>
52  // create map from
53  auto detector_element_to_geoid = std::make_unique<DetectorElementToActsGeometryIdMap>();
54 
55  struct Counter{
56  unsigned n_sensitive_elements{0};
57  unsigned n_detector_elements{0};
58  unsigned n_wrong_type{0};
59  };
60  Counter counter {};
61  trackingGeometry()->visitSurfaces([this, &counter, &detector_element_to_geoid](const Acts::Surface *surface) {
62  if (!surface || !surface->associatedDetectorElement()) {
63  ++counter.n_wrong_type;
64  return;
65  }
66  ++counter.n_sensitive_elements;
67  const auto* detEl = dynamic_cast<const IDetectorElementBase*>(surface->associatedDetectorElement());
68  if (!detEl) {
69  return;
70  }
71 
72  auto insert_id = [&detector_element_to_geoid, &surface, &counter](const xAOD::UncalibMeasType type,
73  const IdentifierHash& hash) {
74  detector_element_to_geoid->insert(std::make_pair(makeDetectorElementKey(type, hash),
75  DetectorElementToActsGeometryIdMap::makeValue(surface->geometryId())));
76  ++counter.n_detector_elements;
77  };
78  switch(detEl->detectorType()) {
79  using enum DetectorType;
80  case Pixel:
82  dynamic_cast<const ActsDetectorElement*>(detEl)->identifyHash());
83  break;
84  case Sct:
86  dynamic_cast<const ActsDetectorElement*>(detEl)->identifyHash());
87  break;
88  case Hgtd:
90  dynamic_cast<const ActsDetectorElement*>(detEl)->identifyHash());
91  break;
92  case Trt: {
93  break;
94  }
96  case Mdt:
97  case Rpc:
98  case Tgc:
99  case Csc:
100  case Mm:
101  case sTgc:{
102  // surface map not needed for the muon detectors
103  ++counter.n_detector_elements;
104  break;
105  }
106  case UnDefined:
107  ATH_MSG_ERROR("Undefined element encountered");
108  counter.n_detector_elements = 0;
109  return;
110  }
111  }, true /*sensitive surfaces*/);
112  ATH_MSG_INFO( "Surfaces without associated detector elements " << (counter.n_sensitive_elements -counter.n_detector_elements)
113  << " (with " << counter.n_detector_elements << ")" );
114  if (counter.n_sensitive_elements > 0 &&
115  counter.n_detector_elements==0) {
116  ATH_MSG_ERROR( "No surface with associated detector element" );
117  return nullptr;
118  }
119  if (counter.n_wrong_type>0) {
120  ATH_MSG_WARNING( "Surfaces associated to detector elements not of type Trk::TrkDetElementBase :" << counter.n_wrong_type);
121  }
122  return detector_element_to_geoid;
123 }
ActsTrackingGeometryTool::surfaceIdMap
virtual const ActsTrk::DetectorElementToActsGeometryIdMap * surfaceIdMap() const override
Definition: ActsTrackingGeometryTool.cxx:32
xAOD::UncalibMeasType::HGTDClusterType
@ HGTDClusterType
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsTrk::DetectorElementToActsGeometryIdMap
Definition: DetectorElementToActsGeometryIdMap.h:31
ActsTrk::DetectorType
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
Definition: GeometryDefs.h:17
Pixel
Definition: PixelFEUtils.h:15
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
ActsTrk::DetectorType::UnDefined
@ UnDefined
Small Thing Gap chambers (NSW)
ActsTrk::DetectorType::Tgc
@ Tgc
Resitive Plate Chambers.
ActsTrk::DetectorType::Sct
@ Sct
ActsTrackingGeometryTool::getGeometryContext
virtual const ActsTrk::GeometryContext & getGeometryContext(const EventContext &ctx) const override
Definition: ActsTrackingGeometryTool.cxx:36
ActsTrk::DetectorType::sTgc
@ sTgc
Micromegas (NSW)
Hgtd
Definition: HgtdTimedClusteringTool.cxx:10
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsTrk::IDetectorElementBase
base class interface providing the bare minimal interface extension.
Definition: IDetectorElement.h:32
ActsTrackingGeometryTool::initialize
StatusCode initialize() override
Definition: ActsTrackingGeometryTool.cxx:14
ActsTrackingGeometryTool::getNominalGeometryContext
virtual const ActsTrk::GeometryContext & getNominalGeometryContext() const override
Definition: ActsTrackingGeometryTool.cxx:45
ActsTrk::DetectorType::Mm
@ Mm
Maybe not needed in the migration.
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:283
ActsTrackingGeometryTool.h
ActsTrk::DetectorType::Csc
@ Csc
Thin gap champers.
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
ActsTrk::makeDetectorElementKey
DetectorElementKey makeDetectorElementKey(xAOD::UncalibMeasType meas_type, unsigned int identifier_hash)
Definition: DetectorElementToActsGeometryIdMap.h:23
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
ActsTrk::DetectorType::Trt
@ Trt
Maybe the Sct / Pixel for Itk become seperate entries?
ActsDetectorElement
Definition: ActsDetectorElement.h:44
ActsTrk::GeometryContext
Definition: GeometryContext.h:28
ActsDetectorElement.h
ActsTrk::DetectorType::Mdt
@ Mdt
MuonSpectrometer.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
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:25
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
ActsTrk::DetectorType::Rpc
@ Rpc
Monitored Drift Tubes.
ActsTrackingGeometryTool::createDetectorElementToGeoIdMap
std::unique_ptr< ActsTrk::DetectorElementToActsGeometryIdMap > createDetectorElementToGeoIdMap() const
Creates and popules the DetectorElement -> Acts::Surface geo identifier map from the geometry service...
Definition: ActsTrackingGeometryTool.cxx:51
IDetectorElement.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MdtCalibInput.h:31
test_pyathena.counter
counter
Definition: test_pyathena.py:15
ActsTrackingGeometryTool::trackingGeometry
virtual std::shared_ptr< const Acts::TrackingGeometry > trackingGeometry() const override
Definition: ActsTrackingGeometryTool.cxx:29
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType