G4Trap origin position

I’m wondering what is the origin of a G4Trap ?
I created two solids
G4Trap* housing_up =
new G4Trap(“housing_up”,fHousingSize.z(),dY,fHousingSize.x(),1.0*mm);


G4Box* housing_bottom =
new G4Box(“housing_bottom”,fHousingSize.x()/2.0,fHousingSize.y()/2.0,fHousingSize.z()/2.0);
and made an union without relative displacement along X :

G4ThreeVector trans(0.0,fHousingSize.y()/2.0+dY/2.0-kCarTolerance,0.0);
G4UnionSolid* housing_solid =
new G4UnionSolid(“PMTHousing”,housing_bottom,housing_up,0,trans);

However the G4Trap is not aligned with the G4Box along X…

Thanks for the help,


If you’re working with Geant4 11-beta, you should be able to see the local coordinate systems with /vis/scene/add/localAxes.


I am using 10.7.0. Regardless the visualisation, is there a way to figure it out ?

To align G4Trap and G4Box, the half dimension of G4Box in X should be set to:

(fHousingSize.x() + 1*mm)/4

Sorry, I’ve misunderstood the issue. The problem is not in the dimensions of the box. To align the solids a displacement in X should be added to the translation vector:

(1*mm - fHousingSize.x())/4

It worked, many thanks ! Could you point me to some place where I could find an explanation ? I thought that by default they would be aligned…
Thanks again.

I do not know where a detailed explanation of this kind of G4Trap (Right Angular Wedge) can be found. The construction of Right Angular Wedge can be understood from its source:

// Constructor for Right Angular Wedge from STEP

G4Trap::G4Trap( const G4String& pName,
                      G4double pZ,
                      G4double pY,
                      G4double pX, G4double pLTX )
  : G4CSGSolid(pName), halfCarTolerance(0.5*kCarTolerance)
  fDz  = 0.5*pZ; fTthetaCphi = 0; fTthetaSphi = 0;
  fDy1 = 0.5*pY; fDx1 = 0.5*pX; fDx2 = 0.5*pLTX; fTalpha1 = 0.5*(pLTX - pX)/pY;
  fDy2 = fDy1;   fDx3 = fDx1;   fDx4 = fDx2;     fTalpha2 = fTalpha1;

There is angle alpha between Y axis and the line joining the centres of pX and pLTX, so the displacement of pX along X is equal to 0.5*pY*tan(alpha).

To have better control of the posion of the solid I would recommend instead of Right Angular Wedge to use G4Trap constructor with eight points:

G4Trap( const G4String& pName, const G4ThreeVector pt[8] )

Another option is to use G4ExtrudedSolid with 2 z-sections:

G4ExtrudedSolid( const G4String&                 pName,
                 const std::vector<G4TwoVector>& polygon,
                 G4double                  halfZ,
                 const G4TwoVector& off1, G4double scale1,
                 const G4TwoVector& off2, G4double scale2 );

BTW, in this particular case a Boolean union can be avoided, the final solid can be defined as G4Trap or G4ExtrudedSolid.

Perfect ! Thanks for the explanation and suggestion. I will follow it.

Hi again,
I am implementing the generic G4ExtrudedSolid and find one of the arguments is a vector of ZSection objects. Looking at the code I find a ZSection is defined by the z position, offset and scale. The first parameter seems obvious, but I could not find a description of the meaning of the last two… Could you point me to some part of the documentation ?
Many thanks,

G4ExtrudedSolid is a solid constructed by moving a 2D polygonal contour along a 3D polyline. The coordinates of a node in the polyline are defined by first two parameters in corresponding ZSection, z-position and offset (x,y). During movement the polygonal contour can be scaled. The scale factor is defined by third parameter of ZSection.

In most of cases G4ExtrudedSolid is used for solids that have only two z-sections. For this reason G4ExtrudedSolid has second, simplified constructor without vector of ZSection objects. I suggested to you this one.

In your case off1, off2 should be specified as G4TwoVector(0,0), and scale1, scale2 should be equal to 1.

Great, got it ! Thanks again.