ATLAS Offline Software
Loading...
Searching...
No Matches
GeoMuonHits.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MuonReadoutGeometry/MuonDetectorManager.h"
6#include "MuonIdHelpers/MdtIdHelper.h"
7#include "MuonIdHelpers/RpcIdHelper.h"
8#include "MuonIdHelpers/CscIdHelper.h"
9#include "MuonIdHelpers/TgcIdHelper.h"
10#include "MuonIdHelpers/sTgcIdHelper.h"
11#include "MuonIdHelpers/MmIdHelper.h"
12
13#include "MuonSimEvent/MDTSimHitCollection.h"
14#include "MuonSimEvent/MDTSimHit.h"
15#include "MuonSimEvent/MdtHitIdHelper.h"
16#include "MuonReadoutGeometry/MdtReadoutElement.h"
17
18#include "MuonPrepRawData/MdtPrepDataContainer.h"
19#include "MuonPrepRawData/RpcPrepDataContainer.h"
20#include "MuonPrepRawData/TgcPrepDataContainer.h"
21#include "MuonPrepRawData/CscPrepDataContainer.h"
22
23#include "MuonSimEvent/RPCSimHitCollection.h"
24#include "MuonSimEvent/RPCSimHit.h"
25#include "MuonSimEvent/RpcHitIdHelper.h"
26#include "MuonReadoutGeometry/RpcReadoutElement.h"
27
28#include "MuonSimEvent/TGCSimHitCollection.h"
29#include "MuonSimEvent/TGCSimHit.h"
30#include "MuonSimEvent/TgcHitIdHelper.h"
31#include "MuonReadoutGeometry/TgcReadoutElement.h"
32
33#include "MuonSimEvent/CSCSimHitCollection.h"
34#include "MuonSimEvent/CSCSimHit.h"
35#include "MuonSimEvent/CscHitIdHelper.h"
36#include "MuonReadoutGeometry/CscReadoutElement.h"
37
38#include "MuonSimEvent/MMSimHitCollection.h"
39#include "MuonSimEvent/MMSimHit.h"
40#include "MuonSimEvent/sTGCSimHitCollection.h"
41#include "MuonSimEvent/sTGCSimHit.h"
42#include "MuonSimEvent/MicromegasHitIdHelper.h"
43#include "MuonSimEvent/sTgcHitIdHelper.h"
44#include "MuonSimEvent/sTgcSimIdToOfflineId.h"
45#include "MuonSimEvent/MM_SimIdToOfflineId.h"
46#include "MuonReadoutGeometry/sTgcReadoutElement.h"
47#include "MuonReadoutGeometry/MMReadoutElement.h"
48#include "GeoPrimitives/GeoPrimitivesHelpers.h"
49
50
51inline GeoMDTHit::GeoMDTHit (const MDTSimHit & h) {
52 m_hit = &h;
53}
54
55
56inline Amg::Vector3D GeoMDTHit::getGlobalPosition() const {
57
58
59
60 HitID hitid = m_hit->MDTid();
61 const MdtIdHelper* mdtID = mgr()->mdtIdHelper();
62 const MdtHitIdHelper* mdthhelper = MdtHitIdHelper::GetHelper(mdtID->tubeMax());
63
64 std::string stname = mdthhelper->GetStationName(hitid);
65 int steta = mdthhelper->GetZSector(hitid);
66 int stphi = mdthhelper->GetPhiSector(hitid);
67 int ml = mdthhelper->GetMultiLayer(hitid);
68 int tl = mdthhelper->GetLayer(hitid);
69 int tube = mdthhelper->GetTube(hitid);
70
71 Identifier offid = mdtID->channelID(stname,
72 steta,
73 stphi,ml,tl,tube);
74
75 if (offid == 0)
76 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
77
78
79 const MuonGM::MdtReadoutElement* mdtdet = mgr()->getMdtReadoutElement(offid);
80 if (!mdtdet) {
81 const MdtIdHelper* mdtID = mgr()->mdtIdHelper();
82 std::cerr<<"MDT readout element not found for Id = "
83 <<mdtID->show_to_string(offid)<<std::endl;
84 return Amg::Vector3D::Zero();
85 }
86
87 // -------- Testing Sim to Offline ID conversion ---------
88
89 return mdtdet->localToGlobalTransf(offid) * m_hit->localPosition();
90
91}
92
93inline GeoRPCHit::GeoRPCHit (const RPCSimHit & h):m_hit{&h} {
94 try{
95
96 HitID hitid = m_hit->RPCid();
97 const RpcIdHelper* rpcID = mgr()->rpcIdHelper();
98 const RpcHitIdHelper* rpchhelper = RpcHitIdHelper::GetHelper(rpcID->gasGapMax());
99 std::string stname = rpchhelper->GetStationName(hitid);
100 int steta = rpchhelper->GetZSector(hitid);
101 int stphi = rpchhelper->GetPhiSector(hitid);
102 int dbr = rpchhelper->GetDoubletR(hitid);
103 int dbz = rpchhelper->GetDoubletZ(hitid);
104 int dbp = rpchhelper->GetDoubletPhi(hitid);
105 int gg = rpchhelper->GetGasGapLayer(hitid);
106 int mfi = rpchhelper->GetMeasuresPhi(hitid);
107 int strip = 1;
108
109 m_id = rpcID->channelID(stname, steta, stphi,
110 dbr, dbz, dbp, gg, mfi, strip, m_goodHit);
111 if (m_goodHit) {
112 m_goodHit = mgr()->idHelperSvc()->detElementHash(m_id) <
113 rpcID->detectorElement_hash_max();
114 }
115 }catch(...) {
116 m_goodHit = false;
117 }
118}
119
120inline Amg::Vector3D GeoRPCHit::getGlobalPosition() const {
121
122 const MuonGM::RpcReadoutElement* rpcdet = mgr()->getRpcReadoutElement(m_id);
123 if (rpcdet) {
124 return rpcdet->localToGlobalTransf(m_id) * m_hit->localPosition();
125 }
126 std::cerr<<"RPC readout element not found for Id = "
127 <<mgr()->idHelperSvc()->toString(m_id)<<std::endl;
128 return Amg::Vector3D::Zero();
129
130
131}
132
133inline GeoTGCHit::GeoTGCHit (const TGCSimHit & h) {
134 m_hit = &h;
135}
136
137inline Amg::Vector3D GeoTGCHit::getGlobalPosition() const {
138
139 HitID hitid = m_hit->TGCid();
140 const TgcHitIdHelper* tgchhelper = TgcHitIdHelper::GetHelper();
141 std::string stname = tgchhelper->GetStationName(hitid);
142 int steta = tgchhelper->GetStationEta(hitid);
143 int stphi = tgchhelper->GetStationPhi(hitid);
144 int gg = tgchhelper->GetGasGap(hitid);
145 int isstrip= 0;
146 int channel= 1;
147 const TgcIdHelper* tgcID = mgr()->tgcIdHelper();
148 Identifier offid = tgcID->channelID(stname,
149 steta,
150 stphi,
151 gg, isstrip, channel);
152 if ( offid == 0)
153 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
154
155 const MuonGM::TgcReadoutElement* tgcdet = mgr()->getTgcReadoutElement(offid);
156 if (tgcdet) {
157 return tgcdet->localToGlobalTransf(offid) * m_hit->localPosition();
158 }
159 std::cerr<<"TGC readout element not found for Id = "
160 <<tgcID->show_to_string(offid)<<std::endl;
161 return Amg::Vector3D::Zero();
162}
163
164inline GeoCSCHit::GeoCSCHit (const CSCSimHit & h) {
165 m_hit = &h;
166}
167
168inline Amg::Vector3D GeoCSCHit::getGlobalPosition() const {
169
170 HitID hitid = m_hit->CSCid();
171 const CscHitIdHelper* cschhelper = CscHitIdHelper::GetHelper();
172
173 std::string stname = cschhelper->GetStationName(hitid);
174 int steta = cschhelper->GetZSector(hitid);
175 int stphi = cschhelper->GetPhiSector(hitid);
176 int ml = cschhelper->GetChamberLayer(hitid);
177 int wl = cschhelper->GetWireLayer(hitid);
178 int measphi = 0;
179 int channel = 1;
180
181 const CscIdHelper* cscID = mgr()->cscIdHelper();
182 Identifier offid = cscID->channelID(stname,
183 steta,
184 stphi,ml,wl,measphi,channel);
185
186 if (offid == 0)
187 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
188
189
190 const MuonGM::CscReadoutElement* cscdet = mgr()->getCscReadoutElement(offid);
191 if (!cscdet) {
192 const CscIdHelper* cscID = mgr()->cscIdHelper();
193 std::cerr<<"CSC readout element not found for Id = "
194 <<cscID->show_to_string(offid)<<std::endl;
195 return Amg::Vector3D::Zero();
196 }
197 return cscdet->localToGlobalTransf(offid) * m_hit->getHitStart();
198}
199
200inline GeoMMHit::GeoMMHit (const MMSimHit & h) {
201 m_hit = &h;
202}
203
204inline Amg::Vector3D GeoMMHit::getGlobalPosition() const {
205
206 HitID hitid = m_hit->MMId();
207 const MmIdHelper* mmID = mgr()->mmIdHelper();
208 MM_SimIdToOfflineId simToOffline(mmID);
209 Identifier offid = simToOffline.convert(hitid);
210
211 if (offid == 0)
212 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
213
214
215 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
216 if (!mmdet) {
217 const MmIdHelper* mmID = mgr()->mmIdHelper();
218 std::cerr<<"MM readout element not found for Id = "
219 <<mmID->show_to_string(offid)<<std::endl;
220 return Amg::Vector3D::Zero();
221 }
222 return m_hit->globalPosition();
223
224}
225inline Amg::Vector3D GeoMMHit::getTrkGlobalPosition() const {
226
227 HitID hitid = m_hit->MMId();
228 const MmIdHelper* mmID = mgr()->mmIdHelper();
229 MM_SimIdToOfflineId simToOffline(mmID);
230 Identifier offid = simToOffline.convert(hitid);
231
232 if (offid == 0)
233 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
234
235
236 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
237 if (!mmdet) {
238 const MmIdHelper* mmID = mgr()->mmIdHelper();
239 std::cerr<<"MM readout element not found for Id = "
240 <<mmID->show_to_string(offid)<<std::endl;
241 return Amg::Vector3D::Zero();
242 }
243 return mmdet->transform(offid)*getTrkLocalPosition();
244}
245inline Amg::Vector3D GeoMMHit::getTrkLocalPosition() const {
246
247
248 HitID hitid = m_hit->MMId();
249 const MmIdHelper* mmID = mgr()->mmIdHelper();
250 MM_SimIdToOfflineId simToOffline(mmID);
251 Identifier offid = simToOffline.convert(hitid);
252
253 if (offid == 0)
254 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
255
256
257 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
258 if (!mmdet) {
259 const MmIdHelper* mmID = mgr()->mmIdHelper();
260 std::string err = "MM readout element not found for Id = " +
261 mmID->show_to_string(offid);
262 throw std::runtime_error (err);
263 }
264
265 Amg::Transform3D gToL = mmdet->absTransform().inverse();
266 Amg::Vector3D locp = gToL*m_hit->globalPosition();
267 Amg::Vector3D localHit(0.,locp.y(),locp.z());
268 Amg::Vector3D trkLocHit= Amg::getRotateY3D(90.*CLHEP::deg)*localHit;
269 return trkLocHit;
270}
271
272inline GeosTGCHit::GeosTGCHit (const sTGCSimHit & h) {
273 m_hit = &h;
274}
275
276inline Amg::Vector3D GeosTGCHit::getGlobalPosition() const {
277
278 HitID hitid = m_hit->sTGCId();
279 const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
280 sTgcSimIdToOfflineId simToOffline(stgcID);
281 Identifier offid = simToOffline.convert(hitid);
282
283 if (offid == 0)
284 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
285
286
287 const MuonGM::sTgcReadoutElement* stgcdet = mgr()->getsTgcReadoutElement(offid);
288 if (!stgcdet) {
289 const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
290 std::cerr<<"sTGC readout element not found for Id = "
291 <<stgcID->show_to_string(offid)<<std::endl;
292 return Amg::Vector3D::Zero();
293 }
294 return m_hit->globalPosition();
295}
296