ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SafetyHelper.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 // 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 {
46 
47  G4TransportationManager* pTransportMgr=
49 
50  fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
51 
52  // Check
53  //
55  if( worldPV == nullptr )
56  {
57  G4Exception("G4SafetyHelper::InitialiseNavigator",
58  "GeomNav0003", FatalException,
59  "Found that existing tracking Navigator has NULL world");
60  }
61 
63 }
64 
66 {
67  fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
68  fLastSafety = 0.0;
70  fFirstCall = false;
71 }
72 
74 {
75 }
76 
77 G4double
79  const G4ThreeVector& direction,
80  const G4double currentMaxStep,
81  G4double& newSafety )
82 {
83  // Distance in the Mass geometry
84  //
85  G4double linstep = fpMassNavigator->CheckNextStep( position,
86  direction,
87  currentMaxStep,
88  newSafety);
90  fLastSafety = newSafety;
91 
92  // TO-DO: Can replace this with a call to PathFinder
93  // giving id of Mass Geometry --> this avoid doing the work twice
94 
95  return linstep;
96 }
97 
99  G4double maxLength )
100 {
101  G4double newSafety;
102 
103  // Only recompute (calling Navigator/PathFinder) if 'position'
104  // is *not* the safety location and has moved 'significantly'
105  //
106  G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
107  if( (moveLengthSq > 0.0 ) )
108  {
110  {
111  // Safety for mass geometry
112  newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
113 
114  // Only store a 'true' safety - one that was not restricted by maxLength
115  if( newSafety < maxLength )
116  {
117  fLastSafety= newSafety;
119  }
120  }
121  else
122  {
123  // Safety for all geometries
124  newSafety = fpPathFinder->ComputeSafety(position);
125 
126  fLastSafety= newSafety;
128  }
129 
130  }
131  else
132  {
133  // return last value if position is not (significantly) changed
134  //
135  // G4double moveLength = 0;
136  // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
137  newSafety = fLastSafety; // -moveLength;
138  }
139 
140  return newSafety;
141 }
142 
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 
168  {
170  }
171  else
172  {
173  fpPathFinder->ReLocate( newPosition );
174  }
175 }
176 
177 void G4SafetyHelper::Locate( const G4ThreeVector& newPosition,
178  const G4ThreeVector& newDirection)
179 {
181  {
182  fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
183  true, false);
184  }
185  else
186  {
187  fpPathFinder->Locate( newPosition, newDirection );
188  }
189 }
190 
192  const G4ThreeVector& pGlobalPoint,
193  const G4ThreeVector& pDirection,
194  const G4double aProposedMove,
195  G4double* prDistance,
196  G4double* prNewSafety) const
197 {
198  G4bool retval;
200  {
201  retval = fpMassNavigator->RecheckDistanceToCurrentBoundary(pGlobalPoint,
202  pDirection,
203  aProposedMove,
204  prDistance,
205  prNewSafety);
206  }
207  else
208  {
209  retval = fpPathFinder->RecheckDistanceToCurrentBoundary(pGlobalPoint,
210  pDirection,
211  aProposedMove,
212  prDistance,
213  prNewSafety);
214  }
215  return retval;
216 }