8#include <GeoModelKernel/GeoPerfUtils.h>
9#include <GeoModelKernel/GeoClearAbsPosAction.h>
15#include "Acts/Utilities/Helpers.hpp"
30 ATH_MSG_FATAL(
"The detector manager does not contain any elements");
31 return StatusCode::FAILURE;
34 return Acts::rangeContainsValue(
m_techs, d);
54 return StatusCode::SUCCESS;
64 (std::abs(
re->stationEta()) == 7 &&
m_idHelperSvc->stationNameString(
re->identify()) ==
"BML")) {
65 return m_idHelperSvc->rpcIdHelper().elementID(
re->stationName(),
re->stationEta(),
re->stationPhi(), 1);
68 return m_idHelperSvc->mdtIdHelper().elementID(
re->stationName(),
re->stationEta(),
re->stationPhi());
72 return re->identify();
78 ATH_MSG_DEBUG(
"Loading of the A line parameters deactivated");
79 return StatusCode::SUCCESS;
83 std::vector<const MuonReadoutElement*> readoutEles =
m_detMgr->getAllReadoutElements();
84 ATH_MSG_INFO(
"Load the alignment of "<<readoutEles.size()<<
" detector elements");
86 const GeoAlignableTransform* alignTrans =
re->alignableTransform();
89 <<
" has no alignable transform.");
92 std::shared_ptr<const Amg::Transform3D>& cached = alignDeltas[alignTrans];
95 <<
" has been cached before. ");
96 techTransforms[
re->detectorType()].insert(alignTrans);
101 ALineContainer::const_iterator aLineItr = aLineContainer->find(stationId);
102 if (aLineItr == aLineContainer->end()) {
104 <<
". Used "<<
m_idHelperSvc->toString(stationId)<<
" as station Identifier");
108 cached = std::make_shared<Amg::Transform3D>(aLineItr->delta());
109 techTransforms[
re->detectorType()].insert(alignTrans);
111 return StatusCode::SUCCESS;
117 return StatusCode::SUCCESS;
119 auto internAlign = std::make_unique<MdtAlignmentStore>(
m_idHelperSvc.get());
131 BLineContainer::const_iterator itr = bLines->find(stationId);
132 if (itr != bLines->end()) bline = &(*itr);
136 MdtAsBuiltContainer::const_iterator itr = asBuiltCont->find(stationId);
137 if (itr != asBuiltCont->end()) asBuilt = &(*itr);
139 if (asBuilt || bline) {
140 internAlign->storeDistortion(stationId, bline, asBuilt);
144 store.internalAlignment = std::move(internAlign);
145 return StatusCode::SUCCESS;
150 return StatusCode::SUCCESS;
152 auto internAlign = std::make_unique<MmAlignmentStore>();
164 BLineContainer::const_iterator itr = bLines->find(stationId);
165 if (itr != bLines->end()) {
166 internAlign->cacheBLine(
re->identify(), *itr);
170 store.internalAlignment = std::move(internAlign);
171 return StatusCode::SUCCESS;
176 return StatusCode::SUCCESS;
178 auto internAlign = std::make_unique<sTgcAlignmentStore>();
185 BLineContainer::const_iterator itr = bLines->find(stationId);
186 if (itr != bLines->end()) {
187 internAlign->cacheBLine(
re->identify(), *itr);
191 store.internalAlignment = std::move(internAlign);
192 return StatusCode::SUCCESS;
233 return StatusCode::SUCCESS;
239 const unsigned memBeforeAlign = GeoPerfUtils::getMem();
243 for (std::size_t det =0 ; det <
m_techs.size(); ++det) {
248 ActsTrk::DetectorAlignStore::Mode::Block :
249 ActsTrk::DetectorAlignStore::Mode::LazyFill};
252 ATH_MSG_DEBUG(
"The alignment constants for "<<subDet <<
" are still valid.");
255 auto writeCdo = std::make_unique<ActsTrk::DetectorAlignStore>(subDet, mode);
257 const std::set<const GeoAlignableTransform*>& toStore = techTransforms[subDet];
259 for (
const GeoAlignableTransform* alignable : toStore) {
260 const std::shared_ptr<const Amg::Transform3D>& cached = alignDeltas[alignable];
261 if (!cached)
continue;
262 writeCdo->geoModelAlignment->setDelta(alignable, alignDeltas[alignable]);
264 writeCdo->geoModelAlignment->lockDelta();
276 unsigned numAligned{0};
277 std::ranges::for_each(
m_detMgr->getAllReadoutElements(subDet),
279 numAligned += re->storeAlignedTransforms(*writeCdo);
281 std::ranges::for_each(
m_detMgr->getAllChambers(),
283 const auto& placement = chamber->parameters().placement;
285 numAligned+= placement->storeAlignedTransforms(*writeCdo);
289 writeCdo->geoModelAlignment.reset();
290 ATH_MSG_DEBUG(
"Populated the alignment store "<<subDet<<
" with "<<numAligned<<
" transforms");
291 if (writeCdo->trackingAlignment->filled() != writeCdo->trackingAlignment->size()) {
292 ATH_MSG_ERROR(
"The number of aligned transforms "<<(*writeCdo->trackingAlignment)
293 <<
" does not match what's reported from the readout geometry "
294 <<writeCdo->trackingAlignment->filled());
295 return StatusCode::FAILURE;
299 std::ranges::for_each(
m_detMgr->getAllReadoutElements(subDet),
301 const Amg::Transform3D& detTrf{re->getMaterialGeom()->getAbsoluteTransform(writeCdo->geoModelAlignment.get())};
306 writeCdo->geoModelAlignment->getDeltas()->clear();
307 writeCdo->geoModelAlignment->lockPosCache();
309 ATH_CHECK(writeHandle.record(std::move(writeCdo)));
313 techTransforms.clear();
315 GeoClearAbsPosAction whipeTreeTop{};
316 for (
unsigned treeTop = 0 ; treeTop < m_detMgr->getNumTreeTops(); ++treeTop) {
317 m_detMgr->getTreeTop(treeTop)->exec(&whipeTreeTop);
320 const unsigned memAfterAlign = GeoPerfUtils::getMem();
321 ATH_MSG_INFO(
"Caching of the alignment parameters required "<<(memAfterAlign - memBeforeAlign) / 1024<<
" MB of memory");
322 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::set< ALinePar, std::less<> > ALineContainer
std::set< MdtAsBuiltPar, std::less<> > MdtAsBuiltContainer
std::set< BLinePar, std::less<> > BLineContainer
detail::TransformStore::Mode Mode
const ServiceHandle< StoreGateSvc > & detStore() const
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Container classifier the MDT as-built parameters See parameter description in http://atlas-muon-align...
Chamber represent the volume enclosing a muon station.
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
const_id_iterator module_end() const
const_id_iterator module_begin() const
Iterators over full set of ids.
std::unordered_map< const GeoAlignableTransform *, std::shared_ptr< const Amg::Transform3D > > deltaMap
Association map of the GeoAlignableTransforms with the rigid alignment transformations.
StatusCode loadMmDeformPars(const EventContext &ctx, ActsTrk::DetectorAlignStore &store) const
Gaudi::Property< bool > m_applyALines
Apply translations and rotations to align the Muon stations.
const MuonGMR4::MuonDetectorManager * m_detMgr
SG::ReadCondHandleKey< MdtAsBuiltContainer > m_readMdtAsBuiltKey
StatusCode loadMdtDeformPars(const EventContext &ctx, ActsTrk::DetectorAlignStore &store) const
Loads the BLine container and the Mdt-as built parameters from the Conditions store and stores them i...
SG::ReadCondHandleKey< sTGCAsBuiltData > m_readsTgcAsBuiltKey
SG::ReadCondHandleKey< BLineContainer > m_readKeyBLines
Gaudi::Property< bool > m_applyMmPassivation
Gaudi::Property< bool > m_applyMdtAsBuilt
virtual StatusCode initialize() override
std::vector< ActsTrk::DetectorType > m_techs
std::map< ActsTrk::DetectorType, std::set< const GeoAlignableTransform * > > alignTechMap
Association map of the GeoAlignable transforms with the detector technologies.
Gaudi::Property< bool > m_applyBLines
Apply the chamber deformation model (Mdts + Nsw).
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadCondHandleKey< NswPassivationDbData > m_readNswPassivKey
Identifier alignmentId(const MuonGMR4::MuonReadoutElement *reElement) const
Returns the Identifier serving as key to find the alignment parameters connected with the readout ele...
SG::ReadCondHandleKey< NswAsBuiltDbData > m_readNswAsBuiltKey
SG::WriteCondHandleKeyArray< ActsTrk::DetectorAlignStore > m_writeKeys
StatusCode loadDeltas(const EventContext &ctx, deltaMap &alignDeltas, alignTechMap &techTransforms) const
Loads the ALineContainer from the conditions store and fills the deltaMap with the A-Line delta trans...
Gaudi::Property< std::string > m_keyToken
Gaudi::Property< bool > m_applyNswAsBuilt
SG::ReadCondHandleKey< ALineContainer > m_readKeyALines
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_fillAlignStoreCache
Flag toggling whether the alignment store shall be filled with the transforms or not.
StatusCode declareDependencies(const EventContext &ctx, ActsTrk::DetectorType detType, SG::WriteCondHandle< ActsTrk::DetectorAlignStore > &writeHandle) const
Loads the corresponding ReadCondHandles from the Conditions store and adds their IOVs to the dependen...
StatusCode loadStgcDeformPars(const EventContext &ctx, ActsTrk::DetectorAlignStore &store) const
Gaudi::Property< bool > m_fillGeoAlignStore
Flag toggling whether the GeoAlignmentStore shall be filled.
MmAsBuiltPtr microMegaData
void addDependency(const EventIDRange &range)
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
@ Mm
Maybe not needed in the migration.
@ Tgc
Resitive Plate Chambers.
@ Rpc
Monitored Drift Tubes.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.