Problem 830

Summary: Probably bug in G4Sphere::DistanceToOut
Product: Geant4 Reporter: D.A.Shtol
Component: geometry/solidsAssignee: Vladimir.Grichine
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.1   
Hardware: PC   
OS: Linux   

Description D.A.Shtol 2006-01-16 22:59:18 CET
Here is more simple test program working only with solid, which shows a possible
bug in G4Sphere:

/*
 * Program ro demonstarte a bug in G4Sphere
 */

// ----- includes ------

// standard C headers #include <cstdlib>

// standard C++ headers #include <iostream>

// other packages headers #include "ExtGeant4/G4Sphere.hh"

int main() {
   G4double mainInnerRadius =  21.45 * cm ;
   G4double mainOuterRadius = 85.0 * cm ;
   G4double minTheta = 18.0 * degree ;
   //G4double minTheta = 0 ;

   std::string name="mainSp";
   // test sphere
   G4Sphere* solidMainSp =
      new G4Sphere( name,
                    mainInnerRadius,
                    mainOuterRadius,
                    0.0, M_PI*2,
                    minTheta,
                    M_PI - 2*minTheta);

   // Solid test
G4ThreeVector point(81.61117212,-27.77179755,196.4143423);
   G4ThreeVector dir(0.1644697995,0.18507236,0.9688642354);
   if (solidMainSp->Inside(point)) {
      G4cout<<point<<" is inside"<<std::endl;
   }
   else {
      G4cout<<point<<" is outside"<<std::endl;
   }
   G4double dist=solidMainSp->DistanceToOut(point, dir);
   G4cout.precision(10);
   G4cout<<"Distance: "<<dist<<G4endl;

   if (dist>kCarTolerance) {
      G4cout<<"Distance is greater then tolerance"<<std::endl;
   }
   G4ThreeVector p1=point+dir*dist*0.999/dir.r();
   if (solidMainSp->Inside(p1) == kOutside) {
      G4cout<<p1<<" is outside"<<std::endl;
   }
   else {
      G4cout<<p1<<" is inside"<<std::endl;
   }
}

With version 4.7 the output is:
======OUTPUT====
(81.6112,-27.7718,196.414) is inside
Distance: 119.4084556
Distance is greater then tolerance
(101.2306178,-5.694692081,311.9892337) is inside
======END OF OUTPUT====
which is normal. But with version 4.7.p01 and later the output is:

======OUTPUT====
(81.6112,-27.7718,196.414) is inside
Distance: 647.5415503
Distance is greater then tolerance
(188.0057,91.95040333,823.1668115) is outside
======END OF OUTPUT====
which is strange. We tried 4.8.0 but it doesn't help.
Comment 1 Vladimir.Grichine 2006-01-17 01:44:59 CET
sb830.DistanceToOut(pb830,vb830... = 119.40845555751542
sb830.Inside(pb830+Dist*vb830) = Surface
A bug was fixed in G4Sphere::DistanceToOut. An updated G4Sphere.cc will be
available in coming patch for 80 release