14 #define _USE_MATH_DEFINES
26 #include "TGeoShape.h"
36 #include "TGeoParaboloid.h"
37 #include "TGeoSphere.h"
38 #include "TGeoTorus.h"
39 #include "TGeoMatrix.h"
40 #include "TGeoHalfSpace.h"
41 #include "TGeoBoolNode.h"
42 #include "TGeoCompositeShape.h"
45 using namespace DD4hep::Geometry;
52 return "[Invalid shape]";
55 TClass* cl = shape->IsA();
56 int prec = log.precision();
57 log.setf(ios::fixed,ios::floatfield);
58 log << setprecision(precision);
60 if ( cl == TGeoBBox::Class() ) {
61 TGeoBBox*
s = (TGeoBBox*) shape;
62 log <<
" x:" << s->GetDX()
63 <<
" y:" << s->GetDY()
64 <<
" z:" << s->GetDZ();
66 else if (cl == TGeoHalfSpace::Class()) {
67 TGeoHalfSpace*
s = (TGeoHalfSpace*)(const_cast<TGeoShape*>(shape));
68 log <<
" Point: (" << s->GetPoint()[0] <<
", " << s->GetPoint()[1] <<
", " << s->GetPoint()[2] <<
") "
69 <<
" Normal: (" << s->GetNorm()[0] <<
", " << s->GetNorm()[1] <<
", " << s->GetNorm()[2] <<
") ";
71 else if (cl == TGeoTube::Class()) {
72 const TGeoTube*
s = (
const TGeoTube*) shape;
73 log <<
" rmin:" << s->GetRmin() <<
" rmax:" << s->GetRmax() <<
" dz:" << s->GetDz();
75 else if (cl == TGeoTubeSeg::Class()) {
76 const TGeoTubeSeg*
s = (
const TGeoTubeSeg*) shape;
77 log <<
" rmin:" << s->GetRmin() <<
" rmax:" << s->GetRmax() <<
" dz:" << s->GetDz()
78 <<
" Phi1:" << s->GetPhi1() <<
" Phi2:" << s->GetPhi2();
80 else if (cl == TGeoTrd1::Class()) {
81 const TGeoTrd1*
s = (
const TGeoTrd1*) shape;
82 log <<
" x1:" << s->GetDx1() <<
" x2:" << s->GetDx2() <<
" y:" << s->GetDy() <<
" z:" << s->GetDz();
84 else if (cl == TGeoTrd2::Class()) {
85 const TGeoTrd2*
s = (
const TGeoTrd2*) shape;
86 log <<
" x1:" << s->GetDx1() <<
" x2:" << s->GetDx2()
87 <<
" y1:" << s->GetDy1() <<
" y2:" << s->GetDy2() <<
" z:" << s->GetDz();
89 else if (cl == TGeoHype::Class()) {
90 const TGeoHype*
s = (
const TGeoHype*) shape;
91 log <<
" rmin:" << s->GetRmin() <<
" rmax:" << s->GetRmax() <<
" dz:" << s->GetDz()
92 <<
" StIn:" << s->GetStIn() <<
" StOut:" << s->GetStOut();
94 else if (cl == TGeoPgon::Class()) {
95 const TGeoPgon*
s = (
const TGeoPgon*) shape;
96 log <<
" Phi1:" << s->GetPhi1() <<
" dPhi:" << s->GetDphi()
97 <<
" NEdges:" << s->GetNedges() <<
" Nz:" << s->GetNz();
98 for(
int i=0, n=s->GetNz(); i<n; ++i) {
99 log <<
" i=" << i <<
" z:" << s->GetZ(i)
100 <<
" r:[" << s->GetRmin(i) <<
"," << s->GetRmax(i) <<
"]";
103 else if (cl == TGeoPcon::Class()) {
104 const TGeoPcon*
s = (
const TGeoPcon*) shape;
105 log <<
" Phi1:" << s->GetPhi1() <<
" dPhi:" << s->GetDphi() <<
" Nz:" << s->GetNz();
106 for(
int i=0, n=s->GetNz(); i<n; ++i) {
107 log <<
" i=" << i <<
" z:" << s->GetZ(i)
108 <<
" r:[" << s->GetRmin(i) <<
"," << s->GetRmax(i) <<
"]";
111 else if (cl == TGeoConeSeg::Class()) {
113 log <<
" rmin1:" << s->GetRmin1() <<
" rmax1:" << s->GetRmax1()
114 <<
" rmin2:" << s->GetRmin2() <<
" rmax2:" << s->GetRmax2()
115 <<
" dz:" << s->GetDz()
116 <<
" Phi1:" << s->GetPhi1() <<
" Phi2:" << s->GetPhi2();
118 else if (cl == TGeoParaboloid::Class()) {
119 const TGeoParaboloid*
s = (
const TGeoParaboloid*) shape;
120 log <<
" dz:" << s->GetDz() <<
" RLo:" << s->GetRlo() <<
" Rhi:" << s->GetRhi();
122 else if (cl == TGeoSphere::Class()) {
123 const TGeoSphere*
s = (
const TGeoSphere*) shape;
124 log <<
" rmin:" << s->GetRmin() <<
" rmax:" << s->GetRmax()
125 <<
" Phi1:" << s->GetPhi1() <<
" Phi2:" << s->GetPhi2()
126 <<
" Theta1:" << s->GetTheta1() <<
" Theta2:" << s->GetTheta2();
128 else if (cl == TGeoTorus::Class()) {
129 const TGeoTorus*
s = (
const TGeoTorus*) shape;
130 log <<
" rmin:" << s->GetRmin() <<
" rmax:" << s->GetRmax() <<
" r:" << s->GetR()
131 <<
" Phi1:" << s->GetPhi1() <<
" dPhi:" << s->GetDphi();
133 else if (cl == TGeoTrap::Class()) {
134 const TGeoTrap*
s = (
const TGeoTrap*) shape;
135 log <<
" dz:" << s->GetDz() <<
" Theta:" << s->GetTheta() <<
" Phi:" << s->GetPhi()
136 <<
" H1:" << s->GetH1() <<
" Bl1:" << s->GetBl1() <<
" Tl1:" << s->GetTl1() <<
" Alpha1:" << s->GetAlpha1()
137 <<
" H2:" << s->GetH2() <<
" Bl2:" << s->GetBl2() <<
" Tl2:" << s->GetTl2() <<
" Alpha2:" << s->GetAlpha2();
139 else if (shape->IsA() == TGeoCompositeShape::Class()) {
140 const TGeoCompositeShape*
s = (
const TGeoCompositeShape*) shape;
141 const TGeoBoolNode*
boolean = s->GetBoolNode();
142 const TGeoShape* left =
boolean->GetLeftShape();
143 const TGeoShape* right =
boolean->GetRightShape();
144 TGeoBoolNode::EGeoBoolType oper =
boolean->GetBooleanOperator();
145 if (oper == TGeoBoolNode::kGeoSubtraction)
146 log <<
"Subtraction: ";
147 else if (oper == TGeoBoolNode::kGeoUnion)
149 else if (oper == TGeoBoolNode::kGeoIntersection)
150 log <<
"Intersection: ";
153 log << setprecision(prec);
158 this->ptr()->SetDimensions(param);
159 this->ptr()->ComputeBBox();
163 template <
typename T>
165 this->assign(n, nam, tit);
172 return this->ptr()->GetName();
178 return this->ptr()->IsA()->GetName();
183 void Box::make(
double x_val,
double y_val,
double z_val) {
184 _assign(
new TGeoBBox(x_val, y_val, z_val),
"",
"box",
true);
188 Box& Box::setDimensions(
double x_val,
double y_val,
double z_val) {
189 double params[] = { x_val, y_val, z_val};
190 _setDimensions(params);
195 double Box::x()
const {
196 return this->ptr()->GetDX();
200 double Box::y()
const {
201 return this->ptr()->GetDY();
205 double Box::z()
const {
206 return this->ptr()->GetDZ();
210 void HalfSpace::make(
const double*
const point,
const double*
const normal) {
211 _assign(
new TGeoHalfSpace(
"",(Double_t*)point, (Double_t*)normal),
"",
"halfspace",
true);
215 Polycone::Polycone(
double start,
double delta) {
220 Polycone::Polycone(
double start,
double delta,
const vector<double>& rmin,
const vector<double>& rmax,
221 const vector<double>& z) {
222 vector<double> params;
223 if (rmin.size() < 2) {
224 throw runtime_error(
"DD4hep: PolyCone::addZPlanes> Not enough Z planes. minimum is 2!");
228 params.push_back(rmin.size());
229 for (
size_t i = 0; i < rmin.size(); ++i) {
230 params.push_back(z[i] );
231 params.push_back(rmin[i] );
232 params.push_back(rmax[i] );
234 _assign(
new TGeoPcon(¶ms[0]),
"",
"polycone",
true);
238 void Polycone::addZPlanes(
const vector<double>& rmin,
const vector<double>& rmax,
const vector<double>& z) {
240 vector<double> params;
241 size_t num = s->GetNz();
242 if (rmin.size() < 2) {
243 throw runtime_error(
"DD4hep: PolyCone::addZPlanes> Not enough Z planes. minimum is 2!");
245 params.push_back(s->GetPhi1());
246 params.push_back(s->GetDphi());
247 params.push_back(num + rmin.size());
248 for (
size_t i = 0; i < num; ++i) {
249 params.push_back(s->GetZ(i));
250 params.push_back(s->GetRmin(i));
251 params.push_back(s->GetRmax(i));
253 for (
size_t i = 0; i < rmin.size(); ++i) {
254 params.push_back(z[i] );
255 params.push_back(rmin[i] );
256 params.push_back(rmax[i] );
258 _setDimensions(¶ms[0]);
262 ConeSegment::ConeSegment(
double dz,
263 double rmin1,
double rmax1,
264 double rmin2,
double rmax2,
265 double phi1,
double phi2) {
271 double rmin1,
double rmax1,
272 double rmin2,
double rmax2,
273 double phi1,
double phi2) {
275 _setDimensions(params);
280 void Tube::make(
const string& nam,
double rmin,
double rmax,
double z,
double startPhi,
double deltaPhi) {
282 _assign(
new MyConeSeg(), nam,
"tube",
true);
283 setDimensions(rmin, rmax, z, startPhi, deltaPhi);
287 Tube& Tube::setDimensions(
double rmin,
double rmax,
double z,
double startPhi,
double deltaPhi) {
290 _setDimensions(params);
295 void EllipticalTube::make(
double a,
double b,
double dz) {
296 _assign(
new TGeoEltu(),
"",
"elliptic_tube",
true);
297 setDimensions(a, b, dz);
302 double params[] = { a, b, dz };
303 _setDimensions(params);
308 void Cone::make(
double z,
double rmin1,
double rmax1,
double rmin2,
double rmax2) {
309 _assign(
new TGeoCone(z, rmin1, rmax1, rmin2, rmax2 ),
"",
"cone",
true);
312 Cone& Cone::setDimensions(
double z,
double rmin1,
double rmax1,
double rmin2,
double rmax2) {
313 double params[] = { z, rmin1, rmax1, rmin2, rmax2 };
314 _setDimensions(params);
319 Trapezoid::Trapezoid(
double x1,
double x2,
double y1,
double y2,
double z) {
324 void Trapezoid::make(
double x1,
double x2,
double y1,
double y2,
double z) {
325 _assign(
new TGeoTrd2(x1, x2, y1, y2, z ),
"",
"trd2",
true);
329 Trapezoid& Trapezoid::setDimensions(
double x1,
double x2,
double y1,
double y2,
double z) {
330 double params[] = { x1, x2, y1, y2, z };
331 _setDimensions(params);
336 Paraboloid::Paraboloid(
double r_low,
double r_high,
double delta_z) {
337 _assign(
new TGeoParaboloid(r_low, r_high, delta_z ),
"",
"paraboloid",
true);
341 Paraboloid& Paraboloid::setDimensions(
double r_low,
double r_high,
double delta_z) {
342 double params[] = { r_low, r_high, delta_z };
343 _setDimensions(params);
348 Hyperboloid::Hyperboloid(
double rin,
double stin,
double rout,
double stout,
double dz) {
353 Hyperboloid& Hyperboloid::setDimensions(
double rin,
double stin,
double rout,
double stout,
double dz) {
355 _setDimensions(params);
360 Sphere::Sphere(
double rmin,
double rmax,
double theta,
double delta_theta,
double phi,
double delta_phi) {
365 Sphere& Sphere::setDimensions(
double rmin,
double rmax,
double theta,
double delta_theta,
double phi,
double delta_phi) {
367 _setDimensions(params);
372 void Torus::make(
double r,
double rmin,
double rmax,
double phi,
double delta_phi) {
377 Torus& Torus::setDimensions(
double r,
double rmin,
double rmax,
double phi,
double delta_phi) {
379 _setDimensions(params);
384 Trap::Trap(
double z,
double theta,
double phi,
double y1,
double x1,
double x2,
double alpha1,
double y2,
double x3,
double x4,
386 _assign(
new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/
dd4hep::deg, y2, x3, x4, alpha2/
dd4hep::deg),
"",
"trap",
true);
390 void Trap::make(
double pz,
double py,
double px,
double pLTX) {
394 double y1 = py / 2e0;
395 double x1 = px / 2e0;
396 double x2 = pLTX / 2e0;
397 double alpha1 = (pLTX - px) / py;
398 _assign(
new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/
dd4hep::deg, y1, x1, x2, alpha1/
dd4hep::deg),
"",
"trap",
true);
402 Trap& Trap::setDimensions(
double z,
double theta,
double phi,
double y1,
double x1,
double x2,
double alpha1,
double y2,
403 double x3,
double x4,
double alpha2) {
404 double params[] = { z, theta, phi, y1, x1, x2, alpha1/
dd4hep::deg, y2, x3, x4, alpha2/
dd4hep::deg };
405 _setDimensions(params);
411 if (rmin < 0e0 || rmin > rmax)
412 throw runtime_error(
"DD4hep: PolyhedraRegular: Illegal argument rmin:<" +
_toString(rmin) +
"> is invalid!");
414 throw runtime_error(
"DD4hep: PolyhedraRegular: Illegal argument rmax:<" +
_toString(rmax) +
"> is invalid!");
415 _assign(
new TGeoPgon(),
"",
"polyhedra",
false);
416 double params[] = { start, delta, double(nsides), 2e0, zpos, rmin, rmax, zneg, rmin, rmax };
417 _setDimensions(¶ms[0]);
421 PolyhedraRegular::PolyhedraRegular(
int nsides,
double rmin,
double rmax,
double zlen) {
422 _create(nsides, rmin, rmax, zlen / 2, -zlen / 2, 0, 360.);
426 PolyhedraRegular::PolyhedraRegular(
int nsides,
double phistart,
double rmin,
double rmax,
double zlen) {
431 PolyhedraRegular::PolyhedraRegular(
int nsides,
double rmin,
double rmax,
double zplanes[2]) {
432 _create(nsides, rmin, rmax, zplanes[0], zplanes[1], 0, 360.);
436 void EightPointSolid::make(
double dz,
const double* vtx) {
437 _assign(
new TGeoArb8(dz, (
double*)vtx),
"",
"Arb8",
true);
441 SubtractionSolid::SubtractionSolid(
const Solid& shape1,
const Solid& shape2) {
443 _assign(
new TGeoCompositeShape(
"", sub),
"",
"subtraction",
true);
449 _assign(
new TGeoCompositeShape(
"", sub),
"",
"subtraction",
true);
455 _assign(
new TGeoCompositeShape(
"", sub),
"",
"subtraction",
true);
461 _assign(
new TGeoCompositeShape(
"", sub),
"",
"subtraction",
true);
467 _assign(
new TGeoCompositeShape(
"", sub),
"",
"subtraction",
true);
471 UnionSolid::UnionSolid(
const Solid& shape1,
const Solid& shape2) {
473 _assign(
new TGeoCompositeShape(
"", uni),
"",
"union",
true);
479 _assign(
new TGeoCompositeShape(
"", uni),
"",
"union",
true);
485 _assign(
new TGeoCompositeShape(
"", uni),
"",
"union",
true);
491 _assign(
new TGeoCompositeShape(
"", uni),
"",
"union",
true);
497 _assign(
new TGeoCompositeShape(
"", uni),
"",
"union",
true);
501 IntersectionSolid::IntersectionSolid(
const Solid& shape1,
const Solid& shape2) {
503 _assign(
new TGeoCompositeShape(
"", inter),
"",
"intersection",
true);
509 _assign(
new TGeoCompositeShape(
"", inter),
"",
"intersection",
true);
513 IntersectionSolid::IntersectionSolid(
const Solid& shape1,
const Solid& shape2,
const Position& pos) {
515 _assign(
new TGeoCompositeShape(
"", inter),
"",
"intersection",
true);
521 _assign(
new TGeoCompositeShape(
"", inter),
"",
"intersection",
true);
527 _assign(
new TGeoCompositeShape(
"", inter),
"",
"intersection",
true);
530 #define INSTANTIATE(X) template class DD4hep::Geometry::Solid_type<X>
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Class describing a Torus shape.
Class describing a Hyperboloid shape.
TGeoTranslation * _translation(const Geometry::Position &pos)
Convert a Position object to a TGeoTranslation
Class describing a cone segment shape.
Class describing a elliptical tube shape of a section of a tube.
TGeoRotation * _rotationZYX(const Geometry::RotationZYX &rot)
Convert a RotationZYX object to a TGeoRotation
Class describing a box shape.
Class describing a trap shape.
ROOT::Math::RotationZYX RotationZYX
TGeoIdentity * identityTransform()
Access the TGeo identity transformation
ROOT::Math::Rotation3D Rotation3D
Class describing a Paraboloid shape.
TGeoRotation * _rotation3D(const Geometry::Rotation3D &rot)
Convert a Rotation3D object to a TGeoRotation
Base class for Solid (shape) objects.
TGeoHMatrix * _transform(const Geometry::Transform3D &trans)
Convert a Transform3D object to a TGeoHMatrix
ROOT::Math::XYZVector Position
Intermediate class to overcome drawing probles with the TGeoTubeSeg.
Class describing a sphere shape.
Class describing a cone shape.
std::string toStringSolid(const TGeoShape *shape, int precision=2)
Pretty print of solid attributes.
ROOT::Math::Transform3D Transform3D
Class describing a Trapezoid shape.
static void * _create(const char *)
static std::string _toString(const DD4hep::XML::XmlChar *value)
std::string conversion of XML strings (e.g. Unicode for Xerces-C)
Class describing a tube shape of a section of a tube.