ATLAS Offline Software
Loading...
Searching...
No Matches
MuonEventCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MuonEventCnvTool.h"
6
7#include <cassert>
8#include <iostream>
9#include <vector>
10
12#include "Identifier/Identifier.h"
29
30
32 ATH_CHECK(m_idHelperSvc.retrieve());
33 ATH_CHECK(m_rpcPrdKey.initialize());
34 ATH_CHECK(m_tgcPrdKey.initialize());
35 ATH_CHECK(m_mdtPrdKey.initialize());
36 ATH_CHECK(m_detectorManagerKey.initialize());
37 ATH_CHECK(m_cscPrdKey.initialize(!m_cscPrdKey.empty())); // check for layouts without CSCs
38 ATH_CHECK(m_mmPrdKey.initialize(!m_mmPrdKey.empty())); // check for layouts without MicroMegas
39 ATH_CHECK(m_stgcPrdKey.initialize(!m_stgcPrdKey.empty())); // check for layouts without STGCs
40
41 return StatusCode::SUCCESS;
42}
43
45 const Identifier& id = rioOnTrack.identify();
47 const TechIdx_t techIdx = m_idHelperSvc->technologyIndex(id);
48
49 if (techIdx == TechIdx_t::TechnologyUnknown ||
50 techIdx == TechIdx_t::TechnologyIndexMax) {
51 ATH_MSG_ERROR("Type does not match known concrete type of MuonSpectrometer! Dumping RoT:" << rioOnTrack);
52 }
53}
54
55std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> Muon::MuonEventCnvTool::getLinks(Trk::RIO_OnTrack& rioOnTrack) const {
56 using namespace Trk;
57 using namespace MuonGM;
58
59 const Identifier& id = rioOnTrack.identify();
60 const TrkDetElementBase* detEl = getDetectorElement(id);
61 if (!detEl) {
62 ATH_MSG_ERROR("Could not find detector element for " << m_idHelperSvc->toString(id));
63 ATH_MSG_ERROR(rioOnTrack);
64 }
65 const PrepRawData* prd = m_manuallyFindPRDs ? getLink(id, rioOnTrack.idDE()) : nullptr;
66
67 if (m_fixTGCs && m_idHelperSvc->isTgc(id) && !rioOnTrack.prepRawData()) {
68 // Okay, so we might have hit the nasty issue that the TGC EL is broken in some samples
69 // Need to fix by pointing to the key defined here (assumung it has been configured correctly for this sample)
70 Muon::TgcClusterOnTrack* tgc = dynamic_cast<Muon::TgcClusterOnTrack*>(&rioOnTrack);
72 el.resetWithKeyAndIndex(m_tgcPrdKey.key(), el.index());
73 }
74
75 ATH_MSG_VERBOSE("Found PRD at : " << prd);
76 return std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*>(detEl, prd);
77}
78
81 if (mdt) {
82 prepareRIO_OnTrackElementLink<const Muon::MdtPrepDataContainer, Muon::MdtDriftCircleOnTrack>(mdt);
83 return;
84 }
85 Muon::CscClusterOnTrack* csc = dynamic_cast<Muon::CscClusterOnTrack*>(RoT);
86 if (csc) {
87 prepareRIO_OnTrackElementLink<const Muon::CscPrepDataContainer, Muon::CscClusterOnTrack>(csc);
88 return;
89 }
90 Muon::RpcClusterOnTrack* rpc = dynamic_cast<Muon::RpcClusterOnTrack*>(RoT);
91 if (rpc) {
92 prepareRIO_OnTrackElementLink<const Muon::RpcPrepDataContainer, Muon::RpcClusterOnTrack>(rpc);
93 return;
94 }
95 Muon::TgcClusterOnTrack* tgc = dynamic_cast<Muon::TgcClusterOnTrack*>(RoT);
96 if (tgc) {
97 prepareRIO_OnTrackElementLink<const Muon::TgcPrepDataContainer, Muon::TgcClusterOnTrack>(tgc);
98 return;
99 }
100 Muon::sTgcClusterOnTrack* stgc = dynamic_cast<Muon::sTgcClusterOnTrack*>(RoT);
101 if (stgc) {
102 prepareRIO_OnTrackElementLink<const Muon::sTgcPrepDataContainer, Muon::sTgcClusterOnTrack>(stgc);
103 return;
104 }
105 Muon::MMClusterOnTrack* mm = dynamic_cast<Muon::MMClusterOnTrack*>(RoT);
106 if (mm) {
107 prepareRIO_OnTrackElementLink<const Muon::MMPrepDataContainer, Muon::MMClusterOnTrack>(mm);
108 return;
109 }
110}
111
112void Muon::MuonEventCnvTool::prepareRIO_OnTrackLink(const Trk::RIO_OnTrack* RoT, ELKey_t& key, ELIndex_t& index) const {
113 const Muon::MdtDriftCircleOnTrack* mdt = dynamic_cast<const Muon::MdtDriftCircleOnTrack*>(RoT);
114 if (mdt) {
115 prepareRIO_OnTrackElementLink<const Muon::MdtPrepDataContainer, Muon::MdtDriftCircleOnTrack>(mdt, key, index);
116 return;
117 }
118 const Muon::CscClusterOnTrack* csc = dynamic_cast<const Muon::CscClusterOnTrack*>(RoT);
119 if (csc) {
120 prepareRIO_OnTrackElementLink<const Muon::CscPrepDataContainer, Muon::CscClusterOnTrack>(csc, key, index);
121 return;
122 }
123 const Muon::RpcClusterOnTrack* rpc = dynamic_cast<const Muon::RpcClusterOnTrack*>(RoT);
124 if (rpc) {
125 prepareRIO_OnTrackElementLink<const Muon::RpcPrepDataContainer, Muon::RpcClusterOnTrack>(rpc, key, index);
126 return;
127 }
128 const Muon::TgcClusterOnTrack* tgc = dynamic_cast<const Muon::TgcClusterOnTrack*>(RoT);
129 if (tgc) {
130 prepareRIO_OnTrackElementLink<const Muon::TgcPrepDataContainer, Muon::TgcClusterOnTrack>(tgc, key, index);
131 return;
132 }
133 const Muon::sTgcClusterOnTrack* stgc = dynamic_cast<const Muon::sTgcClusterOnTrack*>(RoT);
134 if (stgc) {
135 prepareRIO_OnTrackElementLink<const Muon::sTgcPrepDataContainer, Muon::sTgcClusterOnTrack>(stgc, key, index);
136 return;
137 }
138 const Muon::MMClusterOnTrack* mm = dynamic_cast<const Muon::MMClusterOnTrack*>(RoT);
139 if (mm) {
140 prepareRIO_OnTrackElementLink<const Muon::MMPrepDataContainer, Muon::MMClusterOnTrack>(mm, key, index);
141 return;
142 }
143 }
144
146 std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> pair = getLinks(*RoT);
148}
149
153
155 const EventContext& ctx = Gaudi::Hive::currentContext();
156 const MuonGM::MuonDetectorManager* muonMgr{nullptr};
157 if (!SG::get(muonMgr, m_detectorManagerKey, ctx).isSuccess()) {
158 ATH_MSG_ERROR("Failed to retrieve the Muon detector manager from the conditions store");
159 return nullptr;
160 }
161
162 const Trk::TrkDetElementBase* detEl = muonMgr->getReadoutElement(id);
163
164 if (!detEl) {
165 ATH_MSG_ERROR("Could not find detector element for Identifier: " << m_idHelperSvc->toString(id));
166 }
167 return detEl;
168}
169
171 const EventContext& ctx = Gaudi::Hive::currentContext();
172 switch (m_idHelperSvc->technologyIndex(id)) {
174 case MDT:
175 return getLink(id, idHash, m_mdtPrdKey, ctx);
176 case RPC:
177 return getLink(id, idHash, m_rpcPrdKey, ctx);
178 case TGC:
179 return getLink(id, idHash, m_tgcPrdKey, ctx);
180 case MM:
181 return getLink(id, idHash, m_mmPrdKey, ctx);
182 case STGC:
183 return getLink(id, idHash, m_stgcPrdKey, ctx);
184 case CSC:
185 return getLink(id, idHash, m_cscPrdKey, ctx);
186 default:
187 break;
188 }
189 ATH_MSG_ERROR("The given Identifier is not a muon one " << m_idHelperSvc->toString(id));
190 return nullptr;
191}
192
193template <class CONT>
195 const SG::ReadHandleKey<CONT>& prdKey, const EventContext& ctx) const {
196 SG::ReadHandle<CONT> handle{prdKey, ctx};
197 if (!handle.isValid()) {
198 ATH_MSG_ERROR("PRD container not found at " << prdKey);
199 return nullptr;
200 } else {
201 ATH_MSG_DEBUG("PRD Cluster container found at " << prdKey);
202 }
203
204 auto ptr = handle->indexFindPtr(idHash);
205 if (!ptr) {
206 ATH_MSG_DEBUG("No matching PRD found");
207 return nullptr;
208 }
209 // if we find PRD, then recreate link
210 // loop though collection to find matching PRD.
211 // there MUST be a faster way to do this!!
212 for (const auto& collIt : *ptr) {
213 if (collIt->identify() == id) return collIt;
214 }
215 ATH_MSG_DEBUG("No matching PRD found");
216 return nullptr;
217}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
@ CSC
Definition RegSelEnums.h:34
@ STGC
Definition RegSelEnums.h:39
@ MM
Definition RegSelEnums.h:38
@ RPC
Definition RegSelEnums.h:32
@ MDT
Definition RegSelEnums.h:31
ElementLink< Muon::TgcPrepDataContainer > ElementLinkToIDC_TGC_Container
Class to implement Cluster On Track for Si.
This is a "hash" representation of an Identifier.
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const MuonReadoutElement * getReadoutElement(const Identifier &id) const
Get any read out element.
Class to represent the calibrated clusters created from CSC strips.
Class to represent calibrated clusters formed from TGC strips.
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
Gaudi::Property< bool > m_manuallyFindPRDs
If true, search for PRDs manually - i.e.
virtual std::pair< const Trk::TrkDetElementBase *, const Trk::PrepRawData * > getLinks(Trk::RIO_OnTrack &rioOnTrack) const override
virtual void prepareRIO_OnTrack(Trk::RIO_OnTrack *rot) const override
Gaudi::Property< bool > m_fixTGCs
SG::ReadHandleKey< MdtPrepDataContainer > m_mdtPrdKey
SG::ReadHandleKey< MMPrepDataContainer > m_mmPrdKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadHandleKey< RpcPrepDataContainer > m_rpcPrdKey
virtual void prepareRIO_OnTrackLink(const Trk::RIO_OnTrack *rot, ELKey_t &key, ELIndex_t &index) const override
Similar, but just return the EL components rather then changing ROT.
SG::ReadHandleKey< CscPrepDataContainer > m_cscPrdKey
virtual void checkRoT(const Trk::RIO_OnTrack &rioOnTrack) const override
check that the RoT is correctly filled
SG::ReadHandleKey< sTgcPrepDataContainer > m_stgcPrdKey
virtual StatusCode initialize() override
virtual void recreateRIO_OnTrack(Trk::RIO_OnTrack *RoT) const override
Take the passed RoT and recreate it (i.e.
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const override
Return the detectorElement associated with this Identifier.
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detectorManagerKey
SG::ReadHandleKey< TgcPrepDataContainer > m_tgcPrdKey
const Trk::PrepRawData * getLink(const Identifier &id, const IdentifierHash &idHash) const
Class to represent calibrated clusters formed from RPC strips.
Class to represent calibrated clusters formed from TGC strips.
ElementLinkToIDC_TGC_Container m_rio
PrepRawData object assoicated with this measurement.
Class to represent calibrated clusters formed from TGC strips.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual void setRoT_Values(std::pair< const Trk::TrkDetElementBase *, const Trk::PrepRawData * > &pair, Trk::RIO_OnTrack *RoT) const
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Identifier identify() const
return the identifier -extends MeasurementBase
virtual IdentifierHash idDE() const =0
returns the DE hashID
This is the base class for all tracking detector elements with read-out relevant information.
STL class.
Ensure that the Athena extensions are properly loaded.
Definition GeoMuonHits.h:27
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
Ensure that the ATLAS eigen extensions are properly loaded.
Definition index.py:1