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 // class G4ErrorPropagationNavigator implement 26 // class G4ErrorPropagationNavigator implementation 27 // 27 // 28 // Author: Pedro Arce, CIEMAT 28 // Author: Pedro Arce, CIEMAT 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4ErrorPropagationNavigator.hh" 31 #include "G4ErrorPropagationNavigator.hh" 32 32 33 #include "globals.hh" 33 #include "globals.hh" 34 #include "G4ThreeVector.hh" 34 #include "G4ThreeVector.hh" 35 #include "G4ErrorPropagatorData.hh" 35 #include "G4ErrorPropagatorData.hh" 36 #include "G4ErrorSurfaceTarget.hh" 36 #include "G4ErrorSurfaceTarget.hh" 37 37 38 #include "G4ErrorPlaneSurfaceTarget.hh" 38 #include "G4ErrorPlaneSurfaceTarget.hh" 39 #include "G4ErrorCylSurfaceTarget.hh" 39 #include "G4ErrorCylSurfaceTarget.hh" 40 40 >> 41 >> 42 //------------------------------------------------------------------- >> 43 >> 44 G4ErrorPropagationNavigator::G4ErrorPropagationNavigator() >> 45 { >> 46 } >> 47 >> 48 //------------------------------------------------------------------- >> 49 >> 50 G4ErrorPropagationNavigator::~G4ErrorPropagationNavigator() = default; >> 51 >> 52 //------------------------------------------------------------------- >> 53 41 G4double G4ErrorPropagationNavigator:: 54 G4double G4ErrorPropagationNavigator:: 42 ComputeStep ( const G4ThreeVector &pGlobalPoin 55 ComputeStep ( const G4ThreeVector &pGlobalPoint, 43 const G4ThreeVector &pDirection, 56 const G4ThreeVector &pDirection, 44 const G4double pCurrentProposedS 57 const G4double pCurrentProposedStepLength, 45 G4double &pNewSafety ) 58 G4double &pNewSafety ) 46 { 59 { 47 G4double safetyGeom = DBL_MAX; 60 G4double safetyGeom = DBL_MAX; 48 61 49 G4double Step = G4Navigator::ComputeStep(pGl 62 G4double Step = G4Navigator::ComputeStep(pGlobalPoint, pDirection, 50 pCu 63 pCurrentProposedStepLength, 51 saf 64 safetyGeom); 52 65 53 G4ErrorPropagatorData* g4edata 66 G4ErrorPropagatorData* g4edata 54 = G4ErrorPropagatorData::GetErrorPropagato 67 = G4ErrorPropagatorData::GetErrorPropagatorData(); 55 68 56 if ( g4edata != nullptr ) 69 if ( g4edata != nullptr ) 57 { 70 { 58 const G4ErrorTarget* target = g4edata->Get 71 const G4ErrorTarget* target = g4edata->GetTarget(); 59 if( target != nullptr ) 72 if( target != nullptr ) 60 { 73 { 61 G4double StepPlane=target->GetDistanceFr 74 G4double StepPlane=target->GetDistanceFromPoint(pGlobalPoint,pDirection); 62 75 63 if( StepPlane < 0. ) // Negative means t 76 if( StepPlane < 0. ) // Negative means target is crossed, 64 { // will not be foun 77 { // will not be found 65 StepPlane = DBL_MAX; 78 StepPlane = DBL_MAX; 66 } 79 } 67 #ifdef G4VERBOSE 80 #ifdef G4VERBOSE 68 if( G4ErrorPropagatorData::verbose() >= 81 if( G4ErrorPropagatorData::verbose() >= 4 ) 69 { 82 { 70 G4cout << "G4ErrorPropagationNavigator 83 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl 71 << " Target step: " << StepPla 84 << " Target step: " << StepPlane 72 << ", Transportation step: " << 85 << ", Transportation step: " << Step << G4endl; 73 target->Dump( "G4ErrorPropagationNavig 86 target->Dump( "G4ErrorPropagationNavigator::ComputeStep Target " ); 74 } 87 } 75 #endif 88 #endif 76 89 77 if( StepPlane < Step ) 90 if( StepPlane < Step ) 78 { 91 { 79 #ifdef G4VERBOSE 92 #ifdef G4VERBOSE 80 if( G4ErrorPropagatorData::verbose() > 93 if( G4ErrorPropagatorData::verbose() >= 2 ) 81 { 94 { 82 G4cout << "G4ErrorPropagationNavigat 95 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl 83 << " TargetCloserThanBoundar 96 << " TargetCloserThanBoundary: " << StepPlane << " < " 84 << Step << G4endl; 97 << Step << G4endl; 85 } 98 } 86 #endif 99 #endif 87 Step = StepPlane; 100 Step = StepPlane; 88 g4edata->SetState(G4ErrorState_TargetC 101 g4edata->SetState(G4ErrorState_TargetCloserThanBoundary); 89 } 102 } 90 else 103 else 91 { 104 { 92 g4edata->SetState(G4ErrorState_Propaga 105 g4edata->SetState(G4ErrorState_Propagating); 93 } 106 } 94 } 107 } 95 } 108 } 96 G4double safetyTarget = TargetSafetyFromPoin 109 G4double safetyTarget = TargetSafetyFromPoint(pGlobalPoint); 97 110 98 // Avoid call to G4Navigator::ComputeSafety 111 // Avoid call to G4Navigator::ComputeSafety - which could have side effects 99 // 112 // 100 pNewSafety = std::min(safetyGeom, safetyTarg 113 pNewSafety = std::min(safetyGeom, safetyTarget); 101 114 102 #ifdef G4VERBOSE 115 #ifdef G4VERBOSE 103 if( G4ErrorPropagatorData::verbose() >= 3 ) 116 if( G4ErrorPropagatorData::verbose() >= 3 ) 104 { 117 { 105 G4cout << "G4ErrorPropagationNavigator::Co 118 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl 106 << " Step: " << Step << ", Compute 119 << " Step: " << Step << ", ComputeSafety: " << pNewSafety 107 << G4endl; 120 << G4endl; 108 } 121 } 109 #endif 122 #endif 110 123 111 return Step; 124 return Step; 112 } 125 } 113 126 114 //-------------------------------------------- 127 //------------------------------------------------------------------- 115 128 116 G4double G4ErrorPropagationNavigator:: 129 G4double G4ErrorPropagationNavigator:: 117 TargetSafetyFromPoint( const G4ThreeVector& pG 130 TargetSafetyFromPoint( const G4ThreeVector& pGlobalpoint ) 118 { 131 { 119 G4double safety = DBL_MAX; 132 G4double safety = DBL_MAX; 120 133 121 G4ErrorPropagatorData* g4edata 134 G4ErrorPropagatorData* g4edata 122 = G4ErrorPropagatorData::GetErrorPropagato 135 = G4ErrorPropagatorData::GetErrorPropagatorData(); 123 136 124 if ( g4edata != nullptr ) 137 if ( g4edata != nullptr ) 125 { 138 { 126 const G4ErrorTarget* target = g4edata->Get 139 const G4ErrorTarget* target = g4edata->GetTarget(); 127 if( target != nullptr ) 140 if( target != nullptr ) 128 { 141 { 129 safety = target->GetDistanceFromPoint(p 142 safety = target->GetDistanceFromPoint(pGlobalpoint); 130 } 143 } 131 } 144 } 132 return safety; 145 return safety; 133 } 146 } 134 147 135 //-------------------------------------------- 148 //------------------------------------------------------------------- 136 149 137 G4double G4ErrorPropagationNavigator:: 150 G4double G4ErrorPropagationNavigator:: 138 ComputeSafety( const G4ThreeVector &pGlobalPoi 151 ComputeSafety( const G4ThreeVector &pGlobalPoint, 139 const G4double pMaxLength, 152 const G4double pMaxLength, 140 const G4bool keepState ) 153 const G4bool keepState ) 141 { 154 { 142 G4double safetyGeom = G4Navigator::ComputeSa 155 G4double safetyGeom = G4Navigator::ComputeSafety(pGlobalPoint, 143 156 pMaxLength, keepState); 144 157 145 G4double safetyTarget = TargetSafetyFromPoin 158 G4double safetyTarget = TargetSafetyFromPoint( pGlobalPoint ); 146 159 147 return std::min(safetyGeom, safetyTarget); 160 return std::min(safetyGeom, safetyTarget); 148 } 161 } 149 162 150 //-------------------------------------------- 163 //------------------------------------------------------------------- 151 164 152 G4ThreeVector G4ErrorPropagationNavigator:: 165 G4ThreeVector G4ErrorPropagationNavigator:: 153 GetGlobalExitNormal( const G4ThreeVector& poin 166 GetGlobalExitNormal( const G4ThreeVector& point, G4bool* valid ) 154 { 167 { 155 G4ErrorPropagatorData* g4edata 168 G4ErrorPropagatorData* g4edata 156 = G4ErrorPropagatorData::GetErrorPropa 169 = G4ErrorPropagatorData::GetErrorPropagatorData(); 157 const G4ErrorTarget* target = nullptr; 170 const G4ErrorTarget* target = nullptr; 158 171 159 G4ThreeVector normal(0.0, 0.0, 0.0); 172 G4ThreeVector normal(0.0, 0.0, 0.0); 160 G4double distance= 0; 173 G4double distance= 0; 161 174 162 // Determine which 'geometry' limited the st 175 // Determine which 'geometry' limited the step 163 if ( g4edata != nullptr ) 176 if ( g4edata != nullptr ) 164 { 177 { 165 target = g4edata->GetTarget(); 178 target = g4edata->GetTarget(); 166 if( target != nullptr ) 179 if( target != nullptr ) 167 { 180 { 168 distance = target->GetDistanceFromPoint( 181 distance = target->GetDistanceFromPoint(point); 169 } 182 } 170 } 183 } 171 184 172 if( distance > kCarTolerance || (target == n 185 if( distance > kCarTolerance || (target == nullptr) ) 173 // Not reached the target or if a target d 186 // Not reached the target or if a target does not exist, 174 // this seems the best we can do 187 // this seems the best we can do 175 { 188 { 176 normal = G4Navigator::GetGlobalExitNormal( 189 normal = G4Navigator::GetGlobalExitNormal(point, valid); 177 } 190 } 178 else 191 else 179 { 192 { 180 switch( target->GetType() ) 193 switch( target->GetType() ) 181 { 194 { 182 case G4ErrorTarget_GeomVolume: 195 case G4ErrorTarget_GeomVolume: 183 // The volume is in the 'real' mass ge 196 // The volume is in the 'real' mass geometry 184 normal = G4Navigator::GetGlobalExitNor 197 normal = G4Navigator::GetGlobalExitNormal(point, valid); 185 break; 198 break; 186 case G4ErrorTarget_TrkL: 199 case G4ErrorTarget_TrkL: 187 normal = G4ThreeVector( 0.0, 0.0, 0.0) 200 normal = G4ThreeVector( 0.0, 0.0, 0.0); 188 *valid = false; 201 *valid = false; 189 G4Exception("G4ErrorPropagationNavigat 202 G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal", 190 "Geometry1003", 203 "Geometry1003", 191 JustWarning, "Unexpected v 204 JustWarning, "Unexpected value of Target type"); 192 break; 205 break; 193 case G4ErrorTarget_PlaneSurface: 206 case G4ErrorTarget_PlaneSurface: 194 case G4ErrorTarget_CylindricalSurface: 207 case G4ErrorTarget_CylindricalSurface: 195 const auto surfTarget= static_cast<con 208 const auto surfTarget= static_cast<const G4ErrorSurfaceTarget*>(target); 196 normal = surfTarget->GetTangentPlane(p 209 normal = surfTarget->GetTangentPlane(point).normal().unit(); 197 *valid = true; 210 *valid = true; 198 break; 211 break; 199 212 200 // default: 213 // default: 201 // normal= G4ThreeVector( 0.0, 0.0, 0.0 214 // normal= G4ThreeVector( 0.0, 0.0, 0.0 ); 202 // *valid = false; 215 // *valid = false; 203 // G4Exception("G4ErrorPropagationNavig 216 // G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal", 204 // "Geometry:003", 217 // "Geometry:003", 205 // FatalException, "Impossi 218 // FatalException, "Impossible value of Target type"); 206 // break; 219 // break; 207 } 220 } 208 } 221 } 209 return normal; 222 return normal; 210 } 223 } 211 224 212 225