Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // class G4SafetyHelper Implementation 27 // 28 // Original author: John Apostolakis, 2006 29 // ------------------------------------------- 30 31 #include "G4SafetyHelper.hh" 32 #include "G4PathFinder.hh" 33 #include "G4TransportationManager.hh" 34 #include "G4Navigator.hh" 35 36 #include "globals.hh" 37 38 // ------------------------------------------- 39 G4SafetyHelper::G4SafetyHelper() 40 : fLastSafetyPosition(0.0,0.0,0.0) 41 { 42 } 43 44 // ------------------------------------------- 45 void G4SafetyHelper::InitialiseNavigator() 46 { 47 fpPathFinder = G4PathFinder::GetInstance(); 48 49 G4TransportationManager* pTransportMgr= 50 G4TransportationManager::GetTransportation 51 52 fpMassNavigator = pTransportMgr->GetNavigato 53 54 // Check 55 // 56 G4VPhysicalVolume* worldPV = fpMassNavigator 57 if( worldPV == nullptr ) 58 { 59 G4Exception("G4SafetyHelper::InitialiseNav 60 "GeomNav0003", FatalException, 61 "Found that existing tracking 62 } 63 } 64 65 // ------------------------------------------- 66 void G4SafetyHelper::InitialiseHelper() 67 { 68 fLastSafetyPosition = G4ThreeVector(0.0,0.0, 69 fLastSafety = 0.0; 70 if (fFirstCall) { InitialiseNavigator(); } 71 fFirstCall = false; 72 } 73 74 G4SafetyHelper::~G4SafetyHelper() = default; 75 76 G4double 77 G4SafetyHelper::CheckNextStep(const G4ThreeVec 78 const G4ThreeVec 79 const G4double c 80 G4double& 81 { 82 // Distance in the Mass geometry 83 // 84 G4double linstep = fpMassNavigator->CheckNex 85 86 87 88 fLastSafetyPosition = position; 89 fLastSafety = newSafety; 90 91 // TO-DO: Can replace this with a call to Pa 92 // giving id of Mass Geometry --> thi 93 94 return linstep; 95 } 96 97 // ------------------------------------------- 98 G4double G4SafetyHelper::ComputeSafety( const 99 100 { 101 G4double newSafety; 102 103 // Only recompute (calling Navigator/PathFin 104 // is *not* the safety location and has mov 105 // 106 G4double moveLengthSq = (position-fLastSafet 107 if( (moveLengthSq > 0.0 ) ) 108 { 109 if( !fUseParallelGeometries ) 110 { 111 // Safety for mass geometry 112 newSafety = fpMassNavigator->ComputeSafe 113 114 // Only store a 'true' safety - one that 115 if( newSafety < maxLength ) 116 { 117 fLastSafety= newSafety; 118 fLastSafetyPosition = position; 119 } 120 } 121 else 122 { 123 // Safety for all geometries 124 newSafety = fpPathFinder->ComputeSafety( 125 126 fLastSafety= newSafety; 127 fLastSafetyPosition = position; 128 } 129 130 } 131 else 132 { 133 // return last value if position is not (s 134 // 135 // G4double moveLength = 0; 136 // if( moveLengthSq > 0.0 ) { moveLength= 137 newSafety = fLastSafety; // -moveLength; 138 } 139 140 return newSafety; 141 } 142 143 // ------------------------------------------- 144 void G4SafetyHelper::ReLocateWithinVolume( con 145 { 146 #ifdef G4VERBOSE 147 if( fVerbose > 0 ) 148 { 149 // There is an opportunity - and need - to 150 // the proposed move is safe 151 G4ThreeVector moveVec = newPosition - fLas 152 if( moveVec.mag2() > sqr(fLastSafety) ) 153 { 154 // A problem exists - we are proposing t 155 G4ExceptionDescription ed; 156 ed << "Unsafe Move> Asked to relocate be 157 << G4endl; 158 ed << " Safety Sphere: Radius = " << fL 159 ed << " Center = " << fLastSafetyPosit 160 ed << " New Location : Move = " << mo 161 ed << " Position = " << newPosition << G 162 G4Exception("G4SafetyHelper::ReLocateWit 163 "GeomNav1001", JustWarning, 164 } 165 } 166 #endif 167 168 if( !fUseParallelGeometries ) 169 { 170 fpMassNavigator->LocateGlobalPointWithinVo 171 } 172 else 173 { 174 fpPathFinder->ReLocate( newPosition ); 175 } 176 } 177 178 // ------------------------------------------- 179 void G4SafetyHelper::Locate( const G4ThreeVec 180 const G4ThreeVec 181 { 182 if( !fUseParallelGeometries ) 183 { 184 fpMassNavigator->LocateGlobalPointAndSetup 185 186 } 187 else 188 { 189 fpPathFinder->Locate( newPosition, newDire 190 } 191 } 192