2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONREADOUTGEOMETRYR4_STGCREADOUTELEMENT_ICC
5 #define MUONREADOUTGEOMETRYR4_STGCREADOUTELEMENT_ICC
9 template <> inline Amg::Transform3D
10 TransformCacheDetEle<MuonGMR4::sTgcReadoutElement>::fetchTransform(const DetectorAlignStore* store) const{
11 return m_parent->toStation(store) * m_parent->fromGapToChamOrigin(hash());
13 template <> inline Identifier
14 TransformCacheDetEle<MuonGMR4::sTgcReadoutElement>::identify() const {
15 using RE = MuonGMR4::sTgcReadoutElement;
16 return m_parent->measurementId(RE::createHash(RE::gasGapNumber(hash()) + 1,
17 RE::chType(hash()), 1));
23 namespace sTgcIdMeasHashFields {
24 constexpr unsigned int minusOne = -1;
26 //// (wireInGrp) | (channel) [1-512] | IsWireInGrp (0,1) | (sTgcChannelType) [0-2] | (gasGap -1) [1-4]
27 constexpr unsigned int gasGapShift = 0;
28 constexpr unsigned int chTypeShift = 2;
29 constexpr unsigned int wireInGrpBit = chTypeShift+ 2;
30 constexpr unsigned int chanShift = chTypeShift + 3;
31 constexpr unsigned int wireInGrpShift = chanShift + 9;
34 inline double sTgcReadoutElement::chamberHeight() const { return 2.* m_pars.halfChamberHeight; }
35 inline double sTgcReadoutElement::sChamberLength() const { return 2.* m_pars.sHalfChamberLength; }
36 inline double sTgcReadoutElement::lChamberLength() const { return 2.* m_pars.lHalfChamberLength; }
37 inline double sTgcReadoutElement::thickness() const { return 2.* m_pars.halfChamberTck; }
38 inline double sTgcReadoutElement::sFrameWidth() const { return m_pars.sFrameWidth; }
39 inline double sTgcReadoutElement::lFrameWidth() const { return m_pars.lFrameWidth; }
40 inline int sTgcReadoutElement::multilayer() const { return m_multiLayer; }
42 inline unsigned int sTgcReadoutElement::numLayers() const { return m_pars.numLayers; }
43 inline unsigned int sTgcReadoutElement::nChTypes() const { return m_pars.nChTypes; }
44 inline double sTgcReadoutElement::gasGapThickness() const { return m_pars.gasTck; }
45 inline double sTgcReadoutElement::gasGapPitch() const { return m_gasGapPitch; }
47 inline double sTgcReadoutElement::firstStripPitch(const IdentifierHash& measHash) const { return m_pars.firstStripPitch[gasGapNumber(measHash)]; }
48 inline double sTgcReadoutElement::firstStripPitch(const Identifier& measId) const { return firstStripPitch(measurementHash(measId)); }
50 inline double sTgcReadoutElement::sGapLength(const Identifier& measId) const { return 2*stripDesign(measId).shortHalfHeight(); }
51 inline double sTgcReadoutElement::sGapLength(const IdentifierHash& measHash) const { return 2*stripDesign(measHash).shortHalfHeight(); }
52 inline double sTgcReadoutElement::lGapLength(const Identifier& measId) const { return 2*stripDesign(measId).longHalfHeight(); }
53 inline double sTgcReadoutElement::lGapLength(const IdentifierHash& measHash) const { return 2*stripDesign(measHash).longHalfHeight(); }
54 inline double sTgcReadoutElement::sPadLength(const Identifier& measId) const { return 2*padDesign(measId).shortHalfHeight(); }
55 inline double sTgcReadoutElement::sPadLength(const IdentifierHash& measHash) const { return 2*padDesign(measHash).shortHalfHeight(); }
56 inline double sTgcReadoutElement::lPadLength(const Identifier& measId) const { return 2*padDesign(measId).longHalfHeight(); }
57 inline double sTgcReadoutElement::lPadLength(const IdentifierHash& measHash) const { return 2*padDesign(measHash).longHalfHeight(); }
58 inline double sTgcReadoutElement::gapHeight(const Identifier& measId) const { return 2*stripDesign(measId).halfWidth(); }
59 inline double sTgcReadoutElement::gapHeight(const IdentifierHash& measHash) const { return 2*stripDesign(measHash).halfWidth(); }
60 inline double sTgcReadoutElement::yCutout(const Identifier& measId) const { return stripDesign(measId).yCutout(); }
61 inline double sTgcReadoutElement::yCutout(const IdentifierHash& measHash) const { return stripDesign(measHash).yCutout(); }
63 inline unsigned int sTgcReadoutElement::numStrips(const Identifier& measId) const { return stripDesign(measId).numStrips(); }
64 inline unsigned int sTgcReadoutElement::numStrips(const IdentifierHash& measHash) const { return stripDesign(measHash).numStrips(); }
65 inline double sTgcReadoutElement::stripPitch(const Identifier& measId) const { return stripDesign(measId).stripPitch(); }
66 inline double sTgcReadoutElement::stripPitch(const IdentifierHash& measHash) const { return stripDesign(measHash).stripPitch(); }
67 inline double sTgcReadoutElement::stripWidth(const Identifier& measId) const { return stripDesign(measId).stripWidth(); }
68 inline double sTgcReadoutElement::stripWidth(const IdentifierHash& measHash) const { return stripDesign(measHash).stripWidth(); }
69 inline double sTgcReadoutElement::stripLength(const Identifier& measId) const { unsigned int channel = m_idHelper.channel(measId);
70 return stripDesign(measId).stripLength(channel); }
71 inline double sTgcReadoutElement::stripLength(const IdentifierHash& measHash) const { unsigned int channel = m_idHelper.channel(measurementId(measHash));
72 return stripDesign(measHash).stripLength(channel); }
74 inline double sTgcReadoutElement::wirePitch(const Identifier& measId) const { return wireDesign(measId).stripPitch(); }
75 inline double sTgcReadoutElement::wirePitch(const IdentifierHash& measHash) const { return wireDesign(measHash).stripPitch(); }
76 inline double sTgcReadoutElement::wireWidth(const Identifier& measId) const { return wireDesign(measId).stripWidth(); }
77 inline double sTgcReadoutElement::wireWidth(const IdentifierHash& measHash) const { return wireDesign(measHash).stripWidth(); }
78 inline unsigned int sTgcReadoutElement::wireGroupWidth(unsigned int gasGap) const { return wireDesign(gasGap).numWiresInGroup(2); }
79 inline unsigned int sTgcReadoutElement::numWires(unsigned int gasGap) const {return wireDesign(gasGap).nAllWires();}
80 inline unsigned int sTgcReadoutElement::numWireGroups(unsigned int gasGap) const { return wireDesign(gasGap).numStrips();}
81 inline unsigned int sTgcReadoutElement::firstWireGroupWidth(unsigned int gasGap) const { return wireDesign(gasGap).numWiresInGroup(1); }
82 inline double sTgcReadoutElement::wireCutout(unsigned int gasGap) const { return wireDesign(gasGap).wireCutout(); }
84 inline unsigned int sTgcReadoutElement::numPads(const Identifier& measId) const { return padDesign(measId).numPads(); }
85 inline unsigned int sTgcReadoutElement::numPads(const IdentifierHash& measHash) const { return padDesign(measHash).numPads(); }
86 inline unsigned int sTgcReadoutElement::numPadEta(const Identifier& measId) const { return padDesign(measId).numPadEta(); }
87 inline unsigned int sTgcReadoutElement::numPadEta(const IdentifierHash& measHash) const { return padDesign(measHash).numPadEta(); }
88 inline unsigned int sTgcReadoutElement::numPadPhi(const Identifier& measId) const { return padDesign(measId).numPadPhi(); }
89 inline unsigned int sTgcReadoutElement::numPadPhi(const IdentifierHash& measHash) const { return padDesign(measHash).numPadPhi(); }
90 inline double sTgcReadoutElement::firstPadHeight(const Identifier& measId) const { return padDesign(measId).firstPadHeight(); }
91 inline double sTgcReadoutElement::firstPadHeight(const IdentifierHash& measHash) const { return padDesign(measHash).firstPadHeight(); }
92 inline double sTgcReadoutElement::padHeight(const Identifier& measId) const { return padDesign(measId).padHeight(); }
93 inline double sTgcReadoutElement::padHeight(const IdentifierHash& measHash) const { return padDesign(measHash).padHeight(); }
94 inline double sTgcReadoutElement::padPhiShift(const Identifier& measId) const { return padDesign(measId).padPhiShift(); }
95 inline double sTgcReadoutElement::padPhiShift(const IdentifierHash& measHash) const { return padDesign(measHash).padPhiShift(); }
96 inline double sTgcReadoutElement::firstPadPhiDiv(const Identifier& measId) const { return padDesign(measId).firstPadPhiDiv(); }
97 inline double sTgcReadoutElement::firstPadPhiDiv(const IdentifierHash& measHash) const { return padDesign(measHash).firstPadPhiDiv(); }
98 inline double sTgcReadoutElement::anglePadPhi(const Identifier& measId) const { return padDesign(measId).anglePadPhi(); }
99 inline double sTgcReadoutElement::anglePadPhi(const IdentifierHash& measHash) const { return padDesign(measHash).anglePadPhi(); }
100 inline unsigned int sTgcReadoutElement::maxPadEta(const Identifier& measId) const { return padDesign(measId).anglePadPhi(); }
101 inline unsigned int sTgcReadoutElement::maxPadEta(const IdentifierHash& measHash) const { return padDesign(measHash).anglePadPhi(); }
102 inline unsigned int sTgcReadoutElement::padNumber(const Identifier& measId) const { return padNumber(measurementHash(measId)); }
103 inline unsigned int sTgcReadoutElement::padNumber(const IdentifierHash& measHash) const { return padDesign(measHash).padNumber(channelNumber(measHash)); }
104 inline std::pair<uint, uint> sTgcReadoutElement::padEtaPhi(const Identifier& measId) const { return padEtaPhi(measurementHash(measId)); }
105 inline std::pair<uint, uint> sTgcReadoutElement::padEtaPhi(const IdentifierHash& measHash) const { return padDesign(measHash).padEtaPhi(channelNumber(measHash)); }
106 inline unsigned int sTgcReadoutElement::padEta(const Identifier& measId) const { return padEta(measurementHash(measId)); }
107 inline unsigned int sTgcReadoutElement::padEta(const IdentifierHash& measHash) const { return padDesign(measHash).padEta(channelNumber(measHash)); }
108 inline unsigned int sTgcReadoutElement::padPhi(const Identifier& measId) const { return padPhi(measurementHash(measId)); }
109 inline unsigned int sTgcReadoutElement::padPhi(const IdentifierHash& measHash) const { return padDesign(measHash).padPhi(channelNumber(measHash)); }
110 inline double sTgcReadoutElement::beamlineRadius(const Identifier& measId) const { return padDesign(measId).beamlineRadius(); }
111 inline double sTgcReadoutElement::beamlineRadius(const IdentifierHash& measHash) const { return padDesign(measHash).beamlineRadius(); }
112 using localCornerArray = std::array<Amg::Vector2D, 4>;
113 inline localCornerArray sTgcReadoutElement::localPadCorners(const Identifier& measId) const { return localPadCorners(measurementHash(measId)); }
114 inline localCornerArray sTgcReadoutElement::localPadCorners(const IdentifierHash& measHash) const { return padDesign(measHash).padCorners(channelNumber(measHash)); }
115 using globalCornerArray = std::array<Amg::Vector3D, 4>;
116 inline globalCornerArray sTgcReadoutElement::globalPadCorners(const ActsGeometryContext& ctx, const Identifier& measId) const {
117 return globalPadCorners(ctx, measurementHash(measId));
120 inline const StripDesign& sTgcReadoutElement::stripDesign(const Identifier& measId) const {
121 unsigned int gasGap = m_idHelper.gasGap(measId);
122 return m_pars.stripLayers[gasGap-1].design();
124 inline const StripDesign& sTgcReadoutElement::stripDesign(const IdentifierHash& measHash) const {
125 return stripDesign(measurementId(measHash));
127 inline const StripDesign& sTgcReadoutElement::stripDesign(unsigned int gasGap) const {
128 return m_pars.stripLayers[gasGap-1].design();
131 inline const WireGroupDesign& sTgcReadoutElement::wireDesign(const Identifier& measId) const {
132 unsigned int gasGap = m_idHelper.gasGap(measId);
133 return static_cast<const WireGroupDesign&>(m_pars.wireGroupLayers[gasGap-1].design());
135 inline const WireGroupDesign& sTgcReadoutElement::wireDesign(const IdentifierHash& measHash) const {
136 return wireDesign(measurementId(measHash));
138 inline const WireGroupDesign& sTgcReadoutElement::wireDesign(unsigned int gasGap) const {
139 return static_cast<const WireGroupDesign&>(m_pars.wireGroupLayers[gasGap-1].design());
142 inline const PadDesign& sTgcReadoutElement::padDesign(const Identifier& measId) const {
143 unsigned int gasGap = m_idHelper.gasGap(measId);
144 return static_cast<const PadDesign&>(m_pars.padLayers[gasGap-1].design());
146 inline const PadDesign& sTgcReadoutElement::padDesign(const IdentifierHash& measHash) const {
147 return padDesign(measurementId(measHash));
149 inline const PadDesign& sTgcReadoutElement::padDesign(unsigned int gasGap) const {
150 return static_cast<const PadDesign&>(m_pars.padLayers[gasGap-1].design());
153 inline IdentifierHash sTgcReadoutElement::measurementHash(const Identifier& measId) const {
154 if (idHelperSvc()->detElId(measId) != identify()) {
155 ATH_MSG_WARNING("The measurement " << idHelperSvc()->toString(measId)
156 << " picks the wrong readout element " << idHelperSvc()->toStringDetEl(identify()));
158 return createHash(m_idHelper.gasGap(measId),
159 m_idHelper.channelType(measId),
160 m_idHelper.channel(measId));
162 inline IdentifierHash sTgcReadoutElement::createHash(const unsigned int gasGap,
163 const unsigned int channelType,
164 const unsigned int channel,
165 const unsigned int wireInGrp) {
166 using namespace sTgcIdMeasHashFields;
167 /// Construct the Hash such that (channel) | WireInGrpBit (0,1) | (channelType) | (gasGap -1)
168 if (channelType == ReadoutChannelType::WireInGrp) {
169 const unsigned int readOutHash = static_cast<unsigned int>(createHash(gasGap, ReadoutChannelType::Wire, channel));
170 return IdentifierHash {wireInGrp << wireInGrpShift | (1<<wireInGrpBit) | readOutHash};
172 return IdentifierHash{ channel << chanShift | channelType << chTypeShift | (gasGap -1) };
175 inline IdentifierHash sTgcReadoutElement::layerHash(const IdentifierHash& measHash) {
176 using namespace sTgcIdMeasHashFields;
177 constexpr unsigned int mask = (minusOne << chanShift) | (1<<wireInGrpBit);
178 return IdentifierHash{static_cast<unsigned int>(measHash) & (~mask)};
181 inline unsigned int sTgcReadoutElement::channelNumber(const IdentifierHash& measHash) {
182 using namespace sTgcIdMeasHashFields;
183 constexpr unsigned int mask = (minusOne << wireInGrpShift);
184 const unsigned int stripedHash = (~mask) & static_cast<unsigned int>(measHash);
185 return stripedHash >> chanShift;
187 inline unsigned int sTgcReadoutElement::chType(const IdentifierHash& measHash) {
188 using namespace sTgcIdMeasHashFields;
189 constexpr unsigned int mask = (minusOne << chanShift);
190 const unsigned int stripedHash = (~mask) & static_cast<unsigned int>(measHash);
191 return stripedHash >> chTypeShift;
194 inline unsigned int sTgcReadoutElement::gasGapNumber(const IdentifierHash& measHash) {
195 using namespace sTgcIdMeasHashFields;
196 constexpr unsigned int mask = (minusOne << chTypeShift);
197 return (static_cast<unsigned int>(measHash) &(~mask) );
199 inline Identifier sTgcReadoutElement::measurementId(const IdentifierHash& measHash) const {
200 return m_idHelper.channelID(identify(), multilayer(), gasGapNumber(measHash) + 1, chType(measHash), channelNumber(measHash));
202 inline IdentifierHash sTgcReadoutElement::layerHash(const Identifier& measId) const {
203 if (m_idHelper.elementID(measId) != m_idHelper.elementID(identify()) ) {
204 ATH_MSG_WARNING("The measurement " << idHelperSvc()->toString(measId)
205 << " picks the wrong readout element " << idHelperSvc()->toStringDetEl(identify()));
207 return createHash(m_idHelper.gasGap(measId), m_idHelper.channelType(measId), 0);
210 inline Amg::Vector2D sTgcReadoutElement::localChannelPosition(const Identifier& measId) const {
211 return localChannelPosition(measurementHash(measId)); }
213 inline Amg::Vector3D sTgcReadoutElement::globalChannelPosition(const ActsGeometryContext& ctx, const Identifier& measId) const {
214 return globalChannelPosition(ctx, measurementHash(measId));
217 inline const StripLayer& sTgcReadoutElement::stripLayer(const IdentifierHash& measHash) const {
218 unsigned int gasGap = gasGapNumber(measHash);
219 return m_pars.stripLayers[gasGap];
221 inline const StripLayer& sTgcReadoutElement::stripLayer(const Identifier& measId) const {
222 return stripLayer(measurementHash(measId));
224 inline int sTgcReadoutElement::padNumber(const Amg::Vector2D& hitPos, const Identifier& measId) const {
225 return padNumber(hitPos, measurementHash(measId));
228 } // namespace MuonGMR4