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"
51inline GeoMDTHit::GeoMDTHit (const MDTSimHit & h) {
56inline 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();
93inline GeoRPCHit::GeoRPCHit (const RPCSimHit & h):m_hit{&h} {
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);
109 m_id = rpcID->channelID(stname, steta, stphi,
110 dbr, dbz, dbp, gg, mfi, strip, m_goodHit);
112 m_goodHit = mgr()->idHelperSvc()->detElementHash(m_id) <
113 rpcID->detectorElement_hash_max();
120inline Amg::Vector3D GeoRPCHit::getGlobalPosition() const {
122 const MuonGM::RpcReadoutElement* rpcdet = mgr()->getRpcReadoutElement(m_id);
124 return rpcdet->localToGlobalTransf(m_id) * m_hit->localPosition();
126 std::cerr<<"RPC readout element not found for Id = "
127 <<mgr()->idHelperSvc()->toString(m_id)<<std::endl;
128 return Amg::Vector3D::Zero();
133inline GeoTGCHit::GeoTGCHit (const TGCSimHit & h) {
137inline Amg::Vector3D GeoTGCHit::getGlobalPosition() const {
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);
147 const TgcIdHelper* tgcID = mgr()->tgcIdHelper();
148 Identifier offid = tgcID->channelID(stname,
151 gg, isstrip, channel);
153 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
155 const MuonGM::TgcReadoutElement* tgcdet = mgr()->getTgcReadoutElement(offid);
157 return tgcdet->localToGlobalTransf(offid) * m_hit->localPosition();
159 std::cerr<<"TGC readout element not found for Id = "
160 <<tgcID->show_to_string(offid)<<std::endl;
161 return Amg::Vector3D::Zero();
164inline GeoCSCHit::GeoCSCHit (const CSCSimHit & h) {
168inline Amg::Vector3D GeoCSCHit::getGlobalPosition() const {
170 HitID hitid = m_hit->CSCid();
171 const CscHitIdHelper* cschhelper = CscHitIdHelper::GetHelper();
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);
181 const CscIdHelper* cscID = mgr()->cscIdHelper();
182 Identifier offid = cscID->channelID(stname,
184 stphi,ml,wl,measphi,channel);
187 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
190 const MuonGM::CscReadoutElement* cscdet = mgr()->getCscReadoutElement(offid);
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();
197 return cscdet->localToGlobalTransf(offid) * m_hit->getHitStart();
200inline GeoMMHit::GeoMMHit (const MMSimHit & h) {
204inline Amg::Vector3D GeoMMHit::getGlobalPosition() const {
206 HitID hitid = m_hit->MMId();
207 const MmIdHelper* mmID = mgr()->mmIdHelper();
208 MM_SimIdToOfflineId simToOffline(mmID);
209 Identifier offid = simToOffline.convert(hitid);
212 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
215 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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();
222 return m_hit->globalPosition();
225inline Amg::Vector3D GeoMMHit::getTrkGlobalPosition() const {
227 HitID hitid = m_hit->MMId();
228 const MmIdHelper* mmID = mgr()->mmIdHelper();
229 MM_SimIdToOfflineId simToOffline(mmID);
230 Identifier offid = simToOffline.convert(hitid);
233 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
236 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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();
243 return mmdet->transform(offid)*getTrkLocalPosition();
245inline Amg::Vector3D GeoMMHit::getTrkLocalPosition() const {
248 HitID hitid = m_hit->MMId();
249 const MmIdHelper* mmID = mgr()->mmIdHelper();
250 MM_SimIdToOfflineId simToOffline(mmID);
251 Identifier offid = simToOffline.convert(hitid);
254 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
257 const MuonGM::MMReadoutElement* mmdet = mgr()->getMMReadoutElement(offid);
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);
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;
272inline GeosTGCHit::GeosTGCHit (const sTGCSimHit & h) {
276inline Amg::Vector3D GeosTGCHit::getGlobalPosition() const {
278 HitID hitid = m_hit->sTGCId();
279 const sTgcIdHelper* stgcID = mgr()->stgcIdHelper();
280 sTgcSimIdToOfflineId simToOffline(stgcID);
281 Identifier offid = simToOffline.convert(hitid);
284 std::cerr<<" Cannot build a valid Identifier; skip "<<std::endl;
287 const MuonGM::sTgcReadoutElement* stgcdet = mgr()->getsTgcReadoutElement(offid);
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();
294 return m_hit->globalPosition();