ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
8 #ifndef SIMULATIONBASE
9 # include "Acts/Surfaces/LineBounds.hpp"
10 # include "Acts/Surfaces/PlanarBounds.hpp"
11 # include "Acts/Geometry/GeometryContext.hpp"
12 # include "Acts/Surfaces/StrawSurface.hpp"
13 # include "Acts/Surfaces/PlaneSurface.hpp"
14 #endif
15 
16 using namespace ActsTrk;
17 namespace {
19  static const Amg::Transform3D dummyTrans{Amg::Transform3D::Identity()};
20 }
21 namespace MuonGMR4 {
22 MuonReadoutElement::~MuonReadoutElement() = default;
23 MuonReadoutElement::MuonReadoutElement(const defineArgs& args)
24  : GeoVDetectorElement(args.physVol),
25  AthMessaging("MuonReadoutElement"),
26  m_args{args} {
27  if (!m_idHelperSvc.retrieve().isSuccess()) {
28  ATH_MSG_FATAL("Failed to retrieve the MuonIdHelperSvc");
29  }
30  m_stName = m_idHelperSvc->stationName(identify());
31  m_stEta = m_idHelperSvc->stationEta(identify());
32  m_stPhi = m_idHelperSvc->stationPhi(identify());
33  m_detElHash = m_idHelperSvc->detElementHash(identify());
34  m_chIdx = m_idHelperSvc->chamberIndex(identify());
35 }
38  if(!alignableTransform()) {
39  ATH_MSG_FATAL("The readout element "<<idHelperSvc()->toStringDetEl(identify())<<" has no assigned alignable node");
40  return StatusCode::FAILURE;
41  }
42  return insertTransform<MuonReadoutElement>(geoTransformHash());
43 }
45  static const IdentifierHash hash{static_cast<unsigned>(~0)-1};
46  return hash;
47 }
48 
49 
51  const IdentifierHash& hash) const {
52  TransformCacheMap::const_iterator cache = m_localToGlobalCaches.find(hash);
53  if (cache != m_localToGlobalCaches.end()) return cache->second->getTransform(ctx.getStore(detectorType()).get());
54  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" "<<__func__<<"() -- "
55  <<idHelperSvc()->toStringDetEl(identify())<<" hash: "<<hash<<" is unknown.");
56  return dummyTrans;
57 }
58 
60  return getMaterialGeom()->getAbsoluteTransform(alignStore ? alignStore->geoModelAlignment.get() : nullptr);
61 }
63  for (const auto& cache : m_localToGlobalCaches) {
64  cache.second->releaseNominalCache();
65  }
66 }
67 
69  if (store.detType != detectorType()) return 0;
70  unsigned int aligned{0};
71  for (const auto& cache : m_localToGlobalCaches) {
72  cache.second->getTransform(&store);
73  ++aligned;
74  }
75  return aligned;
76 }
77 
79  return globalToLocalTrans(ctx, geoTransformHash());
80 }
82  return localToGlobalTrans(ctx, geoTransformHash());
83 }
84 #ifndef SIMULATIONBASE
85 const Acts::Transform3& MuonReadoutElement::transform(const Acts::GeometryContext& anygctx) const {
86  const ActsGeometryContext *gctx = anygctx.get<const ActsGeometryContext *>();
87  return localToGlobalTrans(*gctx, geoTransformHash());
88 }
89 std::shared_ptr<Acts::Surface> MuonReadoutElement::surfacePtr(const IdentifierHash& hash) const {
90  ActsTrk::SurfaceCacheSet::const_iterator cache = m_surfaces.find(hash);
91  if(cache != m_surfaces.end()) return (*cache)->getSurface();
92  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" "<<__func__<<"() -- Hash "<<hash
93  <<" is unknown to "<<idHelperSvc()->toStringDetEl(identify()));
94  return nullptr;
95 }
96 
97 const Acts::Surface& MuonReadoutElement::surface() const { return surface(geoTransformHash()); }
98 Acts::Surface& MuonReadoutElement::surface() { return surface(geoTransformHash()); }
99 const Acts::Surface& MuonReadoutElement::surface(const IdentifierHash& hash) const { return *surfacePtr(hash); }
100 Acts::Surface& MuonReadoutElement::surface(const IdentifierHash& hash) { return *surfacePtr(hash); }
101 
103  std::shared_ptr<Acts::LineBounds> lBounds) {
104 
105  //get the local to global transform cache
106  TransformCacheMap::const_iterator transformCache = m_localToGlobalCaches.find(hash);
107  if (transformCache == m_localToGlobalCaches.end()) {
108  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
109  <<" no transform cache available for hash "<<hash);
110  return StatusCode::FAILURE;
111  }
112 
113  auto insert_itr = m_surfaces.insert(std::make_unique<ActsTrk::SurfaceCache>(transformCache->second.get()));
114  if(!insert_itr.second){
115  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
116  <<" Insertion to muon surface cache failed for hash "<<hash);
117  return StatusCode::FAILURE;
118  }
119  //Create straw surface for the surface cache
120  (*insert_itr.first)->setSurface(Acts::Surface::makeShared<Acts::StrawSurface>(lBounds, **insert_itr.first));
121  return StatusCode::SUCCESS;
122 
123 }
124 
125 StatusCode MuonReadoutElement::planeSurfaceFactory(const IdentifierHash& hash, std::shared_ptr<Acts::PlanarBounds> pBounds){
126 
127  //get the local to global transform cache
128  TransformCacheMap::const_iterator transformCache = m_localToGlobalCaches.find(hash);
129  if (transformCache == m_localToGlobalCaches.end()) {
130  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
131  <<" no transform cache available for hash "<<hash);
132  return StatusCode::FAILURE;
133  }
134  auto insert_itr = m_surfaces.insert(std::make_unique<ActsTrk::SurfaceCache>(transformCache->second.get()));
135  if(!insert_itr.second){
136  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
137  <<" Insertion to muon surface cache failed for hash "<<hash);
138  return StatusCode::FAILURE;
139  }
140  //Create a plane surface for the surface cache
141  (*insert_itr.first)->setSurface(Acts::Surface::makeShared<Acts::PlaneSurface>(pBounds, **insert_itr.first));
142  return StatusCode::SUCCESS;
143 }
144 
147 }
149  m_msSectorLink = envelope;
150 }
151 
152 std::vector<std::shared_ptr<Acts::Surface>> MuonReadoutElement::getSurfaces() const {
153  std::vector<std::shared_ptr<Acts::Surface>> surfaces{};
154  surfaces.reserve(m_surfaces.size());
155  for (const std::unique_ptr<SurfaceCache>& cache : m_surfaces) {
156  if (cache->hash() != geoTransformHash()) {
157  surfaces.push_back(cache->getSurface());
158  ATH_MSG_VERBOSE("Add surface "<<idHelperSvc()->toString(cache->identify())
159  <<std::endl<<(surfaces.back()->bounds()));
160  }
161  }
162  return surfaces;
163 }
164 #endif
165 
166 } // namespace MuonGMR4
SGTest::store
TestStore store
Definition: TestStore.cxx:23
MuonGMR4::MuonReadoutElement::storeAlignedTransforms
unsigned int storeAlignedTransforms(const ActsTrk::DetectorAlignStore &store) const override final
Caches the aligned transformation in the provided store. Returns the number of cached elements.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:68
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGMR4::MuonReadoutElement::m_chambLink
const Chamber * m_chambLink
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:217
MuonGMR4::MuonReadoutElement::chamber
const Chamber * chamber() const
Returns the pointer to the chamber enclosing this readout element.
MuonGMR4::SpectrometerSector
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
Definition: SpectrometerSector.h:40
ActsTrk::DetectorAlignStore::geoModelAlignment
std::shared_ptr< GeoAlignmentStore > geoModelAlignment
Store containing the aligned GeoModel nodes.
Definition: DetectorAlignStore.h:31
SurfaceCache.h
MuonGMR4::MuonReadoutElement::m_localToGlobalCaches
TransformCacheMap m_localToGlobalCaches
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:211
MuonGMR4::MuonReadoutElement::surface
const Acts::Surface & surface() const override final
Returns the surface associated to the readout element plane.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:97
calibdata.chamber
chamber
Definition: calibdata.py:32
ActsTrk::DetectorAlignStore
Definition: DetectorAlignStore.h:20
MuonGMR4::MuonReadoutElement::getSurfaces
std::vector< std::shared_ptr< Acts::Surface > > getSurfaces() const
Returns all surfaces that are associated with the active readout planes.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:152
MuonGMR4::MuonReadoutElement::m_surfaces
ActsTrk::SurfaceCacheSet m_surfaces
Cache of all associated surfaces.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:214
MuonGMR4::MuonReadoutElement::createGeoTransform
StatusCode createGeoTransform()
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:36
ActsTrk::IDetectorElementBase::detectorType
virtual DetectorType detectorType() const =0
Returns the detector element type.
MuonGMR4::MuonReadoutElement::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:78
MuonGMR4::MuonReadoutElement::toStation
const Amg::Transform3D & toStation(const ActsTrk::DetectorAlignStore *alignStore) const
Returns the local -> global transformation to go from the volume center origin.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:59
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SpectrometerSector.h
MuonGMR4::Chamber
Definition: Chamber.h:22
ActsGeometryContext::getStore
AlignmentStorePtr & getStore(const DetectorType type)
Returns the mutable alignable store for the ATLAS detector type (Pixel, Mdt, etc.)
Definition: ActsGeometryContext.h:33
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:20
MuonGMR4::MuonReadoutElement::idHelperSvc
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Returns the pointer to the muonIdHelperSvc.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonGMR4::MuonReadoutElement::setSectorLink
void setSectorLink(const SpectrometerSector *envelope)
Set the link to the enclosing sector envelope.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:148
MuonGMR4::MuonReadoutElement::geoTransformHash
static IdentifierHash geoTransformHash()
Returns the hash that is associated with the surface cache holding the transformation that is placing...
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:44
MuonGMR4::MuonReadoutElement::alignableTransform
const GeoAlignableTransform * alignableTransform() const
Returnsthe alignable transform of the readout element.
MuonGMR4::MuonReadoutElement::defineArgs
Helper struct to ship the defining arguments of the detector element around.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:43
MuonGMR4::MuonReadoutElement::strawSurfaceFactory
StatusCode strawSurfaceFactory(const IdentifierHash &hash, std::shared_ptr< Acts::LineBounds > lBounds)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:102
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
TransformCache.h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
MuonGMR4::MuonReadoutElement::planeSurfaceFactory
StatusCode planeSurfaceFactory(const IdentifierHash &hash, std::shared_ptr< Acts::PlanarBounds > pBounds)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:125
MuonGMR4::MuonReadoutElement::surfacePtr
std::shared_ptr< Acts::Surface > surfacePtr(const IdentifierHash &hash) const
Returns the pointer associated to a certain wire / plane.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:89
MuonGMR4::MuonReadoutElement::releaseUnAlignedTrfs
void releaseUnAlignedTrfs() const
Releases all cached transforms that are not connected with alignment.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:62
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
MuonGMR4::MuonReadoutElement::localToGlobalTrans
const Amg::Transform3D & localToGlobalTrans(const ActsGeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:81
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
MuonGMR4::MuonReadoutElement::setChamberLink
void setChamberLink(const Chamber *chamber)
Sets the link to the enclosing chamber.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:145
MuonReadoutElement.h
MuonGMR4::MuonReadoutElement::transform
const Amg::Transform3D & transform(const Acts::GeometryContext &gctx) const override final
Returns the transformation to the origin of the chamber coordinate system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:85
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
MuonGMR4::MuonReadoutElement::m_msSectorLink
const SpectrometerSector * m_msSectorLink
Pointer to the associated MS-sector & MuonChamber.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:216