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>
44 unsigned int doubPhi{0};
51 if (std::abs(cA.x() - cB.x()) >
tolerance)
return (cA.x() < cB.x());
52 return (cA.y() < cB.y());
56 RpcReadoutGeomTool::RpcReadoutGeomTool(
const std::string&
type,
57 const std::string&
name,
60 declareInterface<IMuonReadoutGeomTool>(
this);
72 return StatusCode::FAILURE;
76 if (shape->typeID() != GeoBox::getClassTypeID()) {
78 return StatusCode::FAILURE;
81 const GeoBox* box =
static_cast<const GeoBox*
>(shape);
95 std::vector<physVolWithTrans> stripLayers =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"bottomStripLayer");
96 if (stripLayers.empty()) {
99 return StatusCode::FAILURE;
101 std::vector<physVolWithTrans> allGasGaps =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"RpcGasGap");
102 if (allGasGaps.empty()) {
105 return StatusCode::FAILURE;
108 std::stable_sort(allGasGaps.begin(), allGasGaps.end(),
layerSorter);
109 std::stable_sort(stripLayers.begin(),stripLayers.end(),
layerSorter);
115 const Amg::Vector3D stripTrans = stripLayer.transform.translation();
118 return std::abs(stripTrans.x() - a.transform.translation().x()) <
119 std::abs(stripTrans.x() - b.transform.translation().x());
121 stripLayer.transform.translation().x() = closestGap->transform.translation().x();
126 Amg::Vector3D prevGap{stripLayers[0].transform.translation()};
130 std::vector<gapVolume> allGapsWithIdx{};
135 if (std::abs(gCen.x() - prevGap.x()) >
tolerance) {
140 prevGap = std::move(gCen);
154 return StatusCode::FAILURE;
156 const wRPCTable& paramBook{parBookItr->second};
158 for (
gapVolume& gapVol : allGapsWithIdx) {
159 const GeoShape* gapShape =
m_geoUtilTool->extractShape(gapVol.volume);
160 if (gapShape->typeID() != GeoBox::getClassTypeID()) {
162 return StatusCode::FAILURE;
164 const GeoBox* gapBox =
static_cast<const GeoBox*
>(gapShape);
168 const double firstStripPosEta = -gapBox->getZHalfLength() + paramBook.firstOffSetEta;
169 etaDesign->defineStripLayout(firstStripPosEta * Amg::Vector2D::UnitX(),
170 paramBook.stripPitchEta,
171 paramBook.stripWidthEta,
172 paramBook.numEtaStrips);
174 etaDesign->defineTrapezoid(gapBox->getYHalfLength(), gapBox->getYHalfLength(), gapBox->getZHalfLength());
177 etaDesign = (*factoryCache.
stripDesigns.emplace(etaDesign).first);
179 const unsigned int etaIdx =
static_cast<unsigned int>(etaHash);
180 if (etaIdx >= define.
layers.size()) {
181 define.
layers.resize(etaIdx + 1);
184 auto etaLayer = std::make_unique<StripLayer>(gapVol.transform, etaDesign, etaHash);
185 define.
layers[etaIdx] = (*factoryCache.
stripLayers.emplace(std::move(etaLayer)).first);
190 if (!paramBook.numPhiStrips) {
195 const double firstStripPosPhi = -gapBox->getYHalfLength() + paramBook.firstOffSetPhi;
196 phiDesign->defineStripLayout(firstStripPosPhi * Amg::Vector2D::UnitX(),
197 paramBook.stripPitchPhi,
198 paramBook.stripWidthPhi,
199 paramBook.numPhiStrips);
200 phiDesign->defineTrapezoid(gapBox->getZHalfLength(), gapBox->getZHalfLength(), gapBox->getYHalfLength());
202 phiDesign = (*factoryCache.
stripDesigns.emplace(phiDesign).first);
205 const unsigned int phiIdx =
static_cast<unsigned int>(phiHash);
206 if (phiIdx >= define.
layers.size()) {
207 define.
layers.resize(phiIdx + 1);
211 define.
layers[phiIdx] = (*factoryCache.
stripLayers.emplace(std::move(phiLayer)).first);
215 return StatusCode::SUCCESS;
218 GeoModelIO::ReadGeoModel* sqliteReader =
m_geoDbTagSvc->getSqliteReader();
220 ATH_MSG_FATAL(
"Error, the tool works exclusively from sqlite geometry inputs");
221 return StatusCode::FAILURE;
231 physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>(
"Muon");
232 #ifndef SIMULATIONBASE
235 for (
auto& [
key,
pv] : mapFPV) {
242 std::vector<std::string> key_tokens =
tokenize(
key,
"_");
243 if (key_tokens.size() < 7 ||
244 key_tokens[1].find(
"RPC") == std::string::npos) {
249 const Identifier elementID = idHelper.padID(idHelper.stationNameIndex(key_tokens[0].substr(0, 3)),
258 return StatusCode::FAILURE;
262 define.chambDesign = key_tokens[1];
263 define.alignTransform =
m_geoUtilTool->findAlignableTransform(define.physVol);
264 define.detElId = elementID;
267 #ifndef SIMULATIONBASE
268 define.layerBounds = layerBounds;
270 std::unique_ptr<RpcReadoutElement> readoutEle = std::make_unique<RpcReadoutElement>(std::move(define));
271 ATH_CHECK(
mgr.addRpcReadoutElement(std::move(readoutEle)));
273 return StatusCode::SUCCESS;
279 if (paramTable->size() == 0) {
281 return StatusCode::FAILURE;
284 << paramTable->tagName() <<
"] table with "
285 << paramTable->size() <<
" records");
288 const std::string chambType = record->getString(
"WRPC_TYPE");
292 const double stripDeadWidth = record->getDouble(
"stripDeadWidth") *
Gaudi::Units::cm;
308 <<
", etaStripOffSet: "<<(record->getDouble(
"etaStripOffSet") *
Gaudi::Units::cm)
309 <<
", phiStripOffSet: "<<(record->getDouble(
"phiStripOffSet") *
Gaudi::Units::cm)
312 return StatusCode::SUCCESS;