52 #define G4DEBUG_NAVIGATION 1
59 : fWasLimitedByGeometry(false), fVerbose(0),
60 fTopPhysical(0), fCheck(false), fPushed(false), fWarnPush(true)
63 fLastTriedStepComputation=
false;
66 fActionThreshold_NoZeroSteps = 10;
67 fAbandonThreshold_NoZeroSteps = 25;
85 sWasLimitedByGeometry =
false;
88 sLocatedOnEdge =
false;
89 sLastStepWasZero =
false;
90 sEnteredDaughter =
false;
91 sExitedMother =
false;
94 sValidExitNormal =
false;
98 sPreviousSafety = 0.0;
100 sNumberZeroSteps = 0;
102 spBlockedPhysicalVolume = 0;
103 sBlockedReplicaNo = -1;
105 sLastLocatedPointLocal =
G4ThreeVector( kInfinity, -kInfinity, 0.0 );
106 sLocatedOutsideWorld =
false;
130 fLastTriedStepComputation=
false;
153 const G4bool relativeSearch,
154 const G4bool ignoreDirection )
156 G4bool notKnownContained=
true, noResult;
163 G4bool considerDirection = (!ignoreDirection) || fLocatedOnEdge;
164 fLastTriedStepComputation=
false;
166 if( considerDirection && pGlobalDirection != 0 )
168 globalDirection=*pGlobalDirection;
175 G4cout <<
"*** G4ITNavigator::LocateGlobalPointAndSetup: ***" <<
G4endl;
176 G4cout <<
" Called with arguments: " << G4endl
177 <<
" Globalpoint = " << globalPoint << G4endl
178 <<
" RelativeSearch = " << relativeSearch <<
G4endl;
184 G4cout.precision(oldcoutPrec);
188 if ( !relativeSearch )
209 fLastLocatedPointLocal = localPoint;
210 fLocatedOutsideWorld =
true;
234 fBlockedPhysicalVolume);
237 fBlockedPhysicalVolume->
SetCopyNo(fBlockedReplicaNo);
247 fBlockedPhysicalVolume);
249 fBlockedPhysicalVolume);
251 fBlockedPhysicalVolume);
254 fBlockedPhysicalVolume->
SetCopyNo(fBlockedReplicaNo);
262 ComputeMaterial(fBlockedReplicaNo,
263 fBlockedPhysicalVolume,
269 fBlockedPhysicalVolume = 0;
271 notKnownContained =
false;
276 fBlockedPhysicalVolume = 0;
292 while (notKnownContained)
298 insideCode = targetSolid->
Inside(localPoint);
302 G4String solidResponse =
"-kInside-";
304 solidResponse =
"-kOutside-";
306 solidResponse =
"-kSurface-";
307 G4cout <<
"*** G4ITNavigator::LocateGlobalPointAndSetup(): ***" <<
G4endl
308 <<
" Invoked Inside() for solid: " << targetSolid->
GetName()
309 <<
". Solid replied: " << solidResponse <<
G4endl
310 <<
" For local point p: " << localPoint <<
G4endl;
317 fExiting, notKnownContained);
334 fLastLocatedPointLocal = localPoint;
335 fLocatedOutsideWorld =
true;
342 G4bool isExiting = fExiting;
343 if( (!fExiting)&&considerDirection )
348 G4bool directionExiting =
false;
354 directionExiting = normal.
dot(localDirection) > 0.0;
355 isExiting = isExiting || directionExiting;
368 fValidExitNormal =
false;
372 fLastLocatedPointLocal = localPoint;
373 fLocatedOutsideWorld =
true;
379 notKnownContained=
false;
384 notKnownContained=
false;
405 if (!targetPhysical) {
break; }
413 fBlockedPhysicalVolume,
423 fBlockedPhysicalVolume,
433 fBlockedPhysicalVolume,
444 fBlockedPhysicalVolume,
454 fBlockedPhysicalVolume,
473 fBlockedPhysicalVolume = 0;
474 fBlockedReplicaNo = -1;
481 #ifdef G4DEBUG_NAVIGATION
485 G4cout <<
"*** G4ITNavigator::LocateGlobalPointAndSetup() ***" <<
G4endl;
493 fLastLocatedPointLocal = localPoint;
500 if (targetPhysical) { curPhysVol_Name = targetPhysical->
GetName(); }
501 G4cout <<
" Return value = new volume = " << curPhysVol_Name <<
G4endl;
504 #ifdef G4DEBUG_NAVIGATION
505 G4cout <<
"Upon exiting LocateGlobalPointAndSetup():" <<
G4endl;
508 G4cout.precision(oldcoutPrec);
512 fLocatedOutsideWorld=
false;
514 return targetPhysical;
534 fLastTriedStepComputation=
false;
536 #ifdef G4DEBUG_NAVIGATION
539 G4cout <<
"Entering LocateGlobalWithinVolume(): History = " <<
G4endl;
561 fvoxelNav.
VoxelLocate( pVoxelHeader, fLastLocatedPointLocal );
573 G4Exception(
"G4ITNavigator::LocateGlobalPointWithinVolume()",
575 "Not applicable for replicated volumes.");
585 fBlockedPhysicalVolume = 0;
586 fBlockedReplicaNo = -1;
602 fpSaveState = (G4SaveNavigatorState*) navState;
608 fpSaveState =
new G4SaveNavigatorState();
633 fpSaveState->sExitNormal = fExitNormal;
634 fpSaveState->sValidExitNormal = fValidExitNormal;
635 fpSaveState->sExiting = fExiting;
636 fpSaveState->sEntering = fEntering;
638 fpSaveState->spBlockedPhysicalVolume = fBlockedPhysicalVolume;
639 fpSaveState->sBlockedReplicaNo = fBlockedReplicaNo,
641 fpSaveState->sLastStepWasZero = fLastStepWasZero;
644 fpSaveState->sPreviousSftOrigin = fPreviousSftOrigin;
645 fpSaveState->sPreviousSafety = fPreviousSafety;
646 fpSaveState->sNumberZeroSteps = fNumberZeroSteps;
647 fpSaveState->sLocatedOnEdge = fLocatedOnEdge;
649 fpSaveState->sPushed=fPushed;
650 fpSaveState->sNumberZeroSteps=fNumberZeroSteps;
654 fpSaveState->sLastLocatedPointLocal = fLastLocatedPointLocal;
655 fpSaveState->sLocatedOutsideWorld = fLocatedOutsideWorld;
667 fExitNormal = fpSaveState->sExitNormal;
668 fValidExitNormal = fpSaveState->sValidExitNormal;
669 fExiting = fpSaveState->sExiting;
670 fEntering = fpSaveState->sEntering;
672 fBlockedPhysicalVolume = fpSaveState->spBlockedPhysicalVolume;
673 fBlockedReplicaNo = fpSaveState->sBlockedReplicaNo,
675 fLastStepWasZero = fpSaveState->sLastStepWasZero;
678 fPreviousSftOrigin = fpSaveState->sPreviousSftOrigin ;
679 fPreviousSafety = fpSaveState->sPreviousSafety ;
680 fNumberZeroSteps = fpSaveState->sNumberZeroSteps ;
681 fLocatedOnEdge = fpSaveState->sLocatedOnEdge ;
683 fPushed = fpSaveState->sPushed;
684 fNumberZeroSteps = fpSaveState->sNumberZeroSteps;
688 fLastLocatedPointLocal = fpSaveState->sLastLocatedPointLocal ;
689 fLocatedOutsideWorld = fpSaveState->sLocatedOutsideWorld;
727 const G4double pCurrentProposedStepLength,
735 static G4int sNavCScalls=0;
738 fLastTriedStepComputation=
true;
743 G4cout <<
"*** G4ITNavigator::ComputeStep: ***" <<
G4endl;
745 <<
" - Proposed step length = " << pCurrentProposedStepLength
747 #ifdef G4DEBUG_NAVIGATION
750 G4cout <<
" Called with the arguments: " << G4endl
751 <<
" Globalpoint = " << std::setw(25) << pGlobalpoint << G4endl
752 <<
" Direction = " << std::setw(25) << pDirection <<
G4endl;
761 if( newLocalPoint != fLastLocatedPointLocal )
766 G4double moveLenSq = (newLocalPoint-oldLocalPoint).mag2();
771 ComputeStepLog(pGlobalpoint, moveLenSq);
776 fLastTriedStepComputation=
true;
786 Step = fvoxelNav.
ComputeStep(fLastLocatedPointLocal,
788 pCurrentProposedStepLength,
795 &fBlockedPhysicalVolume,
803 Step = fnormalNav.
ComputeStep(fLastLocatedPointLocal,
805 pCurrentProposedStepLength,
812 &fBlockedPhysicalVolume,
818 fLastTriedStepComputation=
true;
833 "Point is relocated in voxels, while it should be outside!");
834 Step = fnormalNav.
ComputeStep(fLastLocatedPointLocal,
836 pCurrentProposedStepLength,
843 &fBlockedPhysicalVolume,
849 ComputeStepSkippingEqualMaterials(fLastLocatedPointLocal,
851 pCurrentProposedStepLength,
858 &fBlockedPhysicalVolume,
868 Step = fparamNav.
ComputeStep(fLastLocatedPointLocal,
870 pCurrentProposedStepLength,
877 &fBlockedPhysicalVolume,
882 Step = fregularNav.
ComputeStep(fLastLocatedPointLocal,
884 pCurrentProposedStepLength,
891 &fBlockedPhysicalVolume,
896 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav0001",
907 G4bool calculatedExitNormal=
false;
911 fLastLocatedPointLocal,
913 pCurrentProposedStepLength,
917 calculatedExitNormal,
921 &fBlockedPhysicalVolume,
923 fExiting= exitingReplica;
928 fPreviousSftOrigin = pGlobalpoint;
929 fPreviousSafety = pNewSafety;
941 fLocatedOnEdge = fLastStepWasZero && (Step==0.0);
942 fLastStepWasZero = (Step==0.0);
943 if (fPushed) fPushed = fLastStepWasZero;
947 if ( fLastStepWasZero )
950 #ifdef G4DEBUG_NAVIGATION
951 if( fNumberZeroSteps > 1 )
953 G4cout <<
"G4ITNavigator::ComputeStep(): another zero step, # "
955 <<
" at " << pGlobalpoint
956 <<
" in volume " << motherPhysical->
GetName()
957 <<
" nav-comp-step calls # " << sNavCScalls
961 if( fNumberZeroSteps > fActionThreshold_NoZeroSteps-1 )
967 if ((!fPushed) && (fWarnPush))
969 std::ostringstream message;
970 message <<
"Track stuck or not moving." <<
G4endl
971 <<
" Track stuck, not moving for "
972 << fNumberZeroSteps <<
" steps" <<
G4endl
973 <<
" in volume -" << motherPhysical->
GetName()
974 <<
"- at point " << pGlobalpoint <<
G4endl
975 <<
" direction: " << pDirection <<
"." <<
G4endl
976 <<
" Potential geometry or navigation problem !"
978 <<
" Trying pushing it of " << Step <<
" mm ...";
979 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav1002",
980 JustWarning, message,
"Potential overlap in geometry!");
985 if( fNumberZeroSteps > fAbandonThreshold_NoZeroSteps-1 )
989 std::ostringstream message;
990 message <<
"Stuck Track: potential geometry or navigation problem."
992 <<
" Track stuck, not moving for "
993 << fNumberZeroSteps <<
" steps" <<
G4endl
994 <<
" in volume -" << motherPhysical->
GetName()
995 <<
"- at point " << pGlobalpoint <<
G4endl
996 <<
" direction: " << pDirection <<
".";
998 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav0003",
1004 if (!fPushed) fNumberZeroSteps = 0;
1015 #ifdef G4DEBUG_NAVIGATION
1018 G4cout <<
" At G4Nav CompStep End - if(exiting) - fExiting= " << fExiting
1019 <<
" fValidExitNormal = " << fValidExitNormal <<
G4endl;
1024 if(fValidExitNormal)
1028 fGrandMotherExitNormal= fExitNormal;
1035 fLastLocatedPointLocal + localDirection*Step;
1039 fGrandMotherExitNormal =
1045 fGrandMotherExitNormal *= (*mRot).inverse();
1052 if( (Step == pCurrentProposedStepLength) && (!fExiting) && (!fEntering) )
1069 if( Step == kInfinity )
1071 G4cout <<
" Original proposed step = "
1072 << pCurrentProposedStepLength <<
G4endl;
1089 const G4double pCurrentProposedStepLength,
1100 pCurrentProposedStepLength,
1121 fLocatedOnEdge =
false;
1122 fLastStepWasZero =
false;
1127 fValidExitNormal =
false;
1131 fPreviousSafety = 0.0;
1133 fNumberZeroSteps = 0;
1135 fBlockedPhysicalVolume = 0;
1136 fBlockedReplicaNo = -1;
1138 fLastLocatedPointLocal =
G4ThreeVector( kInfinity, -kInfinity, 0.0 );
1139 fLocatedOutsideWorld =
false;
1158 for ( i=1; i<=cdepth; i++ )
1187 ComputeMaterial(replicaNo, current, &touchable) );
1205 if ( fLastTriedStepComputation )
1211 if( fEntering && (fBlockedPhysicalVolume!=0) )
1214 if( candidateLogical )
1235 currentSolid= candidateLogical->
GetSolid();
1236 inSideIt = currentSolid->
Inside(daughterPointOwnLocal);
1237 onSurface = (inSideIt ==
kSurface);
1242 safety = (currentSolid->
DistanceToIn(daughterPointOwnLocal));
1245 else if (inSideIt ==
kInside )
1247 safety = (currentSolid->
DistanceToOut(daughterPointOwnLocal));
1254 nextSolidExitNormal =
1259 ExitNormal = -nextSolidExitNormal;
1264 if((
fVerbose == 1 ) && ( fCheck ))
1266 std::ostringstream message;
1267 message <<
"Point not on surface ! " <<
G4endl
1269 << daughterPointOwnLocal <<
G4endl
1270 <<
" Physical volume = "
1272 <<
" Logical volume = "
1274 <<
" Solid = " << currentSolid->
GetName()
1277 << *currentSolid <<
G4endl;
1280 message <<
"Point is Outside. " << G4endl
1281 <<
" Safety (from outside) = " << safety <<
G4endl;
1285 message <<
"Point is Inside. " << G4endl
1286 <<
" Safety (from inside) = " << safety <<
G4endl;
1288 G4Exception(
"G4ITNavigator::GetLocalExitNormal()",
"GeomNav1001",
1298 #ifdef G4DEBUG_NAVIGATION
1299 G4Exception(
"G4ITNavigator::GetLocalExitNormal()",
"GeomNav0001",
1301 "Local normal not (yet) available for replica volumes.");
1306 else if ( fExiting )
1308 ExitNormal = fGrandMotherExitNormal;
1321 GetSolid()->SurfaceNormal(fLastLocatedPointLocal));
1328 ExitNormal = fGrandMotherExitNormal;
1348 G4int enteringReplicaNo,
1351 switch (enteringVolumeType)
1356 G4Exception(
"G4ITNavigator::GetMotherToDaughterTransform()",
1358 "Method NOT Implemented yet for replica volumes.");
1366 pParam->
ComputeSolid(enteringReplicaNo, pEnteringPhysVol);
1400 if ( fLastTriedStepComputation )
1403 ExpectedBoundaryPointLocal =
1425 *pValidNormal = validNormal;
1429 return globalNormal;
1447 #ifdef G4DEBUG_NAVIGATION
1451 G4cout <<
"*** G4ITNavigator::ComputeSafety: ***" <<
G4endl
1452 <<
" Called at point: " << pGlobalpoint <<
G4endl;
1456 <<
" - Maximum length = " << pMaxLength <<
G4endl;
1459 G4cout <<
" ----- Upon entering Compute Safety:" <<
G4endl;
1472 if( !(endpointOnSurface && stayedOnEndpoint) )
1485 #ifdef G4DEBUG_NAVIGATION
1488 G4cout <<
" G4ITNavigator::ComputeSafety() relocates-in-volume to point: "
1489 << pGlobalpoint <<
G4endl;
1522 G4Exception(
"G4ITNavigator::ComputeSafety()",
"NotApplicable",
1529 newSafety = freplicaNav.
ComputeSafety(pGlobalpoint, localPoint,
1535 #ifdef G4DEBUG_NAVIGATION
1538 G4cout <<
" G4ITNavigator::ComputeSafety() finds that point - "
1539 << pGlobalpoint <<
" - is on surface " <<
G4endl;
1551 fPreviousSftOrigin = pGlobalpoint;
1552 fPreviousSafety = newSafety;
1556 #ifdef G4DEBUG_NAVIGATION
1561 G4cout <<
" Returned value of Safety = " << newSafety <<
G4endl;
1563 G4cout.precision(oldcoutPrec);
1587 G4cout <<
"The current state of G4ITNavigator is: " <<
G4endl;
1588 G4cout <<
" ValidExitNormal= " << fValidExitNormal << G4endl
1589 <<
" ExitNormal = " << fExitNormal << G4endl
1590 <<
" Exiting = " << fExiting << G4endl
1591 <<
" Entering = " << fEntering << G4endl
1592 <<
" BlockedPhysicalVolume= " ;
1593 if (fBlockedPhysicalVolume==0)
1598 <<
" BlockedReplicaNo = " << fBlockedReplicaNo << G4endl
1599 <<
" LastStepWasZero = " << fLastStepWasZero << G4endl
1604 G4cout << std::setw(30) <<
" ExitNormal " <<
" "
1605 << std::setw( 5) <<
" Valid " <<
" "
1606 << std::setw( 9) <<
" Exiting " <<
" "
1607 << std::setw( 9) <<
" Entering" <<
" "
1608 << std::setw(15) <<
" Blocked:Volume " <<
" "
1609 << std::setw( 9) <<
" ReplicaNo" <<
" "
1610 << std::setw( 8) <<
" LastStepZero " <<
" "
1612 G4cout <<
"( " << std::setw(7) << fExitNormal.
x()
1613 <<
", " << std::setw(7) << fExitNormal.
y()
1614 <<
", " << std::setw(7) << fExitNormal.
z() <<
" ) "
1615 << std::setw( 5) << fValidExitNormal <<
" "
1616 << std::setw( 9) << fExiting <<
" "
1617 << std::setw( 9) << fEntering <<
" ";
1618 if ( fBlockedPhysicalVolume==0 )
1619 G4cout << std::setw(15) <<
"None";
1621 G4cout << std::setw(15)<< fBlockedPhysicalVolume->
GetName();
1622 G4cout << std::setw( 9) << fBlockedReplicaNo <<
" "
1623 << std::setw( 8) << fLastStepWasZero <<
" "
1629 G4cout <<
" Current Localpoint = " << fLastLocatedPointLocal <<
G4endl;
1630 G4cout <<
" PreviousSftOrigin = " << fPreviousSftOrigin <<
G4endl;
1631 G4cout <<
" PreviousSafety = " << fPreviousSafety <<
G4endl;
1633 G4cout.precision(oldcoutPrec);
1640 void G4ITNavigator::ComputeStepLog(
const G4ThreeVector& pGlobalpoint,
1650 TransformPoint(fLastLocatedPointLocal);
1652 G4double shiftOriginSafSq = (fPreviousSftOrigin-pGlobalpoint).mag2();
1660 if( shiftOriginSafSq >=
sqr(fPreviousSafety) )
1662 G4double shiftOrigin = std::sqrt(shiftOriginSafSq);
1663 G4double diffShiftSaf = shiftOrigin - fPreviousSafety;
1665 if( diffShiftSaf > fAccuracyForWarning )
1669 std::ostringstream message, suggestion;
1670 message <<
"Accuracy error or slightly inaccurate position shift."
1672 <<
" The Step's starting point has moved "
1673 << std::sqrt(moveLenSq)/
mm <<
" mm " <<
G4endl
1674 <<
" since the last call to a Locate method." <<
G4endl
1675 <<
" This has resulted in moving "
1676 << shiftOrigin/
mm <<
" mm "
1677 <<
" from the last point at which the safety "
1678 <<
" was calculated " <<
G4endl
1679 <<
" which is more than the computed safety= "
1680 << fPreviousSafety/
mm <<
" mm at that point." <<
G4endl
1681 <<
" This difference is "
1682 << diffShiftSaf/
mm <<
" mm." <<
G4endl
1683 <<
" The tolerated accuracy is "
1684 << fAccuracyForException/
mm <<
" mm.";
1687 static G4int warnNow = 0;
1688 if( ((++warnNow % 100) == 1) )
1691 <<
" This problem can be due to either " <<
G4endl
1692 <<
" - a process that has proposed a displacement"
1693 <<
" larger than the current safety , or" <<
G4endl
1694 <<
" - inaccuracy in the computation of the safety";
1695 suggestion <<
"We suggest that you " << G4endl
1696 <<
" - find i) what particle is being tracked, and "
1697 <<
" ii) through what part of your geometry " << G4endl
1698 <<
" for example by re-running this event with "
1700 <<
" /tracking/verbose 1 " << G4endl
1701 <<
" - check which processes you declare for"
1702 <<
" this particle (and look at non-standard ones)"
1704 <<
" - in case, create a detailed logfile"
1705 <<
" of this event using:" << G4endl
1706 <<
" /tracking/verbose 6 ";
1710 message,
G4String(suggestion.str()));
1711 G4cout.precision(oldcoutPrec);
1712 G4cerr.precision(oldcerrPrec);
1714 #ifdef G4DEBUG_NAVIGATION
1717 G4cerr <<
"WARNING - G4ITNavigator::ComputeStep()" <<
G4endl
1718 <<
" The Step's starting point has moved "
1719 << std::sqrt(moveLenSq) <<
"," <<
G4endl
1720 <<
" which has taken it to the limit of"
1721 <<
" the current safety. " <<
G4endl;
1725 G4double safetyPlus = fPreviousSafety + fAccuracyForException;
1726 if ( shiftOriginSafSq >
sqr(safetyPlus) )
1728 std::ostringstream message;
1729 message <<
"May lead to a crash or unreliable results." <<
G4endl
1730 <<
" Position has shifted considerably without"
1731 <<
" notifying the navigator !" <<
G4endl
1732 <<
" Tolerated safety: " << safetyPlus <<
G4endl
1733 <<
" Computed shift : " << shiftOriginSafSq;
1734 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav1002",