Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PathFinder Class Reference

G4PathFinder directs the lock-stepped propagation of a track in the 'mass' and other parallel geometries. It ensures that tracking in a magnetic field sees these parallel geometries at each trial step and that the earliest boundary limits the step. More...

#include <G4PathFinder.hh>

Public Member Functions

 ~G4PathFinder ()
G4double ComputeStep (const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
void Locate (const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
void ReLocate (const G4ThreeVector &position)
void PrepareNewTrack (const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=nullptr)
void EndTrack ()
G4TouchableHandle CreateTouchableHandle (G4int navId) const
G4VPhysicalVolumeGetLocatedVolume (G4int navId) const
G4double GetCurrentSafety () const
G4double GetMinimumStep () const
unsigned int GetNumberGeometriesLimitingStep () const
G4double ComputeSafety (const G4ThreeVector &globalPoint)
G4double ObtainSafety (G4int navId, G4ThreeVector &globalCenterPoint)
void EnableParallelNavigation (G4bool enableChoice=true)
G4int SetVerboseLevel (G4int lev=-1)
G4int GetMaxLoopCount () const
void SetMaxLoopCount (G4int new_max)
void MovePoint ()
G4double LastPreSafety (G4int navId, G4ThreeVector &globCenterPoint, G4double &minSafety)
void PushPostSafetyToPreSafety ()
G4StringLimitedString (ELimited lim)

Static Public Member Functions

static G4PathFinderGetInstance ()
static G4PathFinderGetInstanceIfExist ()

Detailed Description

G4PathFinder directs the lock-stepped propagation of a track in the 'mass' and other parallel geometries. It ensures that tracking in a magnetic field sees these parallel geometries at each trial step and that the earliest boundary limits the step.

Definition at line 60 of file G4PathFinder.hh.

Constructor & Destructor Documentation

◆ ~G4PathFinder()

G4PathFinder::~G4PathFinder ( )

Destructor, called only by G4RunManagerKernel.

Definition at line 106 of file G4PathFinder.cc.

107{
108 delete fpMultiNavigator;
109 fpPathFinder = nullptr;
110}

Member Function Documentation

◆ ComputeSafety()

G4double G4PathFinder::ComputeSafety ( const G4ThreeVector & globalPoint)

Recomputes the safety for the relevant point, i.e. the endpoint of the last step. Maintains a vector of individual safety values (used by next method below).

Parameters
[in]globalPointPoint in global coordinates system.
Returns
The safety value for the specified point in the geometry.

Definition at line 735 of file G4PathFinder.cc.

736{
737 // Recompute safety for the relevant point
738
739 G4double minSafety = kInfinity;
740
741 std::vector<G4Navigator*>::iterator pNavigatorIter;
742 pNavigatorIter = fpTransportManager->GetActiveNavigatorsIterator();
743
744 for( auto num=0; num<fNoActiveNavigators; ++pNavigatorIter,++num )
745 {
746 G4double safety = (*pNavigatorIter)->ComputeSafety(position,DBL_MAX,true);
747 if( safety < minSafety ) { minSafety = safety; }
748 fNewSafetyComputed[num] = safety;
749 }
750
751 fSafetyLocation = position;
752 fMinSafety_atSafLocation = minSafety;
753
754#ifdef G4DEBUG_PATHFINDER
755 if( fVerboseLevel > 1 )
756 {
757 G4cout << " G4PathFinder::ComputeSafety - returns "
758 << minSafety << " at location " << position << G4endl;
759 }
760#endif
761 return minSafety;
762}
double G4double
Definition G4Types.hh:83
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
#define DBL_MAX
Definition templates.hh:62

Referenced by ReLocate().

◆ ComputeStep()

G4double G4PathFinder::ComputeStep ( const G4FieldTrack & pFieldTrack,
G4double pCurrentProposedStepLength,
G4int navigatorId,
G4int stepNo,
G4double & pNewSafety,
ELimited & limitedStep,
G4FieldTrack & EndState,
G4VPhysicalVolume * currentVolume )

Computes the next geometric Step, curved or linear. If it is called with a larger 'stepNo' it will execute a new step; if 'stepNo' is same as last call, then the results for the geometry with Id number 'navigatorId' will be returned.

Parameters
[in,out]pFieldTrackField track to be filled.
[in]pCurrentProposedStepLengthCurrent proposed step length.
[in]navigatorIdIdentifier of the geometry.
[in]stepNoStep number; see next step/check.
[in,out]pNewSafetyNew safety for this geometry.
[in,out]limitedStepStep characterisation to be returned.
[in,out]EndStateField track end state.
[in]currentVolumePointer to the current volume.
Returns
Step length.

Definition at line 142 of file G4PathFinder.cc.

150{
151 G4double possibleStep = -1.0;
152
153#ifdef G4DEBUG_PATHFINDER
154 if( fVerboseLevel > 2 )
155 {
156 G4cout << " -------------------------" << G4endl;
157 G4cout << " G4PathFinder::ComputeStep - entered " << G4endl;
158 G4cout << " - stepNo = " << std::setw(4) << stepNo << " "
159 << " navigatorId = " << std::setw(2) << navigatorNo << " "
160 << " proposed step len = " << proposedStepLength << " " << G4endl;
161 G4cout << " PF::ComputeStep requested step "
162 << " from " << InitialFieldTrack.GetPosition()
163 << " dir " << InitialFieldTrack.GetMomentumDirection() << G4endl;
164 }
165#endif
166#ifdef G4VERBOSE
167 if( navigatorNo >= fNoActiveNavigators )
168 {
169 std::ostringstream message;
170 message << "Bad Navigator ID !" << G4endl
171 << " Requested Navigator ID = " << navigatorNo << G4endl
172 << " Number of active navigators = " << fNoActiveNavigators;
173 G4Exception("G4PathFinder::ComputeStep()", "GeomNav0002",
174 FatalException, message);
175 }
176#endif
177
178 if( fNewTrack || (stepNo != fLastStepNo) )
179 {
180 // This is a new track or a new step, so we must make the step
181 // ( else we can simply retrieve its results for this Navigator Id )
182
183 G4FieldTrack currentState = InitialFieldTrack;
184
185 fCurrentStepNo = stepNo;
186
187 // Check whether a process shifted the position
188 // since the last step -- by physics processes
189 //
190 G4ThreeVector newPosition = InitialFieldTrack.GetPosition();
191 G4ThreeVector moveVector = newPosition - fLastLocatedPosition;
192 G4double moveLenSq = moveVector.mag2();
193 if( moveLenSq > sqr(kCarTolerance) )
194 {
195 G4ThreeVector newDirection = InitialFieldTrack.GetMomentumDirection();
196#ifdef G4DEBUG_PATHFINDER
197 if( fVerboseLevel > 2 )
198 {
199 G4double moveLen= std::sqrt( moveLenSq );
200 G4cout << " G4PathFinder::ComputeStep : Point moved since last step "
201 << " -- at step # = " << stepNo << G4endl
202 << " by " << moveLen << " to " << newPosition << G4endl;
203 }
204#endif
205 MovePoint(); // Unintentional changed -- ????
206
207 // Relocate to cope with this move -- else could abort !?
208 //
209 Locate( newPosition, newDirection );
210 }
211
212 // Check whether the particle have an (EM) field force exerting upon it
213 //
214 G4double particleCharge = currentState.GetCharge();
215
216 G4FieldManager* fieldMgr = nullptr;
217 G4bool fieldExertsForce = false ;
218 if( particleCharge != 0.0 )
219 {
220 fieldMgr = fpFieldPropagator->FindAndSetFieldManager( currentVolume );
221
222 // Protect for case where field manager has no field (= field is zero)
223 //
224 fieldExertsForce = (fieldMgr != nullptr)
225 && (fieldMgr->GetDetectorField() != nullptr);
226 }
227 fFieldExertedForce = fieldExertsForce; // Store for use in later calls
228 // referring to this 'step'.
229
230 fNoGeometriesLimiting = -1; // At start of track, no process limited step
231 if( fieldExertsForce )
232 {
233 DoNextCurvedStep( currentState, proposedStepLength, currentVolume );
234 //--------------
235 }else{
236 DoNextLinearStep( currentState, proposedStepLength );
237 //--------------
238 }
239 fLastStepNo = stepNo;
240 fRelocatedPoint = false;
241
242#ifdef G4DEBUG_PATHFINDER
243 if ( (fNoGeometriesLimiting < 0)
244 || (fNoGeometriesLimiting > fNoActiveNavigators) )
245 {
246 std::ostringstream message;
247 message << "Number of geometries limiting the step not set." << G4endl
248 << " Number of geometries limiting step = "
249 << fNoGeometriesLimiting;
250 G4Exception("G4PathFinder::ComputeStep()",
251 "GeomNav0002", FatalException, message);
252 }
253#endif
254 }
255#ifdef G4DEBUG_PATHFINDER
256 else
257 {
258 const G4double checkTolerance = 1.0e-9;
259 if( proposedStepLength < fTrueMinStep * ( 1.0 - checkTolerance) )
260 { // For 2nd+ geometry
261 std::ostringstream message;
262 message.precision( 12 );
263 message << "Problem in step size request." << G4endl
264 << " Being requested to make a step which is shorter"
265 << " than the minimum Step " << G4endl
266 << " already computed for any Navigator/geometry during"
267 << " this tracking-step: " << G4endl
268 << " This could happen due to an error in process ordering."
269 << G4endl
270 << " Check that all physics processes are registered"
271 << " before all processes with a navigator/geometry."
272 << G4endl
273 << " If using pre-packaged physics list and/or"
274 << " functionality, please report this error."
275 << G4endl << G4endl
276 << " Additional information for problem: " << G4endl
277 << " Steps request/proposed = " << proposedStepLength
278 << G4endl
279 << " MinimumStep (true) = " << fTrueMinStep
280 << G4endl
281 << " MinimumStep (navraw) = " << fMinStep
282 << G4endl
283 << " Navigator raw return value" << G4endl
284 << " Requested step now = " << proposedStepLength
285 << G4endl
286 << " Difference min-req (absolute) = "
287 << fTrueMinStep-proposedStepLength << G4endl
288 << " Relative (to max of two) = "
289 << (fTrueMinStep-proposedStepLength)
290 / std::max(proposedStepLength, fTrueMinStep) << G4endl
291 << " -- Step info> stepNo= " << stepNo
292 << " last= " << fLastStepNo
293 << " newTr= " << fNewTrack << G4endl;
294 G4Exception("G4PathFinder::ComputeStep()",
295 "GeomNav0003", FatalException, message);
296 }
297 else
298 {
299 // This is neither a new track nor a new step -- just another
300 // client accessing information for the current track, step
301 // We will simply retrieve the results of the synchronous
302 // stepping for this Navigator Id below.
303 //
304 if( fVerboseLevel > 1 )
305 {
306 G4cout << " G4P::CS -> Not calling DoNextLinearStep: "
307 << " stepNo= " << stepNo << " last= " << fLastStepNo
308 << " new= " << fNewTrack << " Step already done" << G4endl;
309 }
310 }
311 }
312#endif
313
314 fNewTrack = false;
315
316 // Prepare the information to return
317
318 pNewSafety = fCurrentPreStepSafety[ navigatorNo ];
319 limitedStep = fLimitedStep[ navigatorNo ];
320
321 possibleStep = std::min(proposedStepLength, fCurrentStepSize[ navigatorNo ]);
322 EndState = fEndState; // now corrected for smaller step, if needed
323
324#ifdef G4DEBUG_PATHFINDER
325 if( fVerboseLevel > 0 )
326 {
327 G4cout << " G4PathFinder::ComputeStep returns "
328 << fCurrentStepSize[ navigatorNo ]
329 << " for Navigator " << navigatorNo
330 << " Limited step = " << limitedStep
331 << " Safety(mm) = " << pNewSafety / mm
332 << G4endl;
333 }
334#endif
335
336 return possibleStep;
337}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
bool G4bool
Definition G4Types.hh:86
double mag2() const
const G4Field * GetDetectorField() const
G4double GetCharge() const
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
void MovePoint()
T sqr(const T &x)
Definition templates.hh:128

◆ CreateTouchableHandle()

G4TouchableHandle G4PathFinder::CreateTouchableHandle ( G4int navId) const

Creates a touchable handle for the specified navigator.

Parameters
[in]navIdThe navigator identifier.
Returns
A touchable handle of the geometry.

Definition at line 768 of file G4PathFinder.cc.

769{
770#ifdef G4DEBUG_PATHFINDER
771 if( fVerboseLevel > 2 )
772 {
773 G4cout << "G4PathFinder::CreateTouchableHandle : navId = "
774 << navId << " -- " << GetNavigator(navId) << G4endl;
775 }
776#endif
777
778 G4TouchableHistory* touchHist;
779 touchHist = GetNavigator(navId)->CreateTouchableHistory();
780
781 G4VPhysicalVolume* locatedVolume = fLocatedVolume[navId];
782 if( locatedVolume == nullptr )
783 {
784 // Workaround to ensure that the touchable is fixed !! // TODO: fix
785
786 touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
787 }
788
789#ifdef G4DEBUG_PATHFINDER
790 if( fVerboseLevel > 2 )
791 {
792 G4String VolumeName("None");
793 if( locatedVolume ) { VolumeName = locatedVolume->GetName(); }
794 G4cout << " Touchable History created at address " << touchHist
795 << "; volume = " << locatedVolume << "; name= " << VolumeName
796 << G4endl;
797 }
798#endif
799
800 return touchHist;
801}
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=nullptr)
const G4NavigationHistory * GetHistory() const
const G4String & GetName() const

◆ EnableParallelNavigation()

void G4PathFinder::EnableParallelNavigation ( G4bool enableChoice = true)

To enable parallel navigation. Must call it to ensure that G4PathFinder is prepared, especially for curved tracks. If true it switches G4PropagatorInField to use G4MultiNavigator. Must call it with false to undo (i.e. G4PropagatorInField uses classic G4Navigator for tracking in such case).

Parameters
[in]enableChoiceFlag to enable/disable parallel navigation.

Definition at line 115 of file G4PathFinder.cc.

116{
117 G4Navigator *navigatorForPropagation = nullptr, *massNavigator = nullptr;
118
119 massNavigator = fpTransportManager->GetNavigatorForTracking();
120 if( enableChoice )
121 {
122 navigatorForPropagation = fpMultiNavigator;
123
124 // Enable SafetyHelper to use PF
125 //
126 fpTransportManager->GetSafetyHelper()->EnableParallelNavigation(true);
127 }
128 else
129 {
130 navigatorForPropagation = massNavigator;
131
132 // Disable SafetyHelper to use PF
133 //
134 fpTransportManager->GetSafetyHelper()->EnableParallelNavigation(false);
135 }
136 fpFieldPropagator->SetNavigatorForPropagating(navigatorForPropagation);
137}

Referenced by EndTrack(), and PrepareNewTrack().

◆ EndTrack()

void G4PathFinder::EndTrack ( )

Signals the end of tracking of the current track. Resets internal state and informs G4TransportationManager to use 'ordinary' Navigator.

Definition at line 432 of file G4PathFinder.cc.

436{
437 EnableParallelNavigation(false); // Else it will be continue to be used
438}
void EnableParallelNavigation(G4bool enableChoice=true)

◆ GetCurrentSafety()

G4double G4PathFinder::GetCurrentSafety ( ) const
inline

Returns the minimum value of safety after last ComputeStep().

◆ GetInstance()

◆ GetInstanceIfExist()

G4PathFinder * G4PathFinder::GetInstanceIfExist ( )
static

Retrieve singleton instance pointer.

Definition at line 66 of file G4PathFinder.cc.

67{
68 return fpPathFinder;
69}

Referenced by G4RunManagerKernel::~G4RunManagerKernel().

◆ GetLocatedVolume()

G4VPhysicalVolume * G4PathFinder::GetLocatedVolume ( G4int navId) const
inline

Returns the located volume for the specified navigator.

Parameters
[in]navIdThe navigator identifier.
Returns
A pointer to the located volume in the geometry.

◆ GetMaxLoopCount()

G4int G4PathFinder::GetMaxLoopCount ( ) const
inline

To get/set the maximum for the number of steps that a (looping) particle can take.

◆ GetMinimumStep()

G4double G4PathFinder::GetMinimumStep ( ) const
inline

Gets the minimum step size from the last ComputeStep() call.

Note
In case full step is taken, this is kInfinity.

◆ GetNumberGeometriesLimitingStep()

unsigned int G4PathFinder::GetNumberGeometriesLimitingStep ( ) const
inline

Returns the number of all geometries limiting the step.

◆ LastPreSafety()

G4double G4PathFinder::LastPreSafety ( G4int navId,
G4ThreeVector & globCenterPoint,
G4double & minSafety )
inline

Obtains the last safety needed in ComputeStep() for the specified geometry 'navId' (i.e. the last point at which ComputeStep() has recalculated the safety). Returns the point (center) for which this safety is valid and also the minimum safety over all navigators.

Parameters
[in]navIdThe navigator identifier.
[in,out]globCenterPointThe point (center) for which this safety is valid.
[in,out]minSafetyThe minimum safety over all navigators.
Returns
The safety value in the specified geometry.

◆ LimitedString()

G4String & G4PathFinder::LimitedString ( ELimited lim)

Utility to convert ELimited specification to a string.

Definition at line 1363 of file G4PathFinder.cc.

1364{
1365 static G4String StrDoNot("DoNot"),
1366 StrUnique("Unique"),
1367 StrUndefined("Undefined"),
1368 StrSharedTransport("SharedTransport"),
1369 StrSharedOther("SharedOther");
1370
1371 G4String* limitedStr;
1372 switch ( lim )
1373 {
1374 case kDoNot: limitedStr = &StrDoNot; break;
1375 case kUnique: limitedStr = &StrUnique; break;
1376 case kSharedTransport: limitedStr = &StrSharedTransport; break;
1377 case kSharedOther: limitedStr = &StrSharedOther; break;
1378 default: limitedStr = &StrUndefined; break;
1379 }
1380 return *limitedStr;
1381}
@ kDoNot
@ kUnique
@ kSharedOther
@ kSharedTransport

◆ Locate()

void G4PathFinder::Locate ( const G4ThreeVector & position,
const G4ThreeVector & direction,
G4bool relativeSearch = true )

Makes primary relocation of the global point in all navigators, and updates them.

Parameters
[in]positionPoint in global coordinates system.
[in]directionGlobal direction vector.
[in]relativeSearchIf set to true (default), the search begins is the geometrical hierarchy at the location of the last located point.

Definition at line 461 of file G4PathFinder.cc.

464{
465 // Locate the point in each geometry
466
467 auto pNavIter = fpTransportManager->GetActiveNavigatorsIterator();
468
469 G4ThreeVector lastEndPosition = fRelocatedPoint
470 ? fLastLocatedPosition
471 : fEndState.GetPosition();
472 fLastLocatedPosition = position;
473
474#ifdef G4DEBUG_PATHFINDER
475 static const G4double movLenTol = 10*sqr(kCarTolerance);
476
477 G4ThreeVector moveVec = ( position - lastEndPosition );
478 G4double moveLenSq = moveVec.mag2();
479 if( (!fNewTrack) && ( moveLenSq > movLenTol ) )
480 {
481 ReportMove( lastEndPosition, position,
482 " (End) Position / G4PathFinder::Locate" );
483 }
484
485 if( fVerboseLevel > 2 )
486 {
487 G4cout << G4endl;
488 G4cout << " G4PathFinder::Locate : entered " << G4endl;
489 G4cout << " -------------------- -------" << G4endl;
490 G4cout << " Locating at position " << position
491 << " with direction " << direction
492 << " relative= " << relative << G4endl;
493 if ( (fVerboseLevel > 1) || ( moveLenSq > 0.0) )
494 {
495 G4cout << " lastEndPosition = " << lastEndPosition
496 << " moveVec = " << moveVec
497 << " newTr = " << fNewTrack
498 << " relocated = " << fRelocatedPoint << G4endl;
499 }
500
501 G4cout << " Located at " << position ;
502 if( fNoActiveNavigators > 1 ) { G4cout << G4endl; }
503 }
504#endif
505
506 for ( auto num=0; num<fNoActiveNavigators ; ++pNavIter,++num )
507 {
508 // ... who limited the step ....
509
510 if( fLimitTruth[num] ) { (*pNavIter)->SetGeometricallyLimitedStep(); }
511
512 G4VPhysicalVolume *pLocated=
513 (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
514 relative,
515 false);
516 // Set the state related to the location
517 //
518 fLocatedVolume[num] = pLocated;
519
520 // Clear state related to the step
521 //
522 fLimitedStep[num] = kDoNot;
523 fCurrentStepSize[num] = 0.0;
524
525#ifdef G4DEBUG_PATHFINDER
526 if( fVerboseLevel > 2 )
527 {
528 G4cout << " - In world " << num << " geomLimStep= " << fLimitTruth[num]
529 << " gives volume= " << pLocated ;
530 if( pLocated )
531 {
532 G4cout << " name = '" << pLocated->GetName() << "'";
533 G4cout << " - CopyNo= " << pLocated->GetCopyNo();
534 }
535 G4cout << G4endl;
536 }
537#endif
538 }
539
540 fRelocatedPoint = false;
541}

Referenced by ComputeStep(), and PrepareNewTrack().

◆ MovePoint()

void G4PathFinder::MovePoint ( )
inline

Signals that the point location will be moved.

Note
Internal use primarily.

Referenced by ComputeStep(), and PrepareNewTrack().

◆ ObtainSafety()

G4double G4PathFinder::ObtainSafety ( G4int navId,
G4ThreeVector & globalCenterPoint )
inline

Obtains the safety for the specified navigator/geometry for last point 'computed' (i.e., the last point for which ComputeSafety() was called).

Parameters
[in]navIdThe navigator identifier.
[in,out]globalCenterPointThe point (center) for which this safety is valid.
Returns
The safety value in the specified geometry.

◆ PrepareNewTrack()

void G4PathFinder::PrepareNewTrack ( const G4ThreeVector & position,
const G4ThreeVector & direction,
G4VPhysicalVolume * massStartVol = nullptr )

Checks and caches the set of active navigators.

Parameters
[in]positionPoint in global coordinates system.
[in]directionGlobal direction vector.
[in]massStartVolPointer to the mass geometry world.

Definition at line 342 of file G4PathFinder.cc.

345{
346 // Key purposes:
347 // - Check and cache set of active navigators
348 // - Reset state for new track
349
350 G4int num=0;
351
353 // Switch PropagatorInField to use MultiNavigator
354
355 fpTransportManager->GetSafetyHelper()->InitialiseHelper();
356 // Reinitialise state of safety helper -- avoid problems with overlaps
357
358 fNewTrack = true;
359 this->MovePoint(); // Signal further that the last status is wiped
360
361 fpFieldPropagator->PrepareNewTrack(); // Inform field propagator of new track
362
363 // Message the G4NavigatorPanel / Dispatcher to find active navigators
364 //
365 std::vector<G4Navigator*>::iterator pNavigatorIter;
366
367 fNoActiveNavigators = (G4int)fpTransportManager-> GetNoActiveNavigators();
368 if( fNoActiveNavigators > fMaxNav )
369 {
370 std::ostringstream message;
371 message << "Too many active Navigators / worlds." << G4endl
372 << " Transportation Manager has "
373 << fNoActiveNavigators << " active navigators." << G4endl
374 << " This is more than the number allowed = "
375 << fMaxNav << " !";
376 G4Exception("G4PathFinder::PrepareNewTrack()", "GeomNav0002",
377 FatalException, message);
378 }
379
380 fpMultiNavigator->PrepareNavigators();
381 //------------------------------------
382
383 pNavigatorIter = fpTransportManager->GetActiveNavigatorsIterator();
384 for( num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
385 {
386 // Keep information in C-array ... for creating touchables - at least
387 //
388 fpNavigator[num] = *pNavigatorIter;
389 fLimitTruth[num] = false;
390 fLimitedStep[num] = kDoNot;
391 fCurrentStepSize[num] = 0.0;
392 fLocatedVolume[num] = nullptr;
393 }
394 fNoGeometriesLimiting = 0; // At start of track, no process limited step
395
396 // In case of one geometry, the tracking will have done the locating!!
397
398 if( fNoActiveNavigators > 1 )
399 {
400 Locate( position, direction, false );
401 }
402 else
403 {
404 // Update state -- depending on the tracking's call to Mass Navigator
405
406 fLastLocatedPosition = position;
407 fLocatedVolume[0] = massStartVol; // This information must be given
408 // by transportation
409 fLimitedStep[0] = kDoNot;
410 fCurrentStepSize[0] = 0.0;
411 }
412
413 // Reset Safety Information -- as in case of overlaps this can cause
414 // inconsistencies ...
415 //
416 fMinSafety_PreStepPt = fPreSafetyMinValue = fMinSafety_atSafLocation = 0.0;
417
418 for( num=0; num<fNoActiveNavigators; ++num )
419 {
420 fPreSafetyValues[num] = 0.0;
421 fNewSafetyComputed[num] = 0.0;
422 fCurrentPreStepSafety[num] = 0.0;
423 }
424
425 // The first location for each Navigator must be non-relative
426 // or else call ResetStackAndState() for each Navigator
427
428 fRelocatedPoint = false;
429}
int G4int
Definition G4Types.hh:85

◆ PushPostSafetyToPreSafety()

void G4PathFinder::PushPostSafetyToPreSafety ( )

Tells G4PathFinder to copy PostStep Safety to PreSafety for use at the next step.

Definition at line 1383 of file G4PathFinder.cc.

1384{
1385 fPreSafetyLocation = fSafetyLocation;
1386 fPreSafetyMinValue = fMinSafety_atSafLocation;
1387 for( auto nav=0; nav < fNoActiveNavigators; ++nav )
1388 {
1389 fPreSafetyValues[nav] = fNewSafetyComputed[nav];
1390 }
1391}

◆ ReLocate()

void G4PathFinder::ReLocate ( const G4ThreeVector & position)

Makes secondary relocation of the global point (within safety only) in all navigators, and updates them.

Parameters
[in]positionPoint in global coordinates system.

Definition at line 543 of file G4PathFinder.cc.

544{
545 // Locate the point in each geometry
546
547 auto pNavIter = fpTransportManager->GetActiveNavigatorsIterator();
548
549#ifdef G4DEBUG_PATHFINDER
550
551 // Check that this relocation does not violate safety
552 // - at endpoint (computed from start point) AND
553 // - at last safety location (likely just called)
554
555 G4ThreeVector lastEndPosition = fEndState.GetPosition();
556
557 // Calculate end-point safety ...
558 //
559 G4double DistanceStartEnd = (lastEndPosition - fPreStepLocation).mag();
560 G4double endPointSafety_raw = fMinSafety_PreStepPt - DistanceStartEnd;
561 G4double endPointSafety_Est1 = std::max( 0.0, endPointSafety_raw );
562
563 // ... and check move from endpoint against this endpoint safety
564 //
565 G4ThreeVector moveVecEndPos = position - lastEndPosition;
566 G4double moveLenEndPosSq = moveVecEndPos.mag2();
567
568 // Check that move from endpoint of last step is within safety
569 // -- or check against last location or relocation ??
570 //
571 G4ThreeVector moveVecSafety = position - fSafetyLocation;
572 G4double moveLenSafSq = moveVecSafety.mag2();
573
574 G4double distCheckEnd_sq = ( moveLenEndPosSq - endPointSafety_Est1
575 *endPointSafety_Est1 );
576 G4double distCheckSaf_sq = ( moveLenSafSq - fMinSafety_atSafLocation
577 *fMinSafety_atSafLocation );
578
579 G4bool longMoveEnd = distCheckEnd_sq > 0.0;
580 G4bool longMoveSaf = distCheckSaf_sq > 0.0;
581
582 G4double revisedSafety = 0.0;
583
584 if( (!fNewTrack) && ( longMoveEnd && longMoveSaf ) )
585 {
586 // Recompute ComputeSafety for end position
587 //
588 revisedSafety = ComputeSafety(lastEndPosition);
589
590 const G4double kRadTolerance =
592 const G4double cErrorTolerance = 1e-12;
593 // Maximum relative error from roundoff of arithmetic
594
595 G4double distCheckRevisedEnd = moveLenEndPosSq - sqr(revisedSafety);
596
597 G4bool longMoveRevisedEnd = ( distCheckRevisedEnd > 0. ) ;
598
599 G4double moveMinusSafety = 0.0;
600 G4double moveLenEndPosition = std::sqrt( moveLenEndPosSq );
601 moveMinusSafety = moveLenEndPosition - revisedSafety;
602
603 if ( longMoveRevisedEnd && ( moveMinusSafety > 0.0 )
604 && ( revisedSafety > 0.0 ) )
605 {
606 // Take into account possibility of roundoff error causing
607 // this apparent move further than safety
608
609 if( fVerboseLevel > 0 )
610 {
611 G4cout << " G4PF:Relocate> Ratio to revised safety is "
612 << std::fabs(moveMinusSafety)/revisedSafety << G4endl;
613 }
614
615 G4double absMoveMinusSafety = std::fabs(moveMinusSafety);
616 G4bool smallRatio = absMoveMinusSafety < kRadTolerance * revisedSafety;
617 G4double maxCoordPos = std::max(
618 std::max( std::fabs(position.x()),
619 std::fabs(position.y())),
620 std::fabs(position.z()) );
621 G4bool smallValue= absMoveMinusSafety < cErrorTolerance * maxCoordPos;
622 if( !(smallRatio || smallValue) )
623 {
624 G4cout << " G4PF:Relocate> Ratio to revised safety is "
625 << std::fabs(moveMinusSafety)/revisedSafety << G4endl;
626 G4cout << " Difference of move and safety is not very small."
627 << G4endl;
628 }
629 else
630 {
631 moveMinusSafety = 0.0;
632 longMoveRevisedEnd = false; // Numerical issue -- not too long!
633
634 G4cout << " Difference of move & safety is very small in magnitude, "
635 << absMoveMinusSafety << G4endl;
636 if( smallRatio )
637 {
638 G4cout << " ratio to safety " << revisedSafety
639 << " is " << absMoveMinusSafety / revisedSafety
640 << "smaller than " << kRadTolerance << " of safety ";
641 }
642 else
643 {
644 G4cout << " as fraction " << absMoveMinusSafety / maxCoordPos
645 << " of position vector max-coord " << maxCoordPos
646 << " smaller than " << cErrorTolerance ;
647 }
648 G4cout << " -- reset moveMinusSafety to "
649 << moveMinusSafety << G4endl;
650 }
651 }
652
653 if ( longMoveEnd && longMoveSaf
654 && longMoveRevisedEnd && (moveMinusSafety>0.0) )
655 {
656 std::ostringstream message;
657 message.precision(9);
658 message << "ReLocation is further than end-safety value." << G4endl
659 << " Moved from last endpoint by " << moveLenEndPosition
660 << " compared to end safety (from preStep point) = "
661 << endPointSafety_Est1 << G4endl
662 << " --> last PreSafety Location was " << fPreSafetyLocation
663 << G4endl
664 << " safety value = " << fPreSafetyMinValue << G4endl
665 << " --> last PreStep Location was " << fPreStepLocation
666 << G4endl
667 << " safety value = " << fMinSafety_PreStepPt << G4endl
668 << " --> last EndStep Location was " << lastEndPosition
669 << G4endl
670 << " safety value = " << endPointSafety_Est1
671 << " raw-value = " << endPointSafety_raw << G4endl
672 << " --> Calling again at this endpoint, we get "
673 << revisedSafety << " as safety value." << G4endl
674 << " --> last position for safety " << fSafetyLocation
675 << G4endl
676 << " its safety value = " << fMinSafety_atSafLocation
677 << G4endl
678 << " move from safety location = "
679 << std::sqrt(moveLenSafSq) << G4endl
680 << " again= " << moveVecSafety.mag() << G4endl
681 << " safety - Move-from-end= "
682 << revisedSafety - moveLenEndPosition
683 << " (negative is Bad.)" << G4endl
684 << " Debug: distCheckRevisedEnd = "
685 << distCheckRevisedEnd;
686 ReportMove( lastEndPosition, position, "Position" );
687 G4Exception("G4PathFinder::ReLocate", "GeomNav0003",
688 FatalException, message);
689 }
690 }
691
692 if( fVerboseLevel > 2 )
693 {
694 G4cout << G4endl;
695 G4cout << " G4PathFinder::ReLocate : entered " << G4endl;
696 G4cout << " ---------------------- -------" << G4endl;
697 G4cout << " *Re*Locating at position " << position << G4endl;
698 if ( (fVerboseLevel > -1) || ( moveLenEndPosSq > 0.0) )
699 {
700 G4cout << " lastEndPosition = " << lastEndPosition
701 << " moveVec from step-end = " << moveVecEndPos
702 << " is new Track = " << fNewTrack
703 << " relocated = " << fRelocatedPoint << G4endl;
704 }
705 }
706#endif // G4DEBUG_PATHFINDER
707
708 for ( auto num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
709 {
710 // ... none limited the step
711
712 (*pNavIter)->LocateGlobalPointWithinVolume( position );
713
714 // Clear state related to the step
715 //
716 fLimitedStep[num] = kDoNot;
717 fCurrentStepSize[num] = 0.0;
718 fLimitTruth[num] = false;
719 }
720
721 fLastLocatedPosition = position;
722 fRelocatedPoint = true;
723
724#ifdef G4DEBUG_PATHFINDER
725 if( fVerboseLevel > 2 )
726 {
727 G4cout << " G4PathFinder::ReLocate : exiting "
728 << " at position " << fLastLocatedPosition << G4endl << G4endl;
729 }
730#endif
731}
double z() const
double x() const
double y() const
double mag() const
G4double GetRadialTolerance() const
static G4GeometryTolerance * GetInstance()
G4double ComputeSafety(const G4ThreeVector &globalPoint)

◆ SetMaxLoopCount()

void G4PathFinder::SetMaxLoopCount ( G4int new_max)
inline

◆ SetVerboseLevel()

G4int G4PathFinder::SetVerboseLevel ( G4int lev = -1)
inline

To control the level of verbosity. Default is no verbosity.


The documentation for this class was generated from the following files: