ATLAS Offline Software
MdtReadoutGeomTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <GaudiKernel/SystemOfUnits.h>
9 
12 #include <GeoModelKernel/GeoFullPhysVol.h>
13 #include <GeoModelKernel/GeoPhysVol.h>
14 #include <GeoModelKernel/GeoTrd.h>
15 #include <GeoModelKernel/GeoTube.h>
16 
17 #include <GeoModelRead/ReadGeoModel.h>
20 
21 using namespace CxxUtils;
22 using namespace ActsTrk;
23 
24 namespace MuonGMR4 {
26 
27 
28 MdtReadoutGeomTool::MdtReadoutGeomTool(const std::string& type,
29  const std::string& name,
30  const IInterface* parent)
31  : AthAlgTool{type, name, parent} {
32  declareInterface<IMuonReadoutGeomTool>(this);
33 }
34 
36  MdtReadoutElement::defineArgs& define) const {
37 
38  ATH_MSG_VERBOSE("Load dimensions of "<<m_idHelperSvc->toString(define.detElId)
39  <<std::endl<<std::endl<<m_geoUtilTool->dumpVolume(define.physVol));
40  const GeoShape* shape = m_geoUtilTool->extractShape(define.physVol);
41  if (!shape) {
42  ATH_MSG_FATAL("Failed to deduce a valid shape for "<<m_idHelperSvc->toString(define.detElId));
43  return StatusCode::FAILURE;
44  }
47  if (shape->typeID() == GeoTrd::getClassTypeID()) {
48  ATH_MSG_VERBOSE("Extracted shape "<<m_geoUtilTool->dumpShape(shape));
49  const GeoTrd* trd = static_cast<const GeoTrd*>(shape);
50  define.longHalfX = std::max(trd->getYHalfLength1(), trd->getYHalfLength2()) * Gaudi::Units::mm;
51  define.shortHalfX = std::min(trd->getYHalfLength1(), trd->getYHalfLength2())* Gaudi::Units::mm;
52  define.halfY = trd->getZHalfLength()* Gaudi::Units::mm;
53  define.halfHeight = std::max(trd->getXHalfLength1(), trd->getXHalfLength2()) * Gaudi::Units::mm;
54  } else {
55  ATH_MSG_FATAL("Unknown shape type "<<shape->type());
56  return StatusCode::FAILURE;
57  }
61  for (unsigned int ch = 1; ch < define.physVol->getNChildNodes(); ++ch) {
62  const GeoGraphNode* childNode = (*define.physVol->getChildNode(ch));
63  const GeoVPhysVol* childVol = dynamic_cast<const GeoVPhysVol*>(childNode);
64  if (!childVol || childVol->getLogVol()->getName() != "TubeLayerLog") {
65  continue;
66  }
67  const GeoTransform* trfNode = dynamic_cast<const GeoTransform*>(*define.physVol->getChildNode(ch-1));
68  if (!trfNode) {
69  ATH_MSG_FATAL("Expect a GeoTransform node right before the tubelayer node");
70  return StatusCode::FAILURE;
71  }
72  ATH_MSG_VERBOSE("Add new tube layer "<<m_idHelperSvc->toStringDetEl(define.detElId)<<
73  std::endl<<std::endl<<m_geoUtilTool->dumpVolume(childVol));
74 
75  MdtTubeLayerPtr newLay = std::make_unique<MdtTubeLayer>(childVol, trfNode);
76  define.tubeLayers.emplace_back(*facCache.tubeLayers.insert(newLay).first);
77 
78  const MdtTubeLayer& lay{*define.tubeLayers.back()};
81  bool chEndPlug{false};
82  for (unsigned int tube = 0 ; tube < lay.nTubes(); ++tube) {
83  constexpr std::string_view airTubeName{"airTube"};
84  PVConstLink tubeVol{lay.getTubeNode(tube)};
85  if (tubeVol->getLogVol()->getName() == airTubeName) {
86  define.removedTubes.insert(MdtReadoutElement::measurementHash(define.tubeLayers.size(), tube+1));
87  } else if (!chEndPlug) {
89  chEndPlug = true;
90  std::vector<physVolWithTrans> endPlugs = m_geoUtilTool->findAllLeafNodesByName(tubeVol, "Endplug");
91  if (endPlugs.empty()) {
93  continue;
94  }
95  const GeoShape* plugShape = m_geoUtilTool->extractShape(endPlugs[0].volume);
96  if (plugShape->typeID() != GeoTube::getClassTypeID()){
97  ATH_MSG_FATAL("The shape "<<m_geoUtilTool->dumpShape(plugShape)<<" is not a tube");
98  return StatusCode::FAILURE;
99  }
100  const GeoTube* plugTube = static_cast<const GeoTube*>(plugShape);
101  define.endPlugLength = plugTube->getZHalfLength();
102  }
103  }
104  }
105  define.readoutSide = facCache.readoutOnLeftSide.count(m_idHelperSvc->chamberId(define.detElId)) ? -1. : 1.;
106  return StatusCode::SUCCESS;
107 }
109  ATH_CHECK(m_geoDbTagSvc.retrieve());
110  ATH_CHECK(m_idHelperSvc.retrieve());
111  ATH_CHECK(m_geoUtilTool.retrieve());
112  GeoModelIO::ReadGeoModel* sqliteReader = m_geoDbTagSvc->getSqliteReader();
113  if (!sqliteReader) {
114  ATH_MSG_FATAL("Error, the tool works exclusively from sqlite geometry inputs");
115  return StatusCode::FAILURE;
116  }
117  FactoryCache facCache{};
118  ATH_CHECK(readParameterBook(facCache));
119  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
120  // Get the list of full phys volumes from SQLite, and create detector elements
121  physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>("Muon");
122 #ifndef SIMULATIONBASE
123  SurfaceBoundSetPtr<Acts::LineBounds> tubeBounds = std::make_shared<SurfaceBoundSet<Acts::LineBounds>>();
124  SurfaceBoundSetPtr<Acts::TrapezoidBounds> layerBounds = std::make_shared<SurfaceBoundSet<Acts::TrapezoidBounds>>();
125 #endif
126  for (auto& [key, pv] : mapFPV) {
133  std::vector<std::string> key_tokens = tokenize(key, "_");
134  if (key_tokens.size() != 5 ||
135  key_tokens[1].find("MDT") == std::string::npos)
136  continue;
137 
139  bool isValid{false};
140  define.detElId = idHelper.channelID(key_tokens[0].substr(0, 3),
141  atoi(key_tokens[2]),
142  atoi(key_tokens[3]),
143  atoi(key_tokens[4]), 1, 1, isValid);
144  if (!isValid) {
145  ATH_MSG_FATAL("Failed to build a good identifier out of " << key);
146  return StatusCode::FAILURE;
147  }
148  ATH_MSG_DEBUG("Key "<<key<<" brought us "<<m_idHelperSvc->toStringDetEl(define.detElId));
150  define.physVol = pv;
151  define.chambDesign = key_tokens[1];
152  define.alignTransform = m_geoUtilTool->findAlignableTransform(define.physVol);
153 
155  ParamBookTable::const_iterator book_itr = facCache.parBook.find(define.chambDesign);
156  if (book_itr == facCache.parBook.end()) {
157  ATH_MSG_FATAL("There is no chamber called "<<define.chambDesign);
158  return StatusCode::FAILURE;
159  }
160  static_cast<parameterBook&>(define) = book_itr->second;
161 #ifndef SIMULATIONBASE
162  define.tubeBounds = tubeBounds;
163  define.layerBounds = layerBounds;
164  #endif
166  ATH_CHECK(loadDimensions(facCache, define));
167  std::unique_ptr<MdtReadoutElement> mdtDetectorElement = std::make_unique<MdtReadoutElement>(std::move(define));
168  ATH_CHECK(mgr.addMdtReadoutElement(std::move(mdtDetectorElement)));
169  }
170  return StatusCode::SUCCESS;
171 }
173  ServiceHandle<IRDBAccessSvc> accessSvc(m_geoDbTagSvc->getParamSvcName(),
174  name());
175  ATH_CHECK(accessSvc.retrieve());
176  IRDBRecordset_ptr paramTable = accessSvc->getRecordsetPtr("WMDT", "");
177  if (paramTable->size() == 0) {
178  ATH_MSG_FATAL("Empty parameter book table found");
179  return StatusCode::FAILURE;
180  }
181  ATH_MSG_VERBOSE("Found the " << paramTable->nodeName() << " ["
182  << paramTable->tagName() << "] table with "
183  << paramTable->size() << " records");
184  for (const IRDBRecord_ptr& record : *paramTable) {
186  pars.tubeWall = record->getDouble("TUBWAL") * Gaudi::Units::cm;
187  pars.tubePitch = record->getDouble("TUBPIT") * Gaudi::Units::cm;
188  pars.tubeInnerRad = record->getDouble("TUBRAD") * Gaudi::Units::cm;
189  pars.endPlugLength = record->getDouble("TUBDEA") * Gaudi::Units::cm;
190  pars.radLengthX0 = record->getDouble("X0");
191  unsigned int nLay = record->getInt("LAYMDT");
192  const std::string key {record->getString("WMDT_TYPE")};
193  ATH_MSG_DEBUG("Extracted parameters " <<pars<<" number of layers: "<<nLay<<" will be safed under key "<<key);
194  cache.parBook[key] = std::move(pars);
195  }
197  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
198  paramTable = accessSvc->getRecordsetPtr("MdtTubeROSides" ,"");
199  if (paramTable->size() == 0) {
200  ATH_MSG_FATAL("Empty parameter book table found");
201  return StatusCode::FAILURE;
202  }
203  ATH_MSG_VERBOSE("Found the " << paramTable->nodeName() << " ["
204  << paramTable->tagName() << "] table with "
205  << paramTable->size() << " records");
206  for (const IRDBRecord_ptr& record : *paramTable) {
207  const std::string stName = record->getString("stationName");
208  const int stEta = record->getInt("stationEta");
209  const int stPhi = record->getInt("stationPhi");
210  const int side = record->getInt("side");
211  if (side == -1) {
212  bool isValid{false};
213  cache.readoutOnLeftSide.insert(idHelper.elementID(stName,stEta,stPhi, isValid));
214  if (!isValid) {
215  ATH_MSG_FATAL("station "<<stName<<" eta: "<<stEta<<" phi: "<<stPhi<<" is unknown.");
216  return StatusCode::FAILURE;
217  }
218  }
219  }
220  return StatusCode::SUCCESS;
221 }
222 
223 } // namespace MuonGMR4
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
MuonGMR4::MdtReadoutGeomTool::FactoryCache::tubeLayers
MdtTubeLayerSet tubeLayers
Definition: MdtReadoutGeomTool.h:45
MuonGMR4::MdtReadoutElement::parameterBook::tubeBounds
ActsTrk::SurfaceBoundSetPtr< Acts::LineBounds > tubeBounds
Sets of surface bounds which is shared amongst all readout elements used to assign the same bound obj...
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:62
MuonGMR4::MdtReadoutElement::parameterBook::removedTubes
std::set< IdentifierHash > removedTubes
List of tube places without tubes.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:28
max
#define max(a, b)
Definition: cfImp.cxx:41
MuonGMR4::MuonDetectorManager
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:61
MdtReadoutGeomTool.h
MuonGMR4::MdtReadoutElement::parameterBook::tubeLayers
std::vector< MdtTubeLayerPtr > tubeLayers
Vector defining the position of all tubes in each tube layer.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:25
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
MuonGMR4::MdtReadoutElement::parameterBook::halfHeight
double halfHeight
Height of the chamber ~ number of layers.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:56
MuonGMR4::MdtReadoutElement::measurementHash
static IdentifierHash measurementHash(unsigned int layerNumber, unsigned int tubeNumber)
Transform the layer and tube number to the measurementHash.
MuonGMR4::MdtReadoutGeomTool::FactoryCache
Definition: MdtReadoutGeomTool.h:39
MuonGMR4::MdtTubeLayer
Helper struct to retrieve the tube lengths and the tube centers directly from the GeoModel tree.
Definition: MdtTubeLayer.h:28
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
MuonGMR4::MdtReadoutGeomTool::m_geoDbTagSvc
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
Definition: MdtReadoutGeomTool.h:32
MuonGMR4::MdtReadoutGeomTool::readParameterBook
StatusCode readParameterBook(FactoryCache &facCache) const
Retrieves the auxillary tables from the database.
Definition: MdtReadoutGeomTool.cxx:172
MuonGMR4::MdtReadoutGeomTool::m_geoUtilTool
PublicToolHandle< IMuonGeoUtilityTool > m_geoUtilTool
Definition: MdtReadoutGeomTool.h:35
MuonGMR4::MdtReadoutElement::parameterBook::readoutSide
double readoutSide
Is the readout chip at positive or negative Z?
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:58
TRT::Hit::side
@ side
Definition: HitInfo.h:83
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
MuonGMR4::MdtReadoutElement::parameterBook::halfY
double halfY
Length ~ number of tubes.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:54
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
MuonGMR4
A muon chamber is a collection of readout elements belonging to the same station.
Definition: ChamberAssembleTool.h:16
EventPrimitivesToStringConverter.h
MuonGMR4::MdtReadoutElement::parameterBook
Set of parameters to describe a MDT chamber.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:20
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
CxxUtils
Definition: aligned_vector.h:29
MuonDetectorManager.h
MdtIdHelper
Definition: MdtIdHelper.h:61
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
min
#define min(a, b)
Definition: cfImp.cxx:40
MuonGMR4::MdtReadoutGeomTool::FactoryCache::readoutOnLeftSide
std::set< Identifier > readoutOnLeftSide
List of chambers that have the readout chip at negative Z.
Definition: MdtReadoutGeomTool.h:43
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
MuonGMR4::MdtReadoutGeomTool::buildReadOutElements
StatusCode buildReadOutElements(MuonDetectorManager &mgr) override final
Retrieves the GeoModel from the GeoModelSvc and append the ReadoutElements of the Given MuonDetectorT...
Definition: MdtReadoutGeomTool.cxx:108
MuonGMR4::MdtReadoutGeomTool::loadDimensions
StatusCode loadDimensions(FactoryCache &facCache, MdtReadoutElement::defineArgs &args) const
Loads the chamber dimensions from GeoModel.
Definition: MdtReadoutGeomTool.cxx:35
MuonGMR4::physVolWithTrans
IMuonGeoUtilityTool::physVolWithTrans physVolWithTrans
Definition: MdtReadoutGeomTool.cxx:25
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
MuonGMR4::MdtReadoutElement::parameterBook::endPlugLength
double endPlugLength
Depth of the endplug into the active tube volume.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:39
MuonGMR4::MdtReadoutElement::parameterBook::shortHalfX
double shortHalfX
The chambers have either a rectangular or a trapezoidal shape to first approximation.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:51
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
GeoPrimitivesHelpers.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IRDBRecord_ptr
std::unique_ptr< IRDBRecord > IRDBRecord_ptr
Definition: IRDBRecordset.h:23
python.changerun.pv
pv
Definition: changerun.py:81
MuonGMR4::MdtReadoutElement::parameterBook::longHalfX
double longHalfX
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:52
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
MuonGMR4::MuonReadoutElement::defineArgs::detElId
Identifier detElId
ATLAS identifier.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:51
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:34
ActsTrk::SurfaceBoundSetPtr
std::shared_ptr< SurfaceBoundSet< BoundType > > SurfaceBoundSetPtr
Aberivation to create a new SurfaceBoundSetPtr.
Definition: SurfaceBoundSet.h:50
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
AthAlgTool
Definition: AthAlgTool.h:26
MuonGMR4::IMuonReadoutGeomTool::physNodeMap
std::map< std::string, GeoFullPhysVol * > physNodeMap
Definition: IMuonReaoutGeomTool.h:25
MuonGMR4::MuonReadoutElement::defineArgs::physVol
GeoIntrusivePtr< GeoVFullPhysVol > physVol
Pointer to the underlying physical volume in GeoModel.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:45
calibdata.tube
tube
Definition: calibdata.py:31
MuonGMR4::MdtReadoutGeomTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtReadoutGeomTool.h:29
ServiceHandle< IRDBAccessSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MuonGMR4::MdtReadoutElement::defineArgs
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:69
MuonGMR4::MdtReadoutGeomTool::FactoryCache::parBook
ParamBookTable parBook
Definition: MdtReadoutGeomTool.h:40