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
266 const G4double checkTolerance = 1.0e-9;
267 if( proposedStepLength <
fTrueMinStep * ( 1.0 + checkTolerance) )
269 std::ostringstream message;
270 message.precision( 12 );
271 message <<
"Problem in step size request." <<
G4endl
272 <<
" Being requested to make a step which is shorter"
273 <<
" than the minimum Step " <<
G4endl
274 <<
" already computed for any Navigator/geometry during"
275 <<
" this tracking-step: " <<
G4endl
276 <<
" This could happen due to an error in process ordering."
278 <<
" Check that all physics processes are registered"
279 <<
" before all processes with a navigator/geometry."
281 <<
" If using pre-packaged physics list and/or"
282 <<
" functionality, please report this error."
284 <<
" Additional information for problem: " <<
G4endl
285 <<
" Steps request/proposed = " << proposedStepLength
289 <<
" MinimumStep (navraw) = " <<
fMinStep
291 <<
" Navigator raw return value" <<
G4endl
292 <<
" Requested step now = " << proposedStepLength
294 <<
" Difference min-req (absolute) = "
296 <<
" Relative (to max of two) = "
299 <<
" -- Step info> stepNo= " << stepNo
314 G4cout <<
" G4P::CS -> Not calling DoNextLinearStep: "
315 <<
" stepNo= " << stepNo <<
" last= " <<
fLastStepNo
333 #ifdef G4DEBUG_PATHFINDER
336 G4cout <<
" G4PathFinder::ComputeStep returns "
338 <<
" for Navigator " << navigatorNo
339 <<
" Limited step = " << limitedStep
340 <<
" Safety(mm) = " << pNewSafety /
mm
374 std::vector<G4Navigator*>::iterator pNavigatorIter;
379 std::ostringstream message;
380 message <<
"Too many active Navigators / worlds." <<
G4endl
381 <<
" Transportation Manager has "
383 <<
" This is more than the number allowed = "
385 G4Exception(
"G4PathFinder::PrepareNewTrack()",
"GeomNav0002",
407 if( fNoActiveNavigators > 1 )
409 Locate( position, direction,
false );
456 std::ostringstream message;
457 message <<
"Endpoint moved between value returned by ComputeStep()"
458 <<
" and call to Locate(). " <<
G4endl
459 <<
" Change of " << Quantity <<
" is "
460 << moveVec.mag() /
mm <<
" mm long" <<
G4endl
461 <<
" and its vector is "
462 << (1.0/
mm) * moveVec <<
" mm " <<
G4endl
463 <<
" Endpoint of ComputeStep() was " << OldVector <<
G4endl
464 <<
" and current position to locate is " << NewVector;
465 G4Exception(
"G4PathFinder::ReportMove()",
"GeomNav1002",
477 std::vector<G4Navigator*>::iterator pNavIter=
486 ReportMove( position, lastEndPosition,
"Position" );
490 #ifdef G4DEBUG_PATHFINDER
496 G4cout <<
" Locating at position " << position
497 <<
" with direction " << direction
498 <<
" relative= " << relative <<
G4endl;
501 G4cout <<
" lastEndPosition = " << lastEndPosition
502 <<
" moveVec = " << moveVec
516 if(
fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
519 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
531 #ifdef G4DEBUG_PATHFINDER
535 <<
" gives volume= " << pLocated ;
538 G4cout <<
" name = '" << pLocated->GetName() <<
"'";
539 G4cout <<
" - CopyNo= " << pLocated->GetCopyNo();
553 std::vector<G4Navigator*>::iterator pNavIter=
556 #ifdef G4DEBUG_PATHFINDER
573 G4double moveLenEndPosSq = moveVecEndPos.mag2();
579 G4double moveLenSafSq= moveVecSafety.mag2();
581 G4double distCheckEnd_sq= ( moveLenEndPosSq - endPointSafety_Est1
582 *endPointSafety_Est1 );
586 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
587 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
591 if( (!
fNewTrack) && ( longMoveEnd && longMoveSaf ) )
599 const G4double cErrorTolerance=1e-12;
602 G4double distCheckRevisedEnd= moveLenEndPosSq-revisedSafety*revisedSafety;
604 G4bool longMoveRevisedEnd= ( distCheckRevisedEnd > 0. ) ;
607 G4double moveLenEndPosition= std::sqrt( moveLenEndPosSq );
608 moveMinusSafety = moveLenEndPosition - revisedSafety;
610 if ( longMoveRevisedEnd && (moveMinusSafety > 0.0 )
611 && ( revisedSafety > 0.0 ) )
618 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
619 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
622 G4double absMoveMinusSafety= std::fabs(moveMinusSafety);
623 G4bool smallRatio= absMoveMinusSafety < kRadTolerance * revisedSafety ;
626 std::fabs(position.y())),
627 std::fabs(position.z()) );
628 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
629 if( ! (smallRatio || smallValue) )
631 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
632 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
633 G4cout <<
" Difference of move and safety is not very small."
638 moveMinusSafety = 0.0;
639 longMoveRevisedEnd =
false;
641 G4cout <<
" Difference of move & safety is very small in magnitude, "
642 << absMoveMinusSafety <<
G4endl;
645 G4cout <<
" ratio to safety " << revisedSafety
646 <<
" is " << absMoveMinusSafety / revisedSafety
647 <<
"smaller than " << kRadTolerance <<
" of safety ";
651 G4cout <<
" as fraction " << absMoveMinusSafety / maxCoordPos
652 <<
" of position vector max-coord " << maxCoordPos
653 <<
" smaller than " << cErrorTolerance ;
655 G4cout <<
" -- reset moveMinusSafety to "
656 << moveMinusSafety <<
G4endl;
660 if ( longMoveEnd && longMoveSaf
661 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
664 std::ostringstream message;
665 message <<
"ReLocation is further than end-safety value." <<
G4endl
666 <<
" Moved from last endpoint by " << moveLenEndPosition
667 <<
" compared to end safety (from preStep point) = "
668 << endPointSafety_Est1 <<
G4endl
675 <<
" --> last EndStep Location was " << lastEndPosition
677 <<
" safety value = " << endPointSafety_Est1
678 <<
" raw-value = " << endPointSafety_raw <<
G4endl
679 <<
" --> Calling again at this endpoint, we get "
680 << revisedSafety <<
" as safety value." <<
G4endl
681 <<
" --> last position for safety " << fSafetyLocation
685 <<
" move from safety location = "
686 << std::sqrt(moveLenSafSq) <<
G4endl
687 <<
" again= " << moveVecSafety.mag() <<
G4endl
688 <<
" safety - Move-from-end= "
689 << revisedSafety - moveLenEndPosition
690 <<
" (negative is Bad.)" <<
G4endl
691 <<
" Debug: distCheckRevisedEnd = "
692 << distCheckRevisedEnd;
693 ReportMove( lastEndPosition, position,
"Position" );
694 G4Exception(
"G4PathFinder::ReLocate",
"GeomNav0003",
696 G4cout.precision(oldPrec);
703 G4cout <<
" G4PathFinder::ReLocate : entered " <<
G4endl;
705 G4cout <<
" *Re*Locating at position " << position <<
G4endl;
710 G4cout <<
" lastEndPosition = " << lastEndPosition
711 <<
" moveVec from step-end = " << moveVecEndPos
716 #endif // G4DEBUG_PATHFINDER
722 (*pNavIter)->LocateGlobalPointWithinVolume( position );
734 #ifdef G4DEBUG_PATHFINDER
737 G4cout <<
" G4PathFinder::ReLocate : exiting "
751 std::vector<G4Navigator*>::iterator pNavigatorIter;
756 G4double safety = (*pNavigatorIter)->ComputeSafety( position,
DBL_MAX,
true );
757 if( safety < minSafety ) { minSafety = safety; }
764 #ifdef G4DEBUG_PATHFINDER
767 G4cout <<
" G4PathFinder::ComputeSafety - returns "
768 << minSafety <<
" at location " << position <<
G4endl;
780 #ifdef G4DEBUG_PATHFINDER
783 G4cout <<
"G4PathFinder::CreateTouchableHandle : navId = "
789 touchHist=
GetNavigator(navId) -> CreateTouchableHistory();
792 if( locatedVolume == 0 )
799 #ifdef G4DEBUG_PATHFINDER
803 if( locatedVolume ) { VolumeName= locatedVolume->
GetName(); }
804 G4cout <<
" Touchable History created at address " << touchHist
805 <<
" volume = " << locatedVolume <<
" name= " << VolumeName
817 std::vector<G4Navigator*>::iterator pNavigatorIter;
821 const G4int IdTransport= 0;
824 #ifdef G4DEBUG_PATHFINDER
827 G4cout <<
" G4PathFinder::DoNextLinearStep : entered " <<
G4endl;
828 G4cout <<
" Input field track= " << initialState <<
G4endl;
829 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
837 G4double MagSqShift = OriginShift.mag2() ;
846 MagShift= std::sqrt(MagSqShift) ;
848 #ifdef G4PATHFINDER_OPTIMISATION
860 if( proposedStepLength < fullSafety )
871 minSafety=
std::min( safety, minSafety );
876 #ifdef G4DEBUG_PATHFINDER
879 G4cout <<
"G4PathFinder::DoNextLinearStep : Quick Stepping. " <<
G4endl
880 <<
" proposedStepLength " << proposedStepLength
881 <<
" < (full) safety = " << fullSafety
882 <<
" at " << initialPosition
888 #endif // End of G4PATHFINDER_OPTIMISATION 1
902 #ifdef G4PATHFINDER_OPTIMISATION
903 if( proposedStepLength <= safety )
909 #ifdef G4DEBUG_PATHFINDER
911 G4cout <<
"PathFinder::ComputeStep> small proposed step = "
912 << proposedStepLength
913 <<
" <= safety = " << safety <<
" for nav " << num
914 <<
" Step fully taken. " <<
G4endl;
918 #endif // End of G4PATHFINDER_OPTIMISATION 2
920 #ifdef G4DEBUG_PATHFINDER
923 step= (*pNavigatorIter)->ComputeStep( initialPosition,
932 #ifdef G4DEBUG_PATHFINDER
936 G4cout <<
"PathFinder::ComputeStep> long proposed step = "
937 << proposedStepLength
938 <<
" > safety = " << previousSafety
939 <<
" for nav " << num
940 <<
" . New safety = " << safety <<
" step= " << step
954 minSafety=
std::min( safety, minSafety );
956 #ifdef G4DEBUG_PATHFINDER
959 G4cout <<
"G4PathFinder::DoNextLinearStep : Navigator ["
960 << num <<
"] -- step size " << step <<
G4endl;
968 fPreSafetyLocation= initialPosition;
981 minStep = proposedStepLength;
990 endPosition= initialPosition + minStep * initialDirection ;
992 #ifdef G4DEBUG_PATHFINDER
995 G4cout <<
"G4PathFinder::DoNextLinearStep : "
996 <<
" initialPosition = " << initialPosition
997 <<
" and endPosition = " << endPosition<<
G4endl;
1018 #ifdef G4DEBUG_PATHFINDER
1021 G4cout <<
" G4PathFinder::DoNextLinearStep : exits returning "
1035 G4int num=-1, last=-1;
1039 const G4int IdTransport= 0;
1046 if( transportLimited ) {
1073 if( (last > -1) && (noLimited == 1 ) )
1078 #ifdef G4DEBUG_PATHFINDER
1083 G4cout <<
" G4PathFinder::WhichLimited - exiting. " <<
G4endl;
1093 G4cout <<
"G4PathFinder::PrintLimited reports: " ;
1099 G4cout << std::setw(5) <<
" Step#" <<
" "
1100 << std::setw(5) <<
" NavId" <<
" "
1101 << std::setw(12) <<
" step-size " <<
" "
1102 << std::setw(12) <<
" raw-size " <<
" "
1103 << std::setw(12) <<
" pre-safety " <<
" "
1104 << std::setw(15) <<
" Limited / flag" <<
" "
1105 << std::setw(15) <<
" World " <<
" "
1120 << std::setw(5) << num <<
" "
1121 << std::setw(12) << stepLen <<
" "
1122 << std::setw(12) << rawStep <<
" "
1124 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
1126 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
1127 G4cout.precision(oldPrec);
1136 WorldName = pWorld->
GetName();
1139 G4cout <<
" " << WorldName ;
1145 G4cout <<
" G4PathFinder::PrintLimited - exiting. " <<
G4endl;
1154 const G4double toleratedRelativeError= 1.0e-10;
1163 ->GetEquationOfMotion();
1169 #ifdef G4DEBUG_PATHFINDER
1173 G4cout <<
" G4PathFinder::DoNextCurvedStep ****** " <<
G4endl;
1174 G4cout <<
" Initial value of field track is " << fieldTrack
1175 <<
" and proposed step= " << proposedStepLength <<
G4endl;
1191 minSafety =
std::min( safety, minSafety );
1207 pCurrentPhysicalVolume );
1231 #ifdef G4DEBUG_PATHFINDER
1234 G4cout <<
"G4PathFinder::DoNextCurvedStep : " <<
G4endl
1235 <<
" initialState = " << initialState <<
G4endl
1237 G4cout <<
"G4PathFinder::DoNextCurvedStep : "
1238 <<
" minStep = " << minStep
1239 <<
" proposedStepLength " << proposedStepLength
1240 <<
" safety = " << newSafety <<
G4endl;
1244 if( minStep < proposedStepLength )
1252 G4double finalStep, lastPreSafety=0.0, minStepLast;
1257 minStepLast, didLimit );
1266 diffStep = (finalStep-minStepLast);
1267 if ( std::abs(diffStep) <= toleratedRelativeError * finalStep )
1271 currentStepSize += diffStep;
1288 if( limited ) { noLimited++; }
1290 #ifdef G4DEBUG_PATHFINDER
1291 G4bool StepError= (currentStepSize < 0)
1292 || ( (minStepLast !=
kInfinity) && (diffStep < 0) ) ;
1297 G4cout <<
" G4PathFinder::ComputeStep. Geometry " << numNav
1299 <<
" from final-step= " << finalStep
1301 <<
" minStepLast= " << minStepLast
1302 <<
" limited = " << (
fLimitTruth[numNav] ?
"YES" :
" NO")
1304 G4cout <<
" status = " << limitedString <<
" #= " << didLimit
1309 std::ostringstream message;
1310 message <<
"Incorrect calculation of step size for one navigator"
1312 <<
" currentStepSize = " << currentStepSize
1313 <<
", diffStep= " << diffStep << G4endl
1314 <<
"ERROR in computing step size for this navigator.";
1324 else if ( (minStep == proposedStepLength)
1326 || ( std::abs(minStep-proposedStepLength)
1327 < toleratedRelativeError * proposedStepLength ) )
1336 currentStepSize= minStep;
1348 std::ostringstream message;
1349 message <<
"Incorrect calculation of step size for one navigator." <<
G4endl
1350 <<
" currentStepSize = " << minStep <<
" is larger than "
1351 <<
" proposed StepSize = " << proposedStepLength <<
".";
1356 #ifdef G4DEBUG_PATHFINDER
1359 G4cout <<
" Exiting G4PathFinder::DoNextCurvedStep " <<
G4endl;
1395 minSafety =
std::min( safety, minSafety );
1396 minMove =
std::min( distance, minMove );
1402 *prDistance= minMove;
1403 if( prNewSafety ) *prNewSafety=
minSafety;
1417 StrUnique(
"Unique"),
1418 StrUndefined(
"Undefined"),
1419 StrSharedTransport(
"SharedTransport"),
1420 StrSharedOther(
"SharedOther");
1425 case kDoNot: limitedStr= &StrDoNot;
break;
1426 case kUnique: limitedStr = &StrUnique;
break;
1428 case kSharedOther: limitedStr = &StrSharedOther;
break;
1429 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
virtual void SetChargeMomentumMass(G4ChargeState particleCharge, G4double MomentumXc, G4double MassXc2)=0
CLHEP::Hep3Vector G4ThreeVector
const G4MagIntegratorStepper * GetStepper() const
void ReLocate(const G4ThreeVector &position)
G4double GetSurfaceTolerance() const
G4Navigator * GetNavigatorForTracking() const
G4VPhysicalVolume * fLocatedVolume[fMaxNav]
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4ThreeVector fPreStepLocation
G4double fMinSafety_atSafLocation
#define fFieldExertedForce
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 GetRestMass() const
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
virtual G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double CurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
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()
G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
static const G4double minSafety
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()
G4ChordFinder * GetChordFinder()
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)
const G4NavigationHistory * GetHistory() const
G4ThreeVector GetMomentum() const
const G4Field * GetDetectorField() const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4bool fPreStepCenterRenewed
G4MagInt_Driver * GetIntegrationDriver()
G4PropagatorInField * GetPropagatorInField() const
const G4ChargeState * GetChargeState() 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)