58 : fCheck(false), fVerbose(0)
83 const G4int replicaNo,
95 G4double coord, rad2, rmin, tolRMax2, rmax, tolRMin2;
104 coord = std::fabs(localPoint(axis))-width*0.5;
115 if ( localPoint.y()||localPoint.x() )
117 coord = std::fabs(std::atan2(localPoint.y(),localPoint.x()))-width*0.5;
133 rad2 = localPoint.perp2();
134 rmax = (replicaNo+1)*width+offset;
136 tolRMax2 *= tolRMax2;
140 tolRMax2 *= tolRMax2;
141 if ( rad2<=tolRMax2 )
150 if ( replicaNo||offset )
154 tolRMin2 *= tolRMin2;
158 tolRMin2 *= tolRMin2;
159 if ( rad2>=tolRMin2 )
176 G4Exception(
"G4ReplicaNavigation::Inside()",
"GeomNav0002",
189 const G4int replicaNo,
209 coord = localPoint(axis);
210 safe1 = width*0.5-coord;
211 safe2 = width*0.5+coord;
212 safety = (safe1<=safe2) ? safe1 : safe2;
215 if ( localPoint.y()<=0 )
217 safety = localPoint.x()*std::sin(width*0.5)
218 + localPoint.y()*std::cos(width*0.5);
222 safety = localPoint.x()*std::sin(width*0.5)
223 - localPoint.y()*std::cos(width*0.5);
227 rho = localPoint.perp();
228 rmax = width*(replicaNo+1)+offset;
229 if ( replicaNo||offset )
234 safety = (safe1<=safe2) ? safe1 : safe2;
242 G4Exception(
"G4ReplicaNavigation::DistanceToOut()",
"GeomNav0002",
255 const G4int replicaNo,
278 coord = localPoint(axis);
279 Comp = localDirection(axis);
282 lindist = width*0.5-coord;
283 Dist = (lindist>0) ? lindist/Comp : 0;
288 lindist = width*0.5+coord;
289 Dist = (lindist>0) ? -lindist/Comp : 0;
297 candidateNormal.
exitNormal = ( signC * VecCartAxes[axis]);
301 (Comp>0) ? SideCartAxesPlus[axis] : SideCartAxesMinus[axis];
309 replicaNo,candidateNormal);
313 G4Exception(
"G4ReplicaNavigation::DistanceToOut()",
"GeomNav0002",
318 arExitNormal= candidateNormal;
336 G4double sinSPhi= -2.0, cosSPhi= -2.0;
337 G4double pDistS, pDistE, compS, compE, Dist, dist2, yi;
341 if ( (localPoint.x()!=0.0) || (localPoint.y()!=0.0) )
343 sinSPhi = std::sin(-width*0.5);
344 cosSPhi = std::cos(width*0.5);
348 pDistS = localPoint.x()*sinSPhi-localPoint.y()*cosSPhi;
350 pDistE = localPoint.x()*sinSPhi+localPoint.y()*cosSPhi;
355 compS = -sinSPhi*localDirection.x()+cosSPhi*localDirection.y();
356 compE = -sinSPhi*localDirection.x()-cosSPhi*localDirection.y();
358 if ( (pDistS<=0)&&(pDistE<=0) )
364 dist2 = pDistS/compS;
365 yi = localPoint.y()+dist2*localDirection.y();
385 dist2 = pDistE/compE;
391 yi = localPoint.y()+dist2*localDirection.y();
405 else if ( (pDistS>=0)&&(pDistE>=0) )
410 Dist = ((compS>=0)&&(compE>=0)) ?
kInfinity : 0;
412 else if ( (pDistS>0)&&(pDistE<0) )
418 dist2 = pDistE/compE;
419 yi = localPoint.y()+dist2*localDirection.y();
441 dist2 = pDistS/compS;
442 yi = localPoint.y()+dist2*localDirection.y();
468 if( (std::fabs(localDirection.phi())<=width*0.5) )
506 const G4int replicaNo,
509 G4double rmin, rmax, t1, t2, t3, deltaR;
529 rmin = replicaNo*width+offset;
530 rmax = (replicaNo+1)*width+offset;
532 t1 = 1.0-localDirection.z()*localDirection.z();
533 t2 = localPoint.x()*localDirection.x()+localPoint.y()*localDirection.y();
534 t3 = localPoint.x()*localPoint.x()+localPoint.y()*localPoint.y();
544 deltaR = t3-rmax*rmax;
553 srd = -b+std::sqrt(b*b-c);
571 deltaR = t3-rmin*rmin;
590 deltaR = t3-rmax*rmax;
593 srd = (d2 < 0.) ? 0.0 : -b+std::sqrt(d2);
601 deltaR = t3-rmax*rmax;
605 srd = (d2 < 0.) ? 0.0 : -b+std::sqrt(d2);
621 xi = localPoint.x() + srd*localDirection.x() ;
622 yi = localPoint.y() + srd*localDirection.y() ;
628 normalR *= (-1.0)/rmin;
666 val = -width*0.5*(nReplicas-1)+width*replicaNo;
668 point.setX(point.x()-val);
671 val = -width*0.5*(nReplicas-1)+width*replicaNo;
673 point.setY(point.y()-val);
676 val = -width*0.5*(nReplicas-1)+width*replicaNo;
678 point.setZ(point.z()-val);
681 val = -(offset+width*(replicaNo+0.5));
683 cosv = std::cos(val);
684 sinv = std::sin(val);
685 tmpx = point.x()*cosv-point.y()*sinv;
686 tmpy = point.x()*sinv+point.y()*cosv;
721 val = -width*0.5*(nReplicas-1)+width*replicaNo;
725 val = -width*0.5*(nReplicas-1)+width*replicaNo;
729 val = -width*0.5*(nReplicas-1)+width*replicaNo;
733 val = -(offset+width*(replicaNo+0.5));
752 const G4double currentProposedStepLength,
757 G4bool &calculatedExitNormal,
762 G4int &blockedReplicaNo )
769 G4double ourStep=currentProposedStepLength;
771 G4double sampleStep, sampleSafety, motherStep, motherSafety;
772 G4int localNoDaughters, sampleNo;
777 calculatedExitNormal=
false;
781 if ( exiting&&validExitNormal )
787 blockedExitedVol = *pBlockedPhysical;
807 ourSafety =
std::min( ourSafety, sampleSafety);
809 if ( sampleSafety<ourStep )
817 if ( sampleStep<ourStep )
819 ourStep = sampleStep;
821 validExitNormal = normalOutStc.validConvex;
823 exitNormalStc= normalOutStc;
825 TransformAxis(normalOutStc.exitNormal);
826 calculatedExitNormal=
true;
829 const G4int secondDepth= topDepth;
841 if ( sampleSafety < ourSafety )
843 ourSafety = sampleSafety;
845 if ( sampleSafety < ourStep )
854 if ( sampleStep < ourStep )
856 ourStep = sampleStep;
865 exitNormalStc= normalOutStc;
867 calculatedExitNormal=
true;
880 motherPhysical = history.
GetVolume(depth);
885 motherStep = motherSolid->
DistanceToOut(repPoint,repDirection,
true,
886 &exitConvex,&exitVectorMother);
889 motherNormalStc =
G4ExitNormal( exitVectorMother,
true,
false,
891 calculatedExitNormal=
true;
895 G4bool motherDeterminedStep= (motherStep<ourStep);
897 if( (!exitConvex) && motherDeterminedStep )
900 motherNormalStc=
G4ExitNormal( exitVectorMother,
true,
false,
906 calculatedExitNormal=
true;
908 if( motherDeterminedStep)
913 exitNormalStc= motherNormalStc;
914 exitNormalStc.
exitNormal= globalExitNormalTop;
930 if ( motherSafety<ourSafety )
932 ourSafety = motherSafety;
940 std::ostringstream message;
941 message <<
"Point outside volume !" <<
G4endl
942 <<
" Point " << localPoint
943 <<
" is outside current volume " << motherPhysical->
GetName()
946 message <<
" Estimated isotropic distance to solid (distToIn)= "
947 << estDistToSolid <<
G4endl;
953 "Point is far outside Current Volume !" );
958 "Point is a little outside Current Volume.");
966 if( motherDeterminedStep)
968 ourStep = motherStep;
974 if ( calculatedExitNormal )
976 if ( motherDeterminedStep )
983 exitNormalVector= globalToLocalTop.
TransformAxis(exitNormalGlobal);
991 exitNormalVector *= rot->inverse();
997 validExitNormal =
false;
1001 if ( motherSafety<=ourStep )
1003 if ( motherStep<=ourStep )
1005 ourStep = motherStep;
1007 if ( validExitNormal )
1012 exitNormal *= rot->inverse();
1018 validExitNormal =
false;
1025 G4bool daughterDeterminedStep=
false;
1034 for ( sampleNo=localNoDaughters-1; sampleNo>=0; sampleNo-- )
1036 samplePhysical = repLogical->
GetDaughter(sampleNo);
1037 if ( samplePhysical!=blockedExitedVol )
1049 const G4double sampleSafetyDistance =
1051 if ( sampleSafetyDistance<ourSafety )
1053 ourSafety = sampleSafetyDistance;
1055 if ( sampleSafetyDistance<=ourStep )
1057 sampleDirection = sampleTf.TransformAxis(localDirection);
1058 const G4double sampleStepDistance =
1059 sampleSolid->
DistanceToIn(samplePoint,sampleDirection);
1060 if ( sampleStepDistance<=ourStep )
1062 daughterDeterminedStep=
true;
1064 ourStep = sampleStepDistance;
1067 *pBlockedPhysical = samplePhysical;
1068 blockedReplicaNo = sampleNo;
1070 #ifdef DAUGHTER_NORMAL_ALSO
1073 daughtNormRepCrd = sampleTf.Inverse().TransformAxis(localExitNorm);
1083 intersectionPoint= samplePoint
1084 + sampleStepDistance * sampleDirection;
1085 EInside insideIntPt= sampleSolid->
Inside(intersectionPoint);
1089 std::ostringstream message;
1090 message <<
"Navigator gets conflicting response from Solid."
1092 <<
" Inaccurate DistanceToIn for solid "
1094 <<
" Solid gave DistanceToIn = "
1095 << sampleStepDistance <<
" yet returns " ;
1097 message <<
"-kInside-";
1098 else if ( insideIntPt ==
kOutside )
1099 message <<
"-kOutside-";
1101 message <<
"-kSurface-";
1102 message <<
" for this point !" <<
G4endl
1103 <<
" Point = " << intersectionPoint <<
G4endl;
1105 message <<
" DistanceToIn(p) = "
1109 message <<
" DistanceToOut(p) = "
1113 G4cout.precision(oldcoutPrec);
1122 calculatedExitNormal &= (!daughterDeterminedStep);
1124 #ifdef DAUGHTER_NORMAL_ALSO
1125 if( daughterDeterminedStep )
1132 validExitNormal=
false;
1134 calculatedExitNormal=
true;
1139 newSafety = ourSafety;
1163 G4int localNoDaughters, sampleNo;
1176 if ( sampleSafety<ourSafety )
1178 ourSafety = sampleSafety;
1188 if ( sampleSafety<ourSafety )
1190 ourSafety = sampleSafety;
1198 motherPhysical = history.
GetVolume(depth);
1202 if ( sampleSafety<ourSafety )
1204 ourSafety = sampleSafety;
1210 for ( sampleNo=localNoDaughters-1; sampleNo>=0; sampleNo-- )
1212 samplePhysical = repLogical->
GetDaughter(sampleNo);
1213 if ( samplePhysical!=blockedExitedVol )
1222 const G4double sampleSafetyDistance =
1224 if ( sampleSafetyDistance<ourSafety )
1226 ourSafety = sampleSafetyDistance;
1242 G4bool ¬KnownInside )
const
1247 G4int mdepth, depth, cdepth;
1254 for ( mdepth=cdepth-1; mdepth>=0; mdepth-- )
1268 G4Exception(
"G4ReplicaNavigation::BackLocate()",
"GeomNav0002",
1275 insideCode = motherSolid->
Inside(goodPoint);
1287 notKnownInside =
false;
1292 for ( depth=mdepth+1; depth<cdepth; depth++)
1300 localPoint = goodPoint;
1306 goodPoint = repPoint;
1319 localPoint = goodPoint;
G4double halfkAngTolerance
G4VPhysicalVolume * GetTopVolume() const
const G4ThreeVector & GetTranslation() const
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
EInside Inside(const G4VPhysicalVolume *pVol, const G4int replicaNo, const G4ThreeVector &localPoint) const
G4double GetSurfaceTolerance() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
EVolume GetVolumeType(G4int n) const
G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4bool &calculatedExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
G4double DistanceToOut(const G4VPhysicalVolume *pVol, const G4int replicaNo, const G4ThreeVector &localPoint) const
void ComputeTransformation(const G4int replicaNo, G4VPhysicalVolume *pVol, G4ThreeVector &point) const
G4int GetTopReplicaNo() const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
G4double halfkRadTolerance
G4double GetRadialTolerance() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
G4int GetReplicaNo(G4int n) const
void SetTranslation(const G4ThreeVector &v)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
static const double kMinExitingNormalCosine
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4LogicalVolume * GetLogicalVolume() const
const G4AffineTransform & GetTransform(G4int n) const
G4double DistanceToOutRad(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double width, const G4double offset, const G4int replicaNo, G4ExitNormal &foundNormal) const
const G4RotationMatrix * GetRotation() const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4double DistanceToOutPhi(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double width, G4ExitNormal &foundNormal) const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
const G4AffineTransform & GetTopTransform() const
G4double ComputeSafety(const G4ThreeVector &globalPoint, const G4ThreeVector &localPoint, G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
G4VPhysicalVolume * GetVolume(G4int n) const
void SetPhiTransformation(const G4double ang, G4VPhysicalVolume *pVol=0) const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
EInside BackLocate(G4NavigationHistory &history, const G4ThreeVector &globalPoint, G4ThreeVector &localPoint, const G4bool &exiting, G4bool ¬KnownInside) const
G4double GetAngularTolerance() const
G4double halfkCarTolerance
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const