23 #include <TGeoMatrix.h>
24 #include <TGeoBoolNode.h>
25 #include <TGeoScaledShape.h>
36 #include <G4Sphere.hh>
37 #include <G4CutTubs.hh>
38 #include <G4Polycone.hh>
39 #include <G4Polyhedra.hh>
40 #include <G4Ellipsoid.hh>
41 #include <G4Paraboloid.hh>
42 #include <G4TwistedTubs.hh>
43 #include <G4GenericTrap.hh>
44 #include <G4ExtrudedSolid.hh>
45 #include <G4EllipticalTube.hh>
46 #include <G4TessellatedSolid.hh>
47 #include <G4TriangularFacet.hh>
48 #include <G4QuadrangularFacet.hh>
60 static const double CM_2_MM = (CLHEP::centimeter/dd4hep::centimeter);
63 template <
typename T> G4VSolid*
convertShape(
const TGeoShape* shape) {
65 except(
"convertShape",
"Unsupported shape: %s",shape->IsA()->GetName());
67 except(
"convertShape",
"Invalid shape conversion requested.");
76 const TGeoBBox* sh = (
const TGeoBBox*) shape;
81 const TGeoTube* sh = (
const TGeoTube*) shape;
86 const TGeoTubeSeg* sh = (
const TGeoTubeSeg*) shape;
87 return new G4Tubs(sh->GetName(), sh->GetRmin() *
CM_2_MM, sh->GetRmax() *
CM_2_MM, sh->GetDz() *
CM_2_MM,
92 const TGeoCtub* sh = (
const TGeoCtub*) shape;
93 const Double_t* ln = sh->GetNlow();
94 const Double_t* hn = sh->GetNhigh();
95 G4ThreeVector lowNorm (ln[0], ln[1], ln[2]);
96 G4ThreeVector highNorm(hn[0], hn[1], hn[2]);
97 return new G4CutTubs(sh->GetName(),
100 std::move(lowNorm), std::move(highNorm));
104 const TGeoEltu* sh = (
const TGeoEltu*) shape;
105 return new G4EllipticalTube(sh->GetName(),sh->GetA() *
CM_2_MM, sh->GetB() *
CM_2_MM, sh->GetDz() *
CM_2_MM);
125 const TGeoTrd1* sh = (
const TGeoTrd1*) shape;
126 return new G4Trd(sh->GetName(),
133 const TGeoTrd2* sh = (
const TGeoTrd2*) shape;
134 return new G4Trd(sh->GetName(),
141 const TGeoHype* sh = (
const TGeoHype*) shape;
142 return new G4Hype(sh->GetName(), sh->GetRmin() *
CM_2_MM, sh->GetRmax() *
CM_2_MM,
148 std::vector<G4TwoVector> vertices;
149 TGeoArb8* sh = (TGeoArb8*) shape;
150 Double_t* vtx_xy = sh->GetVertices();
151 for ( std::size_t i=0; i<8; ++i, vtx_xy +=2 )
153 return new G4GenericTrap(sh->GetName(), sh->GetDz() *
CM_2_MM, vertices);
157 const auto* sh =
static_cast<const TGeoPara*
>(shape);
158 return new G4Para(sh->GetName(),
165 const TGeoXtru* sh = (
const TGeoXtru*) shape;
166 std::size_t nz = sh->GetNz();
167 std::vector<G4ExtrudedSolid::ZSection> z;
169 for(std::size_t i=0; i<nz; ++i) {
170 z.emplace_back(G4ExtrudedSolid::ZSection(sh->GetZ(i) *
CM_2_MM, {sh->GetXOffset(i), sh->GetYOffset(i)}, sh->GetScale(i)));
172 std::size_t np = sh->GetNvert();
173 std::vector<G4TwoVector> polygon;
175 for(std::size_t i=0; i<np; ++i) {
176 polygon.emplace_back(sh->GetX(i) *
CM_2_MM,sh->GetY(i) *
CM_2_MM);
178 return new G4ExtrudedSolid(sh->GetName(), polygon, z);
182 const TGeoPgon* sh = (
const TGeoPgon*) shape;
183 std::vector<double> rmin, rmax, z;
184 for (Int_t i = 0; i < sh->GetNz(); ++i) {
185 rmin.emplace_back(sh->GetRmin(i) *
CM_2_MM);
186 rmax.emplace_back(sh->GetRmax(i) *
CM_2_MM);
187 z.emplace_back(sh->GetZ(i) *
CM_2_MM);
190 sh->GetNedges(), sh->GetNz(), &z[0], &rmin[0], &rmax[0]);
194 const TGeoPcon* sh = (
const TGeoPcon*) shape;
195 std::vector<double> rmin, rmax, z;
196 for (Int_t i = 0; i < sh->GetNz(); ++i) {
197 rmin.emplace_back(sh->GetRmin(i) *
CM_2_MM);
198 rmax.emplace_back(sh->GetRmax(i) *
CM_2_MM);
199 z.emplace_back(sh->GetZ(i) *
CM_2_MM);
202 sh->GetNz(), &z[0], &rmin[0], &rmax[0]);
206 const TGeoCone* sh = (
const TGeoCone*) shape;
207 return new G4Cons(sh->GetName(), sh->GetRmin1() *
CM_2_MM, sh->GetRmax1() *
CM_2_MM, sh->GetRmin2() *
CM_2_MM,
213 return new G4Cons(sh->GetName(), sh->GetRmin1() *
CM_2_MM, sh->GetRmax1() *
CM_2_MM,
220 const TGeoParaboloid* sh = (
const TGeoParaboloid*) shape;
221 return new G4Paraboloid(sh->GetName(), sh->GetDz() *
CM_2_MM, sh->GetRlo() *
CM_2_MM, sh->GetRhi() *
CM_2_MM);
225 const TGeoSphere* sh = (
const TGeoSphere*) shape;
226 return new G4Sphere(sh->GetName(), sh->GetRmin() *
CM_2_MM, sh->GetRmax() *
CM_2_MM,
232 const TGeoTorus* sh = (
const TGeoTorus*) shape;
233 return new G4Torus(sh->GetName(), sh->GetRmin() *
CM_2_MM, sh->GetRmax() *
CM_2_MM, sh->GetR() *
CM_2_MM,
238 const TGeoTrap* sh = (
const TGeoTrap*) shape;
245 std::vector<G4TwoVector> vertices;
246 TGeoTrap* sh = (TGeoTrap*) shape;
247 Double_t* vtx_xy = sh->GetVertices();
248 for ( std::size_t i=0; i<8; ++i, vtx_xy +=2 )
250 return new G4GenericTrap(sh->GetName(), sh->GetDz() *
CM_2_MM, vertices);
254 TGeoTessellated* sh = (TGeoTessellated*) shape;
255 G4TessellatedSolid* g4 =
new G4TessellatedSolid(sh->GetName());
256 int num_facet = sh->GetNfacets();
258 printout(DEBUG,
"TessellatedSolid",
"+++ %s> Converting %d facets", sh->GetName(), num_facet);
259 for(
int i=0; i<num_facet; ++i) {
260 const TGeoFacet& facet = sh->GetFacet(i);
261 int nv = facet.GetNvert();
262 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1)
263 const auto& v0 = sh->GetVertex(facet[0]);
264 const auto& v1 = sh->GetVertex(facet[1]);
265 const auto& v2 = sh->GetVertex(facet[2]);
267 const auto& v0 = sh->GetVertex(facet.GetVertexIndex(0));
268 const auto& v1 = sh->GetVertex(facet.GetVertexIndex(1));
269 const auto& v2 = sh->GetVertex(facet.GetVertexIndex(2));
278 else if ( nv == 4 ) {
279 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1)
280 const auto& v3 = sh->GetVertex(facet[3]);
282 const auto& v3 = sh->GetVertex(facet.GetVertexIndex(3));
291 except(
"TGeoTessellated",
"Tessellated shape [%s] has facet with wrong number of vertices: %d",
296 g4->SetSolidClosed(sh->IsClosedBody());