136 G4Navigator *navigatorForPropagation=0, *massNavigator=0;
149 navigatorForPropagation= massNavigator;
172 #ifdef G4DEBUG_PATHFINDER
176 G4cout <<
" G4PathFinder::ComputeStep - entered " <<
G4endl;
177 G4cout <<
" - stepNo = " << std::setw(4) << stepNo <<
" "
178 <<
" navigatorId = " << std::setw(2) << navigatorNo <<
" "
179 <<
" proposed step len = " << proposedStepLength <<
" " <<
G4endl;
180 G4cout <<
" PF::ComputeStep requested step "
189 message <<
"Bad Navigator ID !" <<
G4endl
190 <<
" Requested Navigator ID = " << navigatorNo <<
G4endl
192 G4Exception(
"G4PathFinder::ComputeStep()",
"GeomNav0002",
215 #ifdef G4DEBUG_PATHFINDER
218 G4double moveLen= std::sqrt( moveLenSq );
219 G4cout <<
" G4PathFinder::ComputeStep : Point moved since last step "
220 <<
" -- at step # = " << stepNo <<
G4endl
221 <<
" by " << moveLen <<
" to " << newPosition <<
G4endl;
228 Locate( newPosition, newDirection );
236 G4bool fieldExertsForce = false ;
237 if( (particleCharge != 0.0) )
243 fieldExertsForce = (fieldMgr != 0)
250 if( fieldExertsForce )
261 #ifdef G4DEBUG_PATHFINDER
266 message <<
"Number of geometries limiting the step not set." <<
G4endl
267 <<
" Number of geometries limiting step = "
274 #ifdef G4DEBUG_PATHFINDER
277 const G4double checkTolerance = 1.0e-9;
278 if( proposedStepLength <
fTrueMinStep * ( 1.0 - checkTolerance) )
281 message.precision( 12 );
282 message <<
"Problem in step size request." <<
G4endl
283 <<
" Being requested to make a step which is shorter"
284 <<
" than the minimum Step " <<
G4endl
285 <<
" already computed for any Navigator/geometry during"
286 <<
" this tracking-step: " <<
G4endl
287 <<
" This could happen due to an error in process ordering."
289 <<
" Check that all physics processes are registered"
290 <<
" before all processes with a navigator/geometry."
292 <<
" If using pre-packaged physics list and/or"
293 <<
" functionality, please report this error."
295 <<
" Additional information for problem: " <<
G4endl
296 <<
" Steps request/proposed = " << proposedStepLength
300 <<
" MinimumStep (navraw) = " <<
fMinStep
302 <<
" Navigator raw return value" <<
G4endl
303 <<
" Requested step now = " << proposedStepLength
305 <<
" Difference min-req (absolute) = "
307 <<
" Relative (to max of two) = "
310 <<
" -- Step info> stepNo= " << stepNo
325 G4cout <<
" G4P::CS -> Not calling DoNextLinearStep: "
326 <<
" stepNo= " << stepNo <<
" last= " <<
fLastStepNo
343 #ifdef G4DEBUG_PATHFINDER
346 G4cout <<
" G4PathFinder::ComputeStep returns "
348 <<
" for Navigator " << navigatorNo
349 <<
" Limited step = " << limitedStep
350 <<
" Safety(mm) = " << pNewSafety /
mm
384 std::vector<G4Navigator*>::iterator pNavigatorIter;
390 message <<
"Too many active Navigators / worlds." <<
G4endl
391 <<
" Transportation Manager has "
393 <<
" This is more than the number allowed = "
395 G4Exception(
"G4PathFinder::PrepareNewTrack()",
"GeomNav0002",
417 if( fNoActiveNavigators > 1 )
419 Locate( position, direction,
false );
466 message.precision(16);
467 message <<
"Endpoint moved between value returned by ComputeStep()"
468 <<
" and call to Locate(). " <<
G4endl
469 <<
" Change of " << Quantity <<
" is "
471 <<
" and its vector is "
472 << (1.0/
mm) * moveVec <<
" mm " <<
G4endl
473 <<
" Endpoint of ComputeStep() was " << OldVector <<
G4endl
474 <<
" and current position to locate is " << NewVector;
475 G4Exception(
"G4PathFinder::ReportMove()",
"GeomNav1002",
488 std::vector<G4Navigator*>::iterator pNavIter=
495 if( (!
fNewTrack) && ( moveLenSq > movLenTol ) )
498 " (End) Position / G4PathFinder::Locate" );
502 #ifdef G4DEBUG_PATHFINDER
508 G4cout <<
" Locating at position " << position
509 <<
" with direction " << direction
510 <<
" relative= " << relative <<
G4endl;
513 G4cout <<
" lastEndPosition = " << lastEndPosition
514 <<
" moveVec = " << moveVec
528 if(
fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
531 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
543 #ifdef G4DEBUG_PATHFINDER
547 <<
" gives volume= " << pLocated ;
550 G4cout <<
" name = '" << pLocated->GetName() <<
"'";
551 G4cout <<
" - CopyNo= " << pLocated->GetCopyNo();
565 std::vector<G4Navigator*>::iterator pNavIter=
568 #ifdef G4DEBUG_PATHFINDER
593 G4double distCheckEnd_sq= ( moveLenEndPosSq - endPointSafety_Est1
594 *endPointSafety_Est1 );
598 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
599 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
603 if( (!
fNewTrack) && ( longMoveEnd && longMoveSaf ) )
614 G4double distCheckRevisedEnd= moveLenEndPosSq-revisedSafety*revisedSafety;
616 G4bool longMoveRevisedEnd= ( distCheckRevisedEnd > 0. ) ;
619 G4double moveLenEndPosition= std::sqrt( moveLenEndPosSq );
620 moveMinusSafety = moveLenEndPosition - revisedSafety;
622 if ( longMoveRevisedEnd && (moveMinusSafety > 0.0 )
623 && ( revisedSafety > 0.0 ) )
630 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
631 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
634 G4double absMoveMinusSafety= std::fabs(moveMinusSafety);
635 G4bool smallRatio= absMoveMinusSafety < kRadTolerance * revisedSafety ;
638 std::fabs(position.
y())),
639 std::fabs(position.
z()) );
640 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
641 if( ! (smallRatio || smallValue) )
643 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
644 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
645 G4cout <<
" Difference of move and safety is not very small."
650 moveMinusSafety = 0.0;
651 longMoveRevisedEnd =
false;
653 G4cout <<
" Difference of move & safety is very small in magnitude, "
654 << absMoveMinusSafety <<
G4endl;
657 G4cout <<
" ratio to safety " << revisedSafety
658 <<
" is " << absMoveMinusSafety / revisedSafety
659 <<
"smaller than " << kRadTolerance <<
" of safety ";
663 G4cout <<
" as fraction " << absMoveMinusSafety / maxCoordPos
664 <<
" of position vector max-coord " << maxCoordPos
665 <<
" smaller than " << cErrorTolerance ;
667 G4cout <<
" -- reset moveMinusSafety to "
668 << moveMinusSafety <<
G4endl;
672 if ( longMoveEnd && longMoveSaf
673 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
676 message.precision(9);
677 message <<
"ReLocation is further than end-safety value." <<
G4endl
678 <<
" Moved from last endpoint by " << moveLenEndPosition
679 <<
" compared to end safety (from preStep point) = "
680 << endPointSafety_Est1 <<
G4endl
687 <<
" --> last EndStep Location was " << lastEndPosition
689 <<
" safety value = " << endPointSafety_Est1
690 <<
" raw-value = " << endPointSafety_raw <<
G4endl
691 <<
" --> Calling again at this endpoint, we get "
692 << revisedSafety <<
" as safety value." <<
G4endl
693 <<
" --> last position for safety " << fSafetyLocation
697 <<
" move from safety location = "
698 << std::sqrt(moveLenSafSq) <<
G4endl
699 <<
" again= " << moveVecSafety.
mag() <<
G4endl
700 <<
" safety - Move-from-end= "
701 << revisedSafety - moveLenEndPosition
702 <<
" (negative is Bad.)" <<
G4endl
703 <<
" Debug: distCheckRevisedEnd = "
704 << distCheckRevisedEnd;
705 ReportMove( lastEndPosition, position,
"Position" );
706 G4Exception(
"G4PathFinder::ReLocate",
"GeomNav0003",
714 G4cout <<
" G4PathFinder::ReLocate : entered " <<
G4endl;
716 G4cout <<
" *Re*Locating at position " << position <<
G4endl;
721 G4cout <<
" lastEndPosition = " << lastEndPosition
722 <<
" moveVec from step-end = " << moveVecEndPos
727 #endif // G4DEBUG_PATHFINDER
733 (*pNavIter)->LocateGlobalPointWithinVolume( position );
745 #ifdef G4DEBUG_PATHFINDER
748 G4cout <<
" G4PathFinder::ReLocate : exiting "
762 std::vector<G4Navigator*>::iterator pNavigatorIter;
767 G4double safety = (*pNavigatorIter)->ComputeSafety( position,
DBL_MAX,
true );
768 if( safety < minSafety ) { minSafety = safety; }
775 #ifdef G4DEBUG_PATHFINDER
778 G4cout <<
" G4PathFinder::ComputeSafety - returns "
779 << minSafety <<
" at location " << position <<
G4endl;
791 #ifdef G4DEBUG_PATHFINDER
794 G4cout <<
"G4PathFinder::CreateTouchableHandle : navId = "
800 touchHist=
GetNavigator(navId) -> CreateTouchableHistory();
803 if( locatedVolume == 0 )
810 #ifdef G4DEBUG_PATHFINDER
814 if( locatedVolume ) { VolumeName= locatedVolume->
GetName(); }
815 G4cout <<
" Touchable History created at address " << touchHist
816 <<
" volume = " << locatedVolume <<
" name= " << VolumeName
828 std::vector<G4Navigator*>::iterator pNavigatorIter;
832 const G4int IdTransport= 0;
835 #ifdef G4DEBUG_PATHFINDER
838 G4cout <<
" G4PathFinder::DoNextLinearStep : entered " <<
G4endl;
839 G4cout <<
" Input field track= " << initialState <<
G4endl;
840 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
857 MagShift= std::sqrt(MagSqShift) ;
859 #ifdef G4PATHFINDER_OPTIMISATION
871 if( proposedStepLength < fullSafety )
882 minSafety=
std::min( safety, minSafety );
887 #ifdef G4DEBUG_PATHFINDER
890 G4cout <<
"G4PathFinder::DoNextLinearStep : Quick Stepping. " <<
G4endl
891 <<
" proposedStepLength " << proposedStepLength
892 <<
" < (full) safety = " << fullSafety
893 <<
" at " << initialPosition
899 #endif // End of G4PATHFINDER_OPTIMISATION 1
913 #ifdef G4PATHFINDER_OPTIMISATION
914 if( proposedStepLength <= safety )
920 #ifdef G4DEBUG_PATHFINDER
922 G4cout <<
"PathFinder::ComputeStep> small proposed step = "
923 << proposedStepLength
924 <<
" <= safety = " << safety <<
" for nav " << num
925 <<
" Step fully taken. " <<
G4endl;
929 #endif // End of G4PATHFINDER_OPTIMISATION 2
931 #ifdef G4DEBUG_PATHFINDER
934 step= (*pNavigatorIter)->ComputeStep( initialPosition,
940 #ifdef G4DEBUG_PATHFINDER
944 G4cout <<
"PathFinder::ComputeStep> long proposed step = "
945 << proposedStepLength
946 <<
" > safety = " << previousSafety
947 <<
" for nav " << num
948 <<
" . New safety = " << safety <<
" step= " << step
966 minSafety=
std::min( safety, minSafety );
968 #ifdef G4DEBUG_PATHFINDER
971 G4cout <<
"G4PathFinder::DoNextLinearStep : Navigator ["
972 << num <<
"] -- step size " << step <<
G4endl;
980 fPreSafetyLocation= initialPosition;
993 minStep = proposedStepLength;
1002 endPosition= initialPosition + minStep * initialDirection ;
1004 #ifdef G4DEBUG_PATHFINDER
1008 G4cout <<
"G4PathFinder::DoNextLinearStep : "
1009 <<
" initialPosition = " << initialPosition
1010 <<
" and endPosition = " << endPosition<<
G4endl;
1011 G4cout.precision(oldPrec);
1032 #ifdef G4DEBUG_PATHFINDER
1035 G4cout <<
" G4PathFinder::DoNextLinearStep : exits returning "
1049 G4int num=-1, last=-1;
1053 const G4int IdTransport= 0;
1060 if( transportLimited ) {
1087 if( (last > -1) && (noLimited == 1 ) )
1092 #ifdef G4DEBUG_PATHFINDER
1097 G4cout <<
" G4PathFinder::WhichLimited - exiting. " <<
G4endl;
1107 G4cout <<
"G4PathFinder::PrintLimited reports: " ;
1113 G4cout << std::setw(5) <<
" Step#" <<
" "
1114 << std::setw(5) <<
" NavId" <<
" "
1115 << std::setw(12) <<
" step-size " <<
" "
1116 << std::setw(12) <<
" raw-size " <<
" "
1117 << std::setw(12) <<
" pre-safety " <<
" "
1118 << std::setw(15) <<
" Limited / flag" <<
" "
1119 << std::setw(15) <<
" World " <<
" "
1134 << std::setw(5) << num <<
" "
1135 << std::setw(12) << stepLen <<
" "
1136 << std::setw(12) << rawStep <<
" "
1138 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
1140 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
1141 G4cout.precision(oldPrec);
1150 WorldName = pWorld->
GetName();
1153 G4cout <<
" " << WorldName ;
1159 G4cout <<
" G4PathFinder::PrintLimited - exiting. " <<
G4endl;
1168 const G4double toleratedRelativeError= 1.0e-10;
1182 #ifdef G4DEBUG_PATHFINDER
1186 G4cout <<
" G4PathFinder::DoNextCurvedStep ****** " <<
G4endl;
1187 G4cout <<
" Initial value of field track is " << fieldTrack
1188 <<
" and proposed step= " << proposedStepLength <<
G4endl;
1204 minSafety =
std::min( safety, minSafety );
1220 pCurrentPhysicalVolume );
1244 #ifdef G4DEBUG_PATHFINDER
1247 G4cout <<
"G4PathFinder::DoNextCurvedStep : " <<
G4endl
1248 <<
" initialState = " << initialState <<
G4endl
1250 G4cout <<
"G4PathFinder::DoNextCurvedStep : "
1251 <<
" minStep = " << minStep
1252 <<
" proposedStepLength " << proposedStepLength
1253 <<
" safety = " << newSafety <<
G4endl;
1257 if( minStep < proposedStepLength )
1265 G4double finalStep, lastPreSafety=0.0, minStepLast;
1270 minStepLast, didLimit );
1279 diffStep = (finalStep-minStepLast);
1280 if ( std::abs(diffStep) <= toleratedRelativeError * finalStep )
1284 currentStepSize += diffStep;
1301 if( limited ) { noLimited++; }
1303 #ifdef G4DEBUG_PATHFINDER
1304 G4bool StepError= (currentStepSize < 0)
1305 || ( (minStepLast !=
kInfinity) && (diffStep < 0) ) ;
1310 G4cout <<
" G4PathFinder::ComputeStep. Geometry " << numNav
1312 <<
" from final-step= " << finalStep
1314 <<
" minStepLast= " << minStepLast
1315 <<
" limited = " << (
fLimitTruth[numNav] ?
"YES" :
" NO")
1317 G4cout <<
" status = " << limitedString <<
" #= " << didLimit
1323 message <<
"Incorrect calculation of step size for one navigator"
1325 <<
" currentStepSize = " << currentStepSize
1326 <<
", diffStep= " << diffStep << G4endl
1327 <<
"ERROR in computing step size for this navigator.";
1337 else if ( (minStep == proposedStepLength)
1339 || ( std::abs(minStep-proposedStepLength)
1340 < toleratedRelativeError * proposedStepLength ) )
1349 currentStepSize= minStep;
1362 message <<
"Incorrect calculation of step size for one navigator." <<
G4endl
1363 <<
" currentStepSize = " << minStep <<
" is larger than "
1364 <<
" proposed StepSize = " << proposedStepLength <<
".";
1369 #ifdef G4DEBUG_PATHFINDER
1372 G4cout <<
" Exiting G4PathFinder::DoNextCurvedStep " <<
G4endl;
1408 minSafety =
std::min( safety, minSafety );
1409 minMove =
std::min( distance, minMove );
1415 *prDistance= minMove;
1416 if( prNewSafety ) *prNewSafety= minSafety;
1430 StrUnique(
"Unique"),
1431 StrUndefined(
"Undefined"),
1432 StrSharedTransport(
"SharedTransport"),
1433 StrSharedOther(
"SharedOther");
1438 case kDoNot: limitedStr= &StrDoNot;
break;
1439 case kUnique: limitedStr = &StrUnique;
break;
1441 case kSharedOther: limitedStr = &StrSharedOther;
break;
1442 default: limitedStr = &StrUndefined;
break;
G4VPhysicalVolume * fLocatedVolume[fMaxNav]
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4bool fLimitTruth[fMaxNav]
static G4PathFinder * GetInstanceIfExist()
G4SafetyHelper * GetSafetyHelper() const
G4bool fPreStepCenterRenewed
static const G4double kInfinity
void SetProperTimeOfFlight(G4double tofProper)
G4int fNoActiveNavigators
static const G4int fMaxNav
static constexpr double mm
G4double GetRestMass() const
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
std::vector< G4Navigator * >::iterator GetActiveNavigatorsIterator()
G4EquationOfMotion * GetCurrentEquationOfMotion()
static G4ThreadLocal G4PathFinder * fpPathFinder
G4Navigator * fpNavigator[fMaxNav]
#define fFieldExertedForce
void message(RunManager *runmanager)
G4ThreeVector fSafetyLocation
G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
G4double GetRadialTolerance() const
const G4ChargeState * GetChargeState() const
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=0)
void ReLocate(const G4ThreeVector &position)
G4Navigator * GetNavigatorForTracking() const
G4double ComputeStep(G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4double &pNewSafety, G4VPhysicalVolume *pPhysVol=0)
G4double DoNextLinearStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength)
G4PropagatorInField * fpFieldPropagator
void EnableParallelNavigation(G4bool enableChoice=true)
G4ThreeVector fPreStepLocation
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
G4Navigator * GetNavigator(G4int n) const
void SetPosition(G4ThreeVector nPos)
void SetNavigatorForPropagating(G4Navigator *SimpleOrMultiNavigator)
G4String & LimitedString(ELimited lim)
G4ThreeVector GetPosition() const
G4double DoNextCurvedStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength, G4VPhysicalVolume *pCurrentPhysVolume)
G4ThreeVector GetMomentumDirection() const
G4FieldManager * FindAndSetFieldManager(G4VPhysicalVolume *pCurrentPhysVol)
const G4NavigationHistory * GetHistory() const
G4double fPreSafetyValues[fMaxNav]
void PushPostSafetyToPreSafety()
G4double fCurrentPreStepSafety[fMaxNav]
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4ThreeVector GetMomentum() const
const G4Field * GetDetectorField() const
G4ThreeVector fPreSafetyLocation
ELimited fLimitedStep[fMaxNav]
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
void EnableParallelNavigation(G4bool parallel)
G4ThreeVector fLastLocatedPosition
G4bool fFieldExertedForce
G4double fCurrentStepSize[fMaxNav]
static G4TransportationManager * GetTransportationManager()
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4double fNewSafetyComputed[fMaxNav]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4double fMinSafety_atSafLocation
void ReportMove(const G4ThreeVector &OldV, const G4ThreeVector &NewV, const G4String &Quantity) const
G4int fNoGeometriesLimiting
G4MultiNavigator * fpMultiNavigator
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
G4GLOB_DLL std::ostream G4cout
G4TransportationManager * fpTransportManager
static G4GeometryTolerance * GetInstance()
G4PropagatorInField * GetPropagatorInField() const
G4VPhysicalVolume * GetWorldVolume() const
G4double GetCharge() const
static G4PathFinder * GetInstance()
G4double fPreSafetyMinValue
virtual void SetChargeMomentumMass(G4ChargeState particleCharge, G4double MomentumXc, G4double MassXc2)=0
G4double GetSurfaceTolerance() const
G4double ComputeSafety(const G4ThreeVector &globalPoint)
const G4String & GetName() const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
virtual G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double CurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
G4double fMinSafety_PreStepPt