45#define State(X) fpTrackState->X
46#define fLimitedStep State(fLimitedStep)
47#define fLimitTruth State(fLimitTruth)
48#define fCurrentStepSize State(fCurrentStepSize)
49#define fNewSafety State(fNewSafety)
50#define fNoLimitingStep State(fNoLimitingStep)
51#define fIdNavLimiting State(fIdNavLimiting)
52#define fMinStep State(fMinStep)
53#define fMinSafety State(fMinSafety)
54#define fTrueMinStep State(fTrueMinStep)
55#define fLocatedVolume State(fLocatedVolume)
56#define fLastLocatedPosition State(fLastLocatedPosition)
57#define fSafetyLocation State(fSafetyLocation)
58#define fMinSafety_atSafLocation State(fMinSafety_atSafLocation)
59#define fPreStepLocation State(fPreStepLocation)
60#define fMinSafety_PreStepPt State(fMinSafety_PreStepPt)
61#define fWasLimitedByGeometry State(fWasLimitedByGeometry)
69 fNoActiveNavigators= 0;
71 for(
auto & num : fpNavigator)
79 if( massNav !=
nullptr )
82 if( pWorld !=
nullptr )
84 SetWorldVolume( pWorld );
85 fLastMassWorld = pWorld;
99 G4double minSafety= kInfinity, minStep= kInfinity;
104#ifdef G4DEBUG_NAVIGATION
107 G4cout <<
" G4ITMultiNavigator::ComputeStep : entered " <<
G4endl;
108 G4cout <<
" Input position= " << pGlobalPoint
109 <<
" direction= " << pDirection <<
G4endl;
110 G4cout <<
" Requested step= " << proposedStepLength <<
G4endl;
114 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
116 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
121 for(
G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
125 step= (*pNavigatorIter)->ComputeStep( initialPosition,
129 if( safety < minSafety ){ minSafety = safety; }
130 if( step < minStep ) { minStep= step; }
136#ifdef G4DEBUG_NAVIGATION
139 G4cout <<
"G4ITMultiNavigator::ComputeStep : Navigator ["
140 << num <<
"] -- step size " << step
141 <<
" safety= " << safety <<
G4endl;
161#ifdef G4DEBUG_NAVIGATION
167 G4cout <<
"G4ITMultiNavigator::ComputeStep : "
168 <<
" initialPosition = " << initialPosition
169 <<
" and endPosition = " << endPosition <<
G4endl;
170 G4cout.precision( oldPrec );
174 pNewSafety = minSafety;
178#ifdef G4DEBUG_NAVIGATION
181 G4cout <<
" G4ITMultiNavigator::ComputeStep : exits returning "
197 if( navigatorId > fNoActiveNavigators )
199 std::ostringstream message;
200 message <<
"Bad Navigator Id!" <<
G4endl
201 <<
" Navigator Id = " << navigatorId
202 <<
" No Active = " << fNoActiveNavigators <<
".";
203 G4Exception(
"G4ITMultiNavigator::ObtainFinalStep()",
"GeomNav0002",
213#ifdef G4DEBUG_NAVIGATION
216 G4cout <<
" G4ITMultiNavigator::ComputeStep returns "
218 <<
" for Navigator " << navigatorId
219 <<
" Limited step = " << limitedStep
220 <<
" Safety(mm) = " << pNewSafety / mm <<
G4endl;
232#ifdef G4DEBUG_NAVIGATION
235 G4cout <<
" Entered G4ITMultiNavigator::PrepareNewTrack() " <<
G4endl;
256#ifdef G4DEBUG_NAVIGATION
259 G4cout <<
" Entered G4ITMultiNavigator::PrepareNavigators() " <<
G4endl;
265 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
266 fNoActiveNavigators = (
G4int)pTransportManager-> GetNoActiveNavigators();
268 if( fNoActiveNavigators > fMaxNav )
270 std::ostringstream message;
271 message <<
"Too many active Navigators / worlds !" <<
G4endl
272 <<
" Active Navigators (worlds): "
273 << fNoActiveNavigators <<
G4endl
274 <<
" which is more than the number allowed: "
276 G4Exception(
"G4ITMultiNavigator::PrepareNavigators()",
"GeomNav0002",
280 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
281 for(
G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
283 fpNavigator[num] = *pNavigatorIter;
296 if( (massWorld != fLastMassWorld) && (massWorld!=
nullptr) )
299 fpNavigator[0] -> SetWorldVolume( massWorld );
301#ifdef G4DEBUG_NAVIGATION
304 G4cout <<
" G4ITMultiNavigator::PrepareNavigators() changed world volume "
305 <<
" for mass geometry to " << massWorld->
GetName() <<
G4endl;
309 fLastMassWorld = massWorld;
318 const G4bool pRelativeSearch,
319 const G4bool ignoreDirection )
324 G4bool relative = pRelativeSearch;
328 if( pDirection !=
nullptr ) { direction = *pDirection; }
330#ifdef G4DEBUG_NAVIGATION
333 G4cout <<
" Entered G4ITMultiNavigator::LocateGlobalPointAndSetup() "
336 <<
", with direction: " << direction <<
G4endl
337 <<
" Relative: " << relative
338 <<
", ignore direction: " << ignoreDirection <<
G4endl;
339 G4cout <<
" Number of active navigators: " << fNoActiveNavigators
344 for (
G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
348 (*pNavIter)->SetGeometricallyLimitedStep();
352 = (*pNavIter)->LocateGlobalPointAndSetup(
position, &direction,
353 relative, ignoreDirection );
364#ifdef G4DEBUG_NAVIGATION
369 <<
", found in volume: " << pLocated <<
G4endl;
378 G4cout <<
"Null' Id: Not-Set ";
388 return volMassLocated;
401#ifdef G4DEBUG_NAVIGATION
404 G4cout <<
" Entered G4ITMultiNavigator::ReLocate() " <<
G4endl
409 for (
G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
413 (*pNavIter)->LocateGlobalPointWithinVolume(
position );
434 G4double minSafety = kInfinity, safety = kInfinity;
436 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
437 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
439 for(
G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
441 safety = (*pNavigatorIter)->ComputeSafety(
position, maxDistance, state);
442 if( safety < minSafety ) { minSafety = safety; }
448#ifdef G4DEBUG_NAVIGATION
451 G4cout <<
" G4ITMultiNavigator::ComputeSafety - returns: "
462 G4Exception(
"G4ITMultiNavigator::CreateTouchableHistoryHandle()",
464 "Getting a touchable from G4ITMultiNavigator is not defined.");
467 touchHist= fpNavigator[0] -> CreateTouchableHistory();
470 if( locatedVolume ==
nullptr )
487 const G4int IdTransport= 0;
491#ifdef G4DEBUG_NAVIGATION
494 G4cout <<
" Entered G4ITMultiNavigator::WhichLimited() " <<
G4endl;
502 if( transportLimited )
507 for (
G4int num= 0; num < fNoActiveNavigators; num++ )
513 limitedStep = ( step ==
fMinStep ) && ( step != kInfinity);
527 if( (last > -1) && (noLimited == 1 ) )
544 static const G4String StrDoNot(
"DoNot"), StrUnique(
"Unique"),
545 StrUndefined(
"Undefined"),
546 StrSharedTransport(
"SharedTransport"),
547 StrSharedOther(
"SharedOther");
548 G4cout <<
"### G4ITMultiNavigator::PrintLimited() reports: " <<
G4endl;
552#ifdef G4DEBUG_NAVIGATION
555 G4cout << std::setw(5) <<
" NavId" <<
" "
556 << std::setw(12) <<
" step-size " <<
" "
557 << std::setw(12) <<
" raw-size " <<
" "
558 << std::setw(12) <<
" pre-safety " <<
" "
559 << std::setw(15) <<
" Limited / flag" <<
" "
560 << std::setw(15) <<
" World " <<
" "
565 for (
G4int num= 0; num < fNoActiveNavigators; num++ )
575 G4cout << std::setw(5) << num <<
" "
576 << std::setw(12) << stepLen <<
" "
577 << std::setw(12) << rawStep <<
" "
579 << std::setw(5) << (
fLimitTruth[num] ?
"YES" :
" NO") <<
" ";
583 case kDoNot : limitedStr= StrDoNot;
break;
584 case kUnique : limitedStr = StrUnique;
break;
587 default : limitedStr = StrUndefined;
break;
589 G4cout <<
" " << std::setw(15) << limitedStr <<
" ";
590 G4cout.precision(oldPrec);
592 G4ITNavigator *pNav= fpNavigator[ num ];
597 if( pWorld !=
nullptr )
602 G4cout <<
" " << WorldName ;
614 G4Exception(
"G4ITMultiNavigator::ResetState()",
"GeomNav0001",
616 "Cannot reset state for navigators of G4ITMultiNavigator.");
618 std::vector<G4ITNavigator*>::iterator pNavigatorIter;
619 pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
620 for(
G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
630 G4Exception(
"G4ITMultiNavigator::SetupHierarchy()",
632 "Cannot setup hierarchy for navigators of G4ITMultiNavigator.");
642 if( navTrackWorld != fLastMassWorld )
644 G4Exception(
"G4ITMultiNavigator::CheckMassWorld()",
646 "Mass world pointer has been changed." );
660 G4ITNavigator* pMassNavigator= fpNavigator[0];
662 if( pMassNavigator !=
nullptr )
664 massVolume= pMassNavigator->ResetHierarchyAndLocate( point, direction,
669 G4Exception(
"G4ITMultiNavigator::ResetHierarchyAndLocate()",
671 "Cannot reset hierarchy before navigators are initialised.");
677 for (
G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
679 G4bool relativeSearch, ignoreDirection;
683 relativeSearch=
false,
684 ignoreDirection=
false);
698 G4int firstNavigatorId= -1;
699 G4bool oneObtained=
false;
704 normalGlobalCrd= fpNavigator[
fIdNavLimiting ]->GetGlobalExitNormal( argPoint, &isObtained);
705 *argpObtained= isObtained;
714 for (
G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
723 if( !isObtained && (newNormal.
mag2() != 0.0) )
725 normalGlobalCrd= newNormal;
726 isObtained = oneObtained;
727 firstNavigatorId= num;
730 G4double dotNewPrevious= newNormal.
dot( normalGlobalCrd );
732 if( productMagSq > 0.0 )
734 G4double productMag= std::sqrt( productMagSq );
735 dotNewPrevious /= productMag;
736 if( dotNewPrevious < (1 - perThousand) )
738 *argpObtained=
false;
742 std::ostringstream message;
743 message <<
"Clash of Normal from different Navigators!" <<
G4endl
744 <<
" Previous Navigator Id = " << firstNavigatorId <<
G4endl
745 <<
" Current Navigator Id = " << num <<
G4endl;
746 message <<
" Dot product of 2 normals = " << dotNewPrevious <<
G4endl;
747 message <<
" Normal (previous) = " << normalGlobalCrd <<
G4endl;
748 message <<
" Normal (current) = " << newNormal <<
G4endl;
749 G4Exception(
"G4ITMultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
766 std::ostringstream message;
768 <<
" candidate Navigators limiting the step!" <<
G4endl;
769 G4Exception(
"G4ITMultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
776 *argpObtained= isObtained;
777 return normalGlobalCrd;
793 normalGlobalCrd= fpNavigator[
fIdNavLimiting ]->GetLocalExitNormal( &isObtained);
794 *argpObtained= isObtained;
797 G4int noWarningsStart= 10, noModuloWarnings=100;
799 if( (numberWarnings < noWarningsStart ) || (numberWarnings%noModuloWarnings==0) )
801 std::ostringstream message;
802 message <<
"Cannot obtain normal in local coordinates of two or more coordinate systems." <<
G4endl;
803 G4Exception(
"G4ITMultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
812 std::ostringstream message;
813 message <<
"Cannot obtain normal in local coordinates of two or more coordinate systems." <<
G4endl;
814 G4Exception(
"G4ITMultiNavigator::GetGlobalExitNormal()",
"GeomNav0002",
819 *argpObtained= isObtained;
820 return normalGlobalCrd;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define fWasLimitedByGeometry
#define fMinSafety_atSafLocation
#define fLastLocatedPosition
#define fMinSafety_PreStepPt
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
G4GLOB_DLL std::ostream G4cout
double dot(const Hep3Vector &) const
G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true) override
G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h) override
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety) override
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=false) override
G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &CurrentE_Point, G4bool *obtained) override
void ResetState() override
void PrepareNewTrack(const G4ThreeVector position, const G4ThreeVector direction)
G4TouchableHandle CreateTouchableHistoryHandle() const override
G4ThreeVector GetLocalExitNormal(G4bool *obtained) override
void SetupHierarchy() override
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &CurrentE_Point, G4bool *obtained) override
void LocateGlobalPointWithinVolume(const G4ThreeVector &position) override
~G4ITMultiNavigator() override
std::vector< G4ITNavigator * >::iterator GetActiveNavigatorsIterator()
static G4ITTransportationManager * GetTransportationManager()
G4ITNavigator * GetNavigatorForTracking() const
virtual const G4NavigationHistory * GetHistory() const
virtual void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=nullptr)
virtual G4int GetCopyNo() const =0
const G4String & GetName() const