Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ErrorPropagationNavigator.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// class G4ErrorPropagationNavigator implementation
27//
28// Author: Pedro Arce, CIEMAT
29// --------------------------------------------------------------------
30
32
33#include "globals.hh"
34#include "G4ThreeVector.hh"
37
40
41
42//-------------------------------------------------------------------
43
47
48//-------------------------------------------------------------------
49
51
52//-------------------------------------------------------------------
53
55ComputeStep ( const G4ThreeVector &pGlobalPoint,
56 const G4ThreeVector &pDirection,
57 const G4double pCurrentProposedStepLength,
58 G4double &pNewSafety )
59{
60 G4double safetyGeom = DBL_MAX;
61
62 G4double Step = G4Navigator::ComputeStep(pGlobalPoint, pDirection,
63 pCurrentProposedStepLength,
64 safetyGeom);
65
68
69 if ( g4edata != nullptr )
70 {
71 const G4ErrorTarget* target = g4edata->GetTarget();
72 if( target != nullptr )
73 {
74 G4double StepPlane=target->GetDistanceFromPoint(pGlobalPoint,pDirection);
75
76 if( StepPlane < 0. ) // Negative means target is crossed,
77 { // will not be found
78 StepPlane = DBL_MAX;
79 }
80#ifdef G4VERBOSE
82 {
83 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
84 << " Target step: " << StepPlane
85 << ", Transportation step: " << Step << G4endl;
86 target->Dump( "G4ErrorPropagationNavigator::ComputeStep Target " );
87 }
88#endif
89
90 if( StepPlane < Step )
91 {
92#ifdef G4VERBOSE
94 {
95 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
96 << " TargetCloserThanBoundary: " << StepPlane << " < "
97 << Step << G4endl;
98 }
99#endif
100 Step = StepPlane;
102 }
103 else
104 {
106 }
107 }
108 }
109 G4double safetyTarget = TargetSafetyFromPoint(pGlobalPoint);
110
111 // Avoid call to G4Navigator::ComputeSafety - which could have side effects
112 //
113 pNewSafety = std::min(safetyGeom, safetyTarget);
114
115#ifdef G4VERBOSE
117 {
118 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
119 << " Step: " << Step << ", ComputeSafety: " << pNewSafety
120 << G4endl;
121 }
122#endif
123
124 return Step;
125}
126
127//-------------------------------------------------------------------
128
130TargetSafetyFromPoint( const G4ThreeVector& pGlobalpoint )
131{
132 G4double safety = DBL_MAX;
133
134 G4ErrorPropagatorData* g4edata
136
137 if ( g4edata != nullptr )
138 {
139 const G4ErrorTarget* target = g4edata->GetTarget();
140 if( target != nullptr )
141 {
142 safety = target->GetDistanceFromPoint(pGlobalpoint);
143 }
144 }
145 return safety;
146}
147
148//-------------------------------------------------------------------
149
151ComputeSafety( const G4ThreeVector &pGlobalPoint,
152 const G4double pMaxLength,
153 const G4bool keepState )
154{
155 G4double safetyGeom = G4Navigator::ComputeSafety(pGlobalPoint,
156 pMaxLength, keepState);
157
158 G4double safetyTarget = TargetSafetyFromPoint( pGlobalPoint );
159
160 return std::min(safetyGeom, safetyTarget);
161}
162
163//-------------------------------------------------------------------
164
166GetGlobalExitNormal( const G4ThreeVector& point, G4bool* valid )
167{
168 G4ErrorPropagatorData* g4edata
170 const G4ErrorTarget* target = nullptr;
171
172 G4ThreeVector normal(0.0, 0.0, 0.0);
173 G4double distance= 0;
174
175 // Determine which 'geometry' limited the step
176 if ( g4edata != nullptr )
177 {
178 target = g4edata->GetTarget();
179 if( target != nullptr )
180 {
181 distance = target->GetDistanceFromPoint(point);
182 }
183 }
184
185 if( distance > kCarTolerance || (target == nullptr) )
186 // Not reached the target or if a target does not exist,
187 // this seems the best we can do
188 {
189 normal = G4Navigator::GetGlobalExitNormal(point, valid);
190 }
191 else
192 {
193 switch( target->GetType() )
194 {
196 // The volume is in the 'real' mass geometry
197 normal = G4Navigator::GetGlobalExitNormal(point, valid);
198 break;
200 normal = G4ThreeVector( 0.0, 0.0, 0.0);
201 *valid = false;
202 G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal",
203 "Geometry1003",
204 JustWarning, "Unexpected value of Target type");
205 break;
208 const auto surfTarget= static_cast<const G4ErrorSurfaceTarget*>(target);
209 normal = surfTarget->GetTangentPlane(point).normal().unit();
210 *valid = true;
211 break;
212
213// default:
214// normal= G4ThreeVector( 0.0, 0.0, 0.0 );
215// *valid = false;
216// G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal",
217// "Geometry:003",
218// FatalException, "Impossible value of Target type");
219// break;
220 }
221 }
222 return normal;
223}
224
@ G4ErrorState_TargetCloserThanBoundary
@ G4ErrorState_Propagating
@ G4ErrorTarget_PlaneSurface
@ G4ErrorTarget_CylindricalSurface
@ G4ErrorTarget_GeomVolume
@ G4ErrorTarget_TrkL
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
Hep3Vector unit() const
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety) override
G4double TargetSafetyFromPoint(const G4ThreeVector &pGlobalpoint)
G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid) override
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true) override
~G4ErrorPropagationNavigator() override
static G4ErrorPropagatorData * GetErrorPropagatorData()
const G4ErrorTarget * GetTarget(G4bool mustExist=false) const
void SetState(G4ErrorState sta)
virtual void Dump(const G4String &msg) const =0
G4ErrorTargetType GetType() const
virtual G4double GetDistanceFromPoint(const G4ThreeVector &, const G4ThreeVector &) const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
G4double kCarTolerance
virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
#define DBL_MAX
Definition templates.hh:62