Import Geant4 10.5.1 source tree
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
//
|
||||
@@ -44,45 +44,31 @@
|
||||
//
|
||||
G4IntersectingCone::G4IntersectingCone( const G4double r[2],
|
||||
const G4double z[2] )
|
||||
{
|
||||
{
|
||||
const G4double halfCarTolerance
|
||||
= 0.5 * G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
||||
|
||||
//
|
||||
// What type of cone are we?
|
||||
//
|
||||
type1 = (std::fabs(z[1]-z[0]) > std::fabs(r[1]-r[0]));
|
||||
|
||||
if (type1)
|
||||
type1 = (std::abs(z[1]-z[0]) > std::abs(r[1]-r[0]));
|
||||
|
||||
if (type1) // tube like
|
||||
{
|
||||
B = (r[1]-r[0])/(z[1]-z[0]); // tube like
|
||||
A = 0.5*( r[1]+r[0] - B*(z[1]+z[0]) );
|
||||
B = (r[1] - r[0]) / (z[1] - z[0]);
|
||||
A = (r[0]*z[1] - r[1]*z[0]) / (z[1] -z[0]);
|
||||
}
|
||||
else
|
||||
else // disk like
|
||||
{
|
||||
B = (z[1]-z[0])/(r[1]-r[0]); // disk like
|
||||
A = 0.5*( z[1]+z[0] - B*(r[1]+r[0]) );
|
||||
B = (z[1] - z[0]) / (r[1] - r[0]);
|
||||
A = (z[0]*r[1] - z[1]*r[0]) / (r[1] - r[0]);
|
||||
}
|
||||
//
|
||||
|
||||
// Calculate extent
|
||||
//
|
||||
if (r[0] < r[1])
|
||||
{
|
||||
rLo = r[0]-halfCarTolerance; rHi = r[1]+halfCarTolerance;
|
||||
}
|
||||
else
|
||||
{
|
||||
rLo = r[1]-halfCarTolerance; rHi = r[0]+halfCarTolerance;
|
||||
}
|
||||
|
||||
if (z[0] < z[1])
|
||||
{
|
||||
zLo = z[0]-halfCarTolerance; zHi = z[1]+halfCarTolerance;
|
||||
}
|
||||
else
|
||||
{
|
||||
zLo = z[1]-halfCarTolerance; zHi = z[0]+halfCarTolerance;
|
||||
}
|
||||
rLo = std::min(r[0], r[1]) - halfCarTolerance;
|
||||
rHi = std::max(r[0], r[1]) + halfCarTolerance;
|
||||
zLo = std::min(z[0], z[1]) - halfCarTolerance;
|
||||
zHi = std::max(z[0], z[1]) + halfCarTolerance;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,11 +157,11 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
|
||||
//
|
||||
// where:
|
||||
//
|
||||
// a = x0**2 + y0**2 - (A + B*z0)**2
|
||||
// a = tx**2 + ty**2 - (B*tz)**2
|
||||
//
|
||||
// b = 2*( x0*tx + y0*ty - (A*B - B*B*z0)*tz)
|
||||
// b = 2*( px*vx + py*vy - B*(A + B*pz)*vz )
|
||||
//
|
||||
// c = tx**2 + ty**2 - (B*tz)**2
|
||||
// c = x0**2 + y0**2 - (A + B*z0)**2
|
||||
//
|
||||
// Notice, that if a < 0, this indicates that the two solutions (assuming
|
||||
// they exist) are in opposite cones (that is, given z0 = -A/B, one z < z0
|
||||
@@ -191,7 +177,7 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
|
||||
// This should be rare.
|
||||
//
|
||||
// For b*b - 4*a*c = 0, we also have one solution, which is almost always
|
||||
// a line just grazing the surface of a the cone, which we want to ignore.
|
||||
// a line just grazing the surface of a the cone, which we want to ignore.
|
||||
// However, there are two other, very rare, possibilities:
|
||||
// a line intersecting the z axis and either:
|
||||
// 1. At the same angle std::atan(B) to just miss one side of the cone, or
|
||||
@@ -204,12 +190,12 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
|
||||
//
|
||||
// Now: x0*tx + y0*ty = 0 in terms of roundoff error. We can write:
|
||||
// Delta = x0*tx + y0*ty
|
||||
// b = 2*( Delta - (A*B + B*B*z0)*tz )
|
||||
// b = 2*( Delta - B*(A + B*z0)*tz )
|
||||
// For:
|
||||
// b*b - 4*a*c = epsilon
|
||||
// where epsilon is small, then:
|
||||
// Delta = epsilon/2/B
|
||||
//
|
||||
//
|
||||
G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
|
||||
const G4ThreeVector &v,
|
||||
G4double *s1, G4double *s2 )
|
||||
@@ -219,14 +205,34 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
|
||||
G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
|
||||
G4double tx = v.x(), ty = v.y(), tz = v.z();
|
||||
|
||||
G4double a = tx*tx + ty*ty - sqr(B*tz);
|
||||
G4double b = 2*( x0*tx + y0*ty - (A*B + B*B*z0)*tz);
|
||||
G4double c = x0*x0 + y0*y0 - sqr(A + B*z0);
|
||||
|
||||
G4double radical = b*b - 4*a*c;
|
||||
|
||||
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
|
||||
|
||||
// Value of radical can be inaccurate due to loss of precision
|
||||
// if to calculate the coefficiets a,b,c like the following:
|
||||
// G4double a = tx*tx + ty*ty - sqr(B*tz);
|
||||
// G4double b = 2*( x0*tx + y0*ty - B*(A + B*z0)*tz);
|
||||
// G4double c = x0*x0 + y0*y0 - sqr(A + B*z0);
|
||||
//
|
||||
// For more accurate calculation of radical the coefficients
|
||||
// are splitted in two components, radial and along z-axis
|
||||
//
|
||||
G4double ar = tx*tx + ty*ty;
|
||||
G4double az = sqr(B*tz);
|
||||
G4double br = 2*(x0*tx + y0*ty);
|
||||
G4double bz = 2*B*(A + B*z0)*tz;
|
||||
G4double cr = x0*x0 + y0*y0;
|
||||
G4double cz = sqr(A + B*z0);
|
||||
|
||||
// Instead radical = b*b - 4*a*c
|
||||
G4double arcz = 4*ar*cz;
|
||||
G4double azcr = 4*az*cr;
|
||||
G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
|
||||
|
||||
// Find the coefficients
|
||||
G4double a = ar - az;
|
||||
G4double b = br - bz;
|
||||
G4double c = cr - cz;
|
||||
|
||||
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
|
||||
|
||||
if (radical < EPS*std::fabs(b))
|
||||
{
|
||||
//
|
||||
@@ -247,7 +253,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
|
||||
{
|
||||
radical = std::sqrt(radical);
|
||||
}
|
||||
|
||||
|
||||
if (a > 1/kInfinity)
|
||||
{
|
||||
G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
|
||||
@@ -277,7 +283,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// LineHitsCone2
|
||||
//
|
||||
@@ -297,7 +303,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
|
||||
//
|
||||
// a > 0 now means we intersect only once in the correct hemisphere.
|
||||
//
|
||||
// a > 0 ? We only want solution which produces R > 0.
|
||||
// a > 0 ? We only want solution which produces R > 0.
|
||||
// since R = (z0+s*tz-A)/B, for tz/B > 0, this is the largest s
|
||||
// for tz/B < 0, this is the smallest s
|
||||
// thus, same as in case 1 ( since sign(tz/B) = sign(tz*B) )
|
||||
@@ -310,27 +316,47 @@ G4int G4IntersectingCone::LineHitsCone2( const G4ThreeVector &p,
|
||||
// originally it was 1E-6
|
||||
G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
|
||||
G4double tx = v.x(), ty = v.y(), tz = v.z();
|
||||
|
||||
|
||||
// Special case which might not be so rare: B = 0 (precisely)
|
||||
//
|
||||
if (B==0)
|
||||
{
|
||||
if (std::fabs(tz) < 1/kInfinity) { return 0; }
|
||||
|
||||
|
||||
*s1 = (A-z0)/tz;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Value of radical can be inaccurate due to loss of precision
|
||||
// if to calculate the coefficiets a,b,c like the following:
|
||||
// G4double a = tz*tz - B2*(tx*tx + ty*ty);
|
||||
// G4double b = 2*( (z0-A)*tz - B2*(x0*tx + y0*ty) );
|
||||
// G4double c = sqr(z0-A) - B2*( x0*x0 + y0*y0 );
|
||||
//
|
||||
// For more accurate calculation of radical the coefficients
|
||||
// are splitted in two components, radial and along z-axis
|
||||
//
|
||||
G4double B2 = B*B;
|
||||
|
||||
G4double a = tz*tz - B2*(tx*tx + ty*ty);
|
||||
G4double b = 2*( (z0-A)*tz - B2*(x0*tx + y0*ty) );
|
||||
G4double c = sqr(z0-A) - B2*( x0*x0 + y0*y0 );
|
||||
|
||||
G4double radical = b*b - 4*a*c;
|
||||
|
||||
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
|
||||
|
||||
G4double az = tz*tz;
|
||||
G4double ar = B2*(tx*tx + ty*ty);
|
||||
G4double bz = 2*(z0-A)*tz;
|
||||
G4double br = 2*B2*(x0*tx + y0*ty);
|
||||
G4double cz = sqr(z0-A);
|
||||
G4double cr = B2*(x0*x0 + y0*y0);
|
||||
|
||||
// Instead radical = b*b - 4*a*c
|
||||
G4double arcz = 4*ar*cz;
|
||||
G4double azcr = 4*az*cr;
|
||||
G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
|
||||
|
||||
// Find the coefficients
|
||||
G4double a = az - ar;
|
||||
G4double b = bz - br;
|
||||
G4double c = cz - cr;
|
||||
|
||||
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
|
||||
|
||||
if (radical < EPS*std::fabs(b))
|
||||
{
|
||||
//
|
||||
@@ -350,7 +376,7 @@ G4int G4IntersectingCone::LineHitsCone2( const G4ThreeVector &p,
|
||||
{
|
||||
radical = std::sqrt(radical);
|
||||
}
|
||||
|
||||
|
||||
if (a < -1/kInfinity)
|
||||
{
|
||||
G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
|
||||
|
||||
@@ -1859,18 +1859,22 @@ G4TessellatedSolid::CalculateExtent(const EAxis pAxis,
|
||||
G4double& pMin, G4double& pMax) const
|
||||
{
|
||||
G4ThreeVector bmin, bmax;
|
||||
G4bool exist;
|
||||
|
||||
// Check bounding box (bbox)
|
||||
//
|
||||
BoundingLimits(bmin,bmax);
|
||||
G4BoundingEnvelope bbox(bmin,bmax);
|
||||
#ifdef G4BBOX_EXTENT
|
||||
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
|
||||
// Use simple bounding-box to help in the case of complex meshes
|
||||
//
|
||||
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
|
||||
#if 0
|
||||
// Precise extent computation (disabled by default for this shape)
|
||||
//
|
||||
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
|
||||
{
|
||||
return exist = (pMin < pMax) ? true : false;
|
||||
return (pMin < pMax) ? true : false;
|
||||
}
|
||||
|
||||
// The extent is calculated as cumulative extent of the pyramids
|
||||
@@ -1907,6 +1911,7 @@ G4TessellatedSolid::CalculateExtent(const EAxis pAxis,
|
||||
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
|
||||
}
|
||||
return (pMin < pMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
//#if !defined(G4GEOM_USE_UTET)
|
||||
|
||||
const char G4Tet::CVSVers[]="$Id: G4Tet.cc 113723 2018-12-06 14:12:07Z gunter $";
|
||||
const char G4Tet::CVSVers[]="$Id$";
|
||||
|
||||
#include "G4VoxelLimits.hh"
|
||||
#include "G4AffineTransform.hh"
|
||||
@@ -328,15 +328,20 @@ G4bool G4Tet::CalculateExtent(const EAxis pAxis,
|
||||
G4double& pMin, G4double& pMax) const
|
||||
{
|
||||
G4ThreeVector bmin, bmax;
|
||||
G4bool exist;
|
||||
|
||||
// Check bounding box (bbox)
|
||||
//
|
||||
BoundingLimits(bmin,bmax);
|
||||
G4BoundingEnvelope bbox(bmin,bmax);
|
||||
#ifdef G4BBOX_EXTENT
|
||||
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
|
||||
// Use simple bounding-box to help in the case of complex 3D meshes
|
||||
//
|
||||
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
|
||||
#if 0
|
||||
// Precise extent computation (disabled by default for this shape)
|
||||
//
|
||||
G4bool exist;
|
||||
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
|
||||
{
|
||||
return exist = (pMin < pMax) ? true : false;
|
||||
@@ -359,8 +364,8 @@ G4bool G4Tet::CalculateExtent(const EAxis pAxis,
|
||||
polygons[1] = &base;
|
||||
|
||||
G4BoundingEnvelope benv(bmin,bmax,polygons);
|
||||
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
return exist;
|
||||
return exists = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -326,19 +326,23 @@ G4UTessellatedSolid::CalculateExtent(const EAxis pAxis,
|
||||
G4double& pMin, G4double& pMax) const
|
||||
{
|
||||
G4ThreeVector bmin, bmax;
|
||||
G4bool exist;
|
||||
G4double kCarToleranceHalf = 0.5*kCarTolerance;
|
||||
|
||||
// Check bounding box (bbox)
|
||||
//
|
||||
BoundingLimits(bmin,bmax);
|
||||
G4BoundingEnvelope bbox(bmin,bmax);
|
||||
#ifdef G4BBOX_EXTENT
|
||||
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
|
||||
// Use simple bounding-box to help in the case of complex meshes
|
||||
//
|
||||
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
|
||||
#if 0
|
||||
// Precise extent computation (disabled by default for this shape)
|
||||
//
|
||||
G4double kCarToleranceHalf = 0.5*kCarTolerance;
|
||||
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
|
||||
{
|
||||
return exist = (pMin < pMax) ? true : false;
|
||||
return (pMin < pMax) ? true : false;
|
||||
}
|
||||
|
||||
// The extent is calculated as cumulative extent of the pyramids
|
||||
@@ -373,6 +377,7 @@ G4UTessellatedSolid::CalculateExtent(const EAxis pAxis,
|
||||
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
|
||||
}
|
||||
return (pMin < pMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -188,15 +188,20 @@ G4UTet::CalculateExtent(const EAxis pAxis,
|
||||
G4double& pMin, G4double& pMax) const
|
||||
{
|
||||
G4ThreeVector bmin, bmax;
|
||||
G4bool exist;
|
||||
|
||||
// Check bounding box (bbox)
|
||||
//
|
||||
BoundingLimits(bmin,bmax);
|
||||
G4BoundingEnvelope bbox(bmin,bmax);
|
||||
#ifdef G4BBOX_EXTENT
|
||||
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
|
||||
// Use simple bounding-box to help in the case of complex 3D meshes
|
||||
//
|
||||
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
|
||||
#if 0
|
||||
// Precise extent computation (disabled by default for this shape)
|
||||
//
|
||||
G4bool exist;
|
||||
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
|
||||
{
|
||||
return exist = (pMin < pMax) ? true : false;
|
||||
@@ -219,8 +224,8 @@ G4UTet::CalculateExtent(const EAxis pAxis,
|
||||
polygons[1] = &base;
|
||||
|
||||
G4BoundingEnvelope benv(bmin,bmax,polygons);
|
||||
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
return exist;
|
||||
return exists = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user