2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONREADOUTGEOMETRYR4_RPCREADOUTELEMENT_ICC
5 #define MUONREADOUTGEOMETRYR4_RPCREADOUTELEMENT_ICC
9 template <> inline Amg::Transform3D
10 TransformCacheDetEle<MuonGMR4::RpcReadoutElement>::fetchTransform(const DetectorAlignStore* store) const{
11 return m_parent->toStation(store) * m_parent->fromGapToChamOrigin(hash());
13 template <> inline Identifier
14 TransformCacheDetEle<MuonGMR4::RpcReadoutElement>::identify() const {
15 using RE = MuonGMR4::RpcReadoutElement;
16 return m_parent->measurementId(RE::createHash(1,
17 RE::gasGapNumber(hash()) +1,
18 RE::doubletPhiNumber(hash()) + 1,
19 RE::measuresPhi(hash())));
24 namespace RpcIdMeasHashFields{
25 constexpr unsigned int minOne = -1;
26 /// Bitwise layout of the measurement hash
27 /// ( strip | meashPhi | doubletPhi [1-2]| gasGap [1-3])
29 constexpr unsigned int gasGapShift = 0;
30 /// @brief gasGap ranges from 1-3 -> 2 bits
31 constexpr unsigned int doubletPhiShift = 2;
32 /// @brief doubletPhi ranges from 1-2 -> 1 bit
33 constexpr unsigned int measPhiShift = doubletPhiShift + 1;
34 /// @brief measPhi is one bit
35 constexpr unsigned int channelShift = measPhiShift + 1;
37 inline double RpcReadoutElement::thickness() const { return 2.* m_pars.halfThickness; }
38 inline double RpcReadoutElement::gasGapPitch() const {return m_gasThickness; }
39 inline int RpcReadoutElement::doubletZ() const{ return m_doubletZ; }
40 inline int RpcReadoutElement::doubletR() const{ return m_doubletR; }
41 inline int RpcReadoutElement::doubletPhi() const{ return m_doubletPhi; }
42 inline unsigned int RpcReadoutElement::nGasGaps() const { return m_pars.nGasGaps; }
43 inline int RpcReadoutElement::nPhiPanels() const { return m_pars.nPanelsInPhi; }
44 inline int RpcReadoutElement::doubletPhiMax() const {return std::max(nPhiPanels(), doubletPhi()); }
45 inline unsigned int RpcReadoutElement::nEtaStrips() const { return (m_pars.etaDesign ? m_pars.etaDesign->numStrips(): 0u); }
46 inline unsigned int RpcReadoutElement::nPhiStrips() const { return (m_pars.phiDesign ? m_pars.phiDesign->numStrips(): 0u); }
47 inline unsigned int RpcReadoutElement::nStrips(const IdentifierHash& hash) const { return measuresPhi(hash) ? nPhiStrips() : nEtaStrips(); }
48 inline double RpcReadoutElement::stripEtaPitch() const { return (m_pars.etaDesign ? m_pars.etaDesign->stripPitch() : 0.); }
49 inline double RpcReadoutElement::stripPhiPitch() const { return (m_pars.phiDesign ? m_pars.phiDesign->stripPitch() : 0.); }
50 inline double RpcReadoutElement::stripEtaWidth() const { return (m_pars.etaDesign ? m_pars.etaDesign->stripWidth() : 0.); }
51 inline double RpcReadoutElement::stripPhiWidth() const { return (m_pars.phiDesign ? m_pars.phiDesign->stripWidth() : 0.); }
52 inline double RpcReadoutElement::stripEtaLength() const { return (m_pars.etaDesign ? m_pars.etaDesign->longHalfHeight()*2. : 0.);}
53 inline double RpcReadoutElement::stripPhiLength() const { return (m_pars.phiDesign ? m_pars.phiDesign->longHalfHeight()*2. : 0.);}
54 inline IdentifierHash RpcReadoutElement::measurementHash(const Identifier& measId) const {
55 if (m_idHelper.doubletZ(measId) != doubletZ() ||
56 (doubletPhi() != 1 && m_idHelper.doubletPhi(measId) == 1) ||
57 m_idHelper.elementID(measId) != m_idHelper.elementID(identify()) ) {
58 ATH_MSG_WARNING("The measurement " << idHelperSvc()->toString(measId)
59 << " picks the wrong readout element " << idHelperSvc()->toStringDetEl(identify()));
61 return createHash(m_idHelper.strip(measId),
62 m_idHelper.gasGap(measId),
63 m_idHelper.doubletPhi(measId),
64 m_idHelper.measuresPhi(measId));
66 inline IdentifierHash RpcReadoutElement::layerHash(const Identifier& measId) const {
67 if (m_idHelper.doubletZ(measId) != doubletZ() ||
68 (doubletPhi() != 1 && m_idHelper.doubletPhi(measId) == 1) ||
69 m_idHelper.elementID(measId) != m_idHelper.elementID(identify()) ) {
70 ATH_MSG_WARNING("The measurement " << idHelperSvc()->toString(measId)
71 << " picks the wrong readout element " << idHelperSvc()->toStringDetEl(identify()));
73 return createHash(0, m_idHelper.gasGap(measId),
74 m_idHelper.doubletPhi(measId),
75 m_idHelper.measuresPhi(measId));
77 inline IdentifierHash RpcReadoutElement::layerHash(const IdentifierHash& measHash) const {
78 using namespace RpcIdMeasHashFields;
79 constexpr unsigned int mask = minOne << channelShift;
80 return IdentifierHash{static_cast<unsigned int>(measHash) & (~mask)};
82 inline IdentifierHash RpcReadoutElement::createHash(const unsigned int strip,
83 const unsigned int gasGap,
84 const unsigned int doubPhi,
86 using namespace RpcIdMeasHashFields;
87 const IdentifierHash hash{ strip << channelShift | measPhi << measPhiShift |
88 (doubPhi -1) << doubletPhiShift | (gasGap -1) << gasGapShift };
91 inline unsigned int RpcReadoutElement::stripNumber(const IdentifierHash& measHash) {
92 using namespace RpcIdMeasHashFields;
93 return static_cast<unsigned int>(measHash) >> channelShift;
95 inline unsigned int RpcReadoutElement::gasGapNumber(const IdentifierHash& measHash) {
96 using namespace RpcIdMeasHashFields;
97 constexpr unsigned int mask = minOne << doubletPhiShift;
98 const unsigned int stripedHash = (~mask) & static_cast<unsigned int>(measHash);
99 return ( stripedHash >> gasGapShift);
101 inline unsigned int RpcReadoutElement::doubletPhiNumber(const IdentifierHash& measHash) {
102 using namespace RpcIdMeasHashFields;
103 constexpr unsigned int mask = minOne << measPhiShift;
104 const unsigned int stripedMask = (~mask) & static_cast<unsigned int>(measHash);
105 return (stripedMask >> doubletPhiShift);
107 inline bool RpcReadoutElement::measuresPhi(const IdentifierHash& measHash) {
108 using namespace RpcIdMeasHashFields;
109 constexpr unsigned int mask = minOne << channelShift;
110 const unsigned int stripedMask = (~mask) & static_cast<unsigned int>(measHash);
111 return (stripedMask >> measPhiShift);
113 inline const StripLayer& RpcReadoutElement::sensorLayout(const IdentifierHash& measHash) const {
114 const unsigned int layIdx{static_cast<unsigned int>(layerHash(measHash))};
115 if (layIdx >= m_pars.layers.size() || !m_pars.layers[layIdx]) {
116 ATH_MSG_FATAL("The sensorLayout does not exist for "<<idHelperSvc()->toStringDetEl(identify())
117 <<" gasGap "<<(gasGapNumber(measHash) +1)
118 <<" doubletPhi: "<<(doubletPhiNumber(measHash) + 1)
119 <<" isPhiChannel: "<<measuresPhi(measHash)
120 <<" strip: "<<stripNumber(measHash) );
121 throw std::runtime_error("Invalid sensor layout");
123 return (*m_pars.layers[layIdx]);
126 inline Identifier RpcReadoutElement::measurementId(const IdentifierHash& measHash) const {
127 return m_idHelper.channelID(identify(), doubletZ(), doubletPhiNumber(measHash) + 1,
128 gasGapNumber(measHash) + 1, measuresPhi(measHash), stripNumber(measHash));
131 inline Amg::Vector3D RpcReadoutElement::stripPosition(const ActsGeometryContext& ctx, const Identifier& measId) const {
132 return stripPosition(ctx, measurementHash(measId));
134 inline Amg::Vector3D RpcReadoutElement::rightStripEdge(const ActsGeometryContext& ctx, const Identifier& measId) const{
135 return rightStripEdge(ctx, measurementHash(measId));
137 inline Amg::Vector3D RpcReadoutElement::leftStripEdge(const ActsGeometryContext& ctx, const Identifier& measId) const{
138 return leftStripEdge(ctx, measurementHash(measId));
140 } // namespace MuonGMR4