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 // G4Navigator << 26 // >> 27 // $Id: G4Navigator.hh 97507 2016-06-03 12:48:42Z gcosmo $ >> 28 // >> 29 // >> 30 // class G4Navigator 27 // 31 // 28 // Class description: 32 // Class description: 29 // 33 // 30 // A class for use by the tracking management, 34 // A class for use by the tracking management, able to obtain/calculate 31 // dynamic tracking time information such as t 35 // dynamic tracking time information such as the distance to the next volume, 32 // or to find the physical volume containing a 36 // or to find the physical volume containing a given point in the world 33 // reference system. The navigator maintains a 37 // reference system. The navigator maintains a transformation history and 34 // other information to optimise the tracking 38 // other information to optimise the tracking time performance. 35 39 >> 40 // History: 36 // - Created. 41 // - Created. Paul Kent, Jul 95/96 37 // - Made Navigator Abstract << 38 // - Added check mode << 39 // - Zero step protections 42 // - Zero step protections J.A. / G.C., Nov 2004 40 // ------------------------------------------- << 43 // - Added check mode G. Cosmo, Mar 2004 >> 44 // - Made Navigator Abstract G. Cosmo, Nov 2003 >> 45 // ********************************************************************* >> 46 41 #ifndef G4NAVIGATOR_HH 47 #ifndef G4NAVIGATOR_HH 42 #define G4NAVIGATOR_HH 1 << 48 #define G4NAVIGATOR_HH 43 49 44 #include "geomdefs.hh" 50 #include "geomdefs.hh" 45 51 46 #include "G4ThreeVector.hh" 52 #include "G4ThreeVector.hh" 47 #include "G4AffineTransform.hh" 53 #include "G4AffineTransform.hh" 48 #include "G4RotationMatrix.hh" 54 #include "G4RotationMatrix.hh" 49 55 50 #include "G4LogicalVolume.hh" // U 56 #include "G4LogicalVolume.hh" // Used in inline methods >> 57 #include "G4GRSVolume.hh" // " " >> 58 #include "G4GRSSolid.hh" // " " 51 #include "G4TouchableHandle.hh" // 59 #include "G4TouchableHandle.hh" // " " >> 60 #include "G4TouchableHistoryHandle.hh" 52 61 53 #include "G4NavigationHistory.hh" 62 #include "G4NavigationHistory.hh" 54 #include "G4NormalNavigation.hh" 63 #include "G4NormalNavigation.hh" 55 #include "G4VoxelNavigation.hh" 64 #include "G4VoxelNavigation.hh" 56 #include "G4ParameterisedNavigation.hh" 65 #include "G4ParameterisedNavigation.hh" 57 #include "G4ReplicaNavigation.hh" 66 #include "G4ReplicaNavigation.hh" 58 #include "G4RegularNavigation.hh" 67 #include "G4RegularNavigation.hh" 59 #include "G4VExternalNavigation.hh" << 60 68 61 #include <iostream> 69 #include <iostream> 62 70 63 class G4VPhysicalVolume; 71 class G4VPhysicalVolume; 64 class G4SafetyCalculator; << 65 72 66 class G4Navigator 73 class G4Navigator 67 { 74 { 68 public: << 75 public: // with description 69 << 70 friend std::ostream& operator << (std::ost << 71 << 72 G4Navigator(); << 73 // Constructor - initialisers and setup. << 74 << 75 G4Navigator(const G4Navigator&) = delete; << 76 G4Navigator& operator=(const G4Navigator&) << 77 // Copy constructor & assignment operato << 78 << 79 virtual ~G4Navigator(); << 80 // Destructor. No actions. << 81 << 82 virtual G4double ComputeStep(const G4Three << 83 const G4Three << 84 const G4doubl << 85 G4doubl << 86 // Calculate the distance to the next bo << 87 // along the specified NORMALISED vector << 88 // from the specified point in the globa << 89 // system. LocateGlobalPointAndSetup or << 90 // must have been called with the same g << 91 // The isotropic distance to the nearest << 92 // calculated (usually an underestimate) << 93 // proposed Step length is used to avoid << 94 // calculations: if it can be determined << 95 // boundary is >pCurrentProposedStepLeng << 96 // is returned together with the compute << 97 // distance. Geometry must be closed. << 98 << 99 G4double CheckNextStep(const G4ThreeVector << 100 const G4ThreeVector << 101 const G4double pCur << 102 G4double& pNe << 103 // Same as above, but do not disturb the << 104 << 105 virtual << 106 G4VPhysicalVolume* ResetHierarchyAndLocate << 107 << 108 << 109 << 110 // Resets the geometrical hierarchy and << 111 // in the hierarchy containing the point << 112 // The direction is used to check if a v << 113 // The search begin is the geometrical h << 114 // last located point, or the endpoint o << 115 // SetGeometricallyLimitedStep() has bee << 116 // << 117 // Important Note: In order to call this << 118 << 119 virtual << 120 G4VPhysicalVolume* LocateGlobalPointAndSet << 121 const G << 122 const G << 123 const G << 124 // Search the geometrical hierarchy for << 125 // containing the point in the global co << 126 // are: << 127 // i) If pRelativeSearch=false it makes << 128 // information. Returns the physical << 129 // with all previous mothers correct << 130 // ii) If pRelativeSearch is set to true << 131 // geometrical hierarchy at the loca << 132 // or the endpoint of previous Step << 133 // has been called immediately befor << 134 // The direction is used (to check if a << 135 // - the argument ignoreDirection is f << 136 // - the Navigator has determined that << 137 // or more volumes. (This is state << 138 // << 139 // Important Note: In order to call this << 140 << 141 virtual << 142 void LocateGlobalPointWithinVolume(const G << 143 // Notify the Navigator that a track has << 144 // 'position', that is known to be withi << 145 // No check is performed to ensure that << 146 // This method can be called instead of << 147 // the caller is certain that the new gl << 148 // the same volume as the previous posit << 149 // Usually this can be guaranteed only i << 150 << 151 inline void LocateGlobalPointAndUpdateTouc << 152 const G4ThreeVector& p << 153 const G4ThreeVector& d << 154 G4TouchableHandle& o << 155 const G4bool R << 156 // First, search the geometrical hierarc << 157 // LocateGlobalPointAndSetup(). Then use << 158 // navigation history to update the touc << 159 << 160 inline void LocateGlobalPointAndUpdateTouc << 161 const G4ThreeVector& p << 162 const G4ThreeVector& d << 163 G4VTouchable* t << 164 const G4bool R << 165 // First, search the geometrical hierarc << 166 // LocateGlobalPointAndSetup(). Then use << 167 // navigation history to update the touc << 168 << 169 inline void LocateGlobalPointAndUpdateTouc << 170 const G4ThreeVector& p << 171 G4VTouchable* t << 172 const G4bool R << 173 // Same as the method above but missing << 174 << 175 inline void SetGeometricallyLimitedStep(); << 176 // Inform the navigator that the previou << 177 // by the geometry was taken in its enti << 178 << 179 virtual G4double ComputeSafety(const G4Thr << 180 const G4dou << 181 const G4boo << 182 // Calculate the isotropic distance to t << 183 // specified point in the global coordin << 184 // The globalpoint utilised must be with << 185 // The value returned is usually an unde << 186 // The proposed maximum length is used t << 187 // calculations. The geometry must be c << 188 // To ensure minimum side effects from t << 189 << 190 inline G4VPhysicalVolume* GetWorldVolume() << 191 // Return the current world (`topmost') << 192 << 193 inline void SetWorldVolume(G4VPhysicalVolu << 194 // Set the world (`topmost') volume. Thi << 195 // origin (0,0,0) and unrotated. << 196 << 197 inline G4TouchableHistory* CreateTouchable << 198 inline G4TouchableHistory* CreateTouchable << 199 // `Touchable' creation methods: caller << 200 << 201 virtual G4TouchableHandle CreateTouchableH << 202 // Returns a reference counted handle to << 203 << 204 virtual G4ThreeVector GetLocalExitNormal(G << 205 virtual G4ThreeVector GetLocalExitNormalAn << 206 << 207 virtual G4ThreeVector GetGlobalExitNormal( << 208 << 209 // Return Exit Surface Normal and validi << 210 // Can only be called if the Navigator's << 211 // volume geometrical boundary. << 212 // It returns the Normal to the surface << 213 // was left behind and/or into the volum << 214 // Convention: << 215 // The *local* normal is in the coordi << 216 // Restriction: << 217 // Normals are not available for repli << 218 // These methods takes full care about h << 219 // but if the surfaces are not convex it << 220 << 221 inline G4int GetVerboseLevel() const; << 222 inline void SetVerboseLevel(G4int level); << 223 // Get/Set Verbose(ness) level. << 224 // [if level>0 && G4VERBOSE, printout ca << 225 << 226 inline G4bool IsActive() const; << 227 // Verify if the navigator is active. << 228 inline void Activate(G4bool flag); << 229 // Activate/inactivate the navigator. << 230 << 231 inline G4bool EnteredDaughterVolume() cons << 232 // The purpose of this function is to in << 233 // entering a daughter volume while exit << 234 // This method returns << 235 // - True only in case 1) above, that is << 236 // the track to arrive at a boundary o << 237 // - False in cases 2), 3) and 4), i.e. << 238 // This function is not guaranteed to wo << 239 // was not called when it should have be << 240 inline G4bool ExitedMotherVolume() const; << 241 // Verify if the step has exited the mot << 242 << 243 inline void CheckMode(G4bool mode); << 244 // Run navigation in "check-mode", there << 245 // verifications and more strict correct << 246 // Is effective only with G4VERBOSE set. << 247 inline G4bool IsCheckModeActive() const; << 248 inline void SetPushVerbosity(G4bool mode); << 249 // Set/unset verbosity for pushed tracks << 250 << 251 void PrintState() const; << 252 // Print the internal state of the Navig << 253 // The level of detail is according to t << 254 << 255 inline const G4AffineTransform& GetGlobalT << 256 inline const G4AffineTransform GetLocalTo << 257 // Obtain the transformations Global/Loc << 258 // Clients of these methods must copy th << 259 << 260 G4AffineTransform GetMotherToDaughterTrans << 261 << 262 << 263 // Obtain mother to daughter transformat << 264 << 265 inline void ResetStackAndState(); << 266 // Reset stack and minimum or navigator << 267 // as needed by LocalGlobalPointAndSetup << 268 // Does not perform clears, resizes, or << 269 << 270 inline G4int SeverityOfZeroStepping( G4int << 271 // Report on severity of error and numbe << 272 // in case Navigator is stuck and is ret << 273 // Values: 1 (small problem), 5 (correc << 274 // 9 (ready to abandon), 10 (aba << 275 << 276 inline G4ThreeVector GetCurrentLocalCoordi << 277 // Return the local coordinate of the po << 278 // of its containing volume that was fou << 279 // The local coordinate of the last loca << 280 << 281 inline G4ThreeVector NetTranslation() cons << 282 inline G4RotationMatrix NetRotation() cons << 283 // Compute+return the local->global tran << 284 << 285 inline void EnableBestSafety( G4bool value << 286 // Enable best-possible evaluation of is << 287 << 288 inline G4VExternalNavigation* GetExternalN << 289 void SetExternalNavigation(G4VExternalNavi << 290 // Accessor & modifier for custom extern << 291 << 292 inline G4VoxelNavigation& GetVoxelNavigato << 293 void SetVoxelNavigation(G4VoxelNavigation* << 294 // Alternative navigator for voxel volum << 295 << 296 inline G4Navigator* Clone() const; << 297 // Cloning feature for use in MT applica << 298 // navigator, including external sub-nav << 299 // Client has responsibility for ownersh << 300 << 301 inline G4ThreeVector GetLastStepEndPoint() << 302 // Get endpoint of last step. << 303 << 304 void InformLastStep(G4double lastStep, << 305 G4bool entersDaughtVol << 306 G4bool exitsMotherVol << 307 // Derived navigators which rely on Loca << 308 // inform size of step, to maintain logi << 309 // for challenging cases. << 310 // Required in order to cope with multip << 311 // => Locate with use direction rather t << 312 << 313 protected: << 314 << 315 void SetSavedState(); << 316 // ( fValidExitNormal, fExitNormal, fExi << 317 // fBlockedPhysicalVolume, fBlockedRep << 318 // Extended to include: << 319 // ( fLastLocatedPointLocal, fLocatedOut << 320 // fEnteredDaughter, fExitedMother << 321 // fPreviousSftOrigin, sPreviousSafety << 322 << 323 void RestoreSavedState(); << 324 // Copy aspects of the state, to enable << 325 // call to ComputeStep(). << 326 << 327 virtual void ResetState(); << 328 // Utility method to reset the navigator << 329 << 330 inline G4ThreeVector ComputeLocalPoint(con << 331 // Return position vector in local coord << 332 // vector in world coordinate system. << 333 << 334 inline G4ThreeVector ComputeLocalAxis(cons << 335 // Return the local direction of the spe << 336 // system of the volume that was found b << 337 // The Local Coordinates of point in wor << 338 << 339 inline EVolume VolumeType(const G4VPhysica << 340 // Characterise `type' of volume - norma << 341 << 342 inline EVolume CharacteriseDaughters(const << 343 // Characterise daughter of logical volu << 344 << 345 inline G4int GetDaughtersRegularStructureI << 346 // Get regular structure ID of first dau << 347 76 348 virtual void SetupHierarchy(); << 77 friend std::ostream& operator << (std::ostream &os, const G4Navigator &n); 349 // Renavigate & reset hierarchy describe << 350 // o Reset volumes and recompute transfo << 351 // replicated/parameterised volumes. << 352 78 353 G4bool CheckOverlapsIterative(G4VPhysicalV << 79 G4Navigator(); 354 // Utility method to trigger overlaps ch << 80 // Constructor - initialisers and setup. 355 // overlaps ordered by relevance. Used i << 356 // with zero step are detected. << 357 81 358 private: << 82 virtual ~G4Navigator(); 359 << 83 // Destructor. No actions. 360 void ComputeStepLog(const G4ThreeVector& p << 84 361 G4double moveLen << 85 virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint, 362 // Log and checks for steps larger than << 86 const G4ThreeVector &pDirection, 363 << 87 const G4double pCurrentProposedStepLength, 364 protected: << 88 G4double &pNewSafety); 365 << 89 // Calculate the distance to the next boundary intersected 366 G4double kCarTolerance, fMinStep, fSqTol; << 90 // along the specified NORMALISED vector direction and 367 // Cached tolerances. << 91 // from the specified point in the global coordinate 368 << 92 // system. LocateGlobalPointAndSetup or LocateGlobalPointWithinVolume 369 // << 93 // must have been called with the same global point prior to this call. 370 // BEGIN State information << 94 // The isotropic distance to the nearest boundary is also 371 // << 95 // calculated (usually an underestimate). The current 372 << 96 // proposed Step length is used to avoid intersection 373 G4NavigationHistory fHistory; << 97 // calculations: if it can be determined that the nearest 374 // Transformation and history of the cur << 98 // boundary is >pCurrentProposedStepLength away, kInfinity 375 // through the geometrical hierarchy. << 99 // is returned together with the computed isotropic safety 376 << 100 // distance. Geometry must be closed. 377 G4ThreeVector fStepEndPoint; << 101 378 // Endpoint of last ComputeStep << 102 G4double CheckNextStep(const G4ThreeVector &pGlobalPoint, 379 // can be used for optimisation (e.g. wh << 103 const G4ThreeVector &pDirection, 380 G4ThreeVector fLastStepEndPointLocal; << 104 const G4double pCurrentProposedStepLength, 381 // Position of the end-point of the last << 105 G4double &pNewSafety); 382 // in last Local coordinates. << 106 // Same as above, but do not disturb the state of the Navigator. >> 107 >> 108 virtual >> 109 G4VPhysicalVolume* ResetHierarchyAndLocate(const G4ThreeVector &point, >> 110 const G4ThreeVector &direction, >> 111 const G4TouchableHistory &h); >> 112 >> 113 // Resets the geometrical hierarchy and search for the volumes deepest >> 114 // in the hierarchy containing the point in the global coordinate space. >> 115 // The direction is used to check if a volume is entered. >> 116 // The search begin is the geometrical hierarchy at the location of the >> 117 // last located point, or the endpoint of the previous Step if >> 118 // SetGeometricallyLimitedStep() has been called immediately before. >> 119 // >> 120 // Important Note: In order to call this the geometry MUST be closed. 383 121 384 G4int fVerbose = 0; << 122 virtual 385 // Verbose(ness) level [if > 0, printou << 123 G4VPhysicalVolume* LocateGlobalPointAndSetup(const G4ThreeVector& point, 386 << 124 const G4ThreeVector* direction=0, 387 G4bool fEnteredDaughter; << 125 const G4bool pRelativeSearch=true, 388 // A memory of whether in this Step a da << 126 const G4bool ignoreDirection=true); 389 // (set in Compute & Locate). << 127 // Search the geometrical hierarchy for the volumes deepest in the hierarchy 390 // After Compute: it expects to enter a << 128 // containing the point in the global coordinate space. Two main cases are: 391 // After Locate: it has entered a daugh << 129 // i) If pRelativeSearch=false it makes use of no previous/state 392 << 130 // information. Returns the physical volume containing the point, 393 G4bool fExitedMother; << 131 // with all previous mothers correctly set up. 394 // A similar memory whether the Step exi << 132 // ii) If pRelativeSearch is set to true, the search begin is the 395 // completely, not entering daughter. << 133 // geometrical hierarchy at the location of the last located point, 396 << 134 // or the endpoint of the previous Step if SetGeometricallyLimitedStep() 397 G4bool fWasLimitedByGeometry = false; << 135 // has been called immediately before. 398 // Set true if last Step was limited by << 136 // The direction is used (to check if a volume is entered) if either 399 << 137 // - the argument ignoreDirection is false, or 400 private: << 138 // - the Navigator has determined that it is on an edge shared by two or 401 << 139 // more volumes. (This is state information.) 402 G4ThreeVector fLastLocatedPointLocal; << 140 // 403 // Position of the last located point re << 141 // Important Note: In order to call this the geometry MUST be closed. 404 // This is coupled with the bool member << 405 << 406 G4ThreeVector fExitNormal; << 407 // Leaving volume normal, in the volume << 408 // volume's coordinate system. << 409 // This is closely coupled with fValidEx << 410 // we have a (valid) normal for volume w << 411 << 412 G4ThreeVector fGrandMotherExitNormal; << 413 // Leaving volume normal, in its own coo << 414 G4ThreeVector fExitNormalGlobalFrame; << 415 // Leaving volume normal, in the global << 416 << 417 G4ThreeVector fPreviousSftOrigin; << 418 G4double fPreviousSafety; << 419 // Memory of last safety origin & value. << 420 // that origin of current Step is in the << 421 // last relocation. << 422 << 423 G4VPhysicalVolume* fLastMotherPhys = nullp << 424 // Memory of the mother volume during pr << 425 // Intended use: inform user in case of << 426 << 427 G4VPhysicalVolume* fBlockedPhysicalVolume; << 428 G4int fBlockedReplicaNo; << 429 // Identifies the volume and copy / repl << 430 // (after exiting -- because the exit di << 431 // or a candidate for entry (after compu << 432 << 433 G4int fNumberZeroSteps; << 434 // Count zero steps, as one or two can o << 435 // a boundary or at an edge common betwe << 436 // are likely a problem in the geometry << 437 // Number of preceding moves that were Z << 438 G4int fActionThreshold_NoZeroSteps = 10; << 439 // After this many failed/zero steps, ac << 440 G4int fAbandonThreshold_NoZeroSteps = 25; << 441 // After this many failed/zero steps, ab << 442 << 443 G4bool fActive = false; << 444 // States if the navigator is activated << 445 << 446 G4bool fLastTriedStepComputation = false; << 447 // Whether ComputeStep() was called sinc << 448 // Uses: distinguish parts of state whic << 449 // to ComputeStep() or one of the Locate << 450 // calls to compute-step (illegal). << 451 << 452 G4bool fEntering, fExiting; << 453 // Entering/Exiting volumes blocking/set << 454 // o If exiting, volume ptr & replica nu << 455 // used for blocking on redescent of g << 456 // o If entering, volume ptr & replica n << 457 // used by Locate..()) of volume for ' << 458 << 459 G4bool fValidExitNormal; << 460 // Set true if have leaving volume norma << 461 G4bool fLastStepWasZero; << 462 // Whether the last ComputeStep moved Ze << 463 G4bool fLocatedOnEdge; << 464 // Whether the Navigator has detected an << 465 G4bool fLocatedOutsideWorld; << 466 // Whether the last call to Locate metho << 467 << 468 G4bool fChangedGrandMotherRefFrame; << 469 // Whether frame is changed. << 470 G4bool fCalculatedExitNormal; << 471 // Has it been computed since the last c << 472 // Covers both Global and GrandMother. << 473 142 474 // END State information << 143 virtual 475 // << 144 void LocateGlobalPointWithinVolume(const G4ThreeVector& position); >> 145 // Notify the Navigator that a track has moved to the new Global point >> 146 // 'position', that is known to be within the current safety. >> 147 // No check is performed to ensure that it is within the volume. >> 148 // This method can be called instead of LocateGlobalPointAndSetup ONLY if >> 149 // the caller is certain that the new global point (position) is inside the >> 150 // same volume as the previous position. Usually this can be guaranteed >> 151 // only if the point is within safety. >> 152 >> 153 inline void LocateGlobalPointAndUpdateTouchableHandle( >> 154 const G4ThreeVector& position, >> 155 const G4ThreeVector& direction, >> 156 G4TouchableHandle& oldTouchableToUpdate, >> 157 const G4bool RelativeSearch = true); >> 158 // First, search the geometrical hierarchy like the above method >> 159 // LocateGlobalPointAndSetup(). Then use the volume found and its >> 160 // navigation history to update the touchable. >> 161 >> 162 inline void LocateGlobalPointAndUpdateTouchable( >> 163 const G4ThreeVector& position, >> 164 const G4ThreeVector& direction, >> 165 G4VTouchable* touchableToUpdate, >> 166 const G4bool RelativeSearch = true); >> 167 // First, search the geometrical hierarchy like the above method >> 168 // LocateGlobalPointAndSetup(). Then use the volume found and its >> 169 // navigation history to update the touchable. >> 170 >> 171 inline void LocateGlobalPointAndUpdateTouchable( >> 172 const G4ThreeVector& position, >> 173 G4VTouchable* touchableToUpdate, >> 174 const G4bool RelativeSearch = true); >> 175 // Same as the method above but missing direction. >> 176 >> 177 inline void SetGeometricallyLimitedStep(); >> 178 // Inform the navigator that the previous Step calculated >> 179 // by the geometry was taken in its entirety. >> 180 >> 181 virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, >> 182 const G4double pProposedMaxLength = DBL_MAX, >> 183 const G4bool keepState = true); >> 184 // Calculate the isotropic distance to the nearest boundary from the >> 185 // specified point in the global coordinate system. >> 186 // The globalpoint utilised must be within the current volume. >> 187 // The value returned is usually an underestimate. >> 188 // The proposed maximum length is used to avoid volume safety >> 189 // calculations. The geometry must be closed. >> 190 // To ensure minimum side effects from the call, keepState >> 191 // must be true. >> 192 >> 193 virtual G4bool RecheckDistanceToCurrentBoundary( >> 194 const G4ThreeVector &pGlobalPoint, >> 195 const G4ThreeVector &pDirection, >> 196 const G4double CurrentProposedStepLength, >> 197 G4double *prDistance, >> 198 G4double *prNewSafety=0) const; >> 199 // Trial method for checking potential displacement for MS >> 200 // Check new Globalpoint, to see whether it is in current volume >> 201 // (mother) and not in potential entering daughter. >> 202 // If in mother, check distance to boundary along pDirection. >> 203 // If in entering daughter, check distance back to boundary. >> 204 // NOTE: >> 205 // Can be called only after ComputeStep is called - before ReLocation >> 206 // Deals only with current volume (and potentially entered) >> 207 >> 208 inline G4VPhysicalVolume* GetWorldVolume() const; >> 209 // Return the current world (`topmost') volume. >> 210 >> 211 inline void SetWorldVolume(G4VPhysicalVolume* pWorld); >> 212 // Set the world (`topmost') volume. This must be positioned at >> 213 // origin (0,0,0) and unrotated. >> 214 >> 215 inline G4GRSVolume* CreateGRSVolume() const; >> 216 inline G4GRSSolid* CreateGRSSolid() const; >> 217 inline G4TouchableHistory* CreateTouchableHistory() const; >> 218 inline G4TouchableHistory* CreateTouchableHistory(const G4NavigationHistory*) const; >> 219 // `Touchable' creation methods: caller has deletion responsibility. >> 220 >> 221 virtual G4TouchableHistoryHandle CreateTouchableHistoryHandle() const; >> 222 // Returns a reference counted handle to a touchable history. >> 223 >> 224 virtual G4ThreeVector GetLocalExitNormal(G4bool* valid); >> 225 virtual G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector& point, >> 226 G4bool* valid); >> 227 virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector& point, >> 228 G4bool* valid); >> 229 // Return Exit Surface Normal and validity too. >> 230 // Can only be called if the Navigator's last Step has crossed a >> 231 // volume geometrical boundary. >> 232 // It returns the Normal to the surface pointing out of the volume that >> 233 // was left behind and/or into the volume that was entered. >> 234 // Convention: >> 235 // The *local* normal is in the coordinate system of the *final* volume. >> 236 // Restriction: >> 237 // Normals are not available for replica volumes (returns valid= false) >> 238 // These methods takes full care about how to calculate this normal, >> 239 // but if the surfaces are not convex it will return valid=false. >> 240 >> 241 inline G4int GetVerboseLevel() const; >> 242 inline void SetVerboseLevel(G4int level); >> 243 // Get/Set Verbose(ness) level. >> 244 // [if level>0 && G4VERBOSE, printout can occur] >> 245 >> 246 inline G4bool IsActive() const; >> 247 // Verify if the navigator is active. >> 248 inline void Activate(G4bool flag); >> 249 // Activate/inactivate the navigator. >> 250 >> 251 inline G4bool EnteredDaughterVolume() const; >> 252 // The purpose of this function is to inform the caller if the track is >> 253 // entering a daughter volume while exiting from the current volume. >> 254 // This method returns >> 255 // - True only in case 1) above, that is when the Step has caused >> 256 // the track to arrive at a boundary of a daughter. >> 257 // - False in cases 2), 3) and 4), i.e. in all other cases. >> 258 // This function is not guaranteed to work if SetGeometricallyLimitedStep() >> 259 // was not called when it should have been called. >> 260 inline G4bool ExitedMotherVolume() const; >> 261 // Verify if the step has exited the mother volume. >> 262 >> 263 inline void CheckMode(G4bool mode); >> 264 // Run navigation in "check-mode", therefore using additional >> 265 // verifications and more strict correctness conditions. >> 266 // Is effective only with G4VERBOSE set. >> 267 inline G4bool IsCheckModeActive() const; >> 268 inline void SetPushVerbosity(G4bool mode); >> 269 // Set/unset verbosity for pushed tracks (default is true). >> 270 >> 271 void PrintState() const; >> 272 // Print the internal state of the Navigator (for debugging). >> 273 // The level of detail is according to the verbosity. >> 274 >> 275 inline const G4AffineTransform& GetGlobalToLocalTransform() const; >> 276 inline const G4AffineTransform GetLocalToGlobalTransform() const; >> 277 // Obtain the transformations Global/Local (and inverse). >> 278 // Clients of these methods must copy the data if they need to keep it. >> 279 >> 280 G4AffineTransform GetMotherToDaughterTransform(G4VPhysicalVolume* dVolume, >> 281 G4int dReplicaNo, >> 282 EVolume dVolumeType ); >> 283 // Obtain mother to daughter transformation >> 284 >> 285 inline void ResetStackAndState(); >> 286 // Reset stack and minimum or navigator state machine necessary for reset >> 287 // as needed by LocalGlobalPointAndSetup. >> 288 // [Does not perform clears, resizes, or reset fLastLocatedPointLocal] >> 289 >> 290 inline G4int SeverityOfZeroStepping( G4int* noZeroSteps ) const; >> 291 // Report on severity of error and number of zero steps, >> 292 // in case Navigator is stuck and is returning zero steps. >> 293 // Values: 1 (small problem), 5 (correcting), >> 294 // 9 (ready to abandon), 10 (abandoned) >> 295 >> 296 inline G4ThreeVector GetCurrentLocalCoordinate() const; >> 297 // Return the local coordinate of the point in the reference system >> 298 // of its containing volume that was found by LocalGlobalPointAndSetup. >> 299 // The local coordinate of the last located track. >> 300 >> 301 inline G4ThreeVector NetTranslation() const; >> 302 inline G4RotationMatrix NetRotation() const; >> 303 // Compute+return the local->global translation/rotation of current volume. >> 304 >> 305 inline void EnableBestSafety( G4bool value= false ); >> 306 // Enable best-possible evaluation of isotropic safety >> 307 >> 308 protected: // with description >> 309 >> 310 void SetSavedState(); >> 311 // ( fValidExitNormal, fExitNormal, fExiting, fEntering, >> 312 // fBlockedPhysicalVolume, fBlockedReplicaNo, fLastStepWasZero); >> 313 // Extended to include: >> 314 // ( fLastLocatedPointLocal, fLocatedOutsideWorld; >> 315 // fEnteredDaughter, fExitedMother >> 316 // fPreviousSftOrigin, sPreviousSafety) Safety Sphere. >> 317 >> 318 void RestoreSavedState(); >> 319 // Copy aspects of the state, to enable a non-state changing >> 320 // call to ComputeStep(). >> 321 >> 322 virtual void ResetState(); >> 323 // Utility method to reset the navigator state machine. 476 324 477 // Optional State information (created/use << 325 inline G4ThreeVector ComputeLocalPoint(const G4ThreeVector& rGlobPoint) const; 478 // << 326 // Return position vector in local coordinate system, given a position >> 327 // vector in world coordinate system. >> 328 >> 329 inline G4ThreeVector ComputeLocalAxis(const G4ThreeVector& pVec) const; >> 330 // Return the local direction of the specified vector in the reference >> 331 // system of the volume that was found by LocalGlobalPointAndSetup. >> 332 // The Local Coordinates of point in world coordinate system. >> 333 >> 334 inline EVolume VolumeType(const G4VPhysicalVolume *pVol) const; >> 335 // Characterise `type' of volume - normal/replicated/parameterised. >> 336 >> 337 inline EVolume CharacteriseDaughters(const G4LogicalVolume *pLog) const; >> 338 // Characterise daughter of logical volume. >> 339 >> 340 inline G4int GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const; >> 341 // Get regular structure ID of first daughter >> 342 >> 343 virtual void SetupHierarchy(); >> 344 // Renavigate & reset hierarchy described by current history >> 345 // o Reset volumes >> 346 // o Recompute transforms and/or solids of replicated/parameterised >> 347 // volumes. >> 348 >> 349 private: >> 350 >> 351 G4Navigator(const G4Navigator&); >> 352 G4Navigator& operator=(const G4Navigator&); >> 353 // Private copy-constructor and assignment operator. >> 354 >> 355 void ComputeStepLog(const G4ThreeVector& pGlobalpoint, >> 356 G4double moveLenSq) const; >> 357 // Log and checks for steps larger than the tolerance >> 358 >> 359 protected: // without description >> 360 >> 361 G4double kCarTolerance, fMinStep, fSqTol; >> 362 // Cached tolerances. >> 363 >> 364 // >> 365 // BEGIN State information >> 366 // >> 367 >> 368 G4NavigationHistory fHistory; >> 369 // Transformation and history of the current path >> 370 // through the geometrical hierarchy. >> 371 >> 372 G4bool fEnteredDaughter; >> 373 // A memory of whether in this Step a daughter volume is entered >> 374 // (set in Compute & Locate). >> 375 // After Compute: it expects to enter a daughter >> 376 // After Locate: it has entered a daughter >> 377 >> 378 G4bool fExitedMother; >> 379 // A similar memory whether the Step exited current "mother" volume >> 380 // completely, not entering daughter. >> 381 >> 382 G4bool fWasLimitedByGeometry; >> 383 // Set true if last Step was limited by geometry. >> 384 >> 385 G4ThreeVector fStepEndPoint; >> 386 // Endpoint of last ComputeStep >> 387 // can be used for optimisation (e.g. when computing safety). >> 388 G4ThreeVector fLastStepEndPointLocal; >> 389 // Position of the end-point of the last call to ComputeStep >> 390 // in last Local coordinates. >> 391 >> 392 G4int fVerbose; >> 393 // Verbose(ness) level [if > 0, printout can occur]. >> 394 >> 395 private: >> 396 >> 397 G4bool fActive; >> 398 // States if the navigator is activated or not. >> 399 >> 400 G4bool fLastTriedStepComputation; >> 401 // Whether ComputeStep was called since the last call to a Locate method >> 402 // Uses: - distinguish parts of state which differ before/after calls >> 403 // to ComputeStep or one of the Locate methods; >> 404 // - avoid two consecutive calls to compute-step (illegal). >> 405 >> 406 G4bool fEntering,fExiting; >> 407 // Entering/Exiting volumes blocking/setup >> 408 // o If exiting >> 409 // volume ptr & replica number (set & used by Locate..()) >> 410 // used for blocking on redescent of geometry >> 411 // o If entering >> 412 // volume ptr & replica number (set by ComputeStep(),used by >> 413 // Locate..()) of volume for `automatic' entry >> 414 >> 415 G4VPhysicalVolume *fBlockedPhysicalVolume; >> 416 G4int fBlockedReplicaNo; >> 417 >> 418 G4ThreeVector fLastLocatedPointLocal; >> 419 // Position of the last located point relative to its containing volume. >> 420 G4bool fLocatedOutsideWorld; >> 421 // Whether the last call to Locate methods left the world >> 422 >> 423 G4bool fValidExitNormal; // Set true if have leaving volume normal >> 424 G4ThreeVector fExitNormal; // Leaving volume normal, in the >> 425 // volume containing the exited >> 426 // volume's coordinate system >> 427 G4ThreeVector fGrandMotherExitNormal; // Leaving volume normal, in its >> 428 // own coordinate system >> 429 G4bool fChangedGrandMotherRefFrame; // Whether frame is changed >> 430 >> 431 G4ThreeVector fExitNormalGlobalFrame; // Leaving volume normal, in the >> 432 // global coordinate system >> 433 G4bool fCalculatedExitNormal; // Has it been computed since >> 434 // the last call to ComputeStep >> 435 // Covers both Global and GrandMother 479 436 480 // Save key state information (NOT the nav << 437 // Count zero steps - as one or two can occur due to changing momentum at 481 // << 438 // a boundary or at an edge common between volumes 482 struct G4SaveNavigatorState << 439 // - several are likely a problem in the geometry 483 { << 440 // description or in the navigation 484 G4ThreeVector sExitNormal; << 441 // 485 G4bool sValidExitNormal; << 442 G4bool fLastStepWasZero; 486 G4bool sEntering, sExiting; << 443 // Whether the last ComputeStep moved Zero. Used to check for edges. 487 G4VPhysicalVolume* spBlockedPhysicalVol << 444 488 G4int sBlockedReplicaNo; << 445 G4bool fLocatedOnEdge; 489 G4int sLastStepWasZero; << 446 // Whether the Navigator has detected an edge 490 G4bool sWasLimitedByGeometry; << 447 G4int fNumberZeroSteps; 491 << 448 // Number of preceding moves that were Zero. Reset to 0 after finite step 492 // Potentially relevant << 449 G4int fActionThreshold_NoZeroSteps; 493 // << 450 // After this many failed/zero steps, act (push etc) 494 G4bool sLocatedOutsideWorld; << 451 G4int fAbandonThreshold_NoZeroSteps; 495 G4ThreeVector sLastLocatedPointLocal; << 452 // After this many failed/zero steps, abandon track 496 G4bool sEnteredDaughter, sExitedMother; << 453 497 G4ThreeVector sPreviousSftOrigin; << 454 G4ThreeVector fPreviousSftOrigin; 498 G4double sPreviousSafety; << 455 G4double fPreviousSafety; 499 } fSaveState; << 456 // Memory of last safety origin & value. Used in ComputeStep to ensure 500 << 457 // that origin of current Step is in the same volume as the point of the 501 // BEGIN -- Tracking Invariants << 458 // last relocation 502 // ======================================= << 459 503 << 460 // 504 G4VPhysicalVolume* fTopPhysical = nullptr; << 461 // END State information 505 // A link to the topmost physical volume << 462 // 506 // Must be positioned at the origin and << 463 507 << 464 // Save key state information (NOT the navigation history stack) 508 // Helpers/Utility classes << 465 // 509 // << 466 struct G4SaveNavigatorState 510 G4NormalNavigation fnormalNav; << 467 { 511 G4VoxelNavigation* fpvoxelNav; << 468 G4ThreeVector sExitNormal; 512 G4ParameterisedNavigation fparamNav; << 469 G4bool sValidExitNormal; 513 G4ReplicaNavigation freplicaNav; << 470 G4bool sEntering, sExiting; 514 G4RegularNavigation fregularNav; << 471 G4VPhysicalVolume* spBlockedPhysicalVolume; 515 G4VExternalNavigation* fpExternalNav = nul << 472 G4int sBlockedReplicaNo; 516 G4VoxelSafety* fpVoxelSafety; << 473 G4int sLastStepWasZero; 517 G4SafetyCalculator* fpSafetyCalculator = n << 474 G4bool sWasLimitedByGeometry; 518 << 475 519 // Utility information << 476 // Potentially relevant 520 // << 477 // 521 G4bool fCheck = false; << 478 G4bool sLocatedOutsideWorld; 522 // Check-mode flag [if true, more stric << 479 G4ThreeVector sLastLocatedPointLocal; 523 G4bool fPushed = false, fWarnPush = true; << 480 G4bool sEnteredDaughter, sExitedMother; 524 // Push flags [if true, means a stuck p << 481 G4ThreeVector sPreviousSftOrigin; 525 << 482 G4double sPreviousSafety; 526 // End -- Tracking Invariants << 483 } fSaveState; >> 484 >> 485 // Tracking Invariants >> 486 // >> 487 G4VPhysicalVolume *fTopPhysical; >> 488 // A link to the topmost physical volume in the detector. >> 489 // Must be positioned at the origin and unrotated. >> 490 >> 491 // Utility information >> 492 // >> 493 G4bool fCheck; >> 494 // Check-mode flag [if true, more strict checks are performed]. >> 495 G4bool fPushed, fWarnPush; >> 496 // Push flags [if true, means a stuck particle has been pushed]. >> 497 >> 498 // Helpers/Utility classes >> 499 // >> 500 G4NormalNavigation fnormalNav; >> 501 G4VoxelNavigation fvoxelNav; >> 502 G4ParameterisedNavigation fparamNav; >> 503 G4ReplicaNavigation freplicaNav; >> 504 G4RegularNavigation fregularNav; >> 505 G4VoxelSafety *fpVoxelSafety; 527 }; 506 }; 528 507 529 #include "G4Navigator.icc" 508 #include "G4Navigator.icc" 530 509 531 #endif 510 #endif 532 511 533 512 534 // NOTES: 513 // NOTES: 535 // 514 // 536 // The following methods provide detailed info 515 // The following methods provide detailed information when a Step has 537 // arrived at a geometrical boundary. They di 516 // arrived at a geometrical boundary. They distinguish between the different 538 // causes that can result in the track leaving 517 // causes that can result in the track leaving its current volume. 539 // 518 // 540 // Four cases are possible: 519 // Four cases are possible: 541 // 520 // 542 // 1) The particle has reached a boundary of a 521 // 1) The particle has reached a boundary of a daughter of the current volume: 543 // (this could cause the relocation to ent 522 // (this could cause the relocation to enter the daughter itself 544 // or a potential granddaughter or further 523 // or a potential granddaughter or further descendant) 545 // 524 // 546 // 2) The particle has reached a boundary of t 525 // 2) The particle has reached a boundary of the current 547 // volume, exiting into a mother (regardle 526 // volume, exiting into a mother (regardless the level 548 // at which it is located in the tree): 527 // at which it is located in the tree): 549 // 528 // 550 // 3) The particle has reached a boundary of t 529 // 3) The particle has reached a boundary of the current 551 // volume, exiting into a volume which is 530 // volume, exiting into a volume which is not in its 552 // parental hierarchy: 531 // parental hierarchy: 553 // 532 // 554 // 4) The particle is not on a boundary betwee 533 // 4) The particle is not on a boundary between volumes: 555 // the function returns an exception, and 534 // the function returns an exception, and the caller is 556 // reccomended to compare the G4touchables 535 // reccomended to compare the G4touchables associated 557 // to the preStepPoint and postStepPoint t 536 // to the preStepPoint and postStepPoint to handle this case. 558 // 537 // 559 // G4bool EnteredDaughterVolume() 538 // G4bool EnteredDaughterVolume() 560 // G4bool IsExitNormalValid() 539 // G4bool IsExitNormalValid() 561 // G4ThreeVector GetLocalExitNormal() 540 // G4ThreeVector GetLocalExitNormal() 562 // 541 // 563 // The expected usefulness of these methods is 542 // The expected usefulness of these methods is to allow the caller to 564 // determine how to compute the surface normal 543 // determine how to compute the surface normal at the volume boundary. The two 565 // possibilities are to obtain the normal from 544 // possibilities are to obtain the normal from: 566 // 545 // 567 // i) the solid associated with the volume o 546 // i) the solid associated with the volume of the initial point of the Step. 568 // This is valid for cases 2 and 3. 547 // This is valid for cases 2 and 3. 569 // (Note that the initial point is genera 548 // (Note that the initial point is generally the PreStepPoint of a Step). 570 // or 549 // or 571 // 550 // 572 // ii) the solid of the final point, ie of th 551 // ii) the solid of the final point, ie of the volume after the relocation. 573 // This is valid for case 1. 552 // This is valid for case 1. 574 // (Note that the final point is generall 553 // (Note that the final point is generally the PreStepPoint of a Step). 575 // 554 // 576 // This way the caller can always get a valid 555 // This way the caller can always get a valid normal, pointing outside 577 // the solid for which it is computed, that ca 556 // the solid for which it is computed, that can be used at his own 578 // discretion. 557 // discretion. 579 558