71 fFieldExertedForce(false),
72 fRelocatedPoint(true),
73 fLastStepNo(-1), fCurrentStepNo(-1),
126 G4Navigator *navigatorForPropagation=0, *massNavigator=0;
139 navigatorForPropagation= massNavigator;
162 #ifdef G4DEBUG_PATHFINDER
166 G4cout <<
" G4PathFinder::ComputeStep - entered " <<
G4endl;
167 G4cout <<
" - stepNo = " << std::setw(4) << stepNo <<
" "
168 <<
" navigatorId = " << std::setw(2) << navigatorNo <<
" "
169 <<
" proposed step len = " << proposedStepLength <<
" " <<
G4endl;
170 G4cout <<
" PF::ComputeStep requested step "
178 std::ostringstream message;
179 message <<
"Bad Navigator ID !" <<
G4endl
180 <<
" Requested Navigator ID = " << navigatorNo <<
G4endl
182 G4Exception(
"G4PathFinder::ComputeStep()",
"GeomNav0002",
201 G4double moveLenSq= moveVector.mag2();
205 #ifdef G4DEBUG_PATHFINDER
208 G4double moveLen= std::sqrt( moveLenSq );
209 G4cout <<
" G4PathFinder::ComputeStep : Point moved since last step "
210 <<
" -- at step # = " << stepNo <<
G4endl
211 <<
" by " << moveLen <<
" to " << newPosition <<
G4endl;
218 Locate( newPosition, newDirection );
226 G4bool fieldExertsForce = false ;
227 if( (particleCharge != 0.0) )
233 fieldExertsForce = (fieldMgr != 0)
240 if( fieldExertsForce )
250 #ifdef G4DEBUG_PATHFINDER
254 std::ostringstream message;
255 message <<
"Number of geometries limiting the step not set." <<
G4endl
256 <<
" Number of geometries limiting step = "
263 #ifdef G4DEBUG_PATHFINDER
268 std::ostringstream message;
269 message <<
"Problem in step size request." <<
G4endl
270 <<
" Error can be caused by incorrect process ordering."
271 <<
" Being requested to make a step which is shorter"
272 <<
" than the minimum Step " <<
G4endl
273 <<
" already computed for any Navigator/geometry during"
274 <<
" this tracking-step: " <<
G4endl
275 <<
" This can happen due to an error in process ordering."
277 <<
" Check that all physics processes are registered"
279 <<
" before all processes with a navigator/geometry."
281 <<
" If using pre-packaged physics list and/or"
283 <<
" functionality, please report this error."
285 <<
" Additional information for problem: " <<
G4endl
286 <<
" Steps request/proposed = " << proposedStepLength
290 <<
" MinimumStep (navraw) = " <<
fMinStep
292 <<
" Navigator raw return value" <<
G4endl
293 <<
" Requested step now = " << proposedStepLength
295 <<
" Difference min-req = "
297 <<
" -- Step info> stepNo= " << stepNo
312 G4cout <<
" G4P::CS -> Not calling DoNextLinearStep: "
313 <<
" stepNo= " << stepNo <<
" last= " <<
fLastStepNo
331 #ifdef G4DEBUG_PATHFINDER
334 G4cout <<
" G4PathFinder::ComputeStep returns "
336 <<
" for Navigator " << navigatorNo
337 <<
" Limited step = " << limitedStep
338 <<
" Safety(mm) = " << pNewSafety /
mm
370 std::vector<G4Navigator*>::iterator pNavigatorIter;
375 std::ostringstream message;
376 message <<
"Too many active Navigators / worlds." <<
G4endl
377 <<
" Transportation Manager has "
379 <<
" This is more than the number allowed = "
381 G4Exception(
"G4PathFinder::PrepareNewTrack()",
"GeomNav0002",
403 if( fNoActiveNavigators > 1 )
405 Locate( position, direction,
false );
452 std::ostringstream message;
453 message <<
"Endpoint moved between value returned by ComputeStep()"
454 <<
" and call to Locate(). " <<
G4endl
455 <<
" Change of " << Quantity <<
" is "
456 << moveVec.mag() /
mm <<
" mm long" <<
G4endl
457 <<
" and its vector is "
458 << (1.0/
mm) * moveVec <<
" mm " <<
G4endl
459 <<
" Endpoint of ComputeStep() was " << OldVector <<
G4endl
460 <<
" and current position to locate is " << NewVector;
461 G4Exception(
"G4PathFinder::ReportMove()",
"GeomNav1002",
473 std::vector<G4Navigator*>::iterator pNavIter=
482 ReportMove( position, lastEndPosition,
"Position" );
486 #ifdef G4DEBUG_PATHFINDER
492 G4cout <<
" Locating at position " << position
493 <<
" with direction " << direction
494 <<
" relative= " << relative <<
G4endl;
497 G4cout <<
" lastEndPosition = " << lastEndPosition
498 <<
" moveVec = " << moveVec
512 if(
fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
515 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
527 #ifdef G4DEBUG_PATHFINDER
531 <<
" gives volume= " << pLocated ;
534 G4cout <<
" name = '" << pLocated->GetName() <<
"'";
535 G4cout <<
" - CopyNo= " << pLocated->GetCopyNo();
549 std::vector<G4Navigator*>::iterator pNavIter=
552 #ifdef G4DEBUG_PATHFINDER
569 G4double moveLenEndPosSq = moveVecEndPos.mag2();
575 G4double moveLenSafSq= moveVecSafety.mag2();
577 G4double distCheckEnd_sq= ( moveLenEndPosSq - endPointSafety_Est1
578 *endPointSafety_Est1 );
582 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
583 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
587 if( (!
fNewTrack) && ( longMoveEnd && longMoveSaf ) )
595 const G4double cErrorTolerance=1e-12;
598 G4double distCheckRevisedEnd= moveLenEndPosSq-revisedSafety*revisedSafety;
600 G4bool longMoveRevisedEnd= ( distCheckRevisedEnd > 0. ) ;
603 G4double moveLenEndPosition= std::sqrt( moveLenEndPosSq );
604 moveMinusSafety = moveLenEndPosition - revisedSafety;
606 if ( longMoveRevisedEnd && (moveMinusSafety > 0.0 )
607 && ( revisedSafety > 0.0 ) )
614 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
615 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
618 G4double absMoveMinusSafety= std::fabs(moveMinusSafety);
619 G4bool smallRatio= absMoveMinusSafety < kRadTolerance * revisedSafety ;
622 std::fabs(position.y())),
623 std::fabs(position.z()) );
624 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
625 if( ! (smallRatio || smallValue) )
627 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
628 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
629 G4cout <<
" Difference of move and safety is not very small."
634 moveMinusSafety = 0.0;
635 longMoveRevisedEnd =
false;
637 G4cout <<
" Difference of move & safety is very small in magnitude, "
638 << absMoveMinusSafety <<
G4endl;
641 G4cout <<
" ratio to safety " << revisedSafety
642 <<
" is " << absMoveMinusSafety / revisedSafety
643 <<
"smaller than " << kRadTolerance <<
" of safety ";
647 G4cout <<
" as fraction " << absMoveMinusSafety / maxCoordPos
648 <<
" of position vector max-coord " << maxCoordPos
649 <<
" smaller than " << cErrorTolerance ;
651 G4cout <<
" -- reset moveMinusSafety to "
652 << moveMinusSafety <<
G4endl;
656 if ( longMoveEnd && longMoveSaf
657 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
660 std::ostringstream message;
661 message <<
"ReLocation is further than end-safety value." <<
G4endl
662 <<
" Moved from last endpoint by " << moveLenEndPosition
663 <<
" compared to end safety (from preStep point) = "
664 << endPointSafety_Est1 <<
G4endl
671 <<
" --> last EndStep Location was " << lastEndPosition
673 <<
" safety value = " << endPointSafety_Est1
674 <<
" raw-value = " << endPointSafety_raw <<
G4endl
675 <<
" --> Calling again at this endpoint, we get "
676 << revisedSafety <<
" as safety value." <<
G4endl
677 <<
" --> last position for safety " << fSafetyLocation
681 <<
" move from safety location = "
682 << std::sqrt(moveLenSafSq) <<
G4endl
683 <<
" again= " << moveVecSafety.mag() <<
G4endl
684 <<
" safety - Move-from-end= "
685 << revisedSafety - moveLenEndPosition
686 <<
" (negative is Bad.)" <<
G4endl
687 <<
" Debug: distCheckRevisedEnd = "
688 << distCheckRevisedEnd;
689 ReportMove( lastEndPosition, position,
"Position" );
690 G4Exception(
"G4PathFinder::ReLocate",
"GeomNav0003",
692 G4cout.precision(oldPrec);
699 G4cout <<
" G4PathFinder::ReLocate : entered " <<
G4endl;
701 G4cout <<
" *Re*Locating at position " << position <<
G4endl;
706 G4cout <<
" lastEndPosition = " << lastEndPosition
707 <<
" moveVec from step-end = " << moveVecEndPos
712 #endif // G4DEBUG_PATHFINDER
718 (*pNavIter)->LocateGlobalPointWithinVolume( position );
730 #ifdef G4DEBUG_PATHFINDER
733 G4cout <<
" G4PathFinder::ReLocate : exiting "
747 std::vector<G4Navigator*>::iterator pNavigatorIter;
752 G4double safety = (*pNavigatorIter)->ComputeSafety( position,
true );
753 if( safety < minSafety ) { minSafety = safety; }
760 #ifdef G4DEBUG_PATHFINDER
763 G4cout <<
" G4PathFinder::ComputeSafety - returns "
764 << minSafety <<
" at location " << position <<
G4endl;
776 #ifdef G4DEBUG_PATHFINDER
779 G4cout <<
"G4PathFinder::CreateTouchableHandle : navId = "
785 touchHist=
GetNavigator(navId) -> CreateTouchableHistory();
788 if( locatedVolume == 0 )
795 #ifdef G4DEBUG_PATHFINDER
799 if( locatedVolume ) { VolumeName= locatedVolume->
GetName(); }
800 G4cout <<
" Touchable History created at address " << touchHist
801 <<
" volume = " << locatedVolume <<
" name= " << VolumeName
813 std::vector<G4Navigator*>::iterator pNavigatorIter;
817 const G4int IdTransport= 0;
820 #ifdef G4DEBUG_PATHFINDER
823 G4cout <<
" G4PathFinder::DoNextLinearStep : entered " <<
G4endl;
824 G4cout <<
" Input field track= " << initialState <<
G4endl;
825 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
833 G4double MagSqShift = OriginShift.mag2() ;
842 MagShift= std::sqrt(MagSqShift) ;
844 #ifdef G4PATHFINDER_OPTIMISATION
856 if( proposedStepLength < fullSafety )
867 minSafety=
std::min( safety, minSafety );
872 #ifdef G4DEBUG_PATHFINDER
875 G4cout <<
"G4PathFinder::DoNextLinearStep : Quick Stepping. " <<
G4endl
876 <<
" proposedStepLength " << proposedStepLength
877 <<
" < (full) safety = " << fullSafety
878 <<
" at " << initialPosition
884 #endif // End of G4PATHFINDER_OPTIMISATION 1
898 #ifdef G4PATHFINDER_OPTIMISATION
899 if( proposedStepLength <= safety )
905 #ifdef G4DEBUG_PATHFINDER
907 G4cout <<
"PathFinder::ComputeStep> small proposed step = "
908 << proposedStepLength
909 <<
" <= safety = " << safety <<
" for nav " << num
910 <<
" Step fully taken. " <<
G4endl;
914 #endif // End of G4PATHFINDER_OPTIMISATION 2
916 #ifdef G4DEBUG_PATHFINDER
919 step= (*pNavigatorIter)->ComputeStep( initialPosition,
928 #ifdef G4DEBUG_PATHFINDER
932 G4cout <<
"PathFinder::ComputeStep> long proposed step = "
933 << proposedStepLength
934 <<
" > safety = " << previousSafety
935 <<
" for nav " << num
936 <<
" . New safety = " << safety <<
" step= " << step
950 minSafety=
std::min( safety, minSafety );
952 #ifdef G4DEBUG_PATHFINDER
955 G4cout <<
"G4PathFinder::DoNextLinearStep : Navigator ["
956 << num <<
"] -- step size " << step <<
G4endl;
964 fPreSafetyLocation= initialPosition;
977 minStep = proposedStepLength;
986 endPosition= initialPosition + minStep * initialDirection ;
988 #ifdef G4DEBUG_PATHFINDER
991 G4cout <<
"G4PathFinder::DoNextLinearStep : "
992 <<
" initialPosition = " << initialPosition
993 <<
" and endPosition = " << endPosition<<
G4endl;
1014 #ifdef G4DEBUG_PATHFINDER
1017 G4cout <<
" G4PathFinder::DoNextLinearStep : exits returning "
1031 G4int num=-1, last=-1;
1035 const G4int IdTransport= 0;
1042 if( transportLimited ) {
1069 if( (last > -1) && (noLimited == 1 ) )
1074 #ifdef G4DEBUG_PATHFINDER
1079 G4cout <<
" G4PathFinder::WhichLimited - exiting. " <<
G4endl;
1089 G4cout <<
"G4PathFinder::PrintLimited reports: " ;
1095 G4cout << std::setw(5) <<
" Step#" <<
" "
1096 << std::setw(5) <<
" NavId" <<
" "
1097 << std::setw(12) <<
" step-size " <<
" "
1098 << std::setw(12) <<
" raw-size " <<
" "
1099 << std::setw(12) <<
" pre-safety " <<
" "
1100 << std::setw(15) <<
" Limited / flag" <<
" "
1101 << std::setw(15) <<
" World " <<
" "
1116 << std::setw(5) << num <<
" "
1117 << std::setw(12) << stepLen <<
" "
1118 << std::setw(12) << rawStep <<
" "
1120 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
1122 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
1123 G4cout.precision(oldPrec);
1132 WorldName = pWorld->
GetName();
1135 G4cout <<
" " << WorldName ;
1141 G4cout <<
" G4PathFinder::PrintLimited - exiting. " <<
G4endl;
1150 const G4double toleratedRelativeError= 1.0e-10;
1156 #ifdef G4DEBUG_PATHFINDER
1160 G4cout <<
" G4PathFinder::DoNextCurvedStep ****** " <<
G4endl;
1161 G4cout <<
" Initial value of field track is " << fieldTrack
1162 <<
" and proposed step= " << proposedStepLength <<
G4endl;
1178 minSafety =
std::min( safety, minSafety );
1194 pCurrentPhysicalVolume );
1218 #ifdef G4DEBUG_PATHFINDER
1221 G4cout <<
"G4PathFinder::DoNextCurvedStep : " <<
G4endl
1222 <<
" initialState = " << initialState <<
G4endl
1224 G4cout <<
"G4PathFinder::DoNextCurvedStep : "
1225 <<
" minStep = " << minStep
1226 <<
" proposedStepLength " << proposedStepLength
1227 <<
" safety = " << newSafety <<
G4endl;
1231 if( minStep < proposedStepLength )
1239 G4double finalStep, lastPreSafety=0.0, minStepLast;
1244 minStepLast, didLimit );
1253 diffStep = (finalStep-minStepLast);
1254 if ( std::abs(diffStep) <= toleratedRelativeError * finalStep )
1258 currentStepSize += diffStep;
1275 if( limited ) { noLimited++; }
1277 #ifdef G4DEBUG_PATHFINDER
1278 G4bool StepError= (currentStepSize < 0)
1279 || ( (minStepLast !=
kInfinity) && (diffStep < 0) ) ;
1284 G4cout <<
" G4PathFinder::ComputeStep. Geometry " << numNav
1286 <<
" from final-step= " << finalStep
1288 <<
" minStepLast= " << minStepLast
1289 <<
" limited = " << (
fLimitTruth[numNav] ?
"YES" :
" NO")
1291 G4cout <<
" status = " << limitedString <<
" #= " << didLimit
1296 std::ostringstream message;
1297 message <<
"Incorrect calculation of step size for one navigator"
1299 <<
" currentStepSize = " << currentStepSize
1300 <<
", diffStep= " << diffStep << G4endl
1301 <<
"ERROR in computing step size for this navigator.";
1311 else if ( (minStep == proposedStepLength)
1313 || ( std::abs(minStep-proposedStepLength)
1314 < toleratedRelativeError * proposedStepLength ) )
1323 currentStepSize= minStep;
1335 std::ostringstream message;
1336 message <<
"Incorrect calculation of step size for one navigator." <<
G4endl
1337 <<
" currentStepSize = " << minStep <<
" is larger than "
1338 <<
" proposed StepSize = " << proposedStepLength <<
".";
1343 #ifdef G4DEBUG_PATHFINDER
1346 G4cout <<
" Exiting G4PathFinder::DoNextCurvedStep " <<
G4endl;
1358 StrUnique(
"Unique"),
1359 StrUndefined(
"Undefined"),
1360 StrSharedTransport(
"SharedTransport"),
1361 StrSharedOther(
"SharedOther");
1366 case kDoNot: limitedStr= &StrDoNot;
break;
1367 case kUnique: limitedStr = &StrUnique;
break;
1369 case kSharedOther: limitedStr = &StrSharedOther;
break;
1370 default: limitedStr = &StrUndefined;
break;
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
G4bool fLimitTruth[fMaxNav]
G4String & LimitedString(ELimited lim)
static G4PathFinder * GetInstance()
ELimited fLimitedStep[fMaxNav]
void SetPosition(G4ThreeVector nPos)
G4MultiNavigator * fpMultiNavigator
G4double fNewSafetyComputed[fMaxNav]
G4TransportationManager * fpTransportManager
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
void SetNavigatorForPropagating(G4Navigator *SimpleOrMultiNavigator)
G4SafetyHelper * GetSafetyHelper() const
void EnableParallelNavigation(G4bool enableChoice=true)
static const G4int fMaxNav
G4double fMinSafety_PreStepPt
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
void ReLocate(const G4ThreeVector &position)
G4double GetSurfaceTolerance() const
G4Navigator * GetNavigatorForTracking() const
G4VPhysicalVolume * fLocatedVolume[fMaxNav]
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4ThreeVector fPreStepLocation
G4double fMinSafety_atSafLocation
G4double DoNextCurvedStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength, G4VPhysicalVolume *pCurrentPhysVolume)
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
G4int fNoActiveNavigators
G4double fCurrentPreStepSafety[fMaxNav]
static G4ThreadLocal G4PathFinder * fpPathFinder
G4ThreeVector GetPosition() const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
G4double GetRadialTolerance() const
G4Navigator * fpNavigator[fMaxNav]
void EnableParallelNavigation(G4bool parallel)
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
G4double DoNextLinearStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength)
G4double ComputeSafety(const G4ThreeVector &globalPoint)
G4FieldManager * FindAndSetFieldManager(G4VPhysicalVolume *pCurrentPhysVol)
void PushPostSafetyToPreSafety()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4TransportationManager * GetTransportationManager()
G4double GetCharge() const
G4double ComputeStep(G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4double &pNewSafety, G4VPhysicalVolume *pPhysVol=0)
G4double fPreSafetyValues[fMaxNav]
G4PropagatorInField * fpFieldPropagator
G4double fCurrentStepSize[fMaxNav]
G4ThreeVector fLastLocatedPosition
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::vector< G4Navigator * >::iterator GetActiveNavigatorsIterator()
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4ThreeVector fPreSafetyLocation
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=0)
static char * endPosition
const G4NavigationHistory * GetHistory() const
const G4Field * GetDetectorField() const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4bool fPreStepCenterRenewed
G4PropagatorInField * GetPropagatorInField() const
G4bool fFieldExertedForce
void ReportMove(const G4ThreeVector &OldV, const G4ThreeVector &NewV, const G4String &Quantity) const
G4int fNoGeometriesLimiting
G4VPhysicalVolume * GetWorldVolume() const
G4Navigator * GetNavigator(G4int n) const
G4ThreeVector fSafetyLocation
G4double fPreSafetyMinValue
static G4GeometryTolerance * GetInstance()
G4GLOB_DLL std::ostream G4cerr
G4ThreeVector GetMomentumDirection() const
void SetProperTimeOfFlight(G4double tofProper)