54 for(
auto num=0; num< fMaxNav; ++num )
56 fpNavigator[num] =
nullptr;
72 fLastMassWorld = pWorld;
87 G4double minSafety= kInfinity, minStep= kInfinity;
92#ifdef G4DEBUG_NAVIGATION
95 G4cout <<
" G4MultiNavigator::ComputeStep : entered " <<
G4endl;
96 G4cout <<
" Input position= " << pGlobalPoint
97 <<
" direction= " << pDirection <<
G4endl;
98 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
102 std::vector<G4Navigator*>::iterator pNavigatorIter;
104 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
109 for(
auto num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
113 step= (*pNavigatorIter)->ComputeStep( initialPosition,
117 if( safety < minSafety ){ minSafety = safety; }
118 if( step < minStep ) { minStep= step; }
124#ifdef G4DEBUG_NAVIGATION
127 G4cout <<
"G4MultiNavigator::ComputeStep : Navigator ["
128 << num <<
"] -- step size " << step
129 <<
" safety= " << safety <<
G4endl;
149#ifdef G4DEBUG_NAVIGATION
155 G4cout <<
"G4MultiNavigator::ComputeStep : "
156 <<
" initialPosition = " << initialPosition
157 <<
" and endPosition = " << endPosition <<
G4endl;
158 G4cout.precision( oldPrec );
162 pNewSafety = minSafety;
166#ifdef G4DEBUG_NAVIGATION
169 G4cout <<
" G4MultiNavigator::ComputeStep : exits returning "
185 if( navigatorId > fNoActiveNavigators )
187 std::ostringstream message;
188 message <<
"Bad Navigator Id!" <<
G4endl
189 <<
" Navigator Id = " << navigatorId
190 <<
" No Active = " << fNoActiveNavigators <<
".";
191 G4Exception(
"G4MultiNavigator::ObtainFinalStep()",
"GeomNav0002",
201#ifdef G4DEBUG_NAVIGATION
204 G4cout <<
" G4MultiNavigator::ComputeStep returns "
206 <<
" for Navigator " << navigatorId
207 <<
" Limited step = " << limitedStep
208 <<
" Safety(mm) = " << pNewSafety / mm <<
G4endl;
220#ifdef G4DEBUG_NAVIGATION
223 G4cout <<
" Entered G4MultiNavigator::PrepareNewTrack() " <<
G4endl;
244#ifdef G4DEBUG_NAVIGATION
247 G4cout <<
" Entered G4MultiNavigator::PrepareNavigators() " <<
G4endl;
253 std::vector<G4Navigator*>::iterator pNavigatorIter;
254 fNoActiveNavigators= pTransportManager-> GetNoActiveNavigators();
256 if( fNoActiveNavigators > fMaxNav )
258 std::ostringstream message;
259 message <<
"Too many active Navigators / worlds !" <<
G4endl
260 <<
" Active Navigators (worlds): "
261 << fNoActiveNavigators <<
G4endl
262 <<
" which is more than the number allowed: "
264 G4Exception(
"G4MultiNavigator::PrepareNavigators()",
"GeomNav0002",
269 for(
auto num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
271 fpNavigator[num] = *pNavigatorIter;
284 if( (massWorld != fLastMassWorld) && (massWorld!=0) )
289#ifdef G4DEBUG_NAVIGATION
292 G4cout <<
" G4MultiNavigator::PrepareNavigators() changed world volume "
293 <<
" for mass geometry to " << massWorld->
GetName() <<
G4endl;
297 fLastMassWorld = massWorld;
306 const G4bool pRelativeSearch,
307 const G4bool ignoreDirection )
312 G4bool relative = pRelativeSearch;
313 std::vector<G4Navigator*>::iterator pNavIter
316 if( pDirection ) { direction = *pDirection; }
318#ifdef G4DEBUG_NAVIGATION
321 G4cout <<
" Entered G4MultiNavigator::LocateGlobalPointAndSetup() "
324 <<
", with direction: " << direction <<
G4endl
325 <<
" Relative: " << relative
326 <<
", ignore direction: " << ignoreDirection <<
G4endl;
327 G4cout <<
" Number of active navigators: " << fNoActiveNavigators
332 for (
auto num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
336 (*pNavIter)->SetGeometricallyLimitedStep();
340 = (*pNavIter)->LocateGlobalPointAndSetup(
position, &direction,
341 relative, ignoreDirection );
352#ifdef G4DEBUG_NAVIGATION
357 <<
", found in volume: " << pLocated <<
G4endl;
366 G4cout <<
"Null' Id: Not-Set ";
376 return volMassLocated;
386 std::vector<G4Navigator*>::iterator pNavIter
389#ifdef G4DEBUG_NAVIGATION
392 G4cout <<
" Entered G4MultiNavigator::ReLocate() " <<
G4endl
397 for (
auto num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
401 (*pNavIter)->LocateGlobalPointWithinVolume(
position );
422 G4double minSafety = kInfinity, safety = kInfinity;
424 std::vector<G4Navigator*>::iterator pNavigatorIter;
425 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
427 for(
auto num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
429 safety = (*pNavigatorIter)->ComputeSafety(
position, maxDistance, state);
430 if( safety < minSafety ) { minSafety = safety; }
436#ifdef G4DEBUG_NAVIGATION
439 G4cout <<
" G4MultiNavigator::ComputeSafety - returns: "
451 G4Exception(
"G4MultiNavigator::CreateTouchableHistoryHandle()",
453 "Getting a touchable from G4MultiNavigator is not defined.");
459 if( locatedVolume ==
nullptr )
476 const G4int IdTransport= 0;
480#ifdef G4DEBUG_NAVIGATION
483 G4cout <<
" Entered G4MultiNavigator::WhichLimited() " <<
G4endl;
491 if( transportLimited )
496 for (
auto num = 0; num < fNoActiveNavigators; ++num )
502 limitedStep = ( step ==
fMinStep ) && ( step != kInfinity);
516 if( (last > -1) && (noLimited == 1 ) )
534 static const G4String StrDoNot(
"DoNot"), StrUnique(
"Unique"),
535 StrUndefined(
"Undefined"),
536 StrSharedTransport(
"SharedTransport"),
537 StrSharedOther(
"SharedOther");
538 G4cout <<
"### G4MultiNavigator::PrintLimited() reports: " <<
G4endl;
542#ifdef G4DEBUG_NAVIGATION
545 G4cout << std::setw(5) <<
" NavId" <<
" "
546 << std::setw(12) <<
" step-size " <<
" "
547 << std::setw(12) <<
" raw-size " <<
" "
548 << std::setw(12) <<
" pre-safety " <<
" "
549 << std::setw(15) <<
" Limited / flag" <<
" "
550 << std::setw(15) <<
" World " <<
" "
555 for (
auto num = 0; num < fNoActiveNavigators; ++num )
565 G4cout << std::setw(5) << num <<
" "
566 << std::setw(12) << stepLen <<
" "
567 << std::setw(12) << rawStep <<
" "
569 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
573 case kDoNot : limitedStr = StrDoNot;
break;
574 case kUnique : limitedStr = StrUnique;
break;
577 default : limitedStr = StrUndefined;
break;
579 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
580 G4cout.precision(oldPrec);
592 G4cout <<
" " << WorldName ;
604 G4Exception(
"G4MultiNavigator::ResetState()",
"GeomNav0001",
606 "Cannot reset state for navigators of G4MultiNavigator.");
623 "Cannot setup hierarchy for navigators of G4MultiNavigator.");
633 if( navTrackWorld != fLastMassWorld )
637 "Mass world pointer has been changed." );
653 if( pMassNavigator !=
nullptr )
660 G4Exception(
"G4MultiNavigator::ResetHierarchyAndLocate()",
662 "Cannot reset hierarchy before navigators are initialised.");
665 std::vector<G4Navigator*>::iterator pNavIter=
668 for (
auto num = 0; num < fNoActiveNavigators ; ++pNavIter,++num )
670 G4bool relativeSearch, ignoreDirection;
674 relativeSearch=
false,
675 ignoreDirection=
false);
687 G4bool isObtained =
false;
689 G4int firstNavigatorId = -1;
690 G4bool oneObtained =
false;
697 *argpObtained = isObtained;
703 std::vector<G4Navigator*>::iterator pNavIter=
706 for (
auto num = 0; num < fNoActiveNavigators ; ++pNavIter, ++num )
712 (*pNavIter)->GetGlobalExitNormal( argPoint, &oneObtained );
716 if( !isObtained && (newNormal.
mag2() != 0.0) )
718 normalGlobalCrd = newNormal;
719 isObtained = oneObtained;
720 firstNavigatorId = num;
725 G4double dotNewPrevious = newNormal.
dot( normalGlobalCrd );
727 if( productMagSq > 0.0 )
729 G4double productMag = std::sqrt( productMagSq );
730 dotNewPrevious /= productMag;
731 if( dotNewPrevious < (1 - perThousand) )
733 *argpObtained =
false;
737 std::ostringstream message;
738 message <<
"Clash of Normal from different Navigators!"
740 <<
" Previous Navigator Id = "
741 << firstNavigatorId <<
G4endl
742 <<
" Current Navigator Id = "
744 message <<
" Dot product of 2 normals = "
745 << dotNewPrevious <<
G4endl;
746 message <<
" Normal (previous) = "
747 << normalGlobalCrd <<
G4endl;
748 message <<
" Normal (current) = " << newNormal <<
G4endl;
749 G4Exception(
"G4MultiNavigator::GetGlobalExitNormal()",
766 std::ostringstream message;
768 <<
" candidate Navigators limiting the step!" <<
G4endl;
769 G4Exception(
"G4MultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
776 *argpObtained = isObtained;
777 return normalGlobalCrd;
787 G4bool isObtained =
false;
795 *argpObtained = isObtained;
798 G4int noWarningsStart = 10, noModuloWarnings = 100;
800 if( (numberWarnings < noWarningsStart )
801 || (numberWarnings%noModuloWarnings == 0) )
803 std::ostringstream message;
804 message <<
"Cannot obtain normal in local coordinates of two or more "
805 <<
"coordinate systems." <<
G4endl;
806 G4Exception(
"G4MultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
814 std::ostringstream message;
815 message <<
"Cannot obtain normal in local coordinates of two or more "
816 <<
"coordinate systems." <<
G4endl;
817 G4Exception(
"G4MultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
822 *argpObtained = isObtained;
823 return normalGlobalCrd;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define fMinSafety_atSafLocation
#define fLastLocatedPosition
#define fMinSafety_PreStepPt
G4ReferenceCountedHandle< G4TouchableHistory > G4TouchableHistoryHandle
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &E_Pt, G4bool *obtained)
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
void PrepareNewTrack(const G4ThreeVector position, const G4ThreeVector direction)
G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=false)
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
virtual G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &E_Pt, G4bool *obtained)
void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
virtual G4ThreeVector GetLocalExitNormal(G4bool *obtained)
G4TouchableHistoryHandle CreateTouchableHistoryHandle() const
G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4TouchableHistory * CreateTouchableHistory() const
G4bool fWasLimitedByGeometry
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
virtual G4ThreeVector GetLocalExitNormal(G4bool *valid)
void SetWorldVolume(G4VPhysicalVolume *pWorld)
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
G4VPhysicalVolume * GetWorldVolume() const
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=nullptr)
const G4NavigationHistory * GetHistory() const
std::vector< G4Navigator * >::iterator GetActiveNavigatorsIterator()
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const