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>
26 #ifndef SIMULATIONBASE
27 # include "Acts/Surfaces/TrapezoidBounds.hpp"
39 TgcReadoutGeomTool::TgcReadoutGeomTool(
const std::string&
type,
40 const std::string&
name,
50 return StatusCode::FAILURE;
53 if (shape->typeID() != GeoTrd::getClassTypeID()) {
55 <<
" is expected to be a trapezoid "<<
m_geoUtilTool->dumpShape(shape));
56 return StatusCode::FAILURE;
58 const GeoTrd* chambTrd =
static_cast<const GeoTrd*
>(shape);
61 define.
halfHeight = chambTrd->getZHalfLength();
64 std::vector<physVolWithTrans> allGasGaps =
m_geoUtilTool->findAllLeafNodesByName(define.
physVol,
"TgcGas");
65 if (allGasGaps.empty()) {
68 return StatusCode::FAILURE;
72 std::stringstream
key{};
79 if (!stripLayout || !wireLayout) {
85 return StatusCode::FAILURE;
87 const GeoShape* gapShape =
m_geoUtilTool->extractShape(pVolTrans.volume);
88 if (gapShape->typeID() != GeoTrd::getClassTypeID()) {
90 <<
" to be a trapezoid");
91 return StatusCode::FAILURE;
93 const GeoTrd* gapTrd =
static_cast<const GeoTrd*
>(gapShape);
95 const double halfMinX =
std::min(gapTrd->getYHalfLength1(), gapTrd->getYHalfLength2());
96 const double halfMaxX =
std::max(gapTrd->getYHalfLength1(), gapTrd->getYHalfLength2());
97 const double halfY = gapTrd->getZHalfLength();
99 if (!wireLayout &&
table.wireGangs.size()) {
101 wireGrp->defineTrapezoid(halfMinX, halfMaxX, halfY);
102 for (
unsigned int gang :
table.wireGangs) {
103 wireGrp->declareGroup(gang);
105 const double wireOffSet = -0.5*
table.wirePitch * wireGrp->nAllWires();
114 wireLayout = std::make_unique<StripLayer>(trans, (*factoryCache.
wireLayouts.insert(std::move(wireGrp)).first),
hash);
116 if (!stripLayout &&
table.bottomStripPos.size()) {
118 radDesign->defineTrapezoid(halfMinX, halfMaxX, halfY);
120 0.,0.,
table.bottomStripPos.size());
121 radDesign->flipTrapezoid();
122 for (
size_t s = 0;
s <
table.bottomStripPos.size(); ++
s) {
123 radDesign->addStrip(
table.bottomStripPos.at(
s),
131 stripLayout = std::make_unique<StripLayer>(trans, (*factoryCache.
stripLayouts.insert(std::move(radDesign)).first),
hash);
136 unsigned int stripIdx =
static_cast<unsigned>(stripLayout->hash());
139 return StatusCode::FAILURE;
144 unsigned int wireIdx =
static_cast<unsigned>(wireLayout->hash());
147 return StatusCode::FAILURE;
153 return StatusCode::SUCCESS;
159 GeoModelIO::ReadGeoModel* sqliteReader =
m_geoDbTagSvc->getSqliteReader();
161 ATH_MSG_FATAL(
"Error, the tool works exclusively from sqlite geometry inputs");
162 return StatusCode::FAILURE;
168 #ifndef SIMULATIONBASE
174 physNodeMap mapFPV = sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>(
"Muon");
175 for (
auto& [
key,
pv] : mapFPV) {
179 std::vector<std::string> key_tokens =
tokenize(
key,
"_");
180 if (key_tokens.size() < 4 ||
181 !key_tokens[0].starts_with(
"TGC"))
185 const Identifier elementID = idHelper.elementID(key_tokens[1].substr(0,3),
atoi(key_tokens[2]),
atoi(key_tokens[3]),
isValid);
189 return StatusCode::FAILURE;
193 define.detElId = elementID;
194 define.chambDesign = key_tokens[0];
195 define.alignTransform =
m_geoUtilTool->findAlignableTransform(define.physVol);
196 #ifndef SIMULATIONBASE
197 define.layerBounds = layerBounds;
201 std::unique_ptr<TgcReadoutElement> readoutEle = std::make_unique<TgcReadoutElement>(std::move(define));
202 ATH_CHECK(
mgr.addTgcReadoutElement(std::move(readoutEle)));
205 return StatusCode::SUCCESS;
209 std::vector<const TgcReadoutElement*> tgcReadOutEles =
mgr.getAllTgcReadoutElements();
210 std::unique_ptr<std::vector<int>> tgcSectorMapping = std::make_unique<std::vector<int>>();
211 tgcSectorMapping->resize(
m_idHelperSvc->tgcIdHelper().module_hash_max());
215 int& sectNumb = (*tgcSectorMapping)[
m_idHelperSvc->moduleHash(readoutEle->identify())];
216 sectNumb = sectorMapping.getSector(readoutEle->center(gctx).phi());
219 return StatusCode::SUCCESS;
224 IRDBRecordset_ptr paramTable = accessSvc->getRecordsetPtr(
"TgcSensorLayout",
"");
225 if (paramTable->size() == 0) {
227 return StatusCode::FAILURE;
230 const std::string chambType = record->getString(
"technology");
231 const int gasGap = record->getInt(
"gasGap");
232 const std::vector<int> wireGangs{
tokenizeInt(record->getString(
"wireGangs"),
",")};
233 const std::vector<double> botStrips =
tokenizeDouble(record->getString(
"bottomStrips"),
",");
234 const std::vector<double> topStrips =
tokenizeDouble(record->getString(
"topStrips"),
",");
235 const std::vector<std::string>
sides =
tokenize(record->getString(
"side"),
";");
236 const double wirePitch = record->getDouble(
"wirePitch");
238 std::stringstream
key{};
241 parBook.wireGangs.insert(parBook.wireGangs.end(), wireGangs.begin(), wireGangs.end());
242 parBook.bottomStripPos = botStrips;
243 parBook.topStripPos = topStrips;
244 parBook.wirePitch = wirePitch;
250 return StatusCode::SUCCESS;