Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4SafetyHelper.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4SafetyHelper.cc 109355 2018-04-12 08:08:58Z gcosmo $
27 // GEANT4 tag $ Name: $
28 //
29 // class G4SafetyHelper Implementation
30 //
31 // Original author: John Apostolakis, 2006
32 //
33 // --------------------------------------------------------------------
34 
35 #include "G4SafetyHelper.hh"
36 #include "G4PathFinder.hh"
38 #include "G4Navigator.hh"
39 
40 #include "globals.hh"
41 
43  : fUseParallelGeometries(false), // By default, one geometry only
44  fFirstCall(true),
45  fVerbose(0),
46  fLastSafetyPosition(0.0,0.0,0.0),
47  fLastSafety(0.0)
48  // fRecomputeFactor(0.0)
49 {
50  fpPathFinder= 0; // Cannot initialise this yet - a loop results
51 
52  // Initialization of the Navigator pointer is postponed, and must
53  // be undertaken by another class calling InitialiseHelper()
54  //
55  fpMassNavigator= 0;
56  fMassNavigatorId= -1;
57 }
58 
60 {
62 
63  G4TransportationManager* pTransportMgr=
65 
66  fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
67 
68  // Check
69  //
71  if( worldPV == 0 )
72  {
73  G4Exception("G4SafetyHelper::InitialiseNavigator",
74  "InvalidNavigatorWorld", FatalException,
75  "Found that existing tracking Navigator has NULL world");
76  }
77 
79 }
80 
82 {
83  fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
84  fLastSafety = 0.0;
86  fFirstCall = false;
87 }
88 
90 {
91 }
92 
93 G4double
95  const G4ThreeVector &direction,
96  const G4double currentMaxStep,
97  G4double& newSafety )
98 {
99  // Distance in the Mass geometry
100  //
101  G4double linstep = fpMassNavigator->CheckNextStep( position,
102  direction,
103  currentMaxStep,
104  newSafety);
106  fLastSafety = newSafety;
107 
108  // TO-DO: Can replace this with a call to PathFinder
109  // giving id of Mass Geometry --> this avoid doing the work twice
110 
111  return linstep;
112 }
113 
115 {
116  G4double newSafety;
117 
118  // Only recompute (calling Navigator/PathFinder) if 'position'
119  // is *not* the safety location and has moved 'significantly'
120  //
121  G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
122  if( (moveLengthSq > 0.0 ) )
123  {
125  {
126  // Safety for mass geometry
127  newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
128 
129  // Only store a 'true' safety - one that was not restricted by maxLength
130  if( newSafety < maxLength )
131  {
132  fLastSafety= newSafety;
134  }
135  }
136  else
137  {
138  // Safety for all geometries
139  newSafety = fpPathFinder->ComputeSafety(position);
140 
141  fLastSafety= newSafety;
143  }
144 
145  }
146  else
147  {
148  // return last value if position is not (significantly) changed
149  //
150  // G4double moveLength = 0;
151  // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
152  newSafety = fLastSafety; // -moveLength;
153  }
154 
155  return newSafety;
156 }
157 
159 {
160  // G4cout << " G4SafetyHelper::ReLocateWithinVolume called at " << newPosition << G4endl;
161 #ifdef G4VERBOSE
162  if( fVerbose > 0 ) {
163  // There is an opportunity - and need - to check whether the proposed move is safe
164  G4ThreeVector moveVec= newPosition - fLastSafetyPosition;
165  if( moveVec.mag2() > sqr(fLastSafety) )
166  {
167  // A problem exists - we are proposing to move outside 'Safety Sphere'
169  ed << "Unsafe Move> Asked to relocate beyond 'Safety sphere'. Details: " << G4endl;
170  ed << " Safety Sphere: Radius = " << fLastSafety;
171  ed << " Center = " << fLastSafetyPosition << G4endl;
172  ed << " New Location : Move = " << moveVec.mag();
173  ed << " Position = " << newPosition << G4endl;
174  G4Exception("G4SafetyHelper::ReLocateWithinVolume", "GeomNav999", JustWarning, ed);
175  }
176  }
177 #endif
178 
180  {
182  }
183  else
184  {
185  fpPathFinder->ReLocate( newPosition );
186  }
187 }
188 
189 void G4SafetyHelper::Locate( const G4ThreeVector& newPosition,
190  const G4ThreeVector& newDirection)
191 {
193  {
194  fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
195  true, false);
196  }
197  else
198  {
199  fpPathFinder->Locate( newPosition, newDirection );
200  }
201 }
202 
204  const G4ThreeVector &pGlobalPoint,
205  const G4ThreeVector &pDirection,
206  const G4double aProposedMove,
207  G4double *prDistance,
208  G4double *prNewSafety) const
209 {
210  G4bool retval;
212  {
214  pGlobalPoint,
215  pDirection,
216  aProposedMove,
217  prDistance,
218  prNewSafety);
219  }
220  else
221  {
222  //G4Exception("G4Navigator::RecheckDistanceToCurrentBoundary()", "GeomNav0001",
223  // JustWarning, "Method NOT Available (yet) in case of Multiple Geometries (where PathFinder is involved.).");
225  pGlobalPoint,
226  pDirection,
227  aProposedMove,
228  prDistance,
229  prNewSafety);
230  }
231  return retval;
232 }
233 
void ReLocateWithinVolume(const G4ThreeVector &pGlobalPoint)
CLHEP::Hep3Vector G4ThreeVector
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
virtual void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
Definition: G4Navigator.cc:588
#define G4endl
Definition: G4ios.hh:61
G4double fLastSafety
G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
G4bool fUseParallelGeometries
G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const
void ReLocate(const G4ThreeVector &position)
G4Navigator * GetNavigatorForTracking() const
G4double CheckNextStep(const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
#define position
Definition: xmlparse.cc:622
void InitialiseNavigator()
double mag2() const
void InitialiseHelper()
G4double CheckNextStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
static G4TransportationManager * GetTransportationManager()
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
double mag() const
G4int ActivateNavigator(G4Navigator *aNavigator)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:131
G4Navigator * fpMassNavigator
G4double ComputeSafety(const G4ThreeVector &pGlobalPoint, G4double maxRadius=DBL_MAX)
T sqr(const T &x)
Definition: templates.hh:145
G4ThreeVector fLastSafetyPosition
G4VPhysicalVolume * GetWorldVolume() const
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:57
G4double ComputeSafety(const G4ThreeVector &globalPoint)
G4PathFinder * fpPathFinder
void Locate(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &direction)
virtual G4bool RecheckDistanceToCurrentBoundary(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double CurrentProposedStepLength, G4double *prDistance, G4double *prNewSafety=0) const