ATLAS Offline Software
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 
51 inline GeoMDTHit::GeoMDTHit (const MDTSimHit & h) {
52  m_hit = &h;
53 }
54 
55 
56 inline 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 
93 inline GeoRPCHit::GeoRPCHit (const RPCSimHit & h) {
94  m_hit = &h;
95 }
96 
97 inline Amg::Vector3D GeoRPCHit::getGlobalPosition() const {
98 
99  HitID hitid = m_hit->RPCid();
100  const RpcIdHelper* rpcID = mgr()->rpcIdHelper();
101  const RpcHitIdHelper* rpchhelper = RpcHitIdHelper::GetHelper(rpcID->gasGapMax());
102  std::string stname = rpchhelper->GetStationName(hitid);
103  int steta = rpchhelper->GetZSector(hitid);
104  int stphi = rpchhelper->GetPhiSector(hitid);
105  int dbr = rpchhelper->GetDoubletR(hitid);
106  int dbz = rpchhelper->GetDoubletZ(hitid);
107  int dbp = rpchhelper->GetDoubletPhi(hitid);
108  int gg = rpchhelper->GetGasGapLayer(hitid);
109  int mfi = rpchhelper->GetMeasuresPhi(hitid);
110  int strip = 1;
111  Identifier offid = rpcID->channelID(stname,
112  steta,
113  stphi,
114  dbr, dbz, dbp, gg, mfi, strip);
115  if ( offid == 0)
116  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
117 
118  const MuonGM::RpcReadoutElement* rpcdet = mgr()->getRpcReadoutElement(offid);
119  if (rpcdet) {
120  return rpcdet->localToGlobalTransf(offid) * m_hit->localPosition();
121  }
122  std::cerr<<"RPC readout element not found for Id = "
123  <<rpcID->show_to_string(offid)<<std::endl;
124  return Amg::Vector3D::Zero();
125 
126 
127 }
128 
129 inline GeoTGCHit::GeoTGCHit (const TGCSimHit & h) {
130  m_hit = &h;
131 }
132 
133 inline Amg::Vector3D GeoTGCHit::getGlobalPosition() const {
134 
135  HitID hitid = m_hit->TGCid();
136  const TgcHitIdHelper* tgchhelper = TgcHitIdHelper::GetHelper();
137  std::string stname = tgchhelper->GetStationName(hitid);
138  int steta = tgchhelper->GetStationEta(hitid);
139  int stphi = tgchhelper->GetStationPhi(hitid);
140  int gg = tgchhelper->GetGasGap(hitid);
141  int isstrip= 0;
142  int channel= 1;
143  const TgcIdHelper* tgcID = mgr()->tgcIdHelper();
144  Identifier offid = tgcID->channelID(stname,
145  steta,
146  stphi,
147  gg, isstrip, channel);
148  if ( offid == 0)
149  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
150 
151  const MuonGM::TgcReadoutElement* tgcdet = mgr()->getTgcReadoutElement(offid);
152  if (tgcdet) {
153  return tgcdet->localToGlobalTransf(offid) * m_hit->localPosition();
154  }
155  std::cerr<<"TGC readout element not found for Id = "
156  <<tgcID->show_to_string(offid)<<std::endl;
157  return Amg::Vector3D::Zero();
158 }
159 
160 inline GeoCSCHit::GeoCSCHit (const CSCSimHit & h) {
161  m_hit = &h;
162 }
163 
164 inline Amg::Vector3D GeoCSCHit::getGlobalPosition() const {
165 
166  HitID hitid = m_hit->CSCid();
167  const CscHitIdHelper* cschhelper = CscHitIdHelper::GetHelper();
168 
169  std::string stname = cschhelper->GetStationName(hitid);
170  int steta = cschhelper->GetZSector(hitid);
171  int stphi = cschhelper->GetPhiSector(hitid);
172  int ml = cschhelper->GetChamberLayer(hitid);
173  int wl = cschhelper->GetWireLayer(hitid);
174  int measphi = 0;
175  int channel = 1;
176 
177  const CscIdHelper* cscID = mgr()->cscIdHelper();
178  Identifier offid = cscID->channelID(stname,
179  steta,
180  stphi,ml,wl,measphi,channel);
181 
182  if (offid == 0)
183  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
184 
185 
186  const MuonGM::CscReadoutElement* cscdet = mgr()->getCscReadoutElement(offid);
187  if (!cscdet) {
188  const CscIdHelper* cscID = mgr()->cscIdHelper();
189  std::cerr<<"CSC readout element not found for Id = "
190  <<cscID->show_to_string(offid)<<std::endl;
191  return Amg::Vector3D::Zero();
192  }
193  return cscdet->localToGlobalTransf(offid) * m_hit->getHitStart();
194 }
195 
196 inline GeoMMHit::GeoMMHit (const MMSimHit & h) {
197  m_hit = &h;
198 }
199 
200 inline Amg::Vector3D GeoMMHit::getGlobalPosition() const {
201 
202  HitID hitid = m_hit->MMId();
203  const MmIdHelper* mmID = mgr()->mmIdHelper();
204  MM_SimIdToOfflineId simToOffline(mmID);
205  Identifier offid = simToOffline.convert(hitid);
206 
207  if (offid == 0)
208  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
209 
210 
211  const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
212  if (!mmdet) {
213  const MmIdHelper* mmID = mgr()->mmIdHelper();
214  std::cerr<<"MM readout element not found for Id = "
215  <<mmID->show_to_string(offid)<<std::endl;
216  return Amg::Vector3D::Zero();
217  }
218  return m_hit->globalPosition();
219 
220 }
221 inline Amg::Vector3D GeoMMHit::getTrkGlobalPosition() const {
222 
223  HitID hitid = m_hit->MMId();
224  const MmIdHelper* mmID = mgr()->mmIdHelper();
225  MM_SimIdToOfflineId simToOffline(mmID);
226  Identifier offid = simToOffline.convert(hitid);
227 
228  if (offid == 0)
229  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
230 
231 
232  const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
233  if (!mmdet) {
234  const MmIdHelper* mmID = mgr()->mmIdHelper();
235  std::cerr<<"MM readout element not found for Id = "
236  <<mmID->show_to_string(offid)<<std::endl;
237  return Amg::Vector3D::Zero();
238  }
239  return mmdet->transform(offid)*getTrkLocalPosition();
240 }
241 inline Amg::Vector3D GeoMMHit::getTrkLocalPosition() const {
242 
243 
244  HitID hitid = m_hit->MMId();
245  const MmIdHelper* mmID = mgr()->mmIdHelper();
246  MM_SimIdToOfflineId simToOffline(mmID);
247  Identifier offid = simToOffline.convert(hitid);
248 
249  if (offid == 0)
250  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
251 
252 
253  const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
254  if (!mmdet) {
255  const MmIdHelper* mmID = mgr()->mmIdHelper();
256  std::string err = "MM readout element not found for Id = " +
257  mmID->show_to_string(offid);
258  throw std::runtime_error (err);
259  }
260 
261  Amg::Transform3D gToL = mmdet->absTransform().inverse();
262  Amg::Vector3D locp = gToL*m_hit->globalPosition();
263  Amg::Vector3D localHit(0.,locp.y(),locp.z());
264  Amg::Vector3D trkLocHit= Amg::getRotateY3D(90.*CLHEP::deg)*localHit;
265  return trkLocHit;
266 }
267 
268 inline GeosTGCHit::GeosTGCHit (const sTGCSimHit & h) {
269  m_hit = &h;
270 }
271 
272 inline Amg::Vector3D GeosTGCHit::getGlobalPosition() const {
273 
274  HitID hitid = m_hit->sTGCId();
275  const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
276  sTgcSimIdToOfflineId simToOffline(stgcID);
277  Identifier offid = simToOffline.convert(hitid);
278 
279  if (offid == 0)
280  std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
281 
282 
283  const MuonGM::sTgcReadoutElement* stgcdet = mgr()->getsTgcReadoutElement(offid);
284  if (!stgcdet) {
285  const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
286  std::cerr<<"sTGC readout element not found for Id = "
287  <<stgcID->show_to_string(offid)<<std::endl;
288  return Amg::Vector3D::Zero();
289  }
290  return m_hit->globalPosition();
291 }
292