Geant4  10.01.p03
G4ITSafetyHelper.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 // $Id: G4ITSafetyHelper.cc 72309 2013-07-15 15:52:17Z gcosmo $
27 // GEANT4 tag $ Name: $
28 //
29 // class G4ITSafetyHelper Implementation
30 //
31 // Original author: John Apostolakis, 2006
32 //
33 // --------------------------------------------------------------------
34 
35 #include "G4ITSafetyHelper.hh"
36 #include "G4ITPathFinder.hh"
38 #include "G4ITNavigator.hh"
39 #include "G4PathFinder.hh"
40 #include "globals.hh"
41 
43  G4TrackStateDependent<G4ITSafetyHelper>(), fUseParallelGeometries(false), // By default, one geometry only
44  fFirstCall(true), fVerbose(0)
45 // fRecomputeFactor(0.0)
46 {
47  fpPathFinder = 0; // Cannot initialise this yet - a loop results
48 
49  // Initialization of the Navigator pointer is postponed, and must
50  // be undertaken by another class calling InitialiseHelper()
51  //
52  fpMassNavigator = 0;
53  fMassNavigatorId = -1;
54 }
55 
57 {
59 
60  G4ITTransportationManager* pTransportMgr =
62 
63  fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
64 
65  if(fpMassNavigator == 0) abort();
66 
67  // Check
68  //
69  G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume();
70  if (worldPV == 0)
71  {
72  G4Exception("G4ITSafetyHelper::InitialiseNavigator",
73  "InvalidNavigatorWorld", FatalException,
74  "Found that existing tracking Navigator has NULL world");
75  }
76 
77  // fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator );
78 }
79 
81 {
82  NewTrackState();
83  if (fFirstCall)
84  {
86  }
87  fFirstCall = false;
88 }
89 
91 {
92 }
93 
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, direction,
102  currentMaxStep, newSafety);
103  fpTrackState->fLastSafetyPosition = position;
104  fpTrackState->fLastSafety = newSafety;
105 
106  // TODO: Can replace this with a call to PathFinder
107  // giving id of Mass Geometry --> this avoid doing the work twice
108 
109  return linstep;
110 }
111 
113  G4double maxLength)
114 {
115  G4double newSafety;
116 
117  // Only recompute (calling Navigator/PathFinder) if 'position'
118  // is *not* the safety location and has moved 'significantly'
119  //
120  G4double moveLengthSq = (position - fpTrackState->fLastSafetyPosition).mag2();
121  if ((moveLengthSq > 0.0))
122  {
124  {
125  // Safety for mass geometry
126  newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
127  }
128  else
129  {
130  // Safety for all geometries
131  newSafety = fpPathFinder->ComputeSafety(position);
132  }
133 
134  // We can only store a 'true' safety - one that was not restricted by maxLength
135  if (newSafety < maxLength)
136  {
137  fpTrackState->fLastSafety = newSafety;
138  fpTrackState->fLastSafetyPosition = position;
139  }
140  }
141  else
142  {
143  // return last value if position is not (significantly) changed
144  //
145  // G4double moveLength = 0;
146  // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
147  newSafety = fpTrackState->fLastSafety; // -moveLength;
148  }
149  return newSafety;
150 }
151 
153 {
154 #ifdef G4VERBOSE
155  if (fVerbose > 0)
156  {
157  // There is an opportunity - and need - to check whether the proposed move is safe
158  G4ThreeVector moveVec = newPosition - fpTrackState->fLastSafetyPosition;
159  if (moveVec.mag2() > sqr(fpTrackState->fLastSafety))
160  {
161  // A problem exists - we are proposing to move outside 'Safety Sphere'
163  ed << " Safety Sphere: Radius = " << fpTrackState->fLastSafety;
164  ed << " Center = " << fpTrackState->fLastSafetyPosition << G4endl;
165  ed << " New Location : Move = " << moveVec.mag2();
166  ed << " Position = " << newPosition << G4endl;
167  G4Exception("G4ITSafetyHelper::ReLocateWithinVolume", "GeomNav999",
168  JustWarning,
169  "Unsafe Move> Asked to relocate beyond 'Safety sphere'.");
170  }
171  }
172 #endif
173 
175  {
176  fpMassNavigator->LocateGlobalPointWithinVolume(newPosition);
177  }
178  else
179  {
180  fpPathFinder->ReLocate(newPosition);
181  }
182 }
183 
184 void G4ITSafetyHelper::Locate(const G4ThreeVector& newPosition,
185  const G4ThreeVector& newDirection)
186 {
188  {
189  fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection, true,
190  false);
191  }
192  else
193  {
194  fpPathFinder->Locate(newPosition, newDirection);
195  }
196 }
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:57
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
G4double CheckNextStep(const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
void ReLocate(const G4ThreeVector &position)
void ReLocateWithinVolume(const G4ThreeVector &pGlobalPoint)
static G4ITTransportationManager * GetTransportationManager()
#define position
Definition: xmlparse.cc:605
G4double ComputeSafety(const G4ThreeVector &globalPoint)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4ITNavigator * fpMassNavigator
G4PathFinder * fpPathFinder
G4ITNavigator * GetNavigatorForTracking() const
G4double ComputeSafety(const G4ThreeVector &pGlobalPoint, G4double maxRadius=DBL_MAX)
void Locate(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &direction)
#define G4endl
Definition: G4ios.hh:61
T sqr(const T &x)
Definition: templates.hh:145
double G4double
Definition: G4Types.hh:76