2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4#ifndef MUONGEOMODELR4_MUONREADOUTELEMENT_ICC
5#define MUONGEOMODELR4_MUONREADOUTELEMENT_ICC
7#include <ActsGeoUtils/TransformCache.h>
10 template <> inline Amg::Transform3D
11 TransformCacheDetEle<MuonGMR4::MuonReadoutElement>::fetchTransform(const DetectorAlignStore* store) const {
12 return m_parent->toStation(store) * MuonGMR4::detail::rotationToAMDB(detectorType());
18inline const GeoAlignableTransform* MuonReadoutElement::alignableTransform() const { return m_args.alignTransform; }
19inline Identifier MuonReadoutElement::identify() const { return m_args.detElId; }
20inline IdentifierHash MuonReadoutElement::identHash() const { return m_detElHash;}
21inline const std::string& MuonReadoutElement::chamberDesign() const { return m_args.chambDesign; }
22inline const Muon::IMuonIdHelperSvc* MuonReadoutElement::idHelperSvc() const { return m_idHelperSvc.get(); }
23inline Muon::MuonStationIndex::ChIndex MuonReadoutElement::chamberIndex() const { return m_chIdx; }
24inline int MuonReadoutElement::stationName() const { return m_stName; }
25inline int MuonReadoutElement::stationEta() const { return m_stEta; }
26inline int MuonReadoutElement::stationPhi() const { return m_stPhi; }
28/// Returns the detector center (Which is the same as the detector center of the
29/// first measurement layer)
30inline Amg::Vector3D MuonReadoutElement::center(const ActsTrk::GeometryContext& ctx) const {
31 return localToGlobalTransform(ctx).translation();
33inline Amg::Vector3D MuonReadoutElement::center(const ActsTrk::GeometryContext& ctx,
34 const Identifier& id) const {
35 return localToGlobalTransform(ctx, id).translation();
37inline Amg::Vector3D MuonReadoutElement::center(const ActsTrk::GeometryContext& ctx,
38 const IdentifierHash& hash) const {
39 return localToGlobalTransform(ctx, hash).translation();
41inline Amg::Transform3D MuonReadoutElement::globalToLocalTransform(const ActsTrk::GeometryContext& ctx,
42 const IdentifierHash& hash) const {
43 return localToGlobalTransform(ctx, hash).inverse();
45inline Amg::Transform3D MuonReadoutElement::globalToLocalTransform(const ActsTrk::GeometryContext& ctx,
46 const Identifier& id) const {
47 return globalToLocalTransform(ctx, layerHash(id));
49inline const Amg::Transform3D& MuonReadoutElement::localToGlobalTransform(const ActsTrk::GeometryContext& ctx,
50 const Identifier& id) const {
51 return localToGlobalTransform(ctx, layerHash(id));
54inline const SpectrometerSector* MuonReadoutElement::msSector() const { return m_msSectorLink; }
55inline const Chamber* MuonReadoutElement::chamber() const { return m_chambLink; }
58inline const Amg::Transform3D& MuonReadoutElement::localToGlobalTransform(const ActsTrk::GeometryContext& ctx,
59 const IdentifierHash& hash) const {
60 const ActsTrk::TransformCache* cache = transformCache(hash);
62 return cache->getTransform(ctx.getStore(detectorType()).get());
64 ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" "<<__func__<<"() -- "
65 <<idHelperSvc()->toStringDetEl(identify())<<" hash: "<<hash<<" is unknown.");
66 static const Amg::Transform3D dummyTrf{Amg::Transform3D::Identity()};
70inline const ActsTrk::TransformCache* MuonReadoutElement::transformCache(const IdentifierHash& measHash) const {
71 if (measHash == geoTransformHash()) {
72 return m_centralTrfCache.get();
74 return m_localToGlobalCaches.size() > static_cast<unsigned>(measHash) ?
75 m_localToGlobalCaches[measHash].get() : nullptr;
77template<class MuonImpl>
78StatusCode MuonReadoutElement::insertTransform(const IdentifierHash& hash) {
79 const unsigned idx = static_cast<unsigned>(hash);
80 ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toStringDetEl(identify())
81 <<" Insert new transform cache: "<<idx);
83 if (m_localToGlobalCaches.size() <= idx) {
84 m_localToGlobalCaches.resize(idx+1);
86 if (m_localToGlobalCaches[idx]) {
87 ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toStringDetEl(identify())
88 <<" has already a transformation cached for hash "<<hash);
89 return StatusCode::FAILURE;
91 m_localToGlobalCaches[idx] = std::make_unique<ActsTrk::TransformCacheDetEle<MuonImpl>>(hash, static_cast<MuonImpl*>(this));
92 return StatusCode::SUCCESS;
95} // namespace MuonGMR4