ATLAS Offline Software
TgcReadoutGeomTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TgcReadoutGeomTool.h"
6 
7 #include <GaudiKernel/SystemOfUnits.h>
10 
11 #include <GeoModelKernel/GeoFullPhysVol.h>
12 #include <GeoModelKernel/GeoPhysVol.h>
13 #include <GeoModelKernel/GeoTrd.h>
14 #include <GeoModelKernel/GeoBox.h>
15 
16 #include <GeoModelRead/ReadGeoModel.h>
21 
23 
25 
26 #ifndef SIMULATIONBASE
27 # include "Acts/Surfaces/TrapezoidBounds.hpp"
28 #endif
29 
30 using namespace CxxUtils;
31 using namespace ActsTrk;
32 
33 namespace MuonGMR4 {
34 
37 
38 
39 TgcReadoutGeomTool::TgcReadoutGeomTool(const std::string& type,
40  const std::string& name,
41  const IInterface* parent)
42  : base_class{type, name, parent} {}
44  FactoryCache& factoryCache) {
45  ATH_MSG_VERBOSE("Load dimensions of "<<m_idHelperSvc->toString(define.detElId)
46  <<std::endl<<std::endl<<m_geoUtilTool->dumpVolume(define.physVol));
47  const GeoShape* shape = m_geoUtilTool->extractShape(define.physVol);
48  if (!shape) {
49  ATH_MSG_FATAL("Failed to deduce a valid shape for "<<m_idHelperSvc->toString(define.detElId));
50  return StatusCode::FAILURE;
51  }
52 
53  if (shape->typeID() != GeoTrd::getClassTypeID()) {
54  ATH_MSG_FATAL("The shape of "<<m_idHelperSvc->toStringDetEl(define.detElId)
55  <<" is expected to be a trapezoid "<<m_geoUtilTool->dumpShape(shape));
56  return StatusCode::FAILURE;
57  }
58  const GeoTrd* chambTrd = static_cast<const GeoTrd*>(shape);
59  define.halfWidthShort = std::min(chambTrd->getYHalfLength1(), chambTrd->getYHalfLength2());
60  define.halfWidthLong = std::max(chambTrd->getYHalfLength1(), chambTrd->getYHalfLength2());
61  define.halfHeight = chambTrd->getZHalfLength();
62  define.halfThickness = chambTrd->getXHalfLength1();
64  std::vector<physVolWithTrans> allGasGaps = m_geoUtilTool->findAllLeafNodesByName(define.physVol, "TgcGas");
65  if (allGasGaps.empty()) {
66  ATH_MSG_FATAL("The volume "<<m_idHelperSvc->toStringDetEl(define.detElId)<<" does not have any childern TgcGas"
67  <<std::endl<<m_geoUtilTool->dumpVolume(define.physVol));
68  return StatusCode::FAILURE;
69  }
70  unsigned int gasGap{0};
71  for (const physVolWithTrans& pVolTrans : allGasGaps) {
72  std::stringstream key{};
73  key<<define.chambDesign<<"_"<<(gasGap+1)
74  <<(m_idHelperSvc->stationEta(define.detElId) > 0 ? "A" : "C");
75 
76  StripLayerPtr& stripLayout{factoryCache.stripDesigns[key.str()]};
77  StripLayerPtr& wireLayout{factoryCache.wireDesigns[key.str()]};
78 
79  if (!stripLayout || !wireLayout) {
80  const wTgcTable& table{factoryCache.parameterBook[key.str()]};
81  if (!table.gasGap) {
82  ATH_MSG_FATAL("No wTGC table could be found for "
83  <<m_idHelperSvc->toStringDetEl(define.detElId)
84  <<" "<<define.chambDesign<<", gasGap "<<(gasGap+1));
85  return StatusCode::FAILURE;
86  }
87  const GeoShape* gapShape = m_geoUtilTool->extractShape(pVolTrans.volume);
88  if (gapShape->typeID() != GeoTrd::getClassTypeID()) {
89  ATH_MSG_FATAL("Expected shape "<<m_geoUtilTool->dumpShape(gapShape)
90  <<" to be a trapezoid");
91  return StatusCode::FAILURE;
92  }
93  const GeoTrd* gapTrd = static_cast<const GeoTrd*>(gapShape);
94 
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();
98 
99  if (!wireLayout && table.wireGangs.size()) {
100  WireDesignPtr wireGrp = std::make_unique<WireGroupDesign>();
101  wireGrp->defineTrapezoid(halfMinX, halfMaxX, halfY);
102  for (unsigned int gang : table.wireGangs) {
103  wireGrp->declareGroup(gang);
104  }
105  const double wireOffSet = -0.5*table.wirePitch * wireGrp->nAllWires();
106  wireGrp->defineStripLayout(Amg::Vector2D{wireOffSet, 0.},
107  table.wirePitch, 0., table.wireGangs.size());
108 
109  const Amg::Transform3D trans{pVolTrans.transform
113  const IdentifierHash hash{gasGap << 1};
114  wireLayout = std::make_unique<StripLayer>(trans, (*factoryCache.wireLayouts.insert(std::move(wireGrp)).first), hash);
115  }
116  if (!stripLayout && table.bottomStripPos.size()) {
117  RadialStripDesignPtr radDesign = std::make_unique<RadialStripDesign>();
118  radDesign->defineTrapezoid(halfMinX, halfMaxX, halfY);
119  radDesign->defineStripLayout(Amg::Vector2D{-halfY,0.},
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),
124  table.topStripPos.at(s));
125  }
127  const IdentifierHash hash{gasGap<< 1 | 1};
128  const Amg::Transform3D trans{pVolTrans.transform
131  stripLayout = std::make_unique<StripLayer>(trans, (*factoryCache.stripLayouts.insert(std::move(radDesign)).first), hash);
132  }
133  }
134  ++gasGap;
135  if (stripLayout) {
136  unsigned int stripIdx = static_cast<unsigned>(stripLayout->hash());
137  if (stripIdx >= define.sensorLayouts.size()) {
138  ATH_MSG_FATAL("The strip index "<<stripIdx<<" is out of range for gasGap "<<gasGap);
139  return StatusCode::FAILURE;
140  }
141  define.sensorLayouts[stripIdx] = stripLayout;
142  }
143  if (wireLayout) {
144  unsigned int wireIdx = static_cast<unsigned>(wireLayout->hash());
145  if (wireIdx >= define.sensorLayouts.size()) {
146  ATH_MSG_FATAL("The wire index "<<wireIdx<<" is out of range for gasGap "<<gasGap);
147  return StatusCode::FAILURE;
148  }
149  define.sensorLayouts[wireIdx] = wireLayout;
150  }
151  }
152  define.nGasGaps = gasGap;
153  return StatusCode::SUCCESS;
154 }
156  ATH_CHECK(m_geoDbTagSvc.retrieve());
157  ATH_CHECK(m_idHelperSvc.retrieve());
158  ATH_CHECK(m_geoUtilTool.retrieve());
159  GeoModelIO::ReadGeoModel* sqliteReader = m_geoDbTagSvc->getSqliteReader();
160  if (!sqliteReader) {
161  ATH_MSG_FATAL("Error, the tool works exclusively from sqlite geometry inputs");
162  return StatusCode::FAILURE;
163  }
164 
165  FactoryCache facCache{};
166  ATH_CHECK(readParameterBook(facCache));
167 
168 #ifndef SIMULATIONBASE
169  SurfaceBoundSetPtr<Acts::TrapezoidBounds> layerBounds = std::make_shared<SurfaceBoundSet<Acts::TrapezoidBounds>>();
170 #endif
171  const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
172  // Get the list of full phys volumes from SQLite, and create detector elements
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"))
182  continue;
183 
184  bool isValid{false};
185  const Identifier elementID = idHelper.elementID(key_tokens[1].substr(0,3), atoi(key_tokens[2]), atoi(key_tokens[3]), isValid);
187  if (!isValid){
188  ATH_MSG_FATAL("Failed to construct the station Identifier from "<<key);
189  return StatusCode::FAILURE;
190  }
191  defineArgs define{};
192  define.physVol = pv;
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;
198 #endif
199  ATH_MSG_DEBUG("Key "<<key<<" lead to Identifier "<<m_idHelperSvc->toStringDetEl(define.detElId));
200  ATH_CHECK(loadDimensions(define, facCache));
201  std::unique_ptr<TgcReadoutElement> readoutEle = std::make_unique<TgcReadoutElement>(std::move(define));
202  ATH_CHECK(mgr.addTgcReadoutElement(std::move(readoutEle)));
203  }
205  return StatusCode::SUCCESS;
206 }
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());
212  Muon::MuonSectorMapping sectorMapping{};
213  const ActsGeometryContext gctx{};
214  for (const TgcReadoutElement* readoutEle : tgcReadOutEles) {
215  int& sectNumb = (*tgcSectorMapping)[m_idHelperSvc->moduleHash(readoutEle->identify())];
216  sectNumb = sectorMapping.getSector(readoutEle->center(gctx).phi());
217  }
218  ATH_CHECK(detStore()->record(std::move(tgcSectorMapping), "TGC_SectorMapping"));
219  return StatusCode::SUCCESS;
220 }
222  ServiceHandle<IRDBAccessSvc> accessSvc(m_geoDbTagSvc->getParamSvcName(), name());
223  ATH_CHECK(accessSvc.retrieve());
224  IRDBRecordset_ptr paramTable = accessSvc->getRecordsetPtr("TgcSensorLayout", "");
225  if (paramTable->size() == 0) {
226  ATH_MSG_FATAL("Empty parameter book table found");
227  return StatusCode::FAILURE;
228  }
229  for (const IRDBRecord_ptr& record : *paramTable) {
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");
237  for (const std::string& side : sides) {
238  std::stringstream key{};
239  key<<chambType<<"_"<<gasGap<<side;
240  wTgcTable& parBook{cache.parameterBook[key.str()]};
241  parBook.wireGangs.insert(parBook.wireGangs.end(), wireGangs.begin(), wireGangs.end());
242  parBook.bottomStripPos = botStrips;
243  parBook.topStripPos = topStrips;
244  parBook.wirePitch = wirePitch;
245  parBook.gasGap = gasGap;
246  }
247 
248  }
249  ATH_MSG_DEBUG("Read in total "<<cache.parameterBook.size()<<" chamber layouts");
250  return StatusCode::SUCCESS;
251 }
252 } // namespace MuonGMR4
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CxxUtils::tokenizeDouble
std::vector< double > tokenizeDouble(const std::string &the_str, std::string_view delimiter)
Definition: Control/CxxUtils/Root/StringUtils.cxx:34
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MuonGMR4::RpcReadoutElement::defineArgs
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:46
MuonGMR4::TgcReadoutGeomTool::FactoryCache::stripDesigns
ReadoutTable stripDesigns
Definition: TgcReadoutGeomTool.h:52
max
#define max(a, b)
Definition: cfImp.cxx:41
MuonGMR4::MuonDetectorManager
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:62
TgcIdHelper
Definition: TgcIdHelper.h:50
RPDUtils::sides
constexpr std::initializer_list< unsigned int > sides
Definition: RPDUtils.h:17
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
CxxUtils::tokenizeInt
std::vector< int > tokenizeInt(const std::string &the_str, std::string_view delimiter)
Definition: Control/CxxUtils/Root/StringUtils.cxx:55
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
MuonGMR4::TgcReadoutGeomTool::wTgcTable
Helper struct to cache the essential readout parameters from the WTGC tables.
Definition: TgcReadoutGeomTool.h:39
WireGroupDesign.h
MuonGMR4::TgcReadoutElement::parameterBook::halfThickness
double halfThickness
Describe the chamber dimensions Half thickness of the chamber.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:27
deg
#define deg
Definition: SbPolyhedron.cxx:17
SurfaceBoundSet.h
RadialStripDesign.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
MuonGMR4::TgcReadoutGeomTool::FactoryCache::stripLayouts
RadialStripDesignSet stripLayouts
Definition: TgcReadoutGeomTool.h:54
Amg::getRotateZ3D
Amg::Transform3D getRotateZ3D(double angle)
get a rotation transformation around Z-axis
Definition: GeoPrimitivesHelpers.h:270
TRT::Hit::side
@ side
Definition: HitInfo.h:83
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
MuonGMR4::TgcReadoutGeomTool::writeSectorMapping
StatusCode writeSectorMapping(const MuonDetectorManager &mgr) const
Map the Tgc sectors to the classical Muon System sectors.
Definition: TgcReadoutGeomTool.cxx:207
Amg::getRotateX3D
Amg::Transform3D getRotateX3D(double angle)
get a rotation transformation around X-axis
Definition: GeoPrimitivesHelpers.h:252
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:20
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonGMR4::TgcReadoutGeomTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TgcReadoutGeomTool.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
CxxUtils
Definition: aligned_vector.h:29
MuonGMR4::TgcReadoutGeomTool::readParameterBook
StatusCode readParameterBook(FactoryCache &cache)
Retrieves the auxillary tables from the database.
Definition: TgcReadoutGeomTool.cxx:221
MuonGMR4::TgcReadoutElement::parameterBook::halfWidthLong
double halfWidthLong
Half length of the chamber long edge (Top)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:33
MuonDetectorManager.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGMR4::TgcReadoutGeomTool::loadDimensions
StatusCode loadDimensions(TgcReadoutElement::defineArgs &args, FactoryCache &factory)
Loads the chamber dimensions from GeoModel.
Definition: TgcReadoutGeomTool.cxx:43
MuonGMR4::TgcReadoutGeomTool::FactoryCache::wireLayouts
WireGroupDesignSet wireLayouts
Definition: TgcReadoutGeomTool.h:55
TgcReadoutGeomTool.h
MuonGMR4::TgcReadoutGeomTool::buildReadOutElements
StatusCode buildReadOutElements(MuonDetectorManager &mgr) override final
Definition: TgcReadoutGeomTool.cxx:155
MuonGMR4::TgcReadoutElement::parameterBook::halfWidthShort
double halfWidthShort
Half length of the chamber short edge (Bottom)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:31
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
min
#define min(a, b)
Definition: cfImp.cxx:40
MuonGMR4::TgcReadoutElement::defineArgs
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:45
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonGMR4::MuonReadoutElement::defineArgs::chambDesign
std::string chambDesign
chamber design name as it's occuring in the parameter book tables E.g. BMS5, RPC10,...
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.ext.table_printer.table
list table
Definition: table_printer.py:81
MuonGMR4::physVolWithTrans
IMuonGeoUtilityTool::physVolWithTrans physVolWithTrans
Definition: MdtReadoutGeomTool.cxx:33
Amg::getRotateY3D
Amg::Transform3D getRotateY3D(double angle)
get a rotation transformation around Y-axis
Definition: GeoPrimitivesHelpers.h:261
MuonGMR4::TgcReadoutGeomTool::FactoryCache::parameterBook
ParamBookTable parameterBook
Definition: TgcReadoutGeomTool.h:48
MuonSectorMapping.h
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
MuonGMR4::TgcReadoutElement::parameterBook::halfHeight
double halfHeight
Half height of the chamber (Top - botom edge)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:29
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IRDBRecord_ptr
std::unique_ptr< IRDBRecord > IRDBRecord_ptr
Definition: IRDBRecordset.h:23
python.changerun.pv
pv
Definition: changerun.py:81
MuonGMR4::TgcReadoutElement::parameterBook::sensorLayouts
std::array< StripLayerPtr, 6 > sensorLayouts
We have maximum 3 gasgaps times eta / phi measurement.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:37
MuonGMR4::TgcReadoutElement::parameterBook::nGasGaps
unsigned int nGasGaps
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:35
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
MuonGMR4::MuonReadoutElement::defineArgs::detElId
Identifier detElId
ATLAS identifier.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:51
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:49
ActsTrk::SurfaceBoundSetPtr
std::shared_ptr< SurfaceBoundSet< BoundType > > SurfaceBoundSetPtr
Aberivation to create a new SurfaceBoundSetPtr.
Definition: Tracking/Acts/ActsGeoUtils/ActsGeoUtils/Defs.h:19
MuonGMR4::TgcReadoutGeomTool::FactoryCache::wireDesigns
ReadoutTable wireDesigns
Definition: TgcReadoutGeomTool.h:51
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
MuonGMR4::MuonReadoutElement::defineArgs::physVol
GeoIntrusivePtr< GeoVFullPhysVol > physVol
Pointer to the underlying physical volume in GeoModel.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:45
MuonGMR4::TgcReadoutGeomTool::m_geoDbTagSvc
ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc
Definition: TgcReadoutGeomTool.h:34
MuonGMR4::TgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:19
MuonGMR4::TgcReadoutGeomTool::FactoryCache
Definition: TgcReadoutGeomTool.h:46
MuonGMR4::TgcReadoutGeomTool::m_geoUtilTool
PublicToolHandle< IMuonGeoUtilityTool > m_geoUtilTool
Definition: TgcReadoutGeomTool.h:36
MuonGMR4::defineArgs
RpcReadoutElement::defineArgs defineArgs
Definition: RpcReadoutGeomTool.cxx:37
ServiceHandle< IRDBAccessSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14