Geant4-11
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
45 : G4Navigator()
46{
47}
48
49//-------------------------------------------------------------------
50
52{
53}
54
55//-------------------------------------------------------------------
56
58ComputeStep ( const G4ThreeVector &pGlobalPoint,
59 const G4ThreeVector &pDirection,
60 const G4double pCurrentProposedStepLength,
61 G4double &pNewSafety )
62{
63 G4double safetyGeom = DBL_MAX;
64
65 G4double Step = G4Navigator::ComputeStep(pGlobalPoint, pDirection,
66 pCurrentProposedStepLength,
67 safetyGeom);
68
71
72 if ( g4edata != nullptr )
73 {
74 const G4ErrorTarget* target = g4edata->GetTarget();
75 if( target != nullptr )
76 {
77 G4double StepPlane=target->GetDistanceFromPoint(pGlobalPoint,pDirection);
78
79 if( StepPlane < 0. ) // Negative means target is crossed,
80 { // will not be found
81 StepPlane = DBL_MAX;
82 }
83#ifdef G4VERBOSE
85 {
86 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
87 << " Target step: " << StepPlane
88 << ", Transportation step: " << Step << G4endl;
89 target->Dump( "G4ErrorPropagationNavigator::ComputeStep Target " );
90 }
91#endif
92
93 if( StepPlane < Step )
94 {
95#ifdef G4VERBOSE
97 {
98 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
99 << " TargetCloserThanBoundary: " << StepPlane << " < "
100 << Step << G4endl;
101 }
102#endif
103 Step = StepPlane;
105 }
106 else
107 {
109 }
110 }
111 }
112 G4double safetyTarget = TargetSafetyFromPoint(pGlobalPoint);
113
114 // Avoid call to G4Navigator::ComputeSafety - which could have side effects
115 //
116 pNewSafety = std::min(safetyGeom, safetyTarget);
117
118#ifdef G4VERBOSE
120 {
121 G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
122 << " Step: " << Step << ", ComputeSafety: " << pNewSafety
123 << G4endl;
124 }
125#endif
126
127 return Step;
128}
129
130//-------------------------------------------------------------------
131
133TargetSafetyFromPoint( const G4ThreeVector& pGlobalpoint )
134{
135 G4double safety = DBL_MAX;
136
137 G4ErrorPropagatorData* g4edata
139
140 if ( g4edata != nullptr )
141 {
142 const G4ErrorTarget* target = g4edata->GetTarget();
143 if( target != nullptr )
144 {
145 safety = target->GetDistanceFromPoint(pGlobalpoint);
146 }
147 }
148 return safety;
149}
150
151//-------------------------------------------------------------------
152
154ComputeSafety( const G4ThreeVector &pGlobalPoint,
155 const G4double pMaxLength,
156 const G4bool keepState )
157{
158 G4double safetyGeom = G4Navigator::ComputeSafety(pGlobalPoint,
159 pMaxLength, keepState);
160
161 G4double safetyTarget = TargetSafetyFromPoint( pGlobalPoint );
162
163 return std::min(safetyGeom, safetyTarget);
164}
165
166//-------------------------------------------------------------------
167
169GetGlobalExitNormal( const G4ThreeVector& point, G4bool* valid )
170{
171 G4ErrorPropagatorData* g4edata
173 const G4ErrorTarget* target = nullptr;
174
175 G4ThreeVector normal(0.0, 0.0, 0.0);
176 G4double distance= 0;
177
178 // Determine which 'geometry' limited the step
179 if ( g4edata != nullptr )
180 {
181 target = g4edata->GetTarget();
182 if( target != nullptr )
183 {
184 distance = target->GetDistanceFromPoint(point);
185 }
186 }
187
188 if( distance > kCarTolerance || (target == nullptr) )
189 // Not reached the target or if a target does not exist,
190 // this seems the best we can do
191 {
193 }
194 else
195 {
196 switch( target->GetType() )
197 {
199 // The volume is in the 'real' mass geometry
201 break;
203 normal = G4ThreeVector( 0.0, 0.0, 0.0);
204 *valid = false;
205 G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal",
206 "Geometry1003",
207 JustWarning, "Unexpected value of Target type");
208 break;
211 const G4ErrorSurfaceTarget* surfaceTarget=
212 static_cast<const G4ErrorSurfaceTarget*>(target);
213 normal = surfaceTarget->GetTangentPlane(point).normal().unit();
214 *valid = true;
215 break;
216
217// default:
218// normal= G4ThreeVector( 0.0, 0.0, 0.0 );
219// *valid = false;
220// G4Exception("G4ErrorPropagationNavigator::GetGlobalExitNormal",
221// "Geometry:003",
222// FatalException, "Impossible value of Target type");
223// break;
224 }
225 }
226 return normal;
227}
228
@ 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)
Definition: G4Exception.cc:35
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
G4double TargetSafetyFromPoint(const G4ThreeVector &pGlobalpoint)
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid)
static G4ErrorPropagatorData * GetErrorPropagatorData()
const G4ErrorTarget * GetTarget(G4bool mustExist=false) const
void SetState(G4ErrorState sta)
virtual G4Plane3D GetTangentPlane(const G4ThreeVector &point) const =0
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
Definition: G4Navigator.hh:377
virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
Definition: G4Navigator.cc:770
Normal3D< T > normal() const
Definition: Plane3D.h:97
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:79
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
#define DBL_MAX
Definition: templates.hh:62