Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/GeoModelRpcTest.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 "GeoModelRpcTest.h"
9 #include <fstream>
10 
11 using namespace ActsTrk;
12 namespace MuonGMR4{
13 
14 
16  ATH_CHECK(m_idHelperSvc.retrieve());
17  ATH_CHECK(m_geoCtxKey.initialize());
19  ATH_CHECK(m_tree.init(this));
20 
21  const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
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() != 6) {
27  ATH_MSG_WARNING("Wrong format given for "<<token<<". Expecting 6 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, 1).c_str());
34  bool isValid{false};
35  const Identifier eleId = idHelper.elementID(statName, statEta, statPhi, 1, isValid);
36  if (!isValid) {
37  ATH_MSG_WARNING("Failed to deduce a station name for " << token);
38  continue;
39  }
40  transcriptedIds.insert(eleId);
41  std::copy_if(idHelper.detectorElement_begin(), idHelper.detectorElement_end(),
42  std::inserter(transcriptedIds, transcriptedIds.end()),
43  [&eleId, &idHelper](const Identifier& copyMe){
44  return idHelper.stationName(copyMe) == idHelper.stationName(eleId) &&
45  idHelper.stationEta(copyMe) == idHelper.stationEta(eleId) &&
46  idHelper.stationPhi(copyMe) == idHelper.stationPhi(eleId);
47  });
48  }
49  return transcriptedIds;
50  };
51 
52  std::vector <std::string>& selectedSt = m_selectStat.value();
53  const std::vector <std::string>& excludedSt = m_excludeStat.value();
54  selectedSt.erase(std::remove_if(selectedSt.begin(), selectedSt.end(),
55  [&excludedSt](const std::string& token){
56  return std::ranges::find(excludedSt, token) != excludedSt.end();
57  }), selectedSt.end());
58 
59  if (selectedSt.size()) {
60  m_testStations = translateTokenList(selectedSt);
61  std::stringstream sstr{};
62  for (const Identifier& id : m_testStations) {
63  sstr<<" *** "<<m_idHelperSvc->toString(id)<<std::endl;
64  }
65  ATH_MSG_INFO("Test only the following stations "<<std::endl<<sstr.str());
66  } else {
67  const std::set<Identifier> excluded = translateTokenList(excludedSt);
69  for(auto itr = idHelper.detectorElement_begin();
70  itr!= idHelper.detectorElement_end();++itr){
71  if (!excluded.count(*itr)) {
72  m_testStations.insert(*itr);
73  }
74  }
76  if (!excluded.empty()) {
77  std::stringstream excluded_report{};
78  for (const Identifier& id : excluded){
79  excluded_report << " *** " << m_idHelperSvc->toStringDetEl(id) << std::endl;
80  }
81  ATH_MSG_INFO("Test all station except the following excluded ones " << std::endl << excluded_report.str());
82  }
83  }
84  ATH_CHECK(detStore()->retrieve(m_detMgr));
85  return StatusCode::SUCCESS;
86 }
88  ATH_CHECK(m_tree.write());
89  return StatusCode::SUCCESS;
90 }
92  const EventContext& ctx{Gaudi::Hive::currentContext()};
93 
94  const ActsGeometryContext* geoContextHandle{nullptr};
95  ATH_CHECK(SG::get(geoContextHandle, m_geoCtxKey, ctx));
96  const ActsGeometryContext& gctx{*geoContextHandle};
97 
98  for (const Identifier& test_me : m_testStations) {
99  ATH_MSG_DEBUG("Test retrieval of Rpc detector element "<<m_idHelperSvc->toStringDetEl(test_me));
100  const RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(test_me);
101  if (!reElement) {
102  continue;
103  }
105  if (reElement->identify() != test_me) {
106  ATH_MSG_FATAL("Expected to retrieve "<<m_idHelperSvc->toStringDetEl(test_me)
107  <<". But got instead "<<m_idHelperSvc->toStringDetEl(reElement->identify()));
108  return StatusCode::FAILURE;
109  }
110  ATH_CHECK(dumpToTree(ctx,gctx,reElement));
111  const Amg::Transform3D globToLocal{reElement->globalToLocalTrans(gctx)};
112  const Amg::Transform3D& localToGlob{reElement->localToGlobalTrans(gctx)};
114  const Amg::Transform3D transClosure = globToLocal * localToGlob;
115  if (!Amg::doesNotDeform(transClosure)) {
116  ATH_MSG_FATAL("Closure test failed for "<<m_idHelperSvc->toStringDetEl(test_me)
117  <<". Ended up with "<< Amg::toString(transClosure) );
118  return StatusCode::FAILURE;
119  }
120  const RpcIdHelper& id_helper{m_idHelperSvc->rpcIdHelper()};
121  for (unsigned int gasGap = 1; gasGap <= reElement->nGasGaps(); ++gasGap) {
122  for (int doubPhi = reElement->doubletPhi(); doubPhi <= reElement->doubletPhiMax(); ++doubPhi) {
123  for (bool measPhi: {false, true}) {
124  unsigned int numStrip = (measPhi ? reElement->nPhiStrips() :
125  reElement->nEtaStrips());
126  for (unsigned int strip = 1; strip < numStrip ; ++strip) {
127  bool isValid{false};
128  const Identifier chId = id_helper.channelID(reElement->identify(),
129  reElement->doubletZ(),
130  doubPhi, gasGap, measPhi, strip, isValid);
131  if (!isValid) {
132  continue;
133  }
135  const IdentifierHash measHash = reElement->measurementHash(chId);
136  const IdentifierHash layHash = reElement->layerHash(chId);
137  ATH_MSG_VERBOSE("gasGap: "<<gasGap<<", doubletPhi: "<<doubPhi<<", measPhi: "<<measPhi
138  <<" --> layerHash: "<<static_cast<unsigned>(layHash));
139  const Identifier backCnv = reElement->measurementId(measHash);
140  if (backCnv != chId) {
141  ATH_MSG_FATAL("The back and forth conversion of "<<m_idHelperSvc->toString(chId)
142  <<" failed. Got "<<m_idHelperSvc->toString(backCnv));
143  return StatusCode::FAILURE;
144  }
145  if (layHash != reElement->layerHash(measHash)) {
146  ATH_MSG_FATAL("Constructing the layer hash from the identifier "<<
147  m_idHelperSvc->toString(chId)<<" leadds to different layer hashes "<<
148  layHash<<" vs. "<< reElement->layerHash(measHash));
149  return StatusCode::FAILURE;
150  }
151  ATH_MSG_VERBOSE("Channel "<<m_idHelperSvc->toString(chId)<<" strip position "
152  <<Amg::toString(reElement->stripPosition(gctx, measHash)));
153  }
154  }
155  }
156  }
157  }
158  return StatusCode::SUCCESS;
159 }
160 StatusCode GeoModelRpcTest::dumpToTree(const EventContext& ctx,
161  const ActsGeometryContext& gctx,
162  const RpcReadoutElement* reElement){
163 
164  m_stIndex = reElement->stationName();
165  m_stEta = reElement->stationEta();
166  m_stPhi = reElement->stationPhi();
167  m_doubletR = reElement->doubletR();
168  m_doubletZ = reElement->doubletZ();
169  m_doubletPhi = reElement->doubletPhi();
170  m_chamberDesign = reElement->chamberDesign();
171 
172  m_numRpcLayers = reElement->nGasGaps();
173 
174  m_numGasGapsPhi = reElement->nPhiPanels();
175  m_numPhiPanels = reElement->nPhiPanels();
176 
178  m_numStripsEta = reElement->nEtaStrips();
179  m_numStripsPhi = reElement->nPhiStrips();
180 
181  m_stripEtaPitch = reElement->stripEtaPitch();
182  m_stripPhiPitch = reElement->stripPhiPitch();
183  m_stripEtaWidth = reElement->stripEtaWidth();
184  m_stripPhiWidth = reElement->stripPhiWidth();
185  m_stripEtaLength = reElement->stripEtaLength();
186  m_stripPhiLength = reElement->stripPhiLength();
187 
189  const Amg::Transform3D& transform{reElement->localToGlobalTrans(gctx)};
190  m_readoutTransform = transform;
191  m_alignableNode = reElement->alignableTransform()->getDefTransform();
192 
193  const RpcIdHelper& id_helper{m_idHelperSvc->rpcIdHelper()};
194 
195  for (unsigned int gasGap = 1; gasGap <= reElement->nGasGaps(); ++gasGap) {
196  for (int doubPhi = reElement->doubletPhi(); doubPhi <= reElement->doubletPhiMax(); ++doubPhi) {
197  for (bool measPhi: {false, true}) {
198  unsigned int numStrip = (measPhi ? reElement->nPhiStrips() :
199  reElement->nEtaStrips());
200  for (unsigned int strip = 1; strip <= numStrip ; ++strip) {
201 
202  bool isValid{false};
203  const Identifier stripID = id_helper.channelID(reElement->identify(),
204  reElement->doubletZ(),
205  doubPhi, gasGap, measPhi, strip, isValid);
206  if (!isValid) {
207  ATH_MSG_WARNING("Invalid Identifier detected for readout element "
208  <<m_idHelperSvc->toStringDetEl(reElement->identify())
209  <<" gap: "<<gasGap<<" strip: "<<strip<<" meas phi: "<<measPhi);
210  continue;
211  }
212  const IdentifierHash measHash = reElement->measurementHash(stripID);
213  const IdentifierHash layHash = reElement->layerHash(measHash);
214  const Amg::Vector3D stripPos = reElement->stripPosition(gctx, measHash);
215  m_stripPos.push_back(stripPos);
216  m_locStripPos.push_back((reElement->globalToLocalTrans(gctx, layHash) * stripPos).block<2,1>(0,0));
217  m_stripPosGasGap.push_back(gasGap);
218  m_stripPosMeasPhi.push_back(measPhi);
219  m_stripPosNum.push_back(strip);
220  m_stripDblPhi.push_back(doubPhi);
221 
222  if (strip != 1) continue;
223  const Amg::Transform3D locToGlob = reElement->localToGlobalTrans(gctx, layHash);
224  m_stripRot.push_back(locToGlob);
225  m_stripRotGasGap.push_back(gasGap);
226  m_stripRotMeasPhi.push_back(measPhi);
227  m_stripRotDblPhi.push_back(doubPhi);
228  }
229  }
230  }
231  }
232  return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
233 }
234 
235 }
236 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonGMR4::RpcReadoutElement::stripPhiLength
double stripPhiLength() const
Returns the length of a phi strip.
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MuonGMR4::RpcReadoutElement::doubletR
int doubletR() const
Returns the doublet R field of the MuonReadoutElement identifier.
ActsGeometryContext.h
MuonGMR4::RpcReadoutElement::stripEtaPitch
double stripEtaPitch() const
Strip pitch in eta.
initialize
void initialize()
Definition: run_EoverP.cxx:894
MuonGMR4::MuonReadoutElement::chamberDesign
const std::string & chamberDesign() const
The chamber design refers to the construction parameters of a readout element.
MuonGMR4::RpcReadoutElement::measurementId
Identifier measurementId(const IdentifierHash &measHash) const override final
Converts the measurement hash back to the full Identifier.
MuonGMR4::RpcReadoutElement::nGasGaps
unsigned int nGasGaps() const
Returns the number of gasgaps described by this ReadOutElement (usally 2 or 3)
MuonGMR4::RpcReadoutElement::stripPhiPitch
double stripPhiPitch() const
Strip pitch in phi.
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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:812
MuonGMR4::RpcReadoutElement::nPhiPanels
int nPhiPanels() const
Returns the number of phi panels (1 or 2)
MuonGMR4::RpcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:17
RpcIdHelper
Definition: RpcIdHelper.h:51
MuonGMR4::RpcReadoutElement::nEtaStrips
unsigned int nEtaStrips() const
Number of strips measuring the eta coordinate.
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
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
MuonGMR4::RpcReadoutElement::doubletPhi
int doubletPhi() const
Returns the doublet Phi field of the MuonReadoutElement identifier.
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::RpcReadoutElement::stripPosition
Amg::Vector3D stripPosition(const ActsGeometryContext &ctx, const Identifier &measId) const
Returns the position of the strip center.
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
GeoModelRpcTest.h
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
MuonGMR4::RpcReadoutElement::doubletZ
int doubletZ() const
Returns the doublet Z field of the MuonReadoutElement identifier.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGMR4::RpcReadoutElement::measurementHash
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonGMR4::MuonReadoutElement::alignableTransform
const GeoAlignableTransform * alignableTransform() const
Returnsthe alignable transform of the readout element.
MuonGMR4::RpcReadoutElement::layerHash
IdentifierHash layerHash(const Identifier &measId) const override final
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
MuonGMR4::RpcReadoutElement::nPhiStrips
unsigned int nPhiStrips() const
Number of strips measuring the phi coordinate.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
RpcReadoutElement.h
MuonGMR4::MuonReadoutElement::stationName
int stationName() const
Returns the stationName (BIS, BOS, etc) encoded into the integer.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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: MuonDetectorBuilderTool.cxx:55
MuonGMR4::RpcReadoutElement::stripPhiWidth
double stripPhiWidth() const
Strip width in phi.
MuonGMR4::MuonReadoutElement::stationEta
int stationEta() const
Returns the stationEta (positive A site, negative O site)
MuonGMR4::RpcReadoutElement::stripEtaWidth
double stripEtaWidth() const
Strip width in eta.
MuonGMR4::MuonReadoutElement::stationPhi
int stationPhi() const
Returns the stationPhi (1-8) -> sector (2*phi - (isSmall))
MuonGMR4::RpcReadoutElement::stripEtaLength
double stripEtaLength() const
Returns the length of an eta strip.
Identifier
Definition: IdentifierFieldParser.cxx:14