|
||||
File indexing completed on 2025-01-18 09:59:04
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4SafetyCalculator 0027 // 0028 // Class description: 0029 // 0030 // A class that provides an estimate of the isotropic safety - the 0031 // minimum distance from a global point to the nearest boundary 0032 // of the current volume or the nearest daughter volumes. 0033 // This estimate can be an underestimate, either because a solid 0034 // provides an underestimate (for speed) or in order to avoid 0035 // substantial additional computations. 0036 // 0037 // Obtains from the navigator the current transformation history. 0038 0039 // Author: John Apostolakis, CERN - February 2023 0040 // -------------------------------------------------------------------- 0041 #ifndef G4SafetyCalculator_HH 0042 #define G4SafetyCalculator_HH 1 0043 0044 #include "geomdefs.hh" 0045 0046 #include "G4ThreeVector.hh" 0047 #include "G4AffineTransform.hh" 0048 #include "G4RotationMatrix.hh" 0049 0050 #include "G4LogicalVolume.hh" // Used in inline methods 0051 #include "G4TouchableHistoryHandle.hh" 0052 0053 #include "G4NavigationHistory.hh" 0054 #include "G4NormalNavigation.hh" 0055 #include "G4VoxelNavigation.hh" 0056 #include "G4ParameterisedNavigation.hh" 0057 #include "G4ReplicaNavigation.hh" 0058 #include "G4RegularNavigation.hh" 0059 #include "G4VExternalNavigation.hh" 0060 0061 #include "G4VoxelSafety.hh" 0062 0063 #include <iostream> 0064 0065 class G4VPhysicalVolume; 0066 0067 class G4SafetyCalculator 0068 { 0069 public: 0070 0071 G4SafetyCalculator( const G4Navigator& navigator, 0072 const G4NavigationHistory& navHistory ); 0073 // Constructor - initialisers and setup. 0074 0075 G4SafetyCalculator(const G4SafetyCalculator&) = delete; 0076 G4SafetyCalculator& operator=(const G4SafetyCalculator&) = delete; 0077 // Copy constructor & assignment operator not allowed. 0078 0079 ~G4SafetyCalculator() = default; 0080 // Destructor. No actions. 0081 0082 G4double SafetyInCurrentVolume(const G4ThreeVector& globalpoint, 0083 G4VPhysicalVolume* physicalVolume, 0084 const G4double pProposedMaxLength = DBL_MAX, 0085 G4bool verbose = false ); 0086 // Calculate the isotropic distance to the nearest boundary from the 0087 // specified point in the global coordinate system. 0088 // The globalpoint utilised *must* be located exactly within the 0089 // current volume (it also must *not* be in a daughter volume). 0090 // The value returned can be an underestimate (and typically will be 0091 // if complex volumes are involved). 0092 // The calculation will not look beyond the proposed maximum length 0093 // to avoid extra volume safety calculations. The geometry must be closed. 0094 0095 G4VExternalNavigation* GetExternalNavigation() const; 0096 void SetExternalNavigation(G4VExternalNavigation* externalNav); 0097 // Accessor & modifier for custom external navigation. 0098 0099 void CompareSafetyValues( G4double oldSafety, 0100 G4double newValue, 0101 G4VPhysicalVolume* motherPhysical, 0102 const G4ThreeVector &globalPoint, 0103 G4bool keepState, 0104 G4double maxLength, 0105 G4bool enteredVolume, 0106 G4bool exitedVolume ); 0107 // Compare estimates of the safety, and report if difference(s) found. 0108 0109 protected: 0110 0111 void QuickLocateWithinVolume(const G4ThreeVector& pointLocal, 0112 G4VPhysicalVolume* motherPhysical); 0113 // Prepare state of sub-navigators by informing them of current point. 0114 0115 inline G4ThreeVector ComputeLocalPoint(const G4ThreeVector& rGlobPoint) const; 0116 // Return position vector in local coordinate system, given a position 0117 // vector in world coordinate system. 0118 0119 inline G4ThreeVector ComputeLocalAxis(const G4ThreeVector& pVec) const; 0120 // Return the local direction of the specified vector in the reference 0121 // system of the volume that was found by LocalGlobalPointAndSetup(). 0122 // The Local Coordinates of point in world coordinate system. 0123 0124 inline EVolume CharacteriseDaughters(const G4LogicalVolume* pLog) const; 0125 // Characterise daughter of logical volume. 0126 0127 inline G4int GetDaughtersRegularStructureId(const G4LogicalVolume* pLv) const; 0128 // Get regular structure ID of first daughter. 0129 0130 private: 0131 0132 // BEGIN -- Tracking Invariants part 1 0133 // 0134 const G4Navigator& fNavigator; 0135 // Associated navigator. Needed for details of current state, 0136 // for optimisation 0137 0138 const G4NavigationHistory& fNavHistory; 0139 // Associated navigator's navigation history. Transformation and history 0140 // of the current path through the geometrical hierarchy. 0141 // 0142 // END -- Tracking Invariants part 1 0143 0144 G4double fkCarTolerance; 0145 // Cached tolerance. 0146 0147 // BEGIN State information 0148 // 0149 G4ThreeVector fPreviousSftOrigin; 0150 G4double fPreviousSafety = 0.0; 0151 // Memory of last safety origin & value. Used in ComputeStep to ensure 0152 // that origin of current Step is in the same volume as the point of the 0153 // last relocation. 0154 0155 // Helpers/Utility classes - their state can change 0156 // 0157 G4NormalNavigation fnormalNav; 0158 G4VoxelNavigation fvoxelNav; 0159 G4ParameterisedNavigation fparamNav; 0160 G4ReplicaNavigation freplicaNav; 0161 G4RegularNavigation fregularNav; 0162 G4VExternalNavigation* fpExternalNav = nullptr; 0163 G4VoxelSafety fVoxelSafety; 0164 }; 0165 0166 // Auxiliary inline methods -- copied from G4Navigator 0167 0168 // Return local coordinates given point in the world coord system. 0169 // 0170 inline G4ThreeVector 0171 G4SafetyCalculator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const 0172 { 0173 return fNavHistory.GetTopTransform().TransformPoint(pGlobalPoint); 0174 } 0175 0176 // Returns local direction given vector direction in world coord system. 0177 // 0178 inline G4ThreeVector 0179 G4SafetyCalculator::ComputeLocalAxis(const G4ThreeVector& pVec) const 0180 { 0181 return fNavHistory.GetTopTransform().TransformAxis(pVec); 0182 } 0183 0184 inline EVolume 0185 G4SafetyCalculator::CharacteriseDaughters(const G4LogicalVolume* pLog) const 0186 { 0187 return pLog->CharacteriseDaughters(); 0188 } 0189 0190 inline G4int 0191 G4SafetyCalculator::GetDaughtersRegularStructureId(const G4LogicalVolume* pLog) const 0192 { 0193 G4int regId = 0; 0194 G4VPhysicalVolume *pVol; 0195 0196 if ( pLog->GetNoDaughters() == 1 ) 0197 { 0198 pVol = pLog->GetDaughter(0); 0199 regId = pVol->GetRegularStructureId(); 0200 } 0201 return regId; 0202 } 0203 0204 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |