7 #include <GaudiKernel/SystemOfUnits.h>
13 #include <GeoModelKernel/GeoFullPhysVol.h>
14 #include <GeoModelKernel/GeoPhysVol.h>
15 #include <GeoModelKernel/GeoTrd.h>
16 #include <GeoModelKernel/GeoTube.h>
18 #include <GeoModelRead/ReadGeoModel.h>
24 #ifndef SIMULATIONBASE
25 # include "Acts/Surfaces/TrapezoidBounds.hpp"
26 # include "Acts/Surfaces/LineBounds.hpp"
36 MdtReadoutGeomTool::MdtReadoutGeomTool(
const std::string&
type,
37 const std::string&
name,
49 return StatusCode::FAILURE;
53 if (shape->typeID() == GeoTrd::getClassTypeID()) {
55 const GeoTrd* trd =
static_cast<const GeoTrd*
>(shape);
62 return StatusCode::FAILURE;
68 for (
unsigned int ch = 1;
ch < define.
physVol->getNChildNodes(); ++
ch) {
69 const GeoGraphNode* childNode = (*define.
physVol->getChildNode(
ch));
70 const GeoVPhysVol* childVol =
dynamic_cast<const GeoVPhysVol*
>(childNode);
71 if (!childVol || childVol->getLogVol()->getName() !=
"TubeLayerLog") {
74 const GeoTransform* trfNode =
dynamic_cast<const GeoTransform*
>(*define.
physVol->getChildNode(
ch-1));
76 ATH_MSG_FATAL(
"Expect a GeoTransform node right before the tubelayer node");
77 return StatusCode::FAILURE;
82 idHelper.multilayer(define.
detElId),
90 bool chEndPlug{
false};
91 for (
unsigned int tube = 0 ;
tube < lay.nTubes(); ++
tube) {
92 constexpr std::string_view airTubeName{
"airTube"};
93 PVConstLink tubeVol{lay.getTubeNode(
tube)};
94 if (tubeVol->getLogVol()->getName() == airTubeName) {
96 }
else if (!chEndPlug) {
99 std::vector<physVolWithTrans> endPlugs =
m_geoUtilTool->findAllLeafNodesByName(tubeVol,
"Endplug");
100 if (endPlugs.empty()) {
104 const GeoShape* plugShape =
m_geoUtilTool->extractShape(endPlugs[0].volume);
105 if (plugShape->typeID() != GeoTube::getClassTypeID()){
107 return StatusCode::FAILURE;
109 const GeoTube* plugTube =
static_cast<const GeoTube*
>(plugShape);
115 return StatusCode::SUCCESS;
121 GeoModelIO::ReadGeoModel* sqliteReader =
m_geoDbTagSvc->getSqliteReader();
123 ATH_MSG_FATAL(
"Error, the tool works exclusively from sqlite geometry inputs");
124 return StatusCode::FAILURE;
130 physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>(
"Muon");
131 #ifndef SIMULATIONBASE
135 for (
auto& [
key,
pv] : mapFPV) {
142 std::vector<std::string> key_tokens =
tokenize(
key,
"_");
143 if (key_tokens.size() != 5 ||
144 key_tokens[1].find(
"MDT") == std::string::npos)
149 define.detElId = idHelper.channelID(key_tokens[0].substr(0, 3),
155 return StatusCode::FAILURE;
160 define.chambDesign = key_tokens[1];
161 define.alignTransform =
m_geoUtilTool->findAlignableTransform(define.physVol);
164 ParamBookTable::const_iterator book_itr = facCache.parBook.find(define.chambDesign);
165 if (book_itr == facCache.parBook.end()) {
166 ATH_MSG_FATAL(
"There is no chamber called "<<define.chambDesign);
167 return StatusCode::FAILURE;
170 #ifndef SIMULATIONBASE
172 define.layerBounds = layerBounds;
176 std::unique_ptr<MdtReadoutElement> mdtDetectorElement = std::make_unique<MdtReadoutElement>(std::move(define));
177 ATH_CHECK(
mgr.addMdtReadoutElement(std::move(mdtDetectorElement)));
179 return StatusCode::SUCCESS;
186 if (paramTable->size() == 0) {
188 return StatusCode::FAILURE;
191 << paramTable->tagName() <<
"] table with "
192 << paramTable->size() <<
" records");
199 pars.radLengthX0 = record->getDouble(
"X0");
200 unsigned int nLay = record->getInt(
"LAYMDT");
201 const std::string
key {record->getString(
"WMDT_TYPE")};
202 ATH_MSG_DEBUG(
"Extracted parameters " <<
pars<<
" number of layers: "<<nLay<<
" will be safed under key "<<
key);
207 paramTable = accessSvc->getRecordsetPtr(
"MdtTubeROSides" ,
"");
208 if (paramTable->size() == 0) {
210 return StatusCode::FAILURE;
213 << paramTable->tagName() <<
"] table with "
214 << paramTable->size() <<
" records");
216 const std::string stName = record->getString(
"stationName");
217 const int stEta = record->getInt(
"stationEta");
218 const int stPhi = record->getInt(
"stationPhi");
219 const int side = record->getInt(
"side");
224 ATH_MSG_FATAL(
"station "<<stName<<
" eta: "<<stEta<<
" phi: "<<stPhi<<
" is unknown.");
225 return StatusCode::FAILURE;
230 paramTable = accessSvc->getRecordsetPtr(
"MdtCutTubes" ,
"");
231 if (paramTable->size() == 0) {
232 ATH_MSG_INFO(
"No information about cut mdt tubes has been found. Skipping.");
233 return StatusCode::SUCCESS;
236 const std::string stName = record->getString(
"stationName");
237 const int stEta = record->getInt(
"stationEta");
238 const int stPhi = record->getInt(
"stationPhi");
239 const int multiLay = record->getInt(
"multiLayer");
240 const int tubeLay = record->getInt(
"tubeLayer");
242 const Identifier tubeId = idHelper.channelID(stName, stEta, stPhi, multiLay, tubeLay, 1 ,
isValid);
244 ATH_MSG_FATAL(
"Failed to deduce valid Idnetifier "<<stName<<
", "<<stEta<<
", "<<stPhi<<
","<<multiLay<<
", "<<tubeLay);
245 return StatusCode::FAILURE;
249 cutTubes.
firstTube = record->getInt(
"firstTube");
250 cutTubes.lastTube = record->getInt(
"lastTube");
251 cutTubes.unCutHalfLength = record->getDouble(
"uncutHalfLength");
253 <<cutTubes.firstTube<<
"-"<<cutTubes.lastTube<<
"], length: "<< 2.*cutTubes.unCutHalfLength );
254 cache.
cutTubes[tubeId].insert(std::move(cutTubes));
257 return StatusCode::SUCCESS;