ATLAS Offline Software
MuonGeoUtilitiyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "MuonGeoUtilityTool.h"
5 
7 #include <GeoModelKernel/GeoBox.h>
8 #include <GeoModelKernel/GeoTrd.h>
9 #include <GeoModelKernel/GeoSimplePolygonBrep.h>
10 
11 #include <GeoModelKernel/GeoTube.h>
12 
13 #include <GeoModelKernel/GeoShapeUnion.h>
14 #include <GeoModelKernel/GeoShapeIntersection.h>
15 #include <GeoModelKernel/GeoShapeSubtraction.h>
16 #include <GeoModelKernel/GeoShapeShift.h>
17 
18 #include <GeoModelKernel/GeoTransform.h>
19 
20 #include <GeoModelKernel/GeoVolumeCursor.h>
21 
22 #include <GeoModelHelpers/GeoShapeUtils.h>
23 #include <GeoModelHelpers/TransformToStringConverter.h>
24 
25 #include <set>
26 #include <sstream>
27 #include <string>
28 
29 
30 using namespace ActsTrk;
31 namespace MuonGMR4{
32 
33 MuonGeoUtilityTool::~MuonGeoUtilityTool() = default;
34 MuonGeoUtilityTool::MuonGeoUtilityTool(const std::string &type, const std::string &name,
35  const IInterface *parent):
36  base_class(type,name,parent) {}
37 
38 const GeoShape* MuonGeoUtilityTool::extractShape(const PVConstLink& physVol) const {
39  const GeoLogVol* logVol = physVol->getLogVol();
40  if (!logVol) {
41  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" Physical volume has no logical volume attached ");
42  return nullptr;
43  }
44  return extractShape(logVol->getShape());
45 }
46 const GeoShape* MuonGeoUtilityTool::extractShape(const GeoShape* inShape) const {
47 
48  if (!inShape) {
49  ATH_MSG_INFO(__FILE__<<":"<<__LINE__<<" "<<__func__<<" nullptr given ");
50  return nullptr;
51  }
52  if (inShape->typeID() == GeoShapeShift::getClassTypeID()) {
53  const GeoShapeShift* shift = dynamic_pointer_cast<const GeoShapeShift>(compressShift(inShape));
54  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<
55  "Shape is a shift by "<<GeoTrf::toString(shift->getX())
56  << ". Continue navigation "<<shift);
57  return extractShape(shift->getOp());
58  }
59  if (inShape->typeID() == GeoShapeSubtraction::getClassTypeID()){
60  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<
61  "Shape is a subtraction. Extract the basic shape. Continue navigation "<<inShape);
62  const GeoShapeSubtraction* subtract = static_cast<const GeoShapeSubtraction*>(inShape);
63  return extractShape(subtract->getOpA());
64  }
65  return inShape;
66 }
67 Amg::Transform3D MuonGeoUtilityTool::extractShifts(const PVConstLink& physVol) const {
68  const GeoLogVol* logVol = physVol->getLogVol();
69  if (!logVol) {
70  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" Physical volume has no logical volume attached. ");
71  return Amg::Transform3D::Identity();
72  }
73  return extractShifts(logVol->getShape());
74 }
75 
76 Amg::Transform3D MuonGeoUtilityTool::extractShifts(const GeoShape* inShape) const {
77  if (!inShape) {
78  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" "<<__func__<<" nullptr given ");
79  return Amg::Transform3D::Identity();
80  }
81  Amg::Transform3D sumTrans{Amg::Transform3D::Identity()};
82  if (inShape->typeID() == GeoShapeShift::getClassTypeID()) {
83  const GeoShapeShift* shift = dynamic_pointer_cast<const GeoShapeShift>(compressShift(inShape));
84  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<" Shape is a shift . Continue navigation "<<shift);
85  sumTrans = shift->getX();
86  }
87  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<" Extacted transformation "<<GeoTrf::toString(sumTrans));
88  return sumTrans;
89 }
90 std::string MuonGeoUtilityTool::dumpShape(const GeoShape* shape) const { return printGeoShape(shape); }
91 std::string MuonGeoUtilityTool::dumpVolume(const PVConstLink& physVol) const {
92  return dumpVolume(physVol, "");
93 }
94 std::string MuonGeoUtilityTool::dumpVolume(const PVConstLink& physVol, const std::string& childDelim) const {
95  std::stringstream sstr{};
96  if (!physVol || !physVol->getLogVol()){
97  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" "<<__func__<<" No logical volume attached ");
98  return sstr.str();
99  }
100  const GeoShape* shape = extractShape(physVol);
101  if (!shape) {
102  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" "<<__func__
103  <<" Failed to extract shape from phys volume "
104  << physVol->getLogVol()->getName());
105  return sstr.str();
106  }
107  sstr<<"logical volume "<<physVol->getLogVol()->getName()<<", ";
108  if (physVol->isShared() || !physVol->getParent()){
109  sstr<<"shared volume, ";
110  } else {
111  const GeoVPhysVol* pv = physVol;
112  if (typeid(*pv) == typeid(GeoFullPhysVol)){
113  const Amg::Transform3D absTrans = static_cast<const GeoFullPhysVol&>(*physVol).getAbsoluteTransform();
114  sstr<<"absolute pos: "<<GeoTrf::toString(absTrans,true) << ", ";
115  } else{
116  sstr<<"relative pos: "<<GeoTrf::toString(physVol->getX(), true)<<", ";
117  }
118  }
119  sstr<<dumpShape(shape)<<", ";
120  const Amg::Transform3D shift = extractShifts(physVol);
121  if (!Amg::isIdentity(shift)) {
122  sstr<<" shape shifted by "<<GeoTrf::toString(shift, true);
123  }
124  sstr<<"number of children "<<physVol->getNChildVols()<<", "<<std::endl;
125  std::vector<GeoChildNodeWithTrf> children = getChildrenWithRef(physVol, false);
126  for (unsigned int child = 0; child < children.size(); ++child) {
127  sstr<<childDelim<<(child+1)<<": "<<GeoTrf::toString(children[child].transform, true)
128  <<", "<< dumpVolume(children[child].volume, childDelim + " ");
129  }
130  return sstr.str();
131 }
132 
133 const GeoAlignableTransform* MuonGeoUtilityTool::findAlignableTransform(const PVConstLink& physVol) const {
134  PVConstLink parent{physVol->getParent()}, child{physVol};
135  while (parent) {
136  const GeoGraphNode * const * node1 = parent->findChildNode(child);
137  const GeoGraphNode * const * fence = parent->getChildNode(0);
138  for(const GeoGraphNode * const * current = node1 - 1; current>=fence; current--) {
139  const GeoGraphNode* node{*current};
140  if (dynamic_cast<const GeoVPhysVol*>(node)) break;
141  const GeoAlignableTransform* alignTrans{dynamic_cast<const GeoAlignableTransform*>(node)};
142  if (alignTrans) return alignTrans;
143  }
144  child = parent;
145  parent = child->getParent();
146  }
147  return nullptr;
148 }
149 
150 std::vector<MuonGeoUtilityTool::physVolWithTrans> MuonGeoUtilityTool::findAllLeafNodesByName(const PVConstLink& physVol, const std::string& volumeName) const {
151  const std::vector<physVolWithTrans> children = getChildrenWithRef(physVol, false);
152  std::vector<physVolWithTrans> foundVols{};
153  for (const physVolWithTrans& child : children) {
155  if (child.volume->getLogVol()->getName() == volumeName || child.nodeName == volumeName) {
156  foundVols.push_back(child);
157  }
159  if (!child.volume->getNChildVols()) {
160  continue;
161  }
162  std::vector<physVolWithTrans> grandChildren = findAllLeafNodesByName(child.volume, volumeName);
163  std::transform(std::make_move_iterator(grandChildren.begin()),
164  std::make_move_iterator(grandChildren.end()), std::back_inserter(foundVols),
165  [&child](physVolWithTrans&& vol){
166  vol.transform = child.transform * vol.transform;
167  return vol;
168  });
169  }
170  return foundVols;
171 }
172 std::vector<const GeoShape*> MuonGeoUtilityTool::getComponents(const GeoShape* booleanShape) const {
173  return getBooleanComponents(booleanShape);
174 }
175 
176 std::vector<Amg::Vector2D> MuonGeoUtilityTool::polygonEdges(const GeoSimplePolygonBrep& polygon) const {
177  std::vector<Amg::Vector2D> polygonEdges{};
178  polygonEdges.reserve(polygon.getNVertices());
179  for (unsigned int i = 0; i < polygon.getNVertices(); ++i) {
180  polygonEdges.emplace_back(polygon.getXVertex(i), polygon.getYVertex(i));
181  ATH_MSG_VERBOSE("Polygon vertext point " << i << ": "<< GeoTrf::toString(polygonEdges.back(), 2));
182  }
183  return polygonEdges;
184 }
185 
186 std::vector<Amg::Vector3D> MuonGeoUtilityTool::shapeEdges(const GeoShape* shape,
187  const Amg::Transform3D& refTrf) const {
188  return getPolyShapeEdges(shape, refTrf);
189 }
190 
191 
192 }
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
MuonGeoUtilityTool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonGMR4::MuonGeoUtilityTool::getComponents
std::vector< const GeoShape * > getComponents(const GeoShape *booleanShape) const override final
Definition: MuonGeoUtilitiyTool.cxx:172
MuonGMR4::MuonGeoUtilityTool::dumpVolume
std::string dumpVolume(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:91
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonGMR4::MuonGeoUtilityTool::polygonEdges
std::vector< Amg::Vector2D > polygonEdges(const GeoSimplePolygonBrep &polygon) const override
Transforms the vertices of the Polygon shape into a std::vector consisting of Amg::Vector2D objects.
Definition: MuonGeoUtilitiyTool.cxx:176
lumiFormat.i
int i
Definition: lumiFormat.py:85
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Amg::isIdentity
bool isIdentity(const Amg::Transform3D &trans)
Checks whether the transformation is the Identity transformation.
Definition: GeoPrimitivesHelpers.h:393
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
MuonGMR4::MuonGeoUtilityTool::extractShifts
Amg::Transform3D extractShifts(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:67
MuonGMR4::MuonGeoUtilityTool::findAlignableTransform
const GeoAlignableTransform * findAlignableTransform(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:133
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonGMR4::MuonGeoUtilityTool::findAllLeafNodesByName
std::vector< physVolWithTrans > findAllLeafNodesByName(const PVConstLink &physVol, const std::string &volumeName) const override final
Definition: MuonGeoUtilitiyTool.cxx:150
MuonGMR4::physVolWithTrans
IMuonGeoUtilityTool::physVolWithTrans physVolWithTrans
Definition: MdtReadoutGeomTool.cxx:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.changerun.pv
pv
Definition: changerun.py:81
python.DecayParser.children
children
Definition: DecayParser.py:32
MuonGMR4::MuonGeoUtilityTool::dumpShape
std::string dumpShape(const GeoShape *inShape) const override final
Dumps the shape to string.
Definition: MuonGeoUtilitiyTool.cxx:90
MuonDetectorDefs.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
MuonGMR4::MuonGeoUtilityTool::shapeEdges
std::vector< Amg::Vector3D > shapeEdges(const GeoShape *shape, const Amg::Transform3D &refTrf) const override
Definition: MuonGeoUtilitiyTool.cxx:186
node
Definition: memory_hooks-stdcmalloc.h:74
MuonGMR4::MuonGeoUtilityTool::extractShape
const GeoShape * extractShape(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:38