43 const G4int handedness,
54 axis0min, axis1min, axis0max, axis1max),
55 fKappa(kappa), fTanStereo(tanstereo),
56 fTan2Stereo(tanstereo*tanstereo), fR0(r0), fR02(r0*r0), fDPhi(twopi)
60 G4Exception(
"G4TwistTubsHypeSide::G4TwistTubsHypeSide()",
62 "Should swap axis0 and axis1!");
64 fInside.gp.set(kInfinity, kInfinity, kInfinity);
98 fTanStereo = TanInnerStereo;
103 fTanStereo = TanOuterStereo;
106 fTan2Stereo = fTanStereo * fTanStereo;
112 fInside.gp.set(kInfinity, kInfinity, kInfinity);
115 SetCorners(EndInnerRadius, EndOuterRadius, DPhi, EndPhi, EndZ) ;
160 normal = normal.
unit();
182 if (fInside.gp == gp)
184 return fInside.inside;
194 return fInside.inside;
201 if (distanceToOut < -halftol)
207 G4int areacode = GetAreaCode(p);
218 if (distanceToOut <= halftol)
229 G4cout <<
"WARNING - G4TwistTubsHypeSide::Inside()" <<
G4endl
230 <<
" Invalid option !" <<
G4endl
231 <<
" name, areacode, distanceToOut = "
232 <<
GetName() <<
", " << std::hex << areacode
233 << std::dec <<
", " << distanceToOut <<
G4endl;
237 return fInside.inside;
302 for (
auto i=0; i<2; ++i)
304 distance[i] = kInfinity;
307 gxx[i].
set(kInfinity, kInfinity, kInfinity);
336 if (vrho == 0 || (vrho/absvz) <= (absvz*std::fabs(fTanStereo)/absvz))
339 distance[0] = kInfinity;
340 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
341 isvalid[0], 0, validate, &gp, &gv);
347 G4double xxz = std::sqrt(fR02 / (vslope2 - fTan2Stereo))
348 * (vz / std::fabs(vz)) ;
350 xx[0].
set(t*v.
x(), t*v.
y(), xxz);
355 xx[0].
set(v.
x()*fR0, v.
y()*fR0, 0);
357 distance[0] = xx[0].
mag();
362 areacode[0] = GetAreaCode(xx[0]);
365 if (distance[0] >= 0) { isvalid[0] =
true; }
370 areacode[0] = GetAreaCode(xx[0],
false);
373 if (distance[0] >= 0) { isvalid[0] =
true; }
379 if (distance[0] >= 0) { isvalid[0] =
true; }
382 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
383 isvalid[0], 1, validate, &gp, &gv);
393 * ( p.
x() * v.
x() + p.
y() * v.
y() - p.
z() * v.
z() * fTan2Stereo );
394 G4double c = p.
x()*p.
x() + p.
y()*p.
y() - fR02 - p.
z()*p.
z()*fTan2Stereo;
403 xx[0] = p + distance[0]*v;
408 areacode[0] = GetAreaCode(xx[0]);
411 if (distance[0] >= 0) { isvalid[0] =
true; }
416 areacode[0] = GetAreaCode(xx[0],
false);
419 if (distance[0] >= 0) { isvalid[0] =
true; }
425 if (distance[0] >= 0) { isvalid[0] =
true; }
428 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
429 isvalid[0], 1, validate, &gp, &gv);
438 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
439 isvalid[0], 0, validate, &gp, &gv);
447 G4double tmpdist[2] = {kInfinity, kInfinity};
450 G4bool tmpisvalid[2] = {
false,
false};
452 for (
auto i=0; i<2; ++i)
454 tmpdist[i] = factor*(-b -
D);
456 tmpxx[i] = p + tmpdist[i]*v;
460 tmpareacode[i] = GetAreaCode(tmpxx[i]);
463 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
469 tmpareacode[i] = GetAreaCode(tmpxx[i],
false);
472 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
479 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
484 if (tmpdist[0] <= tmpdist[1])
486 distance[0] = tmpdist[0];
487 distance[1] = tmpdist[1];
492 areacode[0] = tmpareacode[0];
493 areacode[1] = tmpareacode[1];
494 isvalid[0] = tmpisvalid[0];
495 isvalid[1] = tmpisvalid[1];
499 distance[0] = tmpdist[1];
500 distance[1] = tmpdist[0];
505 areacode[0] = tmpareacode[1];
506 areacode[1] = tmpareacode[0];
507 isvalid[0] = tmpisvalid[1];
508 isvalid[1] = tmpisvalid[0];
511 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
512 isvalid[0], 2, validate, &gp, &gv);
513 fCurStatWithV.SetCurrentStatus(1, gxx[1], distance[1], areacode[1],
514 isvalid[1], 2, validate, &gp, &gv);
522 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
523 isvalid[0], 0, validate, &gp, &gv);
555 distance[i] =
fCurStat.GetDistance(i);
556 areacode[i] =
fCurStat.GetAreacode(i);
562 for (
auto i=0; i<2; ++i)
564 distance[i] = kInfinity;
566 gxx[i].
set(kInfinity, kInfinity, kInfinity);
577 for (
auto i=0; i<2; ++i)
582 if ((gp - lastgxx[0]).mag() < halftol || (gp - lastgxx[1]).mag() < halftol)
590 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
601 G4double r1 = std::sqrt(fR02 + pz * pz * fTan2Stereo);
605 if (prho > r1 + halftol)
612 G4double z2 = (prho * fTanStereo + pz) / (1 + fTan2Stereo);
613 G4double r2 = std::sqrt(fR02 + z2 * z2 * fTan2Stereo);
622 distance[0] = (pabsz - xx1).mag();
631 else if (prho < r1 - halftol)
638 xx1.
set(r1, 0. , pz);
643 xx1.
set(t * pabsz.
x(), t * pabsz.
y() , pz);
659 xx2.
set(r2, 0. , 0.);
664 xx2.
set(t * pabsz.
x(), t * pabsz.
y() , 0.);
674 xx.
set(p.
x(), p.
y(), pz);
686 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
707 G4int phiareacode = GetAreaCodeInPhi(xx);
715 if (isoutsideinphi) { isoutside =
true; }
720 if (isoutsideinphi) { isoutside =
true; }
737 if (xx.
z() <=
fAxisMin[zaxis] - ctol) { isoutside =
true; }
739 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
751 if (xx.
z() >=
fAxisMax[zaxis] + ctol) { isoutside =
true; }
760 areacode = tmpareacode;
770 G4int phiareacode = GetAreaCodeInPhi(xx,
false);
820 std::ostringstream message;
821 message <<
"Feature NOT implemented !" <<
G4endl
823 <<
" fAxis[1] = " <<
fAxis[1];
863 areacode = tmpareacode;
884void G4TwistTubsHypeSide::SetCorners(
G4double EndInnerRadius[2],
897 for (
auto i=0; i<2; ++i)
899 endRad[i] = (
fHandedness == 1 ? EndOuterRadius[i] : EndInnerRadius[i]);
908 x = endRad[zmin]*std::cos(endPhi[zmin] - halfdphi);
909 y = endRad[zmin]*std::sin(endPhi[zmin] - halfdphi);
914 x = endRad[zmin]*std::cos(endPhi[zmin] + halfdphi);
915 y = endRad[zmin]*std::sin(endPhi[zmin] + halfdphi);
920 x = endRad[zmax]*std::cos(endPhi[zmax] + halfdphi);
921 y = endRad[zmax]*std::sin(endPhi[zmax] + halfdphi);
926 x = endRad[zmax]*std::cos(endPhi[zmax] - halfdphi);
927 y = endRad[zmax]*std::sin(endPhi[zmax] - halfdphi);
934 std::ostringstream message;
935 message <<
"Feature NOT implemented !" <<
G4endl
937 <<
" fAxis[1] = " <<
fAxis[1];
946void G4TwistTubsHypeSide::SetCorners()
950 "Method NOT implemented !");
956void G4TwistTubsHypeSide::SetBoundaries()
967 direction = direction.
unit();
973 direction = direction.
unit();
979 direction = direction.
unit();
985 direction = direction.
unit();
991 std::ostringstream message;
992 message <<
"Feature NOT implemented !" <<
G4endl
994 <<
" fAxis[1] = " <<
fAxis[1];
995 G4Exception(
"G4TwistTubsHypeSide::SetBoundaries()",
1016 for (
G4int i = 0 ; i<
n ; ++i )
1020 for (
G4int j = 0 ; j<k ; ++j )
1022 nnode =
GetNode(i,j,k,n,iside) ;
1024 xmin = GetBoundaryMin(z) ;
1025 xmax = GetBoundaryMax(z) ;
1029 x = xmin + j*(xmax-xmin)/(k-1) ;
1033 x = xmax - j*(xmax-xmin)/(k-1) ;
1036 p = SurfacePoint(x,z,
true) ;
1038 xyz[nnode][0] = p.
x() ;
1039 xyz[nnode][1] = p.
y() ;
1040 xyz[nnode][2] = p.
z() ;
1042 if ( i<n-1 && j<k-1 )
1044 nface =
GetFace(i,j,k,n,iside) ;
1046 * (
GetNode(i ,j ,k,n,iside)+1) ;
1048 * (
GetNode(i+1,j ,k,n,iside)+1) ;
1050 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1052 * (
GetNode(i ,j+1,k,n,iside)+1) ;
const G4double kCarTolerance
G4double D(G4double temp)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
G4double GetRadialTolerance() const
static G4GeometryTolerance * GetInstance()
G4ThreeVector GetNormal(const G4ThreeVector &p, G4bool isGlobal=false) override
G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
EInside Inside(const G4ThreeVector &gp)
G4TwistTubsHypeSide(const G4String &name, const G4RotationMatrix &rot, const G4ThreeVector &tlate, const G4int handedness, const G4double kappa, const G4double tanstereo, const G4double r0, const EAxis axis0=kPhi, const EAxis axis1=kZAxis, G4double axis0min=-kInfinity, G4double axis1min=-kInfinity, G4double axis0max=kInfinity, G4double axis1max=kInfinity)
G4double GetRhoAtPZ(const G4ThreeVector &p, G4bool isglobal=false) const
virtual G4int AmIOnLeftSide(const G4ThreeVector &me, const G4ThreeVector &vec, G4bool withTol=true)
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4VTwistSurface(const G4String &name)
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sOutside
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
static const G4int sAxisMax
static const G4int sAxis0
G4int GetFace(G4int i, G4int j, G4int m, G4int n, G4int iside)
const G4String & GetName() const
G4int GetEdgeVisibility(G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
G4double DistanceToLine(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &d, G4ThreeVector &xx)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
static const G4int sAxisPhi
static const G4int sAxisMin
static const G4int sC0Max1Max
static const G4int sAxis1
virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode, const G4ThreeVector &p) const
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
G4ThreeVector GetCorner(G4int areacode) const
static const G4int sBoundary
static const G4int sAxisZ
G4bool IsOutside(G4int areacode) const
static const G4int sCorner
static const G4int sC0Max1Min
static const G4int sInside
CurrentStatus fCurStatWithV
G4bool IsBoundary(G4int areacode, G4bool testbitmode=false) const
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal