71 fFieldExertedForce(false),
72 fRelocatedPoint(true),
73 fLastStepNo(-1), fCurrentStepNo(-1),
99 for(
register int num=0; num<
fMaxNav; ++num )
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 );
443 std::ostringstream message;
444 message <<
"Endpoint moved between value returned by ComputeStep()"
445 <<
" and call to Locate(). " <<
G4endl
446 <<
" Change of " << Quantity <<
" is "
447 << moveVec.mag() /
mm <<
" mm long" <<
G4endl
448 <<
" and its vector is "
449 << (1.0/
mm) * moveVec <<
" mm " <<
G4endl
450 <<
" Endpoint of ComputeStep() was " << OldVector <<
G4endl
451 <<
" and current position to locate is " << NewVector;
452 G4Exception(
"G4PathFinder::ReportMove()",
"GeomNav1002",
464 std::vector<G4Navigator*>::iterator pNavIter=
473 ReportMove( position, lastEndPosition,
"Position" );
477 #ifdef G4DEBUG_PATHFINDER
483 G4cout <<
" Locating at position " << position
484 <<
" with direction " << direction
485 <<
" relative= " << relative <<
G4endl;
488 G4cout <<
" lastEndPosition = " << lastEndPosition
489 <<
" moveVec = " << moveVec
503 if(
fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
506 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
518 #ifdef G4DEBUG_PATHFINDER
522 <<
" gives volume= " << pLocated ;
525 G4cout <<
" name = '" << pLocated->GetName() <<
"'";
526 G4cout <<
" - CopyNo= " << pLocated->GetCopyNo();
540 std::vector<G4Navigator*>::iterator pNavIter=
543 #ifdef G4DEBUG_PATHFINDER
560 G4double moveLenEndPosSq = moveVecEndPos.mag2();
566 G4double moveLenSafSq= moveVecSafety.mag2();
568 G4double distCheckEnd_sq= ( moveLenEndPosSq - endPointSafety_Est1
569 *endPointSafety_Est1 );
573 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
574 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
578 if( (!
fNewTrack) && ( longMoveEnd && longMoveSaf ) )
586 const G4double cErrorTolerance=1e-12;
589 G4double distCheckRevisedEnd= moveLenEndPosSq-revisedSafety*revisedSafety;
591 G4bool longMoveRevisedEnd= ( distCheckRevisedEnd > 0. ) ;
594 G4double moveLenEndPosition= std::sqrt( moveLenEndPosSq );
595 moveMinusSafety = moveLenEndPosition - revisedSafety;
597 if ( longMoveRevisedEnd && (moveMinusSafety > 0.0 )
598 && ( revisedSafety > 0.0 ) )
605 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
606 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
609 G4double absMoveMinusSafety= std::fabs(moveMinusSafety);
610 G4bool smallRatio= absMoveMinusSafety < kRadTolerance * revisedSafety ;
613 std::fabs(position.y())),
614 std::fabs(position.z()) );
615 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
616 if( ! (smallRatio || smallValue) )
618 G4cout <<
" G4PF:Relocate> Ratio to revised safety is "
619 << std::fabs(moveMinusSafety)/revisedSafety <<
G4endl;
620 G4cout <<
" Difference of move and safety is not very small."
625 moveMinusSafety = 0.0;
626 longMoveRevisedEnd =
false;
628 G4cout <<
" Difference of move & safety is very small in magnitude, "
629 << absMoveMinusSafety <<
G4endl;
632 G4cout <<
" ratio to safety " << revisedSafety
633 <<
" is " << absMoveMinusSafety / revisedSafety
634 <<
"smaller than " << kRadTolerance <<
" of safety ";
638 G4cout <<
" as fraction " << absMoveMinusSafety / maxCoordPos
639 <<
" of position vector max-coord " << maxCoordPos
640 <<
" smaller than " << cErrorTolerance ;
642 G4cout <<
" -- reset moveMinusSafety to "
643 << moveMinusSafety <<
G4endl;
647 if ( longMoveEnd && longMoveSaf
648 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
651 std::ostringstream message;
652 message <<
"ReLocation is further than end-safety value." <<
G4endl
653 <<
" Moved from last endpoint by " << moveLenEndPosition
654 <<
" compared to end safety (from preStep point) = "
655 << endPointSafety_Est1 <<
G4endl
662 <<
" --> last EndStep Location was " << lastEndPosition
664 <<
" safety value = " << endPointSafety_Est1
665 <<
" raw-value = " << endPointSafety_raw <<
G4endl
666 <<
" --> Calling again at this endpoint, we get "
667 << revisedSafety <<
" as safety value." <<
G4endl
668 <<
" --> last position for safety " << fSafetyLocation
672 <<
" move from safety location = "
673 << std::sqrt(moveLenSafSq) <<
G4endl
674 <<
" again= " << moveVecSafety.mag() <<
G4endl
675 <<
" safety - Move-from-end= "
676 << revisedSafety - moveLenEndPosition
677 <<
" (negative is Bad.)" <<
G4endl
678 <<
" Debug: distCheckRevisedEnd = "
679 << distCheckRevisedEnd;
680 ReportMove( lastEndPosition, position,
"Position" );
681 G4Exception(
"G4PathFinder::ReLocate",
"GeomNav0003",
683 G4cout.precision(oldPrec);
690 G4cout <<
" G4PathFinder::ReLocate : entered " <<
G4endl;
692 G4cout <<
" *Re*Locating at position " << position <<
G4endl;
697 G4cout <<
" lastEndPosition = " << lastEndPosition
698 <<
" moveVec from step-end = " << moveVecEndPos
703 #endif // G4DEBUG_PATHFINDER
709 (*pNavIter)->LocateGlobalPointWithinVolume( position );
721 #ifdef G4DEBUG_PATHFINDER
724 G4cout <<
" G4PathFinder::ReLocate : exiting "
738 std::vector<G4Navigator*>::iterator pNavigatorIter;
743 G4double safety = (*pNavigatorIter)->ComputeSafety( position,
true );
744 if( safety < minSafety ) { minSafety = safety; }
751 #ifdef G4DEBUG_PATHFINDER
754 G4cout <<
" G4PathFinder::ComputeSafety - returns "
755 << minSafety <<
" at location " << position <<
G4endl;
767 #ifdef G4DEBUG_PATHFINDER
770 G4cout <<
"G4PathFinder::CreateTouchableHandle : navId = "
776 touchHist=
GetNavigator(navId) -> CreateTouchableHistory();
779 if( locatedVolume == 0 )
786 #ifdef G4DEBUG_PATHFINDER
790 if( locatedVolume ) { VolumeName= locatedVolume->
GetName(); }
791 G4cout <<
" Touchable History created at address " << touchHist
792 <<
" volume = " << locatedVolume <<
" name= " << VolumeName
804 std::vector<G4Navigator*>::iterator pNavigatorIter;
808 const G4int IdTransport= 0;
809 register G4int num=0;
811 #ifdef G4DEBUG_PATHFINDER
814 G4cout <<
" G4PathFinder::DoNextLinearStep : entered " <<
G4endl;
815 G4cout <<
" Input field track= " << initialState <<
G4endl;
816 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
824 G4double MagSqShift = OriginShift.mag2() ;
833 MagShift= std::sqrt(MagSqShift) ;
835 #ifdef G4PATHFINDER_OPTIMISATION
847 if( proposedStepLength < fullSafety )
858 minSafety=
std::min( safety, minSafety );
863 #ifdef G4DEBUG_PATHFINDER
866 G4cout <<
"G4PathFinder::DoNextLinearStep : Quick Stepping. " <<
G4endl
867 <<
" proposedStepLength " << proposedStepLength
868 <<
" < (full) safety = " << fullSafety
869 <<
" at " << initialPosition
875 #endif // End of G4PATHFINDER_OPTIMISATION 1
889 #ifdef G4PATHFINDER_OPTIMISATION
890 if( proposedStepLength <= safety )
896 #ifdef G4DEBUG_PATHFINDER
898 G4cout <<
"PathFinder::ComputeStep> small proposed step = "
899 << proposedStepLength
900 <<
" <= safety = " << safety <<
" for nav " << num
901 <<
" Step fully taken. " <<
G4endl;
905 #endif // End of G4PATHFINDER_OPTIMISATION 2
907 #ifdef G4DEBUG_PATHFINDER
910 step= (*pNavigatorIter)->ComputeStep( initialPosition,
919 #ifdef G4DEBUG_PATHFINDER
923 G4cout <<
"PathFinder::ComputeStep> long proposed step = "
924 << proposedStepLength
925 <<
" > safety = " << previousSafety
926 <<
" for nav " << num
927 <<
" . New safety = " << safety <<
" step= " << step
941 minSafety=
std::min( safety, minSafety );
943 #ifdef G4DEBUG_PATHFINDER
946 G4cout <<
"G4PathFinder::DoNextLinearStep : Navigator ["
947 << num <<
"] -- step size " << step <<
G4endl;
955 fPreSafetyLocation= initialPosition;
968 minStep = proposedStepLength;
977 endPosition= initialPosition + minStep * initialDirection ;
979 #ifdef G4DEBUG_PATHFINDER
982 G4cout <<
"G4PathFinder::DoNextLinearStep : "
983 <<
" initialPosition = " << initialPosition
984 <<
" and endPosition = " << endPosition<<
G4endl;
1005 #ifdef G4DEBUG_PATHFINDER
1008 G4cout <<
" G4PathFinder::DoNextLinearStep : exits returning "
1022 G4int num=-1, last=-1;
1026 const G4int IdTransport= 0;
1033 if( transportLimited ) {
1060 if( (last > -1) && (noLimited == 1 ) )
1065 #ifdef G4DEBUG_PATHFINDER
1070 G4cout <<
" G4PathFinder::WhichLimited - exiting. " <<
G4endl;
1080 G4cout <<
"G4PathFinder::PrintLimited reports: " ;
1086 G4cout << std::setw(5) <<
" Step#" <<
" "
1087 << std::setw(5) <<
" NavId" <<
" "
1088 << std::setw(12) <<
" step-size " <<
" "
1089 << std::setw(12) <<
" raw-size " <<
" "
1090 << std::setw(12) <<
" pre-safety " <<
" "
1091 << std::setw(15) <<
" Limited / flag" <<
" "
1092 << std::setw(15) <<
" World " <<
" "
1107 << std::setw(5) << num <<
" "
1108 << std::setw(12) << stepLen <<
" "
1109 << std::setw(12) << rawStep <<
" "
1111 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
1113 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
1114 G4cout.precision(oldPrec);
1123 WorldName = pWorld->
GetName();
1126 G4cout <<
" " << WorldName ;
1132 G4cout <<
" G4PathFinder::PrintLimited - exiting. " <<
G4endl;
1141 const G4double toleratedRelativeError= 1.0e-10;
1147 #ifdef G4DEBUG_PATHFINDER
1151 G4cout <<
" G4PathFinder::DoNextCurvedStep ****** " <<
G4endl;
1152 G4cout <<
" Initial value of field track is " << fieldTrack
1153 <<
" and proposed step= " << proposedStepLength <<
G4endl;
1169 minSafety =
std::min( safety, minSafety );
1185 pCurrentPhysicalVolume );
1209 #ifdef G4DEBUG_PATHFINDER
1212 G4cout <<
"G4PathFinder::DoNextCurvedStep : " <<
G4endl
1213 <<
" initialState = " << initialState <<
G4endl
1215 G4cout <<
"G4PathFinder::DoNextCurvedStep : "
1216 <<
" minStep = " << minStep
1217 <<
" proposedStepLength " << proposedStepLength
1218 <<
" safety = " << newSafety <<
G4endl;
1222 if( minStep < proposedStepLength )
1230 G4double finalStep, lastPreSafety=0.0, minStepLast;
1235 minStepLast, didLimit );
1244 diffStep = (finalStep-minStepLast);
1245 if ( std::abs(diffStep) <= toleratedRelativeError * finalStep )
1249 currentStepSize += diffStep;
1266 if( limited ) { noLimited++; }
1268 #ifdef G4DEBUG_PATHFINDER
1269 G4bool StepError= (currentStepSize < 0)
1270 || ( (minStepLast !=
kInfinity) && (diffStep < 0) ) ;
1275 G4cout <<
" G4PathFinder::ComputeStep. Geometry " << numNav
1277 <<
" from final-step= " << finalStep
1279 <<
" minStepLast= " << minStepLast
1280 <<
" limited = " << (
fLimitTruth[numNav] ?
"YES" :
" NO")
1282 G4cout <<
" status = " << limitedString <<
" #= " << didLimit
1287 std::ostringstream message;
1288 message <<
"Incorrect calculation of step size for one navigator"
1290 <<
" currentStepSize = " << currentStepSize
1291 <<
", diffStep= " << diffStep << G4endl
1292 <<
"ERROR in computing step size for this navigator.";
1302 else if ( (minStep == proposedStepLength)
1304 || ( std::abs(minStep-proposedStepLength)
1305 < toleratedRelativeError * proposedStepLength ) )
1314 currentStepSize= minStep;
1326 std::ostringstream message;
1327 message <<
"Incorrect calculation of step size for one navigator." <<
G4endl
1328 <<
" currentStepSize = " << minStep <<
" is larger than "
1329 <<
" proposed StepSize = " << proposedStepLength <<
".";
1334 #ifdef G4DEBUG_PATHFINDER
1337 G4cout <<
" Exiting G4PathFinder::DoNextCurvedStep " <<
G4endl;
1349 StrUnique(
"Unique"),
1350 StrUndefined(
"Undefined"),
1351 StrSharedTransport(
"SharedTransport"),
1352 StrSharedOther(
"SharedOther");
1357 case kDoNot: limitedStr= &StrDoNot;
break;
1358 case kUnique: limitedStr = &StrUnique;
break;
1360 case kSharedOther: limitedStr = &StrSharedOther;
break;
1361 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 SetProperTimeOfFlight(G4double nTOF)
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