G4Trap construction was occasionally failing when using the 8-point construction method. When constructing a new G4Trap using 8 points, a test is performed to check the the points conform to the expected order and the object is in the correct orientation. To do this, a number of comparisons are made using the sums of the x,y and z components. The tests check for equality to zero using '==', but this kind of comparison is generally a bad idea for floating point numbers due to round-off errors. A better solution is to test against a tolerance limit. The patch is attached below, applied from the 'source' directory, for 8.1.p02: --- geometry/solids/CSG/src/G4Trap.cc.old 2007-03-28 08:13:57.000000000 -0 400 +++ geometry/solids/CSG/src/G4Trap.cc 2007-03-28 08:21:26.000000000 -0400 @@ -135,17 +135,23 @@ { // Start with check of centering - the center of gravity trap line // should cross the origin of frame - + double tolerance = 1e-9; if ( pt[0].z() < 0 - && pt[0].z() == pt[1].z() && pt[0].z() == pt[2].z() && pt[0].z() == pt[3] .z() + && fabs( pt[0].z() - pt[1].z() ) < tolerance + && fabs( pt[0].z() -pt[2].z() ) < tolerance + && fabs( pt[0].z() - pt[3].z() ) < tolerance && pt[4].z() > 0 - && pt[4].z() == pt[5].z() && pt[4].z() == pt[6].z() && pt[4].z() == pt[7] .z() - && ( pt[0].z() + pt[4].z() ) == 0 - && pt[0].y() == pt[1].y() && pt[2].y() == pt[3].y() - && pt[4].y() == pt[5].y() && pt[6].y() == pt[7].y() - && ( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) == 0 - && ( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() + - pt[2].x() + pt[3].x() + pt[6].x() + pt[7].x() ) == 0 ) + && fabs( pt[4].z() - pt[5].z() ) < tolerance + && fabs( pt[4].z() - pt[6].z() ) < tolerance + && fabs( pt[4].z() - pt[7].z() ) < tolerance + && fabs( pt[0].z() + pt[4].z() ) < tolerance + && fabs( pt[0].y() - pt[1].y() ) < tolerance + && fabs( pt[2].y() - pt[3].y() ) < tolerance + && fabs( pt[4].y() - pt[5].y() ) < tolerance + && fabs( pt[6].y() - pt[7].y() ) < tolerance + && fabs( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) < tolerance + && fabs( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() + + pt[2].x() + pt[3].x() + pt[6].x() + pt[7].x() ) < tolerance ) { G4bool good;
To be verified by the author.
The severity of conditions inside 8-point constructor for G4Trap was changed for the cases where there are arithmetic actions on the point coordinates.