64 G4cout <<
" G4Navigator parameters: Action Threshold (No Zero Steps) = "
66 <<
" Abandon Threshold (No Zero Steps) = "
128 const G4bool relativeSearch,
129 const G4bool ignoreDirection )
131 G4bool notKnownContained =
true, noResult;
143 if( considerDirection && pGlobalDirection !=
nullptr )
145 globalDirection=*pGlobalDirection;
152 G4cout <<
"*** G4Navigator::LocateGlobalPointAndSetup: ***" <<
G4endl;
153 G4cout <<
" Called with arguments: " << G4endl
154 <<
" Globalpoint = " << globalPoint << G4endl
155 <<
" RelativeSearch = " << relativeSearch <<
G4endl;
161 G4cout.precision(oldcoutPrec);
165 G4int noLevelsExited = 0;
166 G4int noLevelsEntered = 0;
168 if ( !relativeSearch )
265 G4Exception(
"G4Navigator::LocateGlobalPointAndSetup()",
267 "Extra levels not applicable for external volumes.");
273 notKnownContained =
false;
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;
349 if( noLevelsExited > 1 )
373 if( (!
fExiting) && considerDirection )
378 G4bool directionExiting =
false;
389 directionExiting = normal.
dot(localDirection) > 0.0;
390 isExiting = isExiting || directionExiting;
406 if( noLevelsExited > 1 )
429 notKnownContained =
false;
434 notKnownContained =
false;
455 if (!targetPhysical) {
break; }
557 #ifdef G4DEBUG_NAVIGATION
561 G4cout <<
"*** G4Navigator::LocateGlobalPointAndSetup() ***" <<
G4endl;
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);
591 return targetPhysical;
610 #ifdef G4DEBUG_NAVIGATION
766 const G4double pCurrentProposedStepLength,
792 G4cout <<
"*** G4Navigator::ComputeStep: ***" <<
G4endl;
794 <<
" - Proposed step length = " << pCurrentProposedStepLength
796 #ifdef G4DEBUG_NAVIGATION
799 G4cout <<
" Called with the arguments: " << G4endl
800 <<
" Globalpoint = " << std::setw(25) << pGlobalpoint << G4endl
801 <<
" Direction = " << std::setw(25) << pDirection <<
G4endl;
818 G4double moveLenSq = (newLocalPoint-oldLocalPoint).mag2();
820 if ( moveLenSq >=
fSqTol )
840 pCurrentProposedStepLength,
857 pCurrentProposedStepLength,
885 "Point is relocated in voxels, while it should be outside!");
888 pCurrentProposedStepLength,
903 pCurrentProposedStepLength,
922 pCurrentProposedStepLength,
936 pCurrentProposedStepLength,
948 G4Exception(
"G4Navigator::ComputeStep()",
"GeomNav0001",
954 pCurrentProposedStepLength,
972 G4bool calculatedExitNormal;
977 pCurrentProposedStepLength,
981 calculatedExitNormal,
1017 G4bool actAndReport =
false;
1023 #ifdef G4DEBUG_NAVIGATION
1027 if ( act || inform )
1029 if( act && !abandon )
1037 if( actAndReport || abandon || inform )
1041 message.precision(16);
1042 message <<
"Stuck Track: potential geometry or navigation problem."
1044 message <<
" Track stuck, not moving for "
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: '"
1054 <<
"'" << G4endl << G4endl;
1055 if( actAndReport || abandon )
1057 message <<
" Likely geometry overlap - else navigation problem !"
1066 message <<
" Track *abandoned* due to excessive number of Zero steps."
1067 <<
" Event aborted. " << G4endl <<
G4endl;
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
1088 message <<
", nav-comp-step calls # " << sNavCScalls
1089 <<
", Step= " << Step <<
G4endl;
1108 +
std::min(Step,pCurrentProposedStepLength) * pDirection;
1113 #ifdef G4DEBUG_NAVIGATION
1116 G4cout <<
" At G4Nav CompStep End - if(exiting) - fExiting= " <<
fExiting
1141 + localDirection*Step;
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.");
1229 G4cout <<
" Returned step= " << Step;
1233 G4cout <<
" Requested step= " << pCurrentProposedStepLength ;
1251 const G4double pCurrentProposedStepLength,
1262 pCurrentProposedStepLength,
1330 for (
auto i=1; i<=cdepth; ++i )
1369 ComputeMaterial(replicaNo, current, pTouchable) );
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
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",
1497 "Incorrect call to GetLocalSurfaceNormal." );
1510 desc <<
" Parameters of solid: " << *daughterSolid
1514 "Surface Normal returned by Solid is not a Unit Vector." );
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
1613 G4ThreeVector ExpectedBoundaryPointLocal;
1616 ExpectedBoundaryPointLocal =
1637 G4bool* pNormalCalculated)
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
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.");
1711 #ifdef G4DEBUG_NAVIGATION
1712 usingStored =
false;
1721 edN <<
" State of Navigator: " <<
G4endl;
1727 "LocalExitNormalAndCheck() did not calculate Normal.");
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;
1757 "Value obtained from new local *solid* is incorrect.");
1758 localNormal = localNormal.
unit();
1764 #ifdef G4DEBUG_NAVIGATION
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;
1782 edDfn <<
" Normal stored (Global) = " << fExitNormalGlobalFrame
1784 edDfn <<
" Global Computed from Local = " << globalNormAgn <<
G4endl;
1785 G4Exception(
"G4Navigator::GetGlobalExitNormal()",
"GeomNav0003",
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",
1942 #ifdef G4DEBUG_NAVIGATION
1947 G4cout <<
" Returned value of Safety = " << newSafety <<
G4endl;
1949 G4cout.precision(oldcoutPrec);
1990 #ifdef CHECK_ORDER_OF_METHODS
1993 G4Exception(
"G4Navigator::RecheckDistanceToCurrentBoundary()",
1995 "Method must be called after ComputeStep(), before call to LocateMethod.");
2024 G4ThreeVector dgPosition = nextLevelTrf.TransformPoint(localPosition);
2025 G4ThreeVector dgDirection = nextLevelTrf.TransformAxis(localDirection);
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;
2157 <<
" BlockedPhysicalVolume= " ;
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 " <<
" "
2186 << std::setw( 9) <<
fExiting <<
" "
2189 {
G4cout << std::setw(15) <<
"None"; }
2203 G4cout.precision(oldcoutPrec);
2232 G4double shiftOrigin = std::sqrt(shiftOriginSafSq);
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= "
2250 << fPreviousSafety/
mm <<
" mm at that point." <<
G4endl
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) )
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;
2320 while ( ntrials-- > 0 && !foundOverlap )
2324 G4cout <<
" ** Running overlap checks in volume "
2326 <<
" with length = " << trialLength <<
G4endl;
2331 if ( trialLength <= 1.0
e-5 ) { numOverlaps= 1;}
2333 return foundOverlap;
2348 G4int oldcoutPrec = os.precision(4);
2351 os <<
"The current state of G4Navigator is: " <<
G4endl;
2354 <<
" Exiting = " << n.
fExiting << G4endl
2355 <<
" Entering = " << n.
fEntering << G4endl
2356 <<
" BlockedPhysicalVolume= " ;
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 " <<
" "
2381 << std::setw( 9) << n.
fExiting <<
" "
2384 { os << std::setw(15) <<
"None"; }
2403 os.precision(oldcoutPrec);