Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SafetyHelper.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// class G4SafetyHelper Implementation
27//
28// Original author: John Apostolakis, 2006
29// --------------------------------------------------------------------
30
31#include "G4SafetyHelper.hh"
32#include "G4PathFinder.hh"
34#include "G4Navigator.hh"
35
36#include "globals.hh"
37
39 : fLastSafetyPosition(0.0,0.0,0.0)
40{
41}
42
44{
45 fpPathFinder = G4PathFinder::GetInstance();
46
47 G4TransportationManager* pTransportMgr=
49
50 fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
51
52 // Check
53 //
54 G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume();
55 if( worldPV == nullptr )
56 {
57 G4Exception("G4SafetyHelper::InitialiseNavigator",
58 "GeomNav0003", FatalException,
59 "Found that existing tracking Navigator has NULL world");
60 }
61}
62
64{
65 fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
66 fLastSafety = 0.0;
67 if (fFirstCall) { InitialiseNavigator(); }
68 fFirstCall = false;
69}
70
72{
73}
74
77 const G4ThreeVector& direction,
78 const G4double currentMaxStep,
79 G4double& newSafety )
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}
95
97 G4double maxLength )
98{
99 G4double newSafety;
100
101 // Only recompute (calling Navigator/PathFinder) if 'position'
102 // is *not* the safety location and has moved 'significantly'
103 //
104 G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
105 if( (moveLengthSq > 0.0 ) )
106 {
107 if( !fUseParallelGeometries )
108 {
109 // Safety for mass geometry
110 newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
111
112 // Only store a 'true' safety - one that was not restricted by maxLength
113 if( newSafety < maxLength )
114 {
115 fLastSafety= newSafety;
116 fLastSafetyPosition = position;
117 }
118 }
119 else
120 {
121 // Safety for all geometries
122 newSafety = fpPathFinder->ComputeSafety(position);
123
124 fLastSafety= newSafety;
125 fLastSafetyPosition = position;
126 }
127
128 }
129 else
130 {
131 // return last value if position is not (significantly) changed
132 //
133 // G4double moveLength = 0;
134 // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
135 newSafety = fLastSafety; // -moveLength;
136 }
137
138 return newSafety;
139}
140
142{
143#ifdef G4VERBOSE
144 if( fVerbose > 0 )
145 {
146 // There is an opportunity - and need - to check whether
147 // the proposed move is safe
148 G4ThreeVector moveVec = newPosition - fLastSafetyPosition;
149 if( moveVec.mag2() > sqr(fLastSafety) )
150 {
151 // A problem exists - we are proposing to move outside 'Safety Sphere'
153 ed << "Unsafe Move> Asked to relocate beyond 'Safety sphere'. Details: "
154 << G4endl;
155 ed << " Safety Sphere: Radius = " << fLastSafety;
156 ed << " Center = " << fLastSafetyPosition << G4endl;
157 ed << " New Location : Move = " << moveVec.mag();
158 ed << " Position = " << newPosition << G4endl;
159 G4Exception("G4SafetyHelper::ReLocateWithinVolume",
160 "GeomNav1001", JustWarning, ed);
161 }
162 }
163#endif
164
165 if( !fUseParallelGeometries )
166 {
167 fpMassNavigator->LocateGlobalPointWithinVolume( newPosition );
168 }
169 else
170 {
171 fpPathFinder->ReLocate( newPosition );
172 }
173}
174
175void G4SafetyHelper::Locate( const G4ThreeVector& newPosition,
176 const G4ThreeVector& newDirection)
177{
178 if( !fUseParallelGeometries )
179 {
180 fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
181 true, false);
182 }
183 else
184 {
185 fpPathFinder->Locate( newPosition, newDirection );
186 }
187}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
#define G4endl
Definition: G4ios.hh:57
double mag2() const
double mag() const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
Definition: G4Navigator.cc:600
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:132
G4double CheckNextStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
G4VPhysicalVolume * GetWorldVolume() const
G4double ComputeSafety(const G4ThreeVector &globalPoint)
void ReLocate(const G4ThreeVector &position)
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:52
G4double ComputeSafety(const G4ThreeVector &pGlobalPoint, G4double maxRadius=DBL_MAX)
G4double CheckNextStep(const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
void InitialiseNavigator()
void Locate(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &direction)
void ReLocateWithinVolume(const G4ThreeVector &pGlobalPoint)
void InitialiseHelper()
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
T sqr(const T &x)
Definition: templates.hh:128