Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4SafetyHelper.cc 81060 2014-05-20 09:12:39Z gcosmo $ >> 27 // GEANT4 tag $ Name: $ >> 28 // 26 // class G4SafetyHelper Implementation 29 // class G4SafetyHelper Implementation 27 // 30 // 28 // Original author: John Apostolakis, 2006 31 // Original author: John Apostolakis, 2006 >> 32 // 29 // ------------------------------------------- 33 // -------------------------------------------------------------------- 30 34 31 #include "G4SafetyHelper.hh" 35 #include "G4SafetyHelper.hh" 32 #include "G4PathFinder.hh" 36 #include "G4PathFinder.hh" 33 #include "G4TransportationManager.hh" 37 #include "G4TransportationManager.hh" 34 #include "G4Navigator.hh" 38 #include "G4Navigator.hh" 35 39 36 #include "globals.hh" 40 #include "globals.hh" 37 41 38 // ------------------------------------------- << 39 G4SafetyHelper::G4SafetyHelper() 42 G4SafetyHelper::G4SafetyHelper() 40 : fLastSafetyPosition(0.0,0.0,0.0) << 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) 41 { 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; 42 } 57 } 43 58 44 // ------------------------------------------- << 45 void G4SafetyHelper::InitialiseNavigator() 59 void G4SafetyHelper::InitialiseNavigator() 46 { 60 { 47 fpPathFinder = G4PathFinder::GetInstance(); << 61 fpPathFinder= G4PathFinder::GetInstance(); 48 62 49 G4TransportationManager* pTransportMgr= 63 G4TransportationManager* pTransportMgr= 50 G4TransportationManager::GetTransportation 64 G4TransportationManager::GetTransportationManager(); 51 65 52 fpMassNavigator = pTransportMgr->GetNavigato 66 fpMassNavigator = pTransportMgr->GetNavigatorForTracking(); 53 67 54 // Check 68 // Check 55 // 69 // 56 G4VPhysicalVolume* worldPV = fpMassNavigator 70 G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume(); 57 if( worldPV == nullptr ) << 71 if( worldPV == 0 ) 58 { 72 { 59 G4Exception("G4SafetyHelper::InitialiseNav 73 G4Exception("G4SafetyHelper::InitialiseNavigator", 60 "GeomNav0003", FatalException, << 74 "InvalidNavigatorWorld", FatalException, 61 "Found that existing tracking 75 "Found that existing tracking Navigator has NULL world"); 62 } 76 } >> 77 >> 78 fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator ); 63 } 79 } 64 80 65 // ------------------------------------------- << 66 void G4SafetyHelper::InitialiseHelper() 81 void G4SafetyHelper::InitialiseHelper() 67 { 82 { 68 fLastSafetyPosition = G4ThreeVector(0.0,0.0, 83 fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0); 69 fLastSafety = 0.0; 84 fLastSafety = 0.0; 70 if (fFirstCall) { InitialiseNavigator(); } 85 if (fFirstCall) { InitialiseNavigator(); } 71 fFirstCall = false; 86 fFirstCall = false; 72 } 87 } 73 88 74 G4SafetyHelper::~G4SafetyHelper() = default; << 89 G4SafetyHelper::~G4SafetyHelper() >> 90 { >> 91 } 75 92 76 G4double 93 G4double 77 G4SafetyHelper::CheckNextStep(const G4ThreeVec << 94 G4SafetyHelper::CheckNextStep(const G4ThreeVector &position, 78 const G4ThreeVec << 95 const G4ThreeVector &direction, 79 const G4double c 96 const G4double currentMaxStep, 80 G4double& 97 G4double& newSafety ) 81 { 98 { 82 // Distance in the Mass geometry 99 // Distance in the Mass geometry 83 // 100 // 84 G4double linstep = fpMassNavigator->CheckNex 101 G4double linstep = fpMassNavigator->CheckNextStep( position, 85 102 direction, 86 103 currentMaxStep, 87 104 newSafety); 88 fLastSafetyPosition = position; 105 fLastSafetyPosition = position; 89 fLastSafety = newSafety; 106 fLastSafety = newSafety; 90 107 91 // TO-DO: Can replace this with a call to Pa 108 // TO-DO: Can replace this with a call to PathFinder 92 // giving id of Mass Geometry --> thi 109 // giving id of Mass Geometry --> this avoid doing the work twice 93 110 94 return linstep; 111 return linstep; 95 } 112 } 96 113 97 // ------------------------------------------- << 114 G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position, G4double maxLength ) 98 G4double G4SafetyHelper::ComputeSafety( const << 99 << 100 { 115 { 101 G4double newSafety; 116 G4double newSafety; 102 << 117 103 // Only recompute (calling Navigator/PathFin 118 // Only recompute (calling Navigator/PathFinder) if 'position' 104 // is *not* the safety location and has mov 119 // is *not* the safety location and has moved 'significantly' 105 // 120 // 106 G4double moveLengthSq = (position-fLastSafet 121 G4double moveLengthSq = (position-fLastSafetyPosition).mag2(); 107 if( (moveLengthSq > 0.0 ) ) 122 if( (moveLengthSq > 0.0 ) ) 108 { 123 { 109 if( !fUseParallelGeometries ) 124 if( !fUseParallelGeometries ) 110 { 125 { 111 // Safety for mass geometry 126 // Safety for mass geometry 112 newSafety = fpMassNavigator->ComputeSafe 127 newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true); 113 << 114 // Only store a 'true' safety - one that << 115 if( newSafety < maxLength ) << 116 { << 117 fLastSafety= newSafety; << 118 fLastSafetyPosition = position; << 119 } << 120 } 128 } 121 else 129 else 122 { 130 { 123 // Safety for all geometries 131 // Safety for all geometries 124 newSafety = fpPathFinder->ComputeSafety( << 132 newSafety = fpPathFinder->ComputeSafety(position); 125 << 126 fLastSafety= newSafety; << 127 fLastSafetyPosition = position; << 128 } 133 } 129 134 >> 135 // We can only store a 'true' safety - one that was not restricted by maxLength >> 136 if( newSafety < maxLength ) >> 137 { >> 138 fLastSafety= newSafety; >> 139 fLastSafetyPosition = position; >> 140 } 130 } 141 } 131 else 142 else 132 { 143 { 133 // return last value if position is not (s 144 // return last value if position is not (significantly) changed 134 // 145 // 135 // G4double moveLength = 0; 146 // G4double moveLength = 0; 136 // if( moveLengthSq > 0.0 ) { moveLength= 147 // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); } 137 newSafety = fLastSafety; // -moveLength; 148 newSafety = fLastSafety; // -moveLength; 138 } << 149 } 139 << 140 return newSafety; 150 return newSafety; 141 } 151 } 142 152 143 // ------------------------------------------- << 153 void G4SafetyHelper::ReLocateWithinVolume( const G4ThreeVector &newPosition ) 144 void G4SafetyHelper::ReLocateWithinVolume( con << 145 { 154 { 146 #ifdef G4VERBOSE 155 #ifdef G4VERBOSE 147 if( fVerbose > 0 ) << 156 if( fVerbose > 0 ) { 148 { << 157 // There is an opportunity - and need - to check whether the proposed move is safe 149 // There is an opportunity - and need - to << 158 G4ThreeVector moveVec= newPosition - fLastSafetyPosition; 150 // the proposed move is safe << 151 G4ThreeVector moveVec = newPosition - fLas << 152 if( moveVec.mag2() > sqr(fLastSafety) ) 159 if( moveVec.mag2() > sqr(fLastSafety) ) 153 { 160 { 154 // A problem exists - we are proposing t 161 // A problem exists - we are proposing to move outside 'Safety Sphere' 155 G4ExceptionDescription ed; 162 G4ExceptionDescription ed; 156 ed << "Unsafe Move> Asked to relocate be << 157 << G4endl; << 158 ed << " Safety Sphere: Radius = " << fL 163 ed << " Safety Sphere: Radius = " << fLastSafety; 159 ed << " Center = " << fLastSafetyPosit 164 ed << " Center = " << fLastSafetyPosition << G4endl; 160 ed << " New Location : Move = " << mo << 165 ed << " New Location : Move = " << moveVec.mag2(); 161 ed << " Position = " << newPosition << G 166 ed << " Position = " << newPosition << G4endl; 162 G4Exception("G4SafetyHelper::ReLocateWit << 167 G4Exception("G4SafetyHelper::ReLocateWithinVolume", "GeomNav999", JustWarning, 163 "GeomNav1001", JustWarning, << 168 "Unsafe Move> Asked to relocate beyond 'Safety sphere'."); 164 } 169 } 165 } 170 } 166 #endif 171 #endif 167 172 168 if( !fUseParallelGeometries ) 173 if( !fUseParallelGeometries ) 169 { 174 { 170 fpMassNavigator->LocateGlobalPointWithinVo 175 fpMassNavigator->LocateGlobalPointWithinVolume( newPosition ); 171 } 176 } 172 else 177 else 173 { 178 { 174 fpPathFinder->ReLocate( newPosition ); 179 fpPathFinder->ReLocate( newPosition ); 175 } 180 } 176 } 181 } 177 182 178 // ------------------------------------------- << 179 void G4SafetyHelper::Locate( const G4ThreeVec 183 void G4SafetyHelper::Locate( const G4ThreeVector& newPosition, 180 const G4ThreeVec 184 const G4ThreeVector& newDirection) 181 { 185 { 182 if( !fUseParallelGeometries ) << 186 if( !fUseParallelGeometries) 183 { 187 { 184 fpMassNavigator->LocateGlobalPointAndSetup 188 fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection, 185 189 true, false); 186 } 190 } 187 else 191 else 188 { 192 { 189 fpPathFinder->Locate( newPosition, newDire 193 fpPathFinder->Locate( newPosition, newDirection ); 190 } 194 } 191 } 195 } >> 196 >> 197 G4bool G4SafetyHelper::RecheckDistanceToCurrentBoundary( >> 198 const G4ThreeVector &pGlobalPoint, >> 199 const G4ThreeVector &pDirection, >> 200 const G4double aProposedMove, >> 201 G4double *prDistance, >> 202 G4double *prNewSafety) const >> 203 { >> 204 G4bool retval; >> 205 if( !fUseParallelGeometries) >> 206 { >> 207 retval= fpMassNavigator->RecheckDistanceToCurrentBoundary( >> 208 pGlobalPoint, >> 209 pDirection, >> 210 aProposedMove, >> 211 prDistance, >> 212 prNewSafety); >> 213 } >> 214 else >> 215 { >> 216 //G4Exception("G4Navigator::RecheckDistanceToCurrentBoundary()", "GeomNav0001", >> 217 // JustWarning, "Method NOT Available (yet) in case of Multiple Geometries (where PathFinder is involved.)."); >> 218 retval= fpPathFinder->RecheckDistanceToCurrentBoundary( >> 219 pGlobalPoint, >> 220 pDirection, >> 221 aProposedMove, >> 222 prDistance, >> 223 prNewSafety); >> 224 } >> 225 return retval; >> 226 } >> 227 192 228