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/GeoModelMdtTest.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 "GeoModelMdtTest.h"
10 
11 #include <fstream>
12 
13 using namespace ActsTrk;
14 
15 namespace MuonGMR4{
16 
17 
19  ATH_CHECK(m_idHelperSvc.retrieve());
20  ATH_CHECK(m_geoCtxKey.initialize());
22  ATH_CHECK(m_tree.init(this));
23 
24  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
25  auto translateTokenList = [this, &idHelper](const std::vector<std::string>& chNames){
26 
27  std::set<Identifier> transcriptedIds{};
28  for (const std::string& token : chNames) {
29  if (token.size() != 6) {
30  ATH_MSG_WARNING("Wrong format given for "<<token<<". Expecting 6 characters");
31  continue;
32  }
34  const std::string statName = token.substr(0, 3);
35  const unsigned statEta = std::atoi(token.substr(3, 1).c_str()) * (token[4] == 'A' ? 1 : -1);
36  const unsigned statPhi = std::atoi(token.substr(5, 1).c_str());
37  bool isValid{false};
38  const Identifier eleId = idHelper.elementID(statName, statEta, statPhi, isValid);
39  if (!isValid) {
40  ATH_MSG_WARNING("Failed to deduce a station name for " << token);
41  continue;
42  }
43  transcriptedIds.insert(eleId);
44  const Identifier secMlId = idHelper.multilayerID(eleId, 2, isValid);
45  if (isValid){
46  transcriptedIds.insert(secMlId);
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  SG::ReadHandle geoContextHandle{m_geoCtxKey, ctx};
94  ATH_CHECK(geoContextHandle.isPresent());
95 
96  const ActsGeometryContext& gctx{*geoContextHandle};
97 
98  const MdtIdHelper& id_helper{m_idHelperSvc->mdtIdHelper()};
99  for (const Identifier& test_me : m_testStations) {
100  const int ml = id_helper.multilayer(test_me);
101  const std::string detStr = m_idHelperSvc->toStringDetEl(test_me);
102  ATH_MSG_DEBUG("Test retrieval of Mdt detector element "<<detStr);
103  const MdtReadoutElement* reElement = m_detMgr->getMdtReadoutElement(test_me);
104  if (!reElement) {
105  continue;
106  }
108  if (reElement->identify() != test_me) {
109  ATH_MSG_FATAL("Expected to retrieve "<<detStr<<". But got instead "<<m_idHelperSvc->toStringDetEl(reElement->identify()));
110  return StatusCode::FAILURE;
111  }
112  ATH_CHECK(dumpToTree(ctx,gctx,reElement));
113  const Amg::Transform3D globToLocal{reElement->globalToLocalTrans(gctx)};
114  const Amg::Transform3D& localToGlob{reElement->localToGlobalTrans(gctx)};
116  const Amg::Transform3D transClosure = globToLocal * localToGlob;
117  if (!Amg::doesNotDeform(transClosure)) {
118  ATH_MSG_FATAL("Closure test failed for "<<detStr<<". Ended up with "<< Amg::toString(transClosure) );
119  return StatusCode::FAILURE;
120  }
121  for (unsigned int lay = 1 ; lay <= reElement->numLayers() ; ++lay ) {
122  for (unsigned int tube = 1; tube <=reElement->numTubesInLay(); ++tube ){
123  const Identifier tube_id = id_helper.channelID(test_me,ml,lay,tube);
125  const IdentifierHash measHash = reElement->measurementHash(tube_id);
126  const Identifier cnv_tube_id = reElement->measurementId(measHash);
127  if (tube_id != cnv_tube_id) {
128  ATH_MSG_FATAL("Failed to convert "<<m_idHelperSvc->toString(tube_id)<<" back and forth "<<m_idHelperSvc->toString(cnv_tube_id));
129  return StatusCode::FAILURE;
130  }
131  }
132  }
133  }
134  dumpReadoutSideXML();
135  return StatusCode::SUCCESS;
136 }
137 void GeoModelMdtTest::dumpReadoutSideXML() const {
138  if (m_swapRead.empty()) return;
139  std::ofstream swapReadXML{m_swapRead};
140  if (!swapReadXML.good()) {
141  ATH_MSG_ERROR("Failed to create "<<m_swapRead);
142  return;
143  }
144  std::set<Identifier> chamberIDs{};
145  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
146  swapReadXML<<"<Table name=\"MdtTubeROSides\">"<<std::endl;
147  unsigned int counter{1};
148  for (MdtIdHelper::const_id_iterator itr = idHelper.detectorElement_begin();
149  itr != idHelper.detectorElement_end();
150  ++itr){
151  const Identifier swap{*itr};
152  const MdtReadoutElement* readoutEle = m_detMgr->getMdtReadoutElement(swap);
153  if(!readoutEle) continue;
154  if (!chamberIDs.insert(idHelper.elementID(swap)).second) continue;
155  const int side = readoutEle->getParameters().readoutSide;
156  swapReadXML<<" <Row ";
157  swapReadXML<<"MDTTUBEROSIDES_DATA_ID=\""<<counter<<"\" ";
158  swapReadXML<<"stationName=\""<<m_idHelperSvc->stationNameString(swap)<<"\" ";
159  swapReadXML<<"stationEta=\""<<m_idHelperSvc->stationEta(swap)<<"\" ";
160  swapReadXML<<"stationPhi=\""<<m_idHelperSvc->stationPhi(swap)<<"\" ";
161  swapReadXML<<"side=\""<<side<<"\" ";
162  swapReadXML<<"/>"<<std::endl;
163  ++counter;
164  }
165  swapReadXML<<"</Table>"<<std::endl;
166 
167 }
168 StatusCode GeoModelMdtTest::dumpToTree(const EventContext& ctx,
169  const ActsGeometryContext& gctx,
170  const MdtReadoutElement* readoutEle) {
171 
172  m_stIndex = readoutEle->stationName();
173  m_stEta = readoutEle->stationEta();
174  m_stPhi = readoutEle->stationPhi();
175  m_stML = readoutEle->multilayer();
176  m_chamberDesign = readoutEle->chamberDesign();
177 
178  m_numLayers = readoutEle->numLayers();
179  m_numTubes = readoutEle->numTubesInLay();
180 
181  m_tubeRad = readoutEle->innerTubeRadius();
182  m_tubePitch = readoutEle->tubePitch();
183 
185  const Amg::Transform3D& transform {readoutEle->localToGlobalTrans(gctx)};
186  m_readoutTransform = transform;
187  m_alignableNode = readoutEle->alignableTransform()->getDefTransform();
188 
190  for (unsigned int lay = 1; lay <= readoutEle->numLayers(); ++lay) {
191  for (unsigned int tube = 1; tube <= readoutEle->numTubesInLay(); ++tube) {
192  const IdentifierHash measHash{readoutEle->measurementHash(lay,tube)};
193  if (!readoutEle->isValid(measHash)) continue;
194  const Amg::Transform3D& tubeTransform{readoutEle->localToGlobalTrans(gctx,measHash)};
195  m_tubeLay.push_back(lay);
196  m_tubeNum.push_back(tube);
197  m_tubeTransform.push_back(tubeTransform);
198  m_tubePosInCh.push_back(readoutEle->msSector()->globalToLocalTrans(gctx) *
199  readoutEle->center(gctx, measHash));
200  m_roPos.push_back(readoutEle->readOutPos(gctx, measHash));
201  m_tubeLength.push_back(readoutEle->tubeLength(measHash));
202  m_activeTubeLength.push_back(readoutEle->activeTubeLength(measHash));
203  m_wireLength.push_back(readoutEle->wireLength(measHash));
204  }
205  }
206 
207  return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
208 }
209 
210 }
211 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MdtIdHelper::multilayer
int multilayer(const Identifier &id) const
Access to components of the ID.
Definition: MdtIdHelper.cxx:722
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::MuonReadoutElement::msSector
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
MuonGMR4::MdtReadoutElement::numTubesInLay
unsigned int numTubesInLay() const
Returns the number of tubes per layer.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsGeometryContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonGMR4::MdtReadoutElement::tubeLength
double tubeLength(const IdentifierHash &hash) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:185
initialize
void initialize()
Definition: run_EoverP.cxx:894
MuonGMR4::MdtReadoutElement::measurementHash
static IdentifierHash measurementHash(unsigned int layerNumber, unsigned int tubeNumber)
Transform the layer and tube number to the measurementHash.
MuonGMR4::MuonReadoutElement::chamberDesign
const std::string & chamberDesign() const
The chamber design refers to the construction parameters of a readout element.
MuonGMR4::MdtReadoutElement::activeTubeLength
double activeTubeLength(const IdentifierHash &hash) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:173
MuonGMR4::MdtReadoutElement::readOutPos
Amg::Vector3D readOutPos(const ActsGeometryContext &ctx, const Identifier &measId) const
Returns the global position of the readout card.
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:778
SpectrometerSector.h
MuonGMR4::MdtReadoutElement::parameterBook::readoutSide
double readoutSide
Is the readout chip at positive or negative Z?
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:64
TRT::Hit::side
@ side
Definition: HitInfo.h:83
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
MuonGMR4::MdtReadoutElement::measurementId
Identifier measurementId(const IdentifierHash &measHash) const override final
Converts the measurement hash back to the full Identifier.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:47
MuonGMR4::MdtReadoutElement::multilayer
unsigned int multilayer() const
Returns the multi layer of the MdtReadoutElement.
MuonGMR4::MdtReadoutElement::wireLength
double wireLength(const IdentifierHash &hash) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:188
GeoModelMdtTest.h
calibdata.tube_id
tube_id
Definition: calibdata.py:30
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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::SpectrometerSector::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
Definition: SpectrometerSector.cxx:54
MuonGMR4::MdtReadoutElement::numLayers
unsigned int numLayers() const
Returns the number of tube layer.
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
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
MdtIdHelper
Definition: MdtIdHelper.h:61
MuonGMR4::MuonReadoutElement::center
Amg::Vector3D center(const ActsGeometryContext &ctx) const
Returns the detector center (Which is the same as the detector center of the first measurement layer)
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonGMR4::MdtReadoutElement::innerTubeRadius
double innerTubeRadius() const
Returns the inner tube radius.
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonGMR4::MdtReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:22
MuonGMR4::MuonReadoutElement::alignableTransform
const GeoAlignableTransform * alignableTransform() const
Returnsthe alignable transform of the readout element.
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
MuonGMR4::MdtReadoutElement::tubePitch
double tubePitch() const
Returns the pitch between 2 tubes in a layer.
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
MdtReadoutElement.h
GeoPrimitivesToStringConverter.h
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
MuonIdHelper::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: MuonIdHelper.h:143
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::MuonReadoutElement::stationEta
int stationEta() const
Returns the stationEta (positive A site, negative O site)
MuonGMR4::MdtReadoutElement::getParameters
const parameterBook & getParameters() const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:46
test_pyathena.counter
counter
Definition: test_pyathena.py:15
MuonGMR4::MdtReadoutElement::isValid
bool isValid(const IdentifierHash &measHash) const
MuonGMR4::MuonReadoutElement::stationPhi
int stationPhi() const
Returns the stationPhi (1-8) -> sector (2*phi - (isSmall))
calibdata.tube
tube
Definition: calibdata.py:31
Identifier
Definition: IdentifierFieldParser.cxx:14