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

G4SafetyHelper is a helper class for physics processes which require knowledge of the safety, and the step size for the 'mass' geometry. More...

#include <G4SafetyHelper.hh>

Public Member Functions

 G4SafetyHelper ()
 ~G4SafetyHelper ()=default
G4double CheckNextStep (const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
G4double ComputeSafety (const G4ThreeVector &pGlobalPoint, G4double maxRadius=DBL_MAX)
void Locate (const G4ThreeVector &pGlobalPoint, const G4ThreeVector &direction)
void ReLocateWithinVolume (const G4ThreeVector &pGlobalPoint)
void EnableParallelNavigation (G4bool parallel)
void InitialiseNavigator ()
G4int SetVerboseLevel (G4int lev)
G4VPhysicalVolumeGetWorldVolume ()
void SetCurrentSafety (G4double val, const G4ThreeVector &pos)
void InitialiseHelper ()

Detailed Description

G4SafetyHelper is a helper class for physics processes which require knowledge of the safety, and the step size for the 'mass' geometry.

Definition at line 51 of file G4SafetyHelper.hh.

Constructor & Destructor Documentation

◆ G4SafetyHelper()

G4SafetyHelper::G4SafetyHelper ( )

Constructor and default Destructor.

Definition at line 39 of file G4SafetyHelper.cc.

40 : fLastSafetyPosition(0.0,0.0,0.0)
41{
42}

◆ ~G4SafetyHelper()

G4SafetyHelper::~G4SafetyHelper ( )
default

Member Function Documentation

◆ CheckNextStep()

G4double G4SafetyHelper::CheckNextStep ( const G4ThreeVector & position,
const G4ThreeVector & direction,
const G4double currentMaxStep,
G4double & newSafety )

Computes the distance in the mass geometry.

Parameters
[in]positionPoint in global coordinates.
[in]directionDirection.
[in]currentMaxStepProposed step length to nearest boundary.
[in,out]newSafetyNew safety.
Returns
The linear step for mass geometry.

Definition at line 76 of file G4SafetyHelper.cc.

80{
81 // Distance in the Mass geometry
82 //
83 G4double linstep = fpMassNavigator->CheckNextStep( position,
84 direction,
85 currentMaxStep,
86 newSafety);
87 fLastSafetyPosition = position;
88 fLastSafety = newSafety;
89
90 // TO-DO: Can replace this with a call to PathFinder
91 // giving id of Mass Geometry --> this avoid doing the work twice
92
93 return linstep;
94}
double G4double
Definition G4Types.hh:83

◆ ComputeSafety()

G4double G4SafetyHelper::ComputeSafety ( const G4ThreeVector & pGlobalPoint,
G4double maxRadius = DBL_MAX )

Computes the safety distance for all geometries.

Parameters
[in]pGlobalPointPoint in global coordinates.
[in]maxRadiusRadius of interest (e.g. maximum displacement). Giving this, one can reduce the average computational cost. If not provided, the real isotropic safety is computed.
Returns
The safety distance for all geometries.

Definition at line 97 of file G4SafetyHelper.cc.

99{
100 G4double newSafety;
101
102 // Only recompute (calling Navigator/PathFinder) if 'position'
103 // is *not* the safety location and has moved 'significantly'
104 //
105 G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
106 if( (moveLengthSq > 0.0 ) )
107 {
108 if( !fUseParallelGeometries )
109 {
110 // Safety for mass geometry
111 newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
112
113 // Only store a 'true' safety - one that was not restricted by maxLength
114 if( newSafety < maxLength )
115 {
116 fLastSafety= newSafety;
117 fLastSafetyPosition = position;
118 }
119 }
120 else
121 {
122 // Safety for all geometries
123 newSafety = fpPathFinder->ComputeSafety(position);
124
125 fLastSafety= newSafety;
126 fLastSafetyPosition = position;
127 }
128
129 }
130 else
131 {
132 // return last value if position is not (significantly) changed
133 //
134 // G4double moveLength = 0;
135 // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
136 newSafety = fLastSafety; // -moveLength;
137 }
138
139 return newSafety;
140}

◆ EnableParallelNavigation()

void G4SafetyHelper::EnableParallelNavigation ( G4bool parallel)
inline

Enables navigation in parallel geometries.

Parameters
[in]parallelFlag to have parallel worlds considered. Alternative is to use single (mass) navigator directly.

◆ GetWorldVolume()

G4VPhysicalVolume * G4SafetyHelper::GetWorldVolume ( )
inline

Retrieves the world volume of the mass geometry.

Returns
The pointer to the mass geometry world volume.

◆ InitialiseHelper()

void G4SafetyHelper::InitialiseHelper ( )

Initialises all data and navigator.

Definition at line 66 of file G4SafetyHelper.cc.

67{
68 fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
69 fLastSafety = 0.0;
70 if (fFirstCall) { InitialiseNavigator(); }
71 fFirstCall = false;
72}
CLHEP::Hep3Vector G4ThreeVector
void InitialiseNavigator()

Referenced by G4ElNeutrinoNucleusProcess::G4ElNeutrinoNucleusProcess(), G4MuNeutrinoNucleusProcess::G4MuNeutrinoNucleusProcess(), G4NeutrinoElectronProcess::G4NeutrinoElectronProcess(), G4TauNeutrinoNucleusProcess::G4TauNeutrinoNucleusProcess(), G4VMscModel::GetParticleChangeForMSC(), and G4VMultipleScattering::PreparePhysicsTable().

◆ InitialiseNavigator()

void G4SafetyHelper::InitialiseNavigator ( )

Checks for new navigator for tracking, and reinitialises pointer.

Definition at line 45 of file G4SafetyHelper.cc.

46{
47 fpPathFinder = G4PathFinder::GetInstance();
48
49 G4TransportationManager* pTransportMgr=
51
52 fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
53
54 // Check
55 //
56 G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume();
57 if( worldPV == nullptr )
58 {
59 G4Exception("G4SafetyHelper::InitialiseNavigator",
60 "GeomNav0003", FatalException,
61 "Found that existing tracking Navigator has NULL world");
62 }
63}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4VPhysicalVolume * GetWorldVolume() const
static G4PathFinder * GetInstance()
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const

Referenced by InitialiseHelper().

◆ Locate()

void G4SafetyHelper::Locate ( const G4ThreeVector & pGlobalPoint,
const G4ThreeVector & direction )

Locates the point for all geometries.

Parameters
[in]pGlobalPointPoint in global coordinates.
[in]directionDirection.

Definition at line 178 of file G4SafetyHelper.cc.

180{
181 if( !fUseParallelGeometries )
182 {
183 fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
184 true, false);
185 }
186 else
187 {
188 fpPathFinder->Locate( newPosition, newDirection );
189 }
190}

◆ ReLocateWithinVolume()

void G4SafetyHelper::ReLocateWithinVolume ( const G4ThreeVector & pGlobalPoint)

Relocates the point in the volume of interest.

Parameters
[in]pGlobalPointPoint in global coordinates.

Definition at line 143 of file G4SafetyHelper.cc.

144{
145#ifdef G4VERBOSE
146 if( fVerbose > 0 )
147 {
148 // There is an opportunity - and need - to check whether
149 // the proposed move is safe
150 G4ThreeVector moveVec = newPosition - fLastSafetyPosition;
151 if( moveVec.mag2() > sqr(fLastSafety) )
152 {
153 // A problem exists - we are proposing to move outside 'Safety Sphere'
155 ed << "Unsafe Move> Asked to relocate beyond 'Safety sphere'. Details: "
156 << G4endl;
157 ed << " Safety Sphere: Radius = " << fLastSafety;
158 ed << " Center = " << fLastSafetyPosition << G4endl;
159 ed << " New Location : Move = " << moveVec.mag();
160 ed << " Position = " << newPosition << G4endl;
161 G4Exception("G4SafetyHelper::ReLocateWithinVolume",
162 "GeomNav1001", JustWarning, ed);
163 }
164 }
165#endif
166
167 if( !fUseParallelGeometries )
168 {
169 fpMassNavigator->LocateGlobalPointWithinVolume( newPosition );
170 }
171 else
172 {
173 fpPathFinder->ReLocate( newPosition );
174 }
175}
@ JustWarning
std::ostringstream G4ExceptionDescription
#define G4endl
Definition G4ios.hh:67
double mag2() const
double mag() const
T sqr(const T &x)
Definition templates.hh:128

◆ SetCurrentSafety()

void G4SafetyHelper::SetCurrentSafety ( G4double val,
const G4ThreeVector & pos )
inline

Sets the safety value for the given position.

Parameters
[in]valThe safety value.
[in]posThe position.

◆ SetVerboseLevel()

G4int G4SafetyHelper::SetVerboseLevel ( G4int lev)
inline

Verbosity control.

Parameters
[in]levThe new verbosity level to enable.
Returns
The old verbosity level.

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