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 // G4SafetyCalculator 26 // G4SafetyCalculator 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // A class that provides an estimate of the is 30 // A class that provides an estimate of the isotropic safety - the 31 // minimum distance from a global point to t 31 // minimum distance from a global point to the nearest boundary 32 // of the current volume or the nearest daug 32 // of the current volume or the nearest daughter volumes. 33 // This estimate can be an underestimate, eith 33 // This estimate can be an underestimate, either because a solid 34 // provides an underestimate (for speed) or 34 // provides an underestimate (for speed) or in order to avoid 35 // substantial additional computations. 35 // substantial additional computations. 36 // 36 // 37 // Obtains from the navigator the current tran 37 // Obtains from the navigator the current transformation history. 38 38 39 // Author: John Apostolakis, CERN - February 2 39 // Author: John Apostolakis, CERN - February 2023 40 // ------------------------------------------- 40 // -------------------------------------------------------------------- 41 #ifndef G4SafetyCalculator_HH 41 #ifndef G4SafetyCalculator_HH 42 #define G4SafetyCalculator_HH 1 42 #define G4SafetyCalculator_HH 1 43 43 44 #include "geomdefs.hh" 44 #include "geomdefs.hh" 45 45 46 #include "G4ThreeVector.hh" 46 #include "G4ThreeVector.hh" 47 #include "G4AffineTransform.hh" 47 #include "G4AffineTransform.hh" 48 #include "G4RotationMatrix.hh" 48 #include "G4RotationMatrix.hh" 49 49 50 #include "G4LogicalVolume.hh" // U 50 #include "G4LogicalVolume.hh" // Used in inline methods 51 #include "G4TouchableHistoryHandle.hh" 51 #include "G4TouchableHistoryHandle.hh" 52 52 53 #include "G4NavigationHistory.hh" 53 #include "G4NavigationHistory.hh" 54 #include "G4NormalNavigation.hh" 54 #include "G4NormalNavigation.hh" 55 #include "G4VoxelNavigation.hh" 55 #include "G4VoxelNavigation.hh" 56 #include "G4ParameterisedNavigation.hh" 56 #include "G4ParameterisedNavigation.hh" 57 #include "G4ReplicaNavigation.hh" 57 #include "G4ReplicaNavigation.hh" 58 #include "G4RegularNavigation.hh" 58 #include "G4RegularNavigation.hh" 59 #include "G4VExternalNavigation.hh" 59 #include "G4VExternalNavigation.hh" 60 60 61 #include "G4VoxelSafety.hh" 61 #include "G4VoxelSafety.hh" 62 62 63 #include <iostream> 63 #include <iostream> 64 64 65 class G4VPhysicalVolume; 65 class G4VPhysicalVolume; 66 66 67 class G4SafetyCalculator 67 class G4SafetyCalculator 68 { 68 { 69 public: 69 public: 70 70 71 G4SafetyCalculator( const G4Navigator& nav 71 G4SafetyCalculator( const G4Navigator& navigator, 72 const G4NavigationHist 72 const G4NavigationHistory& navHistory ); 73 // Constructor - initialisers and setup. 73 // Constructor - initialisers and setup. 74 74 75 G4SafetyCalculator(const G4SafetyCalculato 75 G4SafetyCalculator(const G4SafetyCalculator&) = delete; 76 G4SafetyCalculator& operator=(const G4Safe 76 G4SafetyCalculator& operator=(const G4SafetyCalculator&) = delete; 77 // Copy constructor & assignment operato 77 // Copy constructor & assignment operator not allowed. 78 78 79 ~G4SafetyCalculator() = default; 79 ~G4SafetyCalculator() = default; 80 // Destructor. No actions. 80 // Destructor. No actions. 81 81 82 G4double SafetyInCurrentVolume(const G4Thr 82 G4double SafetyInCurrentVolume(const G4ThreeVector& globalpoint, 83 G4VPh 83 G4VPhysicalVolume* physicalVolume, 84 const G4dou 84 const G4double pProposedMaxLength = DBL_MAX, 85 G4boo 85 G4bool verbose = false ); 86 // Calculate the isotropic distance to t 86 // Calculate the isotropic distance to the nearest boundary from the 87 // specified point in the global coordin 87 // specified point in the global coordinate system. 88 // The globalpoint utilised *must* be lo 88 // The globalpoint utilised *must* be located exactly within the 89 // current volume (it also must *not* be 89 // current volume (it also must *not* be in a daughter volume). 90 // The value returned can be an underest 90 // The value returned can be an underestimate (and typically will be 91 // if complex volumes are involved). 91 // if complex volumes are involved). 92 // The calculation will not look beyond 92 // The calculation will not look beyond the proposed maximum length 93 // to avoid extra volume safety calculat 93 // to avoid extra volume safety calculations. The geometry must be closed. 94 94 95 G4VExternalNavigation* GetExternalNavigati 95 G4VExternalNavigation* GetExternalNavigation() const; 96 void SetExternalNavigation(G4VExternalNavi 96 void SetExternalNavigation(G4VExternalNavigation* externalNav); 97 // Accessor & modifier for custom extern 97 // Accessor & modifier for custom external navigation. 98 98 99 void CompareSafetyValues( G4double oldSafe 99 void CompareSafetyValues( G4double oldSafety, 100 G4double newValu 100 G4double newValue, 101 G4VPhysicalVolum 101 G4VPhysicalVolume* motherPhysical, 102 const G4ThreeVector &g 102 const G4ThreeVector &globalPoint, 103 G4bool keepState 103 G4bool keepState, 104 G4double maxLeng 104 G4double maxLength, 105 G4bool enteredVo 105 G4bool enteredVolume, 106 G4bool exitedVol 106 G4bool exitedVolume ); 107 // Compare estimates of the safety, and 107 // Compare estimates of the safety, and report if difference(s) found. 108 108 109 protected: 109 protected: 110 110 111 void QuickLocateWithinVolume(const G4Three 111 void QuickLocateWithinVolume(const G4ThreeVector& pointLocal, 112 G4VPhys 112 G4VPhysicalVolume* motherPhysical); 113 // Prepare state of sub-navigators by in 113 // Prepare state of sub-navigators by informing them of current point. 114 114 115 inline G4ThreeVector ComputeLocalPoint(con 115 inline G4ThreeVector ComputeLocalPoint(const G4ThreeVector& rGlobPoint) const; 116 // Return position vector in local coord 116 // Return position vector in local coordinate system, given a position 117 // vector in world coordinate system. 117 // vector in world coordinate system. 118 118 119 inline G4ThreeVector ComputeLocalAxis(cons 119 inline G4ThreeVector ComputeLocalAxis(const G4ThreeVector& pVec) const; 120 // Return the local direction of the spe 120 // Return the local direction of the specified vector in the reference 121 // system of the volume that was found b 121 // system of the volume that was found by LocalGlobalPointAndSetup(). 122 // The Local Coordinates of point in wor 122 // The Local Coordinates of point in world coordinate system. 123 123 124 inline EVolume CharacteriseDaughters(const 124 inline EVolume CharacteriseDaughters(const G4LogicalVolume* pLog) const; 125 // Characterise daughter of logical volu 125 // Characterise daughter of logical volume. 126 126 127 inline G4int GetDaughtersRegularStructureI 127 inline G4int GetDaughtersRegularStructureId(const G4LogicalVolume* pLv) const; 128 // Get regular structure ID of first dau 128 // Get regular structure ID of first daughter. 129 129 130 private: 130 private: 131 131 132 // BEGIN -- Tracking Invariants part 1 132 // BEGIN -- Tracking Invariants part 1 133 // 133 // 134 const G4Navigator& fNavigator; 134 const G4Navigator& fNavigator; 135 // Associated navigator. Needed for deta 135 // Associated navigator. Needed for details of current state, 136 // for optimisation 136 // for optimisation 137 137 138 const G4NavigationHistory& fNavHistory; 138 const G4NavigationHistory& fNavHistory; 139 // Associated navigator's navigation his 139 // Associated navigator's navigation history. Transformation and history 140 // of the current path through the geome 140 // of the current path through the geometrical hierarchy. 141 // 141 // 142 // END -- Tracking Invariants part 1 142 // END -- Tracking Invariants part 1 143 143 144 G4double fkCarTolerance; 144 G4double fkCarTolerance; 145 // Cached tolerance. 145 // Cached tolerance. 146 146 147 // BEGIN State information 147 // BEGIN State information 148 // 148 // 149 G4ThreeVector fPreviousSftOrigin; 149 G4ThreeVector fPreviousSftOrigin; 150 G4double fPreviousSafety = 0.0; 150 G4double fPreviousSafety = 0.0; 151 // Memory of last safety origin & value. 151 // Memory of last safety origin & value. Used in ComputeStep to ensure 152 // that origin of current Step is in the 152 // that origin of current Step is in the same volume as the point of the 153 // last relocation. 153 // last relocation. 154 154 155 // Helpers/Utility classes - their state c 155 // Helpers/Utility classes - their state can change 156 // 156 // 157 G4NormalNavigation fnormalNav; 157 G4NormalNavigation fnormalNav; 158 G4VoxelNavigation fvoxelNav; 158 G4VoxelNavigation fvoxelNav; 159 G4ParameterisedNavigation fparamNav; 159 G4ParameterisedNavigation fparamNav; 160 G4ReplicaNavigation freplicaNav; 160 G4ReplicaNavigation freplicaNav; 161 G4RegularNavigation fregularNav; 161 G4RegularNavigation fregularNav; 162 G4VExternalNavigation* fpExternalNav = nul 162 G4VExternalNavigation* fpExternalNav = nullptr; 163 G4VoxelSafety fVoxelSafety; 163 G4VoxelSafety fVoxelSafety; 164 }; 164 }; 165 165 166 // Auxiliary inline methods -- copied from G4N 166 // Auxiliary inline methods -- copied from G4Navigator 167 167 168 // Return local coordinates given point in th 168 // Return local coordinates given point in the world coord system. 169 // 169 // 170 inline G4ThreeVector 170 inline G4ThreeVector 171 G4SafetyCalculator::ComputeLocalPoint(const G4 171 G4SafetyCalculator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const 172 { 172 { 173 return fNavHistory.GetTopTransform().Transfo 173 return fNavHistory.GetTopTransform().TransformPoint(pGlobalPoint); 174 } 174 } 175 175 176 // Returns local direction given vector direct 176 // Returns local direction given vector direction in world coord system. 177 // 177 // 178 inline G4ThreeVector 178 inline G4ThreeVector 179 G4SafetyCalculator::ComputeLocalAxis(const G4T 179 G4SafetyCalculator::ComputeLocalAxis(const G4ThreeVector& pVec) const 180 { 180 { 181 return fNavHistory.GetTopTransform().Transfo 181 return fNavHistory.GetTopTransform().TransformAxis(pVec); 182 } 182 } 183 183 184 inline EVolume 184 inline EVolume 185 G4SafetyCalculator::CharacteriseDaughters(cons 185 G4SafetyCalculator::CharacteriseDaughters(const G4LogicalVolume* pLog) const 186 { 186 { 187 return pLog->CharacteriseDaughters(); 187 return pLog->CharacteriseDaughters(); 188 } 188 } 189 189 190 inline G4int 190 inline G4int 191 G4SafetyCalculator::GetDaughtersRegularStructu 191 G4SafetyCalculator::GetDaughtersRegularStructureId(const G4LogicalVolume* pLog) const 192 { 192 { 193 G4int regId = 0; 193 G4int regId = 0; 194 G4VPhysicalVolume *pVol; 194 G4VPhysicalVolume *pVol; 195 195 196 if ( pLog->GetNoDaughters() == 1 ) 196 if ( pLog->GetNoDaughters() == 1 ) 197 { 197 { 198 pVol = pLog->GetDaughter(0); 198 pVol = pLog->GetDaughter(0); 199 regId = pVol->GetRegularStructureId(); 199 regId = pVol->GetRegularStructureId(); 200 } 200 } 201 return regId; 201 return regId; 202 } 202 } 203 203 204 #endif 204 #endif 205 205