ATLAS Offline Software
DumpShape.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "GeoModelKernel/GeoShape.h"
9 #include "GeoModelKernel/GeoBox.h"
10 #include "GeoModelKernel/GeoTubs.h"
11 #include "GeoModelKernel/GeoTube.h"
12 #include "GeoModelKernel/GeoCons.h"
13 #include "GeoModelKernel/GeoTrap.h"
14 #include "GeoModelKernel/GeoTrd.h"
15 #include "GeoModelKernel/GeoPcon.h"
16 #include "GeoModelKernel/GeoPgon.h"
17 #include "GeoModelKernel/GeoPara.h"
18 #include "GeoModelKernel/GeoShapeShift.h"
19 #include "GeoModelKernel/GeoShapeUnion.h"
20 #include "GeoModelKernel/GeoShapeIntersection.h"
21 #include "GeoModelKernel/GeoShapeSubtraction.h"
22 #include "GeoModelKernel/GeoGenericTrap.h"
23 
24 #include "CLHEP/Units/SystemOfUnits.h"
25 #include "CLHEP/Vector/TwoVector.h"
26 
28 #include "Inventor/SbMatrix.h"
29 #include <cassert>
30 
31 //Fixme: Add support for the SimpleBREP GeoShape.
32 
33 //____________________________________________________________________
34 QStringList DumpShape::shapeToStringList(const GeoShape* shape)
35 {
36  QStringList out;
37 
38  if(shape->typeID() == GeoBox::getClassTypeID() ) {
39  const GeoBox* theBox = dynamic_cast<const GeoBox*> (shape);
40  assert(theBox);
41  if (theBox){
42  out << " =========> Box:";
43  out << " X = "+QString::number(theBox->getXHalfLength()/CLHEP::mm)+" mm";
44  out << " Y = "+QString::number(theBox->getYHalfLength()/CLHEP::mm)+" mm";
45  out << " Z = "+QString::number(theBox->getZHalfLength()/CLHEP::mm)+" mm";
46  }
47  } else if(shape->typeID() == GeoTube::getClassTypeID() ) {
48  const GeoTube* theTube = dynamic_cast<const GeoTube*> (shape);
49  assert(theTube);
50  if (theTube){
51  out << " =========> Tube:";
52  out << " RMin = "+QString::number(theTube->getRMin()/CLHEP::mm)+" mm";
53  out << " RMax = "+QString::number(theTube->getRMax()/CLHEP::mm)+" mm";
54  out << " DZ = "+QString::number(theTube->getZHalfLength()/CLHEP::mm)+" mm";
55  }
56  } else if(shape->typeID() == GeoTubs::getClassTypeID() ) {
57  const GeoTubs* theTubs = dynamic_cast<const GeoTubs*> (shape);
58  assert(theTubs);
59  if (theTubs){
60  out << " =========> Tubs:";
61  out << " RMin = "+QString::number(theTubs->getRMin()/CLHEP::mm)+" mm";
62  out << " RMax = "+QString::number(theTubs->getRMax()/CLHEP::mm)+" mm";
63  out << " DZ = "+QString::number(theTubs->getZHalfLength()/CLHEP::mm)+" mm";
64  out << " SPhi = "+QString::number(theTubs->getSPhi());
65  out << " DPhi = "+QString::number(theTubs->getDPhi());
66  }
67  } else if(shape->typeID() == GeoTrd::getClassTypeID() ) {
68  const GeoTrd* theTrd = dynamic_cast<const GeoTrd*> (shape);
69  assert(theTrd);
70  if (theTrd){
71  out << " =========> Trd:";
72  out << " X1 = "+QString::number(theTrd->getXHalfLength1()/CLHEP::mm)+" mm";
73  out << " X2 = "+QString::number(theTrd->getXHalfLength2()/CLHEP::mm)+" mm";
74  out << " Y1 = "+QString::number(theTrd->getYHalfLength1()/CLHEP::mm)+" mm";
75  out << " Y2 = "+QString::number(theTrd->getYHalfLength2()/CLHEP::mm)+" mm";
76  out << " Z = "+QString::number(theTrd->getZHalfLength()/CLHEP::mm)+" mm";
77  }
78  } else if(shape->typeID() == GeoPcon::getClassTypeID()) {
79  const GeoPcon* thePcon = dynamic_cast<const GeoPcon*>(shape);
80  assert(thePcon);//only in dbg builds
81  if (thePcon){
82  out << " =========> Pcon:";
83  out<<" Start phi = "+QString::number(thePcon->getSPhi())+", Delta phi = "+QString::number(thePcon->getDPhi());
84  for (unsigned index=0; index < thePcon->getNPlanes(); ++index) {
85  out << " Plane "+QString::number(index);
86  out << " -> RMin = "+QString::number(thePcon->getRMinPlane(index)/CLHEP::mm)+" mm";
87  out << " -> RMax = "+QString::number(thePcon->getRMaxPlane(index)/CLHEP::mm)+" mm";
88  out << " -> Z = "+QString::number(thePcon->getZPlane(index)/CLHEP::mm)+" mm";
89  }
90  }
91  } else if(shape->typeID() == GeoCons::getClassTypeID()) {
92  const GeoCons* theCons = dynamic_cast<const GeoCons*>(shape);
93  assert(theCons);
94  if (theCons){
95  out << " =========> Cons:";
96  out << " RMin1 = "<<QString::number(theCons->getRMin1()/CLHEP::mm)+" mm";
97  out << " RMin2 = "<<QString::number(theCons->getRMin2()/CLHEP::mm)+" mm";
98  out << " RMax1 = "<<QString::number(theCons->getRMax1()/CLHEP::mm)+" mm";
99  out << " RMax2 = "<<QString::number(theCons->getRMax2()/CLHEP::mm)+" mm";
100  out << " DZ = "<<QString::number(theCons->getDZ()/CLHEP::mm)+" mm";
101  out << " SPhi = "+QString::number(theCons->getSPhi());
102  out << " DPhi = "+QString::number(theCons->getDPhi());
103  }
104  } else if(shape->typeID() == GeoPara::getClassTypeID()) {
105  const GeoPara* thePara = dynamic_cast<const GeoPara*>(shape);
106  assert(thePara);
107  if (thePara){
108  out << " =========> Para:";
109  out << " X = "+QString::number(thePara->getXHalfLength()/CLHEP::mm)+" mm";
110  out << " Y = "+QString::number(thePara->getYHalfLength()/CLHEP::mm)+" mm";
111  out << " Z = "+QString::number(thePara->getZHalfLength()/CLHEP::mm)+" mm";
112  out << " Alpha = "+QString::number(thePara->getAlpha());
113  out << " Theta = "+QString::number(thePara->getTheta());
114  out << " Phi = "+QString::number(thePara->getPhi());
115  }
116  } else if(shape->typeID() == GeoPgon::getClassTypeID()) {
117  const GeoPgon* thePgon = dynamic_cast<const GeoPgon*>(shape);
118  assert(thePgon);
119  if (thePgon){
120  out << " =========> Pgon:";
121  for (unsigned int index=0; index<thePgon->getNPlanes(); index++)
122  {
123  out << " Plane "+QString::number(index);
124  out << ": -> RMin = "+QString::number(thePgon->getRMinPlane(index)/CLHEP::mm)+" mm";
125  out << ": -> RMax = "+QString::number(thePgon->getRMaxPlane(index)/CLHEP::mm)+" mm";
126  out << " -> Z = "+QString::number(thePgon->getZPlane(index)/CLHEP::mm)+" mm";
127  }
128  }
129  } else if(shape->typeID() == GeoTrap::getClassTypeID()) {
130  const GeoTrap* theTrap = dynamic_cast<const GeoTrap*>(shape);
131  assert(theTrap);
132  if (theTrap){
133  out << " =========> Trap:";
134  out << " DZ = "+QString::number(theTrap->getZHalfLength()/CLHEP::mm)+" mm";
135  out << " Theta = "+QString::number(theTrap->getTheta());
136  out << " Phi = "+QString::number(theTrap->getPhi());
137  out << " Dydzn = "+QString::number(theTrap->getDydzn()/CLHEP::mm)+" mm";
138  out << " Dxdyndzn = "+QString::number(theTrap->getDxdyndzn()/CLHEP::mm)+" mm";
139  out << " Dxdypdzn = "+QString::number(theTrap->getDxdypdzn()/CLHEP::mm)+" mm";
140  out << " Angleydzn = "+QString::number(theTrap->getAngleydzn());
141  out << " Dydzp = "+QString::number(theTrap->getDydzp()/CLHEP::mm)+" mm";
142  out << " Dxdyndzp = "+QString::number(theTrap->getDxdyndzp()/CLHEP::mm)+" mm";
143  out << " Dxdypdzp = "+QString::number(theTrap->getDxdypdzp()/CLHEP::mm)+" mm";
144  out << " Angleydzp = "+QString::number(theTrap->getAngleydzp());
145  }
146  }
147  // Boolean volumes:
148  else if (shape->typeID() == GeoShapeShift::getClassTypeID() ) {
149  const GeoShapeShift* theShift = dynamic_cast<const GeoShapeShift*>(shape);
150  assert(theShift);
151  if (theShift){
152  out << " =========> GeoShapeShift:";
153  SbMatrix t;
155  float translation_x, translation_y, translation_z, rotaxis_x, rotaxis_y, rotaxis_z, rotangle_radians;
157  translation_x, translation_y, translation_z,
158  rotaxis_x, rotaxis_y, rotaxis_z, rotangle_radians );
159  out << " Information about contained transformation:";
160  out << "===&gt; Translation:";
161  out << " x = "+QString::number(translation_x/CLHEP::mm)+" mm";
162  out << " y = "+QString::number(translation_y/CLHEP::mm)+" mm";
163  out << " z = "+QString::number(translation_z/CLHEP::mm)+" mm";
164  out << "===&gt; Rotation:";
165  out << " axis x = "+QString::number(rotaxis_x);
166  out << " axis y = "+QString::number(rotaxis_y);
167  out << " axis z = "+QString::number(rotaxis_z);
168  out << " angle = "+QString::number(rotangle_radians*180.0/M_PI)+" deg";
169 
170  out << " Information about contained GeoShape:";
171  for(const QString& str : shapeToStringList(theShift->getOp())){
172  out <<" ==> "+str;
173  }
174  }
175  } else if (shape->typeID() == GeoShapeUnion::getClassTypeID() ) {
176  const GeoShapeUnion* theUnion = dynamic_cast<const GeoShapeUnion*>(shape);
177  assert(theUnion);
178  if (theUnion){
179  out << " =========> GeoShapeUnion:";
180  out << " First operand:";
181  for (const QString& s : shapeToStringList(theUnion->getOpA()))
182  out << " ==> "+s;
183  out << " Second operand:";
184  for (const QString& s : shapeToStringList(theUnion->getOpB()))
185  out << " ==> "+s;
186  }
187  } else if (shape->typeID() == GeoShapeIntersection::getClassTypeID() ) {
188  const GeoShapeIntersection* theIntersection = dynamic_cast<const GeoShapeIntersection*>(shape);
189  assert(theIntersection);
190  if (theIntersection){
191  out << " =========> GeoShapeIntersection:";
192  out << " First operand:";
193  for (const QString& s : shapeToStringList(theIntersection->getOpA()))
194  out << " ==> "+s;
195  out << " Second operand:";
196  for (const QString& s : shapeToStringList(theIntersection->getOpB()))
197  out << " ==> "+s;
198  }
199  } else if (shape->typeID() == GeoShapeSubtraction::getClassTypeID() ) {
200  const GeoShapeSubtraction* theSubtraction = dynamic_cast<const GeoShapeSubtraction*>(shape);
201  assert(theSubtraction);
202  if (theSubtraction){
203  out << " =========> GeoShapeSubtraction:";
204  out << " First operand:";
205  for (const QString& s : shapeToStringList(theSubtraction->getOpA()))
206  out << " ==> "+s;
207  out << " Second operand:";
208  for (const QString& s : shapeToStringList(theSubtraction->getOpB()))
209  out << " ==> "+s;
210  }
211  } else if (shape->typeID() == GeoGenericTrap::getClassTypeID() ) {
212  const GeoGenericTrap* theGenericTrap = dynamic_cast<const GeoGenericTrap*>(shape);
213  assert(theGenericTrap);
214  if (theGenericTrap){
215  out << " =========> GenericTrap:";
216  out << " halfZlength = "+QString::number(theGenericTrap->getZHalfLength()/CLHEP::mm)+" mm";
217  std::vector<CLHEP::Hep2Vector> vertices;
218  vertices.reserve(theGenericTrap->getVertices().size());
219  for(const auto& geoVertex : theGenericTrap->getVertices()) {
220  vertices.push_back(CLHEP::Hep2Vector(geoVertex.x(),geoVertex.y()));
221  }
222  //in total 8 vertices by definition!
223  out << "==> First 4 vertices at - hz/2";
224  out << "(Ax,Ay) = ( "+QString::number(vertices[0].x()/CLHEP::mm)+" , "+QString::number(vertices[0].y()/CLHEP::mm)+" ) mm";
225  out << "(Bx,By) = ( "+QString::number(vertices[1].x()/CLHEP::mm)+" , "+QString::number(vertices[1].y()/CLHEP::mm)+" ) mm";
226  out << "(Cx,Cy) = ( "+QString::number(vertices[2].x()/CLHEP::mm)+" , "+QString::number(vertices[2].y()/CLHEP::mm)+" ) mm";
227  out << "(Dx,Dy) = ( "+QString::number(vertices[3].x()/CLHEP::mm)+" , "+QString::number(vertices[3].y()/CLHEP::mm)+" ) mm";
228  out <<"==> Second 4 vertices at +hz/2";
229  out << "(Ax,Ay) = ( "+QString::number(vertices[4].x()/CLHEP::mm)+" , "+QString::number(vertices[4].y()/CLHEP::mm)+" ) mm";
230  out << "(Bx,By) = ( "+QString::number(vertices[5].x()/CLHEP::mm)+" , "+QString::number(vertices[5].y()/CLHEP::mm)+" ) mm";
231  out << "(Cx,Cy) = ( "+QString::number(vertices[6].x()/CLHEP::mm)+" , "+QString::number(vertices[6].y()/CLHEP::mm)+" ) mm";
232  out << "(Dx,Dy) = ( "+QString::number(vertices[7].x()/CLHEP::mm)+" , "+QString::number(vertices[7].y()/CLHEP::mm)+" ) mm";
233  }
234  } else {
235  out << " =========> Unknown shape...";
236  }
237 
238  return out;
239 
240 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
DumpShape::shapeToStringList
static QStringList shapeToStringList(const GeoShape *shape)
Definition: DumpShape.cxx:34
index
Definition: index.py:1
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
M_PI
#define M_PI
Definition: ActiveFraction.h:11
VP1LinAlgUtils::decodeTransformation
static void decodeTransformation(const SbMatrix &, float &translation_x, float &translation_y, float &translation_z, float &rotaxis_x, float &rotaxis_y, float &rotaxis_z, float &rotangle_radians)
Definition: VP1LinAlgUtils.cxx:162
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
x
#define x
VP1LinAlgUtils.h
GeoPrimitives.h
DumpShape.h
python.selection.number
number
Definition: selection.py:20
VP1LinAlgUtils::transformToMatrix
static void transformToMatrix(SoTransform *xf, SbMatrix &result)
Definition: VP1LinAlgUtils.cxx:101
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
DeMoScan.index
string index
Definition: DeMoScan.py:364
y
#define y
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
Amg::EigenTransformToCLHEP
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
Definition: CLHEPtoEigenConverter.h:120
str
Definition: BTagTrackIpAccessor.cxx:11