ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
6 #ifndef SIMULATIONBASE
7 # include "Acts/Surfaces/StrawSurface.hpp"
8 # include "Acts/Surfaces/PlaneSurface.hpp"
9 #endif
10 
11 using namespace ActsTrk;
12 namespace {
14  static const Amg::Transform3D dummyTrans{Amg::Transform3D::Identity()};
15 }
16 namespace MuonGMR4 {
17 
18 MuonReadoutElement::MuonReadoutElement(defineArgs&& args)
19  : GeoVDetectorElement(args.physVol),
20  AthMessaging("MuonReadoutElement"),
21  m_args{std::move(args)} {
22  if (!m_idHelperSvc.retrieve().isSuccess()) {
23  ATH_MSG_FATAL("Failed to retrieve the MuonIdHelperSvc");
24  }
25  m_stName = m_idHelperSvc->stationName(identify());
26  m_stEta = m_idHelperSvc->stationEta(identify());
27  m_stPhi = m_idHelperSvc->stationPhi(identify());
28  m_detElHash = m_idHelperSvc->detElementHash(identify());
29  m_chIdx = m_idHelperSvc->chamberIndex(identify());
30 }
33  if(!alignableTransform()) {
34  ATH_MSG_FATAL("The readout element "<<idHelperSvc()->toStringDetEl(identify())<<" has no assigned alignable node");
35  return StatusCode::FAILURE;
36  }
37  return insertTransform<MuonReadoutElement>(geoTransformHash());
38 }
40  static const IdentifierHash hash{static_cast<unsigned>(~0)-1};
41  return hash;
42 }
43 
44 
46  const IdentifierHash& hash) const {
47  TransformCacheMap::const_iterator cache = m_localToGlobalCaches.find(hash);
48  if (cache != m_localToGlobalCaches.end()) return cache->second->getTransform(ctx.getStore(detectorType()).get());
49  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" "<<__func__<<"() -- "
50  <<idHelperSvc()->toStringDetEl(identify())<<" hash: "<<hash<<" is unknown.");
51  return dummyTrans;
52 }
53 
55  return getMaterialGeom()->getAbsoluteTransform(alignStore ? alignStore->geoModelAlignment.get() : nullptr);
56 }
58  for (const auto& cache : m_localToGlobalCaches) {
59  cache.second->releaseNominalCache();
60  }
61 }
62 
64  if (store.detType != detectorType()) return 0;
65  unsigned int aligned{0};
66  for (const auto& cache : m_localToGlobalCaches) {
67  cache.second->getTransform(&store);
68  ++aligned;
69  }
70  return aligned;
71 }
72 
74  return globalToLocalTrans(ctx, geoTransformHash());
75 }
77  return localToGlobalTrans(ctx, geoTransformHash());
78 }
79 #ifndef SIMULATIONBASE
80 const Acts::Transform3& MuonReadoutElement::transform(const Acts::GeometryContext& anygctx) const {
81  const ActsGeometryContext *gctx = anygctx.get<const ActsGeometryContext *>();
82  return localToGlobalTrans(*gctx, geoTransformHash());
83 }
84 std::shared_ptr<Acts::Surface> MuonReadoutElement::surfacePtr(const IdentifierHash& hash) const {
85  ActsTrk::SurfaceCacheSet::const_iterator cache = m_surfaces.find(hash);
86  if(cache != m_surfaces.end()) return (*cache)->getSurface();
87  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" "<<__func__<<"() -- Hash "<<hash
88  <<" is unknown to "<<idHelperSvc()->toStringDetEl(identify()));
89  return nullptr;
90 }
91 
92 const Acts::Surface& MuonReadoutElement::surface() const { return surface(geoTransformHash()); }
93 Acts::Surface& MuonReadoutElement::surface() { return surface(geoTransformHash()); }
94 const Acts::Surface& MuonReadoutElement::surface(const IdentifierHash& hash) const { return *surfacePtr(hash); }
95 Acts::Surface& MuonReadoutElement::surface(const IdentifierHash& hash) { return *surfacePtr(hash); }
96 
98  std::shared_ptr<Acts::LineBounds> lBounds) {
99 
100  //get the local to global transform cache
101  TransformCacheMap::const_iterator transformCache = m_localToGlobalCaches.find(hash);
102  if (transformCache == m_localToGlobalCaches.end()) {
103  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
104  <<" no transform cache available for hash "<<hash);
105  return StatusCode::FAILURE;
106  }
107 
108  auto insert_itr = m_surfaces.insert(std::make_unique<ActsTrk::SurfaceCache>(transformCache->second.get()));
109  if(!insert_itr.second){
110  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
111  <<" Insertion to muon surface cache failed for hash "<<hash);
112  return StatusCode::FAILURE;
113  }
114  //Create straw surface for the surface cache
115  (*insert_itr.first)->setSurface(Acts::Surface::makeShared<Acts::StrawSurface>(lBounds, **insert_itr.first));
116  return StatusCode::SUCCESS;
117 
118 }
119 
120 StatusCode MuonReadoutElement::planeSurfaceFactory(const IdentifierHash& hash, std::shared_ptr<Acts::PlanarBounds> pBounds){
121 
122  //get the local to global transform cache
123  TransformCacheMap::const_iterator transformCache = m_localToGlobalCaches.find(hash);
124  if (transformCache == m_localToGlobalCaches.end()) {
125  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
126  <<" no transform cache available for hash "<<hash);
127  return StatusCode::FAILURE;
128  }
129  auto insert_itr = m_surfaces.insert(std::make_unique<ActsTrk::SurfaceCache>(transformCache->second.get()));
130  if(!insert_itr.second){
131  ATH_MSG_FATAL(__FILE__<<":"<<__LINE__<<" - "<<idHelperSvc()->toString(identify())
132  <<" Insertion to muon surface cache failed for hash "<<hash);
133  return StatusCode::FAILURE;
134  }
135  //Create a plane surface for the surface cache
136  (*insert_itr.first)->setSurface(Acts::Surface::makeShared<Acts::PlaneSurface>(pBounds, **insert_itr.first));
137  return StatusCode::SUCCESS;
138 }
140  m_chambLink = std::move(chamber);
141 }
143  return m_chambLink.get();
144 }
145 #endif
146 
147 } // namespace MuonGMR4
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
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:63
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ActsTrk::DetectorAlignStore::geoModelAlignment
std::shared_ptr< GeoAlignmentStore > geoModelAlignment
Store containing the aligned GeoModel nodes.
Definition: DetectorAlignStore.h:31
MuonGMR4::MuonReadoutElement::m_localToGlobalCaches
TransformCacheMap m_localToGlobalCaches
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:207
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:92
calibdata.chamber
chamber
Definition: calibdata.py:32
ActsTrk::DetectorAlignStore
Definition: DetectorAlignStore.h:20
MuonGMR4::MuonReadoutElement::m_surfaces
ActsTrk::SurfaceCacheSet m_surfaces
Cache of all associated surfaces.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:210
MuonGMR4::MuonReadoutElement::createGeoTransform
StatusCode createGeoTransform()
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:31
ActsTrk::IDetectorElement::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:73
MuonGMR4::MuonReadoutElement::toStation
const Amg::Transform3D & toStation(const ActsTrk::DetectorAlignStore *alignStore) const
Returns the transformation into the center of the readout volume.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:54
MuonGMR4::MuonChamber
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonChamber.h:39
ActsGeometryContext::getStore
AlignmentStorePtr & getStore(const DetectorType type)
Returns the mutable alignable store for the ATLAS detector type (Pixel, Mdt, etc.)
Definition: ActsGeometryContext.h:34
MuonGMR4::MuonReadoutElement::setChamberLink
void setChamberLink(GeoModel::TransientConstSharedPtr< MuonChamber > chamber)
Set's the link to the MuonChamber object to which the MuonReadoutElement belongs to.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:139
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
A muon chamber is a collection of readout elements belonging to the same station.
Definition: ChamberAssembleTool.h:16
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
MuonGMR4::MuonReadoutElement::getChamber
const MuonChamber * getChamber() const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:142
MuonChamber.h
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:28
MuonGMR4::MuonReadoutElement::m_chambLink
GeoModel::TransientConstSharedPtr< MuonChamber > m_chambLink
Pointer to the associated MuonChamber.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:212
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:39
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:97
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
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:120
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:84
MuonGMR4::MuonReadoutElement::releaseUnAlignedTrfs
void releaseUnAlignedTrfs() const
Releases all cached transforms that are not connected with alignment.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:57
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:76
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:34
MuonReadoutElement.h
MuonGMR4::MuonReadoutElement::transform
const Acts::Transform3 & 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:80
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80