Problem 2011

Summary: G4ErrorPlaneSurfaceTarget distance calculation
Product: Geant4 Reporter: James Mott <jmott>
Component: error_propagationAssignee: Pedro.Arce
Status: RESOLVED FIXED    
Severity: minor CC: resnegfk
Priority: P4    
Version: 10.3   
Hardware: All   
OS: All   

Description James Mott 2017-11-08 19:43:02 CET
There's a bug in the calculation of the distance between a point and the plane of a G4ErrorPlaneSurfaceTarget

Line 151-2 of geometry/management/src/G4ErrorPlaneSurfaceTarget.cc currently reads:

  G4double alpha = std::acos( vec * normal() / vec.mag() / normal().mag() );
  G4double dist = std::fabs(vec.mag() * std::cos( alpha ));

This causes a problem if vec and normal are the same (or very nearly the same), since occasionally this division returns (1 + epsilon) due to the available precision. In this scenario, acos returns nan and the distance is nan, which means we step right over our target plane.

It's actually a curious way to calculate a distance between a point and plane anyway (to take the acos of an angle and calculate cos of it). It can just be:

  G4double dist = std::fabs(vec*normal() / normal().mag());

which avoids the nan problem.
Comment 1 Pedro.Arce 2017-11-10 12:58:29 CET
Solved, thanks for spotting this