57 using namespace CLHEP;
67 :
G4VSolid(pName), fRebuildPolyhedron(false), fpPolyhedron(0),
68 fSurfaceArea(0.), fCubicVolume(0.)
71 if( (pDz <= 0.) || (pR2 <= pR1) || (pR1 < 0.) )
73 std::ostringstream message;
74 message <<
"Invalid dimensions. Negative Input Values or R1>=R2 - "
76 G4Exception(
"G4Paraboloid::G4Paraboloid()",
"GeomSolids0002",
78 "Z half-length must be larger than zero or R1>=R2.");
100 :
G4VSolid(a), fRebuildPolyhedron(false), fpPolyhedron(0),
101 fSurfaceArea(0.), fCubicVolume(0.),
102 dz(0.), r1(0.), r2(0.), k1(0.), k2(0.)
120 :
G4VSolid(rhs), fRebuildPolyhedron(false), fpPolyhedron(0),
121 fSurfaceArea(rhs.fSurfaceArea), fCubicVolume(rhs.fCubicVolume),
122 dz(rhs.dz), r1(rhs.r1), r2(rhs.r2), k1(rhs.k1), k2(rhs.k2)
135 if (
this == &rhs) {
return *
this; }
263 G4bool existsAfterClip=
true;
267 G4int noPolygonVertices=0;
277 for(G4ThreeVectorList::iterator it = vertices->begin();
278 it < vertices->end(); it++)
280 if(pMin > (*it)[pAxis]) pMin = (*it)[pAxis];
285 if(pMax < (*it)[pAxis])
296 || pMax < pVoxelLimit.
GetMinExtent(pAxis)) { existsAfterClip =
false; }
302 existsAfterClip =
false;
305 return existsAfterClip;
324 if(
A < 0 &&
sqr(
A) > rhoSurfTimesTol2)
329 if(std::fabs(p.z()) >
dz - 0.5 * kCarTolerance)
341 else if(
A <= 0 ||
sqr(
A) < rhoSurfTimesTol2)
414 if(A < 0 &&
sqr(A) > rhoSurfTimesTol2)
419 if(p.mag2() != 0) { n = p.unit(); }
421 else if(A <= 0 ||
sqr(A) < rhoSurfTimesTol2)
435 std::ostringstream message;
436 message <<
"No normal defined for this point p." <<
G4endl
437 <<
" p = " << 1 /
mm * p <<
" mm";
438 G4Exception(
"G4Paraboloid::SurfaceNormal(p)",
"GeomSolids1002",
453 G4double rho2 = p.perp2(), paraRho2 = std::fabs(
k1 * p.z() +
k2);
457 if(
r2 && p.z() > - tolh +
dz)
464 if(
sqr(p.x() + v.x()*intersection)
465 +
sqr(p.y() + v.y()*intersection) <
sqr(
r2 + 0.5 * kCarTolerance))
467 if(p.z() < tolh +
dz)
470 {
return intersection; }
478 else if(
r1 && p.z() < tolh -
dz)
484 G4double intersection = (-
dz - p.z()) / v.z();
485 if(
sqr(p.x() + v.x()*intersection)
486 +
sqr(p.y() + v.y()*intersection) <
sqr(
r1 + 0.5 * kCarTolerance))
488 if(p.z() > -tolh -
dz)
504 G4double A =
k1 / 2 * v.z() - p.x() * v.x() - p.y() * v.y(),
505 vRho2 = v.perp2(), intersection,
506 B = (
k1 * p.z() +
k2 - rho2) * vRho2;
508 if ( ( (rho2 > paraRho2) && (
sqr(rho2-paraRho2-0.25*tol2) > tol2*paraRho2) )
516 intersection = ((rho2 -
k2)/
k1 - p.z())/v.z();
517 if(intersection < 0) {
return kInfinity; }
518 else if(std::fabs(p.z() + v.z() * intersection) <=
dz)
533 intersection = (A - std::sqrt(B +
sqr(A))) / vRho2;
538 else if(std::fabs(p.z() + intersection * v.z()) <
dz + tolh)
548 else if(
sqr(rho2 - paraRho2 - .25 * tol2) <= tol2 * paraRho2)
560 std::ostringstream message;
567 message <<
"Likely a problem in this function, for solid: " <<
GetName()
570 message <<
" p = " << p * (1/
mm) <<
" mm" <<
G4endl
571 <<
" v = " << v * (1/
mm) <<
" mm";
572 G4Exception(
"G4Paraboloid::DistanceToIn(p,v)",
"GeomSolids1002",
586 if(safz<0) { safz=0; }
589 G4double rho = p.x()*p.x()+p.y()*p.y();
596 if(safr>safz) { safz=safr; }
600 G4double sqprho = std::sqrt(paraRho);
602 if(dRho<0) {
return safz; }
606 if(tmp<0.) {
return safz; }
608 G4double salf = talf/std::sqrt(tmp);
609 safr = std::fabs(dRho*salf);
610 if(safr>safz) { safz=safr; }
625 G4double rho2 = p.perp2(), paraRho2 = std::fabs(
k1 * p.z() +
k2);
626 G4double vRho2 = v.perp2(), intersection;
630 if(calcNorm) { *validNorm =
false; }
640 G4double A =
k1 / 2 * v.z() - p.x() * v.x() - p.y() * v.y();
644 G4double B = (-rho2 + paraRho2) * vRho2;
646 if ( rho2 < paraRho2 &&
sqr(rho2 - paraRho2 - 0.25 * tol2) > tol2 * paraRho2
647 && std::fabs(p.z()) <
dz - kCarTolerance)
658 intersection = (
dz - p.z()) / v.z();
661 if(ip.perp2() <
sqr(
r2 + kCarTolerance))
666 if(
r2 < tolh || ip.perp2() >
sqr(
r2 - tolh))
683 intersection = (-
dz - p.z()) / v.z();
686 if(ip.perp2() <
sqr(
r1 + tolh))
691 if(
r1 < tolh || ip.perp2() >
sqr(
r1 - tolh))
706 intersection = ((rho2 -
k2)/
k1 - p.z())/v.z();
717 else if( ((A <= 0) && (B >=
sqr(A) * (
sqr(vRho2) - 1))) || (A >= 0))
724 B = (
k1 * p.z() +
k2 - rho2)/vRho2;
725 intersection = B/(-A + std::sqrt(B +
sqr(A)));
735 std::ostringstream message;
736 message <<
"There is no intersection between given line and solid!"
740 G4Exception(
"G4Paraboloid::DistanceToOut(p,v,...)",
"GeomSolids1002",
745 else if ( (rho2 < paraRho2 + kCarTolerance
746 ||
sqr(rho2 - paraRho2 - 0.25 * tol2) < tol2 * paraRho2 )
747 && std::fabs(p.z()) <
dz + tolh)
753 if(std::fabs(p.z()) >
dz - tolh)
757 if( ((v.z() > 0) && (p.z() > 0)) || ((v.z() < 0) && (p.z() < 0)) )
778 A = vRho2 * (
sqr(r) -
sqr(p.x()) -
sqr(p.y()));
779 intersection = (-pDotV + std::sqrt(A +
sqr(pDotV))) / vRho2;
787 * intersection, -
k1/2).unit()).unit();
817 intersection = (
dz - p.z()) / v.z();
820 if(ip.perp2() <
sqr(
r2 - tolh))
829 else if(ip.perp2() <
sqr(
r2 + tolh))
845 intersection = (-
dz - p.z()) / v.z();
848 if(ip.perp2() <
sqr(
r1 - tolh))
857 else if(ip.perp2() <
sqr(
r1 + tolh))
872 if(std::fabs(vRho2) > tol2)
875 B = (
k1 * p.z() +
k2 - rho2);
879 intersection = B/(-A + std::sqrt(B +
sqr(A)));
883 if(normal.dot(v) >= 0)
897 intersection = ((rho2 -
k2) /
k1 - p.z()) / v.z();
904 + intersection * v.y(), -
k1 / 2);
914 G4Exception(
"G4Paraboloid::DistanceToOut(p,v,...)",
"GeomSolids1002",
918 G4Exception(
"G4Paraboloid::DistanceToOut(p,v,...)",
"GeomSolids1002",
919 JustWarning,
"There's an error in this functions code.");
940 std::ostringstream message;
941 G4int oldprc = message.precision(16);
942 message <<
"Point p is outside !?" << G4endl
943 <<
"Position:" << G4endl
944 <<
" p.x() = " << p.x()/
mm <<
" mm" << G4endl
945 <<
" p.y() = " << p.y()/
mm <<
" mm" << G4endl
946 <<
" p.z() = " << p.z()/
mm <<
" mm";
947 message.precision(oldprc) ;
948 G4Exception(
"G4Paraboloid::DistanceToOut(p)",
"GeomSolids1002",
954 safeZ =
dz - std::fabs(p.z()) ;
956 tanRMax = (
r2 -
r1)*0.5/
dz ;
957 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
958 pRMax = tanRMax*p.z() + (
r1+
r2)*0.5 ;
959 safeR = (pRMax - rho)/secRMax ;
961 if (safeZ < safeR) { safe = safeZ; }
962 else { safe = safeR; }
991 G4int oldprc = os.precision(16);
992 os <<
"-----------------------------------------------------------\n"
993 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
994 <<
" ===================================================\n"
995 <<
" Solid type: G4Paraboloid\n"
997 <<
" z half-axis: " <<
dz/
mm <<
" mm \n"
998 <<
" radius at -dz: " <<
r1/
mm <<
" mm \n"
999 <<
" radius at dz: " <<
r2/
mm <<
" mm \n"
1000 <<
"-----------------------------------------------------------\n";
1001 os.precision(oldprc);
1033 std::sqrt(z*
k1 +
k2)*std::sin(phi), z);
1039 G4int& noPolygonVertices)
const
1043 G4double meshAnglePhi, cosMeshAnglePhiPer2,
1044 crossAnglePhi, coscrossAnglePhi, sincrossAnglePhi, sAnglePhi,
1045 sRho, dRho, rho, lastRho = 0., swapRho;
1047 G4int crossSectionPhi, noPhiCrossSections, noRhoSections;
1062 meshAnglePhi=twopi/(noPhiCrossSections-1);
1064 sAnglePhi = -meshAnglePhi*0.5*0;
1065 cosMeshAnglePhiPer2 = std::cos(meshAnglePhi / 2.);
1081 dRho = (
r2 -
r1) /
double(noRhoSections - 1);
1087 for (crossSectionPhi=0; crossSectionPhi<noPhiCrossSections;
1090 crossAnglePhi=sAnglePhi+crossSectionPhi*meshAnglePhi;
1091 coscrossAnglePhi=std::cos(crossAnglePhi);
1092 sincrossAnglePhi=std::sin(crossAnglePhi);
1094 for (
int iRho=0; iRho < noRhoSections;
1099 if(iRho == noRhoSections - 1)
1105 rho = iRho * dRho + sRho;
1110 k3 =
k1 / (2*rho + dRho);
1111 k4 = rho - k3 * (
sqr(rho) -
k2) /
k1;
1113 rho += std::sqrt(
k1 * zm +
k2) - zm * k3 - k4;
1116 rho += (1 / cosMeshAnglePhiPer2 - 1) * (iRho * dRho + sRho);
1121 lastRho = rho + dRho;
1126 lastRho = rho + dRho;
1129 rx = coscrossAnglePhi*rho;
1130 ry = sincrossAnglePhi*rho;
1131 rz = (
sqr(iRho * dRho + sRho) -
k2) /
k1;
1136 noPolygonVertices = noRhoSections ;
1141 G4Exception(
"G4Paraboloid::CreateRotatedVertices()",
1143 "Error in allocation of vertices. Out of memory !");
ThreeVector shoot(const G4int Ap, const G4int Af)
static const G4double kInfinity
G4double GetMinYExtent() const
CLHEP::Hep3Vector G4ThreeVector
G4Polyhedron * fpPolyhedron
G4bool IsYLimited() const
G4Paraboloid & operator=(const G4Paraboloid &rhs)
G4bool IsXLimited() const
G4GeometryType GetEntityType() const
virtual void AddSolid(const G4Box &)=0
#define G4MUTEX_INITIALIZER
G4double CalculateSurfaceArea() const
static double normal(HepRandomEngine *eptr)
G4double GetMaxXExtent() const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4double GetMinZExtent() const
G4GLOB_DLL std::ostream G4cout
void DescribeYourselfTo(G4VGraphicsScene &scene) const
std::vector< G4ThreeVector > G4ThreeVectorList
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=G4bool(false), G4bool *validNorm=0, G4ThreeVector *n=0) const
static const G4double A[nN]
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
EInside Inside(const G4ThreeVector &p) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::ostream & StreamInfo(std::ostream &os) const
G4double GetMinXExtent() const
G4double GetMaxZExtent() const
G4ThreeVector GetPointOnSurface() const
G4double GetMaxYExtent() const
G4VSolid & operator=(const G4VSolid &rhs)
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
G4ThreeVectorList * CreateRotatedVertices(const G4AffineTransform &pTransform, G4int &noPolygonVertices) const
G4double GetMaxExtent(const EAxis pAxis) const
G4bool IsZLimited() const
G4Polyhedron * GetPolyhedron() const
G4Paraboloid(const G4String &pName, G4double pDz, G4double pR1, G4double pR2)
G4double GetMinExtent(const EAxis pAxis) const
const G4double kMeshAngleDefault
G4Polyhedron * CreatePolyhedron() const
G4bool fRebuildPolyhedron