Belle II Software development
G4SafeNavigator Class Reference

Guards against leaving the physical volume. More...

Public Member Functions

G4VPhysicalVolume * GetWorldVolume () const
 Returns the Geant4 world volume.
 
void SetWorldVolume (G4VPhysicalVolume *pWorld)
 Sets the Geant4 world volume.
 
G4VPhysicalVolume * LocateGlobalPointAndSetup (const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
 Use Geant4's LocateGlobalPointAndSetup to get a G4VPhysicalVolume or use cached values from previous calls.
 
G4double CheckNextStep (const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
 Check if within world volume and call Geant4's CheckNextStep.
 
G4VPhysicalVolume * ResetHierarchyAndLocate (const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
 Call Geant4's ResetHierarchyAndLocate to get a G4VPhysicalVolume or use cached values from previous calls.
 
void SetGeometricallyLimitedStep ()
 Calls Geant4's SetGeometricallyLimitedStep.
 
G4TouchableHistory * CreateTouchableHistory () const
 Call Geant4's CreateTouchableHistory.
 

Private Member Functions

void installOurExceptionHandler ()
 Install our specific exception handler and cache the one which was set before.
 
void uninstallAndCheckOurExceptionHandler ()
 Reinstate the previously used exception handler and check whether a critical exception was recorded by our exception handler.
 

Private Attributes

G4ThreeVector lastpoint_
 the last point which has been queried with G4
 
G4VPhysicalVolume * lastvolume_ {0}
 the last volume which has been queried
 
G4Navigator nav_
 Geant4's navigator which calls are forwarded to.
 
const G4VSolid * worldsolid_ {0}
 The topmost solid of the G4 world.
 
G4VExceptionHandler * otherHandler = nullptr
 Stores the pointer to exception handler which this class temporarily replaces for most calls.
 
Geant4MaterialInterfaceExceptioHandler exceptionHandler
 Custom exception handler to handle stuck tracks properly (and abort)
 

Detailed Description

Guards against leaving the physical volume.

Not inheriting from G4Navigator because CheckNextStep is not virtual.

Definition at line 105 of file Geant4MaterialInterface.cc.

Member Function Documentation

◆ CheckNextStep()

G4double CheckNextStep ( const G4ThreeVector &  pGlobalPoint,
const G4ThreeVector &  pDirection,
const G4double  pCurrentProposedStepLength,
G4double &  pNewSafety 
)

Check if within world volume and call Geant4's CheckNextStep.

Definition at line 257 of file Geant4MaterialInterface.cc.

261{
262 //make sure we're inside the world volume
263 if (worldsolid_->Inside(point) == kOutside) {
264 pNewSafety = worldsolid_->DistanceToIn(point);
265 return worldsolid_->DistanceToIn(point, direction);
266 }
267
269 const auto distance = nav_.CheckNextStep(point, direction, pCurrentProposedStepLength, pNewSafety);
271
272 return distance;
273}
G4Navigator nav_
Geant4's navigator which calls are forwarded to.
void uninstallAndCheckOurExceptionHandler()
Reinstate the previously used exception handler and check whether a critical exception was recorded b...
const G4VSolid * worldsolid_
The topmost solid of the G4 world.
void installOurExceptionHandler()
Install our specific exception handler and cache the one which was set before.

◆ CreateTouchableHistory()

G4TouchableHistory * CreateTouchableHistory ( ) const
inline

Call Geant4's CreateTouchableHistory.

Definition at line 157 of file Geant4MaterialInterface.cc.

158 {
159 return nav_.CreateTouchableHistory();
160 }

◆ GetWorldVolume()

G4VPhysicalVolume * GetWorldVolume ( ) const
inline

Returns the Geant4 world volume.

Definition at line 113 of file Geant4MaterialInterface.cc.

113{ return nav_.GetWorldVolume(); }

◆ installOurExceptionHandler()

void installOurExceptionHandler ( )
inlineprivate

Install our specific exception handler and cache the one which was set before.

Be sure to call uninstallAndCheckOurExceptionHandler() once the G4Navigator call is completed.

Definition at line 168 of file Geant4MaterialInterface.cc.

169 {
170 otherHandler = G4StateManager::GetStateManager()->GetExceptionHandler();
172 G4StateManager::GetStateManager()->SetExceptionHandler(&exceptionHandler);
173 }
G4VExceptionHandler * otherHandler
Stores the pointer to exception handler which this class temporarily replaces for most calls.
Geant4MaterialInterfaceExceptioHandler exceptionHandler
Custom exception handler to handle stuck tracks properly (and abort)
void resetFailureState()
Reset the recorded failure state to be ready for the next calls to Geant4.

◆ LocateGlobalPointAndSetup()

G4VPhysicalVolume * LocateGlobalPointAndSetup ( const G4ThreeVector &  point,
const G4ThreeVector *  direction = 0,
const G4bool  pRelativeSearch = true,
const G4bool  ignoreDirection = true 
)

Use Geant4's LocateGlobalPointAndSetup to get a G4VPhysicalVolume or use cached values from previous calls.

Definition at line 213 of file Geant4MaterialInterface.cc.

217{
218 if (point == lastpoint_ && lastvolume_) {
219 return lastvolume_;
220 }
221 //B2INFO("### init: " << point);
222
224 G4VPhysicalVolume* volume = nav_.LocateGlobalPointAndSetup(point, direction, pRelativeSearch, ignoreDirection);
226
227 if (!volume) {
228 volume = nav_.GetWorldVolume();
229 }
230 // remember last point to speed up setup if possible
231 lastpoint_ = point;
232 lastvolume_ = volume;
233 return volume;
234}
G4ThreeVector lastpoint_
the last point which has been queried with G4
G4VPhysicalVolume * lastvolume_
the last volume which has been queried

◆ ResetHierarchyAndLocate()

G4VPhysicalVolume * ResetHierarchyAndLocate ( const G4ThreeVector &  point,
const G4ThreeVector &  direction,
const G4TouchableHistory &  h 
)

Call Geant4's ResetHierarchyAndLocate to get a G4VPhysicalVolume or use cached values from previous calls.

Definition at line 236 of file Geant4MaterialInterface.cc.

239{
240 if (point == lastpoint_ && lastvolume_) {
241 return lastvolume_;
242 }
243 //B2INFO("### reset: " << point);
245 G4VPhysicalVolume* volume = nav_.ResetHierarchyAndLocate(point, direction, h);
247
248 if (!volume) {
249 volume = nav_.GetWorldVolume();
250 }
251 // remember last point to speed up setup if possible
252 lastpoint_ = point;
253 lastvolume_ = volume;
254 return volume;
255}

◆ SetGeometricallyLimitedStep()

void SetGeometricallyLimitedStep ( )

Calls Geant4's SetGeometricallyLimitedStep.

Definition at line 208 of file Geant4MaterialInterface.cc.

209{
210 nav_.SetGeometricallyLimitedStep();
211}

◆ SetWorldVolume()

void SetWorldVolume ( G4VPhysicalVolume *  pWorld)
inline

Sets the Geant4 world volume.

Definition at line 118 of file Geant4MaterialInterface.cc.

119 {
120 nav_.SetWorldVolume(pWorld);
121 worldsolid_ = pWorld->GetLogicalVolume()->GetSolid();
122 }

◆ uninstallAndCheckOurExceptionHandler()

void uninstallAndCheckOurExceptionHandler ( )
inlineprivate

Reinstate the previously used exception handler and check whether a critical exception was recorded by our exception handler.

If so, throw a Genfit exception.

Definition at line 179 of file Geant4MaterialInterface.cc.

180 {
181 G4StateManager::GetStateManager()->SetExceptionHandler(otherHandler);
182
183 // was the a problem in the last usage ?
185 genfit::Exception exc("Geant4MaterialInterface::findNextBoundary ==> Geant4 exception during geometry navigation", __LINE__,
186 __FILE__);
187 exc.setFatal();
188 throw exc;
189 }
190 }
bool isInFailureState() const
Returns true if a problematic exception was encountered.

Member Data Documentation

◆ exceptionHandler

Geant4MaterialInterfaceExceptioHandler exceptionHandler
private

Custom exception handler to handle stuck tracks properly (and abort)

Definition at line 203 of file Geant4MaterialInterface.cc.

◆ lastpoint_

G4ThreeVector lastpoint_
private

the last point which has been queried with G4

Definition at line 193 of file Geant4MaterialInterface.cc.

◆ lastvolume_

G4VPhysicalVolume* lastvolume_ {0}
private

the last volume which has been queried

Definition at line 195 of file Geant4MaterialInterface.cc.

◆ nav_

G4Navigator nav_
private

Geant4's navigator which calls are forwarded to.

Definition at line 197 of file Geant4MaterialInterface.cc.

◆ otherHandler

G4VExceptionHandler* otherHandler = nullptr
private

Stores the pointer to exception handler which this class temporarily replaces for most calls.

Definition at line 201 of file Geant4MaterialInterface.cc.

◆ worldsolid_

const G4VSolid* worldsolid_ {0}
private

The topmost solid of the G4 world.

Definition at line 199 of file Geant4MaterialInterface.cc.


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