226 const G4String geometryType = theSolid->GetEntityType();
227 TGeoShape* theShape = NULL;
228 if (geometryType ==
"G4Box") {
230 const G4Box* box =
dynamic_cast<const G4Box*
>(theSolid);
231 theShape =
new TGeoBBox(box->GetXHalfLength()/
CLHEP::mm,
235 else if (geometryType ==
"G4Tubs") {
236 const G4Tubs* tube =
dynamic_cast<const G4Tubs*
>(theSolid);
239 double zhalf = tube->GetZHalfLength()/
CLHEP::mm;
240 double rmin = tube->GetInnerRadius()/
CLHEP::mm;
241 double rmax = tube->GetOuterRadius()/
CLHEP::mm;
243 double maxPhiDeg = minPhiDeg + tube->GetDeltaPhiAngle()/
CLHEP::degree;
244 theShape =
new TGeoTubeSeg(rmin, rmax,
246 minPhiDeg, maxPhiDeg);
248 else if (geometryType ==
"G4Sphere") {
249 const G4Sphere* sphere =
dynamic_cast<const G4Sphere*
>(theSolid);
253 double maxPhiDeg = minPhiDeg + sphere->GetDeltaPhiAngle()/
CLHEP::degree;
254 double minThetaDeg = sphere->GetStartThetaAngle()/
CLHEP::degree;
255 double maxThetaDeg = minThetaDeg + sphere->GetDeltaThetaAngle()/
CLHEP::degree;
256 theShape =
new TGeoSphere(sphere->GetInnerRadius()/
CLHEP::mm,
258 minThetaDeg, maxThetaDeg,
259 minPhiDeg, maxPhiDeg);
261 else if (geometryType ==
"G4Polyhedra") {
262 const G4Polyhedra* polyhedra
263 =
dynamic_cast<const G4Polyhedra*
>(theSolid);
264 double phi = polyhedra->GetStartPhi();
265 double dPhi = polyhedra->GetEndPhi() - phi;
267 if (dPhi<0) dPhi += 2*
M_PI;
268 int sides = polyhedra->GetNumSide();
269 int numZ = polyhedra->GetNumRZCorner()/2;
272 double g4Factor = std::cos(0.5*dPhi/sides);
275 for (
int i = 0; i< numZ; ++i) {
276 double rMin = g4Factor*polyhedra->GetCorner(numZ-i-1).r;
277 double rMax = g4Factor*polyhedra->GetCorner(numZ+i).r;
279 pgon->DefineSection(i,
280 polyhedra->GetCorner(numZ-i-1).z/
CLHEP::mm,
286 else if (geometryType ==
"G4Polycone") {
287 const G4Polycone* polycone
288 =
dynamic_cast<const G4Polycone*
>(theSolid);
289 double phi = polycone->GetStartPhi();
290 double dPhi = polycone->GetEndPhi() - phi;
292 if (dPhi<0) dPhi += 2*
M_PI;
293 #ifdef G4GEOM_USE_USOLIDS 294 #warning GEANT HAS BEEN COMPILED WITH BROKEN USOLIDS. 295 int numZ = polycone->GetNumRZCorner()/2;
300 for (
int i = 0; i< numZ; ++i) {
301 pcon->DefineSection(i,
302 polycone->GetCorner(numZ-i-1).z/
CLHEP::mm,
303 polycone->GetCorner(numZ-i-1).r/
CLHEP::mm,
304 polycone->GetCorner(numZ+i).r/
CLHEP::mm);
307 const G4PolyconeHistorical* param = polycone->GetOriginalParameters();
308 int numZ = param->Num_z_planes;
312 for (
int i = 0; i< numZ; ++i) {
313 pcon->DefineSection(i,
321 else if (geometryType ==
"G4Trap") {
323 =
dynamic_cast<const G4Trap*
>(theSolid);
324 double dz = trap->GetZHalfLength()/
CLHEP::mm;
328 double bl1 = trap->GetXHalfLength1()/
CLHEP::mm;
329 double tl1 = trap->GetXHalfLength2()/
CLHEP::mm;
330 double alpha1 = std::atan(trap->GetTanAlpha1())/
CLHEP::degree;
332 double bl2 = trap->GetXHalfLength3()/
CLHEP::mm;
333 double tl2 = trap->GetXHalfLength4()/
CLHEP::mm;
334 double alpha2 = std::atan(trap->GetTanAlpha2())/
CLHEP::degree;
335 theShape =
new TGeoTrap(dz, theta, phi,
336 h1, bl1, tl1, alpha1,
337 h2, bl2, tl2, alpha2);
339 else if (geometryType ==
"G4Trd") {
341 =
dynamic_cast<const G4Trd*
>(theSolid);
342 double dz = trd->GetZHalfLength()/
CLHEP::mm;
343 double dx1 = trd->GetXHalfLength1()/
CLHEP::mm;
344 double dx2 = trd->GetXHalfLength2()/
CLHEP::mm;
345 double dy1 = trd->GetYHalfLength1()/
CLHEP::mm;
346 double dy2 = trd->GetYHalfLength2()/
CLHEP::mm;
347 theShape =
new TGeoTrd2(dx1,dx2,dy1,dy2,dz);
349 else if (geometryType ==
"G4SubtractionSolid") {
350 const G4SubtractionSolid*
sub 351 =
dynamic_cast<const G4SubtractionSolid*
>(theSolid);
352 const G4VSolid* solidA = sub->GetConstituentSolid(0);
353 const G4VSolid* solidB = sub->GetConstituentSolid(1);
355 TGeoMatrix* matrixA = NULL;
357 TGeoMatrix* matrixB = NULL;
359 TGeoSubtraction* subtractNode =
new TGeoSubtraction(shapeA,shapeB,
361 theShape =
new TGeoCompositeShape(
"name",subtractNode);
363 else if (geometryType ==
"G4DisplacedSolid") {
364 const G4DisplacedSolid* disp
365 =
dynamic_cast<const G4DisplacedSolid*
>(theSolid);
366 const G4VSolid* movedSolid = disp->GetConstituentMovedSolid();
367 G4RotationMatrix rotation = disp->GetObjectRotation();
368 G4ThreeVector displacement = disp->GetObjectTranslation();
372 =
new TGeoRotation(
"rot",
373 TMath::RadToDeg()*rotation.thetaX(),
374 TMath::RadToDeg()*rotation.phiX(),
375 TMath::RadToDeg()*rotation.thetaY(),
376 TMath::RadToDeg()*rotation.phiY(),
377 TMath::RadToDeg()*rotation.thetaZ(),
378 TMath::RadToDeg()*rotation.phiZ());
379 *returnMatrix =
new TGeoCombiTrans(displacement.x()/
CLHEP::mm,
385 else if (geometryType ==
"G4UnionSolid") {
386 const G4UnionSolid* sub
387 =
dynamic_cast<const G4UnionSolid*
>(theSolid);
388 const G4VSolid* solidA = sub->GetConstituentSolid(0);
389 const G4VSolid* solidB = sub->GetConstituentSolid(1);
391 TGeoMatrix* matrixA = NULL;
393 TGeoMatrix* matrixB = NULL;
395 TGeoUnion* unionNode =
new TGeoUnion(shapeA, shapeB,
397 theShape =
new TGeoCompositeShape(
"name",unionNode);
399 else if (geometryType ==
"G4IntersectionSolid") {
400 const G4IntersectionSolid* sub
401 =
dynamic_cast<const G4IntersectionSolid*
>(theSolid);
402 const G4VSolid* solidA = sub->GetConstituentSolid(0);
403 const G4VSolid* solidB = sub->GetConstituentSolid(1);
405 TGeoMatrix* matrixA = NULL;
407 TGeoMatrix* matrixB = NULL;
409 TGeoIntersection* intersectionNode =
new TGeoIntersection(shapeA, shapeB,
411 theShape =
new TGeoCompositeShape(
"name",intersectionNode);
414 else if (geometryType ==
"G4ExtrudedSolid"){
418 const G4ExtrudedSolid* extr
419 =
dynamic_cast<const G4ExtrudedSolid*
>(theSolid);
422 const G4int nZ = extr->GetNofZSections();
424 const G4int nV = extr->GetNofVertices();
427 const int maxVertices = 1000;
428 double vertices_x[maxVertices];
429 double vertices_y[maxVertices];
430 if (maxVertices < nV) {
436 TGeoXtru *xtru =
new TGeoXtru(nZ);
439 std::vector<G4TwoVector> polyPoints = extr->GetPolygon();
442 for(
int i = 0 ; i < nV ; i++){
443 vertices_x[i]= polyPoints[i].x();
444 vertices_y[i]= polyPoints[i].y();
448 xtru->DefinePolygon(nV, vertices_x, vertices_y);
450 double z_pos, x_off, y_off, scale;
453 for(
int i = 0 ; i < nZ ; i++){
454 z_pos = extr->GetZSection(i).fZ;
455 x_off = extr->GetZSection(i).fOffset.x() ;
456 y_off = extr->GetZSection(i).fOffset.y();
457 scale = extr->GetZSection(i).fScale;
458 xtru->DefineSection(i, z_pos, x_off, y_off, scale);
464 EDepSimThrow(geometryType+
" --> shape not implemented");
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
void swap(Handle< T > &a, Handle< T > &b)
TGeoShape * CreateShape(const G4VSolid *theSolid, TGeoMatrix **mat=NULL)
static constexpr double mm
static constexpr double degree
std::string sub(const std::string &a, const std::string &b)