7 #include <GaudiKernel/SystemOfUnits.h>
13 #include <GeoModelKernel/GeoFullPhysVol.h>
14 #include <GeoModelKernel/GeoPhysVol.h>
15 #include <GeoModelKernel/GeoTrd.h>
16 #include <GeoModelKernel/GeoBox.h>
18 #include <GeoModelRead/ReadGeoModel.h>
23 #ifndef SIMULATIONBASE
24 # include "Acts/Surfaces/TrapezoidBounds.hpp"
49 unsigned int doubPhi{0};
56 if (std::abs(cA.x() - cB.x()) >
tolerance)
return (cA.x() < cB.x());
57 return (cA.y() < cB.y());
61 RpcReadoutGeomTool::RpcReadoutGeomTool(
const std::string&
type,
62 const std::string&
name,
75 return StatusCode::FAILURE;
79 if (shape->typeID() != GeoBox::getClassTypeID()) {
81 return StatusCode::FAILURE;
84 const GeoBox* box =
static_cast<const GeoBox*
>(shape);
98 std::vector<physVolWithTrans> stripLayers =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"bottomStripLayer");
99 if (stripLayers.empty()) {
102 return StatusCode::FAILURE;
104 std::vector<physVolWithTrans> allGasGaps =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"RpcGasGap");
105 if (allGasGaps.empty()) {
108 return StatusCode::FAILURE;
111 std::stable_sort(allGasGaps.begin(), allGasGaps.end(),
layerSorter);
112 std::stable_sort(stripLayers.begin(),stripLayers.end(),
layerSorter);
118 const Amg::Vector3D stripTrans = stripLayer.transform.translation();
121 return std::abs(stripTrans.x() - a.transform.translation().x()) <
122 std::abs(stripTrans.x() - b.transform.translation().x());
124 stripLayer.transform.translation().x() = closestGap->transform.translation().x();
129 Amg::Vector3D prevGap{stripLayers[0].transform.translation()};
133 std::vector<gapVolume> allGapsWithIdx{};
138 if (std::abs(gCen.x() - prevGap.x()) >
tolerance) {
143 prevGap = std::move(gCen);
157 return StatusCode::FAILURE;
159 const wRPCTable& paramBook{parBookItr->second};
161 for (
gapVolume& gapVol : allGapsWithIdx) {
162 const GeoShape* gapShape =
m_geoUtilTool->extractShape(gapVol.volume);
163 if (gapShape->typeID() != GeoBox::getClassTypeID()) {
165 return StatusCode::FAILURE;
167 const GeoBox* gapBox =
static_cast<const GeoBox*
>(gapShape);
171 const double firstStripPosEta = -gapBox->getZHalfLength() + paramBook.firstOffSetEta;
172 etaDesign->defineStripLayout(firstStripPosEta * Amg::Vector2D::UnitX(),
173 paramBook.stripPitchEta,
174 paramBook.stripWidthEta,
175 paramBook.numEtaStrips);
177 etaDesign->defineTrapezoid(gapBox->getYHalfLength(), gapBox->getYHalfLength(), gapBox->getZHalfLength());
180 etaDesign = (*factoryCache.
stripDesigns.emplace(etaDesign).first);
182 const unsigned int etaIdx =
static_cast<unsigned int>(etaHash);
183 if (etaIdx >= define.
layers.size()) {
184 define.
layers.resize(etaIdx + 1);
187 auto etaLayer = std::make_unique<StripLayer>(gapVol.transform, etaDesign, etaHash);
188 define.
layers[etaIdx] = (*factoryCache.
stripLayers.emplace(std::move(etaLayer)).first);
193 if (!paramBook.numPhiStrips) {
198 const double firstStripPosPhi = -gapBox->getYHalfLength() + paramBook.firstOffSetPhi;
199 phiDesign->defineStripLayout(firstStripPosPhi * Amg::Vector2D::UnitX(),
200 paramBook.stripPitchPhi,
201 paramBook.stripWidthPhi,
202 paramBook.numPhiStrips);
203 phiDesign->defineTrapezoid(gapBox->getZHalfLength(), gapBox->getZHalfLength(), gapBox->getYHalfLength());
205 phiDesign = (*factoryCache.
stripDesigns.emplace(phiDesign).first);
208 const unsigned int phiIdx =
static_cast<unsigned int>(phiHash);
209 if (phiIdx >= define.
layers.size()) {
210 define.
layers.resize(phiIdx + 1);
214 define.
layers[phiIdx] = (*factoryCache.
stripLayers.emplace(std::move(phiLayer)).first);
218 return StatusCode::SUCCESS;
221 GeoModelIO::ReadGeoModel* sqliteReader =
m_geoDbTagSvc->getSqliteReader();
223 ATH_MSG_FATAL(
"Error, the tool works exclusively from sqlite geometry inputs");
224 return StatusCode::FAILURE;
234 physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>(
"Muon");
235 #ifndef SIMULATIONBASE
238 for (
auto& [
key,
pv] : mapFPV) {
245 std::vector<std::string> key_tokens =
tokenize(
key,
"_");
246 if (key_tokens.size() < 7 ||
247 key_tokens[1].find(
"RPC") == std::string::npos) {
252 const Identifier elementID = idHelper.padID(idHelper.stationNameIndex(key_tokens[0].substr(0, 3)),
261 return StatusCode::FAILURE;
265 define.chambDesign = key_tokens[1];
266 define.alignTransform =
m_geoUtilTool->findAlignableTransform(define.physVol);
267 define.detElId = elementID;
270 #ifndef SIMULATIONBASE
271 define.layerBounds = layerBounds;
273 std::unique_ptr<RpcReadoutElement> readoutEle = std::make_unique<RpcReadoutElement>(std::move(define));
274 ATH_CHECK(
mgr.addRpcReadoutElement(std::move(readoutEle)));
276 return StatusCode::SUCCESS;
282 if (paramTable->size() == 0) {
284 return StatusCode::FAILURE;
287 << paramTable->tagName() <<
"] table with "
288 << paramTable->size() <<
" records");
291 const std::string chambType = record->getString(
"WRPC_TYPE");
295 const double stripDeadWidth = record->getDouble(
"stripDeadWidth") *
Gaudi::Units::cm;
311 <<
", etaStripOffSet: "<<(record->getDouble(
"etaStripOffSet") *
Gaudi::Units::cm)
312 <<
", phiStripOffSet: "<<(record->getDouble(
"phiStripOffSet") *
Gaudi::Units::cm)
315 return StatusCode::SUCCESS;