ATLAS Offline Software
Loading...
Searching...
No Matches
MuonEventCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 "GaudiKernel/MsgStream.h"
13#include "Identifier/Identifier.h"
30
31Muon::MuonEventCnvTool::MuonEventCnvTool(const std::string& t, const std::string& n, const IInterface* p) : base_class(t, n, p) {}
32
34 ATH_CHECK(m_idHelperSvc.retrieve());
35 ATH_CHECK(m_rpcPrdKey.initialize());
36 ATH_CHECK(m_tgcPrdKey.initialize());
37 ATH_CHECK(m_mdtPrdKey.initialize());
38 ATH_CHECK(m_detectorManagerKey.initialize());
39 ATH_CHECK(m_cscPrdKey.initialize(!m_cscPrdKey.empty())); // check for layouts without CSCs
40 ATH_CHECK(m_mmPrdKey.initialize(!m_mmPrdKey.empty())); // check for layouts without MicroMegas
41 ATH_CHECK(m_stgcPrdKey.initialize(!m_stgcPrdKey.empty())); // check for layouts without STGCs
42
43 return StatusCode::SUCCESS;
44}
45
48 const Identifier& id = rioOnTrack.identify();
49 if (m_idHelperSvc->isRpc(id))
50 type = RPC;
51 else if (m_idHelperSvc->isTgc(id))
52 type = TGC;
53 else if (m_idHelperSvc->isMdt(id))
54 type = MDT;
55 else if (m_idHelperSvc->isMM(id))
56 type = MM;
57 else if (m_idHelperSvc->issTgc(id))
58 type = STGC;
59 else if (m_idHelperSvc->isCsc(id))
60 type = CSC;
61
62 if (type == TypeUnknown) {
63 ATH_MSG_ERROR("Type does not match known concrete type of MuonSpectrometer! Dumping RoT:" << rioOnTrack);
64 } else {
65 ATH_MSG_VERBOSE("Type = " << type << "(RPC=" << RPC << ", CSC=" << CSC << ", TGC=" << TGC << "MDT=" << MDT << ", STGC=" << STGC
66 << "MM=" << MM << ")");
67 }
68}
69
70std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> Muon::MuonEventCnvTool::getLinks(Trk::RIO_OnTrack& rioOnTrack) const {
71 using namespace Trk;
72 using namespace MuonGM;
73
74 const Identifier& id = rioOnTrack.identify();
75 const TrkDetElementBase* detEl = getDetectorElement(id);
76 if (!detEl) {
77 ATH_MSG_ERROR("Could not find detector element for " << m_idHelperSvc->toString(id));
78 ATH_MSG_ERROR(rioOnTrack);
79 }
80 const PrepRawData* prd = m_manuallyFindPRDs ? getLink(id, rioOnTrack.idDE()) : nullptr;
81
82 if (m_fixTGCs && m_idHelperSvc->isTgc(id) && !rioOnTrack.prepRawData()) {
83 // Okay, so we might have hit the nasty issue that the TGC EL is broken in some samples
84 // Need to fix by pointing to the key defined here (assumung it has been configured correctly for this sample)
85 Muon::TgcClusterOnTrack* tgc = dynamic_cast<Muon::TgcClusterOnTrack*>(&rioOnTrack);
87 el.resetWithKeyAndIndex(m_tgcPrdKey.key(), el.index());
88 }
89
90 ATH_MSG_VERBOSE("Found PRD at : " << prd);
91 return std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*>(detEl, prd);
92}
93
96 if (mdt) {
97 prepareRIO_OnTrackElementLink<const Muon::MdtPrepDataContainer, Muon::MdtDriftCircleOnTrack>(mdt);
98 return;
99 }
100 Muon::CscClusterOnTrack* csc = dynamic_cast<Muon::CscClusterOnTrack*>(RoT);
101 if (csc) {
102 prepareRIO_OnTrackElementLink<const Muon::CscPrepDataContainer, Muon::CscClusterOnTrack>(csc);
103 return;
104 }
105 Muon::RpcClusterOnTrack* rpc = dynamic_cast<Muon::RpcClusterOnTrack*>(RoT);
106 if (rpc) {
107 prepareRIO_OnTrackElementLink<const Muon::RpcPrepDataContainer, Muon::RpcClusterOnTrack>(rpc);
108 return;
109 }
110 Muon::TgcClusterOnTrack* tgc = dynamic_cast<Muon::TgcClusterOnTrack*>(RoT);
111 if (tgc) {
112 prepareRIO_OnTrackElementLink<const Muon::TgcPrepDataContainer, Muon::TgcClusterOnTrack>(tgc);
113 return;
114 }
115 Muon::sTgcClusterOnTrack* stgc = dynamic_cast<Muon::sTgcClusterOnTrack*>(RoT);
116 if (stgc) {
117 prepareRIO_OnTrackElementLink<const Muon::sTgcPrepDataContainer, Muon::sTgcClusterOnTrack>(stgc);
118 return;
119 }
120 Muon::MMClusterOnTrack* mm = dynamic_cast<Muon::MMClusterOnTrack*>(RoT);
121 if (mm) {
122 prepareRIO_OnTrackElementLink<const Muon::MMPrepDataContainer, Muon::MMClusterOnTrack>(mm);
123 return;
124 }
125}
126
127void Muon::MuonEventCnvTool::prepareRIO_OnTrackLink(const Trk::RIO_OnTrack* RoT, ELKey_t& key, ELIndex_t& index) const {
128 const Muon::MdtDriftCircleOnTrack* mdt = dynamic_cast<const Muon::MdtDriftCircleOnTrack*>(RoT);
129 if (mdt) {
130 prepareRIO_OnTrackElementLink<const Muon::MdtPrepDataContainer, Muon::MdtDriftCircleOnTrack>(mdt, key, index);
131 return;
132 }
133 const Muon::CscClusterOnTrack* csc = dynamic_cast<const Muon::CscClusterOnTrack*>(RoT);
134 if (csc) {
135 prepareRIO_OnTrackElementLink<const Muon::CscPrepDataContainer, Muon::CscClusterOnTrack>(csc, key, index);
136 return;
137 }
138 const Muon::RpcClusterOnTrack* rpc = dynamic_cast<const Muon::RpcClusterOnTrack*>(RoT);
139 if (rpc) {
140 prepareRIO_OnTrackElementLink<const Muon::RpcPrepDataContainer, Muon::RpcClusterOnTrack>(rpc, key, index);
141 return;
142 }
143 const Muon::TgcClusterOnTrack* tgc = dynamic_cast<const Muon::TgcClusterOnTrack*>(RoT);
144 if (tgc) {
145 prepareRIO_OnTrackElementLink<const Muon::TgcPrepDataContainer, Muon::TgcClusterOnTrack>(tgc, key, index);
146 return;
147 }
148 const Muon::sTgcClusterOnTrack* stgc = dynamic_cast<const Muon::sTgcClusterOnTrack*>(RoT);
149 if (stgc) {
150 prepareRIO_OnTrackElementLink<const Muon::sTgcPrepDataContainer, Muon::sTgcClusterOnTrack>(stgc, key, index);
151 return;
152 }
153 const Muon::MMClusterOnTrack* mm = dynamic_cast<const Muon::MMClusterOnTrack*>(RoT);
154 if (mm) {
155 prepareRIO_OnTrackElementLink<const Muon::MMPrepDataContainer, Muon::MMClusterOnTrack>(mm, key, index);
156 return;
157 }
158 }
159
161 std::pair<const Trk::TrkDetElementBase*, const Trk::PrepRawData*> pair = getLinks(*RoT);
163}
164
168
170 const EventContext& ctx = Gaudi::Hive::currentContext();
171 const MuonGM::MuonDetectorManager* muonMgr{nullptr};
172 SG::ReadCondHandle muonMgrHandle{m_detectorManagerKey, ctx};
173 if (!muonMgrHandle.isValid()) {
174 ATH_MSG_ERROR("Failed to retrieve the Muon detector manager from the conditions store");
175 return nullptr;
176 }
177 muonMgr = muonMgrHandle.cptr();
178
179 const Trk::TrkDetElementBase* detEl = nullptr;
180 // TODO Check that these are in the most likely ordering, for speed. EJWM.
181 if (m_idHelperSvc->isRpc(id)) {
182 detEl = muonMgr->getRpcReadoutElement(id);
183 } else if (m_idHelperSvc->isCsc(id)) {
184 detEl = muonMgr->getCscReadoutElement(id);
185 } else if (m_idHelperSvc->isTgc(id)) {
186 detEl = muonMgr->getTgcReadoutElement(id);
187 } else if (m_idHelperSvc->isMdt(id)) {
188 detEl = muonMgr->getMdtReadoutElement(id);
189 } else if (m_idHelperSvc->issTgc(id)) {
190 detEl = muonMgr->getsTgcReadoutElement(id);
191 } else if (m_idHelperSvc->isMM(id)) {
192 detEl = muonMgr->getMMReadoutElement(id);
193 }
194 if (!detEl) ATH_MSG_ERROR("Could not find detector element for Identifier: " << m_idHelperSvc->toString(id));
195 return detEl;
196}
197
199 const EventContext& ctx = Gaudi::Hive::currentContext();
200 if (m_idHelperSvc->isMdt(id)) {
201 return getLink(id, idHash, m_mdtPrdKey, ctx);
202 } else if (m_idHelperSvc->isRpc(id)) {
203 return getLink(id, idHash, m_rpcPrdKey, ctx);
204 } else if (m_idHelperSvc->isTgc(id)) {
205 return getLink(id, idHash, m_tgcPrdKey, ctx);
206 } else if (m_idHelperSvc->isMM(id)) {
207 return getLink(id, idHash, m_mmPrdKey, ctx);
208 } else if (m_idHelperSvc->issTgc(id)) {
209 return getLink(id, idHash, m_stgcPrdKey, ctx);
210 }
211 ATH_MSG_ERROR("The given Identifier is not a muon one " << m_idHelperSvc->toString(id));
212 return nullptr;
213}
214
215template <class CONT>
217 const SG::ReadHandleKey<CONT>& prdKey, const EventContext& ctx) const {
218 SG::ReadHandle<CONT> handle{prdKey, ctx};
219 if (!handle.isValid()) {
220 ATH_MSG_ERROR("PRD container not found at " << prdKey);
221 return nullptr;
222 } else {
223 ATH_MSG_DEBUG("PRD Cluster container found at " << prdKey);
224 }
225
226 auto ptr = handle->indexFindPtr(idHash);
227 if (!ptr) {
228 ATH_MSG_DEBUG("No matching PRD found");
229 return nullptr;
230 }
231 // if we find PRD, then recreate link
232 // loop though collection to find matching PRD.
233 // there MUST be a faster way to do this!!
234 for (const auto& collIt : *ptr) {
235 if (collIt->identify() == id) return collIt;
236 }
237 ATH_MSG_DEBUG("No matching PRD found");
238 return nullptr;
239}
#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)
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 RpcReadoutElement * getRpcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
const MMReadoutElement * getMMReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
const TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
const sTgcReadoutElement * getsTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
const CscReadoutElement * getCscReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
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
MuonEventCnvTool(const std::string &, const std::string &, const IInterface *)
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.
const_pointer_type cptr()
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
Definition TgcBase.h:6
Ensure that the ATLAS eigen extensions are properly loaded.
Definition index.py:1