Problem 687

Summary: trapezoid corner coordinate constructor allows invalid corners
Product: Geant4 Reporter: richard.thompson
Component: geometry/solidsAssignee: Vladimir.Grichine
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 6.2   
Hardware: PC   
OS: Linux   

Description richard.thompson 2004-11-12 11:45:47 CET
You can call the trapezoid corner constructor
    G4Trap( const G4String& pName, const G4ThreeVector pt[8] ) ;
with invalid corners.  The result is that a solid will be constructed that does
not have the corners specified.

This bug can manifest itself in trapezoid solids being constructed with
incorrect geometry.

Implicit in the constructor is that:
1)  The parallel faces must be z-planes.
2)  The center of the trapezoid must be the origin.  The center of the trapezoid
is defined as the midpoint of the ray that joins the centers of the two paralell
faces.

In the corner constructor, 2) is not fully checked.  It is verfied that the
trapozoid is centered in z and y, but not x.

To observe the error, call the trapzoid in the following manner:


//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
   Corners[0].setX(-3);
    Corners[0].setY(-3);
    Corners[0].setZ(-3);

    Corners[1].setX( 3);
    Corners[1].setY(-3);
    Corners[1].setZ(-3);

    Corners[2].setX(-3);
    Corners[2].setY( 3);
    Corners[2].setZ(-3);

    Corners[3].setX( 3);
    Corners[3].setY( 3);
    Corners[3].setZ(-3);

    Corners[4].setX(-3);
    Corners[4].setY(-3);
    Corners[4].setZ( 3);

    Corners[5].setX( 1);
    Corners[5].setY(-3);
    Corners[5].setZ( 3);

    Corners[6].setX(-3);
    Corners[6].setY( 3);
    Corners[6].setZ( 3);

    Corners[7].setX( 3);
    Corners[7].setX( 1);
    Corners[7].setZ( 3);

    G4Trap tempTrap("temp trap", Corners);

//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


The result should be a "trapezoid" with the top of the positive x face tilted in
at the top by 2 units.  But that's not what you'll get.  You'll get something
tilted in at the top of both the positive and negative x faces by 1 unit.

So the constructed trapezoid will not have the corners that you specified and
there will be no error message.

The cause for this is that the corners you specified are not such that the
trapezoid is centered at the origin.  It is in y and z (which is what the corner
constructor checks), but not in x (which the constructor does NOT check).

The fix is to have the corner constructor check that trapezoid is centered in x
as well as y and z.

In addition the code could be a little clear if it tested the centering of the
corners in the following way:

//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    G4ThreeVector BottomCenter = (Corners[0] + Corners[1] + Corners[2] +
Corners[3])/4.;
    // the coordinate of the center of the bottom (-z) face
    G4ThreeVector    TopCenter = (Corners[4] + Corners[5] + Corners[6] +
Corners[7])/4.;
    // the coordinate of the center of the top (+z) face.
    G4ThreeVector TrapezoidCenter = (BottomCenter + TopCenter)/2.;

if(!TrapezoidCenter.isNear(G4ThreeVector(0,0,0), Tolerance))
    G4Exception(...);
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

where "Tolerance" is whatever it needs to be to compare floating point numbers.
Comment 1 Vladimir.Grichine 2004-11-15 03:28:59 CET
Additional check for x centering relative to the frame
origin was added in G4Trap(G4String,G4ThreeVector[8]) -
constructor based on vertices