52 #define G4DEBUG_NAVIGATION 1
59 : fWasLimitedByGeometry(false), fVerbose(0),
60 fTopPhysical(0), fCheck(false), fPushed(false), fWarnPush(true)
153 const G4bool relativeSearch,
154 const G4bool ignoreDirection )
156 G4bool notKnownContained=
true, noResult;
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 )
271 notKnownContained =
false;
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;
343 if( (!
fExiting)&&considerDirection )
348 G4bool directionExiting =
false;
354 directionExiting = normal.dot(localDirection) > 0.0;
355 isExiting = isExiting || directionExiting;
379 notKnownContained=
false;
384 notKnownContained=
false;
405 if (!targetPhysical) {
break; }
481 #ifdef G4DEBUG_NAVIGATION
485 G4cout <<
"*** G4ITNavigator::LocateGlobalPointAndSetup() ***" <<
G4endl;
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);
514 return targetPhysical;
536 #ifdef G4DEBUG_NAVIGATION
539 G4cout <<
"Entering LocateGlobalWithinVolume(): History = " <<
G4endl;
573 G4Exception(
"G4ITNavigator::LocateGlobalPointWithinVolume()",
575 "Not applicable for replicated volumes.");
727 const G4double pCurrentProposedStepLength,
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;
766 G4double moveLenSq = (newLocalPoint-oldLocalPoint).mag2();
788 pCurrentProposedStepLength,
805 pCurrentProposedStepLength,
833 "Point is relocated in voxels, while it should be outside!");
836 pCurrentProposedStepLength,
851 pCurrentProposedStepLength,
870 pCurrentProposedStepLength,
884 pCurrentProposedStepLength,
896 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav0001",
907 G4bool calculatedExitNormal=
false;
913 pCurrentProposedStepLength,
917 calculatedExitNormal,
950 #ifdef G4DEBUG_NAVIGATION
953 G4cout <<
"G4ITNavigator::ComputeStep(): another zero step, # "
955 <<
" at " << pGlobalpoint
956 <<
" in volume " << motherPhysical->
GetName()
957 <<
" nav-comp-step calls # " << sNavCScalls
969 std::ostringstream message;
970 message <<
"Track stuck or not moving." <<
G4endl
971 <<
" Track stuck, not moving for "
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!");
989 std::ostringstream message;
990 message <<
"Stuck Track: potential geometry or navigation problem."
992 <<
" Track stuck, not moving for "
994 <<
" in volume -" << motherPhysical->
GetName()
995 <<
"- at point " << pGlobalpoint <<
G4endl
996 <<
" direction: " << pDirection <<
".";
998 G4Exception(
"G4ITNavigator::ComputeStep()",
"GeomNav0003",
1015 #ifdef G4DEBUG_NAVIGATION
1018 G4cout <<
" At G4Nav CompStep End - if(exiting) - fExiting= " <<
fExiting
1071 G4cout <<
" Original proposed step = "
1072 << pCurrentProposedStepLength <<
G4endl;
1089 const G4double pCurrentProposedStepLength,
1100 pCurrentProposedStepLength,
1158 for ( i=1; i<=cdepth; i++ )
1187 ComputeMaterial(replicaNo, current, &touchable) );
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;
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.");
1348 G4int enteringReplicaNo,
1351 switch (enteringVolumeType)
1356 G4Exception(
"G4ITNavigator::GetMotherToDaughterTransform()",
1358 "Method NOT Implemented yet for replica volumes.");
1366 pParam->
ComputeSolid(enteringReplicaNo, pEnteringPhysVol);
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",
1535 #ifdef G4DEBUG_NAVIGATION
1538 G4cout <<
" G4ITNavigator::ComputeSafety() finds that point - "
1539 << pGlobalpoint <<
" - is on surface " <<
G4endl;
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;
1590 <<
" Exiting = " <<
fExiting << G4endl
1591 <<
" Entering = " <<
fEntering << G4endl
1592 <<
" BlockedPhysicalVolume= " ;
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 " <<
" "
1614 <<
", " << std::setw(7) <<
fExitNormal.z() <<
" ) "
1616 << std::setw( 9) <<
fExiting <<
" "
1619 G4cout << std::setw(15) <<
"None";
1633 G4cout.precision(oldcoutPrec);
1662 G4double shiftOrigin = std::sqrt(shiftOriginSafSq);
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.";
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;
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",
G4SmartVoxelHeader * GetVoxelHeader() const
G4VPhysicalVolume * GetTopVolume() const
G4ReplicaNavigation freplicaNav
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
G4bool fLocatedOutsideWorld
virtual 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)
virtual void ResetState()
const G4ThreeVector & GetTranslation() const
static const G4double kInfinity
void UpdateMaterial(G4Material *pMaterial)
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
G4int GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=false)
virtual G4VSolid * ComputeSolid(const G4int, G4VPhysicalVolume *)
G4bool sWasLimitedByGeometry
virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
G4double GetSurfaceTolerance() const
friend std::ostream & operator<<(std::ostream &os, const G4ITNavigator &n)
G4int fActionThreshold_NoZeroSteps
const G4AffineTransform & GetGlobalToLocalTransform() const
void ComputeStepLog(const G4ThreeVector &pGlobalpoint, G4double moveLenSq) const
void SetSolid(G4VSolid *pSolid)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
G4SmartVoxelNode * ParamVoxelLocate(G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint)
G4VPhysicalVolume * fBlockedPhysicalVolume
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)
virtual G4GeometryType GetEntityType() const =0
G4VoxelNavigation fvoxelNav
G4ReferenceCountedHandle< G4TouchableHistory > G4TouchableHistoryHandle
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
void ComputeTransformation(const G4int replicaNo, G4VPhysicalVolume *pVol, G4ThreeVector &point) const
virtual G4TouchableHistoryHandle CreateTouchableHistoryHandle() const
G4ThreeVector fLastStepEndPointLocal
G4int GetTopReplicaNo() const
G4bool fLastTriedStepComputation
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
static double normal(HepRandomEngine *eptr)
EVolume VolumeType(const G4VPhysicalVolume *pVol) const
G4ITNavigatorState_Lock * GetNavigatorState()
void SetNormalNavigation(G4NormalNavigation *fnormnav)
const G4AffineTransform GetLocalToGlobalTransform() const
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
G4GLOB_DLL std::ostream G4cout
G4bool sLocatedOutsideWorld
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
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)
virtual G4ThreeVector GetLocalExitNormal(G4bool *valid)
EVolume GetTopVolumeType() const
virtual G4int GetRegularStructureId() const =0
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX)
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual G4VPVParameterisation * GetParameterisation() const =0
virtual void SetCopyNo(G4int CopyNo)=0
G4int GetReplicaNo(G4int n) const
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
G4double CheckNextStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
G4ThreeVector fExitNormal
G4VPhysicalVolume * spBlockedPhysicalVolume
G4ThreeVector ComputeLocalAxis(const G4ThreeVector &pVec) const
G4ThreeVector fGrandMotherExitNormal
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4NormalNavigation fnormalNav
void NewLevel(G4VPhysicalVolume *pNewMother, EVolume vType=kNormal, G4int nReplica=-1)
G4NavigationHistory fHistory
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)
G4LogicalVolume * GetLogicalVolume() const
G4ThreeVector sExitNormal
virtual void ComputeTransformation(const G4int, G4VPhysicalVolume *) const =0
G4bool EnteredDaughterVolume() const
virtual G4int GetCopyNo() const =0
G4RegularNavigation fregularNav
const G4RotationMatrix * GetRotation() const
G4ParameterisedNavigation fparamNav
G4SmartVoxelNode * VoxelLocate(G4SmartVoxelHeader *pHead, const G4ThreeVector &localPoint)
void SetNavigatorState(G4ITNavigatorState_Lock *)
G4int fAbandonThreshold_NoZeroSteps
G4double ComputeSafety(const G4ThreeVector &localPoint, const G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
virtual void SetupHierarchy()
const G4AffineTransform & GetTopTransform() const
G4SaveNavigatorState * fpSaveState
const G4NavigationHistory * GetHistory() const
G4bool fWasLimitedByGeometry
void ResetStackAndState()
EVolume CharacteriseDaughters(const G4LogicalVolume *pLog) const
G4int MoveUpHistory(G4int num_levels=1)
G4double ComputeSafety(const G4ThreeVector &globalPoint, const G4ThreeVector &localPoint, G4NavigationHistory &history, const G4double pProposedMaxLength=DBL_MAX)
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4TouchableHistory * CreateTouchableHistory() const
G4VPhysicalVolume * GetVolume(G4int n) const
G4bool LevelLocate(G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint)
G4ThreeVector sLastLocatedPointLocal
G4AffineTransform GetMotherToDaughterTransform(G4VPhysicalVolume *dVolume, G4int dReplicaNo, EVolume dVolumeType)
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
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)
virtual G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &point, G4bool *valid)
EInside BackLocate(G4NavigationHistory &history, const G4ThreeVector &globalPoint, G4ThreeVector &localPoint, const G4bool &exiting, G4bool ¬KnownInside) const
G4ThreeVector sPreviousSftOrigin
G4ThreeVector fPreviousSftOrigin
virtual G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int errMax=1)
G4ThreeVector fLastLocatedPointLocal
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &rGlobPoint) const
static G4GeometryTolerance * GetInstance()
G4VSolid * GetSolid() const
G4GLOB_DLL std::ostream G4cerr
G4ThreeVector fStepEndPoint
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)