Problem 2011 - G4ErrorPlaneSurfaceTarget distance calculation
Summary: G4ErrorPlaneSurfaceTarget distance calculation
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: error_propagation (show other problems)
Version: 10.3
Hardware: All All
: P4 minor
Assignee: Pedro.Arce
URL:
Depends on:
Blocks:
 
Reported: 2017-11-08 19:43 CET by James Mott
Modified: 2017-11-10 12:58 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
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