62 using namespace CLHEP;
71 :
G4VSolid( name ), fCubicVolume(0.), fSurfaceArea(0.),
72 fRebuildPolyhedron(false), fpPolyhedron(0)
87 :
G4VSolid(a), dx(0.), dy(0.), dz(0.), halfTol(0.),
88 fCubicVolume(0.), fSurfaceArea(0.),
89 fRebuildPolyhedron(false), fpPolyhedron(0)
99 delete fpPolyhedron; fpPolyhedron = 0;
107 :
G4VSolid(rhs), dx(rhs.dx), dy(rhs.dy), dz(rhs.dz), halfTol(rhs.halfTol),
108 fCubicVolume(rhs.fCubicVolume), fSurfaceArea(rhs.fSurfaceArea),
109 fRebuildPolyhedron(false), fpPolyhedron(0)
121 if (
this == &rhs) {
return *
this; }
130 halfTol = rhs.halfTol;
131 fCubicVolume = rhs.fCubicVolume; fSurfaceArea = rhs.fSurfaceArea;
132 fRebuildPolyhedron =
false;
133 delete fpPolyhedron; fpPolyhedron = 0;
167 if (
true)
return bbox.
CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
171 return exist = (pMin < pMax) ?
true :
false;
176 const G4int NSTEPS = 48;
179 G4double sinHalf = std::sin(0.5*ang);
180 G4double cosHalf = std::cos(0.5*ang);
181 G4double sinStep = 2.*sinHalf*cosHalf;
182 G4double cosStep = 1. - 2.*sinHalf*sinHalf;
189 for (
G4int k=0; k<NSTEPS; ++k)
191 baseA[k].set(sx*cosCur,sy*sinCur,-
dz);
192 baseB[k].set(sx*cosCur,sy*sinCur,
dz);
195 sinCur = sinCur*cosStep + cosCur*sinStep;
196 cosCur = cosCur*cosStep - sinTmp*sinStep;
199 std::vector<const G4ThreeVectorList *> polygons(2);
200 polygons[0] = &baseA;
201 polygons[1] = &baseB;
260 if ( (distZ < halfTol ) && ( distR1 <= 1 ) )
265 if( (distR1 <= 1 ) && ( distR2 >= 1 ) )
271 if ( noSurfaces == 0 )
274 G4Exception(
"G4EllipticalTube::SurfaceNormal(p)",
"GeomSolids1002",
277 norm = ApproxSurfaceNormal(p);
279 else if ( noSurfaces == 1 ) { norm = sumnorm; }
280 else { norm = sumnorm.
unit(); }
290 G4EllipticalTube::ApproxSurfaceNormal(
const G4ThreeVector&
p )
const
303 if (distZ*distZ < distR2)
367 yi = p.
y() + q*v.
y();
377 return (sigz < -halfTol) ? q : 0;
379 else if (xi*dy*dy*v.
x() + yi*
dx*
dx*v.
y() >= 0)
406 yi = p.
y() + q*v.
y();
410 return (sigz > -halfTol) ? q : 0;
412 else if (xi*dy*dy*v.
x() + yi*
dx*
dx*v.
y() >= 0)
430 if (std::fabs(p.
z()) <
dz+halfTol) {
431 if (
CheckXY( p.
x(), p.
y(), halfTol ) < 1.0)
436 if (p.
x()*dy*dy*v.
x() + p.
y()*
dx*
dx*v.
y() < 0)
return 0;
486 if (
CheckXY( p.
x(), p.
y(), +halfTol ) < 1.0)
492 if (p.
z() < -
dz-halfTol)
494 else if (p.
z() >
dz+halfTol)
514 G4double tnorm = std::sqrt( tx*tx + ty*ty );
519 G4double distR = ( (p.
x()-xe)*ty - (p.
y()-ye)*tx )/tnorm;
529 return std::sqrt( (p.
z()+
dz)*(p.
z()+
dz) + distR*distR );
531 return std::sqrt( (p.
z()-
dz)*(p.
z()-
dz) + distR*distR );
554 if (calcNorm) { *validNorm =
true; }
568 sBest = -(p.
z()+
dz)/v.
z();
573 if (p.
z() < -
dz+halfTol)
575 if (calcNorm) { *norm = normHere; }
598 if (p.
z() > +
dz-halfTol)
600 if (calcNorm) { *norm = normHere; }
607 if (q < sBest) { sBest = q; nBest = normHere; }
621 std::ostringstream message;
622 G4int oldprc = message.precision(16) ;
623 message <<
"Point p is outside !?" <<
G4endl
625 <<
" p.x() = " << p.
x()/
mm <<
" mm" <<
G4endl
626 <<
" p.y() = " << p.
y()/
mm <<
" mm" <<
G4endl
627 <<
" p.z() = " << p.
z()/
mm <<
" mm" <<
G4endl
629 <<
" v.x() = " << v.
x() <<
G4endl
630 <<
" v.y() = " << v.
y() <<
G4endl
631 <<
" v.z() = " << v.
z() <<
G4endl
632 <<
"Proposed distance :" <<
G4endl
633 <<
" snxt = " << sBest/
mm <<
" mm";
634 message.precision(oldprc) ;
635 G4Exception(
"G4EllipticalTube::DistanceToOut(p,v,...)",
638 if (calcNorm) { *norm = nBest; }
641 else if (q[n-1] > sBest)
643 if (calcNorm) { *norm = nBest; }
660 if (
CheckXY( p.
x(), p.
y(), -halfTol ) > 1.0)
665 if (p.
x()*dy*dy*v.
x() + p.
y()*
dx*
dx*v.
y() > 0)
return 0;
693 if (sBest < halfTol)
return 0;
700 if (radical < +
DBL_MIN)
return 0;
703 if (p.
x() < 0) xi = -xi;
708 radical = 1.0 - p.
x()*p.
x()/
dx/
dx;
709 if (radical < +
DBL_MIN)
return 0;
711 G4double yi = dy*std::sqrt( radical );
712 if (p.
y() < 0) yi = -yi;
721 G4double normi = std::sqrt( xdi*xdi + ydi*ydi );
722 if (normi < halfTol)
return 0;
726 G4double q = 0.5*(xdi*(p.
y()-yi) - ydi*(p.
x()-xi));
727 if (xi*yi < 0) q = -q;
729 if (q < sBest) sBest = q;
734 return sBest < halfTol ? 0 : sBest;
778 if (radical < -
DBL_MIN)
return 0;
789 radical = std::sqrt(radical);
791 G4double q = -0.5*( b + (b < 0 ? -radical : +radical) );
794 if (sa < sb) { ss[0] = sa; ss[1] = sb; }
else { ss[0] = sb; ss[1] = sa; }
804 return G4String(
"G4EllipticalTube");
822 if(fCubicVolume != 0.) {;}
832 if(fSurfaceArea != 0.) {;}
842 G4int oldprc = os.precision(16);
843 os <<
"-----------------------------------------------------------\n"
844 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
845 <<
" ===================================================\n"
846 <<
" Solid type: G4EllipticalTube\n"
848 <<
" length Z: " <<
dz/
mm <<
" mm \n"
849 <<
" surface equation in X and Y: \n"
850 <<
" (X / " <<
dx <<
")^2 + (Y / " << dy <<
")^2 = 1 \n"
851 <<
"-----------------------------------------------------------\n";
852 os.precision(oldprc);
866 G4double xRand, yRand, zRand, phi, cosphi, sinphi, zArea, cArea,
p, chose;
869 cosphi = std::cos(phi);
870 sinphi = std::sin(phi);
879 p = 2.*
pi*std::sqrt(0.5*(
dx*
dx+dy*dy));
890 if( (chose>=0) && (chose < cArea) )
894 else if( (chose >= cArea) && (chose < cArea + zArea) )
897 yRand = std::sqrt(1.-
sqr(xRand/
dx));
904 yRand = std::sqrt(1.-
sqr(xRand/
dx));
933 fRebuildPolyhedron ||
940 fRebuildPolyhedron =
false;
void set(double x, double y, double z)
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
ThreeVector shoot(const G4int Ap, const G4int Af)
static constexpr double mm
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
G4double GetSurfaceArea()
std::vector< ExP01TrackerHit * > a
virtual ~G4EllipticalTube()
virtual G4double GetCubicVolume()
G4ThreeVector GetPointOnSurface() const
G4VisExtent GetExtent() const
void DescribeYourselfTo(G4VGraphicsScene &scene) const
HepPolyhedron & Transform(const G4Transform3D &t)
virtual void AddSolid(const G4Box &)=0
#define G4MUTEX_INITIALIZER
G4Polyhedron * GetPolyhedron() const
static constexpr double twopi
G4EllipticalTube & operator=(const G4EllipticalTube &rhs)
G4double CheckXY(const G4double x, const G4double y, const G4double toler) const
G4int IntersectXY(const G4ThreeVector &p, const G4ThreeVector &v, G4double s[2]) const
G4double GetCubicVolume()
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
G4bool BoundingBoxVsVoxelLimits(const EAxis pAxis, const G4VoxelLimits &pVoxelLimits, const G4Transform3D &pTransform3D, G4double &pMin, G4double &pMax) const
G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pmin, G4double &pmax) const
std::ostream & StreamInfo(std::ostream &os) const
std::vector< G4ThreeVector > G4ThreeVectorList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4Polyhedron * CreatePolyhedron() const
static G4int GetNumberOfRotationSteps()
void Extent(G4ThreeVector &pMin, G4ThreeVector &pMax) const
G4VSolid & operator=(const G4VSolid &rhs)
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
static constexpr double pi
G4EllipticalTube(const G4String &name, G4double theDx, G4double theDy, G4double theDz)
G4GeometryType GetEntityType() const
virtual G4double GetSurfaceArea()
EInside Inside(const G4ThreeVector &p) const