Import Geant4 11.4.0 source tree
This commit is contained in:
@@ -44,6 +44,12 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex boxMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -77,18 +83,6 @@ G4Box::G4Box( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Box::~G4Box() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Box::G4Box(const G4Box&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -259,35 +253,38 @@ G4ThreeVector G4Box::SurfaceNormal(const G4ThreeVector& p) const
|
||||
{
|
||||
G4double px = p.x(), py = p.y(), pz = p.z();
|
||||
G4ThreeVector norm(0.,0.,0.);
|
||||
if (std::abs(std::abs(px) - fDx) <= delta) norm.setX(std::copysign(1.,px));
|
||||
if (std::abs(std::abs(py) - fDy) <= delta) norm.setY(std::copysign(1.,py));
|
||||
if (std::abs(std::abs(pz) - fDz) <= delta) norm.setZ(std::copysign(1.,pz));
|
||||
if (std::abs(std::abs(px)-fDx) <= delta) { norm.setX(std::copysign(1.,px)); }
|
||||
if (std::abs(std::abs(py)-fDy) <= delta) { norm.setY(std::copysign(1.,py)); }
|
||||
if (std::abs(std::abs(pz)-fDz) <= delta) { norm.setZ(std::copysign(1.,pz)); }
|
||||
|
||||
G4double nside = norm.mag2(); // number of sides = magnitude squared
|
||||
if (nside == 1)
|
||||
return norm;
|
||||
else if (nside > 1)
|
||||
return norm.unit(); // edge or corner
|
||||
else
|
||||
{
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4int oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc);
|
||||
G4Exception("G4Box::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
return ApproxSurfaceNormal(p);
|
||||
return norm;
|
||||
}
|
||||
if (nside > 1)
|
||||
{
|
||||
return norm.unit(); // edge or corner
|
||||
}
|
||||
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4int oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc);
|
||||
G4Exception("G4Box::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
|
||||
return ApproxSurfaceNormal(p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -302,11 +299,15 @@ G4ThreeVector G4Box::ApproxSurfaceNormal(const G4ThreeVector& p) const
|
||||
G4double distz = std::abs(p.z()) - fDz;
|
||||
|
||||
if (distx >= disty && distx >= distz)
|
||||
{
|
||||
return {std::copysign(1.,p.x()), 0., 0.};
|
||||
}
|
||||
if (disty >= distx && disty >= distz)
|
||||
{
|
||||
return {0., std::copysign(1.,p.y()), 0.};
|
||||
else
|
||||
return {0., 0., std::copysign(1.,p.z())};
|
||||
}
|
||||
|
||||
return {0., 0., std::copysign(1.,p.z())};
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -320,9 +321,9 @@ G4double G4Box::DistanceToIn(const G4ThreeVector& p,
|
||||
{
|
||||
// Check if point is on the surface and traveling away
|
||||
//
|
||||
if ((std::abs(p.x()) - fDx) >= -delta && p.x()*v.x() >= 0) return kInfinity;
|
||||
if ((std::abs(p.y()) - fDy) >= -delta && p.y()*v.y() >= 0) return kInfinity;
|
||||
if ((std::abs(p.z()) - fDz) >= -delta && p.z()*v.z() >= 0) return kInfinity;
|
||||
if ((std::abs(p.x())-fDx) >= -delta && p.x()*v.x() >= 0) { return kInfinity; }
|
||||
if ((std::abs(p.y())-fDy) >= -delta && p.y()*v.y() >= 0) { return kInfinity; }
|
||||
if ((std::abs(p.z())-fDz) >= -delta && p.z()*v.z() >= 0) { return kInfinity; }
|
||||
|
||||
// Find intersection
|
||||
//
|
||||
@@ -341,7 +342,8 @@ G4double G4Box::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double tmin = std::max(tymin,(p.z() - dz)*invz);
|
||||
G4double tmax = std::min(tymax,(p.z() + dz)*invz);
|
||||
|
||||
if (tmax <= tmin + delta) return kInfinity; // touch or no hit
|
||||
if (tmax <= tmin + delta) { return kInfinity; } // touch or no hit
|
||||
|
||||
return (tmin < delta) ? 0. : tmin;
|
||||
}
|
||||
|
||||
@@ -378,9 +380,9 @@ G4double G4Box::DistanceToOut(const G4ThreeVector& p,
|
||||
|
||||
if (!calcNorm) // calculation of normal is not needed
|
||||
{
|
||||
if ((std::abs(px) - fDx) >= -delta && px*vx > 0) return 0.;
|
||||
if ((std::abs(py) - fDy) >= -delta && py*vy > 0) return 0.;
|
||||
if ((std::abs(pz) - fDz) >= -delta && pz*vz > 0) return 0.;
|
||||
if ((std::abs(px) - fDx) >= -delta && px*vx > 0) { return 0.; }
|
||||
if ((std::abs(py) - fDy) >= -delta && py*vy > 0) { return 0.; }
|
||||
if ((std::abs(pz) - fDz) >= -delta && pz*vz > 0) { return 0.; }
|
||||
G4double tx = (vx == 0) ? DBL_MAX : (std::copysign(fDx,vx) - px)/vx;
|
||||
G4double ty = (vy == 0) ? DBL_MAX : (std::copysign(fDy,vy) - py)/vy;
|
||||
G4double tz = (vz == 0) ? DBL_MAX : (std::copysign(fDz,vz) - pz)/vz;
|
||||
@@ -413,9 +415,12 @@ G4double G4Box::DistanceToOut(const G4ThreeVector& p,
|
||||
G4double tmax = std::min(std::min(tx, ty), tz);
|
||||
|
||||
// Find normal
|
||||
G4double nx = std::copysign((G4double)(tmax == tx), vx);
|
||||
G4double ny = std::copysign((G4double)(tmax == ty && nx == 0), vy);
|
||||
G4double nz = std::copysign((G4double)(tmax == tz && nx == 0 && ny == 0), vz);
|
||||
G4bool pickZ = (tmax == tz);
|
||||
G4bool pickX = (!pickZ) && (tmax == tx);
|
||||
G4bool pickY = (!pickZ) && (!pickX);
|
||||
G4double nz = std::copysign((G4double)pickZ, vz);
|
||||
G4double nx = std::copysign((G4double)pickX, vx);
|
||||
G4double ny = std::copysign((G4double)pickY, vy);
|
||||
n->set(nx, ny, nz);
|
||||
return tmax;
|
||||
}
|
||||
@@ -521,6 +526,36 @@ G4ThreeVector G4Box::GetPointOnSurface() const
|
||||
return { x, y, z };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Computes/returns volume capacity
|
||||
//
|
||||
G4double G4Box::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&boxMutex);
|
||||
fCubicVolume = 8*fDx*fDy*fDz;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Computes/returns surface area
|
||||
//
|
||||
G4double G4Box::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&boxMutex);
|
||||
fSurfaceArea = 8*(fDx*fDy+fDx*fDz+fDy*fDz);
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Make a clone of the object
|
||||
|
||||
@@ -51,6 +51,12 @@
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex consMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -129,18 +135,6 @@ G4Cons::G4Cons( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Cons::~G4Cons() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Cons::G4Cons(const G4Cons&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -183,9 +177,9 @@ EInside G4Cons::Inside(const G4ThreeVector& p) const
|
||||
G4double r2, rl, rh, pPhi, tolRMin, tolRMax; // rh2, rl2 ;
|
||||
EInside in;
|
||||
|
||||
if (std::fabs(p.z()) > fDz + halfCarTolerance ) { return in = kOutside; }
|
||||
else if(std::fabs(p.z()) >= fDz - halfCarTolerance ) { in = kSurface; }
|
||||
else { in = kInside; }
|
||||
if (std::fabs(p.z()) > fDz + halfCarTolerance ) { return in = kOutside; }
|
||||
if(std::fabs(p.z()) >= fDz - halfCarTolerance ) { in = kSurface; }
|
||||
else { in = kInside; }
|
||||
|
||||
r2 = p.x()*p.x() + p.y()*p.y() ;
|
||||
rl = 0.5*(fRmin2*(p.z() + fDz) + fRmin1*(fDz - p.z()))/fDz ;
|
||||
@@ -217,7 +211,7 @@ EInside G4Cons::Inside(const G4ThreeVector& p) const
|
||||
if ( (pPhi < fSPhi - halfAngTolerance) ||
|
||||
(pPhi > fSPhi + fDPhi + halfAngTolerance) ) { return in = kOutside; }
|
||||
|
||||
else if (in == kInside) // else it's kSurface anyway already
|
||||
if (in == kInside) // else it's kSurface anyway already
|
||||
{
|
||||
if ( (pPhi < fSPhi + halfAngTolerance) ||
|
||||
(pPhi > fSPhi + fDPhi - halfAngTolerance) ) { in = kSurface; }
|
||||
@@ -365,7 +359,10 @@ G4bool G4Cons::CalculateExtent( const EAxis pAxis,
|
||||
|
||||
// set quadrilaterals
|
||||
G4ThreeVectorList pols[NSTEPS+2];
|
||||
for (G4int k=0; k<ksteps+2; ++k) pols[k].resize(4);
|
||||
for (G4int k=0; k<ksteps+2; ++k)
|
||||
{
|
||||
pols[k].resize(4);
|
||||
}
|
||||
pols[0][0].set(rmin2*cosStart,rmin2*sinStart, dz);
|
||||
pols[0][1].set(rmin1*cosStart,rmin1*sinStart,-dz);
|
||||
pols[0][2].set(rmax1*cosStart,rmax1*sinStart,-dz);
|
||||
@@ -389,7 +386,10 @@ G4bool G4Cons::CalculateExtent( const EAxis pAxis,
|
||||
// set envelope and calculate extent
|
||||
std::vector<const G4ThreeVectorList *> polygons;
|
||||
polygons.resize(ksteps+2);
|
||||
for (G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
|
||||
for (G4int k=0; k<ksteps+2; ++k)
|
||||
{
|
||||
polygons[k] = &pols[k];
|
||||
}
|
||||
G4BoundingEnvelope benv(bmin,bmax,polygons);
|
||||
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
}
|
||||
@@ -843,15 +843,13 @@ G4double G4Cons::DistanceToIn( const G4ThreeVector& p,
|
||||
// Z ok. Check phi intersection if reqd
|
||||
|
||||
if ( fPhiFullCone ) { return sd; }
|
||||
else
|
||||
{
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
ri = rMaxAv + zi*tanRMax ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
ri = rMaxAv + zi*tanRMax ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
|
||||
|
||||
if ( cosPsi >= cosHDPhiIT ) { return sd; }
|
||||
}
|
||||
if ( cosPsi >= cosHDPhiIT ) { return sd; }
|
||||
}
|
||||
} // end if (sd>0)
|
||||
}
|
||||
@@ -893,26 +891,23 @@ G4double G4Cons::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
sd = -0.5*nt3/nt2 ;
|
||||
|
||||
if ( sd < 0 ) { return kInfinity; } // travel away
|
||||
else // sd >= 0, If 'forwards'. Check z intersection
|
||||
if ( sd < 0 ) { return kInfinity; } // travel away
|
||||
|
||||
// sd >= 0, If 'forwards'. Check z intersection
|
||||
zi = p.z() + sd*v.z() ;
|
||||
|
||||
if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
|
||||
{
|
||||
zi = p.z() + sd*v.z() ;
|
||||
// Z ok. Check phi intersection if reqd
|
||||
|
||||
if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
|
||||
{
|
||||
// Z ok. Check phi intersection if reqd
|
||||
if ( fPhiFullCone ) { return sd; }
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
ri = rMaxAv + zi*tanRMax ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
|
||||
|
||||
if ( fPhiFullCone ) { return sd; }
|
||||
else
|
||||
{
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
ri = rMaxAv + zi*tanRMax ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
|
||||
|
||||
if (cosPsi >= cosHDPhiIT) { return sd; }
|
||||
}
|
||||
}
|
||||
if (cosPsi >= cosHDPhiIT) { return sd; }
|
||||
}
|
||||
}
|
||||
else // travel || cone surface from its origin
|
||||
@@ -985,16 +980,14 @@ G4double G4Cons::DistanceToIn( const G4ThreeVector& p,
|
||||
else
|
||||
{
|
||||
if ( sd > halfRadTolerance ) { return sd; }
|
||||
else
|
||||
{
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1049,16 +1042,14 @@ G4double G4Cons::DistanceToIn( const G4ThreeVector& p,
|
||||
else
|
||||
{
|
||||
if( sd > halfRadTolerance ) { return sd; }
|
||||
else
|
||||
{
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1098,16 +1089,14 @@ G4double G4Cons::DistanceToIn( const G4ThreeVector& p,
|
||||
else
|
||||
{
|
||||
if ( sd > halfRadTolerance ) { return sd; }
|
||||
else
|
||||
{
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
// Calculate a normal vector in order to check Direction
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
|
||||
Normal = G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
|
||||
if ( Normal.dot(v) <= 0 ) { return sd; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1517,49 +1506,47 @@ G4double G4Cons::DistanceToOut( const G4ThreeVector& p,
|
||||
}
|
||||
return snxt=0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sider = kRMax ;
|
||||
if (b>0) { srd = -b - std::sqrt(d); }
|
||||
else { srd = c/(-b+std::sqrt(d)) ; }
|
||||
|
||||
sider = kRMax ;
|
||||
if (b>0) { srd = -b - std::sqrt(d); }
|
||||
else { srd = c/(-b+std::sqrt(d)); }
|
||||
|
||||
zi = p.z() + srd*v.z() ;
|
||||
ri = tanRMax*zi + rMaxAv ;
|
||||
zi = p.z() + srd*v.z() ;
|
||||
ri = tanRMax*zi + rMaxAv ;
|
||||
|
||||
if ((ri >= 0) && (-halfRadTolerance <= srd) && (srd <= halfRadTolerance))
|
||||
if ((ri >= 0) && (-halfRadTolerance <= srd) && (srd <= halfRadTolerance))
|
||||
{
|
||||
// An intersection within the tolerance
|
||||
// we will Store it in case it is good -
|
||||
//
|
||||
slentol = srd ;
|
||||
sidetol = kRMax ;
|
||||
}
|
||||
if ( (ri < 0) || (srd < halfRadTolerance) )
|
||||
{
|
||||
// Safety: if both roots -ve ensure that srd cannot `win'
|
||||
// distance to out
|
||||
|
||||
if (b>0) { sr2 = c/(-b-std::sqrt(d)); }
|
||||
else { sr2 = -b + std::sqrt(d); }
|
||||
zi = p.z() + sr2*v.z() ;
|
||||
ri = tanRMax*zi + rMaxAv ;
|
||||
|
||||
if ((ri >= 0) && (sr2 > halfRadTolerance))
|
||||
{
|
||||
// An intersection within the tolerance
|
||||
// we will Store it in case it is good -
|
||||
//
|
||||
slentol = srd ;
|
||||
sidetol = kRMax ;
|
||||
}
|
||||
if ( (ri < 0) || (srd < halfRadTolerance) )
|
||||
srd = sr2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Safety: if both roots -ve ensure that srd cannot `win'
|
||||
// distance to out
|
||||
srd = kInfinity ;
|
||||
|
||||
if (b>0) { sr2 = c/(-b-std::sqrt(d)); }
|
||||
else { sr2 = -b + std::sqrt(d); }
|
||||
zi = p.z() + sr2*v.z() ;
|
||||
ri = tanRMax*zi + rMaxAv ;
|
||||
|
||||
if ((ri >= 0) && (sr2 > halfRadTolerance))
|
||||
if( (-halfRadTolerance <= sr2) && ( sr2 <= halfRadTolerance) )
|
||||
{
|
||||
srd = sr2;
|
||||
}
|
||||
else
|
||||
{
|
||||
srd = kInfinity ;
|
||||
// An intersection within the tolerance.
|
||||
// Storing it in case it is good.
|
||||
|
||||
if( (-halfRadTolerance <= sr2) && ( sr2 <= halfRadTolerance) )
|
||||
{
|
||||
// An intersection within the tolerance.
|
||||
// Storing it in case it is good.
|
||||
|
||||
slentol = sr2 ;
|
||||
sidetol = kRMax ;
|
||||
}
|
||||
slentol = sr2 ;
|
||||
sidetol = kRMax ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1625,10 +1612,9 @@ G4double G4Cons::DistanceToOut( const G4ThreeVector& p,
|
||||
}
|
||||
return snxt = 0.0 ;
|
||||
}
|
||||
else // On the surface, but not heading out so we ignore this intersection
|
||||
{ // (as it is within tolerance).
|
||||
slentol = kInfinity ;
|
||||
}
|
||||
// On the surface, but not heading out so we ignore this intersection
|
||||
// (as it is within tolerance).
|
||||
slentol = kInfinity ;
|
||||
}
|
||||
|
||||
// Inner Cone intersection
|
||||
@@ -1754,13 +1740,11 @@ G4double G4Cons::DistanceToOut( const G4ThreeVector& p,
|
||||
}
|
||||
return snxt = 0.0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// On the surface, but not heading out so we ignore this
|
||||
// intersection (as it is within tolerance).
|
||||
|
||||
slentol = kInfinity ;
|
||||
}
|
||||
// On the surface, but not heading out so we ignore this
|
||||
// intersection (as it is within tolerance).
|
||||
|
||||
slentol = kInfinity ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2116,8 +2100,6 @@ std::ostream& G4Cons::StreamInfo(std::ostream& os) const
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetPointOnSurface
|
||||
@@ -2155,33 +2137,29 @@ G4ThreeVector G4Cons::GetPointOnSurface() const
|
||||
G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
|
||||
return { rone*cosu*(qone-zRand), rone*sinu*(qone-zRand), zRand };
|
||||
}
|
||||
else
|
||||
{
|
||||
return { fRmax1*cosu, fRmax2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
|
||||
}
|
||||
|
||||
return { fRmax1*cosu, fRmax2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
|
||||
}
|
||||
else if( (chose >= Aone) && (chose < Aone + Atwo) ) // inner surface
|
||||
if( (chose >= Aone) && (chose < Aone + Atwo) ) // inner surface
|
||||
{
|
||||
if(fRmin1 != fRmin2)
|
||||
{
|
||||
G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
|
||||
return { rtwo*cosu*(qtwo-zRand), rtwo*sinu*(qtwo-zRand), zRand };
|
||||
}
|
||||
else
|
||||
{
|
||||
return { fRmin1*cosu, fRmin2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
|
||||
}
|
||||
|
||||
return { fRmin1*cosu, fRmin2*sinu, G4RandFlat::shoot(-1.*fDz,fDz) };
|
||||
}
|
||||
else if( (chose >= Aone + Atwo) && (chose < Aone + Atwo + Athree) ) // base at -Dz
|
||||
if( (chose >= Aone + Atwo) && (chose < Aone + Atwo + Athree) ) // base at -Dz
|
||||
{
|
||||
return {rRand1*cosu, rRand1*sinu, -1*fDz};
|
||||
}
|
||||
else if( (chose >= Aone + Atwo + Athree)
|
||||
if( (chose >= Aone + Atwo + Athree)
|
||||
&& (chose < Aone + Atwo + Athree + Afour) ) // base at +Dz
|
||||
{
|
||||
return { rRand2*cosu, rRand2*sinu, fDz };
|
||||
}
|
||||
else if( (chose >= Aone + Atwo + Athree + Afour) // SPhi section
|
||||
if( (chose >= Aone + Atwo + Athree + Afour) // SPhi section
|
||||
&& (chose < Aone + Atwo + Athree + Afour + Afive) )
|
||||
{
|
||||
G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
|
||||
@@ -2189,13 +2167,64 @@ G4ThreeVector G4Cons::GetPointOnSurface() const
|
||||
fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
|
||||
return { rRand1*cosSPhi, rRand1*sinSPhi, zRand };
|
||||
}
|
||||
else // SPhi+DPhi section
|
||||
|
||||
// SPhi+DPhi section
|
||||
G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
|
||||
rRand1 = G4RandFlat::shoot(fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2),
|
||||
fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
|
||||
return { rRand1*cosEPhi, rRand1*sinEPhi, zRand };
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetCubicVolume
|
||||
|
||||
G4double G4Cons::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4double zRand = G4RandFlat::shoot(-1.*fDz,fDz);
|
||||
rRand1 = G4RandFlat::shoot(fRmin2-((zRand-fDz)/(2.*fDz))*(fRmin1-fRmin2),
|
||||
fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
|
||||
return { rRand1*cosEPhi, rRand1*sinEPhi, zRand };
|
||||
G4AutoLock l(&consMutex);
|
||||
G4double Rmean, rMean, deltaR, deltar;
|
||||
|
||||
Rmean = 0.5*(fRmax1+fRmax2);
|
||||
deltaR = fRmax1-fRmax2;
|
||||
|
||||
rMean = 0.5*(fRmin1+fRmin2);
|
||||
deltar = fRmin1-fRmin2;
|
||||
fCubicVolume = fDPhi*fDz*(Rmean*Rmean-rMean*rMean
|
||||
+(deltaR*deltaR-deltar*deltar)/12);
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetSurfaceArea
|
||||
|
||||
G4double G4Cons::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&consMutex);
|
||||
G4double mmin, mmax, dmin, dmax;
|
||||
|
||||
mmin= (fRmin1+fRmin2)*0.5;
|
||||
mmax= (fRmax1+fRmax2)*0.5;
|
||||
dmin= (fRmin2-fRmin1);
|
||||
dmax= (fRmax2-fRmax1);
|
||||
|
||||
fSurfaceArea = fDPhi*( mmin * std::sqrt(dmin*dmin+4*fDz*fDz)
|
||||
+ mmax * std::sqrt(dmax*dmax+4*fDz*fDz)
|
||||
+ 0.5*(fRmax1*fRmax1-fRmin1*fRmin1
|
||||
+fRmax2*fRmax2-fRmin2*fRmin2 ));
|
||||
if(!fPhiFullCone)
|
||||
{
|
||||
fSurfaceArea = fSurfaceArea+4*fDz*(mmax-mmin);
|
||||
}
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex zminmaxMutex = G4MUTEX_INITIALIZER;
|
||||
G4Mutex ctubsMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
@@ -170,18 +170,6 @@ G4CutTubs::G4CutTubs( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4CutTubs::~G4CutTubs() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4CutTubs::G4CutTubs(const G4CutTubs&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -215,111 +203,6 @@ G4CutTubs& G4CutTubs::operator = (const G4CutTubs& rhs)
|
||||
return *this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4CutTubs::GetCubicVolume()
|
||||
{
|
||||
constexpr G4int nphi = 200, nrho = 100;
|
||||
|
||||
if (fCubicVolume == 0.)
|
||||
{
|
||||
// get parameters
|
||||
G4double rmin = GetInnerRadius();
|
||||
G4double rmax = GetOuterRadius();
|
||||
G4double dz = GetZHalfLength();
|
||||
G4double sphi = GetStartPhiAngle();
|
||||
G4double dphi = GetDeltaPhiAngle();
|
||||
|
||||
// calculate volume
|
||||
G4double volume = dz*dphi*(rmax*rmax - rmin*rmin);
|
||||
if (dphi < twopi) // make recalculation
|
||||
{
|
||||
// set values for calculation of h - distance between
|
||||
// opposite points on bases
|
||||
G4ThreeVector nbot = GetLowNorm();
|
||||
G4ThreeVector ntop = GetHighNorm();
|
||||
G4double nx = nbot.x()/nbot.z() - ntop.x()/ntop.z();
|
||||
G4double ny = nbot.y()/nbot.z() - ntop.y()/ntop.z();
|
||||
|
||||
// compute volume by integration
|
||||
G4double delrho = (rmax - rmin)/nrho;
|
||||
G4double delphi = dphi/nphi;
|
||||
volume = 0.;
|
||||
for (G4int irho=0; irho<nrho; ++irho)
|
||||
{
|
||||
G4double r1 = rmin + delrho*irho;
|
||||
G4double r2 = rmin + delrho*(irho + 1);
|
||||
G4double rho = 0.5*(r1 + r2);
|
||||
G4double sector = 0.5*delphi*(r2*r2 - r1*r1);
|
||||
for (G4int iphi=0; iphi<nphi; ++iphi)
|
||||
{
|
||||
G4double phi = sphi + delphi*(iphi + 0.5);
|
||||
G4double h = nx*rho*std::cos(phi) + ny*rho*std::sin(phi) + 2.*dz;
|
||||
volume += sector*h;
|
||||
}
|
||||
}
|
||||
}
|
||||
fCubicVolume = volume;
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4CutTubs::GetSurfaceArea()
|
||||
{
|
||||
constexpr G4int nphi = 400;
|
||||
|
||||
if (fSurfaceArea == 0.)
|
||||
{
|
||||
// get parameters
|
||||
G4double rmin = GetInnerRadius();
|
||||
G4double rmax = GetOuterRadius();
|
||||
G4double dz = GetZHalfLength();
|
||||
G4double sphi = GetStartPhiAngle();
|
||||
G4double dphi = GetDeltaPhiAngle();
|
||||
G4ThreeVector nbot = GetLowNorm();
|
||||
G4ThreeVector ntop = GetHighNorm();
|
||||
|
||||
// calculate lateral surface area
|
||||
G4double sinner = 2.*dz*dphi*rmin;
|
||||
G4double souter = 2.*dz*dphi*rmax;
|
||||
if (dphi < twopi) // make recalculation
|
||||
{
|
||||
// set values for calculation of h - distance between
|
||||
// opposite points on bases
|
||||
G4double nx = nbot.x()/nbot.z() - ntop.x()/ntop.z();
|
||||
G4double ny = nbot.y()/nbot.z() - ntop.y()/ntop.z();
|
||||
|
||||
// compute lateral surface area by integration
|
||||
G4double delphi = dphi/nphi;
|
||||
sinner = 0.;
|
||||
souter = 0.;
|
||||
for (G4int iphi=0; iphi<nphi; ++iphi)
|
||||
{
|
||||
G4double phi = sphi + delphi*(iphi + 0.5);
|
||||
G4double cosphi = std::cos(phi);
|
||||
G4double sinphi = std::sin(phi);
|
||||
sinner += rmin*(nx*cosphi + ny*sinphi) + 2.*dz;
|
||||
souter += rmax*(nx*cosphi + ny*sinphi) + 2.*dz;
|
||||
}
|
||||
sinner *= delphi*rmin;
|
||||
souter *= delphi*rmax;
|
||||
}
|
||||
// set surface area
|
||||
G4double scut = (dphi == twopi) ? 0. : 2.*dz*(rmax - rmin);
|
||||
G4double szero = 0.5*dphi*(rmax*rmax - rmin*rmin);
|
||||
G4double slow = szero/std::abs(nbot.z());
|
||||
G4double shigh = szero/std::abs(ntop.z());
|
||||
fSurfaceArea = sinner + souter + 2.*scut + slow + shigh;
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get bounding box
|
||||
@@ -352,12 +235,12 @@ void G4CutTubs::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
|
||||
if (dphi > pi)
|
||||
{
|
||||
iftop = true;
|
||||
if (dists > 0 && diste > 0)iftop = false;
|
||||
if (dists > 0 && diste > 0) { iftop = false; }
|
||||
}
|
||||
else
|
||||
{
|
||||
iftop = false;
|
||||
if (dists <= 0 && diste <= 0) iftop = true;
|
||||
if (dists <= 0 && diste <= 0) { iftop = true; }
|
||||
}
|
||||
if (iftop)
|
||||
{
|
||||
@@ -384,12 +267,12 @@ void G4CutTubs::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
|
||||
if (dphi > pi)
|
||||
{
|
||||
iftop = true;
|
||||
if (dists > 0 && diste > 0) iftop = false;
|
||||
if (dists > 0 && diste > 0) { iftop = false; }
|
||||
}
|
||||
else
|
||||
{
|
||||
iftop = false;
|
||||
if (dists <= 0 && diste <= 0) iftop = true;
|
||||
if (dists <= 0 && diste <= 0) { iftop = true; }
|
||||
}
|
||||
if (iftop)
|
||||
{
|
||||
@@ -517,7 +400,10 @@ G4bool G4CutTubs::CalculateExtent( const EAxis pAxis,
|
||||
|
||||
// set quadrilaterals
|
||||
G4ThreeVectorList pols[NSTEPS+2];
|
||||
for (G4int k=0; k<ksteps+2; ++k) pols[k].resize(4);
|
||||
for (G4int k=0; k<ksteps+2; ++k)
|
||||
{
|
||||
pols[k].resize(4);
|
||||
}
|
||||
pols[0][0].set(rmin*cosStart,rmin*sinStart,zmax);
|
||||
pols[0][1].set(rmin*cosStart,rmin*sinStart,zmin);
|
||||
pols[0][2].set(rmax*cosStart,rmax*sinStart,zmin);
|
||||
@@ -596,14 +482,18 @@ EInside G4CutTubs::Inside( const G4ThreeVector& p ) const
|
||||
G4double ephi = sphi + fDPhi + kAngTolerance;
|
||||
if ((phi0 >= sphi && phi0 <= ephi) ||
|
||||
(phi1 >= sphi && phi1 <= ephi) ||
|
||||
(phi2 >= sphi && phi2 <= ephi)) in = kSurface;
|
||||
(phi2 >= sphi && phi2 <= ephi))
|
||||
{
|
||||
in = kSurface;
|
||||
}
|
||||
if (in == kOutside) { return kOutside; }
|
||||
|
||||
sphi += kAngTolerance;
|
||||
ephi -= kAngTolerance;
|
||||
if ((phi0 >= sphi && phi0 <= ephi) ||
|
||||
(phi1 >= sphi && phi1 <= ephi) ||
|
||||
(phi2 >= sphi && phi2 <= ephi)) in = kInside;
|
||||
(phi2 >= sphi && phi2 <= ephi)) { in = kInside;
|
||||
}
|
||||
if (in == kSurface) { return kSurface; }
|
||||
}
|
||||
|
||||
@@ -1056,13 +946,11 @@ G4double G4CutTubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return sd ;
|
||||
}
|
||||
else
|
||||
{
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
|
||||
if (cosPsi >= cosHDPhiIT) { return sd ; }
|
||||
}
|
||||
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
|
||||
if (cosPsi >= cosHDPhiIT) { return sd ; }
|
||||
} // end if std::fabs(zi)
|
||||
}
|
||||
} // end if (sd>=0)
|
||||
@@ -1095,22 +983,18 @@ G4double G4CutTubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
snxt = c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
snxt = c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
|
||||
return kInfinity;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1126,22 +1010,18 @@ G4double G4CutTubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
snxt= c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
snxt= c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
|
||||
return kInfinity;
|
||||
} // end if (!fPhiFullCutTube)
|
||||
} // end if (t3>tolIRMin2)
|
||||
} // end if (Inside Outer Radius)
|
||||
@@ -1181,16 +1061,14 @@ G4double G4CutTubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return sd ;
|
||||
}
|
||||
else
|
||||
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMin ;
|
||||
if (cosPsi >= cosHDPhiIT)
|
||||
{
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMin ;
|
||||
if (cosPsi >= cosHDPhiIT)
|
||||
{
|
||||
// Good inner radius isect
|
||||
// - but earlier phi isect still possible
|
||||
//
|
||||
snxt = sd ;
|
||||
}
|
||||
// Good inner radius isect
|
||||
// - but earlier phi isect still possible
|
||||
//
|
||||
snxt = sd ;
|
||||
}
|
||||
} // end if std::fabs(zi)
|
||||
}
|
||||
@@ -1922,7 +1800,7 @@ G4ThreeVector G4CutTubs::GetPointOnSurface() const
|
||||
// Set min and max z
|
||||
if (fZMin == 0. && fZMax == 0.)
|
||||
{
|
||||
G4AutoLock l(&zminmaxMutex);
|
||||
G4AutoLock l(&ctubsMutex);
|
||||
G4ThreeVector bmin, bmax;
|
||||
BoundingLimits(bmin,bmax);
|
||||
fZMin = bmin.z();
|
||||
@@ -2019,8 +1897,8 @@ G4ThreeVector G4CutTubs::GetPointOnSurface() const
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((ntop.dot(p) - fDz*ntop.z()) > 0.) continue;
|
||||
if ((nbot.dot(p) + fDz*nbot.z()) > 0.) continue;
|
||||
if ((ntop.dot(p) - fDz*ntop.z()) > 0.) { continue; }
|
||||
if ((nbot.dot(p) + fDz*nbot.z()) > 0.) { continue; }
|
||||
return p;
|
||||
}
|
||||
// Just in case, if all attempts to generate a point have failed
|
||||
@@ -2031,6 +1909,115 @@ G4ThreeVector G4CutTubs::GetPointOnSurface() const
|
||||
return {x, y, z};
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4CutTubs::GetCubicVolume()
|
||||
{
|
||||
constexpr G4int nphi = 200, nrho = 100;
|
||||
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&ctubsMutex);
|
||||
// get parameters
|
||||
G4double rmin = GetInnerRadius();
|
||||
G4double rmax = GetOuterRadius();
|
||||
G4double dz = GetZHalfLength();
|
||||
G4double sphi = GetStartPhiAngle();
|
||||
G4double dphi = GetDeltaPhiAngle();
|
||||
|
||||
// calculate volume
|
||||
G4double volume = dz*dphi*(rmax*rmax - rmin*rmin);
|
||||
if (dphi < twopi) // make recalculation
|
||||
{
|
||||
// set values for calculation of h - distance between
|
||||
// opposite points on bases
|
||||
G4ThreeVector nbot = GetLowNorm();
|
||||
G4ThreeVector ntop = GetHighNorm();
|
||||
G4double nx = nbot.x()/nbot.z() - ntop.x()/ntop.z();
|
||||
G4double ny = nbot.y()/nbot.z() - ntop.y()/ntop.z();
|
||||
|
||||
// compute volume by integration
|
||||
G4double delrho = (rmax - rmin)/nrho;
|
||||
G4double delphi = dphi/nphi;
|
||||
volume = 0.;
|
||||
for (G4int irho=0; irho<nrho; ++irho)
|
||||
{
|
||||
G4double r1 = rmin + delrho*irho;
|
||||
G4double r2 = rmin + delrho*(irho + 1);
|
||||
G4double rho = 0.5*(r1 + r2);
|
||||
G4double sector = 0.5*delphi*(r2*r2 - r1*r1);
|
||||
for (G4int iphi=0; iphi<nphi; ++iphi)
|
||||
{
|
||||
G4double phi = sphi + delphi*(iphi + 0.5);
|
||||
G4double h = nx*rho*std::cos(phi) + ny*rho*std::sin(phi) + 2.*dz;
|
||||
volume += sector*h;
|
||||
}
|
||||
}
|
||||
}
|
||||
fCubicVolume = volume;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4CutTubs::GetSurfaceArea()
|
||||
{
|
||||
constexpr G4int nphi = 400;
|
||||
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&ctubsMutex);
|
||||
// get parameters
|
||||
G4double rmin = GetInnerRadius();
|
||||
G4double rmax = GetOuterRadius();
|
||||
G4double dz = GetZHalfLength();
|
||||
G4double sphi = GetStartPhiAngle();
|
||||
G4double dphi = GetDeltaPhiAngle();
|
||||
G4ThreeVector nbot = GetLowNorm();
|
||||
G4ThreeVector ntop = GetHighNorm();
|
||||
|
||||
// calculate lateral surface area
|
||||
G4double sinner = 2.*dz*dphi*rmin;
|
||||
G4double souter = 2.*dz*dphi*rmax;
|
||||
if (dphi < twopi) // make recalculation
|
||||
{
|
||||
// set values for calculation of h - distance between
|
||||
// opposite points on bases
|
||||
G4double nx = nbot.x()/nbot.z() - ntop.x()/ntop.z();
|
||||
G4double ny = nbot.y()/nbot.z() - ntop.y()/ntop.z();
|
||||
|
||||
// compute lateral surface area by integration
|
||||
G4double delphi = dphi/nphi;
|
||||
sinner = 0.;
|
||||
souter = 0.;
|
||||
for (G4int iphi=0; iphi<nphi; ++iphi)
|
||||
{
|
||||
G4double phi = sphi + delphi*(iphi + 0.5);
|
||||
G4double cosphi = std::cos(phi);
|
||||
G4double sinphi = std::sin(phi);
|
||||
sinner += rmin*(nx*cosphi + ny*sinphi) + 2.*dz;
|
||||
souter += rmax*(nx*cosphi + ny*sinphi) + 2.*dz;
|
||||
}
|
||||
sinner *= delphi*rmin;
|
||||
souter *= delphi*rmax;
|
||||
}
|
||||
// set surface area
|
||||
G4double scut = (dphi == twopi) ? 0. : 2.*dz*(rmax - rmin);
|
||||
G4double szero = 0.5*dphi*(rmax*rmax - rmin*rmin);
|
||||
G4double slow = szero/std::abs(nbot.z());
|
||||
G4double shigh = szero/std::abs(ntop.z());
|
||||
fSurfaceArea = sinner + souter + 2.*scut + slow + shigh;
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
@@ -2110,8 +2097,8 @@ G4bool G4CutTubs::IsCrossingCutPlanes() const
|
||||
// opposite points on bases
|
||||
G4ThreeVector nbot = GetLowNorm();
|
||||
G4ThreeVector ntop = GetHighNorm();
|
||||
if (std::abs(nbot.z()) < kCarTolerance) return true;
|
||||
if (std::abs(ntop.z()) < kCarTolerance) return true;
|
||||
if (std::abs(nbot.z()) < kCarTolerance) { return true; }
|
||||
if (std::abs(ntop.z()) < kCarTolerance) { return true; }
|
||||
G4double nx = nbot.x()/nbot.z() - ntop.x()/ntop.z();
|
||||
G4double ny = nbot.y()/nbot.z() - ntop.y()/ntop.z();
|
||||
|
||||
@@ -2125,7 +2112,7 @@ G4bool G4CutTubs::IsCrossingCutPlanes() const
|
||||
for (G4int i=0; i<npoints+1; ++i)
|
||||
{
|
||||
G4double h = nx*cosphi + ny*sinphi + hzero;
|
||||
if (h < 0.) return true;
|
||||
if (h < 0.) { return true; }
|
||||
G4double sintmp = sinphi;
|
||||
sinphi = sintmp*cosdel + cosphi*sindel;
|
||||
cosphi = cosphi*cosdel - sintmp*sindel;
|
||||
|
||||
@@ -42,6 +42,12 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex orbMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -65,18 +71,6 @@ G4Orb::G4Orb( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Orb::~G4Orb() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Orb::G4Orb(const G4Orb&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -103,7 +97,7 @@ G4Orb& G4Orb::operator = (const G4Orb& rhs)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Check radius and initialize dada members
|
||||
// Check radius and initialize data members
|
||||
|
||||
void G4Orb::Initialize()
|
||||
{
|
||||
@@ -250,7 +244,7 @@ G4bool G4Orb::CalculateExtent(const EAxis pAxis,
|
||||
EInside G4Orb::Inside( const G4ThreeVector& p ) const
|
||||
{
|
||||
G4double rr = p.mag2();
|
||||
if (rr > sqrRmaxPlusTol) return kOutside;
|
||||
if (rr > sqrRmaxPlusTol) { return kOutside; }
|
||||
return (rr > sqrRmaxMinusTol) ? kSurface : kInside;
|
||||
}
|
||||
|
||||
@@ -276,7 +270,7 @@ G4double G4Orb::DistanceToIn( const G4ThreeVector& p,
|
||||
//
|
||||
G4double rr = p.mag2();
|
||||
G4double pv = p.dot(v);
|
||||
if (rr >= sqrRmaxMinusTol && pv >= 0) return kInfinity;
|
||||
if (rr >= sqrRmaxMinusTol && pv >= 0) { return kInfinity; }
|
||||
|
||||
// Find intersection
|
||||
//
|
||||
@@ -287,7 +281,7 @@ G4double G4Orb::DistanceToIn( const G4ThreeVector& p,
|
||||
// => tmin = -(p.v) - Sqrt((p.v)^2 - (r^2 - R^2))
|
||||
//
|
||||
G4double D = pv*pv - rr + fRmax*fRmax;
|
||||
if (D < 0) return kInfinity; // no intersection
|
||||
if (D < 0) { return kInfinity; } // no intersection
|
||||
|
||||
G4double sqrtD = std::sqrt(D);
|
||||
G4double dist = -pv - sqrtD;
|
||||
@@ -303,7 +297,8 @@ G4double G4Orb::DistanceToIn( const G4ThreeVector& p,
|
||||
return (dist >= kInfinity) ? kInfinity : dist;
|
||||
}
|
||||
|
||||
if (sqrtD*2 <= halfRmaxTol) return kInfinity; // touch
|
||||
if (sqrtD*2 <= halfRmaxTol) { return kInfinity; } // touch
|
||||
|
||||
return (dist < halfRmaxTol) ? 0. : dist;
|
||||
}
|
||||
|
||||
@@ -354,7 +349,7 @@ G4double G4Orb::DistanceToOut( const G4ThreeVector& p,
|
||||
//
|
||||
G4double D = pv*pv - rr + fRmax*fRmax;
|
||||
G4double tmax = (D <= 0) ? 0. : std::sqrt(D) - pv;
|
||||
if (tmax < halfRmaxTol) tmax = 0.;
|
||||
if (tmax < halfRmaxTol) { tmax = 0.; }
|
||||
if (calcNorm)
|
||||
{
|
||||
*validNorm = true;
|
||||
@@ -443,6 +438,35 @@ G4ThreeVector G4Orb::GetPointOnSurface() const
|
||||
return { fRmax*a*u, fRmax*a*v, fRmax*(2.*b - 1.) };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Computes/returns volume capacity
|
||||
|
||||
G4double G4Orb::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&orbMutex);
|
||||
fCubicVolume = 4*CLHEP::pi*fRmax*fRmax*fRmax/3.;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Computes/returns surface area
|
||||
|
||||
G4double G4Orb::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&orbMutex);
|
||||
fSurfaceArea = 4*CLHEP::pi*fRmax*fRmax;
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
|
||||
@@ -43,6 +43,12 @@
|
||||
#include "G4VPVParameterisation.hh"
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex paraMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -130,12 +136,6 @@ G4Para::G4Para( __void__& a )
|
||||
fRebuildPolyhedron = false; // default value for G4CSGSolid
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Para::~G4Para() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
@@ -260,35 +260,6 @@ void G4Para::MakePlanes()
|
||||
fPlanes[3].d = fPlanes[2].d;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Para::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
fCubicVolume = 8*fDx*fDy*fDz;
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Para::GetSurfaceArea()
|
||||
{
|
||||
if(fSurfaceArea == 0)
|
||||
{
|
||||
G4double sxy = fDx*fDy;
|
||||
G4double sxz = fDx*fDz*std::sqrt(1. + sqr(fTthetaSphi));
|
||||
G4double syz = fDy*fDz*std::sqrt(1. + sqr(fTalpha) + sqr(fTalpha*fTthetaSphi - fTthetaCphi));
|
||||
fSurfaceArea = 8*(sxy+sxz+syz);
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dispatch to parameterisation for replication mechanism dimension
|
||||
@@ -415,7 +386,8 @@ EInside G4Para::Inside( const G4ThreeVector& p ) const
|
||||
G4double dz = std::abs(p.z())-fDz;
|
||||
G4double dist = std::max(dxy,dz);
|
||||
|
||||
if (dist > halfCarTolerance) return kOutside;
|
||||
if (dist > halfCarTolerance) { return kOutside; }
|
||||
|
||||
return (dist > -halfCarTolerance) ? kSurface : kInside;
|
||||
}
|
||||
|
||||
@@ -475,28 +447,33 @@ G4ThreeVector G4Para::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
// Return normal
|
||||
//
|
||||
if (nsurf == 1) return {nx,ny,nz};
|
||||
else if (nsurf != 0) return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
else
|
||||
if (nsurf == 1)
|
||||
{
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4int oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Para::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
return ApproxSurfaceNormal(p);
|
||||
return {nx,ny,nz};
|
||||
}
|
||||
if (nsurf != 0)
|
||||
{
|
||||
return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
}
|
||||
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4int oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Para::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
|
||||
return ApproxSurfaceNormal(p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -518,9 +495,11 @@ G4ThreeVector G4Para::ApproxSurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
G4double distz = std::abs(p.z()) - fDz;
|
||||
if (dist > distz)
|
||||
{
|
||||
return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
|
||||
else
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -534,7 +513,10 @@ G4double G4Para::DistanceToIn(const G4ThreeVector& p,
|
||||
// Z intersections
|
||||
//
|
||||
if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
|
||||
G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
|
||||
G4double dz = (invz < 0) ? fDz : -fDz;
|
||||
G4double tzmin = (p.z() + dz)*invz;
|
||||
@@ -548,14 +530,14 @@ G4double G4Para::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis0 = fPlanes[0].d + disy;
|
||||
if (dis0 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos0 >= 0) return kInfinity;
|
||||
if (cos0 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis0/cos0;
|
||||
if (tmin0 < tmp) tmin0 = tmp;
|
||||
if (tmin0 < tmp) { tmin0 = tmp; }
|
||||
}
|
||||
else if (cos0 > 0)
|
||||
{
|
||||
G4double tmp = -dis0/cos0;
|
||||
if (tmax0 > tmp) tmax0 = tmp;
|
||||
if (tmax0 > tmp) { tmax0 = tmp; }
|
||||
}
|
||||
|
||||
G4double tmin1 = tmin0, tmax1 = tmax0;
|
||||
@@ -563,14 +545,14 @@ G4double G4Para::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis1 = fPlanes[1].d - disy;
|
||||
if (dis1 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos1 >= 0) return kInfinity;
|
||||
if (cos1 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis1/cos1;
|
||||
if (tmin1 < tmp) tmin1 = tmp;
|
||||
if (tmin1 < tmp) { tmin1 = tmp; }
|
||||
}
|
||||
else if (cos1 > 0)
|
||||
{
|
||||
G4double tmp = -dis1/cos1;
|
||||
if (tmax1 > tmp) tmax1 = tmp;
|
||||
if (tmax1 > tmp) { tmax1 = tmp; }
|
||||
}
|
||||
|
||||
// X intersections
|
||||
@@ -581,14 +563,14 @@ G4double G4Para::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis2 = fPlanes[2].d + disx;
|
||||
if (dis2 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos2 >= 0) return kInfinity;
|
||||
if (cos2 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis2/cos2;
|
||||
if (tmin2 < tmp) tmin2 = tmp;
|
||||
if (tmin2 < tmp) { tmin2 = tmp; }
|
||||
}
|
||||
else if (cos2 > 0)
|
||||
{
|
||||
G4double tmp = -dis2/cos2;
|
||||
if (tmax2 > tmp) tmax2 = tmp;
|
||||
if (tmax2 > tmp) { tmax2 = tmp; }
|
||||
}
|
||||
|
||||
G4double tmin3 = tmin2, tmax3 = tmax2;
|
||||
@@ -596,20 +578,21 @@ G4double G4Para::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis3 = fPlanes[3].d - disx;
|
||||
if (dis3 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos3 >= 0) return kInfinity;
|
||||
if (cos3 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis3/cos3;
|
||||
if (tmin3 < tmp) tmin3 = tmp;
|
||||
if (tmin3 < tmp) { tmin3 = tmp; }
|
||||
}
|
||||
else if (cos3 > 0)
|
||||
{
|
||||
G4double tmp = -dis3/cos3;
|
||||
if (tmax3 > tmp) tmax3 = tmp;
|
||||
if (tmax3 > tmp) { tmax3 = tmp; }
|
||||
}
|
||||
|
||||
// Find distance
|
||||
//
|
||||
G4double tmin = tmin3, tmax = tmax3;
|
||||
if (tmax <= tmin + halfCarTolerance) return kInfinity; // touch or no hit
|
||||
if (tmax <= tmin + halfCarTolerance) { return kInfinity; } // touch or no hit
|
||||
|
||||
return (tmin < halfCarTolerance ) ? 0. : tmin;
|
||||
}
|
||||
|
||||
@@ -716,7 +699,8 @@ G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
|
||||
G4double cos3 = -cos2;
|
||||
if (cos3 > 0)
|
||||
{
|
||||
G4double dis3 = fPlanes[3].a*p.x()+fPlanes[3].b*p.y()+fPlanes[3].c*p.z()+fPlanes[3].d;
|
||||
G4double dis3 = fPlanes[3].a*p.x()+fPlanes[3].b*p.y()
|
||||
+ fPlanes[3].c*p.z()+fPlanes[3].d;
|
||||
if (dis3 >= -halfCarTolerance)
|
||||
{
|
||||
if (calcNorm)
|
||||
@@ -735,10 +719,8 @@ G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
|
||||
if (calcNorm)
|
||||
{
|
||||
*validNorm = true;
|
||||
if (iside < 0)
|
||||
n->set(0, 0, iside + 3); // (-4+3)=-1, (-2+3)=+1
|
||||
else
|
||||
n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c);
|
||||
(iside < 0) ? (n->set(0, 0, iside + 3)) // (-4+3)=-1, (-2+3)=+1
|
||||
: (n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c));
|
||||
}
|
||||
return tmax;
|
||||
}
|
||||
@@ -871,6 +853,39 @@ G4ThreeVector G4Para::GetPointOnSurface() const
|
||||
return { x + y*fTalpha + z*fTthetaCphi, y + z*fTthetaSphi, z };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Para::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(¶Mutex);
|
||||
fCubicVolume = 8*fDx*fDy*fDz;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Para::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(¶Mutex);
|
||||
G4double sxy = fDx*fDy;
|
||||
G4double sxz = fDx*fDz*std::sqrt(1. + sqr(fTthetaSphi));
|
||||
G4double syz = fDy*fDz*std::sqrt(1. + sqr(fTalpha) + sqr(fTalpha*fTthetaSphi - fTthetaCphi));
|
||||
fSurfaceArea = 8*(sxy+sxz+syz);
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
|
||||
@@ -53,17 +53,26 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex sphereMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
// Private enums: Not for external use
|
||||
namespace {
|
||||
// used by distanceToOut
|
||||
enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kSTheta,kETheta};
|
||||
//
|
||||
namespace
|
||||
{
|
||||
// used by distanceToOut
|
||||
enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kSTheta,kETheta};
|
||||
|
||||
// used by normal
|
||||
enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNSTheta,kNETheta};
|
||||
// used by normal
|
||||
enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNSTheta,kNETheta};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// constructor - check parameters, convert angles so 0<sphi+dpshi<=2_PI
|
||||
@@ -111,18 +120,6 @@ G4Sphere::G4Sphere( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Sphere::~G4Sphere() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Sphere::G4Sphere(const G4Sphere&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -200,8 +197,8 @@ void G4Sphere::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
|
||||
G4double etheta = stheta + GetDeltaThetaAngle();
|
||||
G4double rhomin = rmin*std::min(sinStart,sinEnd);
|
||||
G4double rhomax = rmax;
|
||||
if (stheta > halfpi) rhomax = rmax*sinStart;
|
||||
if (etheta < halfpi) rhomax = rmax*sinEnd;
|
||||
if (stheta > halfpi) { rhomax = rmax*sinStart; }
|
||||
if (etheta < halfpi) { rhomax = rmax*sinEnd; }
|
||||
|
||||
G4TwoVector xymin,xymax;
|
||||
G4GeomTools::DiskExtent(rhomin,rhomax,
|
||||
@@ -284,10 +281,8 @@ EInside G4Sphere::Inside( const G4ThreeVector& p ) const
|
||||
{
|
||||
return in = kSurface;
|
||||
}
|
||||
else
|
||||
{
|
||||
return in = kInside;
|
||||
}
|
||||
|
||||
return in = kInside;
|
||||
}
|
||||
|
||||
if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
|
||||
@@ -320,7 +315,7 @@ EInside G4Sphere::Inside( const G4ThreeVector& p ) const
|
||||
if ( (pPhi < fSPhi - halfAngTolerance)
|
||||
|| (pPhi > ePhi + halfAngTolerance) ) { return in = kOutside; }
|
||||
|
||||
else if (in == kInside) // else it's kSurface anyway already
|
||||
if (in == kInside) // else it's kSurface anyway already
|
||||
{
|
||||
if ( (pPhi < fSPhi + halfAngTolerance)
|
||||
|| (pPhi > ePhi - halfAngTolerance) ) { in = kSurface; }
|
||||
@@ -384,7 +379,7 @@ G4ThreeVector G4Sphere::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
rho = std::sqrt(rho2);
|
||||
|
||||
G4double distRMax = std::fabs(radius-fRmax);
|
||||
if (fRmin != 0.0) distRMin = std::fabs(radius-fRmin);
|
||||
if (fRmin != 0.0) { distRMin = std::fabs(radius-fRmin); }
|
||||
|
||||
if ( (rho != 0.0) && !fFullSphere )
|
||||
{
|
||||
@@ -1799,11 +1794,9 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
}
|
||||
return snxt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
snxt = -pDotV3d+std::sqrt(d2); // second root since inside Rmax
|
||||
side = kRMax ;
|
||||
}
|
||||
|
||||
snxt = -pDotV3d+std::sqrt(d2); // second root since inside Rmax
|
||||
side = kRMax ;
|
||||
}
|
||||
|
||||
// Inner spherical shell intersection:
|
||||
@@ -1823,17 +1816,15 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
if(calcNorm) { *validNorm = false; } // Rmin surface is concave
|
||||
return snxt = 0 ;
|
||||
}
|
||||
else
|
||||
|
||||
if ( d2 >= 0. )
|
||||
{
|
||||
if ( d2 >= 0. )
|
||||
{
|
||||
sd = -pDotV3d-std::sqrt(d2);
|
||||
sd = -pDotV3d-std::sqrt(d2);
|
||||
|
||||
if ( sd >= 0. ) // Always intersect Rmin first
|
||||
{
|
||||
snxt = sd ;
|
||||
side = kRMin ;
|
||||
}
|
||||
if ( sd >= 0. ) // Always intersect Rmin first
|
||||
{
|
||||
snxt = sd ;
|
||||
side = kRMin ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1905,7 +1896,7 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
if( calcNorm ) { *validNorm = false; }
|
||||
return snxt = 0.;
|
||||
}
|
||||
else if( (fSTheta > halfpi) && (p.z() <= 0) )
|
||||
if( (fSTheta > halfpi) && (p.z() <= 0) )
|
||||
{
|
||||
if( calcNorm )
|
||||
{
|
||||
@@ -1918,7 +1909,10 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
p.y()/rhoSecTheta,
|
||||
std::sin(fSTheta) );
|
||||
}
|
||||
else *n = G4ThreeVector(0.,0.,1.);
|
||||
else
|
||||
{
|
||||
*n = G4ThreeVector(0.,0.,1.);
|
||||
}
|
||||
}
|
||||
return snxt = 0.;
|
||||
}
|
||||
@@ -1948,7 +1942,7 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
}
|
||||
return snxt = 0.;
|
||||
}
|
||||
else if( (fSTheta < halfpi) && (t2 < 0.) && (p.z() >=0.) ) // leave
|
||||
if( (fSTheta < halfpi) && (t2 < 0.) && (p.z() >=0.) ) // leave
|
||||
{
|
||||
if( calcNorm ) { *validNorm = false; }
|
||||
return snxt = 0.;
|
||||
@@ -2039,7 +2033,7 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
if( calcNorm ) { *validNorm = false; }
|
||||
return snxt = 0.;
|
||||
}
|
||||
else if ( (eTheta < halfpi) && (p.z() >= 0) )
|
||||
if ( (eTheta < halfpi) && (p.z() >= 0) )
|
||||
{
|
||||
if( calcNorm )
|
||||
{
|
||||
@@ -2076,17 +2070,19 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
*validNorm = true;
|
||||
if (rho2 != 0.0)
|
||||
{
|
||||
rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
|
||||
*n = G4ThreeVector( p.x()/rhoSecTheta,
|
||||
p.y()/rhoSecTheta,
|
||||
-sinETheta );
|
||||
rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
|
||||
*n = G4ThreeVector( p.x()/rhoSecTheta,
|
||||
p.y()/rhoSecTheta,
|
||||
-sinETheta );
|
||||
}
|
||||
else
|
||||
{
|
||||
*n = G4ThreeVector(0.,0.,-1.);
|
||||
}
|
||||
else *n = G4ThreeVector(0.,0.,-1.);
|
||||
}
|
||||
return snxt = 0.;
|
||||
}
|
||||
else if ( (eTheta > halfpi)
|
||||
&& (t2 < 0.) && (p.z() <=0.) ) // leave
|
||||
if ( (eTheta > halfpi) && (t2 < 0.) && (p.z() <=0.) ) // leave
|
||||
{
|
||||
if( calcNorm ) { *validNorm = false; }
|
||||
return snxt = 0.;
|
||||
@@ -2336,7 +2332,10 @@ G4double G4Sphere::DistanceToOut( const G4ThreeVector& p,
|
||||
sidephi = kEPhi ;
|
||||
}
|
||||
}
|
||||
else sphi=kInfinity;
|
||||
else
|
||||
{
|
||||
sphi=kInfinity;
|
||||
}
|
||||
}
|
||||
else // leaving immediately by starting phi
|
||||
{
|
||||
@@ -2744,11 +2743,13 @@ std::ostream& G4Sphere::StreamInfo( std::ostream& os ) const
|
||||
|
||||
G4double G4Sphere::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0.)
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&sphereMutex);
|
||||
G4double RRR = fRmax*fRmax*fRmax;
|
||||
G4double rrr = fRmin*fRmin*fRmin;
|
||||
fCubicVolume = fDPhi*(cosSTheta - cosETheta)*(RRR - rrr)/3.;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
@@ -2759,14 +2760,16 @@ G4double G4Sphere::GetCubicVolume()
|
||||
|
||||
G4double G4Sphere::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0.)
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&sphereMutex);
|
||||
G4double RR = fRmax*fRmax;
|
||||
G4double rr = fRmin*fRmin;
|
||||
fSurfaceArea = fDPhi*(RR + rr)*(cosSTheta - cosETheta);
|
||||
if (!fFullPhiSphere) fSurfaceArea += fDTheta*(RR - rr);
|
||||
if (fSTheta > 0) fSurfaceArea += 0.5*fDPhi*(RR - rr)*sinSTheta;
|
||||
if (eTheta < CLHEP::pi) fSurfaceArea += 0.5*fDPhi*(RR - rr)*sinETheta;
|
||||
if (!fFullPhiSphere) { fSurfaceArea += fDTheta*(RR - rr); }
|
||||
if (fSTheta > 0) { fSurfaceArea += 0.5*fDPhi*(RR - rr)*sinSTheta; }
|
||||
if (eTheta < CLHEP::pi) { fSurfaceArea += 0.5*fDPhi*(RR - rr)*sinETheta; }
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
@@ -2802,7 +2805,7 @@ G4ThreeVector G4Sphere::GetPointOnSurface() const
|
||||
G4double phi = fDPhi*v + fSPhi;
|
||||
return { r*rho*std::cos(phi), r*rho*std::sin(phi), r*z };
|
||||
}
|
||||
else if (select < aInner + aOuter + aPhi) // cut in phi
|
||||
if (select < aInner + aOuter + aPhi) // cut in phi
|
||||
{
|
||||
G4double phi = (select < aInner + aOuter + 0.5*aPhi) ? fSPhi : fSPhi + fDPhi;
|
||||
G4double r = std::sqrt((RR - rr)*u + rr);
|
||||
@@ -2811,15 +2814,15 @@ G4ThreeVector G4Sphere::GetPointOnSurface() const
|
||||
G4double rho = std::sin(theta);
|
||||
return { r*rho*std::cos(phi), r*rho*std::sin(phi), r*z };
|
||||
}
|
||||
else // cut in theta
|
||||
{
|
||||
G4double theta = (select < aTotal - aETheta) ? fSTheta : fSTheta + fDTheta;
|
||||
G4double r = std::sqrt((RR - rr)*u + rr);
|
||||
G4double phi = fDPhi*v + fSPhi;
|
||||
G4double z = std::cos(theta);
|
||||
G4double rho = std::sin(theta);
|
||||
return { r*rho*std::cos(phi), r*rho*std::sin(phi), r*z };
|
||||
}
|
||||
|
||||
// cut in theta
|
||||
|
||||
G4double theta = (select < aTotal - aETheta) ? fSTheta : fSTheta + fDTheta;
|
||||
G4double r = std::sqrt((RR - rr)*u + rr);
|
||||
G4double phi = fDPhi*v + fSPhi;
|
||||
G4double z = std::cos(theta);
|
||||
G4double rho = std::sin(theta);
|
||||
return { r*rho*std::cos(phi), r*rho*std::sin(phi), r*z };
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -52,6 +52,12 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex torusMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -175,18 +181,6 @@ G4Torus::G4Torus( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Torus::~G4Torus() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Torus::G4Torus(const G4Torus&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -485,28 +479,28 @@ G4bool G4Torus::CalculateExtent( const EAxis pAxis,
|
||||
|
||||
// define vectors for bounding envelope
|
||||
G4ThreeVectorList pols[NDISK+1];
|
||||
for (auto & pol : pols) pol.resize(4);
|
||||
for (auto & pol : pols) { pol.resize(4); }
|
||||
|
||||
std::vector<const G4ThreeVectorList *> polygons;
|
||||
polygons.resize(NDISK+1);
|
||||
for (G4int k=0; k<NDISK+1; ++k) polygons[k] = &pols[k];
|
||||
for (G4int k=0; k<NDISK+1; ++k) { polygons[k] = &pols[k]; }
|
||||
|
||||
// set internal and external reference circles
|
||||
G4TwoVector rzmin[NDISK];
|
||||
G4TwoVector rzmax[NDISK];
|
||||
|
||||
if ((rtor-rmin*sinHalfDisk)/cosHalf > (rtor+rmin*sinHalfDisk)) rmin = 0;
|
||||
if ((rtor-rmin*sinHalfDisk)/cosHalf > (rtor+rmin*sinHalfDisk)) { rmin = 0; }
|
||||
rmax /= cosHalfDisk;
|
||||
G4double sinCurDisk = sinHalfDisk;
|
||||
G4double cosCurDisk = cosHalfDisk;
|
||||
for (G4int k=0; k<NDISK; ++k)
|
||||
{
|
||||
G4double rmincur = rtor + rmin*cosCurDisk;
|
||||
if (cosCurDisk < 0 && rmin > 0) rmincur /= cosHalf;
|
||||
if (cosCurDisk < 0 && rmin > 0) { rmincur /= cosHalf; }
|
||||
rzmin[k].set(rmincur,rmin*sinCurDisk);
|
||||
|
||||
G4double rmaxcur = rtor + rmax*cosCurDisk;
|
||||
if (cosCurDisk > 0) rmaxcur /= cosHalf;
|
||||
if (cosCurDisk > 0) { rmaxcur /= cosHalf; }
|
||||
rzmax[k].set(rmaxcur,rmax*sinCurDisk);
|
||||
|
||||
G4double sinTmpDisk = sinCurDisk;
|
||||
@@ -558,10 +552,13 @@ G4bool G4Torus::CalculateExtent( const EAxis pAxis,
|
||||
// set bounding envelope for current slice and adjust extent
|
||||
G4double emin,emax;
|
||||
G4BoundingEnvelope benv(bmin,bmax,polygons);
|
||||
if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) continue;
|
||||
if (emin < pMin) pMin = emin;
|
||||
if (emax > pMax) pMax = emax;
|
||||
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
|
||||
if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (emin < pMin) { pMin = emin; }
|
||||
if (emax > pMax) { pMax = emax; }
|
||||
if (eminlim > pMin && emaxlim < pMax) { break; } // max possible extent
|
||||
}
|
||||
return (pMin < pMax);
|
||||
}
|
||||
@@ -581,8 +578,7 @@ EInside G4Torus::Inside( const G4ThreeVector& p ) const
|
||||
r = std::hypot(p.x(),p.y());
|
||||
pt2 = p.z()*p.z() + (r-fRtor)*(r-fRtor);
|
||||
|
||||
if (fRmin != 0.0) tolRMin = fRmin + fRminTolerance ;
|
||||
else tolRMin = 0 ;
|
||||
(fRmin != 0.0) ? (tolRMin = fRmin + fRminTolerance) : (tolRMin = 0);
|
||||
|
||||
tolRMax = fRmax - fRmaxTolerance;
|
||||
|
||||
@@ -701,7 +697,7 @@ G4ThreeVector G4Torus::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
pt = std::hypot(p.z(),rho-fRtor);
|
||||
|
||||
G4double distRMax = std::fabs(pt - fRmax);
|
||||
if(fRmin != 0.0) distRMin = std::fabs(pt - fRmin);
|
||||
if(fRmin != 0.0) { distRMin = std::fabs(pt - fRmin); }
|
||||
|
||||
if( rho > delta && pt != 0.0 )
|
||||
{
|
||||
@@ -861,7 +857,7 @@ G4ThreeVector G4Torus::ApproxSurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
if (distSPhi < distEPhi) // Find new minimum
|
||||
{
|
||||
if (distSPhi<distMin) side = kNSPhi ;
|
||||
if (distSPhi<distMin) { side = kNSPhi ; }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -934,9 +930,9 @@ G4double G4Torus::DistanceToIn( const G4ThreeVector& p,
|
||||
G4double distX = std::abs(p.x()) - boxDx;
|
||||
G4double distY = std::abs(p.y()) - boxDy;
|
||||
G4double distZ = std::abs(p.z()) - boxDz;
|
||||
if (distX >= -halfCarTolerance && p.x()*v.x() >= 0) return kInfinity;
|
||||
if (distY >= -halfCarTolerance && p.y()*v.y() >= 0) return kInfinity;
|
||||
if (distZ >= -halfCarTolerance && p.z()*v.z() >= 0) return kInfinity;
|
||||
if (distX >= -halfCarTolerance && p.x()*v.x() >= 0) { return kInfinity; }
|
||||
if (distY >= -halfCarTolerance && p.y()*v.y() >= 0) { return kInfinity; }
|
||||
if (distZ >= -halfCarTolerance && p.z()*v.z() >= 0) { return kInfinity; }
|
||||
|
||||
// Calculate safety distance to bounding box
|
||||
// If point is too far, move it closer and calculate distance
|
||||
@@ -1616,7 +1612,7 @@ G4ThreeVector G4Torus::GetPointOnSurface() const
|
||||
ds = fRtor + r*std::cos(v);
|
||||
for (auto i = 0; i < 10; ++i)
|
||||
{
|
||||
if ((fRtor + r)*G4QuickRand() < ds) break;
|
||||
if ((fRtor + r)*G4QuickRand() < ds) { break; }
|
||||
v = twopi*G4QuickRand();
|
||||
ds = fRtor + r*std::cos(v);
|
||||
}
|
||||
@@ -1624,6 +1620,40 @@ G4ThreeVector G4Torus::GetPointOnSurface() const
|
||||
return { ds*std::cos(phi), ds*std::sin(phi), r*std::sin(v) };
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetCubicVolume
|
||||
|
||||
G4double G4Torus::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&torusMutex);
|
||||
fCubicVolume = fDPhi*CLHEP::pi*fRtor*(fRmax*fRmax-fRmin*fRmin);
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetSurfaceArea
|
||||
|
||||
G4double G4Torus::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&torusMutex);
|
||||
fSurfaceArea = fDPhi*CLHEP::twopi*fRtor*(fRmax+fRmin);
|
||||
if(fDPhi < CLHEP::twopi)
|
||||
{
|
||||
fSurfaceArea = fSurfaceArea + CLHEP::twopi*(fRmax*fRmax-fRmin*fRmin);
|
||||
}
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Visualisation Functions
|
||||
|
||||
@@ -49,6 +49,12 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex trapMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -225,12 +231,6 @@ G4Trap::G4Trap( __void__& a )
|
||||
MakePlanes();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Trap::~G4Trap() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
@@ -367,7 +367,7 @@ void G4Trap::MakePlanes(const G4ThreeVector pt[8])
|
||||
pt[iface[i][1]],
|
||||
pt[iface[i][2]],
|
||||
pt[iface[i][3]],
|
||||
fPlanes[i])) continue;
|
||||
fPlanes[i])) { continue; }
|
||||
|
||||
// Non planar side face
|
||||
G4ThreeVector normal(fPlanes[i].a,fPlanes[i].b,fPlanes[i].c);
|
||||
@@ -375,7 +375,7 @@ void G4Trap::MakePlanes(const G4ThreeVector pt[8])
|
||||
for (G4int k=0; k<4; ++k)
|
||||
{
|
||||
G4double dist = normal.dot(pt[iface[i][k]]) + fPlanes[i].d;
|
||||
if (std::abs(dist) > std::abs(dmax)) dmax = dist;
|
||||
if (std::abs(dist) > std::abs(dmax)) { dmax = dist; }
|
||||
}
|
||||
std::ostringstream message;
|
||||
message << "Side face " << side[i] << " is not planar for solid: "
|
||||
@@ -404,9 +404,9 @@ G4bool G4Trap::MakePlane( const G4ThreeVector& p1,
|
||||
TrapSidePlane& plane )
|
||||
{
|
||||
G4ThreeVector normal = ((p4 - p2).cross(p3 - p1)).unit();
|
||||
if (std::abs(normal.x()) < DBL_EPSILON) normal.setX(0);
|
||||
if (std::abs(normal.y()) < DBL_EPSILON) normal.setY(0);
|
||||
if (std::abs(normal.z()) < DBL_EPSILON) normal.setZ(0);
|
||||
if (std::abs(normal.x()) < DBL_EPSILON) { normal.setX(0); }
|
||||
if (std::abs(normal.y()) < DBL_EPSILON) { normal.setY(0); }
|
||||
if (std::abs(normal.z()) < DBL_EPSILON) { normal.setZ(0); }
|
||||
normal = normal.unit();
|
||||
|
||||
G4ThreeVector centre = (p1 + p2 + p3 + p4)*0.25;
|
||||
@@ -479,55 +479,6 @@ void G4Trap::SetCachedValues()
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Trap::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4ThreeVector pt[8];
|
||||
GetVertices(pt);
|
||||
|
||||
G4double dz = pt[4].z() - pt[0].z();
|
||||
G4double dy1 = pt[2].y() - pt[0].y();
|
||||
G4double dx1 = pt[1].x() - pt[0].x();
|
||||
G4double dx2 = pt[3].x() - pt[2].x();
|
||||
G4double dy2 = pt[6].y() - pt[4].y();
|
||||
G4double dx3 = pt[5].x() - pt[4].x();
|
||||
G4double dx4 = pt[7].x() - pt[6].x();
|
||||
|
||||
fCubicVolume = ((dx1 + dx2 + dx3 + dx4)*(dy1 + dy2) +
|
||||
(dx4 + dx3 - dx2 - dx1)*(dy2 - dy1)/3)*dz*0.125;
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Trap::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4ThreeVector pt[8];
|
||||
G4int iface [6][4] =
|
||||
{ {0,1,3,2}, {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3}, {4,6,7,5} };
|
||||
|
||||
GetVertices(pt);
|
||||
for (const auto & i : iface)
|
||||
{
|
||||
fSurfaceArea += G4GeomTools::QuadAreaNormal(pt[i[0]],
|
||||
pt[i[1]],
|
||||
pt[i[2]],
|
||||
pt[i[3]]).mag();
|
||||
}
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dispatch to parameterisation for replication mechanism dimension
|
||||
@@ -554,11 +505,11 @@ void G4Trap::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
|
||||
for (const auto & i : pt)
|
||||
{
|
||||
G4double x = i.x();
|
||||
if (x < xmin) xmin = x;
|
||||
if (x > xmax) xmax = x;
|
||||
if (x < xmin) { xmin = x; }
|
||||
if (x > xmax) { xmax = x; }
|
||||
G4double y = i.y();
|
||||
if (y < ymin) ymin = y;
|
||||
if (y > ymax) ymax = y;
|
||||
if (y < ymin) { ymin = y; }
|
||||
if (y > ymax) { ymax = y; }
|
||||
}
|
||||
|
||||
G4double dz = GetZHalfLength();
|
||||
@@ -709,7 +660,7 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
for (G4int i=0; i<2; ++i)
|
||||
{
|
||||
G4double dy = fPlanes[i].b*p.y() + fPlanes[i].c*p.z() + fPlanes[i].d;
|
||||
if (std::abs(dy) > halfCarTolerance) continue;
|
||||
if (std::abs(dy) > halfCarTolerance) { continue; }
|
||||
ny = fPlanes[i].b;
|
||||
nz += fPlanes[i].c;
|
||||
break;
|
||||
@@ -718,7 +669,7 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
{
|
||||
G4double dx = fPlanes[i].a*p.x() +
|
||||
fPlanes[i].b*p.y() + fPlanes[i].c*p.z() + fPlanes[i].d;
|
||||
if (std::abs(dx) > halfCarTolerance) continue;
|
||||
if (std::abs(dx) > halfCarTolerance) { continue; }
|
||||
nx = fPlanes[i].a;
|
||||
ny += fPlanes[i].b;
|
||||
nz += fPlanes[i].c;
|
||||
@@ -734,7 +685,7 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
{
|
||||
G4double dx = fPlanes[i].a*p.x() +
|
||||
fPlanes[i].b*p.y() + fPlanes[i].c*p.z() + fPlanes[i].d;
|
||||
if (std::abs(dx) > halfCarTolerance) continue;
|
||||
if (std::abs(dx) > halfCarTolerance) { continue; }
|
||||
nx = fPlanes[i].a;
|
||||
ny += fPlanes[i].b;
|
||||
nz += fPlanes[i].c;
|
||||
@@ -748,7 +699,7 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
ny = std::copysign(G4double(std::abs(dy) <= halfCarTolerance), p.y());
|
||||
G4double dx = fPlanes[3].a*std::abs(p.x()) +
|
||||
fPlanes[3].c*p.z() + fPlanes[3].d;
|
||||
G4double k = std::abs(dx) <= halfCarTolerance;
|
||||
G4double k = static_cast<G4double>(std::abs(dx) <= halfCarTolerance);
|
||||
nx = std::copysign(k, p.x())*fPlanes[3].a;
|
||||
nz += k*fPlanes[3].c;
|
||||
break;
|
||||
@@ -759,7 +710,7 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
ny = std::copysign(G4double(std::abs(dy) <= halfCarTolerance), p.y());
|
||||
G4double dx = fPlanes[3].a*std::abs(p.x()) +
|
||||
fPlanes[3].b*p.y() + fPlanes[3].d;
|
||||
G4double k = std::abs(dx) <= halfCarTolerance;
|
||||
G4double k = static_cast<G4double>(std::abs(dx) <= halfCarTolerance);
|
||||
nx = std::copysign(k, p.x())*fPlanes[3].a;
|
||||
ny += k*fPlanes[3].b;
|
||||
break;
|
||||
@@ -769,28 +720,33 @@ G4ThreeVector G4Trap::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
// Return normal
|
||||
//
|
||||
G4double mag2 = nx*nx + ny*ny + nz*nz;
|
||||
if (mag2 == 1) return { nx,ny,nz };
|
||||
else if (mag2 != 0) return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
else
|
||||
if (mag2 == 1)
|
||||
{
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4long oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Trap::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
return ApproxSurfaceNormal(p);
|
||||
return { nx,ny,nz };
|
||||
}
|
||||
if (mag2 != 0)
|
||||
{
|
||||
return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
}
|
||||
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4long oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Trap::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
|
||||
return ApproxSurfaceNormal(p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -812,9 +768,11 @@ G4ThreeVector G4Trap::ApproxSurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
G4double distz = std::abs(p.z()) - fDz;
|
||||
if (dist > distz)
|
||||
{
|
||||
return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
|
||||
else
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -828,7 +786,9 @@ G4double G4Trap::DistanceToIn(const G4ThreeVector& p,
|
||||
// Z intersections
|
||||
//
|
||||
if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
|
||||
G4double dz = (invz < 0) ? fDz : -fDz;
|
||||
G4double tzmin = (p.z() + dz)*invz;
|
||||
@@ -844,14 +804,14 @@ G4double G4Trap::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dist = fPlanes[i].b*p.y() + fPlanes[i].c*p.z() + fPlanes[i].d;
|
||||
if (dist >= -halfCarTolerance)
|
||||
{
|
||||
if (cosa >= 0) return kInfinity;
|
||||
if (cosa >= 0) { return kInfinity; }
|
||||
G4double tmp = -dist/cosa;
|
||||
if (tymin < tmp) tymin = tmp;
|
||||
if (tymin < tmp) { tymin = tmp; }
|
||||
}
|
||||
else if (cosa > 0)
|
||||
{
|
||||
G4double tmp = -dist/cosa;
|
||||
if (tymax > tmp) tymax = tmp;
|
||||
if (tymax > tmp) { tymax = tmp; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,14 +825,14 @@ G4double G4Trap::DistanceToIn(const G4ThreeVector& p,
|
||||
fPlanes[i].d;
|
||||
if (dist >= -halfCarTolerance)
|
||||
{
|
||||
if (cosa >= 0) return kInfinity;
|
||||
if (cosa >= 0) { return kInfinity; }
|
||||
G4double tmp = -dist/cosa;
|
||||
if (txmin < tmp) txmin = tmp;
|
||||
if (txmin < tmp) { txmin = tmp; }
|
||||
}
|
||||
else if (cosa > 0)
|
||||
{
|
||||
G4double tmp = -dist/cosa;
|
||||
if (txmax > tmp) txmax = tmp;
|
||||
if (txmax > tmp) { txmax = tmp; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -881,7 +841,8 @@ G4double G4Trap::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double tmin = std::max(std::max(txmin,tymin),tzmin);
|
||||
G4double tmax = std::min(std::min(txmax,tymax),tzmax);
|
||||
|
||||
if (tmax <= tmin + halfCarTolerance) return kInfinity; // touch or no hit
|
||||
if (tmax <= tmin + halfCarTolerance) { return kInfinity; } // touch or no hit
|
||||
|
||||
return (tmin < halfCarTolerance ) ? 0. : tmin;
|
||||
}
|
||||
|
||||
@@ -1019,9 +980,13 @@ G4double G4Trap::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
|
||||
{
|
||||
*validNorm = true;
|
||||
if (iside < 0)
|
||||
{
|
||||
n->set(0, 0, iside + 3); // (-4+3)=-1, (-2+3)=+1
|
||||
}
|
||||
else
|
||||
{
|
||||
n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c);
|
||||
}
|
||||
}
|
||||
return tmax;
|
||||
}
|
||||
@@ -1208,7 +1173,7 @@ G4ThreeVector G4Trap::GetPointOnSurface() const
|
||||
G4int i2 = iface[k][2];
|
||||
G4int i3 = iface[k][3];
|
||||
G4double s2 = G4GeomTools::TriangleAreaNormal(pt[i2],pt[i1],pt[i3]).mag();
|
||||
if (select > fAreas[k] - s2) i0 = i2;
|
||||
if (select > fAreas[k] - s2) { i0 = i2; }
|
||||
|
||||
// Generate point
|
||||
//
|
||||
@@ -1218,6 +1183,59 @@ G4ThreeVector G4Trap::GetPointOnSurface() const
|
||||
return (1.-u-v)*pt[i0] + u*pt[i1] + v*pt[i3];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Trap::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&trapMutex);
|
||||
G4ThreeVector pt[8];
|
||||
GetVertices(pt);
|
||||
|
||||
G4double dz = pt[4].z() - pt[0].z();
|
||||
G4double dy1 = pt[2].y() - pt[0].y();
|
||||
G4double dx1 = pt[1].x() - pt[0].x();
|
||||
G4double dx2 = pt[3].x() - pt[2].x();
|
||||
G4double dy2 = pt[6].y() - pt[4].y();
|
||||
G4double dx3 = pt[5].x() - pt[4].x();
|
||||
G4double dx4 = pt[7].x() - pt[6].x();
|
||||
|
||||
fCubicVolume = ((dx1 + dx2 + dx3 + dx4)*(dy1 + dy2) +
|
||||
(dx4 + dx3 - dx2 - dx1)*(dy2 - dy1)/3)*dz*0.125;
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Trap::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&trapMutex);
|
||||
G4ThreeVector pt[8];
|
||||
G4int iface [6][4] =
|
||||
{ {0,1,3,2}, {0,4,5,1}, {2,3,7,6}, {0,2,6,4}, {1,5,7,3}, {4,6,7,5} };
|
||||
|
||||
GetVertices(pt);
|
||||
for (const auto & i : iface)
|
||||
{
|
||||
fSurfaceArea += G4GeomTools::QuadAreaNormal(pt[i[0]],
|
||||
pt[i[1]],
|
||||
pt[i[2]],
|
||||
pt[i[3]]).mag();
|
||||
}
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
|
||||
@@ -44,9 +44,15 @@
|
||||
#include "G4VPVParameterisation.hh"
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex trdMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constructor - set & check half widths
|
||||
@@ -74,12 +80,6 @@ G4Trd::G4Trd( __void__& a )
|
||||
MakePlanes();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Trd::~G4Trd() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
@@ -199,34 +199,6 @@ void G4Trd::MakePlanes()
|
||||
fPlanes[3].d = fPlanes[2].d;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Trd::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0.)
|
||||
{
|
||||
fCubicVolume = 2*fDz*( (fDx1+fDx2)*(fDy1+fDy2) +
|
||||
(fDx2-fDx1)*(fDy2-fDy1)/3 );
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Trd::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0.)
|
||||
{
|
||||
fSurfaceArea =
|
||||
4*(fDx1*fDy1 + fDx2*fDy2) + 2*(fDx1+fDx2)*fHx + 2*(fDy1+fDy2)*fHy;
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dispatch to parameterisation for replication mechanism dimension
|
||||
@@ -394,28 +366,32 @@ G4ThreeVector G4Trd::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
// Return normal
|
||||
//
|
||||
if (nsurf == 1) return {nx,ny,nz};
|
||||
else if (nsurf != 0) return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
else
|
||||
if (nsurf == 1)
|
||||
{
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4long oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Trd::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
return ApproxSurfaceNormal(p);
|
||||
return {nx,ny,nz};
|
||||
}
|
||||
if (nsurf != 0)
|
||||
{
|
||||
return G4ThreeVector(nx,ny,nz).unit(); // edge or corner
|
||||
}
|
||||
|
||||
// Point is not on the surface
|
||||
//
|
||||
#ifdef G4CSGDEBUG
|
||||
std::ostringstream message;
|
||||
G4long oldprc = message.precision(16);
|
||||
message << "Point p is not on surface (!?) of solid: "
|
||||
<< GetName() << G4endl;
|
||||
message << "Position:\n";
|
||||
message << " p.x() = " << p.x()/mm << " mm\n";
|
||||
message << " p.y() = " << p.y()/mm << " mm\n";
|
||||
message << " p.z() = " << p.z()/mm << " mm";
|
||||
G4cout.precision(oldprc) ;
|
||||
G4Exception("G4Trd::SurfaceNormal(p)", "GeomSolids1002",
|
||||
JustWarning, message );
|
||||
DumpInfo();
|
||||
#endif
|
||||
return ApproxSurfaceNormal(p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -437,9 +413,11 @@ G4ThreeVector G4Trd::ApproxSurfaceNormal( const G4ThreeVector& p ) const
|
||||
|
||||
G4double distz = std::abs(p.z()) - fDz;
|
||||
if (dist > distz)
|
||||
{
|
||||
return { fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c };
|
||||
else
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
return { 0, 0, (G4double)((p.z() < 0) ? -1 : 1) };
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -453,7 +431,9 @@ G4double G4Trd::DistanceToIn(const G4ThreeVector& p,
|
||||
// Z intersections
|
||||
//
|
||||
if ((std::abs(p.z()) - fDz) >= -halfCarTolerance && p.z()*v.z() >= 0)
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
G4double invz = (-v.z() == 0) ? DBL_MAX : -1./v.z();
|
||||
G4double dz = (invz < 0) ? fDz : -fDz;
|
||||
G4double tzmin = (p.z() + dz)*invz;
|
||||
@@ -468,14 +448,14 @@ G4double G4Trd::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis0 = yd + yc;
|
||||
if (dis0 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos0 >= 0) return kInfinity;
|
||||
if (cos0 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis0/cos0;
|
||||
if (tmin0 < tmp) tmin0 = tmp;
|
||||
if (tmin0 < tmp) { tmin0 = tmp; }
|
||||
}
|
||||
else if (cos0 > 0)
|
||||
{
|
||||
G4double tmp = -dis0/cos0;
|
||||
if (tmax0 > tmp) tmax0 = tmp;
|
||||
if (tmax0 > tmp) { tmax0 = tmp; }
|
||||
}
|
||||
|
||||
G4double tmin1 = tmin0, tmax1 = tmax0;
|
||||
@@ -483,14 +463,14 @@ G4double G4Trd::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis1 = yd - yc;
|
||||
if (dis1 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos1 >= 0) return kInfinity;
|
||||
if (cos1 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis1/cos1;
|
||||
if (tmin1 < tmp) tmin1 = tmp;
|
||||
if (tmin1 < tmp) { tmin1 = tmp; }
|
||||
}
|
||||
else if (cos1 > 0)
|
||||
{
|
||||
G4double tmp = -dis1/cos1;
|
||||
if (tmax1 > tmp) tmax1 = tmp;
|
||||
if (tmax1 > tmp) { tmax1 = tmp; }
|
||||
}
|
||||
|
||||
// X intersections
|
||||
@@ -502,14 +482,14 @@ G4double G4Trd::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis2 = xd + xc;
|
||||
if (dis2 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos2 >= 0) return kInfinity;
|
||||
if (cos2 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis2/cos2;
|
||||
if (tmin2 < tmp) tmin2 = tmp;
|
||||
if (tmin2 < tmp) { tmin2 = tmp; }
|
||||
}
|
||||
else if (cos2 > 0)
|
||||
{
|
||||
G4double tmp = -dis2/cos2;
|
||||
if (tmax2 > tmp) tmax2 = tmp;
|
||||
if (tmax2 > tmp) { tmax2 = tmp; }
|
||||
}
|
||||
|
||||
G4double tmin3 = tmin2, tmax3 = tmax2;
|
||||
@@ -517,20 +497,21 @@ G4double G4Trd::DistanceToIn(const G4ThreeVector& p,
|
||||
G4double dis3 = xd - xc;
|
||||
if (dis3 >= -halfCarTolerance)
|
||||
{
|
||||
if (cos3 >= 0) return kInfinity;
|
||||
if (cos3 >= 0) { return kInfinity; }
|
||||
G4double tmp = -dis3/cos3;
|
||||
if (tmin3 < tmp) tmin3 = tmp;
|
||||
if (tmin3 < tmp) { tmin3 = tmp; }
|
||||
}
|
||||
else if (cos3 > 0)
|
||||
{
|
||||
G4double tmp = -dis3/cos3;
|
||||
if (tmax3 > tmp) tmax3 = tmp;
|
||||
if (tmax3 > tmp) { tmax3 = tmp; }
|
||||
}
|
||||
|
||||
// Find distance
|
||||
//
|
||||
G4double tmin = tmin3, tmax = tmax3;
|
||||
if (tmax <= tmin + halfCarTolerance) return kInfinity; // touch or no hit
|
||||
if (tmax <= tmin + halfCarTolerance) { return kInfinity; // touch or no hit
|
||||
}
|
||||
return (tmin < halfCarTolerance ) ? 0. : tmin;
|
||||
}
|
||||
|
||||
@@ -628,9 +609,13 @@ G4double G4Trd::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v,
|
||||
{
|
||||
*validNorm = true;
|
||||
if (iside < 0)
|
||||
{
|
||||
n->set(0, 0, iside + 3); // (-4+3)=-1, (-2+3)=+1
|
||||
}
|
||||
else
|
||||
{
|
||||
n->set(fPlanes[iside].a, fPlanes[iside].b, fPlanes[iside].c);
|
||||
}
|
||||
}
|
||||
return tmax;
|
||||
}
|
||||
@@ -746,7 +731,7 @@ G4ThreeVector G4Trd::GetPointOnSurface() const
|
||||
else if (select < sbase + 2.*sxz)
|
||||
{
|
||||
G4double ysign = (select < sbase + sxz) ? 1. : -1.;
|
||||
if (ysign < 0.) select -= sxz;
|
||||
if (ysign < 0.) { select -= sxz; }
|
||||
if (u + v > 1.)
|
||||
{
|
||||
u = 1. - u;
|
||||
@@ -762,7 +747,7 @@ G4ThreeVector G4Trd::GetPointOnSurface() const
|
||||
else
|
||||
{
|
||||
G4double xsign = (select < sbase + 2.*sxz + syz) ? 1. : -1.;
|
||||
if (xsign < 0.) select -= syz;
|
||||
if (xsign < 0.) { select -= syz; }
|
||||
if (u + v > 1.)
|
||||
{
|
||||
u = 1. - u;
|
||||
@@ -778,6 +763,36 @@ G4ThreeVector G4Trd::GetPointOnSurface() const
|
||||
return p;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get volume
|
||||
|
||||
G4double G4Trd::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&trdMutex);
|
||||
fCubicVolume = 2*fDz*((fDx1+fDx2)*(fDy1+fDy2) + (fDx2-fDx1)*(fDy2-fDy1)/3);
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get surface area
|
||||
|
||||
G4double G4Trd::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&trdMutex);
|
||||
fSurfaceArea = 4*(fDx1*fDy1+fDx2*fDy2)+2*(fDx1+fDx2)*fHx+2*(fDy1+fDy2)*fHy;
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
|
||||
@@ -47,6 +47,12 @@
|
||||
|
||||
#include "G4VGraphicsScene.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4Mutex tubsMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
@@ -110,18 +116,6 @@ G4Tubs::G4Tubs( __void__& a )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4Tubs::~G4Tubs() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
G4Tubs::G4Tubs(const G4Tubs&) = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Assignment operator
|
||||
@@ -289,7 +283,10 @@ G4bool G4Tubs::CalculateExtent( const EAxis pAxis,
|
||||
|
||||
// set quadrilaterals
|
||||
G4ThreeVectorList pols[NSTEPS+2];
|
||||
for (G4int k=0; k<ksteps+2; ++k) pols[k].resize(4);
|
||||
for (G4int k=0; k<ksteps+2; ++k)
|
||||
{
|
||||
pols[k].resize(4);
|
||||
}
|
||||
pols[0][0].set(rmin*cosStart,rmin*sinStart, dz);
|
||||
pols[0][1].set(rmin*cosStart,rmin*sinStart,-dz);
|
||||
pols[0][2].set(rmax*cosStart,rmax*sinStart,-dz);
|
||||
@@ -313,7 +310,10 @@ G4bool G4Tubs::CalculateExtent( const EAxis pAxis,
|
||||
// set envelope and calculate extent
|
||||
std::vector<const G4ThreeVectorList *> polygons;
|
||||
polygons.resize(ksteps+2);
|
||||
for (G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
|
||||
for (G4int k=0; k<ksteps+2; ++k)
|
||||
{
|
||||
polygons[k] = &pols[k];
|
||||
}
|
||||
G4BoundingEnvelope benv(bmin,bmax,polygons);
|
||||
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
|
||||
}
|
||||
@@ -834,12 +834,12 @@ G4double G4Tubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return sd ;
|
||||
}
|
||||
else
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
|
||||
if (cosPsi >= cosHDPhiIT)
|
||||
{
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
|
||||
if (cosPsi >= cosHDPhiIT) { return sd ; }
|
||||
return sd ;
|
||||
}
|
||||
} // end if std::fabs(zi)
|
||||
} // end if (sd>=0)
|
||||
@@ -872,22 +872,18 @@ G4double G4Tubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
snxt = c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
snxt = c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
|
||||
return kInfinity;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -903,22 +899,18 @@ G4double G4Tubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
c = c/t1 ;
|
||||
d = b*b-c;
|
||||
if ( d>=0.0 )
|
||||
{
|
||||
snxt= c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kInfinity;
|
||||
}
|
||||
snxt= c/(-b+std::sqrt(d)); // using safe solution
|
||||
// for quadratic equation
|
||||
if ( snxt < halfCarTolerance ) { snxt=0; }
|
||||
return snxt ;
|
||||
}
|
||||
|
||||
return kInfinity;
|
||||
} // end if (!fPhiFullTube)
|
||||
} // end if (t3>tolIRMin2)
|
||||
} // end if (Inside Outer Radius)
|
||||
@@ -951,18 +943,16 @@ G4double G4Tubs::DistanceToIn( const G4ThreeVector& p,
|
||||
{
|
||||
return sd ;
|
||||
}
|
||||
else
|
||||
{
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)*fInvRmin;
|
||||
if (cosPsi >= cosHDPhiIT)
|
||||
{
|
||||
// Good inner radius isect
|
||||
// - but earlier phi isect still possible
|
||||
|
||||
snxt = sd ;
|
||||
}
|
||||
xi = p.x() + sd*v.x() ;
|
||||
yi = p.y() + sd*v.y() ;
|
||||
cosPsi = (xi*cosCPhi + yi*sinCPhi)*fInvRmin;
|
||||
if (cosPsi >= cosHDPhiIT)
|
||||
{
|
||||
// Good inner radius isect
|
||||
// - but earlier phi isect still possible
|
||||
|
||||
snxt = sd ;
|
||||
}
|
||||
} // end if std::fabs(zi)
|
||||
} // end if (sd>=0)
|
||||
@@ -1734,6 +1724,40 @@ G4ThreeVector G4Tubs::GetPointOnSurface() const
|
||||
return {0., 0., 0.};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetCubicVolume
|
||||
|
||||
G4double G4Tubs::GetCubicVolume()
|
||||
{
|
||||
if (fCubicVolume == 0)
|
||||
{
|
||||
G4AutoLock l(&tubsMutex);
|
||||
fCubicVolume = fDPhi*fDz*(fRMax*fRMax-fRMin*fRMin);
|
||||
l.unlock();
|
||||
}
|
||||
return fCubicVolume;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetSurfaceArea
|
||||
|
||||
G4double G4Tubs::GetSurfaceArea()
|
||||
{
|
||||
if (fSurfaceArea == 0)
|
||||
{
|
||||
G4AutoLock l(&tubsMutex);
|
||||
fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
|
||||
if (!fPhiFullTube)
|
||||
{
|
||||
fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);
|
||||
}
|
||||
l.unlock();
|
||||
}
|
||||
return fSurfaceArea;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Methods for visualisation
|
||||
|
||||
@@ -52,12 +52,6 @@ G4UBox::G4UBox(const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UBox::~G4UBox() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -54,12 +54,6 @@ G4UCons::G4UCons( const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UCons::~G4UCons() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -57,12 +57,6 @@ G4UCutTubs::G4UCutTubs( const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UCutTubs::~G4UCutTubs() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -53,12 +53,6 @@ G4UOrb::G4UOrb( const G4String& pName, G4double pRmax )
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UOrb::~G4UOrb() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -119,12 +119,6 @@ G4UPara::G4UPara( const G4String& pName,
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UPara::~G4UPara() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -53,12 +53,6 @@ G4USphere::G4USphere( const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4USphere::~G4USphere() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -53,12 +53,6 @@ G4UTorus::G4UTorus(const G4String& pName,
|
||||
: Base_t(pName, rmin, rmax, rtor, sphi, dphi)
|
||||
{ }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UTorus::~G4UTorus() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -134,12 +134,6 @@ G4UTrap::G4UTrap( const G4String& pName )
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
G4UTrap::~G4UTrap() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -51,12 +51,6 @@ G4UTrd::G4UTrd(const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
G4UTrd::~G4UTrd() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
@@ -53,12 +53,6 @@ G4UTubs::G4UTubs( const G4String& pName,
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor
|
||||
|
||||
G4UTubs::~G4UTubs() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copy constructor
|
||||
|
||||
Reference in New Issue
Block a user