ATLAS Offline Software
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 
31 Muon::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 
46 void Muon::MuonEventCnvTool::checkRoT(const Trk::RIO_OnTrack& rioOnTrack) const {
47  MuonConcreteType type = TypeUnknown;
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 
70 std::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 
127 void 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);
162  if (pair.first) Trk::ITrkEventCnvTool::setRoT_Values(pair, RoT);
163 }
164 
165 const Trk::TrkDetElementBase* Muon::MuonEventCnvTool::getDetectorElement(const Identifier& id, const IdentifierHash& ) const {
166  return getDetectorElement(id);
167 }
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 
198 const Trk::PrepRawData* Muon::MuonEventCnvTool::getLink(const Identifier& id, const IdentifierHash& idHash) const {
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 
215 template <class CONT>
216 const Trk::PrepRawData* Muon::MuonEventCnvTool::getLink(const Identifier& id, const IdentifierHash& idHash,
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 }
TGC
@ TGC
Definition: RegSelEnums.h:33
Muon::MuonEventCnvTool::checkRoT
virtual void checkRoT(const Trk::RIO_OnTrack &rioOnTrack) const override
check that the RoT is correctly filled
Definition: MuonEventCnvTool.cxx:46
MdtReadoutElement.h
TrkDetElementBase.h
STGC
@ STGC
Definition: RegSelEnums.h:39
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
sTgcClusterOnTrack.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Muon::MuonEventCnvTool::getLinks
virtual std::pair< const Trk::TrkDetElementBase *, const Trk::PrepRawData * > getLinks(Trk::RIO_OnTrack &rioOnTrack) const override
Definition: MuonEventCnvTool.cxx:70
sTgcReadoutElement.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
Muon::TgcClusterOnTrack
Class to represent calibrated clusters formed from TGC strips.
Definition: TgcClusterOnTrack.h:46
xAOD::TauHelpers::getLink
const T * getLink(const xAOD::IParticle *, const std::string &, bool debug=false)
MM
@ MM
Definition: RegSelEnums.h:38
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
Muon::RpcClusterOnTrack
Class to represent calibrated clusters formed from RPC strips.
Definition: RpcClusterOnTrack.h:35
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MdtDriftCircleOnTrack.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
PrepRawData.h
MMClusterOnTrack.h
TgcClusterOnTrack.h
Muon::TgcClusterOnTrack::m_rio
ElementLinkToIDC_TGC_Container m_rio
PrepRawData object assoicated with this measurement.
Definition: TgcClusterOnTrack.h:112
MMReadoutElement.h
RpcClusterOnTrack.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::MuonEventCnvTool::getLink
const Trk::PrepRawData * getLink(const Identifier &id, const IdentifierHash &idHash) const
Definition: MuonEventCnvTool.cxx:198
TGC
Definition: TgcBase.h:6
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CscClusterOnTrack.h
CscReadoutElement.h
Muon::MuonEventCnvTool::prepareRIO_OnTrack
virtual void prepareRIO_OnTrack(Trk::RIO_OnTrack *rot) const override
Definition: MuonEventCnvTool.cxx:94
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::MuonEventCnvTool::MuonConcreteType
MuonConcreteType
Definition: MuonEventCnvTool.h:32
Muon::MuonEventCnvTool::MuonEventCnvTool
MuonEventCnvTool(const std::string &, const std::string &, const IInterface *)
Definition: MuonEventCnvTool.cxx:31
Trk::ITrkEventCnvTool::setRoT_Values
virtual void setRoT_Values(std::pair< const Trk::TrkDetElementBase *, const Trk::PrepRawData * > &pair, Trk::RIO_OnTrack *RoT) const
Muon::sTgcClusterOnTrack
Class to represent calibrated clusters formed from TGC strips.
Definition: sTgcClusterOnTrack.h:30
Muon::MuonEventCnvTool::initialize
virtual StatusCode initialize() override
Definition: MuonEventCnvTool.cxx:33
Trk::PrepRawData
Definition: PrepRawData.h:62
Muon::MMClusterOnTrack
Class to represent calibrated clusters formed from TGC strips.
Definition: MMClusterOnTrack.h:26
EventPrimitives.h
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Muon::MuonEventCnvTool::recreateRIO_OnTrack
virtual void recreateRIO_OnTrack(Trk::RIO_OnTrack *RoT) const override
Take the passed RoT and recreate it (i.e.
Definition: MuonEventCnvTool.cxx:160
RPC
@ RPC
Definition: RegSelEnums.h:32
RIO_OnTrack.h
IdentifierHash.h
Muon::MdtDriftCircleOnTrack
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
Definition: MdtDriftCircleOnTrack.h:37
Trk::RIO_OnTrack::idDE
virtual IdentifierHash idDE() const =0
returns the DE hashID
Trk::RIO_OnTrack::prepRawData
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
Muon::MuonEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const override
Return the detectorElement associated with this Identifier.
Definition: MuonEventCnvTool.cxx:165
Muon::CscClusterOnTrack
Class to represent the calibrated clusters created from CSC strips.
Definition: CscClusterOnTrack.h:47
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::RIO_OnTrack::identify
Identifier identify() const
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:152
Muon::MuonEventCnvTool::prepareRIO_OnTrackLink
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.
Definition: MuonEventCnvTool.cxx:127
TgcReadoutElement.h
CSC
@ CSC
Definition: RegSelEnums.h:34
MuonEventCnvTool.h
MDT
@ MDT
Definition: RegSelEnums.h:31
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
RpcReadoutElement.h
Identifier
Definition: IdentifierFieldParser.cxx:14