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,v 1.15 2007/11/14 10:04:21 gcosmo Exp $ >> 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 fLastSafetyPosition(0.0,0.0,0.0), >> 46 fLastSafety(0.0), >> 47 fRecomputeFactor(0.0) 41 { 48 { >> 49 fpPathFinder= 0; // Cannot initialise this yet - a loop results >> 50 >> 51 // Initialization of the Navigator pointer is postponed, and must >> 52 // be undertaken by another class calling InitialiseHelper() >> 53 // >> 54 fpMassNavigator= 0; >> 55 fMassNavigatorId= -1; 42 } 56 } 43 57 44 // ------------------------------------------- << 45 void G4SafetyHelper::InitialiseNavigator() 58 void G4SafetyHelper::InitialiseNavigator() 46 { 59 { 47 fpPathFinder = G4PathFinder::GetInstance(); << 60 fpPathFinder= G4PathFinder::GetInstance(); 48 61 49 G4TransportationManager* pTransportMgr= 62 G4TransportationManager* pTransportMgr= 50 G4TransportationManager::GetTransportation 63 G4TransportationManager::GetTransportationManager(); 51 64 52 fpMassNavigator = pTransportMgr->GetNavigato 65 fpMassNavigator = pTransportMgr->GetNavigatorForTracking(); 53 66 54 // Check 67 // Check 55 // 68 // 56 G4VPhysicalVolume* worldPV = fpMassNavigator 69 G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume(); 57 if( worldPV == nullptr ) << 70 if( worldPV == 0 ) 58 { 71 { 59 G4Exception("G4SafetyHelper::InitialiseNav 72 G4Exception("G4SafetyHelper::InitialiseNavigator", 60 "GeomNav0003", FatalException, << 73 "InvalidNavigatorWorld", FatalException, 61 "Found that existing tracking 74 "Found that existing tracking Navigator has NULL world"); 62 } 75 } >> 76 >> 77 fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator ); 63 } 78 } 64 79 65 // ------------------------------------------- << 66 void G4SafetyHelper::InitialiseHelper() 80 void G4SafetyHelper::InitialiseHelper() 67 { 81 { 68 fLastSafetyPosition = G4ThreeVector(0.0,0.0, 82 fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0); 69 fLastSafety = 0.0; 83 fLastSafety = 0.0; 70 if (fFirstCall) { InitialiseNavigator(); } 84 if (fFirstCall) { InitialiseNavigator(); } 71 fFirstCall = false; 85 fFirstCall = false; 72 } 86 } 73 87 74 G4SafetyHelper::~G4SafetyHelper() = default; << 88 G4SafetyHelper::~G4SafetyHelper() >> 89 { >> 90 } 75 91 76 G4double 92 G4double 77 G4SafetyHelper::CheckNextStep(const G4ThreeVec << 93 G4SafetyHelper::CheckNextStep(const G4ThreeVector &position, 78 const G4ThreeVec << 94 const G4ThreeVector &direction, 79 const G4double c 95 const G4double currentMaxStep, 80 G4double& 96 G4double& newSafety ) 81 { 97 { 82 // Distance in the Mass geometry 98 // Distance in the Mass geometry 83 // 99 // 84 G4double linstep = fpMassNavigator->CheckNex 100 G4double linstep = fpMassNavigator->CheckNextStep( position, 85 101 direction, 86 102 currentMaxStep, 87 103 newSafety); 88 fLastSafetyPosition = position; 104 fLastSafetyPosition = position; 89 fLastSafety = newSafety; 105 fLastSafety = newSafety; 90 106 91 // TO-DO: Can replace this with a call to Pa 107 // TO-DO: Can replace this with a call to PathFinder 92 // giving id of Mass Geometry --> thi 108 // giving id of Mass Geometry --> this avoid doing the work twice 93 109 94 return linstep; 110 return linstep; 95 } 111 } 96 112 97 // ------------------------------------------- << 113 G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position ) 98 G4double G4SafetyHelper::ComputeSafety( const << 99 << 100 { 114 { 101 G4double newSafety; 115 G4double newSafety; 102 << 116 103 // Only recompute (calling Navigator/PathFin 117 // Only recompute (calling Navigator/PathFinder) if 'position' 104 // is *not* the safety location and has mov 118 // is *not* the safety location and has moved 'significantly' 105 // 119 // 106 G4double moveLengthSq = (position-fLastSafet 120 G4double moveLengthSq = (position-fLastSafetyPosition).mag2(); 107 if( (moveLengthSq > 0.0 ) ) << 121 G4double safeDistance = fRecomputeFactor*fLastSafety; >> 122 if( (moveLengthSq > 0.0 ) >> 123 && (moveLengthSq >= safeDistance*safeDistance)) 108 { 124 { >> 125 fLastSafetyPosition = position; >> 126 109 if( !fUseParallelGeometries ) 127 if( !fUseParallelGeometries ) 110 { 128 { 111 // Safety for mass geometry 129 // Safety for mass geometry 112 newSafety = fpMassNavigator->ComputeSafe << 130 fLastSafety = fpMassNavigator->ComputeSafety(position); 113 << 114 // Only store a 'true' safety - one that << 115 if( newSafety < maxLength ) << 116 { << 117 fLastSafety= newSafety; << 118 fLastSafetyPosition = position; << 119 } << 120 } 131 } 121 else 132 else 122 { 133 { 123 // Safety for all geometries 134 // Safety for all geometries 124 newSafety = fpPathFinder->ComputeSafety( << 135 fLastSafety = fpPathFinder->ComputeSafety( position ); 125 << 126 fLastSafety= newSafety; << 127 fLastSafetyPosition = position; << 128 } 136 } 129 << 137 newSafety = fLastSafety; 130 } 138 } 131 else 139 else 132 { 140 { 133 // return last value if position is not (s << 141 // return last value if position is not significantly changed 134 // 142 // 135 // G4double moveLength = 0; << 143 G4double moveLength = 0; 136 // if( moveLengthSq > 0.0 ) { moveLength= << 144 if( moveLengthSq > 0.0 ) 137 newSafety = fLastSafety; // -moveLength; << 145 { 138 } << 146 moveLength= std::sqrt(moveLengthSq); 139 << 147 } >> 148 newSafety = fLastSafety-moveLength; >> 149 } 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 << 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 ) 155 if( !fUseParallelGeometries ) 169 { 156 { 170 fpMassNavigator->LocateGlobalPointWithinVo 157 fpMassNavigator->LocateGlobalPointWithinVolume( newPosition ); 171 } 158 } 172 else 159 else 173 { 160 { 174 fpPathFinder->ReLocate( newPosition ); 161 fpPathFinder->ReLocate( newPosition ); 175 } 162 } 176 } 163 } 177 164 178 // ------------------------------------------- << 179 void G4SafetyHelper::Locate( const G4ThreeVec 165 void G4SafetyHelper::Locate( const G4ThreeVector& newPosition, 180 const G4ThreeVec 166 const G4ThreeVector& newDirection) 181 { 167 { 182 if( !fUseParallelGeometries ) << 168 if( !fUseParallelGeometries) 183 { 169 { 184 fpMassNavigator->LocateGlobalPointAndSetup 170 fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection, 185 171 true, false); 186 } 172 } 187 else 173 else 188 { 174 { 189 fpPathFinder->Locate( newPosition, newDire 175 fpPathFinder->Locate( newPosition, newDirection ); 190 } 176 } 191 } 177 } 192 178