8#include <GeoModelKernel/GeoPerfUtils.h>
9#include <GeoModelKernel/GeoClearAbsPosAction.h>
15#define CREATE_READHANDLE(CONT_TYPE, KEY) \
16 SG::ReadCondHandle<CONT_TYPE> readHandle{KEY, ctx}; \
17 if (!readHandle.isValid()) { \
18 ATH_MSG_FATAL(__FILE__<<":"<<__LINE__ \
19 <<" Failed to load "<<KEY.fullKey()); \
20 return StatusCode::FAILURE; \
37 ATH_MSG_FATAL(
"The detector manager does not contain any elements");
38 return StatusCode::FAILURE;
62 return StatusCode::SUCCESS;
72 (std::abs(
re->stationEta()) == 7 &&
m_idHelperSvc->stationNameString(
re->identify()) ==
"BML")) {
73 return m_idHelperSvc->rpcIdHelper().elementID(
re->stationName(),
re->stationEta(),
re->stationPhi(), 1);
76 return m_idHelperSvc->mdtIdHelper().elementID(
re->stationName(),
re->stationEta(),
re->stationPhi());
80 return re->identify();
86 ATH_MSG_DEBUG(
"Loading of the A line parameters deactivated");
87 return StatusCode::SUCCESS;
92 std::vector<const MuonReadoutElement*> readoutEles =
m_detMgr->getAllReadoutElements();
93 ATH_MSG_INFO(
"Load the alignment of "<<readoutEles.size()<<
" detector elements");
95 const GeoAlignableTransform* alignTrans =
re->alignableTransform();
98 <<
" has no alignable transform.");
101 std::shared_ptr<const Amg::Transform3D>& cached = alignDeltas[alignTrans];
104 <<
" has been cached before. ");
105 techTransforms[
re->detectorType()].insert(alignTrans);
110 ALineContainer::const_iterator aLineItr = aLineContainer->find(stationId);
111 if (aLineItr == aLineContainer->end()) {
113 <<
". Used "<<
m_idHelperSvc->toString(stationId)<<
" as station Identifier");
117 cached = std::make_shared<Amg::Transform3D>(aLineItr->delta());
118 techTransforms[
re->detectorType()].insert(alignTrans);
120 return StatusCode::SUCCESS;
126 return StatusCode::SUCCESS;
128 std::unique_ptr<MdtAlignmentStore> internAlign = std::make_unique<MdtAlignmentStore>(
m_idHelperSvc.get());
133 asBuiltCont = readHandle.cptr();
137 bLines = readHandle.cptr();
144 BLineContainer::const_iterator itr = bLines->find(stationId);
145 if (itr != bLines->end()) bline = &(*itr);
149 MdtAsBuiltContainer::const_iterator itr = asBuiltCont->find(stationId);
150 if (itr != asBuiltCont->end()) asBuilt = &(*itr);
152 if (asBuilt || bline) internAlign->storeDistortion(stationId, bline, asBuilt);
155 store.internalAlignment = std::move(internAlign);
156 return StatusCode::SUCCESS;
161 return StatusCode::SUCCESS;
163 std::unique_ptr<MmAlignmentStore> internAlign = std::make_unique<MmAlignmentStore>();
166 internAlign->passivation = readHandle.cptr();
170 internAlign->asBuiltPars = readHandle->microMegaData;
175 std::vector<const MuonReadoutElement*> reEles =
m_detMgr->getAllReadoutElements();
179 BLineContainer::const_iterator itr = readHandle->find(stationId);
180 if (itr != readHandle->end()) internAlign->cacheBLine(
re->identify(), *itr);
183 store.internalAlignment = std::move(internAlign);
184 return StatusCode::SUCCESS;
189 return StatusCode::SUCCESS;
191 std::unique_ptr<sTgcAlignmentStore> internalAlign = std::make_unique<sTgcAlignmentStore>();
194 internalAlign->asBuiltPars = *readHandle;
199 std::vector<const MuonReadoutElement*> reEles =
m_detMgr->getAllReadoutElements();
203 BLineContainer::const_iterator itr = readHandle->find(stationId);
204 if (itr != readHandle->end()) internalAlign->cacheBLine(
re->identify(), *itr);
207 store.internalAlignment = std::move(internalAlign);
208 return StatusCode::SUCCESS;
243 return StatusCode::SUCCESS;
249 unsigned int memBeforeAlign = GeoPerfUtils::getMem();
252 std::vector<const MuonReadoutElement*> readoutEles =
m_detMgr->getAllReadoutElements();
254 unsigned int numAligned{0};
255 for (
size_t det =0 ; det <
m_techs.size(); ++det) {
262 <<
" are still valid.");
265 std::unique_ptr<ActsTrk::DetectorAlignStore> writeCdo = std::make_unique<ActsTrk::DetectorAlignStore>(subDet);
267 const std::set<const GeoAlignableTransform*>& toStore = techTransforms[subDet];
269 for (
const GeoAlignableTransform* alignable : toStore) {
270 const std::shared_ptr<const Amg::Transform3D>& cached = alignDeltas[alignable];
271 if (!cached)
continue;
272 writeCdo->geoModelAlignment->setDelta(alignable, alignDeltas[alignable]);
274 writeCdo->geoModelAlignment->lockDelta();
287 if (
re->detectorType() == subDet) {
288 const Amg::Transform3D& detTrf{
re->getMaterialGeom()->getAbsoluteTransform(writeCdo->geoModelAlignment.get())};
294 writeCdo->geoModelAlignment->getDeltas()->clear();
295 writeCdo->geoModelAlignment->lockPosCache();
298 numAligned+=
re->storeAlignedTransforms(*writeCdo);
301 writeCdo->geoModelAlignment.reset();
306 ATH_MSG_VERBOSE(
"Only "<<numAligned<<
" out of "<<readoutEles.size()<<
" were picked up by the alignment cutalg");
308 techTransforms.clear();
310 GeoClearAbsPosAction whipeTreeTop{};
311 for (
unsigned int treeTop = 0 ; treeTop <
m_detMgr->getNumTreeTops(); ++treeTop) {
312 m_detMgr->getTreeTop(treeTop)->exec(&whipeTreeTop);
315 unsigned int memAfterAlign = GeoPerfUtils::getMem();
316 ATH_MSG_INFO(
"Caching of the alignment parameters required "<<(memAfterAlign - memBeforeAlign) / 1024<<
" MB of memory");
317 return StatusCode::SUCCESS;
320#undef CREATE_READHANDLE
const boost::regex re(r_e)
#define CREATE_READHANDLE(CONT_TYPE, KEY)
#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
StatusCode loadMmDeformPars(const EventContext &ctx, ActsTrk::DetectorAlignStore &store) const
virtual StatusCode initialize() override
Gaudi::Property< bool > m_applyMdtAsBuilt
StatusCode loadStgcDeformPars(const EventContext &ctx, ActsTrk::DetectorAlignStore &store) const
const MuonGMR4::MuonDetectorManager * m_detMgr
SG::ReadCondHandleKey< NswAsBuiltDbData > m_readNswAsBuiltKey
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 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< bool > m_applyMmPassivation
std::unordered_map< const GeoAlignableTransform *, std::shared_ptr< const Amg::Transform3D > > deltaMap
Association map of the GeoAlignableTransforms with the rigid alignment transformations.
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...
ActsMuonAlignCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< BLineContainer > m_readKeyBLines
Gaudi::Property< bool > m_fillGeoAlignStore
Flag toggling whether the GeoAlignmentStore shall be filled.
Gaudi::Property< bool > m_applyNswAsBuilt
std::map< ActsTrk::DetectorType, std::set< const GeoAlignableTransform * > > alignTechMap
Association map of the GeoAlignable transforms with the detector technologies.
SG::ReadCondHandleKey< ALineContainer > m_readKeyALines
Identifier alignmentId(const MuonGMR4::MuonReadoutElement *reElement) const
Returns the Identifier serving as key to find the alignment parameters connected with the readout ele...
Gaudi::Property< std::string > m_keyToken
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_applyALines
Apply translations and rotations to align the Muon stations.
Gaudi::Property< bool > m_applyBLines
Apply the chamber deformation model (Mdts + Nsw)
SG::ReadCondHandleKey< NswPassivationDbData > m_readNswPassivKey
SG::ReadCondHandleKey< sTGCAsBuiltData > m_readsTgcAsBuiltKey
Gaudi::Property< bool > m_fillAlignStoreCache
Flag toggling whether the alignment store shall be filled with the transforms or not.
SG::WriteCondHandleKeyArray< ActsTrk::DetectorAlignStore > m_writeKeys
std::vector< ActsTrk::DetectorType > m_techs
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadCondHandleKey< MdtAsBuiltContainer > m_readMdtAsBuiltKey
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
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...
The MuonReadoutElement is an abstract class representing the geometry representing the muon detector.
const_id_iterator module_end() const
const_id_iterator module_begin() const
Iterators over full set of ids.
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Class holding the sTGC as built conditions data and applying it.
std::string to_string(const DetectorType &type)
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.
Eigen::Affine3d Transform3D
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...