49 #define State(X) fpTrackState->X
50 #define fNewTrack State(fNewTrack)
51 #define fLimitedStep State(fLimitedStep)
52 #define fLimitTruth State(fLimitTruth)
53 #define fCurrentStepSize State(fCurrentStepSize)
54 #define fNoGeometriesLimiting State(fNoGeometriesLimiting)
55 #define fPreSafetyLocation State(fPreSafetyLocation)
56 #define fPreSafetyMinValue State(fPreSafetyMinValue)
57 #define fPreSafetyValues State(fPreSafetyValues)
58 #define fPreStepLocation State(fPreStepLocation)
59 #define fMinSafety_PreStepPt State(fMinSafety_PreStepPt)
60 #define fCurrentPreStepSafety State(fCurrentPreStepSafety)
61 #define fPreStepCenterRenewed State(fPreStepCenterRenewed)
62 #define fMinStep State(fMinStep)
63 #define fTrueMinStep State(fTrueMinStep)
64 #define fLocatedVolume State(fLocatedVolume)
65 #define fLastLocatedPosition State(fLastLocatedPosition)
66 #define fEndState State(fEndState)
67 #define fFieldExertedForce State(fFieldExertedForce)
68 #define fRelocatedPoint State(fRelocatedPoint)
69 #define fSafetyLocation State(fSafetyLocation)
70 #define fMinSafety_atSafLocation State(fMinSafety_atSafLocation)
71 #define fNewSafetyComputed State(fNewSafetyComputed)
72 #define fLastStepNo State(fLastStepNo)
73 #define fCurrentStepNo State(fCurrentStepNo)
107 for(
G4int num=0; num< G4ITNavigator::fMaxNav; ++num )
165 #ifdef G4DEBUG_PATHFINDER
169 G4cout <<
" G4ITPathFinder::ComputeStep - entered " <<
G4endl;
170 G4cout <<
" - stepNo = " << std::setw(4) << stepNo <<
" "
171 <<
" navigatorId = " << std::setw(2) << navigatorNo <<
" "
172 <<
" proposed step len = " << proposedStepLength <<
" " <<
G4endl;
173 G4cout <<
" PF::ComputeStep requested step "
181 std::ostringstream message;
182 message <<
"Bad Navigator ID !" <<
G4endl
183 <<
" Requested Navigator ID = " << navigatorNo <<
G4endl
185 G4Exception(
"G4ITPathFinder::ComputeStep()",
"GeomNav0002",
204 G4double moveLenSq= moveVector.mag2();
208 #ifdef G4DEBUG_PATHFINDER
211 G4double moveLen= std::sqrt( moveLenSq );
212 G4cout <<
" G4ITPathFinder::ComputeStep : Point moved since last step "
213 <<
" -- at step # = " << stepNo <<
G4endl
214 <<
" by " << moveLen <<
" to " << newPosition <<
G4endl;
221 Locate( newPosition, newDirection );
255 #ifdef G4DEBUG_PATHFINDER
259 std::ostringstream message;
260 message <<
"Number of geometries limiting the step not set." <<
G4endl
261 <<
" Number of geometries limiting step = "
268 #ifdef G4DEBUG_PATHFINDER
273 std::ostringstream message;
274 message <<
"Problem in step size request." <<
G4endl
275 <<
" Error can be caused by incorrect process ordering."
276 <<
" Being requested to make a step which is shorter"
277 <<
" than the minimum Step " <<
G4endl
278 <<
" already computed for any Navigator/geometry during"
279 <<
" this tracking-step: " <<
G4endl
280 <<
" This can happen due to an error in process ordering."
282 <<
" Check that all physics processes are registered"
284 <<
" before all processes with a navigator/geometry."
286 <<
" If using pre-packaged physics list and/or"
288 <<
" functionality, please report this error."
290 <<
" Additional information for problem: " <<
G4endl
291 <<
" Steps request/proposed = " << proposedStepLength
295 <<
" MinimumStep (navraw) = " <<
fMinStep
297 <<
" Navigator raw return value" <<
G4endl
298 <<
" Requested step now = " << proposedStepLength
300 <<
" Difference min-req = "
302 <<
" -- Step info> stepNo= " << stepNo
317 G4cout <<
" G4P::CS -> Not calling DoNextLinearStep: "
318 <<
" stepNo= " << stepNo <<
" last= " <<
fLastStepNo
336 #ifdef G4DEBUG_PATHFINDER
339 G4cout <<
" G4ITPathFinder::ComputeStep returns "
341 <<
" for Navigator " << navigatorNo
342 <<
" Limited step = " << limitedStep
343 <<
" Safety(mm) = " << pNewSafety /
mm
375 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
380 std::ostringstream message;
381 message <<
"Too many active Navigators / worlds." <<
G4endl
382 <<
" Transportation Manager has "
384 <<
" This is more than the number allowed = "
385 << G4ITNavigator::fMaxNav <<
" !";
386 G4Exception(
"G4ITPathFinder::PrepareNewTrack()",
"GeomNav0002",
408 if( fNoActiveNavigators > 1 )
410 Locate( position, direction,
false );
448 std::ostringstream message;
449 message <<
"Endpoint moved between value returned by ComputeStep()"
450 <<
" and call to Locate(). " <<
G4endl
451 <<
" Change of " << Quantity <<
" is "
452 << moveVec.mag() /
mm <<
" mm long" <<
G4endl
453 <<
" and its vector is "
454 << (1.0/
mm) * moveVec <<
" mm " <<
G4endl
455 <<
" Endpoint of ComputeStep() was " << OldVector <<
G4endl
456 <<
" and current position to locate is " << NewVector;
457 G4Exception(
"G4ITPathFinder::ReportMove()",
"GeomNav1002",
469 std::vector<G4ITNavigator*>::iterator pNavIter=
478 ReportMove( position, lastEndPosition,
"Position" );
482 #ifdef G4DEBUG_PATHFINDER
486 G4cout <<
" G4ITPathFinder::Locate : entered " <<
G4endl;
488 G4cout <<
" Locating at position " << position
489 <<
" with direction " << direction
490 <<
" relative= " << relative <<
G4endl;
493 G4cout <<
" lastEndPosition = " << lastEndPosition
494 <<
" moveVec = " << moveVec
508 if(
fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
511 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
523 #ifdef G4DEBUG_PATHFINDER
527 <<
" gives volume= " << pLocated ;
530 G4cout <<
" name = '" << pLocated->GetName() <<
"'";
531 G4cout <<
" - CopyNo= " << pLocated->GetCopyNo();
545 std::vector<G4ITNavigator*>::iterator pNavIter=
548 #ifdef G4DEBUG_PATHFINDER
565 G4double moveLenEndPosSq = moveVecEndPos.mag2();
571 G4double moveLenSafSq= moveVecSafety.mag2();
573 G4double distCheckEnd_sq= ( moveLenEndPosSq - endPointSafety_Est1
574 *endPointSafety_Est1 );
578 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
579 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
583 if( (!
fNewTrack) && ( longMoveEnd && longMoveSaf ) )
591 const G4double cErrorTolerance=1e-12;
594 G4double distCheckRevisedEnd= moveLenEndPosSq-revisedSafety*revisedSafety;
596 G4bool longMoveRevisedEnd= ( distCheckRevisedEnd > 0. ) ;
599 G4double moveLenEndPosition= std::sqrt( moveLenEndPosSq );
600 moveMinusSafety = moveLenEndPosition - revisedSafety;
602 if ( longMoveRevisedEnd && (moveMinusSafety > 0.0 )
603 && ( revisedSafety > 0.0 ) )
610 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
611 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
614 G4double absMoveMinusSafety= std::fabs(moveMinusSafety);
615 G4bool smallRatio= absMoveMinusSafety < kRadTolerance * revisedSafety ;
618 std::fabs(position.y())),
619 std::fabs(position.z()) );
620 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
621 if( ! (smallRatio || smallValue) )
623 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
624 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
625 G4cout <<
" Difference of move and safety is not very small."
630 moveMinusSafety = 0.0;
631 longMoveRevisedEnd =
false;
633 G4cout <<
" Difference of move & safety is very small in magnitude, "
634 << absMoveMinusSafety <<
G4endl;
637 G4cout <<
" ratio to safety " << revisedSafety
638 <<
" is " << absMoveMinusSafety / revisedSafety
639 <<
"smaller than " << kRadTolerance <<
" of safety ";
643 G4cout <<
" as fraction " << absMoveMinusSafety / maxCoordPos
644 <<
" of position vector max-coord " << maxCoordPos
645 <<
" smaller than " << cErrorTolerance ;
647 G4cout <<
" -- reset moveMinusSafety to "
648 << moveMinusSafety <<
G4endl;
652 if ( longMoveEnd && longMoveSaf
653 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
656 std::ostringstream message;
657 message <<
"ReLocation is further than end-safety value." <<
G4endl
658 <<
" Moved from last endpoint by " << moveLenEndPosition
659 <<
" compared to end safety (from preStep point) = "
660 << endPointSafety_Est1 <<
G4endl
667 <<
" --> last EndStep Location was " << lastEndPosition
669 <<
" safety value = " << endPointSafety_Est1
670 <<
" raw-value = " << endPointSafety_raw <<
G4endl
671 <<
" --> Calling again at this endpoint, we get "
672 << revisedSafety <<
" as safety value." <<
G4endl
673 <<
" --> last position for safety " << fSafetyLocation
677 <<
" move from safety location = "
678 << std::sqrt(moveLenSafSq) <<
G4endl
679 <<
" again= " << moveVecSafety.mag() <<
G4endl
680 <<
" safety - Move-from-end= "
681 << revisedSafety - moveLenEndPosition
682 <<
" (negative is Bad.)" <<
G4endl
683 <<
" Debug: distCheckRevisedEnd = "
684 << distCheckRevisedEnd;
685 ReportMove( lastEndPosition, position,
"Position" );
686 G4Exception(
"G4ITPathFinder::ReLocate",
"GeomNav0003",
688 G4cout.precision(oldPrec);
695 G4cout <<
" G4ITPathFinder::ReLocate : entered " <<
G4endl;
697 G4cout <<
" *Re*Locating at position " << position <<
G4endl;
702 G4cout <<
" lastEndPosition = " << lastEndPosition
703 <<
" moveVec from step-end = " << moveVecEndPos
708 #endif // G4DEBUG_PATHFINDER
714 (*pNavIter)->LocateGlobalPointWithinVolume( position );
726 #ifdef G4DEBUG_PATHFINDER
729 G4cout <<
" G4ITPathFinder::ReLocate : exiting "
743 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
748 G4double safety = (*pNavigatorIter)->ComputeSafety( position,
true );
749 if( safety < minSafety ) { minSafety = safety; }
756 #ifdef G4DEBUG_PATHFINDER
759 G4cout <<
" G4ITPathFinder::ComputeSafety - returns "
760 << minSafety <<
" at location " << position <<
G4endl;
772 #ifdef G4DEBUG_PATHFINDER
775 G4cout <<
"G4ITPathFinder::CreateTouchableHandle : navId = "
781 touchHist=
GetNavigator(navId) -> CreateTouchableHistory();
784 if( locatedVolume == 0 )
791 #ifdef G4DEBUG_PATHFINDER
795 if( locatedVolume ) { VolumeName= locatedVolume->
GetName(); }
796 G4cout <<
" Touchable History created at address " << touchHist
797 <<
" volume = " << locatedVolume <<
" name= " << VolumeName
809 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
813 const G4int IdTransport= 0;
816 #ifdef G4DEBUG_PATHFINDER
819 G4cout <<
" G4ITPathFinder::DoNextLinearStep : entered " <<
G4endl;
820 G4cout <<
" Input field track= " << initialState <<
G4endl;
821 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
829 G4double MagSqShift = OriginShift.mag2() ;
838 MagShift= std::sqrt(MagSqShift) ;
840 #ifdef G4PATHFINDER_OPTIMISATION
852 if( proposedStepLength < fullSafety )
863 minSafety=
std::min( safety, minSafety );
868 #ifdef G4DEBUG_PATHFINDER
871 G4cout <<
"G4ITPathFinder::DoNextLinearStep : Quick Stepping. " <<
G4endl
872 <<
" proposedStepLength " << proposedStepLength
873 <<
" < (full) safety = " << fullSafety
874 <<
" at " << initialPosition
880 #endif // End of G4PATHFINDER_OPTIMISATION 1
894 #ifdef G4PATHFINDER_OPTIMISATION
895 if( proposedStepLength <= safety )
901 #ifdef G4DEBUG_PATHFINDER
903 G4cout <<
"G4ITNavigator::ComputeStep> small proposed step = "
904 << proposedStepLength
905 <<
" <= safety = " << safety <<
" for nav " << num
906 <<
" Step fully taken. " <<
G4endl;
910 #endif // End of G4PATHFINDER_OPTIMISATION 2
912 #ifdef G4DEBUG_PATHFINDER
915 step= (*pNavigatorIter)->ComputeStep( initialPosition,
924 #ifdef G4DEBUG_PATHFINDER
928 G4cout <<
"G4ITNavigator::ComputeStep> long proposed step = "
929 << proposedStepLength
930 <<
" > safety = " << previousSafety
931 <<
" for nav " << num
932 <<
" . New safety = " << safety <<
" step= " << step
946 minSafety=
std::min( safety, minSafety );
948 #ifdef G4DEBUG_PATHFINDER
951 G4cout <<
"G4ITPathFinder::DoNextLinearStep : Navigator ["
952 << num <<
"] -- step size " << step <<
G4endl;
960 fPreSafetyLocation= initialPosition;
973 minStep = proposedStepLength;
982 endPosition= initialPosition + minStep * initialDirection ;
984 #ifdef G4DEBUG_PATHFINDER
987 G4cout <<
"G4ITPathFinder::DoNextLinearStep : "
988 <<
" initialPosition = " << initialPosition
989 <<
" and endPosition = " << endPosition<<
G4endl;
994 fEndState.SetProperTimeOfFlight( -1.000 );
1010 #ifdef G4DEBUG_PATHFINDER
1013 G4cout <<
" G4ITPathFinder::DoNextLinearStep : exits returning "
1027 G4int num=-1, last=-1;
1031 const G4int IdTransport= 0;
1038 if( transportLimited ) {
1065 if( (last > -1) && (noLimited == 1 ) )
1070 #ifdef G4DEBUG_PATHFINDER
1075 G4cout <<
" G4ITPathFinder::WhichLimited - exiting. " <<
G4endl;
1085 G4cout <<
"G4ITPathFinder::PrintLimited reports: " ;
1091 G4cout << std::setw(5) <<
" Step#" <<
" "
1092 << std::setw(5) <<
" NavId" <<
" "
1093 << std::setw(12) <<
" step-size " <<
" "
1094 << std::setw(12) <<
" raw-size " <<
" "
1095 << std::setw(12) <<
" pre-safety " <<
" "
1096 << std::setw(15) <<
" Limited / flag" <<
" "
1097 << std::setw(15) <<
" World " <<
" "
1112 << std::setw(5) << num <<
" "
1113 << std::setw(12) << stepLen <<
" "
1114 << std::setw(12) << rawStep <<
" "
1116 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
1118 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
1119 G4cout.precision(oldPrec);
1128 WorldName = pWorld->
GetName();
1131 G4cout <<
" " << WorldName ;
1137 G4cout <<
" G4ITPathFinder::PrintLimited - exiting. " <<
G4endl;
1146 const G4double toleratedRelativeError= 1.0e-10;
1152 #ifdef G4DEBUG_PATHFINDER
1156 G4cout <<
" G4ITPathFinder::DoNextCurvedStep ****** " <<
G4endl;
1157 G4cout <<
" Initial value of field track is " << fieldTrack
1158 <<
" and proposed step= " << proposedStepLength <<
G4endl;
1171 safety=
fpNavigator[numNav]->ComputeSafety( startPoint,
false );
1174 minSafety =
std::min( safety, minSafety );
1215 #ifdef G4DEBUG_PATHFINDER
1218 G4cout <<
"G4ITPathFinder::DoNextCurvedStep : " <<
G4endl
1219 <<
" initialState = " << initialState <<
G4endl
1221 G4cout <<
"G4ITPathFinder::DoNextCurvedStep : "
1222 <<
" minStep = " << minStep
1223 <<
" proposedStepLength " << proposedStepLength
1224 <<
" safety = " << newSafety <<
G4endl;
1228 if( minStep < proposedStepLength )
1236 G4double finalStep, lastPreSafety=0.0, minStepLast;
1241 minStepLast, didLimit );
1250 diffStep = (finalStep-minStepLast);
1251 if ( std::abs(diffStep) <= toleratedRelativeError * finalStep )
1255 currentStepSize += diffStep;
1272 if( limited ) { noLimited++; }
1274 #ifdef G4DEBUG_PATHFINDER
1275 G4bool StepError= (currentStepSize < 0)
1276 || ( (minStepLast !=
kInfinity) && (diffStep < 0) ) ;
1281 G4cout <<
" G4ITPathFinder::ComputeStep. Geometry " << numNav
1283 <<
" from final-step= " << finalStep
1285 <<
" minStepLast= " << minStepLast
1286 <<
" limited = " << (
fLimitTruth[numNav] ?
"YES" :
" NO")
1288 G4cout <<
" status = " << limitedString <<
" #= " << didLimit
1293 std::ostringstream message;
1294 message <<
"Incorrect calculation of step size for one navigator"
1296 <<
" currentStepSize = " << currentStepSize
1297 <<
", diffStep= " << diffStep << G4endl
1298 <<
"ERROR in computing step size for this navigator.";
1308 else if ( (minStep == proposedStepLength)
1310 || ( std::abs(minStep-proposedStepLength)
1311 < toleratedRelativeError * proposedStepLength ) )
1320 currentStepSize= minStep;
1332 std::ostringstream message;
1333 message <<
"Incorrect calculation of step size for one navigator." <<
G4endl
1334 <<
" currentStepSize = " << minStep <<
" is larger than "
1335 <<
" proposed StepSize = " << proposedStepLength <<
".";
1340 #ifdef G4DEBUG_PATHFINDER
1343 G4cout <<
" Exiting G4ITPathFinder::DoNextCurvedStep " <<
G4endl;
1355 StrUnique(
"Unique"),
1356 StrUndefined(
"Undefined"),
1357 StrSharedTransport(
"SharedTransport"),
1358 StrSharedOther(
"SharedOther");
1363 case kDoNot: limitedStr= &StrDoNot;
break;
1364 case kUnique: limitedStr = &StrUnique;
break;
1366 case kSharedOther: limitedStr = &StrSharedOther;
break;
1367 default: limitedStr = &StrUndefined;
break;
G4ITNavigator * GetNavigator(G4int n) const
G4ITSafetyHelper * GetSafetyHelper() const
void ReLocate(const G4ThreeVector &position)
G4ITMultiNavigator * fpMultiNavigator
static G4ITPathFinder * GetInstance()
#define fCurrentPreStepSafety
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
#define fNoGeometriesLimiting
void EnableParallelNavigation(G4bool parallel)
void EnableParallelNavigation(G4bool enableChoice=true)
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4double GetSurfaceTolerance() const
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
#define fPreStepCenterRenewed
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
#define fPreSafetyMinValue
static G4ITTransportationManager * GetTransportationManager()
G4double DoNextLinearStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength)
G4ThreeVector GetPosition() const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
static G4ThreadLocal G4ITPathFinder * fpPathFinder
G4double GetRadialTolerance() const
void ReportMove(const G4ThreeVector &OldV, const G4ThreeVector &NewV, const G4String &Quantity) const
#define fLastLocatedPosition
G4double ComputeSafety(const G4ThreeVector &globalPoint)
#define fMinSafety_atSafLocation
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
static const G4double minSafety
G4double DoNextCurvedStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength, G4VPhysicalVolume *pCurrentPhysVolume)
std::vector< G4ITNavigator * >::iterator GetActiveNavigatorsIterator()
#define fMinSafety_PreStepPt
G4String & LimitedString(ELimited lim)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
#define fPreSafetyLocation
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4int fNoActiveNavigators
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=0)
const G4NavigationHistory * GetHistory() const
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
void PushPostSafetyToPreSafety()
static G4GeometryTolerance * GetInstance()
G4ITNavigator * fpNavigator[G4ITNavigator::fMaxNav]
G4GLOB_DLL std::ostream G4cerr
G4ITTransportationManager * fpTransportManager
G4ThreeVector GetMomentumDirection() const
#define fNewSafetyComputed