47static const G4double kToleranceNormalCheck = CLHEP::perThousand;
64 G4cout <<
" G4Navigator parameters: Action Threshold (No Zero Steps) = "
65 << fActionThreshold_NoZeroSteps
66 <<
" Abandon Threshold (No Zero Steps) = "
67 << fAbandonThreshold_NoZeroSteps <<
G4endl;
103 fLastTriedStepComputation =
false;
128 const G4bool relativeSearch,
129 const G4bool ignoreDirection )
131 G4bool notKnownContained =
true, noResult;
138 G4bool considerDirection = (!ignoreDirection) || fLocatedOnEdge;
140 fLastTriedStepComputation =
false;
141 fChangedGrandMotherRefFrame =
false;
143 if( considerDirection && pGlobalDirection !=
nullptr )
145 globalDirection=*pGlobalDirection;
152 G4cout <<
"*** G4Navigator::LocateGlobalPointAndSetup: ***" <<
G4endl;
154 <<
" Globalpoint = " << globalPoint <<
G4endl
155 <<
" RelativeSearch = " << relativeSearch <<
G4endl;
161 G4cout.precision(oldcoutPrec);
165 G4int noLevelsExited = 0;
166 G4int noLevelsEntered = 0;
168 if ( !relativeSearch )
191 fLastLocatedPointLocal = localPoint;
192 fLocatedOutsideWorld =
true;
193 fBlockedPhysicalVolume = 0;
194 fBlockedReplicaNo = -1;
231 fBlockedPhysicalVolume);
234 fBlockedPhysicalVolume->
SetCopyNo(fBlockedReplicaNo);
244 fBlockedPhysicalVolume);
246 fBlockedPhysicalVolume);
248 fBlockedPhysicalVolume);
251 fBlockedPhysicalVolume->
SetCopyNo(fBlockedReplicaNo);
259 ComputeMaterial(fBlockedReplicaNo,
260 fBlockedPhysicalVolume,
265 G4Exception(
"G4Navigator::LocateGlobalPointAndSetup()",
267 "Extra levels not applicable for external volumes.");
271 fBlockedPhysicalVolume =
nullptr;
273 notKnownContained =
false;
278 fBlockedPhysicalVolume =
nullptr;
295 while (notKnownContained)
302 insideCode = targetSolid->
Inside(localPoint);
306 G4String solidResponse =
"-kInside-";
308 solidResponse =
"-kOutside-";
310 solidResponse =
"-kSurface-";
311 G4cout <<
"*** G4Navigator::LocateGlobalPointAndSetup(): ***" <<
G4endl
312 <<
" Invoked Inside() for solid: " << targetSolid->
GetName()
313 <<
". Solid replied: " << solidResponse <<
G4endl
314 <<
" For local point p: " << localPoint <<
G4endl;
323 fExiting, notKnownContained);
335 insideCode = fpExternalNav->
Inside(targetSolid, localPoint, localDirection);
349 if( noLevelsExited > 1 )
356 fGrandMotherExitNormal *= (*mRot).inverse();
357 fChangedGrandMotherRefFrame =
true;
363 fLastLocatedPointLocal = localPoint;
364 fLocatedOutsideWorld =
true;
372 G4bool isExiting = fExiting;
373 if( (!fExiting) && considerDirection )
378 G4bool directionExiting =
false;
389 directionExiting = normal.
dot(localDirection) > 0.0;
390 isExiting = isExiting || directionExiting;
404 fValidExitNormal =
false;
406 if( noLevelsExited > 1 )
414 fGrandMotherExitNormal *= (*mRot).inverse();
415 fChangedGrandMotherRefFrame =
true;
421 fLastLocatedPointLocal = localPoint;
422 fLocatedOutsideWorld =
true;
429 notKnownContained =
false;
434 notKnownContained =
false;
455 if (!targetPhysical) {
break; }
463 fBlockedPhysicalVolume,
473 fBlockedPhysicalVolume,
483 fBlockedPhysicalVolume,
494 fBlockedPhysicalVolume,
504 fBlockedPhysicalVolume,
514 fBlockedPhysicalVolume,
534 fBlockedPhysicalVolume =
nullptr;
535 fBlockedReplicaNo = -1;
552 fGrandMotherExitNormal *= (*mRot);
553 fChangedGrandMotherRefFrame=
true;
557#ifdef G4DEBUG_NAVIGATION
561 G4cout <<
"*** G4Navigator::LocateGlobalPointAndSetup() ***" <<
G4endl;
569 fLastLocatedPointLocal = localPoint;
576 if (targetPhysical) { curPhysVol_Name = targetPhysical->
GetName(); }
577 G4cout <<
" Return value = new volume = " << curPhysVol_Name <<
G4endl;
582 G4cout <<
"Upon exiting LocateGlobalPointAndSetup():" <<
G4endl;
585 G4cout.precision(oldcoutPrec);
589 fLocatedOutsideWorld =
false;
591 return targetPhysical;
610#ifdef G4DEBUG_NAVIGATION
617 fLastTriedStepComputation =
false;
618 fChangedGrandMotherRefFrame =
false;
635 fvoxelNav.
VoxelLocate( pVoxelHeader, fLastLocatedPointLocal );
651 fLastLocatedPointLocal );
660 fBlockedPhysicalVolume =
nullptr;
661 fBlockedReplicaNo = -1;
682 fSaveState.sExitNormal = fExitNormal;
683 fSaveState.sValidExitNormal = fValidExitNormal;
684 fSaveState.sExiting = fExiting;
685 fSaveState.sEntering = fEntering;
687 fSaveState.spBlockedPhysicalVolume = fBlockedPhysicalVolume;
688 fSaveState.sBlockedReplicaNo = fBlockedReplicaNo;
690 fSaveState.sLastStepWasZero = fLastStepWasZero;
692 fSaveState.sLocatedOutsideWorld = fLocatedOutsideWorld;
693 fSaveState.sLastLocatedPointLocal = fLastLocatedPointLocal;
700 fSaveState.sPreviousSftOrigin = fPreviousSftOrigin;
701 fSaveState.sPreviousSafety = fPreviousSafety;
712 fExitNormal = fSaveState.sExitNormal;
713 fValidExitNormal = fSaveState.sValidExitNormal;
714 fExiting = fSaveState.sExiting;
715 fEntering = fSaveState.sEntering;
717 fBlockedPhysicalVolume = fSaveState.spBlockedPhysicalVolume;
718 fBlockedReplicaNo = fSaveState.sBlockedReplicaNo;
720 fLastStepWasZero = fSaveState.sLastStepWasZero;
722 fLocatedOutsideWorld = fSaveState.sLocatedOutsideWorld;
723 fLastLocatedPointLocal = fSaveState.sLastLocatedPointLocal;
729 fPreviousSftOrigin = fSaveState.sPreviousSftOrigin;
730 fPreviousSafety = fSaveState.sPreviousSafety;
766 const G4double pCurrentProposedStepLength,
778 fChangedGrandMotherRefFrame =
false;
781 fCalculatedExitNormal =
false;
787 fLastTriedStepComputation =
true;
792 G4cout <<
"*** G4Navigator::ComputeStep: ***" <<
G4endl;
794 <<
" - Proposed step length = " << pCurrentProposedStepLength
796#ifdef G4DEBUG_NAVIGATION
800 <<
" Globalpoint = " << std::setw(25) << pGlobalpoint <<
G4endl
801 <<
" Direction = " << std::setw(25) << pDirection <<
G4endl;
813 if( newLocalPoint != fLastLocatedPointLocal )
818 G4double moveLenSq = (newLocalPoint-oldLocalPoint).mag2();
820 if ( moveLenSq >=
fSqTol )
823 ComputeStepLog(pGlobalpoint, moveLenSq);
828 fLastTriedStepComputation =
true;
838 Step = fvoxelNav.
ComputeStep(fLastLocatedPointLocal,
840 pCurrentProposedStepLength,
847 &fBlockedPhysicalVolume,
855 Step = fnormalNav.
ComputeStep(fLastLocatedPointLocal,
857 pCurrentProposedStepLength,
864 &fBlockedPhysicalVolume,
870 fLastTriedStepComputation =
true;
885 "Point is relocated in voxels, while it should be outside!");
886 Step = fnormalNav.
ComputeStep(fLastLocatedPointLocal,
888 pCurrentProposedStepLength,
895 &fBlockedPhysicalVolume,
901 ComputeStepSkippingEqualMaterials(fLastLocatedPointLocal,
903 pCurrentProposedStepLength,
910 &fBlockedPhysicalVolume,
920 Step = fparamNav.
ComputeStep(fLastLocatedPointLocal,
922 pCurrentProposedStepLength,
929 &fBlockedPhysicalVolume,
934 Step = fregularNav.
ComputeStep(fLastLocatedPointLocal,
936 pCurrentProposedStepLength,
943 &fBlockedPhysicalVolume,
948 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav0001",
952 Step = fpExternalNav->
ComputeStep(fLastLocatedPointLocal,
954 pCurrentProposedStepLength,
961 &fBlockedPhysicalVolume,
972 G4bool calculatedExitNormal;
975 fLastLocatedPointLocal,
977 pCurrentProposedStepLength,
981 calculatedExitNormal,
985 &fBlockedPhysicalVolume,
987 fExiting = exitingReplica;
988 fCalculatedExitNormal = calculatedExitNormal;
993 fPreviousSftOrigin = pGlobalpoint;
994 fPreviousSafety = pNewSafety;
1006 fLocatedOnEdge = fLastStepWasZero && (Step==0.0);
1007 fLastStepWasZero = (Step<
fMinStep);
1016 G4bool act = fNumberZeroSteps >= fActionThreshold_NoZeroSteps;
1017 G4bool actAndReport =
false;
1018 G4bool abandon = fNumberZeroSteps >= fAbandonThreshold_NoZeroSteps;
1021 actAndReport = act && (!fPushed) && fWarnPush;
1023#ifdef G4DEBUG_NAVIGATION
1024 inform = fNumberZeroSteps > 1;
1027 if ( act || inform )
1029 if( act && !abandon )
1037 if( actAndReport || abandon || inform )
1039 std::ostringstream message;
1041 message.precision(16);
1042 message <<
"Stuck Track: potential geometry or navigation problem."
1044 message <<
" Track stuck, not moving for "
1045 << fNumberZeroSteps <<
" steps." <<
G4endl
1046 <<
" Current phys volume: '" << motherPhysical->
GetName()
1048 <<
" - at position : " << pGlobalpoint <<
G4endl
1049 <<
" in direction: " << pDirection <<
G4endl
1050 <<
" (local position: " << newLocalPoint <<
")" <<
G4endl
1051 <<
" (local direction: " << localDirection <<
")." <<
G4endl
1052 <<
" Previous phys volume: '"
1053 << ( fLastMotherPhys ? fLastMotherPhys->
GetName() :
"" )
1055 if( actAndReport || abandon )
1057 message <<
" Likely geometry overlap - else navigation problem !"
1066 message <<
" Track *abandoned* due to excessive number of Zero steps."
1068 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav0003",
1076 message <<
" *** Trying to get *unstuck* using a push"
1077 <<
" - expanding step to " << Step <<
" (mm) ..."
1078 <<
" Potential overlap in geometry !" <<
G4endl;
1079 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav1002",
1083#ifdef G4DEBUG_NAVIGATION
1086 if( fNumberZeroSteps > 1 )
1088 message <<
", nav-comp-step calls # " << sNavCScalls
1089 <<
", Step= " << Step <<
G4endl;
1100 if (!fPushed) { fNumberZeroSteps = 0; }
1102 fLastMotherPhys = motherPhysical;
1108 + std::min(Step,pCurrentProposedStepLength) * pDirection;
1113#ifdef G4DEBUG_NAVIGATION
1116 G4cout <<
" At G4Nav CompStep End - if(exiting) - fExiting= " << fExiting
1117 <<
" fValidExitNormal = " << fValidExitNormal <<
G4endl;
1122 if ( fValidExitNormal || fCalculatedExitNormal )
1128 fGrandMotherExitNormal = fExitNormal;
1129 fCalculatedExitNormal =
true;
1133 fGrandMotherExitNormal = fExitNormal;
1141 + localDirection*Step;
1155 fChangedGrandMotherRefFrame =
true;
1156 fGrandMotherExitNormal = (*mRot).inverse() * exitNormalMotherFrame;
1160 fGrandMotherExitNormal = exitNormalMotherFrame;
1166 fCalculatedExitNormal =
true;
1170 fCalculatedExitNormal =
false;
1177#ifdef G4DEBUG_NAVIGATION
1180 desc <<
"Problem in ComputeStep: Replica Navigation did not provide"
1181 <<
" valid exit Normal. " <<
G4endl;
1182 desc <<
" Do not know how calculate it in this case." <<
G4endl;
1183 desc <<
" Location = " << finalLocalPoint <<
G4endl;
1184 desc <<
" Volume name = " << motherPhysical->
GetName()
1186 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav0003",
1187 JustWarning, desc,
"Normal not available for exiting.");
1194 if( fValidExitNormal || fCalculatedExitNormal )
1204 fExitNormalGlobalFrame = fGrandMotherExitNormal;
1213 if( (Step == pCurrentProposedStepLength) && (!fExiting) && (!fEntering) )
1229 G4cout <<
" Returned step= " << Step;
1231 if( Step == kInfinity )
1233 G4cout <<
" Requested step= " << pCurrentProposedStepLength ;
1251 const G4double pCurrentProposedStepLength,
1262 pCurrentProposedStepLength,
1287 fLocatedOnEdge =
false;
1288 fLastStepWasZero =
false;
1293 fValidExitNormal =
false;
1294 fChangedGrandMotherRefFrame =
false;
1295 fCalculatedExitNormal =
false;
1302 fPreviousSafety = 0.0;
1304 fNumberZeroSteps = 0;
1306 fBlockedPhysicalVolume =
nullptr;
1307 fBlockedReplicaNo = -1;
1309 fLastLocatedPointLocal =
G4ThreeVector( kInfinity, -kInfinity, 0.0 );
1310 fLocatedOutsideWorld =
false;
1312 fLastMotherPhys =
nullptr;
1330 for (
auto i=1; i<=cdepth; ++i )
1369 ComputeMaterial(replicaNo, current, pTouchable) );
1389 if ( fLastTriedStepComputation )
1395 if( fEntering && (fBlockedPhysicalVolume!=0) )
1398 if( candidateLogical )
1420 currentSolid = candidateLogical->
GetSolid();
1421 inSideIt = currentSolid->
Inside(daughterPointOwnLocal);
1422 onSurface = (inSideIt ==
kSurface);
1427 safety = (currentSolid->
DistanceToIn(daughterPointOwnLocal));
1430 else if (inSideIt ==
kInside )
1432 safety = (currentSolid->
DistanceToOut(daughterPointOwnLocal));
1439 nextSolidExitNormal =
1446 ExitNormal = MotherToDaughterTransform
1448 fCalculatedExitNormal =
true;
1453 if((
fVerbose == 1 ) && ( fCheck ))
1455 std::ostringstream message;
1456 message <<
"Point not on surface ! " <<
G4endl
1458 << daughterPointOwnLocal <<
G4endl
1459 <<
" Physical volume = "
1461 <<
" Logical volume = "
1463 <<
" Solid = " << currentSolid->
GetName()
1466 << *currentSolid <<
G4endl;
1469 message <<
"Point is Outside. " <<
G4endl
1470 <<
" Safety (from outside) = " << safety <<
G4endl;
1474 message <<
"Point is Inside. " <<
G4endl
1475 <<
" Safety (from inside) = " << safety <<
G4endl;
1477 G4Exception(
"G4Navigator::GetLocalExitNormal()",
"GeomNav1001",
1486 else if ( fExiting )
1488 ExitNormal = fGrandMotherExitNormal;
1490 fCalculatedExitNormal =
true;
1497 "Incorrect call to GetLocalSurfaceNormal." );
1506 ExitNormal = -(daughterSolid->
SurfaceNormal(fLastLocatedPointLocal));
1507 if( std::fabs(ExitNormal.
mag2()-1.0 ) > kToleranceNormalCheck )
1510 desc <<
" Parameters of solid: " << *daughterSolid
1511 <<
" Point for surface = " << fLastLocatedPointLocal << std::endl;
1514 "Surface Normal returned by Solid is not a Unit Vector." );
1516 fCalculatedExitNormal =
true;
1523 ExitNormal = fGrandMotherExitNormal;
1525 fCalculatedExitNormal =
true;
1530 fCalculatedExitNormal =
false;
1532 message <<
"Function called when *NOT* at a Boundary." <<
G4endl;
1533 message <<
"Exit Normal not calculated." <<
G4endl;
1550 G4int enteringReplicaNo,
1553 switch (enteringVolumeType)
1558 G4Exception(
"G4Navigator::GetMotherToDaughterTransform()",
1560 "Method NOT Implemented yet for replica volumes.");
1568 pParam->
ComputeSolid(enteringReplicaNo, pEnteringPhysVol);
1608#ifdef G4DEBUG_NAVIGATION
1611 if ( fLastTriedStepComputation )
1616 ExpectedBoundaryPointLocal =
1637 G4bool* pNormalCalculated)
1642 G4bool usingStored = fCalculatedExitNormal && (
1643 ( fLastTriedStepComputation && fExiting )
1645 ( !fLastTriedStepComputation
1655 globalNormal = fExitNormalGlobalFrame;
1657 if( std::fabs ( normMag2 - 1.0 ) < perThousand )
1659 *pNormalCalculated =
true;
1665 message.precision(10);
1666 message <<
" WARNING> Expected normal-global-frame to be valid, "
1667 <<
" i.e. a unit vector!" <<
G4endl
1668 <<
" - but |normal| = " << std::sqrt(normMag2)
1669 <<
" - and |normal|^2 = " << normMag2 <<
G4endl
1670 <<
" which differs from 1.0 by " << normMag2 - 1.0 <<
G4endl
1671 <<
" n = " << fExitNormalGlobalFrame <<
G4endl
1672 <<
" Global point: " << IntersectPointGlobal <<
G4endl
1683 message <<
"============================================================"
1687 message <<
" State of Navigator: " <<
G4endl;
1688 message << *
this <<
G4endl;
1690 message <<
"============================================================"
1695 "Value obtained from stored global-normal is not a unit vector.");
1701 *pNormalCalculated = fCalculatedExitNormal;
1709 *pNormalCalculated = fCalculatedExitNormal;
1711#ifdef G4DEBUG_NAVIGATION
1712 usingStored =
false;
1714 if( (!validNormal) && !fCalculatedExitNormal )
1717 edN <<
" Calculated = " << fCalculatedExitNormal <<
G4endl;
1718 edN <<
" Entering= " << fEntering <<
G4endl;
1721 edN <<
" State of Navigator: " <<
G4endl;
1727 "LocalExitNormalAndCheck() did not calculate Normal.");
1732 if( validNormal && (std::fabs(localMag2-1.0)) > kToleranceNormalCheck )
1736 edN <<
"G4Navigator::GetGlobalExitNormal: "
1737 <<
" Using Local Normal - from call to GetLocalExitNormalAndCheck. "
1739 <<
" Local Exit Normal : " <<
" || = " << std::sqrt(localMag2)
1740 <<
" vec = " << localNormal <<
G4endl
1741 <<
" Global Exit Normal : " <<
" || = " << globalNormal.
mag()
1742 <<
" vec = " << globalNormal <<
G4endl
1743 <<
" Global point: " << IntersectPointGlobal <<
G4endl;
1744 edN <<
" Calculated It = " << fCalculatedExitNormal <<
G4endl
1757 "Value obtained from new local *solid* is incorrect.");
1758 localNormal = localNormal.
unit();
1764#ifdef G4DEBUG_NAVIGATION
1775 G4ThreeVector diffNorm = globalNormAgn - fExitNormalGlobalFrame;
1776 if( diffNorm.
mag2() > kToleranceNormalCheck )
1779 edDfn <<
"Found difference in normals in case of exiting mother "
1780 <<
"- when Get is called after ComputingStep " <<
G4endl;
1781 edDfn <<
" Magnitude of diff = " << diffNorm.
mag() <<
G4endl;
1784 edDfn <<
" Global Computed from Local = " << globalNormAgn <<
G4endl;
1785 G4Exception(
"G4Navigator::GetGlobalExitNormal()",
"GeomNav0003",
1793 fExitNormalGlobalFrame = globalNormal;
1795 return globalNormal;
1799#define G4NEW_SAFETY 1
1816#ifdef G4DEBUG_NAVIGATION
1820 G4cout <<
"*** G4Navigator::ComputeSafety: ***" <<
G4endl
1821 <<
" Called at point: " << pGlobalpoint <<
G4endl;
1825 <<
" - Maximum length = " << pMaxLength <<
G4endl;
1828 G4cout <<
" ----- Upon entering Compute Safety:" <<
G4endl;
1838 if( endpointOnSurface && stayedOnEndpoint )
1840#ifdef G4DEBUG_NAVIGATION
1843 G4cout <<
" G4Navigator::ComputeSafety() finds that point - "
1844 << pGlobalpoint <<
" - is on surface " <<
G4endl;
1868#ifdef G4DEBUG_NAVIGATION
1871 G4cout <<
" G4Navigator::ComputeSafety() relocates-in-volume to point: "
1872 << pGlobalpoint <<
G4endl;
1889 *motherPhysical, pMaxLength);
1890 newSafety = safetyTwo;
1895 newSafety = safetyOldVoxel;
1914 G4Exception(
"G4Navigator::ComputeSafety()",
"GeomNav0001",
1925 newSafety = freplicaNav.
ComputeSafety(pGlobalpoint, localPoint,
1938 fPreviousSftOrigin = pGlobalpoint;
1939 fPreviousSafety = newSafety;
1942#ifdef G4DEBUG_NAVIGATION
1947 G4cout <<
" Returned value of Safety = " << newSafety <<
G4endl;
1949 G4cout.precision(oldcoutPrec);
1990#ifdef CHECK_ORDER_OF_METHODS
1991 if( ! fLastTriedStepComputation )
1993 G4Exception(
"G4Navigator::RecheckDistanceToCurrentBoundary()",
1995 "Method must be called after ComputeStep(), before call to LocateMethod.");
2026 locatedDaug = candSolid->
Inside(dgPosition);
2035 true, &validExitNormal, &exitNormal);
2036 daughterStep= -distanceBackOut;
2051 daughterStep = candSolid->
DistanceToIn(dgPosition, dgDirection);
2062 daughterSafety = 0.0;
2071 *prDistance = daughterStep;
2072 if( prNewSafety ) { *prNewSafety= daughterSafety; }
2092 if( ProposedMove >= motherSafety )
2096 true, &validExitNormal, &exitNormal);
2100 motherStep= ProposedMove;
2105 motherSafety= motherSolid->
DistanceToIn(localPosition);
2106 if( ProposedMove >= motherSafety )
2116 if( prNewSafety ) { *prNewSafety= motherSafety; }
2125 *prDistance = std::min( motherStep, daughterStep );
2128 *prNewSafety = std::min( motherSafety, daughterSafety );
2152 G4cout <<
"The current state of G4Navigator is: " <<
G4endl;
2153 G4cout <<
" ValidExitNormal= " << fValidExitNormal
2154 <<
" ExitNormal = " << fExitNormal
2155 <<
" Exiting = " << fExiting
2156 <<
" Entering = " << fEntering
2157 <<
" BlockedPhysicalVolume= " ;
2158 if (fBlockedPhysicalVolume==0)
2167 <<
" BlockedReplicaNo = " << fBlockedReplicaNo
2168 <<
" LastStepWasZero = " << fLastStepWasZero
2174 G4cout << std::setw(30) <<
" ExitNormal " <<
" "
2175 << std::setw( 5) <<
" Valid " <<
" "
2176 << std::setw( 9) <<
" Exiting " <<
" "
2177 << std::setw( 9) <<
" Entering" <<
" "
2178 << std::setw(15) <<
" Blocked:Volume " <<
" "
2179 << std::setw( 9) <<
" ReplicaNo" <<
" "
2180 << std::setw( 8) <<
" LastStepZero " <<
" "
2182 G4cout <<
"( " << std::setw(7) << fExitNormal.
x()
2183 <<
", " << std::setw(7) << fExitNormal.
y()
2184 <<
", " << std::setw(7) << fExitNormal.
z() <<
" ) "
2185 << std::setw( 5) << fValidExitNormal <<
" "
2186 << std::setw( 9) << fExiting <<
" "
2187 << std::setw( 9) << fEntering <<
" ";
2188 if ( fBlockedPhysicalVolume ==
nullptr )
2189 {
G4cout << std::setw(15) <<
"None"; }
2191 {
G4cout << std::setw(15)<< fBlockedPhysicalVolume->
GetName(); }
2192 G4cout << std::setw( 9) << fBlockedReplicaNo <<
" "
2193 << std::setw( 8) << fLastStepWasZero <<
" "
2199 G4cout <<
" Current Localpoint = " << fLastLocatedPointLocal <<
G4endl;
2200 G4cout <<
" PreviousSftOrigin = " << fPreviousSftOrigin <<
G4endl;
2201 G4cout <<
" PreviousSafety = " << fPreviousSafety <<
G4endl;
2203 G4cout.precision(oldcoutPrec);
2210void G4Navigator::ComputeStepLog(
const G4ThreeVector& pGlobalpoint,
2220 InverseTransformPoint(fLastLocatedPointLocal);
2222 G4double shiftOriginSafSq = (fPreviousSftOrigin-pGlobalpoint).mag2();
2230 if( shiftOriginSafSq >=
sqr(fPreviousSafety) )
2232 G4double shiftOrigin = std::sqrt(shiftOriginSafSq);
2233 G4double diffShiftSaf = shiftOrigin - fPreviousSafety;
2235 if( diffShiftSaf > fAccuracyForWarning )
2239 std::ostringstream message, suggestion;
2240 message <<
"Accuracy error or slightly inaccurate position shift."
2242 <<
" The Step's starting point has moved "
2243 << std::sqrt(moveLenSq)/mm <<
" mm " <<
G4endl
2244 <<
" since the last call to a Locate method." <<
G4endl
2245 <<
" This has resulted in moving "
2246 << shiftOrigin/mm <<
" mm "
2247 <<
" from the last point at which the safety "
2248 <<
" was calculated " <<
G4endl
2249 <<
" which is more than the computed safety= "
2251 <<
" This difference is "
2252 << diffShiftSaf/mm <<
" mm." <<
G4endl
2253 <<
" The tolerated accuracy is "
2254 << fAccuracyForException/mm <<
" mm.";
2258 if( ((++warnNow % 100) == 1) )
2261 <<
" This problem can be due to either " <<
G4endl
2262 <<
" - a process that has proposed a displacement"
2263 <<
" larger than the current safety , or" <<
G4endl
2264 <<
" - inaccuracy in the computation of the safety";
2265 suggestion <<
"We suggest that you " <<
G4endl
2266 <<
" - find i) what particle is being tracked, and "
2267 <<
" ii) through what part of your geometry " <<
G4endl
2268 <<
" for example by re-running this event with "
2270 <<
" /tracking/verbose 1 " <<
G4endl
2271 <<
" - check which processes you declare for"
2272 <<
" this particle (and look at non-standard ones)"
2274 <<
" - in case, create a detailed logfile"
2275 <<
" of this event using:" <<
G4endl
2276 <<
" /tracking/verbose 6 ";
2280 message,
G4String(suggestion.str()));
2281 G4cout.precision(oldcoutPrec);
2282 G4cerr.precision(oldcerrPrec);
2284#ifdef G4DEBUG_NAVIGATION
2287 G4cerr <<
"WARNING - G4Navigator::ComputeStep()" <<
G4endl
2288 <<
" The Step's starting point has moved "
2289 << std::sqrt(moveLenSq) <<
"," <<
G4endl
2290 <<
" which has taken it to the limit of"
2291 <<
" the current safety. " <<
G4endl;
2296 if ( shiftOriginSafSq >
sqr(safetyPlus) )
2298 std::ostringstream message;
2299 message <<
"May lead to a crash or unreliable results." <<
G4endl
2300 <<
" Position has shifted considerably without"
2301 <<
" notifying the navigator !" <<
G4endl
2302 <<
" Tolerated safety: " << safetyPlus <<
G4endl
2303 <<
" Computed shift : " << shiftOriginSafSq;
2304 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav1002",
2317 G4bool foundOverlap =
false;
2318 G4int nPoints = 300000, ntrials = 9, numOverlaps = 5;
2319 G4double trialLength = 1.0 * CLHEP::centimeter;
2320 while ( ntrials-- > 0 && !foundOverlap )
2324 G4cout <<
" ** Running overlap checks in volume "
2326 <<
" with length = " << trialLength <<
G4endl;
2331 if ( trialLength <= 1.0e-5 ) { numOverlaps= 1;}
2333 return foundOverlap;
2348 G4int oldcoutPrec = os.precision(4);
2349 if( n.fVerbose >= 4 )
2351 os <<
"The current state of G4Navigator is: " <<
G4endl;
2352 os <<
" ValidExitNormal= " << n.fValidExitNormal <<
G4endl
2353 <<
" ExitNormal = " << n.fExitNormal <<
G4endl
2354 <<
" Exiting = " << n.fExiting <<
G4endl
2355 <<
" Entering = " << n.fEntering <<
G4endl
2356 <<
" BlockedPhysicalVolume= " ;
2357 if (n.fBlockedPhysicalVolume==0)
2360 os << n.fBlockedPhysicalVolume->GetName();
2362 <<
" BlockedReplicaNo = " << n.fBlockedReplicaNo <<
G4endl
2363 <<
" LastStepWasZero = " << n.fLastStepWasZero <<
G4endl
2366 if( ( 1 < n.fVerbose) && (n.fVerbose < 4) )
2369 os << std::setw(30) <<
" ExitNormal " <<
" "
2370 << std::setw( 5) <<
" Valid " <<
" "
2371 << std::setw( 9) <<
" Exiting " <<
" "
2372 << std::setw( 9) <<
" Entering" <<
" "
2373 << std::setw(15) <<
" Blocked:Volume " <<
" "
2374 << std::setw( 9) <<
" ReplicaNo" <<
" "
2375 << std::setw( 8) <<
" LastStepZero " <<
" "
2377 os <<
"( " << std::setw(7) << n.fExitNormal.x()
2378 <<
", " << std::setw(7) << n.fExitNormal.y()
2379 <<
", " << std::setw(7) << n.fExitNormal.z() <<
" ) "
2380 << std::setw( 5) << n.fValidExitNormal <<
" "
2381 << std::setw( 9) << n.fExiting <<
" "
2382 << std::setw( 9) << n.fEntering <<
" ";
2383 if ( n.fBlockedPhysicalVolume==0 )
2384 { os << std::setw(15) <<
"None"; }
2386 { os << std::setw(15)<< n.fBlockedPhysicalVolume->GetName(); }
2387 os << std::setw( 9) << n.fBlockedReplicaNo <<
" "
2388 << std::setw( 8) << n.fLastStepWasZero <<
" "
2391 if( n.fVerbose > 2 )
2394 os <<
" Current Localpoint = " << n.fLastLocatedPointLocal <<
G4endl;
2395 os <<
" PreviousSftOrigin = " << n.fPreviousSftOrigin <<
G4endl;
2396 os <<
" PreviousSafety = " << n.fPreviousSafety <<
G4endl;
2398 if( n.fVerbose > 3 || n.fVerbose == 0 )
2400 os <<
"Current History: " <<
G4endl << n.fHistory;
2403 os.precision(oldcoutPrec);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4DEBUG_NAVIGATION
#define fExitNormalGlobalFrame
std::ostream & operator<<(std::ostream &os, const G4Navigator &n)
CLHEP::Hep3Vector G4ThreeVector
G4ReferenceCountedHandle< G4TouchableHistory > G4TouchableHistoryHandle
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
EVolume CharacteriseDaughters() const
const G4String & GetName() const
void SetSolid(G4VSolid *pSolid)
G4SmartVoxelHeader * GetVoxelHeader() const
void UpdateMaterial(G4Material *pMaterial)
EVolume GetTopVolumeType() const
void NewLevel(G4VPhysicalVolume *pNewMother, EVolume vType=kNormal, G4int nReplica=-1)
G4int GetReplicaNo(G4int n) const
const G4AffineTransform & GetTopTransform() const
G4int GetTopReplicaNo() const
G4VPhysicalVolume * GetVolume(G4int n) const
G4VPhysicalVolume * GetTopVolume() const
EVolume GetVolumeType(G4int n) const
const G4AffineTransform & GetTransform(G4int n) const
void SetVerboseLevel(G4int level)
virtual void SetupHierarchy()
G4TouchableHistory * CreateTouchableHistory() const
G4ThreeVector fStepEndPoint
G4int GetVerboseLevel() const
virtual void ResetState()
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
EVolume VolumeType(const G4VPhysicalVolume *pVol) const
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
G4ThreeVector fLastStepEndPointLocal
G4bool fWasLimitedByGeometry
G4bool CheckOverlapsIterative(G4VPhysicalVolume *vol)
EVolume CharacteriseDaughters(const G4LogicalVolume *pLog) const
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &rGlobPoint) const
virtual G4TouchableHistoryHandle CreateTouchableHistoryHandle() const
G4ThreeVector ComputeLocalAxis(const G4ThreeVector &pVec) const
virtual G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &point, G4bool *valid)
virtual G4ThreeVector GetLocalExitNormal(G4bool *valid)
virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4AffineTransform GetMotherToDaughterTransform(G4VPhysicalVolume *dVolume, G4int dReplicaNo, EVolume dVolumeType)
void ResetStackAndState()
G4bool EnteredDaughterVolume() const
G4double CheckNextStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
G4int GetDaughtersRegularStructureId(const G4LogicalVolume *pLv) const
G4NavigationHistory fHistory
const G4AffineTransform & GetGlobalToLocalTransform() const
virtual G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double CurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=nullptr) const
G4double ComputeStep(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
G4SmartVoxelNode * ParamVoxelLocate(G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint)
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
void SetNormalNavigation(G4NormalNavigation *fnormnav)
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
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 ComputeSafety(const G4ThreeVector &globalPoint, const G4ThreeVector &localPoint, G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
void ComputeTransformation(const G4int replicaNo, G4VPhysicalVolume *pVol, G4ThreeVector &point) const
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
EInside BackLocate(G4NavigationHistory &history, const G4ThreeVector &globalPoint, G4ThreeVector &localPoint, const G4bool &exiting, G4bool ¬KnownInside) const
const G4NavigationHistory * GetHistory() const
G4int MoveUpHistory(G4int num_levels=1)
virtual void RelocateWithinVolume(G4VPhysicalVolume *motherPhysical, const G4ThreeVector &localPoint)
virtual G4double ComputeStep(const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume **pBlockedPhysical, G4int &blockedReplicaNo)=0
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)=0
virtual EInside Inside(const G4VSolid *solid, const G4ThreeVector &position, const G4ThreeVector &direction)
virtual G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)=0
virtual G4VSolid * ComputeSolid(const G4int, G4VPhysicalVolume *)
virtual void ComputeTransformation(const G4int, G4VPhysicalVolume *) const =0
virtual G4bool IsNested() const
const G4RotationMatrix * GetRotation() const
virtual void SetCopyNo(G4int CopyNo)=0
const G4ThreeVector GetTranslation() const
virtual G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int errMax=1)
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
virtual G4int GetRegularStructureId() const =0
virtual G4VPVParameterisation * GetParameterisation() const =0
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
virtual G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &globalDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo)
G4SmartVoxelNode * VoxelLocate(G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint)
virtual G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4VPhysicalVolume ¤tPhysical, G4double maxLength=DBL_MAX)