ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/GeoModelTgcTest.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 "GeoModelTgcTest.h"
9 #include <fstream>
10 
11 using namespace ActsTrk;
12 
13 namespace MuonGMR4{
14 
16  ATH_CHECK(m_idHelperSvc.retrieve());
17  ATH_CHECK(m_geoCtxKey.initialize());
19  ATH_CHECK(m_tree.init(this));
20 
21  const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
22  auto translateTokenList = [this, &idHelper](const std::vector<std::string>& chNames){
23 
24  std::set<Identifier> transcriptedIds{};
25  for (const std::string& token : chNames) {
26  if (token.size() != 7) {
27  ATH_MSG_WARNING("Wrong format given for "<<token<<". Expecting 7 characters");
28  continue;
29  }
31  const std::string statName = token.substr(0, 3);
32  const unsigned statEta = std::atoi(token.substr(3, 1).c_str()) * (token[4] == 'A' ? 1 : -1);
33  const unsigned statPhi = std::atoi(token.substr(5, 2).c_str());
34  bool isValid{false};
35  const Identifier eleId = idHelper.elementID(statName, statEta, statPhi, isValid);
36  if (!isValid) {
37  ATH_MSG_WARNING("Failed to deduce a station name for " << token);
38  continue;
39  }
40  transcriptedIds.insert(eleId);
41  }
42  return transcriptedIds;
43  };
44 
45  std::vector <std::string>& selectedSt = m_selectStat.value();
46  const std::vector <std::string>& excludedSt = m_excludeStat.value();
47  selectedSt.erase(std::remove_if(selectedSt.begin(), selectedSt.end(),
48  [&excludedSt](const std::string& token){
49  return std::ranges::find(excludedSt, token) != excludedSt.end();
50  }), selectedSt.end());
51 
52  if (selectedSt.size()) {
53  m_testStations = translateTokenList(selectedSt);
54  std::stringstream sstr{};
55  for (const Identifier& id : m_testStations) {
56  sstr<<" *** "<<m_idHelperSvc->toString(id)<<std::endl;
57  }
58  ATH_MSG_INFO("Test only the following stations "<<std::endl<<sstr.str());
59  } else {
60  const std::set<Identifier> excluded = translateTokenList(excludedSt);
62  for(auto itr = idHelper.detectorElement_begin();
63  itr!= idHelper.detectorElement_end();++itr){
64  if (!excluded.count(*itr)) {
65  m_testStations.insert(*itr);
66  }
67  }
69  if (!excluded.empty()) {
70  std::stringstream excluded_report{};
71  for (const Identifier& id : excluded){
72  excluded_report << " *** " << m_idHelperSvc->toStringDetEl(id) << std::endl;
73  }
74  ATH_MSG_INFO("Test all station except the following excluded ones " << std::endl << excluded_report.str());
75  }
76  }
77  ATH_CHECK(detStore()->retrieve(m_detMgr));
78  return StatusCode::SUCCESS;
79 }
81  ATH_CHECK(m_tree.write());
82  return StatusCode::SUCCESS;
83 }
85  const EventContext& ctx{Gaudi::Hive::currentContext()};
86 
87  const ActsGeometryContext* geoContextHandle{nullptr};
88  ATH_CHECK(SG::get(geoContextHandle, m_geoCtxKey, ctx));
89  const ActsGeometryContext& gctx{*geoContextHandle};
90 
91  for (const Identifier& test_me : m_testStations) {
92  ATH_MSG_DEBUG("Test retrieval of Tgc detector element "<<m_idHelperSvc->toStringDetEl(test_me));
93  const TgcReadoutElement* reElement = m_detMgr->getTgcReadoutElement(test_me);
94  if (!reElement) {
95  continue;
96  }
98  if (reElement->identify() != test_me) {
99  ATH_MSG_FATAL("Expected to retrieve "<<m_idHelperSvc->toStringDetEl(test_me)
100  <<". But got instead "<<m_idHelperSvc->toStringDetEl(reElement->identify()));
101  return StatusCode::FAILURE;
102  }
103  const Amg::Transform3D globToLocal{reElement->globalToLocalTrans(gctx)};
104  const Amg::Transform3D& localToGlob{reElement->localToGlobalTrans(gctx)};
106  const Amg::Transform3D transClosure = globToLocal * localToGlob;
107  if (!Amg::doesNotDeform(transClosure)) {
108  ATH_MSG_FATAL("Closure test failed for "<<m_idHelperSvc->toStringDetEl(test_me)
109  <<". Ended up with "<< Amg::toString(transClosure) );
110  return StatusCode::FAILURE;
111  }
112  const TgcIdHelper& id_helper{m_idHelperSvc->tgcIdHelper()};
113  for (unsigned gasGap = 1; gasGap <= reElement->nGasGaps(); ++gasGap) {
114  for (bool isStrip : {false, true}) {
115  const IdentifierHash layHash = reElement->constructHash(0, gasGap, isStrip);
116  const unsigned nChan = reElement->numChannels(layHash);
117  for (unsigned chan = 1; chan <= nChan ; ++chan) {
118  bool isValid{false};
119  const Identifier channelId = id_helper.channelID(reElement->identify(),
121  if (!isValid) {
122  ATH_MSG_DEBUG("No valid Identifier constructed from the fields "
123  <<m_idHelperSvc->toStringDetEl(reElement->identify())
124  <<"isStrip: "<<(isStrip ? "yay" : "nay")<<" gasGap: "<<gasGap<<
125  " channel: "<<chan);
126  continue;
127  }
128  const IdentifierHash measHash{reElement->measurementHash(channelId)};
129  const Identifier backCnv = reElement->measurementId(measHash);
130  if (backCnv != channelId) {
131  ATH_MSG_FATAL("Forward-backward conversion of the Identifier "<<m_idHelperSvc->toString(channelId)
132  <<"failed. Got instead "<<m_idHelperSvc->toString(backCnv));
133  return StatusCode::FAILURE;
134  }
135  if (reElement->layerHash(channelId) != reElement->layerHash(measHash)) {
136  ATH_MSG_FATAL("The cosntruction of the layer hash from the Identifier "<<m_idHelperSvc->toString(channelId)
137  <<" gave something else than doing it from the measurement hash "<<measHash<<". "<<
138  reElement->layerHash(channelId)<<" vs. "<<reElement->layerHash(measHash));
139  }
140  }
141  }
142  }
143  ATH_CHECK(dumpToTree(ctx, gctx, reElement));
144  }
145  return StatusCode::SUCCESS;
146 }
147 StatusCode GeoModelTgcTest::dumpToTree(const EventContext& ctx,
148  const ActsGeometryContext& gctx,
149  const TgcReadoutElement* reElement) {
150 
151  m_stIndex = reElement->stationName();
152  m_stEta = reElement->stationEta();
153  m_stPhi = reElement->stationPhi();
154  m_stLayout = reElement->chamberDesign();
155  m_nGasGaps = reElement->nGasGaps();
156  m_readoutTransform = reElement->localToGlobalTrans(gctx);
157 
158  m_alignableNode = reElement->alignableTransform()->getDefTransform();
159 
160  m_shortWidth = reElement->moduleWidthS();
161  m_longWidth = reElement->moduleWidthL();
162  m_height = reElement->moduleHeight();
163  m_thickness = reElement->moduleThickness();
164 
165  for (unsigned gap = 1; gap <= reElement->nGasGaps(); ++gap) {
166  const IdentifierHash layHash = reElement->constructHash(0, gap, true);
168  for (unsigned strip = 1 ; strip <= reElement->numStrips(layHash); ++strip) {
169  const IdentifierHash measHash = reElement->constructHash(strip, gap, true);
170  const RadialStripDesign& layout{reElement->stripLayout(measHash)};
171 
172  const Amg::Transform3D& localToGlobal{reElement->localToGlobalTrans(gctx , layHash)};
173  if (strip == 1) {
174  m_layTans.push_back(localToGlobal);
175  m_layMeasPhi.push_back(true);
176  m_layNumber.push_back(gap);
177  m_layShortWidth.push_back(2.*layout.shortHalfHeight());
178  m_layLongWidth.push_back(2.*layout.longHalfHeight());
179  m_layHeight.push_back(2.*layout.halfWidth());
180  m_layNumWires.push_back(0);
181  }
182  m_stripGasGap.push_back(gap);
183  m_stripNum.push_back(strip);
184  m_stripCenter.push_back(reElement->channelPosition(gctx, measHash));
185  const auto sensor = reElement->sensorLayout(measHash);
186  const Amg::Vector2D locTop2D{layout.leftEdge(strip).value_or(Amg::Vector2D::Zero())};
187  const Amg::Vector2D locBot2D{layout.rightEdge(strip).value_or(Amg::Vector2D::Zero())};
188  const Amg::Vector3D globTop{localToGlobal * sensor->to3D(layout.leftEdge(strip), true)};
189  const Amg::Vector3D globBot{localToGlobal * sensor->to3D(layout.rightEdge(strip), true)};
190  m_stripBottom.push_back(globBot);
191  m_stripTop.push_back(globTop);
192  m_locStripTop.push_back(locTop2D);
193  m_locStripCenter.push_back(layout.center(strip).value_or(Amg::Vector2D::Zero()));
194  m_locStripBottom.push_back(locBot2D);
195 
196  }
198  for (unsigned gang = 1; gang <= reElement->numWireGangs(layHash); ++gang) {
199  const IdentifierHash measHash = reElement->constructHash(gang, gap, false);
200  const WireGroupDesign& layout{reElement->wireGangLayout(measHash)};
201  if (gang == 1) {
202  m_layTans.push_back(reElement->localToGlobalTrans(gctx, reElement->layerHash(measHash)));
203  m_layMeasPhi.push_back(false);
204  m_layNumber.push_back(gap);
205  m_layShortWidth.push_back(2.*layout.shortHalfHeight());
206  m_layLongWidth.push_back(2.*layout.longHalfHeight());
207  m_layHeight.push_back(2.*layout.halfWidth());
208  m_layNumWires.push_back(layout.nAllWires());
209  }
210  m_gangNum.push_back(gang);
211  m_gangGasGap.push_back(gap);
212  m_gangCenter.push_back(reElement->channelPosition(gctx, measHash));
213  m_gangNumWires.push_back(layout.numWiresInGroup(gang));
214  m_locGangPos.push_back(layout.center(gang).value_or(Amg::Vector2D::Zero()));
215  m_gangLength.push_back(layout.stripLength(gang));
216  }
217  }
218  return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
219 }
220 
221 }
222 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGMR4::WireGroupDesign
Definition: WireGroupDesign.h:23
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsGeometryContext.h
TgcIdHelper
Definition: TgcIdHelper.h:50
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
MuonGMR4::TgcReadoutElement::wireGangLayout
const WireGroupDesign & wireGangLayout(const IdentifierHash &layHash) const
Returns access to the wire group design of the given gasGap [1-3] If the gap does not have a wires an...
initialize
void initialize()
Definition: run_EoverP.cxx:894
GeoModelTgcTest.h
MuonGMR4::MuonReadoutElement::chamberDesign
const std::string & chamberDesign() const
The chamber design refers to the construction parameters of a readout element.
MuonGMR4::TgcReadoutElement::channelPosition
Amg::Vector3D channelPosition(const ActsGeometryContext &ctx, const Identifier &measId) const
Returns the center of the measurement channel eta measurement: wire gang center phi measurement: stri...
MuonGMR4::TgcReadoutElement::moduleWidthS
double moduleWidthS() const
Returns the length of the bottom edge of the chamber (short width)
MuonGMR4::TgcReadoutElement::moduleWidthL
double moduleWidthL() const
Returns the length of the top edge of the chamber (top width)
MuonGMR4::MuonReadoutElement::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:78
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:867
MuonGMR4::TgcReadoutElement::moduleHeight
double moduleHeight() const
Returns the height of the chamber (Distance bottom - topWidth)
CaloSwCorrections.gap
def gap(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:212
MuonGMR4::TgcReadoutElement::nGasGaps
unsigned nGasGaps() const
Returns the number of gasgaps described by this ReadOutElement (usally 2 or 3)
MuonGMR4::TgcReadoutElement::moduleThickness
double moduleThickness() const
Returns the thickness of the chamber.
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:19
EventPrimitivesToStringConverter.h
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::doesNotDeform
bool doesNotDeform(const Amg::Transform3D &trans)
Checks whether the linear part of the transformation rotates or stetches any of the basis vectors.
Definition: GeoPrimitivesHelpers.h:383
MuonGMR4::TgcReadoutElement::measurementId
Identifier measurementId(const IdentifierHash &measHash) const override final
Converts the measurement hash back to the full Identifier.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGMR4::TgcReadoutElement::measurementHash
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:121
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
dumpTgcDigiThreshold.isStrip
list isStrip
Definition: dumpTgcDigiThreshold.py:33
MuonGMR4::TgcReadoutElement::layerHash
IdentifierHash layerHash(const Identifier &measId) const override final
MuonGMR4::MuonReadoutElement::alignableTransform
const GeoAlignableTransform * alignableTransform() const
Returnsthe alignable transform of the readout element.
MuonGMR4::TgcReadoutElement::sensorLayout
const StripLayerPtr & sensorLayout(const IdentifierHash &hash) const
Returns the pointer to the strip layer associated with the gas gap.
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonGMR4::MuonReadoutElement::stationName
int stationName() const
Returns the stationName (BIS, BOS, etc) encoded into the integer.
MuonGMR4::TgcReadoutElement::numStrips
unsigned numStrips(const IdentifierHash &layHash) const
Returns the number of strips for a given gasGap [1-3].
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonGMR4::TgcReadoutElement::numWireGangs
unsigned numWireGangs(const IdentifierHash &layHash) const
Returns the number of wire gangs for a given gasGap [1-3].
MuonGMR4::TgcReadoutElement::constructHash
static IdentifierHash constructHash(unsigned measCh, unsigned gasGap, const bool isStrip)
Constructs the Hash out of the Identifier fields (channel, gasGap, isStrip)
MuonGMR4::MuonReadoutElement::localToGlobalTrans
const Amg::Transform3D & localToGlobalTrans(const ActsGeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:81
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
MuonGMR4::MuonReadoutElement::stationEta
int stationEta() const
Returns the stationEta (positive A site, negative O site)
MuonGMR4::TgcReadoutElement::numChannels
unsigned numChannels(const IdentifierHash &measHash) const
Returns the number of readout channels.
MuonGMR4::RadialStripDesign
Definition: RadialStripDesign.h:23
TgcReadoutElement.h
MuonGMR4::MuonReadoutElement::stationPhi
int stationPhi() const
Returns the stationPhi (1-8) -> sector (2*phi - (isSmall))
MuonGMR4::TgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:19
MuonGMR4::TgcReadoutElement::stripLayout
const RadialStripDesign & stripLayout(const IdentifierHash &layHash) const
Returns access to the strip design of the given gasGap [1-3] If the gap does not have strips an excep...
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
Identifier
Definition: IdentifierFieldParser.cxx:14