ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ITSafetyHelper.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ITSafetyHelper.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 // GEANT4 tag $ Name: $
27 //
28 // class G4ITSafetyHelper Implementation
29 //
30 // Original author: John Apostolakis, 2006
31 //
32 // --------------------------------------------------------------------
33 
34 #include "G4ITSafetyHelper.hh"
35 #include "G4ITPathFinder.hh"
37 #include "G4ITNavigator.hh"
38 #include "G4PathFinder.hh"
39 #include "globals.hh"
40 
42  G4TrackStateDependent<G4ITSafetyHelper>(), fUseParallelGeometries(false), // By default, one geometry only
43  fFirstCall(true), fVerbose(0)
44 // fRecomputeFactor(0.0)
45 {
46  fpPathFinder = 0; // Cannot initialise this yet - a loop results
47 
48  // Initialization of the Navigator pointer is postponed, and must
49  // be undertaken by another class calling InitialiseHelper()
50  //
51  fpMassNavigator = 0;
52  fMassNavigatorId = -1;
53 }
54 
56 {
58 
59  G4ITTransportationManager* pTransportMgr =
61 
62  fpMassNavigator = pTransportMgr->GetNavigatorForTracking();
63 
64  if(fpMassNavigator == 0) abort();
65 
66  // Check
67  //
68  G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume();
69  if (worldPV == 0)
70  {
71  G4Exception("G4ITSafetyHelper::InitialiseNavigator",
72  "InvalidNavigatorWorld", FatalException,
73  "Found that existing tracking Navigator has NULL world");
74  }
75 
76  // fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator );
77 }
78 
80 {
81  NewTrackState();
82  if (fFirstCall)
83  {
85  }
86  fFirstCall = false;
87 }
88 
90 {
91 }
92 
94  const G4ThreeVector &direction,
95  const G4double currentMaxStep,
96  G4double& newSafety)
97 {
98  // Distance in the Mass geometry
99  //
100  G4double linstep = fpMassNavigator->CheckNextStep(position, direction,
101  currentMaxStep, newSafety);
102  fpTrackState->fLastSafetyPosition = position;
103  fpTrackState->fLastSafety = newSafety;
104 
105  // TODO: Can replace this with a call to PathFinder
106  // giving id of Mass Geometry --> this avoid doing the work twice
107 
108  return linstep;
109 }
110 
112  G4double maxLength)
113 {
114  G4double newSafety;
115 
116  // Only recompute (calling Navigator/PathFinder) if 'position'
117  // is *not* the safety location and has moved 'significantly'
118  //
119  G4double moveLengthSq = (position - fpTrackState->fLastSafetyPosition).mag2();
120  if ((moveLengthSq > 0.0))
121  {
123  {
124  // Safety for mass geometry
125  newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
126  }
127  else
128  {
129  // Safety for all geometries
130  newSafety = fpPathFinder->ComputeSafety(position);
131  }
132 
133  // We can only store a 'true' safety - one that was not restricted by maxLength
134  if (newSafety < maxLength)
135  {
136  fpTrackState->fLastSafety = newSafety;
137  fpTrackState->fLastSafetyPosition = position;
138  }
139  }
140  else
141  {
142  // return last value if position is not (significantly) changed
143  //
144  // G4double moveLength = 0;
145  // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
146  newSafety = fpTrackState->fLastSafety; // -moveLength;
147  }
148  return newSafety;
149 }
150 
152 {
153 #ifdef G4VERBOSE
154  if (fVerbose > 0)
155  {
156  // There is an opportunity - and need - to check whether the proposed move is safe
157  G4ThreeVector moveVec = newPosition - fpTrackState->fLastSafetyPosition;
158  if (moveVec.mag2() > sqr(fpTrackState->fLastSafety))
159  {
160  // A problem exists - we are proposing to move outside 'Safety Sphere'
162  ed << " Safety Sphere: Radius = " << fpTrackState->fLastSafety;
163  ed << " Center = " << fpTrackState->fLastSafetyPosition << G4endl;
164  ed << " New Location : Move = " << moveVec.mag2();
165  ed << " Position = " << newPosition << G4endl;
166  G4Exception("G4ITSafetyHelper::ReLocateWithinVolume", "GeomNav999",
167  JustWarning,
168  "Unsafe Move> Asked to relocate beyond 'Safety sphere'.");
169  }
170  }
171 #endif
172 
174  {
175  fpMassNavigator->LocateGlobalPointWithinVolume(newPosition);
176  }
177  else
178  {
179  fpPathFinder->ReLocate(newPosition);
180  }
181 }
182 
183 void G4ITSafetyHelper::Locate(const G4ThreeVector& newPosition,
184  const G4ThreeVector& newDirection)
185 {
187  {
188  fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection, true,
189  false);
190  }
191  else
192  {
193  fpPathFinder->Locate(newPosition, newDirection);
194  }
195 }