ATLAS Offline Software
Loading...
Searching...
No Matches
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/GeoModelsTgcTest.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4*/
5#include "GeoModelsTgcTest.h"
9#include <fstream>
10
11using namespace ActsTrk;
12namespace MuonGMR4{
13
15 ATH_CHECK(m_idHelperSvc.retrieve());
16 ATH_CHECK(m_geoCtxKey.initialize());
18 ATH_CHECK(m_tree.init(this));
19
20 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
21 auto translateTokenList = [this, &idHelper](const std::vector<std::string>& chNames){
22
23 std::set<Identifier> transcriptedIds{};
24 for (const std::string& token : chNames) {
25 if (token.size() != 6) {
26 ATH_MSG_WARNING("Wrong format given for "<<token<<". Expecting 6 characters");
27 continue;
28 }
30 const std::string statName = token.substr(0, 3);
31 const unsigned statEta = std::atoi(token.substr(3, 1).c_str()) * (token[4] == 'A' ? 1 : -1);
32 const unsigned statPhi = std::atoi(token.substr(5, 1).c_str());
33 bool isValid{false};
34 const Identifier eleId = idHelper.elementID(statName, statEta, statPhi, isValid);
35 if (!isValid) {
36 ATH_MSG_WARNING("Failed to deduce a station name for " << token);
37 continue;
38 }
39 transcriptedIds.insert(eleId);
40 const Identifier secMlId = idHelper.multilayerID(eleId, 2, isValid);
41 if (isValid){
42 transcriptedIds.insert(secMlId);
43 }
44 }
45 return transcriptedIds;
46 };
47
48 std::vector <std::string>& selectedSt = m_selectStat.value();
49 const std::vector <std::string>& excludedSt = m_excludeStat.value();
50 selectedSt.erase(std::remove_if(selectedSt.begin(), selectedSt.end(),
51 [&excludedSt](const std::string& token){
52 return std::ranges::find(excludedSt, token) != excludedSt.end();
53 }), selectedSt.end());
54
55 if (selectedSt.size()) {
56 m_testStations = translateTokenList(selectedSt);
57 std::stringstream sstr{};
58 for (const Identifier& id : m_testStations) {
59 sstr<<" *** "<<m_idHelperSvc->toString(id)<<std::endl;
60 }
61 ATH_MSG_INFO("Test only the following stations "<<std::endl<<sstr.str());
62 } else {
63 const std::set<Identifier> excluded = translateTokenList(excludedSt);
65 for(auto itr = idHelper.detectorElement_begin();
66 itr!= idHelper.detectorElement_end();++itr){
67 if (!excluded.count(*itr)) {
68 m_testStations.insert(*itr);
69 }
70 }
72 if (!excluded.empty()) {
73 std::stringstream excluded_report{};
74 for (const Identifier& id : excluded){
75 excluded_report << " *** " << m_idHelperSvc->toStringDetEl(id) << std::endl;
76 }
77 ATH_MSG_INFO("Test all station except the following excluded ones " << std::endl << excluded_report.str());
78 }
79 }
80 ATH_CHECK(detStore()->retrieve(m_detMgr));
81 return StatusCode::SUCCESS;
82}
84 ATH_CHECK(m_tree.write());
85 return StatusCode::SUCCESS;
86}
87StatusCode GeoModelsTgcTest::execute(const EventContext& ctx) {
88
89 const ActsTrk::GeometryContext* geoContextHandle{nullptr};
90 ATH_CHECK(SG::get(geoContextHandle, m_geoCtxKey, ctx));
91 const ActsTrk::GeometryContext& gctx{*geoContextHandle};
92
93 const sTgcIdHelper& id_helper{m_idHelperSvc->stgcIdHelper()};
94 for (const Identifier& test_me : m_testStations) {
95 ATH_MSG_DEBUG("Test retrieval of sTgc detector element "<<m_idHelperSvc->toStringDetEl(test_me));
96 const sTgcReadoutElement* reElement = m_detMgr->getsTgcReadoutElement(test_me);
97 if (!reElement) {
98 continue;
99 }
101 if (id_helper.elementID(reElement->identify()) != id_helper.elementID(test_me)) {
102 ATH_MSG_FATAL("Expected to retrieve "<<m_idHelperSvc->toString(test_me)
103 <<". But got instead "<<m_idHelperSvc->toString(reElement->identify()));
104 return StatusCode::FAILURE;
105 }
106 ATH_CHECK(dumpToTree(ctx, gctx, reElement));
107 const Amg::Transform3D globToLocal{reElement->globalToLocalTransform(gctx)};
108 const Amg::Transform3D& localToGlob{reElement->localToGlobalTransform(gctx)};
110 const Amg::Transform3D transClosure = globToLocal * localToGlob;
111 for (Amg::Vector3D axis :{Amg::Vector3D::UnitX(),Amg::Vector3D::UnitY(),Amg::Vector3D::UnitZ()}) {
112 const double closure_mag = std::abs( (transClosure*axis).dot(axis) - 1.);
113 if (closure_mag > std::numeric_limits<float>::epsilon() ) {
114 ATH_MSG_FATAL("Closure test failed for "<<m_idHelperSvc->toStringDetEl(test_me)<<" and axis "<<Amg::toString(axis, 0)
115 <<". Ended up with "<< Amg::toString(transClosure*axis) );
116 return StatusCode::FAILURE;
117 }
118 }
119
120 for (unsigned int layer = 1; layer <= reElement->numLayers(); ++layer) {
124 bool isValidLay{false};
125 const Identifier layID = id_helper.channelID(reElement->identify(),
126 reElement->multilayer(),
127 layer, chType, 1, isValidLay);
128 if (!isValidLay) {
129 continue;
130 }
131 const unsigned int numChannel = reElement->numChannels(reElement->measurementHash(layID));
132
133 for (unsigned int channel = 1; channel < numChannel ; ++channel) {
134 bool isValidCh{false};
135 const Identifier chID = id_helper.channelID(reElement->identify(),
136 reElement->multilayer(),
137 layer, chType, channel, isValidCh);
138 if (!isValidCh) {
139 continue;
140 }
142 const IdentifierHash measHash = reElement->measurementHash(chID);
143 const IdentifierHash layHash = reElement->layerHash(chID);
144 ATH_MSG_VERBOSE("layer: "<<layer<<", chType: "<<chType
145 <<" --> layerHash: "<<static_cast<unsigned>(layHash));
146 const Identifier backCnv = reElement->measurementId(measHash);
147 if (backCnv != chID) {
148 ATH_MSG_FATAL("The back and forth conversion of "<<m_idHelperSvc->toString(chID)
149 <<" failed. Got "<<m_idHelperSvc->toString(backCnv));
150 return StatusCode::FAILURE;
151 }
152 if (layHash != reElement->layerHash(measHash)) {
153 ATH_MSG_FATAL("Constructing the layer hash from the identifier "<<
154 m_idHelperSvc->toString(chID)<<" leads to different layer hashes "<<
155 layHash<<" vs. "<< reElement->layerHash(measHash));
156 return StatusCode::FAILURE;
157 }
158 ATH_MSG_VERBOSE("Channel "<<m_idHelperSvc->toString(chID)<<" channel position "
159 <<Amg::toString(reElement->globalChannelPosition(gctx, measHash)));
160 }
161 }
162 }
163 }
164 return StatusCode::SUCCESS;
165}
166
167StatusCode GeoModelsTgcTest::dumpToTree(const EventContext& ctx,
168 const ActsTrk::GeometryContext& gctx,
169 const sTgcReadoutElement* reElement){
170
171 m_stIndex = reElement->stationName();
172 m_stEta = reElement->stationEta();
173 m_stPhi = reElement->stationPhi();
174 m_stML = reElement->multilayer();
175 m_chamberDesign = reElement->chamberDesign();
177 m_numLayers = reElement->numLayers();
178 m_gasTck = reElement->gasGapThickness();
180 m_sChamberLength = reElement->sChamberLength();
181 m_lChamberLength = reElement->lChamberLength();
182 m_chamberHeight = reElement->chamberHeight();
183
185 const Amg::Transform3D& transform{reElement->localToGlobalTransform(gctx)};
186 m_readoutTransform = transform;
187 m_alignableNode = reElement->alignableTransform()->getDefTransform();
188
189 const sTgcIdHelper& id_helper{m_idHelperSvc->stgcIdHelper()};
190 for (unsigned int layer = 1; layer <= reElement->numLayers(); ++layer) {
194 unsigned int numWireGroup = 0;
196 bool isValidLay{false};
197 const Identifier layID = id_helper.channelID(reElement->identify(),
198 reElement->multilayer(),
199 layer, chType, 1, isValidLay);
200 if (!isValidLay) {
201 continue;
202 }
204 const IdentifierHash layHash = reElement->measurementHash(layID);
205 m_sGapLength = 2.*reElement->stripDesign(layHash).shortHalfHeight();
206 m_lGapLength = 2.*reElement->stripDesign(layHash).longHalfHeight();
207 m_sPadLength = 2.*reElement->padDesign(layHash).shortHalfHeight();
208 m_lPadLength = 2.*reElement->padDesign(layHash).longHalfHeight();
209 m_gapHeight =2.*reElement->stripDesign(layHash).halfWidth();
210 m_yCutout = reElement->stripDesign(layHash).yCutout();
211
212 switch (chType) {
214 m_numPads.push_back(reElement->numChannels(layHash));
215 m_numPadEta.push_back(reElement->numPadEta(layHash));
216 m_numPadPhi.push_back(reElement->numPadPhi(layHash));
217 m_padPhiShift.push_back(reElement->padPhiShift(layHash));
218 m_firstPadPhiDiv.push_back(reElement->padDesign(layHash).firstPadPhiDiv());
219 m_anglePadPhi = reElement->anglePadPhi(layHash);
220 m_beamlineRadius = reElement->beamlineRadius(layHash);
221
222 for (unsigned int phiIndex = 1; phiIndex <= reElement->numPadPhi(layHash); ++phiIndex) {
223 for(unsigned int etaIndex = 1; etaIndex <= reElement->numPadEta(layHash); ++etaIndex) {
224 bool isValidPad{false};
225 const Identifier padID = id_helper.padID(reElement->identify(),
226 reElement->multilayer(),
227 layer, chType, etaIndex, phiIndex, isValidPad);
228 if (!isValidPad) {
229 ATH_MSG_WARNING("Invalid Identifier detected for readout element "
230 <<m_idHelperSvc->toStringDetEl(reElement->identify())
231 <<" layer: "<<layer<<" pad: ("<<etaIndex << ", " << phiIndex<<") channelType: "<<chType);
232 continue;
233 }
234 const IdentifierHash padIDHash = reElement->measurementHash(padID);
235 if (etaIndex == 1 && phiIndex == 1) {
236 m_firstPadHeight.push_back(reElement->padHeight(padIDHash));
237 } else if (etaIndex == 2 && phiIndex == 1) {
238 m_padHeight.push_back(reElement->padHeight(padIDHash));
239 }
240 Amg::Vector2D localPadPos(Amg::Vector2D::Zero());
241 std::array<Amg::Vector2D,4> localPadCorners{make_array<Amg::Vector2D, 4>(Amg::Vector2D::Zero())};
242 Amg::Vector3D globalPadPos(Amg::Vector3D::Zero());
243 std::array<Amg::Vector3D,4> globalPadCorners{make_array<Amg::Vector3D, 4>(Amg::Vector3D::Zero())};
244
245 localPadPos = reElement->localChannelPosition(padIDHash);
246 localPadCorners = reElement->localPadCorners(padIDHash);
247
248 m_localPadPos.push_back(localPadPos);
249 m_localPadCornerBL.push_back(localPadCorners[0]);
250 m_localPadCornerBR.push_back(localPadCorners[1]);
251 m_localPadCornerTL.push_back(localPadCorners[2]);
252 m_localPadCornerTR.push_back(localPadCorners[3]);
253
254 Amg::Vector2D hitCorrection{-.1, -.1};
255 ATH_MSG_VERBOSE("BL: "<<Amg::toString(localPadCorners[0])
256 <<", BR: "<<Amg::toString(localPadCorners[1])
257 <<", UL: "<<Amg::toString(localPadCorners[2])
258 <<", UR: "<<Amg::toString(localPadCorners[3]));
259 Amg::Vector2D hitPos = localPadCorners[3] + hitCorrection;
260 m_hitPosition.push_back(hitPos);
261 m_padNumber.push_back(reElement->padNumber(hitPos, padIDHash));
262
263 globalPadPos = reElement->globalChannelPosition(gctx, padIDHash);
264 globalPadCorners = reElement->globalPadCorners(gctx, padIDHash);
265
266 m_globalPadPos.push_back(globalPadPos);
267 m_globalPadCornerBR.push_back(globalPadCorners[0]);
268 m_globalPadCornerBL.push_back(globalPadCorners[1]);
269 m_globalPadCornerTR.push_back(globalPadCorners[2]);
270 m_globalPadCornerTL.push_back(globalPadCorners[3]);
271
272 m_padEta.push_back(reElement->padEta(padIDHash));
273 m_padPhi.push_back(reElement->padPhi(padIDHash));
274 m_padGasGap.push_back(layer);
275
276 if (!(etaIndex == 1 && phiIndex == 1)) continue;
277 const Amg::Transform3D locToGlob = reElement->localToGlobalTransform(gctx,
278 reElement->layerHash(padIDHash));
279 ATH_MSG_DEBUG("The local to global transformation on layers is: " << Amg::toString(locToGlob));
280 m_padRot.push_back(locToGlob);
281 m_padRotGasGap.push_back(layer);
282 }
283 }
284 break;
286 const StripDesign& design{reElement->stripDesign(layHash)};
287 m_numStrips = design.numStrips();
288 m_stripPitch = design.stripPitch();
289 m_stripWidth = design.stripWidth();
290 for (unsigned int strip = 1; strip <= reElement->numChannels(layHash); ++strip) {
291 bool isValidStrip{false};
292 const Identifier stripID = id_helper.channelID(reElement->identify(),
293 reElement->multilayer(),
294 layer, chType, strip, isValidStrip);
295 if (!isValidStrip) {
296 ATH_MSG_WARNING("Invalid Identifier detected for readout element "
297 <<m_idHelperSvc->toStringDetEl(reElement->identify())
298 <<" layer: "<<layer<<" strip: "<<strip<<" channelType: "<<chType);
299 continue;
300 }
301 const IdentifierHash stripHash = reElement->measurementHash(stripID);
302 m_localStripPos.push_back(reElement->localChannelPosition(stripHash));
303 m_globalStripPos.push_back(reElement->globalChannelPosition(gctx, stripHash));
304 m_stripGasGap.push_back(layer);
305 m_stripNum.push_back(strip);
306 m_stripLengths.push_back(reElement->stripLength(stripHash));
307
308 if (strip != 1) continue;
309 const Amg::Transform3D locToGlob = reElement->localToGlobalTransform(gctx,
310 reElement->layerHash(stripHash));
311 ATH_MSG_DEBUG("The local to global transformation on layers is: " << Amg::toString(locToGlob));
312 m_stripRot.push_back(locToGlob);
313 m_stripRotGasGap.push_back(layer);
314
315 }
316 break;
318 const WireGroupDesign& design{reElement->wireDesign(layHash)};
320 numWireGroup = design.numStrips();
321 m_wirePitch = design.stripPitch();
322 m_wireWidth = design.stripWidth();
323 m_numWires.push_back(design.nAllWires());
324 m_firstWireGroupWidth.push_back(design.numWiresInGroup(1));
325 m_numWireGroups.push_back(numWireGroup);
326 m_wireCutout.push_back(design.wireCutout());
327 for (unsigned int wireGroup = 1; wireGroup <= numWireGroup; ++wireGroup) {
328 bool isValidWire{false};
329 const Identifier wireGroupID = id_helper.channelID(reElement->identify(),
330 reElement->multilayer(),
331 layer, chType, wireGroup, isValidWire);
332 if (!isValidWire) {
333 ATH_MSG_WARNING("Invalid Identifier detected for readout element "
334 <<m_idHelperSvc->toStringDetEl(reElement->identify())
335 <<" layer: "<<layer<<" wireGroup: "<<wireGroup<<" channelType: "<<chType);
336 continue;
337 }
338 const IdentifierHash wireGroupHash = reElement->measurementHash(wireGroupID);
339 m_localWireGroupPos.push_back(reElement->localChannelPosition(wireGroupHash));
340 m_globalWireGroupPos.push_back(reElement->globalChannelPosition(gctx, wireGroupHash));
341 m_wireGroupGasGap.push_back(layer);
342 m_wireGroupNum.push_back(wireGroup);
343
344 if (wireGroup != 1) continue;
345 const Amg::Transform3D locToGlob = reElement->localToGlobalTransform(gctx,
346 reElement->layerHash(wireGroupHash));
347 ATH_MSG_DEBUG("The local to global transformation on layers is: " << Amg::toString(locToGlob));
348 m_wireGroupRot.push_back(locToGlob);
349 m_wireGroupRotGasGap.push_back(layer);
350 }
351 break;
352 }
353 }
354 }
355 }
356 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
357}
358
359}
360
constexpr std::array< T, N > make_array(const T &def_val)
Helper function to initialize in-place arrays with non-zero values.
Definition ArrayHelper.h:10
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
const ServiceHandle< StoreGateSvc > & detStore() const
This is a "hash" representation of an Identifier.
Gaudi::Property< std::vector< std::string > > m_selectStat
String should be formated like <stationName><stationEta><A/C><stationPhi>.
MuonVal::CoordSystemsBranch m_stripRot
Rotation matrix of the respective strip layers.
StatusCode dumpToTree(const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const sTgcReadoutElement *readoutEle)
MuonVal::CoordTransformBranch m_readoutTransform
Transformation of the readout element (Translation, ColX, ColY, ColZ).
std::set< Identifier > m_testStations
Set of stations to be tested.
MuonVal::ScalarBranch< float > & m_sGapLength
GasGap Lengths for debug.
StatusCode execute(const EventContext &ctx) override
Execute method.
MuonVal::ScalarBranch< float > & m_sChamberLength
Chamber Length for debug.
MuonVal::CoordSystemsBranch m_wireGroupRot
Rotation matrix of the respective wireGroup layers.
MuonVal::CoordSystemsBranch m_padRot
Rotation matrix of the respective pad layers.
MuonVal::ScalarBranch< short > & m_stIndex
Identifier of the readout element.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the local coordinate system of the readout element into the global AT...
int stationEta() const
Returns the stationEta (positive A site, negative C site).
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the global ATLAS coordinate system into the local coordinate system o...
const std::string & chamberDesign() const
The chamber design refers to the construction parameters of a readout element.
Identifier identify() const override final
Return the ATLAS identifier.
int stationName() const
Returns the stationName (BIS, BOS, etc) encoded into the integer.
int stationPhi() const
Returns the stationPhi (1-8) -> sector (2*phi - (isSmall)).
const GeoAlignableTransform * alignableTransform() const
Return the alignable transform node of the readout element.
double firstPadPhiDiv() const
Returns the angle of the first pad outer edge w.r.t. the gasGap center from the beamline.
double halfWidth() const
Returns the half height of the strip panel.
double yCutout() const
Returns the cutout of the diamond.
double stripPitch() const
Distance between two adjacent strips.
double stripWidth() const
Width of a strip.
double shortHalfHeight() const
Returns the shorter half height of the panel.
double longHalfHeight() const
Returns the longer half height of the panel.
virtual int numStrips() const
Number of strips on the panel.
unsigned int numWiresInGroup(unsigned int groupNum) const
Returns the number of wires in a given group.
double wireCutout() const
Extract the wireCutout for a wireGroup layer.
unsigned int nAllWires() const
Returns the number of all wires.
unsigned numChannels(const IdentifierHash &measHash) const
Returns the number of strips / wires / pads in a given gasGap.
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
const PadDesign & padDesign(const IdentifierHash &measHash) const
Retrieves the readoutElement Layer given the Identifier/Hash.
double padHeight(const IdentifierHash &measHash) const
Returns the height of all the pads that are not adjacent to the bottom edge of the trapezoid active a...
unsigned padEta(const IdentifierHash &measHash) const
Returns the Eta index of the pad for the given pad identifier.
double gasGapThickness() const
Returns the thickness of the gas gap.
int multilayer() const
Returns the multilayer of the sTgcReadoutElement.
localCornerArray localPadCorners(const IdentifierHash &measHash) const
double stripLength(const IdentifierHash &measHash) const
Length of each strip.
Identifier measurementId(const IdentifierHash &measHash) const override final
Converts the measurement hash back to the full Identifier.
double padPhiShift(const IdentifierHash &measHash) const
Returns the staggering shift of inner pad edges in the phi direction.
int padNumber(const Amg::Vector2D &hitPos, const IdentifierHash &measHash) const
Returns the pad Number given local position of hit and Identifier/Hash.
double sChamberLength() const
Length of the chamber on the short side.
const StripDesign & stripDesign(const IdentifierHash &measHash) const
Retrieves the readoutElement Layer given the Identifier/Hash.
globalCornerArray globalPadCorners(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
unsigned numLayers() const
Returns the number of gas gap layers.
double anglePadPhi(const IdentifierHash &measHash) const
Returns the angular pitch of the pads in the phi direction.
IdentifierHash layerHash(const Identifier &measId) const override final
Transforms the Identifier into a layer hash.
unsigned numPadEta(const IdentifierHash &measHash) const
Returns the number of pads in the eta direction in the given layer.
unsigned padPhi(const IdentifierHash &measHash) const
Returns the Phi index of the pad for the given pad identifier.
double beamlineRadius(const IdentifierHash &measHash) const
Returns the distance between the gasGap center and the beamline.
double chamberHeight() const
Height of the chamber.
double lChamberLength() const
Length of the chamber on the long side.
Amg::Vector3D globalChannelPosition(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
Returns the global pad/strip/wireGroup position.
unsigned numPadPhi(const IdentifierHash &measHash) const
Returns the number of pads in the Phi direction in the given gasGap layer.
Amg::Vector2D localChannelPosition(const IdentifierHash &measHash) const
Returns the local position of the measurement in the repsective frame.
const WireGroupDesign & wireDesign(const IdentifierHash &measHash) const
Retrieves the readoutElement Layer given the Identifier/Hash.
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Identifier padID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int padEta, int padPhi) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
Identifier multilayerID(const Identifier &channeldID) const
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition dot.py:1
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.