DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
ShapeUtilities.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #define _USE_MATH_DEFINES
15 
16 // Framework include files
17 #include <DD4hep/Shapes.h>
18 #include <DD4hep/MatrixHelpers.h>
19 #include <DD4hep/DD4hepUnits.h>
20 #include <DD4hep/ShapeTags.h>
21 #include <DD4hep/Printout.h>
23 
24 // C/C++ include files
25 #include <stdexcept>
26 #include <iomanip>
27 #include <sstream>
28 
29 // ROOT includes
30 #include <TClass.h>
31 #include <TGeoMatrix.h>
32 #include <TGeoBoolNode.h>
33 #include <TGeoScaledShape.h>
34 #include <TGeoCompositeShape.h>
35 
37 namespace dd4hep {
38 
39  // name units differently
40  namespace units = dd4hep;
41 
42  // Local, anonymous stuff
43  namespace {
44  template <typename T> inline T* get_ptr(const TGeoShape* shape) {
45  if ( shape && shape->IsA() == T::Class() ) return (T*)shape;
46  except("Dimension","Invalid shape pointer!");
47  return 0;
48  }
49  inline void invalidSetDimensionCall(const TGeoShape* sh, const std::vector<double>& params) {
50  except("Solid","+++ Shape:%s setDimension: Invalid number of parameters: %ld",
51  (sh ? typeName(typeid(*sh)) : typeName(typeid(sh))).c_str(), params.size());
52  }
53  template <typename T> inline bool check_shape_type(const Handle<TGeoShape>& solid) {
54  return solid.isValid() && solid->IsA() == T::Class();
55  }
56  }
57 
59  template <typename SOLID> bool isInstance(const Handle<TGeoShape>& solid) {
60  return check_shape_type<typename SOLID::Object>(solid);
61  }
62  template bool isInstance<Box> (const Handle<TGeoShape>& solid);
63  template bool isInstance<Scale> (const Handle<TGeoShape>& solid);
64  template bool isInstance<ShapelessSolid> (const Handle<TGeoShape>& solid);
65  template bool isInstance<HalfSpace> (const Handle<TGeoShape>& solid);
66  template bool isInstance<ConeSegment> (const Handle<TGeoShape>& solid);
67  template bool isInstance<CutTube> (const Handle<TGeoShape>& solid);
68  template bool isInstance<EllipticalTube> (const Handle<TGeoShape>& solid);
69  template bool isInstance<Trap> (const Handle<TGeoShape>& solid);
70  template bool isInstance<Trd1> (const Handle<TGeoShape>& solid);
71  template bool isInstance<Trd2> (const Handle<TGeoShape>& solid);
72  template bool isInstance<Torus> (const Handle<TGeoShape>& solid);
73  template bool isInstance<Sphere> (const Handle<TGeoShape>& solid);
74  template bool isInstance<Paraboloid> (const Handle<TGeoShape>& solid);
75  template bool isInstance<Hyperboloid> (const Handle<TGeoShape>& solid);
76  template bool isInstance<PolyhedraRegular> (const Handle<TGeoShape>& solid);
77  template bool isInstance<Polyhedra> (const Handle<TGeoShape>& solid);
78  template bool isInstance<ExtrudedPolygon> (const Handle<TGeoShape>& solid);
79  template bool isInstance<TessellatedSolid> (const Handle<TGeoShape>& solid);
80  template bool isInstance<BooleanSolid> (const Handle<TGeoShape>& solid);
81 
82  template <> bool isInstance<Cone>(const Handle<TGeoShape>& solid) {
83  return check_shape_type<TGeoConeSeg>(solid) || check_shape_type<TGeoCone>(solid);
84  }
85  template <> bool isInstance<Tube>(const Handle<TGeoShape>& solid) {
86  return check_shape_type<TGeoTubeSeg>(solid)
87  || check_shape_type<TGeoCtub>(solid)
88  || check_shape_type<TwistedTubeObject>(solid);
89  }
90  template <> bool isInstance<Polycone>(const Handle<TGeoShape>& solid) {
91  return check_shape_type<TGeoPcon>(solid) || check_shape_type<TGeoPgon>(solid);
92  }
93  template <> bool isInstance<EightPointSolid>(const Handle<TGeoShape>& solid) {
94  if ( solid.isValid() ) {
95  TClass* c = solid->IsA();
96  return c==TGeoArb8::Class() || c==TGeoTrap::Class() || c==TGeoGtra::Class();
97  }
98  return false;
99  }
100  template <> bool isInstance<TwistedTube>(const Handle<TGeoShape>& solid) {
101  return check_shape_type<TwistedTubeObject>(solid);
102  }
103  template <> bool isInstance<TruncatedTube>(const Handle<TGeoShape>& solid) {
104  return check_shape_type<TGeoCompositeShape>(solid)
105  && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0;
106  }
107  template <> bool isInstance<PseudoTrap>(const Handle<TGeoShape>& solid) {
108  return check_shape_type<TGeoCompositeShape>(solid)
109  && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0;
110  }
111  template <> bool isInstance<SubtractionSolid>(const Handle<TGeoShape>& solid) {
112  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
113  return sh && sh->IsA() == TGeoCompositeShape::Class()
114  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoSubtraction;
115  }
116  template <> bool isInstance<UnionSolid>(const Handle<TGeoShape>& solid) {
117  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
118  return sh && sh->IsA() == TGeoCompositeShape::Class()
119  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoUnion;
120  }
121  template <> bool isInstance<IntersectionSolid>(const Handle<TGeoShape>& solid) {
122  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
123  return sh && sh->IsA() == TGeoCompositeShape::Class()
124  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoIntersection;
125  }
126 
128  template <typename SOLID> bool isA(const Handle<TGeoShape>& solid) {
129  return check_shape_type<typename SOLID::Object>(solid);
130  }
131  template bool isA<Box>(const Handle<TGeoShape>& solid);
132  template bool isA<Scale>(const Handle<TGeoShape>& solid);
133  template bool isA<ShapelessSolid>(const Handle<TGeoShape>& solid);
134  template bool isA<HalfSpace>(const Handle<TGeoShape>& solid);
135  template bool isA<Cone>(const Handle<TGeoShape>& solid);
136  template bool isA<ConeSegment>(const Handle<TGeoShape>& solid);
137  template bool isA<Tube>(const Handle<TGeoShape>& solid);
138  template bool isA<CutTube>(const Handle<TGeoShape>& solid);
139  template bool isA<EllipticalTube>(const Handle<TGeoShape>& solid);
140  template bool isA<Trap>(const Handle<TGeoShape>& solid);
141  template bool isA<Trd1>(const Handle<TGeoShape>& solid);
142  template bool isA<Trd2>(const Handle<TGeoShape>& solid);
143  template bool isA<Torus>(const Handle<TGeoShape>& solid);
144  template bool isA<Sphere>(const Handle<TGeoShape>& solid);
145  template bool isA<Paraboloid>(const Handle<TGeoShape>& solid);
146  template bool isA<Hyperboloid>(const Handle<TGeoShape>& solid);
147  template bool isA<PolyhedraRegular>(const Handle<TGeoShape>& solid);
148  template bool isA<Polyhedra>(const Handle<TGeoShape>& solid);
149  template bool isA<ExtrudedPolygon>(const Handle<TGeoShape>& solid);
150  template bool isA<Polycone>(const Handle<TGeoShape>& solid);
151  template bool isA<EightPointSolid>(const Handle<TGeoShape>& solid);
152  template bool isA<TessellatedSolid>(const Handle<TGeoShape>& solid);
153  template <> bool isA<TwistedTube>(const Handle<TGeoShape>& solid) {
154  return check_shape_type<TwistedTubeObject>(solid)
155  && ::strcmp(solid->GetTitle(), TWISTEDTUBE_TAG) == 0;
156  }
157  template <> bool isA<TruncatedTube>(const Handle<TGeoShape>& solid) {
158  return check_shape_type<TGeoCompositeShape>(solid)
159  && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0;
160  }
161  template <> bool isA<PseudoTrap>(const Handle<TGeoShape>& solid) {
162  return check_shape_type<TGeoCompositeShape>(solid)
163  && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0;
164  }
165  template <> bool isA<SubtractionSolid>(const Handle<TGeoShape>& solid) {
166  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
167  return sh && sh->IsA() == TGeoCompositeShape::Class()
168  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoSubtraction
169  && ::strcmp(sh->GetTitle(), SUBTRACTION_TAG) == 0;
170  }
171  template <> bool isA<UnionSolid>(const Handle<TGeoShape>& solid) {
172  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
173  return sh && sh->IsA() == TGeoCompositeShape::Class()
174  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoUnion
175  && ::strcmp(sh->GetTitle(), UNION_TAG) == 0;
176  }
177  template <> bool isA<IntersectionSolid>(const Handle<TGeoShape>& solid) {
178  TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr();
179  return sh && sh->IsA() == TGeoCompositeShape::Class()
180  && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoIntersection
181  && ::strcmp(sh->GetTitle(), INTERSECTION_TAG) == 0;
182  }
183 
185  std::string get_shape_tag(const TGeoShape* sh) {
186  if ( sh ) {
187  TClass* cl = sh->IsA();
188  if ( cl == TGeoShapeAssembly::Class() )
189  return SHAPELESS_TAG;
190  else if ( cl == TGeoBBox::Class() )
191  return BOX_TAG;
192  else if ( cl == TGeoHalfSpace::Class() )
193  return HALFSPACE_TAG;
194  else if ( cl == TGeoPgon::Class() )
195  return POLYHEDRA_TAG;
196  else if ( cl == TGeoPcon::Class() )
197  return POLYCONE_TAG;
198  else if ( cl == TGeoConeSeg::Class() )
199  return CONESEGMENT_TAG;
200  else if ( cl == TGeoCone::Class() )
201  return CONE_TAG;
202  else if ( cl == TGeoTube::Class() )
203  return TUBE_TAG;
204  else if ( cl == TGeoTubeSeg::Class() )
205  return TUBE_TAG;
206  else if ( cl == TGeoCtub::Class() )
207  return CUTTUBE_TAG;
208  else if ( cl == TGeoEltu::Class() )
209  return ELLIPTICALTUBE_TAG;
210  else if ( cl == TwistedTubeObject::Class() )
211  return TWISTEDTUBE_TAG;
212  else if ( cl == TGeoTrd1::Class() )
213  return TRD1_TAG;
214  else if ( cl == TGeoTrd2::Class() )
215  return TRD2_TAG;
216  else if ( cl == TGeoParaboloid::Class() )
217  return PARABOLOID_TAG;
218  else if ( cl == TGeoHype::Class() )
219  return HYPERBOLOID_TAG;
220  //else if ( cl == TGeoGtra::Class() )
221  // return
222  else if ( cl == TGeoTrap::Class() )
223  return TRAP_TAG;
224  else if ( cl == TGeoArb8::Class() )
225  return EIGHTPOINTSOLID_TAG;
226  else if ( cl == TGeoSphere::Class() )
227  return SPHERE_TAG;
228  else if ( cl == TGeoTorus::Class() )
229  return TORUS_TAG;
230  else if ( cl == TGeoXtru::Class() )
231  return EXTRUDEDPOLYGON_TAG;
232  else if ( cl == TGeoScaledShape::Class() )
233  return SCALE_TAG;
234  else if ( cl == TGeoTessellated::Class() )
235  return TESSELLATEDSOLID_TAG;
236  else if (isA<TruncatedTube>(sh) )
237  return TRUNCATEDTUBE_TAG;
238  else if (isA<PseudoTrap>(sh) )
239  return PSEUDOTRAP_TAG;
240  else if ( isInstance<SubtractionSolid>(sh) )
241  return SUBTRACTION_TAG;
242  else if ( isInstance<UnionSolid>(sh) )
243  return UNION_TAG;
244  else if ( isInstance<IntersectionSolid>(sh) )
245  return INTERSECTION_TAG;
246  else
247  except("Solid","Failed to type of shape: %s [%s]",
248  sh->GetName(), cl->GetName() );
249  return "";
250  }
251  except("Solid","Failed to access dimensions [Invalid handle].");
252  return "";
253  }
254 
255  template <typename T> std::vector<double> dimensions(const TGeoShape* shape) {
256  std::stringstream str;
257  if ( shape )
258  str << "Shape: dimension(" << typeName(typeid(*shape)) << "): Invalid call!";
259  else
260  str << "Shape: dimension<TGeoShape): Invalid call && pointer!";
261  throw std::runtime_error(str.str());
262  }
263  template <> std::vector<double> dimensions<TGeoShapeAssembly>(const TGeoShape* shape) {
264  const auto* sh = get_ptr<TGeoShapeAssembly>(shape);
265  return { sh->GetDX(), sh->GetDY(), sh->GetDZ() };
266  }
267  template <> std::vector<double> dimensions<TGeoBBox>(const TGeoShape* shape) {
268  const auto* sh = get_ptr<TGeoBBox>(shape);
269  return { sh->GetDX(), sh->GetDY(), sh->GetDZ() };
270  }
271  template <> std::vector<double> dimensions<TGeoHalfSpace>(const TGeoShape* shape) {
272  auto* sh = get_ptr<TGeoHalfSpace>(shape);
273  return { sh->GetPoint()[0], sh->GetPoint()[1], sh->GetPoint()[2],
274  sh->GetNorm()[0], sh->GetNorm()[1], sh->GetNorm()[2] };
275  }
276  template <> std::vector<double> dimensions<TGeoPcon>(const TGeoShape* shape) {
277  const TGeoPcon* sh = get_ptr<TGeoPcon>(shape);
278  std::vector<double> pars { sh->GetPhi1()*units::deg, sh->GetDphi()*units::deg, double(sh->GetNz()) };
279  pars.reserve(3+3*sh->GetNz());
280  for (Int_t i = 0; i < sh->GetNz(); ++i) {
281  pars.emplace_back(sh->GetZ(i));
282  pars.emplace_back(sh->GetRmin(i));
283  pars.emplace_back(sh->GetRmax(i));
284  }
285  return pars;
286  }
287  template <> std::vector<double> dimensions<TGeoConeSeg>(const TGeoShape* shape) {
288  const TGeoConeSeg* sh = get_ptr<TGeoConeSeg>(shape);
289  return { sh->GetDz(), sh->GetRmin1(), sh->GetRmax1(), sh->GetRmin2(), sh->GetRmax2(),
290  sh->GetPhi1()*units::deg, sh->GetPhi2()*units::deg };
291  }
292  template <> std::vector<double> dimensions<TGeoCone>(const TGeoShape* shape) {
293  const TGeoCone* sh = get_ptr<TGeoCone>(shape);
294  return { sh->GetDz(), sh->GetRmin1(), sh->GetRmax1(), sh->GetRmin2(), sh->GetRmax2() };
295  }
296  template <> std::vector<double> dimensions<TGeoTube>(const TGeoShape* shape) {
297  const TGeoTube* sh = get_ptr<TGeoTube>(shape);
298  return { sh->GetRmin(), sh->GetRmax(), sh->GetDz() };
299  }
300  template <> std::vector<double> dimensions<TGeoTubeSeg>(const TGeoShape* shape) {
301  const TGeoTubeSeg* sh = get_ptr<TGeoTubeSeg>(shape);
302  return { sh->GetRmin(), sh->GetRmax(), sh->GetDz(), sh->GetPhi1()*units::deg, sh->GetPhi2()*units::deg };
303  }
304  template <> std::vector<double> dimensions<TwistedTubeObject>(const TGeoShape* shape) {
305  const TwistedTubeObject* sh = get_ptr<TwistedTubeObject>(shape);
306  return { sh->GetPhiTwist(), sh->GetRmin(), sh->GetRmax(),
307  sh->GetNegativeEndZ(), sh->GetPositiveEndZ(),
308  double(sh->GetNsegments()), sh->GetPhi2()*units::deg };
309  }
310  template <> std::vector<double> dimensions<TGeoCtub>(const TGeoShape* shape) {
311  const TGeoCtub* sh = get_ptr<TGeoCtub>(shape);
312  const Double_t* lo = sh->GetNlow();
313  const Double_t* hi = sh->GetNhigh();
314  return { sh->GetRmin(), sh->GetRmax(), sh->GetDz(),
315  sh->GetPhi1()*units::deg, sh->GetPhi2()*units::deg,
316  lo[0], lo[1], lo[2], hi[0], hi[1], hi[2] };
317  }
318  template <> std::vector<double> dimensions<TGeoEltu>(const TGeoShape* shape) {
319  const TGeoEltu* sh = get_ptr<TGeoEltu>(shape);
320  return { sh->GetA(), sh->GetB(), sh->GetDz() };
321  }
322  template <> std::vector<double> dimensions<TGeoTrd1>(const TGeoShape* shape) {
323  const TGeoTrd1* sh = get_ptr<TGeoTrd1>(shape);
324  return { sh->GetDx1(), sh->GetDx2(), sh->GetDy(), sh->GetDz() };
325  }
326  template <> std::vector<double> dimensions<TGeoTrd2>(const TGeoShape* shape) {
327  const TGeoTrd2* sh = get_ptr<TGeoTrd2>(shape);
328  return { sh->GetDx1(), sh->GetDx2(), sh->GetDy1(), sh->GetDy2(), sh->GetDz() };
329  }
330  template <> std::vector<double> dimensions<TGeoParaboloid>(const TGeoShape* shape) {
331  const TGeoParaboloid* sh = get_ptr<TGeoParaboloid>(shape);
332  return { sh->GetRlo(), sh->GetRhi(), sh->GetDz() };
333  }
334  template <> std::vector<double> dimensions<TGeoHype>(const TGeoShape* shape) {
335  const TGeoHype* sh = get_ptr<TGeoHype>(shape);
336  return { sh->GetDz(),
337  sh->GetRmin(), sh->GetStIn()*units::deg,
338  sh->GetRmax(), sh->GetStOut()*units::deg };
339  }
340  template <> std::vector<double> dimensions<TGeoSphere>(const TGeoShape* shape) {
341  const TGeoSphere* sh = get_ptr<TGeoSphere>(shape);
342  return { sh->GetRmin(), sh->GetRmax(),
343  sh->GetTheta1()*units::deg, sh->GetTheta2()*units::deg,
344  sh->GetPhi1()*units::deg, sh->GetPhi2()*units::deg };
345  }
346  template <> std::vector<double> dimensions<TGeoTorus>(const TGeoShape* shape) {
347  const TGeoTorus* sh = get_ptr<TGeoTorus>(shape);
348  return { sh->GetR(), sh->GetRmin(), sh->GetRmax(),
349  sh->GetPhi1()*units::deg, sh->GetDphi()*units::deg };
350  }
351  template <> std::vector<double> dimensions<TGeoPgon>(const TGeoShape* shape) {
352  const TGeoPgon* sh = get_ptr<TGeoPgon>(shape);
353  std::vector<double> pars { sh->GetPhi1()*units::deg, sh->GetDphi()*units::deg, double(sh->GetNedges()), double(sh->GetNz()) };
354  pars.reserve(4+3*sh->GetNz());
355  for (Int_t i = 0; i < sh->GetNz(); ++i) {
356  pars.emplace_back(sh->GetZ(i));
357  pars.emplace_back(sh->GetRmin(i));
358  pars.emplace_back(sh->GetRmax(i));
359  }
360  return pars;
361  }
362  template <> std::vector<double> dimensions<TGeoXtru>(const TGeoShape* shape) {
363  const TGeoXtru* sh = get_ptr<TGeoXtru>(shape);
364  Int_t nz = sh->GetNz();
365  std::vector<double> pars { double(nz) };
366  pars.reserve(1+4*nz);
367  for(Int_t i=0; i<nz; ++i) {
368  pars.emplace_back(sh->GetZ(i));
369  pars.emplace_back(sh->GetXOffset(i));
370  pars.emplace_back(sh->GetYOffset(i));
371  pars.emplace_back(sh->GetScale(i));
372  }
373  return pars;
374  }
375  template <> std::vector<double> dimensions<TGeoArb8>(const TGeoShape* shape) {
376  TGeoArb8* sh = get_ptr<TGeoArb8>(shape);
377  struct _V { double xy[8][2]; } *vtx = (_V*)sh->GetVertices();
378  std::vector<double> pars { sh->GetDz() };
379  for ( std::size_t i=0; i<8; ++i ) {
380  pars.emplace_back(vtx->xy[i][0]);
381  pars.emplace_back(vtx->xy[i][1]);
382  }
383  return pars;
384  }
385  template <> std::vector<double> dimensions<TGeoTrap>(const TGeoShape* shape) {
386  const TGeoTrap* sh = get_ptr<TGeoTrap>(shape);
387  return { sh->GetDz(), sh->GetTheta()*units::deg, sh->GetPhi()*units::deg,
388  sh->GetH1(), sh->GetBl1(), sh->GetTl1(), sh->GetAlpha1()*units::deg,
389  sh->GetH2(), sh->GetBl2(), sh->GetTl2(), sh->GetAlpha2()*units::deg };
390  }
391  template <> std::vector<double> dimensions<TGeoGtra>(const TGeoShape* shape) {
392  const TGeoGtra* sh = get_ptr<TGeoGtra>(shape);
393  return { sh->GetDz(), sh->GetTheta()*units::deg, sh->GetPhi()*units::deg,
394  sh->GetH1(), sh->GetBl1(), sh->GetTl1(), sh->GetAlpha1()*units::deg,
395  sh->GetH2(), sh->GetBl2(), sh->GetTl2(), sh->GetAlpha2()*units::deg,
396  sh->GetTwistAngle()*units::deg };
397  }
398  template <> std::vector<double> dimensions<TGeoScaledShape>(const TGeoShape* shape) {
399  TGeoScaledShape* sh = get_ptr<TGeoScaledShape>(shape);
400  TGeoShape* s_sh = sh->GetShape();
401  const Double_t* scale = sh->GetScale()->GetScale();
402  std::vector<double> pars {scale[0],scale[1],scale[2]};
403  std::vector<double> s_pars = get_shape_dimensions(s_sh);
404  for(auto p : s_pars) pars.push_back(p);
405  return pars;
406  }
407 
408  template <> std::vector<double> dimensions<TGeoTessellated>(const TGeoShape* shape) {
409  TGeoTessellated* sh = get_ptr<TGeoTessellated>(shape);
410  int num_facet = sh->GetNfacets();
411  int num_vtx = sh->GetNvertices();
412  std::vector<double> pars;
413 
414  printout(DEBUG,"TessellatedSolid","+++ Saving %d vertices, %d facets",num_vtx, num_facet);
415  pars.reserve(num_facet*5+num_vtx*3+2);
416  pars.emplace_back(num_vtx);
417  pars.emplace_back(num_facet);
418  for(int i=0; i<num_vtx; ++i) {
419  const auto& v = sh->GetVertex(i);
420  pars.emplace_back(v.x());
421  pars.emplace_back(v.y());
422  pars.emplace_back(v.z());
423  }
424  for(int i=0; i<num_facet; ++i) {
425  const TGeoFacet& f = sh->GetFacet(i);
426  pars.emplace_back(double(f.GetNvert()));
427  for(int j=0, n=f.GetNvert(); j<n; ++j) {
428 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1)
429  int idx = f[j];
430  pars.emplace_back(double(idx));
431 #else
432  pars.emplace_back(double(f.GetVertexIndex(j)));
433 #endif
434  }
435  }
436  return pars;
437  }
438 
439  template <> std::vector<double> dimensions<TGeoCompositeShape>(const TGeoShape* shape) {
440  const TGeoCompositeShape* sh = get_ptr<TGeoCompositeShape>(shape);
441  const TGeoBoolNode* boolean = sh->GetBoolNode();
442  TGeoMatrix* right_matrix = boolean->GetRightMatrix();
443  TGeoShape* left_solid = boolean->GetLeftShape();
444  TGeoShape* right_solid = boolean->GetRightShape();
445 
446  TGeoBoolNode::EGeoBoolType oper = boolean->GetBooleanOperator();
447  TGeoMatrix* left_matrix = boolean->GetRightMatrix();
448  const Double_t* left_tr = left_matrix->GetTranslation();
449  const Double_t* left_rot = left_matrix->GetRotationMatrix();
450  const Double_t* right_tr = right_matrix->GetTranslation();
451  const Double_t* right_rot = right_matrix->GetRotationMatrix();
452 
453  std::vector<double> pars { double(oper) };
454  std::vector<double> left_par = Solid(left_solid).dimensions();
455  std::vector<double> right_par = Solid(right_solid).dimensions();
456 
457  pars.insert(pars.end(), left_par.begin(), left_par.end());
458  pars.insert(pars.end(), left_rot, left_rot+9);
459  pars.insert(pars.end(), left_tr, left_tr+3);
460 
461  pars.insert(pars.end(), right_par.begin(), right_par.end());
462  pars.insert(pars.end(), right_rot, right_rot+9);
463  pars.insert(pars.end(), right_tr, right_tr+3);
464  return pars;
465  }
466 
467  template <typename T> std::vector<double> dimensions(const Handle<TGeoShape>& shape)
468  { return dimensions<typename T::Object>(get_ptr<typename T::Object>(shape.ptr())); }
469  template std::vector<double> dimensions<ShapelessSolid> (const Handle<TGeoShape>& shape);
470  template std::vector<double> dimensions<Box> (const Handle<TGeoShape>& shape);
471  template std::vector<double> dimensions<Scale> (const Handle<TGeoShape>& shape);
472  template std::vector<double> dimensions<HalfSpace> (const Handle<TGeoShape>& shape);
473  template std::vector<double> dimensions<Polycone> (const Handle<TGeoShape>& shape);
474  template std::vector<double> dimensions<ConeSegment> (const Handle<TGeoShape>& shape);
475  template std::vector<double> dimensions<Tube> (const Handle<TGeoShape>& shape);
476  template std::vector<double> dimensions<CutTube> (const Handle<TGeoShape>& shape);
477  template std::vector<double> dimensions<TwistedTube> (const Handle<TGeoShape>& shape);
478  template std::vector<double> dimensions<EllipticalTube> (const Handle<TGeoShape>& shape);
479  template std::vector<double> dimensions<Cone> (const Handle<TGeoShape>& shape);
480  template std::vector<double> dimensions<Trap> (const Handle<TGeoShape>& shape);
481  template std::vector<double> dimensions<Trd1> (const Handle<TGeoShape>& shape);
482  template std::vector<double> dimensions<Trd2> (const Handle<TGeoShape>& shape);
483  template std::vector<double> dimensions<Torus> (const Handle<TGeoShape>& shape);
484  template std::vector<double> dimensions<Sphere> (const Handle<TGeoShape>& shape);
485  template std::vector<double> dimensions<Paraboloid> (const Handle<TGeoShape>& shape);
486  template std::vector<double> dimensions<Hyperboloid> (const Handle<TGeoShape>& shape);
487  template std::vector<double> dimensions<PolyhedraRegular> (const Handle<TGeoShape>& shape);
488  template std::vector<double> dimensions<Polyhedra> (const Handle<TGeoShape>& shape);
489  template std::vector<double> dimensions<ExtrudedPolygon> (const Handle<TGeoShape>& shape);
490  template std::vector<double> dimensions<EightPointSolid> (const Handle<TGeoShape>& shape);
491  template std::vector<double> dimensions<TessellatedSolid> (const Handle<TGeoShape>& shape);
492  template std::vector<double> dimensions<BooleanSolid> (const Handle<TGeoShape>& shape);
493  template std::vector<double> dimensions<SubtractionSolid> (const Handle<TGeoShape>& shape);
494  template std::vector<double> dimensions<UnionSolid> (const Handle<TGeoShape>& shape);
495  template std::vector<double> dimensions<IntersectionSolid>(const Handle<TGeoShape>& shape);
496 
497  template <> std::vector<double> dimensions<PseudoTrap>(const Handle<TGeoShape>& shape) {
498  const TGeoCompositeShape* sh = get_ptr<TGeoCompositeShape>(shape.ptr());
499  TGeoMatrix* right_matrix = sh->GetBoolNode()->GetRightMatrix();
500  std::stringstream params(right_matrix->GetTitle());
501  std::vector<double> pars;
502  pars.reserve(7);
503 #ifdef DIMENSION_DEBUG
504  cout << "dimensions: [" << PSEUDOTRAP_TAG << "]" << endl
505  << right_matrix->GetTitle() << endl;
506 #endif
507  for(std::size_t i=0; i<7; ++i) {
508  double val;
509  params >> val;
510  pars.emplace_back(val);
511  if ( !params.good() ) {
512  except("PseudoTrap","+++ dimensions: Invalid parameter stream.");
513  }
514  }
515  return pars;
516  }
517 
518  template <> std::vector<double> dimensions<TruncatedTube>(const Handle<TGeoShape>& shape) {
519  const TGeoCompositeShape* sh = get_ptr<TGeoCompositeShape>(shape.ptr());
520  TGeoMatrix* right_matrix = sh->GetBoolNode()->GetRightMatrix();
521  std::stringstream params(right_matrix->GetTitle());
522  std::vector<double> pars;
523  pars.reserve(8);
524  for(std::size_t i=0; i<8; ++i) {
525  double val;
526  params >> val;
527  pars.emplace_back(val);
528  if ( !params.good() ) {
529  except("TruncatedTube","+++ dimensions: Invalid parameter stream.");
530  }
531  }
532  return pars;
533  }
534 
535  template <> std::vector<double> dimensions<Solid>(const Handle<TGeoShape>& shape) {
536  if ( shape.ptr() ) {
537  TClass* cl = shape->IsA();
538  if ( cl == TGeoShapeAssembly::Class() )
539  return dimensions<TGeoShapeAssembly>(shape.ptr() );
540  else if ( cl == TGeoBBox::Class() )
541  return dimensions<TGeoBBox>(shape.ptr() );
542  else if ( cl == TGeoHalfSpace::Class() )
543  return dimensions<TGeoHalfSpace>(shape.ptr() );
544  else if ( cl == TGeoPgon::Class() )
545  return dimensions<TGeoPgon>(shape.ptr() );
546  else if ( cl == TGeoPcon::Class() )
547  return dimensions<TGeoPcon>(shape.ptr() );
548  else if ( cl == TGeoConeSeg::Class() )
549  return dimensions<TGeoConeSeg>(shape.ptr() );
550  else if ( cl == TGeoCone::Class() )
551  return dimensions<TGeoCone>(shape.ptr() );
552  else if ( cl == TGeoTube::Class() )
553  return dimensions<TGeoTube>(shape.ptr() );
554  else if ( cl == TGeoTubeSeg::Class() )
555  return dimensions<TGeoTubeSeg>(shape.ptr() );
556  else if ( cl == TGeoCtub::Class() )
557  return dimensions<TGeoCtub>(shape.ptr() );
558  else if ( cl == TGeoEltu::Class() )
559  return dimensions<TGeoEltu>(shape.ptr() );
560  else if ( cl == TwistedTubeObject::Class() )
561  return dimensions<TwistedTubeObject>(shape.ptr() );
562  else if ( cl == TGeoTrd1::Class() )
563  return dimensions<TGeoTrd1>(shape.ptr() );
564  else if ( cl == TGeoTrd2::Class() )
565  return dimensions<TGeoTrd2>(shape.ptr() );
566  else if ( cl == TGeoParaboloid::Class() )
567  return dimensions<TGeoParaboloid>(shape.ptr() );
568  else if ( cl == TGeoHype::Class() )
569  return dimensions<TGeoHype>(shape.ptr() );
570  else if ( cl == TGeoGtra::Class() )
571  return dimensions<TGeoGtra>(shape.ptr() );
572  else if ( cl == TGeoTrap::Class() )
573  return dimensions<TGeoTrap>(shape.ptr() );
574  else if ( cl == TGeoArb8::Class() )
575  return dimensions<TGeoArb8>(shape.ptr() );
576  else if ( cl == TGeoSphere::Class() )
577  return dimensions<TGeoSphere>(shape.ptr() );
578  else if ( cl == TGeoTorus::Class() )
579  return dimensions<TGeoTorus>(shape.ptr() );
580  else if ( cl == TGeoXtru::Class() )
581  return dimensions<TGeoXtru>(shape.ptr() );
582  else if ( cl == TGeoScaledShape::Class() )
583  return dimensions<TGeoScaledShape>(shape.ptr() );
584  else if ( cl == TGeoTessellated::Class() )
585  return dimensions<TGeoTessellated>(shape.ptr() );
586  else if (isA<TruncatedTube>(shape.ptr() ))
587  return dimensions<TruncatedTube>(shape);
588  else if (isA<PseudoTrap>(shape.ptr() ))
589  return dimensions<PseudoTrap>(shape);
590  else if ( cl == TGeoCompositeShape::Class() )
591  return dimensions<TGeoCompositeShape>(shape.ptr() );
592  else {
593  printout(ERROR,"Solid","Failed to access dimensions for shape of type:%s.",
594  cl->GetName());
595  }
596  return {};
597  }
598  except("Solid","Failed to access dimensions [Invalid handle].");
599  return {};
600  }
601 
603  std::vector<double> get_shape_dimensions(const Handle<TGeoShape>& shape) {
604  return dimensions<Solid>(shape);
605  }
607  std::vector<double> get_shape_dimensions(TGeoShape* shape) {
608  return dimensions<Solid>(Solid(shape));
609  }
610 
611  template <typename T> void set_dimensions(T shape, const std::vector<double>& ) {
612  std::stringstream str;
613  if ( shape )
614  str << "Shape: set_dimension(" << typeName(typeid(*shape)) << "): Invalid call!";
615  else
616  str << "Shape: set_dimension<TGeoShape): Invalid call && pointer!";
617  throw std::runtime_error(str.str());
618  }
619 
620  template <> void set_dimensions(TGeoShapeAssembly* , const std::vector<double>& ) {
621  printout(WARNING,"ShapelessSolid","+++ setDimensions is a compatibility call. Nothing implemented.");
622  }
623  template <> void set_dimensions(TGeoBBox* sh, const std::vector<double>& params) {
624  auto pars = params;
625  if ( pars.size() != 3 ) {
626  invalidSetDimensionCall(sh,params);
627  }
628  Solid(sh)._setDimensions(&pars[0]);
629  }
630  template <> void set_dimensions(TGeoHalfSpace* sh, const std::vector<double>& params) {
631  auto pars = params;
632  if ( params.size() != 6 ) {
633  invalidSetDimensionCall(sh,params);
634  }
635  Solid(sh)._setDimensions(&pars[0]);
636  }
637  template <> void set_dimensions(TGeoPcon* sh, const std::vector<double>& params) {
638  if ( params.size() < 3 ) {
639  invalidSetDimensionCall(sh,params);
640  }
641  std::size_t nz = std::size_t(params[2]);
642  if ( params.size() != 3 + 3*nz ) {
643  invalidSetDimensionCall(sh,params);
644  }
645  std::vector<double> pars = params;
646  pars[0] /= units::deg;
647  pars[1] /= units::deg;
648  Solid(sh)._setDimensions(&pars[0]);
649  }
650  template <> void set_dimensions(TGeoConeSeg* sh, const std::vector<double>& params) {
651  if ( params.size() != 7 ) {
652  invalidSetDimensionCall(sh,params);
653  }
654  auto pars = params;
655  pars[5] /= units::deg;
656  pars[6] /= units::deg;
657  Solid(sh)._setDimensions(&pars[0]);
658  }
659  template <> void set_dimensions(TGeoCone* sh, const std::vector<double>& params) {
660  auto pars = params;
661  if ( params.size() != 5 ) {
662  invalidSetDimensionCall(sh,params);
663  }
664  Solid(sh)._setDimensions(&pars[0]);
665  }
666  template <> void set_dimensions(TGeoTube* sh, const std::vector<double>& params) {
667  if ( params.size() != 3 ) {
668  invalidSetDimensionCall(sh,params);
669  }
670  auto pars = params;
671  Solid(sh)._setDimensions(&pars[0]);
672  }
673  template <> void set_dimensions(TGeoTubeSeg* sh, const std::vector<double>& params) {
674  if ( params.size() != 5 ) {
675  invalidSetDimensionCall(sh,params);
676  }
677  auto pars = params;
678  pars[3] /= units::deg;
679  pars[4] /= units::deg;
680  Solid(sh)._setDimensions(&pars[0]);
681  }
682  template <> void set_dimensions(TwistedTubeObject* sh, const std::vector<double>& params) {
683  if ( params.size() != 7 ) {
684  invalidSetDimensionCall(sh,params);
685  }
686  auto pars = params;
687  sh->fPhiTwist = pars[0]/units::deg;
688  sh->fNegativeEndz = pars[3];
689  sh->fPositiveEndz = pars[4];
690  sh->fNsegments = (int)pars[5];
691 
692  pars[0] = pars[1];
693  pars[1] = pars[2];
694  pars[2] = (-pars[3]+pars[4])/2.0;
695  pars[3] = 0.0;
696  pars[4] = pars[6];
697  pars.resize(5);
698  set_dimensions((TGeoTubeSeg*)sh, pars);
699  }
700  template <> void set_dimensions(TGeoCtub* sh, const std::vector<double>& params) {
701  if ( params.size() != 11 ) {
702  invalidSetDimensionCall(sh,params);
703  }
704  auto pars = params;
705  pars[3] /= units::deg;
706  pars[4] /= units::deg;
707  Solid(sh)._setDimensions(&pars[0]);
708  }
709  template <> void set_dimensions(TGeoEltu* sh, const std::vector<double>& params) {
710  auto pars = params;
711  if ( params.size() != 3 ) {
712  invalidSetDimensionCall(sh,params);
713  }
714  Solid(sh)._setDimensions(&pars[0]);
715  }
716  template <> void set_dimensions(TGeoTrd1* sh, const std::vector<double>& params) {
717  auto pars = params;
718  if ( params.size() != 4 ) {
719  invalidSetDimensionCall(sh,params);
720  }
721  Solid(sh)._setDimensions(&pars[0]);
722  }
723  template <> void set_dimensions(TGeoTrd2* sh, const std::vector<double>& params) {
724  auto pars = params;
725  if ( params.size() != 5 ) {
726  invalidSetDimensionCall(sh,params);
727  }
728  Solid(sh)._setDimensions(&pars[0]);
729  }
730  template <> void set_dimensions(TGeoParaboloid* sh, const std::vector<double>& params) {
731  auto pars = params;
732  if ( params.size() != 3 ) {
733  invalidSetDimensionCall(sh,params);
734  }
735  Solid(sh)._setDimensions(&pars[0]);
736  }
737  template <> void set_dimensions(TGeoHype* sh, const std::vector<double>& params) {
738  if ( params.size() != 5 ) {
739  invalidSetDimensionCall(sh,params);
740  }
741  double pars[] = { params[0], params[1], params[2]/units::deg, params[3], params[4]/units::deg };
742  Solid(sh)._setDimensions(pars);
743  }
744  template <> void set_dimensions(TGeoSphere* sh, const std::vector<double>& params) {
745  if ( params.size() < 2 ) {
746  invalidSetDimensionCall(sh,params);
747  }
748  double pars[] = { params[0], params[1], 0.0, M_PI/units::deg, 0.0, 2*M_PI/units::deg };
749  if (params.size() > 2) pars[2] = params[2]/units::deg;
750  if (params.size() > 3) pars[3] = params[3]/units::deg;
751  if (params.size() > 4) pars[4] = params[4]/units::deg;
752  if (params.size() > 5) pars[5] = params[5]/units::deg;
753  Sphere(sh).access()->SetDimensions(pars, params.size());
754  sh->ComputeBBox();
755  }
756  template <> void set_dimensions(TGeoTorus* sh, const std::vector<double>& params) {
757  if ( params.size() != 5 ) {
758  invalidSetDimensionCall(sh,params);
759  }
760  double pars[] = { params[0], params[1], params[2], params[3]/units::deg, params[4]/units::deg };
761  Solid(sh)._setDimensions(&pars[0]);
762  }
763  template <> void set_dimensions(TGeoPgon* sh, const std::vector<double>& params) {
764  auto pars = params;
765  if ( params.size() < 4 || params.size() != 4 + 3*std::size_t(params[3]) ) {
766  invalidSetDimensionCall(sh,params);
767  }
768  pars[0] /= units::deg;
769  pars[1] /= units::deg;
770  Solid(sh)._setDimensions(&pars[0]);
771  }
772  template <> void set_dimensions(TGeoXtru* sh, const std::vector<double>& params) {
773  auto pars = params;
774  if ( params.size() < 1 || params.size() != 1 + 4*std::size_t(params[0]) ) {
775  invalidSetDimensionCall(sh,params);
776  }
777  Solid(sh)._setDimensions(&pars[0]);
778  }
779  template <> void set_dimensions(TGeoArb8* sh, const std::vector<double>& params) {
780  if ( params.size() != 17 ) {
781  invalidSetDimensionCall(sh,params);
782  }
783  auto pars = params;
784  Solid(sh)._setDimensions(&pars[0]);
785  }
786  template <> void set_dimensions(TGeoTrap* sh, const std::vector<double>& params) {
787  auto pars = params;
788  if ( params.size() != 11 ) {
789  invalidSetDimensionCall(sh,params);
790  }
791  pars[1] /= units::deg;
792  pars[2] /= units::deg;
793  pars[6] /= units::deg;
794  pars[10] /= units::deg;
795  Solid(sh)._setDimensions(&pars[0]);
796  }
797  template <> void set_dimensions(TGeoGtra* sh, const std::vector<double>& params) {
798  auto pars = params;
799  if ( params.size() != 12 ) {
800  invalidSetDimensionCall(sh,params);
801  }
802  pars[1] /= units::deg;
803  pars[2] /= units::deg;
804  pars[6] /= units::deg;
805  pars[10] /= units::deg;
806  pars[11] /= units::deg;
807  Solid(sh)._setDimensions(&pars[0]);
808  }
809  template <> void set_dimensions(TGeoScaledShape* sh, const std::vector<double>& params) {
810  Solid s_sh(sh->GetShape());
811  sh->GetScale()->SetScale(params[0], params[1], params[2]);
812  auto pars = params;
813  s_sh.access()->SetDimensions(&pars[3]);
814  }
815 
816  template <> void set_dimensions(TGeoTessellated* sh, const std::vector<double>& params) {
817  int num_vtx = params[0];
818  int num_facet = params[1];
819  std::vector<TessellatedSolid::Vertex> vertices;
820  std::size_t i_par = 1;
821  printout(DEBUG,"TessellatedSolid","+++ Loading %d vertices, %d facets",num_vtx, num_facet);
822  for (int i=0; i<num_vtx; ++i) {
823  double x = params[++i_par];
824  double y = params[++i_par];
825  double z = params[++i_par];
826  vertices.emplace_back(x, y, z);
827  }
828  std::string nam = sh->GetName();
829  std::string tit = sh->GetTitle();
830  sh->~TGeoTessellated();
831  new(sh) TGeoTessellated(nam.c_str(), vertices);
832  sh->SetTitle(tit.c_str());
833  for (int i=0; i<num_facet; ++i) {
834  int i0, i1, i2, i3;
835  int n_vtx = params[++i_par];
836  i0 = n_vtx>0 ? params[++i_par] : -1;
837  i1 = n_vtx>1 ? params[++i_par] : -1;
838  i2 = n_vtx>2 ? params[++i_par] : -1;
839  i3 = n_vtx>3 ? params[++i_par] : -1;
840  if ( n_vtx == 3 )
841  sh->AddFacet(i0,i1,i2);
842  else if ( n_vtx == 4 )
843  sh->AddFacet(i0,i1,i2,i3);
844  }
845  sh->CloseShape(true, true, false);
846  }
847 
848  template <> void set_dimensions(TGeoCompositeShape*, const std::vector<double>&) {
849  // In general TGeoCompositeShape instances have an empty SetDimension call
850 #if 0
851  TGeoCompositeShape* sh = (TGeoCompositeShape*) shape;
852  TGeoBoolNode* boolean = sh->GetBoolNode();
853  TGeoMatrix* right_matrix = boolean->GetRightMatrix();
854  TGeoShape* left_solid = boolean->GetLeftShape();
855  TGeoShape* right_solid = boolean->GetRightShape();
856  auto pars = params;
857  Solid(sh)._setDimensions(&pars[0]);
858 #endif
859 #ifdef DIMENSION_DEBUG
860  throw std::runtime_error("Composite shape. setDimensions is not implemented!");
861 #endif
862  }
863 
864  template <> void set_dimensions(ShapelessSolid shape, const std::vector<double>& params)
865  { set_dimensions(shape.ptr(), params); }
866  template <> void set_dimensions(Box shape, const std::vector<double>& params)
867  { set_dimensions(shape.ptr(), params); }
868  template <> void set_dimensions(Scale shape, const std::vector<double>& params)
869  { set_dimensions(shape.ptr(), params); }
870  template <> void set_dimensions(HalfSpace shape, const std::vector<double>& params)
871  { set_dimensions(shape.ptr(), params); }
872  template <> void set_dimensions(Polycone shape, const std::vector<double>& params)
873  { set_dimensions(shape.ptr(), params); }
874  template <> void set_dimensions(Cone shape, const std::vector<double>& params)
875  { set_dimensions(shape.ptr(), params); }
876  template <> void set_dimensions(ConeSegment shape, const std::vector<double>& params)
877  { set_dimensions(shape.ptr(), params); }
878  template <> void set_dimensions(Tube shape, const std::vector<double>& params)
879  { set_dimensions(shape.ptr(), params); }
880  template <> void set_dimensions(CutTube shape, const std::vector<double>& params)
881  { set_dimensions(shape.ptr(), params); }
882  template <> void set_dimensions(TwistedTube shape, const std::vector<double>& params)
883  { set_dimensions((TwistedTubeObject*)shape.ptr(), params); }
884  template <> void set_dimensions(EllipticalTube shape, const std::vector<double>& params)
885  { set_dimensions(shape.ptr(), params); }
886  template <> void set_dimensions(Trap shape, const std::vector<double>& params)
887  { set_dimensions(shape.ptr(), params); }
888  template <> void set_dimensions(Trd1 shape, const std::vector<double>& params)
889  { set_dimensions(shape.ptr(), params); }
890  template <> void set_dimensions(Trd2 shape, const std::vector<double>& params)
891  { set_dimensions(shape.ptr(), params); }
892  template <> void set_dimensions(Paraboloid shape, const std::vector<double>& params)
893  { set_dimensions(shape.ptr(), params); }
894  template <> void set_dimensions(Hyperboloid shape, const std::vector<double>& params)
895  { set_dimensions(shape.ptr(), params); }
896  template <> void set_dimensions(Sphere shape, const std::vector<double>& params)
897  { set_dimensions(shape.ptr(), params); }
898  template <> void set_dimensions(Torus shape, const std::vector<double>& params)
899  { set_dimensions(shape.ptr(), params); }
900  template <> void set_dimensions(PolyhedraRegular shape, const std::vector<double>& params)
901  { set_dimensions(shape.ptr(), params); }
902  template <> void set_dimensions(Polyhedra shape, const std::vector<double>& params)
903  { set_dimensions(shape.ptr(), params); }
904  template <> void set_dimensions(ExtrudedPolygon shape, const std::vector<double>& params)
905  { set_dimensions(shape.ptr(), params); }
906  template <> void set_dimensions(EightPointSolid shape, const std::vector<double>& params)
907  { set_dimensions(shape.ptr(), params); }
908  template <> void set_dimensions(TessellatedSolid shape, const std::vector<double>& params)
909  { set_dimensions(shape.ptr(), params); }
910  template <> void set_dimensions(BooleanSolid shape, const std::vector<double>& params)
911  { set_dimensions(shape.ptr(), params); }
912  template <> void set_dimensions(SubtractionSolid shape, const std::vector<double>& params)
913  { set_dimensions(shape.ptr(), params); }
914  template <> void set_dimensions(UnionSolid shape, const std::vector<double>& params)
915  { set_dimensions(shape.ptr(), params); }
916  template <> void set_dimensions(IntersectionSolid shape, const std::vector<double>& params)
917  { set_dimensions(shape.ptr(), params); }
918 
919  template <> void set_dimensions(TruncatedTube shape, const std::vector<double>& params) {
920  TGeoCompositeShape* sh = (TGeoCompositeShape*) shape.ptr();
921  TGeoBoolNode* boolean = sh->GetBoolNode();
922  TGeoMatrix* right_matrix = boolean->GetRightMatrix();
923  TGeoShape* left_solid = boolean->GetLeftShape();
924  TGeoShape* right_solid = boolean->GetRightShape();
925  TGeoTubeSeg* tubs = (TGeoTubeSeg*)left_solid;
926  TGeoBBox* box = (TGeoBBox*)right_solid;
927  double dz = params[0];
928  double rmin = params[1];
929  double rmax = params[2];
930  double startPhi = params[3]/units::deg;
931  double deltaPhi = params[4]/units::deg;
932  double cutAtStart = params[5];
933  double cutAtDelta = params[6];
934  bool cutInside = params[7] > 0.5;
935 #ifdef DIMENSION_DEBUG
936  cout << "setDimensions: [" << TRUNCATEDTUBE_TAG << "]" << endl
937  << right_matrix->GetTitle() << endl;
938 #endif
939  // check the parameters
940  if( rmin <= 0 || rmax <= 0 || cutAtStart <= 0 || cutAtDelta <= 0 )
941  except(TRUNCATEDTUBE_TAG,"++ 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!");
942  else if( rmin >= rmax )
943  except(TRUNCATEDTUBE_TAG,"++ rIn<rOut violated!");
944  else if( startPhi != 0. )
945  except(TRUNCATEDTUBE_TAG,"++ startPhi != 0 not supported!");
946 
947  double r = cutAtStart;
948  double R = cutAtDelta;
949  // angle of the box w.r.t. tubs
950  double cath = r - R * std::cos( deltaPhi*units::deg );
951  double hypo = std::sqrt( r*r + R*R - 2.*r*R * std::cos( deltaPhi*units::deg ));
952  double cos_alpha = cath / hypo;
953  double alpha = std::acos( cos_alpha );
954  double sin_alpha = std::sin( std::fabs(alpha) );
955 
956  // exaggerate dimensions - does not matter, it's subtracted!
957  // If we don't, the **edge** of the box would cut into the tube segment
958  // for larger delta-phi values
959  double boxX = 1.1*rmax + rmax/sin_alpha; // Need to adjust for move!
960  double boxY = rmax;
961  // width of the box > width of the tubs
962  double boxZ = 1.1 * dz;
963  double xBox; // center point of the box
964  if( cutInside )
965  xBox = r - boxY / sin_alpha;
966  else
967  xBox = r + boxY / sin_alpha;
968 
969  // rotationmatrix of box w.r.t. tubs
970  TGeoRotation rot;
971  rot.RotateZ( -alpha/units::deg );
972  double box_dim[] = {boxX, boxY, boxZ};
973  double tub_dim[] = {rmin, rmax, dz, startPhi, deltaPhi};
974  box->SetDimensions(box_dim);
975  tubs->SetDimensions(tub_dim);
976  TGeoCombiTrans* combi = (TGeoCombiTrans*)right_matrix;
977  combi->SetRotation(rot);
978  combi->SetTranslation(xBox, 0, 0);
979  return;
980  }
981  template <> void set_dimensions(PseudoTrap shape, const std::vector<double>& params) {
982  TGeoCompositeShape* sh = (TGeoCompositeShape*) shape.ptr();
983  TGeoBoolNode* boolean = sh->GetBoolNode();
984  TGeoMatrix* right_matrix = boolean->GetRightMatrix();
985  TGeoShape* left_solid = boolean->GetLeftShape();
986  TGeoShape* right_solid = boolean->GetRightShape();
987  double x1 = params[0];
988  double x2 = params[1];
989  double y1 = params[2];
990  double y2 = params[3];
991  double z = params[4];
992  double r = params[5];
993  bool atMinusZ = params[6] > 0.5;
994  double x = atMinusZ ? x1 : x2;
995  double h = 0;
996  bool intersec = false; // union or intersection solid
997  double displacement = 0;
998  double startPhi = 0;
999  double halfZ = z;
1000  double halfOpeningAngle = std::asin( x / std::abs( r ))/units::deg;
1002  double delta = std::sqrt( r * r - x * x );
1003 
1004 #ifdef DIMENSION_DEBUG
1005  cout << "setDimensions: [" << PSEUDOTRAP_TAG << "]" << endl
1006  << right_matrix->GetTitle() << endl;
1007 #endif
1008  // Implementation from :
1009  // https://cmssdt.cern.ch/lxr/source/Fireworks/Geometry/src/TGeoMgrFromDdd.cc#0538
1010  if( r < 0 && std::abs(r) >= x ) {
1011  intersec = true; // intersection solid
1012  h = y1 < y2 ? y2 : y1; // tubs half height
1013  h += h/20.; // enlarge a bit - for subtraction solid
1014  if( atMinusZ ) {
1015  displacement = - halfZ - delta;
1016  startPhi = 90.0 - halfOpeningAngle;
1017  }
1018  else {
1019  displacement = halfZ + delta;
1020  startPhi = -90.0 - halfOpeningAngle;
1021  }
1022  }
1023  else if( r > 0 && std::abs(r) >= x ) {
1024  if( atMinusZ ) {
1025  displacement = - halfZ + delta;
1026  startPhi = 270.0 - halfOpeningAngle;
1027  h = y1;
1028  }
1029  else
1030  {
1031  displacement = halfZ - delta;
1032  startPhi = 90.0 - halfOpeningAngle;
1033  h = y2;
1034  }
1035  }
1036  else {
1037  except(PSEUDOTRAP_TAG,"Check parameters of the PseudoTrap!");
1038  }
1039  double trd2_dim[] = { x1, x2, y1, y2, halfZ };
1040  double tube_dim[] = { 0.0, std::abs(r), h, startPhi, startPhi + halfOpeningAngle*2. };
1041  if( intersec && left_solid->IsA() == TGeoTrd2::Class() ) {
1042  left_solid->SetDimensions(trd2_dim);
1043  right_solid->SetDimensions(tube_dim);
1044  }
1045  else if ( right_solid->IsA() == TGeoCompositeShape::Class() ) {
1046  double box_dim[] = { 1.1*x, 1.1*h, std::sqrt(r*r-x*x) };
1047  TGeoCompositeShape* comp = (TGeoCompositeShape*)right_solid;
1048  TGeoBoolNode* b_s = comp->GetBoolNode();
1049  b_s->GetLeftShape()->SetDimensions(tube_dim);
1050  b_s->GetRightShape()->SetDimensions(box_dim);
1051  left_solid->SetDimensions(trd2_dim);
1052  }
1053  else {
1054  except("PseudoTrap","+++ Incompatible change of parameters.");
1055  }
1056  ((TGeoTranslation*)right_matrix)->SetTranslation(0,0,displacement);
1057  std::stringstream str;
1058  str << x1 << " " << x2 << " " << y1 << " " << y2 << " " << z << " "
1059  << r << " " << char(atMinusZ ? '1' : '0') << " ";
1060  right_matrix->SetTitle(str.str().c_str());
1061  }
1062 
1064  template <> void set_dimensions(Solid shape, const std::vector<double>& params) {
1065  if ( shape.ptr() ) {
1066  TClass* cl = shape->IsA();
1067  Solid solid(shape);
1068  if ( cl == TGeoShapeAssembly::Class() )
1069  set_dimensions(ShapelessSolid(shape), params);
1070  else if ( cl == TGeoBBox::Class() )
1071  set_dimensions(Box(shape), params);
1072  else if ( cl == TGeoHalfSpace::Class() )
1073  set_dimensions(HalfSpace(shape), params);
1074  else if ( cl == TGeoPcon::Class() )
1075  set_dimensions(Polycone(shape), params);
1076  else if ( cl == TGeoConeSeg::Class() )
1077  set_dimensions(ConeSegment(shape), params);
1078  else if ( cl == TGeoCone::Class() )
1079  set_dimensions(Cone(shape), params);
1080  else if ( cl == TGeoTube::Class() )
1081  set_dimensions(Tube(shape), params);
1082  else if ( cl == TGeoTubeSeg::Class() )
1083  set_dimensions(Tube(shape), params);
1084  else if ( cl == TGeoCtub::Class() )
1085  set_dimensions(CutTube(shape), params);
1086  else if ( cl == TGeoEltu::Class() )
1087  set_dimensions(EllipticalTube(shape), params);
1088  else if ( cl == TwistedTubeObject::Class() )
1089  set_dimensions(TwistedTube(shape), params);
1090  else if ( cl == TGeoTrd1::Class() )
1091  set_dimensions(Trd1(shape), params);
1092  else if ( cl == TGeoTrd2::Class() )
1093  set_dimensions(Trd2(shape), params);
1094  else if ( cl == TGeoParaboloid::Class() )
1095  set_dimensions(Paraboloid(shape), params);
1096  else if ( cl == TGeoHype::Class() )
1097  set_dimensions(Hyperboloid(shape), params);
1098  else if ( cl == TGeoSphere::Class() )
1099  set_dimensions(Sphere(shape), params);
1100  else if ( cl == TGeoTorus::Class() )
1101  set_dimensions(Torus(shape), params);
1102  else if ( cl == TGeoTrap::Class() )
1103  set_dimensions(Trap(shape), params);
1104  else if ( cl == TGeoPgon::Class() )
1105  set_dimensions(PolyhedraRegular(shape), params);
1106  else if ( cl == TGeoXtru::Class() )
1107  set_dimensions(ExtrudedPolygon(shape), params);
1108  else if ( cl == TGeoArb8::Class() )
1109  set_dimensions(EightPointSolid(shape), params);
1110  else if ( cl == TGeoTessellated::Class() )
1111  set_dimensions(TessellatedSolid(shape), params);
1112  else if ( cl == TGeoScaledShape::Class() ) {
1113  TGeoScaledShape* sh = (TGeoScaledShape*) shape.ptr();
1114  set_dimensions(sh, params);
1115  }
1116  else if ( isA<TruncatedTube>(shape) )
1117  set_dimensions(TruncatedTube(shape), params);
1118  else if ( isA<PseudoTrap>(shape) )
1119  set_dimensions(PseudoTrap(shape), params);
1120  else if ( isA<SubtractionSolid>(solid) )
1121  set_dimensions(SubtractionSolid(shape), params);
1122  else if ( isA<UnionSolid>(solid) )
1123  set_dimensions(UnionSolid(shape), params);
1124  else if ( isA<IntersectionSolid>(solid) )
1125  set_dimensions(IntersectionSolid(shape), params);
1126  else if ( isA<BooleanSolid>(solid) )
1127  set_dimensions(BooleanSolid(shape), params);
1128  else
1129  printout(ERROR,"Solid","Failed to set dimensions for shape of type:%s.",cl->GetName() );
1130  return;
1131  }
1132  except("Solid","set_shape_dimensions: Failed to set dimensions [Invalid handle].");
1133  }
1135  template <> void set_dimensions(const TGeoShape* shape, const std::vector<double>& params) {
1136  set_dimensions<Solid>(Solid(shape), params);
1137  }
1139  void set_shape_dimensions(TGeoShape* shape, const std::vector<double>& params) {
1140  set_dimensions<Solid>(Solid(shape), params);
1141  }
1143  void set_shape_dimensions(Solid solid, const std::vector<double>& params) {
1144  set_dimensions<Solid>(solid, params);
1145  }
1146 
1148  std::string toStringSolid(const TGeoShape* shape, int precision) {
1149  if ( !shape ) {
1150  return "[Invalid shape]";
1151  }
1152 
1153  std::stringstream log;
1154  TClass* cl = shape->IsA();
1155  int prec = log.precision();
1156  log.setf(std::ios::fixed,std::ios::floatfield);
1157  log << std::setprecision(precision);
1158  log << cl->GetName();
1159  if ( cl == TGeoBBox::Class() ) {
1160  TGeoBBox* sh = (TGeoBBox*) shape;
1161  log << " x:" << sh->GetDX()
1162  << " y:" << sh->GetDY()
1163  << " z:" << sh->GetDZ();
1164  }
1165  else if ( cl == TGeoHalfSpace::Class() ) {
1166  TGeoHalfSpace* sh = (TGeoHalfSpace*)(const_cast<TGeoShape*>(shape));
1167  log << " Point: (" << sh->GetPoint()[0] << ", " << sh->GetPoint()[1] << ", " << sh->GetPoint()[2] << ") "
1168  << " Normal: (" << sh->GetNorm()[0] << ", " << sh->GetNorm()[1] << ", " << sh->GetNorm()[2] << ") ";
1169  }
1170  else if ( cl == TGeoTube::Class() ) {
1171  const TGeoTube* sh = (const TGeoTube*) shape;
1172  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax() << " dz:" << sh->GetDz();
1173  }
1174  else if ( cl == TGeoTubeSeg::Class() ) {
1175  const TGeoTubeSeg* sh = (const TGeoTubeSeg*) shape;
1176  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax() << " dz:" << sh->GetDz()
1177  << " Phi1:" << sh->GetPhi1() << " Phi2:" << sh->GetPhi2();
1178  }
1179  else if ( cl == TGeoCtub::Class() ) {
1180  const TGeoCtub* sh = (const TGeoCtub*) shape;
1181  const Double_t* hi = sh->GetNhigh();
1182  const Double_t* lo = sh->GetNlow();
1183  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax() << " dz:" << sh->GetDz()
1184  << " Phi1:" << sh->GetPhi1() << " Phi2:" << sh->GetPhi2()
1185  << " lx:" << lo[0] << " ly:" << lo[1] << " lz:" << lo[2]
1186  << " hx:" << hi[0] << " hy:" << hi[1] << " hz:" << hi[2];
1187  }
1188  else if ( cl == TGeoEltu::Class() ) {
1189  const TGeoEltu* sh = (const TGeoEltu*) shape;
1190  log << " A:" << sh->GetA() << " B:" << sh->GetB() << " dz:" << sh->GetDz();
1191  }
1192  else if ( cl == TGeoTrd1::Class() ) {
1193  const TGeoTrd1* sh = (const TGeoTrd1*) shape;
1194  log << " x1:" << sh->GetDx1() << " x2:" << sh->GetDx2() << " y:" << sh->GetDy() << " z:" << sh->GetDz();
1195  }
1196  else if ( cl == TGeoTrd2::Class() ) {
1197  const TGeoTrd2* sh = (const TGeoTrd2*) shape;
1198  log << " x1:" << sh->GetDx1() << " x2:" << sh->GetDx2()
1199  << " y1:" << sh->GetDy1() << " y2:" << sh->GetDy2() << " z:" << sh->GetDz();
1200  }
1201  else if ( cl == TGeoTrap::Class() ) {
1202  const TGeoTrap* sh = (const TGeoTrap*) shape;
1203  log << " dz:" << sh->GetDz() << " Theta:" << sh->GetTheta() << " Phi:" << sh->GetPhi()
1204  << " H1:" << sh->GetH1() << " Bl1:" << sh->GetBl1() << " Tl1:" << sh->GetTl1() << " Alpha1:" << sh->GetAlpha1()
1205  << " H2:" << sh->GetH2() << " Bl2:" << sh->GetBl2() << " Tl2:" << sh->GetTl2() << " Alpha2:" << sh->GetAlpha2();
1206  }
1207  else if ( cl == TGeoHype::Class() ) {
1208  const TGeoHype* sh = (const TGeoHype*) shape;
1209  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax() << " dz:" << sh->GetDz()
1210  << " StIn:" << sh->GetStIn() << " StOut:" << sh->GetStOut();
1211  }
1212  else if ( cl == TGeoPgon::Class() ) {
1213  const TGeoPgon* sh = (const TGeoPgon*) shape;
1214  log << " Phi1:" << sh->GetPhi1() << " dPhi:" << sh->GetDphi()
1215  << " NEdges:" << sh->GetNedges() << " Nz:" << sh->GetNz();
1216  for(int i=0, n=sh->GetNz(); i<n; ++i) {
1217  log << " i=" << i << " z:" << sh->GetZ(i)
1218  << " r:[" << sh->GetRmin(i) << "," << sh->GetRmax(i) << "]";
1219  }
1220  }
1221  else if ( cl == TGeoPcon::Class() ) {
1222  const TGeoPcon* sh = (const TGeoPcon*) shape;
1223  log << " Phi1:" << sh->GetPhi1() << " dPhi:" << sh->GetDphi() << " Nz:" << sh->GetNz();
1224  for(int i=0, n=sh->GetNz(); i<n; ++i) {
1225  log << " i=" << i << " z:" << sh->GetZ(i)
1226  << " r:[" << sh->GetRmin(i) << "," << sh->GetRmax(i) << "]";
1227  }
1228  }
1229  else if ( cl == TGeoCone::Class() ) {
1230  const TGeoCone* sh = (const TGeoCone*) shape;
1231  log << " rmin1:" << sh->GetRmin1() << " rmax1:" << sh->GetRmax1()
1232  << " rmin2:" << sh->GetRmin2() << " rmax2:" << sh->GetRmax2()
1233  << " dz:" << sh->GetDz();
1234  }
1235  else if ( cl == TGeoConeSeg::Class() ) {
1236  const TGeoConeSeg* sh = (const TGeoConeSeg*) shape;
1237  log << " rmin1:" << sh->GetRmin1() << " rmax1:" << sh->GetRmax1()
1238  << " rmin2:" << sh->GetRmin2() << " rmax2:" << sh->GetRmax2()
1239  << " dz:" << sh->GetDz()
1240  << " Phi1:" << sh->GetPhi1() << " Phi2:" << sh->GetPhi2();
1241  }
1242  else if ( cl == TGeoParaboloid::Class() ) {
1243  const TGeoParaboloid* sh = (const TGeoParaboloid*) shape;
1244  log << " dz:" << sh->GetDz() << " RLo:" << sh->GetRlo() << " Rhi:" << sh->GetRhi();
1245  }
1246  else if ( cl == TGeoSphere::Class() ) {
1247  const TGeoSphere* sh = (const TGeoSphere*) shape;
1248  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax()
1249  << " Phi1:" << sh->GetPhi1() << " Phi2:" << sh->GetPhi2()
1250  << " Theta1:" << sh->GetTheta1() << " Theta2:" << sh->GetTheta2();
1251  }
1252  else if ( cl == TGeoTorus::Class() ) {
1253  const TGeoTorus* sh = (const TGeoTorus*) shape;
1254  log << " rmin:" << sh->GetRmin() << " rmax:" << sh->GetRmax() << " r:" << sh->GetR()
1255  << " Phi1:" << sh->GetPhi1() << " dPhi:" << sh->GetDphi();
1256  }
1257  else if ( cl == TGeoArb8::Class() ) {
1258  TGeoArb8* sh = (TGeoArb8*) shape;
1259  const Double_t* v = sh->GetVertices();
1260  log << " dz:" << sh->GetDz();
1261  for(int i=0; i<8; ++i) {
1262  log << " x[" << i << "]:" << *v; ++v;
1263  log << " y[" << i << "]:" << *v; ++v;
1264  }
1265  }
1266  else if ( cl == TGeoXtru::Class() ) {
1267  const TGeoXtru* sh = (const TGeoXtru*) shape;
1268  log << " X: " << sh->GetX(0)
1269  << " Y: " << sh->GetY(0)
1270  << " Z: " << sh->GetZ(0)
1271  << " Xoff:" << sh->GetXOffset(0)
1272  << " Yoff:" << sh->GetYOffset(0)
1273  << " Nvtx:" << sh->GetNvert()
1274  << " Nz: " << sh->GetNz();
1275  }
1276  else if (shape->IsA() == TGeoCompositeShape::Class() ) {
1277  const TGeoCompositeShape* sh = (const TGeoCompositeShape*) shape;
1278  const TGeoBoolNode* boolean = sh->GetBoolNode();
1279  const TGeoShape* left = boolean->GetLeftShape();
1280  const TGeoShape* right = boolean->GetRightShape();
1281  TGeoBoolNode::EGeoBoolType oper = boolean->GetBooleanOperator();
1282  if (oper == TGeoBoolNode::kGeoSubtraction)
1283  log << "Subtraction: ";
1284  else if (oper == TGeoBoolNode::kGeoUnion)
1285  log << "Union: ";
1286  else if (oper == TGeoBoolNode::kGeoIntersection)
1287  log << "Intersection: ";
1288  log << " Left:" << toStringSolid(left) << " Right:" << toStringSolid(right);
1289  }
1290  log << std::setprecision(prec);
1291  return log.str();
1292  }
1293 
1295  std::string toStringMesh(const TGeoShape* shape, int prec) {
1296  Solid sol(shape);
1297  std::stringstream os;
1298 
1299  // Prints shape parameters
1300  Int_t nvert = 0, nsegs = 0, npols = 0;
1301 
1302  sol->GetMeshNumbers(nvert, nsegs, npols);
1303  Double_t* points = new Double_t[3*nvert];
1304  sol->SetPoints(points);
1305 
1306  os << std::setw(16) << std::left << sol->IsA()->GetName()
1307  << " " << nvert << " Mesh-points:" << std::endl;
1308  os << std::setw(16) << std::left << sol->IsA()->GetName() << " " << sol->GetName()
1309  << " N(mesh)=" << sol->GetNmeshVertices()
1310  << " N(vert)=" << nvert << " N(seg)=" << nsegs << " N(pols)=" << npols << std::endl;
1311 
1312  for(Int_t i=0; i<nvert; ++i) {
1313  Double_t* p = points + 3*i;
1314  os << std::setw(16) << std::left << sol->IsA()->GetName() << " " << std::setw(3) << std::left << i
1315  << " Local (" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << p[0]/dd4hep::cm
1316  << ", " << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << p[1]/dd4hep::cm
1317  << ", " << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << p[2]/dd4hep::cm
1318  << ")" << std::endl;
1319  }
1320  Box box = sol;
1321  const Double_t* org = box->GetOrigin();
1322  os << std::setw(16) << std::left << sol->IsA()->GetName()
1323  << " Bounding box: "
1324  << " dx=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << box->GetDX()/dd4hep::cm
1325  << " dy=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << box->GetDY()/dd4hep::cm
1326  << " dz=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << box->GetDZ()/dd4hep::cm
1327  << " Origin: x=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << org[0]/dd4hep::cm
1328  << " y=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << org[1]/dd4hep::cm
1329  << " z=" << std::setw(7) << std::setprecision(prec) << std::fixed << std::right << org[2]/dd4hep::cm
1330  << std::endl;
1331 
1333  delete [] points;
1334  return os.str();
1335  }
1336 }
1337 
dd4hep::isInstance< TwistedTube >
bool isInstance< TwistedTube >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:100
dd4hep::dimensions< TwistedTubeObject >
std::vector< double > dimensions< TwistedTubeObject >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:304
dd4hep::isInstance< Torus >
template bool isInstance< Torus >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< TGeoPgon >
std::vector< double > dimensions< TGeoPgon >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:351
dd4hep::dimensions< TGeoXtru >
std::vector< double > dimensions< TGeoXtru >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:362
dd4hep::isA< ConeSegment >
template bool isA< ConeSegment >(const Handle< TGeoShape > &solid)
dd4hep::isA< TruncatedTube >
bool isA< TruncatedTube >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:157
dd4hep::dimensions< EightPointSolid >
template std::vector< double > dimensions< EightPointSolid >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoPcon >
std::vector< double > dimensions< TGeoPcon >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:276
dd4hep::isA< EightPointSolid >
template bool isA< EightPointSolid >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Solid >
std::vector< double > dimensions< Solid >(const Handle< TGeoShape > &shape)
Definition: ShapeUtilities.cpp:535
dd4hep::dimensions< Hyperboloid >
template std::vector< double > dimensions< Hyperboloid >(const Handle< TGeoShape > &shape)
dd4hep::TruncatedTube
Class describing a truncated tube shape (CMS'ism)
Definition: Shapes.h:779
dd4hep::isInstance< Tube >
bool isInstance< Tube >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:85
dd4hep::dimensions< Cone >
template std::vector< double > dimensions< Cone >(const Handle< TGeoShape > &shape)
dd4hep::isA< Box >
template bool isA< Box >(const Handle< TGeoShape > &solid)
TRD2_TAG
#define TRD2_TAG
Definition: ShapeTags.h:25
dd4hep::isA< EllipticalTube >
template bool isA< EllipticalTube >(const Handle< TGeoShape > &solid)
dd4hep::isA< Hyperboloid >
template bool isA< Hyperboloid >(const Handle< TGeoShape > &solid)
dd4hep::PolyhedraRegular
Class describing a regular polyhedron shape.
Definition: Shapes.h:1493
v
View * v
Definition: MultiView.cpp:28
dd4hep::dimensions< TGeoShapeAssembly >
std::vector< double > dimensions< TGeoShapeAssembly >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:263
dd4hep::PseudoTrap
Class describing a pseudo trap shape (CMS'ism)
Definition: Shapes.h:1060
MatrixHelpers.h
dd4hep::Torus
Class describing a Torus shape.
Definition: Shapes.h:1226
dd4hep::isInstance< TessellatedSolid >
template bool isInstance< TessellatedSolid >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Trd1 >
template std::vector< double > dimensions< Trd1 >(const Handle< TGeoShape > &shape)
dd4hep::HalfSpace
Class describing half-space.
Definition: Shapes.h:351
M_PI
#define M_PI
Definition: Handle.h:33
dd4hep::ShapelessSolid
Class describing a shape-less solid shape.
Definition: Shapes.h:209
dd4hep::dimensions< TGeoEltu >
std::vector< double > dimensions< TGeoEltu >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:318
POLYCONE_TAG
#define POLYCONE_TAG
Definition: ShapeTags.h:19
dd4hep::isInstance< ShapelessSolid >
template bool isInstance< ShapelessSolid >(const Handle< TGeoShape > &solid)
TESSELLATEDSOLID_TAG
#define TESSELLATEDSOLID_TAG
Definition: ShapeTags.h:37
dd4hep::dimensions< Tube >
template std::vector< double > dimensions< Tube >(const Handle< TGeoShape > &shape)
HALFSPACE_TAG
#define HALFSPACE_TAG
Definition: ShapeTags.h:18
dd4hep::dimensions< TGeoGtra >
std::vector< double > dimensions< TGeoGtra >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:391
dd4hep::isInstance< ExtrudedPolygon >
template bool isInstance< ExtrudedPolygon >(const Handle< TGeoShape > &solid)
ShapeTags.h
dd4hep::EllipticalTube
Class describing a twisted tube shape.
Definition: Shapes.h:841
dd4hep::isA< Trd2 >
template bool isA< Trd2 >(const Handle< TGeoShape > &solid)
dd4hep::dimensions
std::vector< double > dimensions(const Handle< TGeoShape > &solid)
Access Shape dimension parameters (As in TGeo, but angles in radians rather than degrees)
Definition: ShapeUtilities.cpp:467
dd4hep::isA< Torus >
template bool isA< Torus >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< TGeoTessellated >
std::vector< double > dimensions< TGeoTessellated >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:408
dd4hep::dimensions< TGeoBBox >
std::vector< double > dimensions< TGeoBBox >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:267
SPHERE_TAG
#define SPHERE_TAG
Definition: ShapeTags.h:30
dd4hep::dimensions< TGeoScaledShape >
std::vector< double > dimensions< TGeoScaledShape >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:398
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::dimensions< EllipticalTube >
template std::vector< double > dimensions< EllipticalTube >(const Handle< TGeoShape > &shape)
dd4hep::Hyperboloid
Class describing a Hyperboloid shape.
Definition: Shapes.h:1434
dd4hep::dimensions< TGeoTorus >
std::vector< double > dimensions< TGeoTorus >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:346
dd4hep::isA< TessellatedSolid >
template bool isA< TessellatedSolid >(const Handle< TGeoShape > &solid)
dd4hep::isA
bool isA(const Handle< TGeoShape > &solid)
Type check of various shapes. Do not allow for polymorphism. Types must match exactly.
Definition: ShapeUtilities.cpp:128
dd4hep::dimensions< CutTube >
template std::vector< double > dimensions< CutTube >(const Handle< TGeoShape > &shape)
dd4hep::isA< Polyhedra >
template bool isA< Polyhedra >(const Handle< TGeoShape > &solid)
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Handle< TGeoShape >
dd4hep::Trap
Class describing a trap shape.
Definition: Shapes.h:974
dd4hep::BooleanSolid
Base class describing boolean (=union,intersection,subtraction) solids.
Definition: Shapes.h:1843
dd4hep::isInstance< BooleanSolid >
template bool isInstance< BooleanSolid >(const Handle< TGeoShape > &solid)
dd4hep::Solid_type
Base class for Solid (shape) objects.
Definition: Shapes.h:135
dd4hep::isInstance< Polyhedra >
template bool isInstance< Polyhedra >(const Handle< TGeoShape > &solid)
SCALE_TAG
#define SCALE_TAG
Definition: ShapeTags.h:33
TRD1_TAG
#define TRD1_TAG
Definition: ShapeTags.h:24
dd4hep::isInstance< EllipticalTube >
template bool isInstance< EllipticalTube >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< SubtractionSolid >
template std::vector< double > dimensions< SubtractionSolid >(const Handle< TGeoShape > &shape)
TUBE_TAG
#define TUBE_TAG
Definition: ShapeTags.h:21
UNION_TAG
#define UNION_TAG
Definition: ShapeTags.h:41
dd4hep::isInstance< CutTube >
template bool isInstance< CutTube >(const Handle< TGeoShape > &solid)
dd4hep::isInstance< Hyperboloid >
template bool isInstance< Hyperboloid >(const Handle< TGeoShape > &solid)
dd4hep::Polyhedra
Class describing a regular polyhedron shape.
Definition: Shapes.h:1582
dd4hep::isInstance< Cone >
bool isInstance< Cone >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:82
dd4hep::isInstance< SubtractionSolid >
bool isInstance< SubtractionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:111
TRAP_TAG
#define TRAP_TAG
Definition: ShapeTags.h:32
dd4hep::IntersectionSolid
Class describing boolean intersection solid.
Definition: Shapes.h:1974
dd4hep::isInstance< TruncatedTube >
bool isInstance< TruncatedTube >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:103
dd4hep::isA< PolyhedraRegular >
template bool isA< PolyhedraRegular >(const Handle< TGeoShape > &solid)
dd4hep::ConeSegment
Class describing a cone segment shape.
Definition: Shapes.h:542
dd4hep::dimensions< IntersectionSolid >
template std::vector< double > dimensions< IntersectionSolid >(const Handle< TGeoShape > &shape)
dd4hep::isInstance< ConeSegment >
template bool isInstance< ConeSegment >(const Handle< TGeoShape > &solid)
dd4hep::Trd2
Class describing a Trd2 shape.
Definition: Shapes.h:1163
dd4hep::toStringSolid
std::string toStringSolid(const TGeoShape *shape, int precision=2)
Pretty print of solid attributes.
Definition: ShapeUtilities.cpp:1148
dd4hep::TwistedTubeObject
Concrete object implementation for the Header handle.
Definition: ShapesInterna.h:29
dd4hep::isInstance< Box >
template bool isInstance< Box >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< TwistedTube >
template std::vector< double > dimensions< TwistedTube >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< BooleanSolid >
template std::vector< double > dimensions< BooleanSolid >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoTrd1 >
std::vector< double > dimensions< TGeoTrd1 >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:322
dd4hep::isA< Tube >
template bool isA< Tube >(const Handle< TGeoShape > &solid)
dd4hep::Scale
Class describing a Scale shape.
Definition: Shapes.h:239
dd4hep::dimensions< ConeSegment >
template std::vector< double > dimensions< ConeSegment >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoHalfSpace >
std::vector< double > dimensions< TGeoHalfSpace >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:271
dd4hep::dimensions< UnionSolid >
template std::vector< double > dimensions< UnionSolid >(const Handle< TGeoShape > &shape)
dd4hep::isA< Polycone >
template bool isA< Polycone >(const Handle< TGeoShape > &solid)
TWISTEDTUBE_TAG
#define TWISTEDTUBE_TAG
Definition: ShapeTags.h:29
ShapesInterna.h
dd4hep::isInstance< Sphere >
template bool isInstance< Sphere >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Box >
template std::vector< double > dimensions< Box >(const Handle< TGeoShape > &shape)
CONE_TAG
#define CONE_TAG
Definition: ShapeTags.h:20
dd4hep::Solid_type::_setDimensions
void _setDimensions(double *param) const
Definition: Shapes.cpp:39
dd4hep::dimensions< TGeoArb8 >
std::vector< double > dimensions< TGeoArb8 >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:375
PARABOLOID_TAG
#define PARABOLOID_TAG
Definition: ShapeTags.h:26
dd4hep::isA< HalfSpace >
template bool isA< HalfSpace >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< HalfSpace >
template std::vector< double > dimensions< HalfSpace >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoTrap >
std::vector< double > dimensions< TGeoTrap >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:385
TRUNCATEDTUBE_TAG
#define TRUNCATEDTUBE_TAG
Definition: ShapeTags.h:39
SHAPELESS_TAG
#define SHAPELESS_TAG
Definition: ShapeTags.h:16
dd4hep::set_shape_dimensions
void set_shape_dimensions(TGeoShape *shape, const std::vector< double > &params)
Set the shape dimensions (As for the TGeo shape, but angles in rad rather than degrees)
Definition: ShapeUtilities.cpp:1139
dd4hep::isInstance< IntersectionSolid >
bool isInstance< IntersectionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:121
dd4hep::isA< Trd1 >
template bool isA< Trd1 >(const Handle< TGeoShape > &solid)
dd4hep::Cone
Class describing a cone shape.
Definition: Shapes.h:402
dd4hep::isA< Cone >
template bool isA< Cone >(const Handle< TGeoShape > &solid)
dd4hep::isInstance< Polycone >
bool isInstance< Polycone >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:90
SUBTRACTION_TAG
#define SUBTRACTION_TAG
Definition: ShapeTags.h:42
Shapes.h
dd4hep::get_shape_dimensions
std::vector< double > get_shape_dimensions(TGeoShape *shape)
Access Shape dimension parameters (As in TGeo, but angles in radians rather than degrees)
Definition: ShapeUtilities.cpp:607
dd4hep::isInstance< EightPointSolid >
bool isInstance< EightPointSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:93
dd4hep::ExtrudedPolygon
Class describing a extruded polygon shape.
Definition: Shapes.h:1658
dd4hep::set_dimensions
void set_dimensions(SOLID solid, const std::vector< double > &params)
Set the shape dimensions. As for the TGeo shape, but angles in rad rather than degrees.
dd4hep::Trd1
Class describing a Trd1 shape.
Definition: Shapes.h:1103
dd4hep::dimensions< TGeoParaboloid >
std::vector< double > dimensions< TGeoParaboloid >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:330
CUTTUBE_TAG
#define CUTTUBE_TAG
Definition: ShapeTags.h:22
dd4hep::isInstance< Trd2 >
template bool isInstance< Trd2 >(const Handle< TGeoShape > &solid)
EIGHTPOINTSOLID_TAG
#define EIGHTPOINTSOLID_TAG
Definition: ShapeTags.h:36
dd4hep::isInstance< UnionSolid >
bool isInstance< UnionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:116
dd4hep::isInstance< Paraboloid >
template bool isInstance< Paraboloid >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< TGeoConeSeg >
std::vector< double > dimensions< TGeoConeSeg >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:287
PSEUDOTRAP_TAG
#define PSEUDOTRAP_TAG
Definition: ShapeTags.h:40
dd4hep::dimensions< Trd2 >
template std::vector< double > dimensions< Trd2 >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoCompositeShape >
std::vector< double > dimensions< TGeoCompositeShape >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:439
dd4hep::dimensions< ShapelessSolid >
template std::vector< double > dimensions< ShapelessSolid >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoTrd2 >
std::vector< double > dimensions< TGeoTrd2 >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:326
dd4hep::UnionSolid
Class describing boolean union solid.
Definition: Shapes.h:1926
EXTRUDEDPOLYGON_TAG
#define EXTRUDEDPOLYGON_TAG
Definition: ShapeTags.h:35
dd4hep::CutTube
Class describing a tube shape of a section of a cut tube segment.
Definition: Shapes.h:716
dd4hep::TwistedTubeObject::fPositiveEndz
double fPositiveEndz
Definition: ShapesInterna.h:42
dd4hep::dimensions< TGeoHype >
std::vector< double > dimensions< TGeoHype >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:334
dd4hep::dimensions< TGeoSphere >
std::vector< double > dimensions< TGeoSphere >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:340
dd4hep::TwistedTube
Class describing a twisted tube shape.
Definition: Shapes.h:900
dd4hep::EightPointSolid
Class describing an arbitray solid defined by 8 vertices.
Definition: Shapes.h:1720
dd4hep::isInstance< HalfSpace >
template bool isInstance< HalfSpace >(const Handle< TGeoShape > &solid)
dd4hep::Polycone
Class describing a Polycone shape.
Definition: Shapes.h:471
dd4hep::dimensions< PolyhedraRegular >
template std::vector< double > dimensions< PolyhedraRegular >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< Torus >
template std::vector< double > dimensions< Torus >(const Handle< TGeoShape > &shape)
dd4hep::TwistedTubeObject::fNsegments
int fNsegments
Definition: ShapesInterna.h:43
CONESEGMENT_TAG
#define CONESEGMENT_TAG
Definition: ShapeTags.h:23
dd4hep::isInstance< Trd1 >
template bool isInstance< Trd1 >(const Handle< TGeoShape > &solid)
dd4hep::Box
Class describing a box shape.
Definition: Shapes.h:294
dd4hep::isA< IntersectionSolid >
bool isA< IntersectionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:177
dd4hep::Handle::access
T * access() const
Checked object access. Throws invalid handle runtime exception if invalid handle.
dd4hep::isA< Scale >
template bool isA< Scale >(const Handle< TGeoShape > &solid)
dd4hep::isA< SubtractionSolid >
bool isA< SubtractionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:165
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::dimensions< Sphere >
template std::vector< double > dimensions< Sphere >(const Handle< TGeoShape > &shape)
dd4hep::isA< CutTube >
template bool isA< CutTube >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Paraboloid >
template std::vector< double > dimensions< Paraboloid >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoTube >
std::vector< double > dimensions< TGeoTube >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:296
TORUS_TAG
#define TORUS_TAG
Definition: ShapeTags.h:31
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Sphere
Class describing a sphere shape.
Definition: Shapes.h:1288
dd4hep::isA< Trap >
template bool isA< Trap >(const Handle< TGeoShape > &solid)
dd4hep::Solid
Solid_type< TGeoShape > Solid
Definition: Shapes.h:197
dd4hep::TessellatedSolid
Class describing a tessellated shape.
Definition: Shapes.h:1772
dd4hep::dimensions< Scale >
template std::vector< double > dimensions< Scale >(const Handle< TGeoShape > &shape)
dd4hep::dimensions< TGeoCone >
std::vector< double > dimensions< TGeoCone >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:292
dd4hep::isA< PseudoTrap >
bool isA< PseudoTrap >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:161
BOX_TAG
#define BOX_TAG
Definition: ShapeTags.h:17
dd4hep::isA< TwistedTube >
bool isA< TwistedTube >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:153
dd4hep::dimensions< TessellatedSolid >
template std::vector< double > dimensions< TessellatedSolid >(const Handle< TGeoShape > &shape)
dd4hep::isA< ExtrudedPolygon >
template bool isA< ExtrudedPolygon >(const Handle< TGeoShape > &solid)
TGeoConeSeg
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:17
dd4hep::isInstance
bool isInstance(const Handle< TGeoShape > &solid)
Type check of various shapes. Result like dynamic_cast. Compare with python's isinstance(obj,...
Definition: ShapeUtilities.cpp:59
dd4hep::isInstance< Scale >
template bool isInstance< Scale >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Trap >
template std::vector< double > dimensions< Trap >(const Handle< TGeoShape > &shape)
INTERSECTION_TAG
#define INTERSECTION_TAG
Definition: ShapeTags.h:43
HYPERBOLOID_TAG
#define HYPERBOLOID_TAG
Definition: ShapeTags.h:27
dd4hep::dimensions< TruncatedTube >
std::vector< double > dimensions< TruncatedTube >(const Handle< TGeoShape > &shape)
Definition: ShapeUtilities.cpp:518
dd4hep::dimensions< ExtrudedPolygon >
template std::vector< double > dimensions< ExtrudedPolygon >(const Handle< TGeoShape > &shape)
dd4hep::isA< Sphere >
template bool isA< Sphere >(const Handle< TGeoShape > &solid)
dd4hep::TwistedTubeObject::fNegativeEndz
double fNegativeEndz
Definition: ShapesInterna.h:41
dd4hep::dimensions< PseudoTrap >
std::vector< double > dimensions< PseudoTrap >(const Handle< TGeoShape > &shape)
Definition: ShapeUtilities.cpp:497
dd4hep::dimensions< TGeoCtub >
std::vector< double > dimensions< TGeoCtub >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:310
DD4hepUnits.h
dd4hep::Tube
Class describing a tube shape of a section of a tube.
Definition: Shapes.h:628
dd4hep::isA< UnionSolid >
bool isA< UnionSolid >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:171
dd4hep::Solid_type::dimensions
std::vector< double > dimensions()
Access the dimensions of the shape: inverse of the setDimensions member function.
Definition: Shapes.cpp:90
dd4hep::isInstance< PolyhedraRegular >
template bool isInstance< PolyhedraRegular >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< TGeoTubeSeg >
std::vector< double > dimensions< TGeoTubeSeg >(const TGeoShape *shape)
Definition: ShapeUtilities.cpp:300
dd4hep::get_shape_tag
std::string get_shape_tag(const TGeoShape *shape)
Retrieve tag name from shape type.
Definition: ShapeUtilities.cpp:185
Printout.h
POLYHEDRA_TAG
#define POLYHEDRA_TAG
Definition: ShapeTags.h:34
dd4hep::dimensions< Polyhedra >
template std::vector< double > dimensions< Polyhedra >(const Handle< TGeoShape > &shape)
dd4hep::TwistedTubeObject::fPhiTwist
double fPhiTwist
Definition: ShapesInterna.h:40
dd4hep::toStringMesh
std::string toStringMesh(const TGeoShape *shape, int precision=2)
Output mesh vertices to string.
Definition: ShapeUtilities.cpp:1295
dd4hep::SubtractionSolid
Class describing boolean subtraction solid.
Definition: Shapes.h:1878
dd4hep::isInstance< PseudoTrap >
bool isInstance< PseudoTrap >(const Handle< TGeoShape > &solid)
Definition: ShapeUtilities.cpp:107
dd4hep::isA< ShapelessSolid >
template bool isA< ShapelessSolid >(const Handle< TGeoShape > &solid)
dd4hep::Paraboloid
Class describing a Paraboloid shape.
Definition: Shapes.h:1378
ELLIPTICALTUBE_TAG
#define ELLIPTICALTUBE_TAG
Definition: ShapeTags.h:28
dd4hep::isInstance< Trap >
template bool isInstance< Trap >(const Handle< TGeoShape > &solid)
dd4hep::dimensions< Polycone >
template std::vector< double > dimensions< Polycone >(const Handle< TGeoShape > &shape)
dd4hep::isA< Paraboloid >
template bool isA< Paraboloid >(const Handle< TGeoShape > &solid)