ATLAS Offline Software
Loading...
Searching...
No Matches
RegionSelectorCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
6
10
11#include "Acts/Surfaces/PlanarBounds.hpp"
12
15
16namespace MuonR4{
18 ATH_CHECK(detStore()->retrieve(m_detMgr));
19 ATH_CHECK(m_tableKey.initialize());
20 ATH_CHECK(m_alignKey.initialize());
24 return StatusCode::SUCCESS;
25 }
26 template <typename Key_t,
27 typename... OtherKey_t>
28 StatusCode RegionSelectorCondAlg::addCondDependency(const EventContext& ctx,
31 OtherKey_t... others) const {
32 if (!key.empty()) {
33 SG::ReadCondHandle readHandle{key, ctx};
34 if (!readHandle.isValid()){
35 ATH_MSG_FATAL("Failed to retrieve "<<key.fullKey()<<".");
36 return StatusCode::FAILURE;
37 }
38 writeHandle.addDependency(readHandle);
39 }
40 if constexpr(sizeof...(others) > 0) {
41 ATH_CHECK(addCondDependency(ctx, writeHandle, others...));
42 }
43 return StatusCode::SUCCESS;
44 }
45
47 switch (type) {
48 using enum ActsTrk::DetectorType;
49 case Mdt:
50 return m_idHelperSvc->mdtIdHelper();
51 case Rpc:
52 return m_idHelperSvc->rpcIdHelper();
53 case Tgc:
54 return m_idHelperSvc->tgcIdHelper();
55 case Mm:
56 return m_idHelperSvc->mmIdHelper();
57 case sTgc:
58 return m_idHelperSvc->stgcIdHelper();
59 default:
60 THROW_EXCEPTION("Unknown detector type "<<ActsTrk::to_string(type));
61 }
62 }
63
64 std::set<std::uint32_t> RegionSelectorCondAlg::getRobIDs(const EventContext& ctx,
65 const Identifier& moduleID) const {
66
67 switch(m_idHelperSvc->technologyIndex(moduleID)) {
69 case MDT: {
70 const MuonMDT_CablingMap* cabling{};
71 if (!SG::get(cabling, m_cablingMdtKey, ctx).isSuccess()) {
72 THROW_EXCEPTION("Failed to load Mdt cabling "<<m_cablingMdtKey.fullKey());
73 }
74 return {cabling->getROBId(m_idHelperSvc->moduleHash(moduleID), msgStream())};
75 } case RPC: {
76 const Muon::RpcCablingMap* cabling{};
77 if (!SG::get(cabling, m_cablingRpcKey, ctx).isSuccess()) {
78 THROW_EXCEPTION("Failed to load Rpc cabling "<<m_cablingRpcKey.fullKey());
79 }
80 return {cabling->getROBId(m_idHelperSvc->moduleHash(moduleID), msgStream())};
81 } case TGC: {
82 const Muon::TgcCablingMap* cabling{};
83 if (!SG::get(cabling, m_cablingTgcKey, ctx).isSuccess()) {
84 THROW_EXCEPTION("Failed to load Tgc cabling");
85 }
86 int subDetectorId{}, rodId{};
87 cabling->getReadoutIDfromElementID(moduleID, subDetectorId, rodId);
88 return {static_cast<std::uint32_t>(((0x0ff) & subDetectorId)<<16 | rodId)};
89 } case MM:
90 case STGC:{
92 m_idHelperSvc->stationNameString(moduleID),
93 static_cast<int8_t>(m_idHelperSvc->stationEta(moduleID)),
94 static_cast<uint8_t>(m_idHelperSvc->stationPhi(moduleID))};
95 return std::set<std::uint32_t>(robIdHelper.get_ids().begin(), robIdHelper.get_ids().end());
96 } default: {
97 THROW_EXCEPTION("Invalid identifier "<<m_idHelperSvc->toStringChamber(moduleID));
98 }
99 }
100 return {};
101 }
102
103 StatusCode RegionSelectorCondAlg::execute(const EventContext& ctx) const {
104 SG::WriteCondHandle writeHandle{m_tableKey, ctx};
105 if (writeHandle.isValid()) {
106 ATH_MSG_DEBUG("Region selector "<<m_tableKey<<" is still valid");
107 return StatusCode::SUCCESS;
108 }
112
113 auto writeCdo = std::make_unique<RegSelSiLUT>();
114 const ActsTrk::DetectorAlignStore* alignDeltas{nullptr};
115 ATH_CHECK(SG::get(alignDeltas, m_alignKey, ctx));
116
118 if (m_splitTrfCache) {
119 gctx.setStore(MuonGMR4::copyDeltas(*alignDeltas));
120 } else {
121 gctx.setStore(std::make_unique<ActsTrk::DetectorAlignStore>(*alignDeltas));
122 }
123 const MuonIdHelper& idHelper{getIdHelper(alignDeltas->detType)};
124
127 struct TempSelTable {
128 std::optional<double> centralPhi{};
129 double zMin{std::numeric_limits<double>::max()};
130 double zMax{-std::numeric_limits<double>::max()};
131 double rMin{std::numeric_limits<double>::max()};
132 double rMax{-std::numeric_limits<double>::max()};
133 double dPhiMin{std::numeric_limits<double>::max()};
134 double dPhiMax{-std::numeric_limits<double>::max()};
135
136 void update(const Amg::Vector3D& v) {
137 const double dPhi = xAOD::P4Helpers::deltaPhi(v.phi(), centralPhi.value_or(0.));
138 rMin = std::min(rMin, v.perp()); rMax = std::max(rMax, v.perp());
139 zMin = std::min(zMin, v.z()); zMax = std::max(zMax, v.z());
140 dPhiMin = std::min(dPhiMin, dPhi); dPhiMax = std::max(dPhiMax, dPhi);
141 }
142
143 };
144 std::vector<TempSelTable> luts(idHelper.module_hash_max());
145 IdentifierHash modHash{};
147 for (const MuonGMR4::MuonReadoutElement* reEle: m_detMgr->getAllReadoutElements(alignDeltas->detType)) {
148
149 const Acts::Surface& surface{reEle->surface()};
150
151 const double halfTck = 0.5*reEle->thickness();
152
153 std::vector<Amg::Vector3D> localVertices{};
154 localVertices.reserve(8);
155 ATH_MSG_VERBOSE(__LINE__<<" - Fetch edge points from surface: "<<m_idHelperSvc->toStringDetEl(reEle->identify()));
156 std::ranges::for_each(static_cast<const Acts::PlanarBounds&>(surface.bounds()).vertices(),
157 [&](const Amg::Vector2D& v){
158 ATH_MSG_VERBOSE(__LINE__<<" - Local vertex: "<<Amg::toString(v)<<", half thickness: "<<halfTck);
159 localVertices.emplace_back(v.x(), v.y(), halfTck);
160 localVertices.emplace_back(v.x(), v.y(), -halfTck);
161 });
162 ATH_MSG_VERBOSE(__LINE__<<" - Fetched "<<localVertices.size()<<" vertices.");
163 const Amg::Transform3D& loc2Glob{surface.localToGlobalTransform(gctx.context())};
164 idHelper.get_module_hash(reEle->identify(), modHash);
165 auto& lut = luts.at(modHash);
166 if (!lut.centralPhi) {
167 lut.centralPhi = loc2Glob.translation().phi();
168 }
169 for (const Amg::Vector3D& locVtx : localVertices) {
170 const Amg::Vector3D globVtx = loc2Glob * locVtx;
171 ATH_MSG_VERBOSE(__LINE__<<" - Expand LUT with vertex "
172 <<std::format("{:.2f}/{:.2f}/{:.2f}", globVtx.perp(), globVtx.z(), globVtx.phi()));
173 lut.update(globVtx);
174 }
175 }
176 const auto modCtx = idHelper.module_context();
178 for (auto module_itr = idHelper.module_begin();
179 module_itr != idHelper.module_end(); ++module_itr) {
180 idHelper.get_module_hash(*module_itr, modHash);
181 const auto& lut = luts.at(modHash);
182
183 if(!lut.centralPhi) {
184 continue;
185 }
186
187 ExpandedIdentifier exp_id{};
188 if (idHelper.get_expanded_id(*module_itr, exp_id, &modCtx)) {
189 ATH_MSG_DEBUG(__LINE__<<" - Failed retrieving ExpandedIdentifier for PRD Identifier = "
190 << m_idHelperSvc->toString(*module_itr) << ". Skipping to the next PRD.");
191 continue;
192 }
193 const int detid = ( exp_id[2]<0 ? -1 : 1 );
194 const int layerid = exp_id[1]+1;
195
196 const double phiMin = lut.centralPhi.value_or(0) + lut.dPhiMin;
197 const double phiMax = lut.centralPhi.value_or(0) + lut.dPhiMax;
198
199
200 for (const std::uint32_t robID : getRobIDs(ctx, *module_itr)) {
201 RegSelModule m{lut.zMin, lut.zMax, lut.rMin, lut.rMax,
202 phiMin, phiMax, layerid, detid, robID, modHash};
203 ATH_MSG_VERBOSE(__LINE__<<" - Insert new entry "<<m_idHelperSvc->chamberNameString(*module_itr)
204 <<", "<<m);
205 writeCdo->addModule(m);
206 }
207 }
208
209 if (m_printTable) {
210 if (const auto *lut = dynamic_cast<const RegSelSiLUT*>(writeCdo.get())) {
211 lut->write(std::format("{:}.map", name()));
212 }
213 }
214
215 ATH_CHECK(writeHandle.record(std::make_unique<IRegSelLUTCondData>(std::move(writeCdo))));
216 return StatusCode::SUCCESS;
217 }
218}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
DetectorType detType
The aligned detector element type.
Acts::GeometryContext context() const
void setStore(AlignmentStorePtr store)
Adds the store to the Geometry context.
const ServiceHandle< StoreGateSvc > & detStore() const
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
This is a "hash" representation of an Identifier.
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
const_id_iterator module_end() const
int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
Create expanded id from compact id (return == 0 for OK)
const_id_iterator module_begin() const
Iterators over full set of ids.
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const
size_type module_hash_max() const
the maximum hash value
IdContext module_context() const
id for module
virtual StatusCode initialize() override final
Gaudi::Property< bool > m_printTable
SG::ReadCondHandleKey< Muon::TgcCablingMap > m_cablingTgcKey
Dependency on the Tgc cabling map.
const MuonGMR4::MuonDetectorManager * m_detMgr
Detector manager.
SG::ReadCondHandleKey< Muon::RpcCablingMap > m_cablingRpcKey
Dependency on the phase II Rpc cabling map.
Gaudi::Property< bool > m_splitTrfCache
Instantiate a new transform cache to ensure lazy transform population in the event processing.
const MuonIdHelper & getIdHelper(const ActsTrk::DetectorType type) const
Retrieve the idHelper for the given detector technology.
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadCondHandleKey< ActsTrk::DetectorAlignStore > m_alignKey
Dependency on the alignment constants.
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Region selector table written by the algorithm.
StatusCode addCondDependency(const EventContext &ctx, SG::WriteCondHandle< IRegSelLUTCondData > &writeHandle, const SG::ReadCondHandleKey< Key_t > &key, OtherKey_t... others) const
Declare the dependency of the region selector table on the other keys set.
std::set< std::uint32_t > getRobIDs(const EventContext &ctx, const Identifier &moduleID) const
Returns the list of ROB ids associated with the module.
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_cablingMdtKey
Dependency on the Mdt cabling map.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
const std::vector< uint32_t > & get_ids() const
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
std::string to_string(const DetectorType &type)
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
std::unique_ptr< ActsTrk::DetectorAlignStore > copyDeltas(const ActsTrk::DetectorAlignStore &inStore)
Copy the alignment deltas from the inStore to a new alignment store.
This header ties the generic definitions in this package.
TechnologyIndex
enum to classify the different layers in the muon spectrometer
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition TgcBase.h:6
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10