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 // 26 // 27 // 27 // 28 // 28 // 29 // class G4ITMultiNavigator 29 // class G4ITMultiNavigator 30 // 30 // 31 // Class description: 31 // Class description: 32 // 32 // 33 // Utility class for polling the navigators of 33 // Utility class for polling the navigators of several geometries to 34 // identify the next boundary. 34 // identify the next boundary. 35 35 36 /// \brief { Class description: 36 /// \brief { Class description: 37 /// 37 /// 38 /// G4ITMultiNavigator is a duplicate version 38 /// G4ITMultiNavigator is a duplicate version of G4MultiNavigator 39 /// 39 /// 40 /// Utility class for polling the navigators o 40 /// Utility class for polling the navigators of several geometries to 41 /// identify the next boundary. 41 /// identify the next boundary. 42 /// 42 /// 43 /// } 43 /// } 44 44 45 // History: 45 // History: 46 // - Created. John Apostolakis, November 2006 46 // - Created. John Apostolakis, November 2006 47 // ******************************************* 47 // ********************************************************************* 48 48 49 #ifndef G4ITMULTINAVIGATOR_HH 49 #ifndef G4ITMULTINAVIGATOR_HH 50 #define G4ITMULTINAVIGATOR_HH 50 #define G4ITMULTINAVIGATOR_HH 51 51 52 #include <iostream> 52 #include <iostream> 53 53 54 #include "geomdefs.hh" 54 #include "geomdefs.hh" 55 #include "G4ThreeVector.hh" 55 #include "G4ThreeVector.hh" 56 #include "G4ITNavigator.hh" 56 #include "G4ITNavigator.hh" 57 57 58 #include "G4TouchableHandle.hh" 58 #include "G4TouchableHandle.hh" 59 59 60 #include "G4NavigationHistory.hh" 60 #include "G4NavigationHistory.hh" 61 #include "G4TrackState.hh" 61 #include "G4TrackState.hh" 62 #include "G4MultiNavigator.hh" 62 #include "G4MultiNavigator.hh" 63 63 64 namespace G4ITMN 64 namespace G4ITMN 65 { 65 { 66 enum ELimited 66 enum ELimited 67 { 67 { 68 kDoNot, 68 kDoNot, 69 kUnique, 69 kUnique, 70 kSharedTransport, 70 kSharedTransport, 71 kSharedOther, 71 kSharedOther, 72 kUndefLimited 72 kUndefLimited 73 }; 73 }; 74 } 74 } 75 class G4ITTransportationManager; 75 class G4ITTransportationManager; 76 class G4VPhysicalVolume; 76 class G4VPhysicalVolume; 77 77 78 class G4ITMultiNavigator; 78 class G4ITMultiNavigator; 79 79 80 // Global state (retained during stepping for 80 // Global state (retained during stepping for one track 81 template<> 81 template<> 82 class G4TrackState<G4ITMultiNavigator> : pub 82 class G4TrackState<G4ITMultiNavigator> : public G4TrackState<G4ITNavigator> 83 { 83 { 84 public: 84 public: 85 ~G4TrackState() override 85 ~G4TrackState() override 86 = default; 86 = default; 87 87 88 G4TrackState() 88 G4TrackState() 89 { 89 { 90 G4ThreeVector Big3Vector(kInfinity, kInf 90 G4ThreeVector Big3Vector(kInfinity, kInfinity, kInfinity); 91 fLastLocatedPosition = Big3Vector; 91 fLastLocatedPosition = Big3Vector; 92 fSafetyLocation = Big3Vector; 92 fSafetyLocation = Big3Vector; 93 fPreStepLocation = Big3Vector; 93 fPreStepLocation = Big3Vector; 94 94 95 fMinSafety_PreStepPt = -1.0; 95 fMinSafety_PreStepPt = -1.0; 96 fMinSafety_atSafLocation = -1.0; 96 fMinSafety_atSafLocation = -1.0; 97 fMinSafety = -kInfinity; 97 fMinSafety = -kInfinity; 98 fTrueMinStep = fMinStep = -kInfinity; 98 fTrueMinStep = fMinStep = -kInfinity; 99 99 100 for (G4int num = 0; num < G4ITNavigator: 100 for (G4int num = 0; num < G4ITNavigator::fMaxNav; ++num) 101 { 101 { 102 fLimitTruth[num] = false; 102 fLimitTruth[num] = false; 103 fLimitedStep[num] = kUndefLimited; 103 fLimitedStep[num] = kUndefLimited; 104 fCurrentStepSize[num] = fNewSafety[num 104 fCurrentStepSize[num] = fNewSafety[num] = -1.0; 105 fLocatedVolume[num] = nullptr; 105 fLocatedVolume[num] = nullptr; 106 } 106 } 107 107 108 fNoLimitingStep = -1; // How many geomet 108 fNoLimitingStep = -1; // How many geometries limited the step 109 fIdNavLimiting = -1; // Id of Navigator 109 fIdNavLimiting = -1; // Id of Navigator limiting step (if only one limits) 110 fWasLimitedByGeometry = false; 110 fWasLimitedByGeometry = false; 111 } 111 } 112 ; 112 ; 113 113 114 protected: 114 protected: 115 friend class G4ITMultiNavigator; 115 friend class G4ITMultiNavigator; 116 // State after a step computation 116 // State after a step computation 117 ELimited fLimitedStep[G4ITNavigator::fMaxN 117 ELimited fLimitedStep[G4ITNavigator::fMaxNav]; 118 G4bool fLimitTruth[G4ITNavigator::fMaxNav] 118 G4bool fLimitTruth[G4ITNavigator::fMaxNav]; 119 G4double fCurrentStepSize[G4ITNavigator::f 119 G4double fCurrentStepSize[G4ITNavigator::fMaxNav]; 120 G4double fNewSafety[G4ITNavigator::fMaxNav 120 G4double fNewSafety[G4ITNavigator::fMaxNav]; // Safety for starting point 121 G4int fNoLimitingStep; // How many geometr 121 G4int fNoLimitingStep; // How many geometries limited the step 122 G4int fIdNavLimiting; // Id of Navigator l 122 G4int fIdNavLimiting; // Id of Navigator limiting step (if only one limits) 123 123 124 G4bool fWasLimitedByGeometry; 124 G4bool fWasLimitedByGeometry; 125 125 126 // Lowest values - determine step length, 126 // Lowest values - determine step length, and safety 127 G4double fMinStep; // As reported by Navig 127 G4double fMinStep; // As reported by Navigators. Can be kInfinity 128 G4double fMinSafety; 128 G4double fMinSafety; 129 G4double fTrueMinStep; // Corrected in cas 129 G4double fTrueMinStep; // Corrected in case fMinStep >= proposed 130 130 131 // State after calling 'locate' 131 // State after calling 'locate' 132 G4VPhysicalVolume* fLocatedVolume[G4ITNavi 132 G4VPhysicalVolume* fLocatedVolume[G4ITNavigator::fMaxNav]; 133 G4ThreeVector fLastLocatedPosition; 133 G4ThreeVector fLastLocatedPosition; 134 134 135 // cache of safety information 135 // cache of safety information 136 G4ThreeVector fSafetyLocation; // point w 136 G4ThreeVector fSafetyLocation; // point where ComputeSafety is called 137 G4double fMinSafety_atSafLocation; // /\ c 137 G4double fMinSafety_atSafLocation; // /\ corresponding value of safety 138 G4ThreeVector fPreStepLocation; // point 138 G4ThreeVector fPreStepLocation; // point where last ComputeStep called 139 G4double fMinSafety_PreStepPt; // /\ cor 139 G4double fMinSafety_PreStepPt; // /\ corresponding value of safety 140 }; 140 }; 141 141 142 class G4ITMultiNavigator : public G4ITNavigato 142 class G4ITMultiNavigator : public G4ITNavigator, 143 public G4TrackState 143 public G4TrackStateDependent<G4ITMultiNavigator> 144 { 144 { 145 public: 145 public: 146 // with description 146 // with description 147 147 148 friend std::ostream& operator <<(std::ostrea 148 friend std::ostream& operator <<(std::ostream &os, const G4ITNavigator &n); 149 149 150 G4ITMultiNavigator(); 150 G4ITMultiNavigator(); 151 // Constructor - initialisers and setup. 151 // Constructor - initialisers and setup. 152 152 153 ~G4ITMultiNavigator() override; 153 ~G4ITMultiNavigator() override; 154 // Destructor. No actions. 154 // Destructor. No actions. 155 155 156 G4double ComputeStep(const G4ThreeVector &pG 156 G4double ComputeStep(const G4ThreeVector &pGlobalPoint, 157 const G4ThreeVector &pD 157 const G4ThreeVector &pDirection, 158 const G4double pCurrent 158 const G4double pCurrentProposedStepLength, 159 G4double &pNewSafety) o 159 G4double &pNewSafety) override; 160 // Return the distance to the next boundary 160 // Return the distance to the next boundary of any geometry 161 161 162 G4double ObtainFinalStep(G4int navigatorId, 162 G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, // for this geom 163 G4double &minStepLa 163 G4double &minStepLast, 164 ELimited &limitedSt 164 ELimited &limitedStep); 165 // Get values for a single geometry 165 // Get values for a single geometry 166 166 167 void PrepareNavigators(); 167 void PrepareNavigators(); 168 // Find which geometries are registered for 168 // Find which geometries are registered for this particles, and keep info 169 void PrepareNewTrack(const G4ThreeVector pos 169 void PrepareNewTrack(const G4ThreeVector position, 170 const G4ThreeVector dir 170 const G4ThreeVector direction); 171 // Prepare Navigators and locate 171 // Prepare Navigators and locate 172 172 173 G4VPhysicalVolume* ResetHierarchyAndLocate(c 173 G4VPhysicalVolume* ResetHierarchyAndLocate(const G4ThreeVector &point, 174 c 174 const G4ThreeVector &direction, 175 c 175 const G4TouchableHistory &h) override; 176 // Reset the geometrical hierarchy for all g 176 // Reset the geometrical hierarchy for all geometries. 177 // Use the touchable history for the first ( 177 // Use the touchable history for the first (mass) geometry. 178 // Return the volume in the first (mass) geo 178 // Return the volume in the first (mass) geometry. 179 // 179 // 180 // Important Note: In order to call this the 180 // Important Note: In order to call this the geometries MUST be closed. 181 181 182 G4VPhysicalVolume* LocateGlobalPointAndSetup 182 G4VPhysicalVolume* LocateGlobalPointAndSetup(const G4ThreeVector& point, 183 183 const G4ThreeVector* direction = 184 184 nullptr, 185 185 const G4bool pRelativeSearch = 186 186 true, 187 187 const G4bool ignoreDirection = 188 188 true) override; 189 // Locate in all geometries. 189 // Locate in all geometries. 190 // Return the volume in the first (mass) geo 190 // Return the volume in the first (mass) geometry 191 // Maintain vector of other volumes, to be 191 // Maintain vector of other volumes, to be returned separately 192 // 192 // 193 // Important Note: In order to call this the 193 // Important Note: In order to call this the geometry MUST be closed. 194 194 195 void LocateGlobalPointWithinVolume(const G4T 195 void LocateGlobalPointWithinVolume(const G4ThreeVector& position) override; 196 // Relocate in all geometries for point that 196 // Relocate in all geometries for point that has not changed volume 197 // (ie is within safety in all geometries o 197 // (ie is within safety in all geometries or is distance less that 198 // along the direction of a computed step. 198 // along the direction of a computed step. 199 199 200 G4double ComputeSafety(const G4ThreeVector & 200 G4double ComputeSafety(const G4ThreeVector &globalpoint, 201 const G4double pPropo 201 const G4double pProposedMaxLength = DBL_MAX, 202 const G4bool keepStat 202 const G4bool keepState = false) override; 203 // Calculate the isot 203 // Calculate the isotropic distance to the nearest boundary 204 // in any geometry fr 204 // in any geometry from the specified point in the global coordinate 205 // system. The geomet 205 // system. The geometry must be closed. 206 206 207 G4TouchableHandle CreateTouchableHistoryHand 207 G4TouchableHandle CreateTouchableHistoryHandle() const override; 208 // Returns a reference counted handle to a t 208 // Returns a reference counted handle to a touchable history. 209 209 210 G4ThreeVector GetLocalExitNormal(G4bool* obt 210 G4ThreeVector GetLocalExitNormal(G4bool* obtained) override;// const 211 G4ThreeVector GetLocalExitNormalAndCheck(con 211 G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &CurrentE_Point, 212 G4bool* obtained) override;// const 212 G4bool* obtained) override;// const 213 G4ThreeVector GetGlobalExitNormal(const G4Th 213 G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &CurrentE_Point, 214 G4bool* obtained) override;// const 214 G4bool* obtained) override;// const 215 // Return Exit Surface Normal and validity t 215 // Return Exit Surface Normal and validity too. 216 // Can only be called if the Navigator's las 216 // Can only be called if the Navigator's last Step either 217 // - has just crossed a volume geometrical 217 // - has just crossed a volume geometrical boundary and relocated, or 218 // - has arrived at a boundary in a Compute 218 // - has arrived at a boundary in a ComputeStep 219 // It returns the Normal to the surface poin 219 // It returns the Normal to the surface pointing out of the volume that 220 // was left behind and/or into the volume 220 // was left behind and/or into the volume that was entered. 221 // Convention:x 221 // Convention:x 222 // The *local* normal is in the coordinate 222 // The *local* normal is in the coordinate system of the *final* volume. 223 // Restriction: 223 // Restriction: 224 // Normals are not available for replica v 224 // Normals are not available for replica volumes (returns obtained= false) 225 225 226 public:// without description 226 public:// without description 227 227 228 G4ITNavigator* GetNavigator(G4int n) const 228 G4ITNavigator* GetNavigator(G4int n) const 229 { 229 { 230 if( (n>fNoActiveNavigators)||(n<0)) 230 if( (n>fNoActiveNavigators)||(n<0)) 231 { n=0;} 231 { n=0;} 232 return fpNavigator[n]; 232 return fpNavigator[n]; 233 } 233 } 234 234 235 protected: // with description 235 protected: // with description 236 236 237 void ResetState() override; 237 void ResetState() override; 238 // Utility method to reset the navigator sta 238 // Utility method to reset the navigator state machine. 239 239 240 void SetupHierarchy() override; 240 void SetupHierarchy() override; 241 // Renavigate & reset hierarchy described by 241 // Renavigate & reset hierarchy described by current history 242 // o Reset volumes 242 // o Reset volumes 243 // o Recompute transforms and/or solids of r 243 // o Recompute transforms and/or solids of replicated/parameterised 244 // volumes. 244 // volumes. 245 245 246 void WhichLimited();// Flag which processes 246 void WhichLimited();// Flag which processes limited the step 247 void PrintLimited();// Auxiliary, debugging 247 void PrintLimited();// Auxiliary, debugging printing 248 void CheckMassWorld(); 248 void CheckMassWorld(); 249 249 250 private: 250 private: 251 251 252 G4int fNoActiveNavigators; 252 G4int fNoActiveNavigators; 253 G4VPhysicalVolume* fLastMassWorld{nullptr}; 253 G4VPhysicalVolume* fLastMassWorld{nullptr}; 254 254 255 G4ITNavigator* fpNavigator[fMaxNav];// G4ITN 255 G4ITNavigator* fpNavigator[fMaxNav];// G4ITNavigator** fpNavigator; 256 256 257 G4ITTransportationManager* pTransportManager 257 G4ITTransportationManager* pTransportManager;// Cache for frequent use 258 }; 258 }; 259 259 260 #endif 260 #endif 261 261