7 #include <GaudiKernel/SystemOfUnits.h>
11 #include <GeoModelKernel/GeoFullPhysVol.h>
12 #include <GeoModelKernel/GeoPhysVol.h>
13 #include <GeoModelKernel/GeoTrd.h>
14 #include <GeoModelKernel/GeoBox.h>
16 #include <GeoModelRead/ReadGeoModel.h>
35 TgcReadoutGeomTool::TgcReadoutGeomTool(
const std::string&
type,
36 const std::string&
name,
39 declareInterface<IMuonReadoutGeomTool>(
this);
49 return StatusCode::FAILURE;
52 if (shape->typeID() != GeoTrd::getClassTypeID()) {
54 <<
" is expected to be a trapezoid "<<
m_geoUtilTool->dumpShape(shape));
55 return StatusCode::FAILURE;
57 const GeoTrd* chambTrd =
static_cast<const GeoTrd*
>(shape);
60 define.
halfHeight = chambTrd->getZHalfLength();
63 std::vector<physVolWithTrans> allGasGaps =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"TgcGas");
64 if (allGasGaps.empty()) {
67 return StatusCode::FAILURE;
71 std::stringstream
key{};
78 if (!stripLayout || !wireLayout) {
84 return StatusCode::FAILURE;
86 const GeoShape* gapShape =
m_geoUtilTool->extractShape(pVolTrans.volume);
87 if (gapShape->typeID() != GeoTrd::getClassTypeID()) {
89 <<
" to be a trapezoid");
90 return StatusCode::FAILURE;
92 const GeoTrd* gapTrd =
static_cast<const GeoTrd*
>(gapShape);
94 const double halfMinX =
std::min(gapTrd->getYHalfLength1(), gapTrd->getYHalfLength2());
95 const double halfMaxX =
std::max(gapTrd->getYHalfLength1(), gapTrd->getYHalfLength2());
96 const double halfY = gapTrd->getZHalfLength();
98 if (!wireLayout &&
table.wireGangs.size()) {
100 wireGrp->defineTrapezoid(halfMinX, halfMaxX, halfY);
101 for (
unsigned int gang :
table.wireGangs) {
102 wireGrp->declareGroup(gang);
104 const double wireOffSet = -0.5*
table.wirePitch * wireGrp->nAllWires();
113 wireLayout = std::make_unique<StripLayer>(trans, (*factoryCache.
wireLayouts.insert(std::move(wireGrp)).first),
hash);
115 if (!stripLayout &&
table.bottomStripPos.size()) {
117 radDesign->defineTrapezoid(halfMinX, halfMaxX, halfY);
119 0.,0.,
table.bottomStripPos.size());
120 radDesign->flipTrapezoid();
121 for (
size_t s = 0;
s <
table.bottomStripPos.size(); ++
s) {
122 radDesign->addStrip(
table.bottomStripPos.at(
s),
130 stripLayout = std::make_unique<StripLayer>(trans, (*factoryCache.
stripLayouts.insert(std::move(radDesign)).first),
hash);
135 unsigned int stripIdx =
static_cast<unsigned>(stripLayout->hash());
138 return StatusCode::FAILURE;
143 unsigned int wireIdx =
static_cast<unsigned>(wireLayout->hash());
146 return StatusCode::FAILURE;
152 return StatusCode::SUCCESS;
158 GeoModelIO::ReadGeoModel* sqliteReader =
m_geoDbTagSvc->getSqliteReader();
160 ATH_MSG_FATAL(
"Error, the tool works exclusively from sqlite geometry inputs");
161 return StatusCode::FAILURE;
167 #ifndef SIMULATIONBASE
173 physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>(
"Muon");
174 for (
auto& [
key,
pv] : mapFPV) {
178 std::vector<std::string> key_tokens =
tokenize(
key,
"_");
179 if (key_tokens.size() < 4 ||
184 const Identifier elementID = idHelper.elementID(key_tokens[1].substr(0,3),
atoi(key_tokens[2]),
atoi(key_tokens[3]),
isValid);
188 return StatusCode::FAILURE;
192 define.detElId = elementID;
193 define.chambDesign = key_tokens[0];
194 define.alignTransform =
m_geoUtilTool->findAlignableTransform(define.physVol);
195 #ifndef SIMULATIONBASE
196 define.layerBounds = layerBounds;
200 std::unique_ptr<TgcReadoutElement> readoutEle = std::make_unique<TgcReadoutElement>(std::move(define));
201 ATH_CHECK(
mgr.addTgcReadoutElement(std::move(readoutEle)));
204 return StatusCode::SUCCESS;
208 std::vector<const TgcReadoutElement*> tgcReadOutEles =
mgr.getAllTgcReadoutElements();
209 std::unique_ptr<std::vector<int>> tgcSectorMapping = std::make_unique<std::vector<int>>();
210 tgcSectorMapping->resize(
m_idHelperSvc->tgcIdHelper().module_hash_max());
214 int& sectNumb = (*tgcSectorMapping)[
m_idHelperSvc->moduleHash(readoutEle->identify())];
215 sectNumb = sectorMapping.getSector(readoutEle->center(gctx).phi());
218 return StatusCode::SUCCESS;
223 IRDBRecordset_ptr paramTable = accessSvc->getRecordsetPtr(
"TgcSensorLayout",
"");
224 if (paramTable->size() == 0) {
226 return StatusCode::FAILURE;
229 const std::string chambType = record->getString(
"technology");
230 const int gasGap = record->getInt(
"gasGap");
231 const std::vector<int> wireGangs{
tokenizeInt(record->getString(
"wireGangs"),
",")};
232 const std::vector<double> botStrips =
tokenizeDouble(record->getString(
"bottomStrips"),
",");
233 const std::vector<double> topStrips =
tokenizeDouble(record->getString(
"topStrips"),
",");
234 const std::vector<std::string> sides =
tokenize(record->getString(
"side"),
";");
235 const double wirePitch = record->getDouble(
"wirePitch");
236 for (
const std::string&
side : sides) {
237 std::stringstream
key{};
240 parBook.wireGangs.insert(parBook.wireGangs.end(), wireGangs.begin(), wireGangs.end());
241 parBook.bottomStripPos = botStrips;
242 parBook.topStripPos = topStrips;
243 parBook.wirePitch = wirePitch;
249 return StatusCode::SUCCESS;