ATLAS Offline Software
MuonGeoUtilitiyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
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):
37  declareInterface<IMuonGeoUtilityTool>(this);
38 }
39 
40 const GeoShape* MuonGeoUtilityTool::extractShape(const PVConstLink& physVol) const {
41  const GeoLogVol* logVol = physVol->getLogVol();
42  if (!logVol) {
43  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" Physical volume has no logical volume attached ");
44  return nullptr;
45  }
46  return extractShape(logVol->getShape());
47 }
48 const GeoShape* MuonGeoUtilityTool::extractShape(const GeoShape* inShape) const {
49 
50  if (!inShape) {
51  ATH_MSG_INFO(__FILE__<<":"<<__LINE__<<" "<<__func__<<" nullptr given ");
52  return nullptr;
53  }
54  if (inShape->typeID() == GeoShapeShift::getClassTypeID()) {
55  const GeoShapeShift* shift = dynamic_pointer_cast<const GeoShapeShift>(compressShift(inShape));
56  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<
57  "Shape is a shift by "<<GeoTrf::toString(shift->getX())
58  << ". Continue navigation "<<shift);
59  return extractShape(shift->getOp());
60  }
61  if (inShape->typeID() == GeoShapeSubtraction::getClassTypeID()){
62  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<
63  "Shape is a subtraction. Extract the basic shape. Continue navigation "<<inShape);
64  const GeoShapeSubtraction* subtract = static_cast<const GeoShapeSubtraction*>(inShape);
65  return extractShape(subtract->getOpA());
66  }
67  return inShape;
68 }
69 Amg::Transform3D MuonGeoUtilityTool::extractShifts(const PVConstLink& physVol) const {
70  const GeoLogVol* logVol = physVol->getLogVol();
71  if (!logVol) {
72  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" Physical volume has no logical volume attached. ");
73  return Amg::Transform3D::Identity();
74  }
75  return extractShifts(logVol->getShape());
76 }
77 
78 Amg::Transform3D MuonGeoUtilityTool::extractShifts(const GeoShape* inShape) const {
79  if (!inShape) {
80  ATH_MSG_ERROR(__FILE__<<":"<<__LINE__<<" "<<__func__<<" nullptr given ");
81  return Amg::Transform3D::Identity();
82  }
83  Amg::Transform3D sumTrans{Amg::Transform3D::Identity()};
84  if (inShape->typeID() == GeoShapeShift::getClassTypeID()) {
85  const GeoShapeShift* shift = dynamic_pointer_cast<const GeoShapeShift>(compressShift(inShape));
86  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<" Shape is a shift . Continue navigation "<<shift);
87  sumTrans = shift->getX();
88  }
89  ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" "<<__func__<<" Extacted transformation "<<GeoTrf::toString(sumTrans));
90  return sumTrans;
91 }
92 std::string MuonGeoUtilityTool::dumpShape(const GeoShape* shape) const { return printGeoShape(shape); }
93 std::string MuonGeoUtilityTool::dumpVolume(const PVConstLink& physVol) const {
94  return dumpVolume(physVol, "");
95 }
96 std::string MuonGeoUtilityTool::dumpVolume(const PVConstLink& physVol, const std::string& childDelim) const {
97  std::stringstream sstr{};
98  if (!physVol || !physVol->getLogVol()){
99  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" "<<__func__<<" No logical volume attached ");
100  return sstr.str();
101  }
102  const GeoShape* shape = extractShape(physVol);
103  if (!shape) {
104  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" "<<__func__
105  <<" Failed to extract shape from phys volume "
106  << physVol->getLogVol()->getName());
107  return sstr.str();
108  }
109  sstr<<"logical volume "<<physVol->getLogVol()->getName()<<", ";
110  if (physVol->isShared() || !physVol->getParent()){
111  sstr<<"shared volume, ";
112  } else {
113  const GeoVPhysVol* pv = physVol;
114  if (typeid(*pv) == typeid(GeoFullPhysVol)){
115  const Amg::Transform3D absTrans = static_cast<const GeoFullPhysVol&>(*physVol).getAbsoluteTransform();
116  sstr<<"absolute pos: "<<GeoTrf::toString(absTrans,true) << ", ";
117  } else{
118  sstr<<"relative pos: "<<GeoTrf::toString(physVol->getX(), true)<<", ";
119  }
120  }
121  sstr<<dumpShape(shape)<<", ";
122  const Amg::Transform3D shift = extractShifts(physVol);
123  if (!Amg::isIdentity(shift)) {
124  sstr<<" shape shifted by "<<GeoTrf::toString(shift, true);
125  }
126  sstr<<"number of children "<<physVol->getNChildVols()<<", "<<std::endl;
127  std::vector<GeoChildNodeWithTrf> children = getChildrenWithRef(physVol, false);
128  for (unsigned int child = 0; child < children.size(); ++child) {
129  sstr<<childDelim<<(child+1)<<": "<<GeoTrf::toString(children[child].transform, true)
130  <<", "<< dumpVolume(children[child].volume, childDelim + " ");
131  }
132  return sstr.str();
133 }
134 
135 const GeoAlignableTransform* MuonGeoUtilityTool::findAlignableTransform(const PVConstLink& physVol) const {
136  PVConstLink parent{physVol->getParent()}, child{physVol};
137  while (parent) {
138  const GeoGraphNode * const * node1 = parent->findChildNode(child);
139  const GeoGraphNode * const * fence = parent->getChildNode(0);
140  for(const GeoGraphNode * const * current = node1 - 1; current>=fence; current--) {
141  const GeoGraphNode* node{*current};
142  if (dynamic_cast<const GeoVPhysVol*>(node)) break;
143  const GeoAlignableTransform* alignTrans{dynamic_cast<const GeoAlignableTransform*>(node)};
144  if (alignTrans) return alignTrans;
145  }
146  child = parent;
147  parent = child->getParent();
148  }
149  return nullptr;
150 }
151 
152 std::vector<MuonGeoUtilityTool::physVolWithTrans> MuonGeoUtilityTool::findAllLeafNodesByName(const PVConstLink& physVol, const std::string& volumeName) const {
153  const std::vector<physVolWithTrans> children = getChildrenWithRef(physVol, false);
154  std::vector<physVolWithTrans> foundVols{};
155  for (const physVolWithTrans& child : children) {
157  if (child.volume->getLogVol()->getName() == volumeName || child.nodeName == volumeName) {
158  foundVols.push_back(child);
159  }
161  if (!child.volume->getNChildVols()) {
162  continue;
163  }
164  std::vector<physVolWithTrans> grandChildren = findAllLeafNodesByName(child.volume, volumeName);
165  std::transform(std::make_move_iterator(grandChildren.begin()),
166  std::make_move_iterator(grandChildren.end()), std::back_inserter(foundVols),
167  [&child](physVolWithTrans&& vol){
168  vol.transform = child.transform * vol.transform;
169  return vol;
170  });
171  }
172  return foundVols;
173 }
174 std::vector<const GeoShape*> MuonGeoUtilityTool::getComponents(const GeoShape* booleanShape) const {
175  return getBooleanComponents(booleanShape);
176 }
177 
178 std::vector<Amg::Vector2D> MuonGeoUtilityTool::polygonEdges(const GeoSimplePolygonBrep& polygon) const {
179  std::vector<Amg::Vector2D> polygonEdges{};
180  polygonEdges.reserve(polygon.getNVertices());
181  for (unsigned int i = 0; i < polygon.getNVertices(); ++i) {
182  polygonEdges.emplace_back(polygon.getXVertex(i), polygon.getYVertex(i));
183  ATH_MSG_VERBOSE("Polygon vertext point " << i << ": "<< GeoTrf::toString(polygonEdges.back(), 2));
184  }
185  return polygonEdges;
186 }
187 
188 std::vector<Amg::Vector3D> MuonGeoUtilityTool::shapeEdges(const GeoShape* shape,
189  const Amg::Transform3D& refTrf) const {
190  return getPolyShapeEdges(shape, refTrf);
191 }
192 
193 
194 }
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
Splits a boolean shape into its building blocks.
Definition: MuonGeoUtilitiyTool.cxx:174
MuonGMR4::MuonGeoUtilityTool::dumpVolume
std::string dumpVolume(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:93
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
A muon chamber is a collection of readout elements belonging to the same station.
Definition: ChamberAssembleTool.h:16
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:178
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
MuonGMR4::IMuonGeoUtilityTool::physVolWithTrans
GeoChildNodeWithTrf physVolWithTrans
Helper struct to cache a PhysVolume pointer together with the transformation to go from the volume to...
Definition: IMuonGeoUtilityTool.h:42
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:348
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
MuonGMR4::MuonGeoUtilityTool::extractShifts
Amg::Transform3D extractShifts(const PVConstLink &physVol) const override final
Definition: MuonGeoUtilitiyTool.cxx:69
MuonGMR4::MuonGeoUtilityTool::findAlignableTransform
const GeoAlignableTransform * findAlignableTransform(const PVConstLink &physVol) const override final
Returns the next Geo alignable transform in the GeoModelTree upstream.
Definition: MuonGeoUtilitiyTool.cxx:135
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
MuonGMR4::MuonGeoUtilityTool::findAllLeafNodesByName
std::vector< physVolWithTrans > findAllLeafNodesByName(const PVConstLink &physVol, const std::string &volumeName) const override final
Searches through all child volumes and collects the nodes where the logical volumes have the requeste...
Definition: MuonGeoUtilitiyTool.cxx:152
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:92
MuonDetectorDefs.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:34
AthAlgTool
Definition: AthAlgTool.h:26
MuonGMR4::MuonGeoUtilityTool::shapeEdges
std::vector< Amg::Vector3D > shapeEdges(const GeoShape *shape, const Amg::Transform3D &refTrf) const override
Returns the edge points of the polygon like GeoShapes.
Definition: MuonGeoUtilitiyTool.cxx:188
node
Definition: memory_hooks-stdcmalloc.h:74
MuonGMR4::MuonGeoUtilityTool::extractShape
const GeoShape * extractShape(const PVConstLink &physVol) const override final
Navigates throughs the volume to find a Box / Prd shape.
Definition: MuonGeoUtilitiyTool.cxx:40