2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
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"
13 #include "MuonSimEvent/MDTSimHitCollection.h"
14 #include "MuonSimEvent/MDTSimHit.h"
15 #include "MuonSimEvent/MdtHitIdHelper.h"
16 #include "MuonReadoutGeometry/MdtReadoutElement.h"
18 #include "MuonPrepRawData/MdtPrepDataContainer.h"
19 #include "MuonPrepRawData/RpcPrepDataContainer.h"
20 #include "MuonPrepRawData/TgcPrepDataContainer.h"
21 #include "MuonPrepRawData/CscPrepDataContainer.h"
23 #include "MuonSimEvent/RPCSimHitCollection.h"
24 #include "MuonSimEvent/RPCSimHit.h"
25 #include "MuonSimEvent/RpcHitIdHelper.h"
26 #include "MuonReadoutGeometry/RpcReadoutElement.h"
28 #include "MuonSimEvent/TGCSimHitCollection.h"
29 #include "MuonSimEvent/TGCSimHit.h"
30 #include "MuonSimEvent/TgcHitIdHelper.h"
31 #include "MuonReadoutGeometry/TgcReadoutElement.h"
33 #include "MuonSimEvent/CSCSimHitCollection.h"
34 #include "MuonSimEvent/CSCSimHit.h"
35 #include "MuonSimEvent/CscHitIdHelper.h"
36 #include "MuonReadoutGeometry/CscReadoutElement.h"
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"
51 inline GeoMDTHit::GeoMDTHit (const MDTSimHit & h) {
56 inline Amg::Vector3D GeoMDTHit::getGlobalPosition() const {
60 HitID hitid = m_hit->MDTid();
61 const MdtIdHelper* mdtID = mgr()->mdtIdHelper();
62 const MdtHitIdHelper* mdthhelper = MdtHitIdHelper::GetHelper(mdtID->tubeMax());
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);
71 Identifier offid = mdtID->channelID(stname,
76 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
79 const MuonGM::MdtReadoutElement* mdtdet = mgr()->getMdtReadoutElement(offid);
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();
87 // -------- Testing Sim to Offline ID conversion ---------
89 return mdtdet->localToGlobalTransf(offid) * m_hit->localPosition();
93 inline GeoRPCHit::GeoRPCHit (const RPCSimHit & h) {
97 inline Amg::Vector3D GeoRPCHit::getGlobalPosition() const {
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);
111 Identifier offid = rpcID->channelID(stname,
114 dbr, dbz, dbp, gg, mfi, strip);
116 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
118 const MuonGM::RpcReadoutElement* rpcdet = mgr()->getRpcReadoutElement(offid);
120 return rpcdet->localToGlobalTransf(offid) * m_hit->localPosition();
122 std::cerr<<"RPC readout element not found for Id = "
123 <<rpcID->show_to_string(offid)<<std::endl;
124 return Amg::Vector3D::Zero();
129 inline GeoTGCHit::GeoTGCHit (const TGCSimHit & h) {
133 inline Amg::Vector3D GeoTGCHit::getGlobalPosition() const {
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);
143 const TgcIdHelper* tgcID = mgr()->tgcIdHelper();
144 Identifier offid = tgcID->channelID(stname,
147 gg, isstrip, channel);
149 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
151 const MuonGM::TgcReadoutElement* tgcdet = mgr()->getTgcReadoutElement(offid);
153 return tgcdet->localToGlobalTransf(offid) * m_hit->localPosition();
155 std::cerr<<"TGC readout element not found for Id = "
156 <<tgcID->show_to_string(offid)<<std::endl;
157 return Amg::Vector3D::Zero();
160 inline GeoCSCHit::GeoCSCHit (const CSCSimHit & h) {
164 inline Amg::Vector3D GeoCSCHit::getGlobalPosition() const {
166 HitID hitid = m_hit->CSCid();
167 const CscHitIdHelper* cschhelper = CscHitIdHelper::GetHelper();
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);
177 const CscIdHelper* cscID = mgr()->cscIdHelper();
178 Identifier offid = cscID->channelID(stname,
180 stphi,ml,wl,measphi,channel);
183 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
186 const MuonGM::CscReadoutElement* cscdet = mgr()->getCscReadoutElement(offid);
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();
193 return cscdet->localToGlobalTransf(offid) * m_hit->getHitStart();
196 inline GeoMMHit::GeoMMHit (const MMSimHit & h) {
200 inline Amg::Vector3D GeoMMHit::getGlobalPosition() const {
202 HitID hitid = m_hit->MMId();
203 const MmIdHelper* mmID = mgr()->mmIdHelper();
204 MM_SimIdToOfflineId simToOffline(mmID);
205 Identifier offid = simToOffline.convert(hitid);
208 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
211 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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();
218 return m_hit->globalPosition();
221 inline Amg::Vector3D GeoMMHit::getTrkGlobalPosition() const {
223 HitID hitid = m_hit->MMId();
224 const MmIdHelper* mmID = mgr()->mmIdHelper();
225 MM_SimIdToOfflineId simToOffline(mmID);
226 Identifier offid = simToOffline.convert(hitid);
229 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
232 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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();
239 return mmdet->transform(offid)*getTrkLocalPosition();
241 inline Amg::Vector3D GeoMMHit::getTrkLocalPosition() const {
244 HitID hitid = m_hit->MMId();
245 const MmIdHelper* mmID = mgr()->mmIdHelper();
246 MM_SimIdToOfflineId simToOffline(mmID);
247 Identifier offid = simToOffline.convert(hitid);
250 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
253 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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);
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;
268 inline GeosTGCHit::GeosTGCHit (const sTGCSimHit & h) {
272 inline Amg::Vector3D GeosTGCHit::getGlobalPosition() const {
274 HitID hitid = m_hit->sTGCId();
275 const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
276 sTgcSimIdToOfflineId simToOffline(stgcID);
277 Identifier offid = simToOffline.convert(hitid);
280 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
283 const MuonGM::sTgcReadoutElement* stgcdet = mgr()->getsTgcReadoutElement(offid);
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();
290 return m_hit->globalPosition();