ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ErrorPropagationNavigator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ErrorPropagationNavigator.cc
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"
35 #include "G4ErrorPropagatorData.hh"
36 #include "G4ErrorSurfaceTarget.hh"
37 
40 
41 
42 //-------------------------------------------------------------------
43 
45  : G4Navigator()
46 {
47 }
48 
49 //-------------------------------------------------------------------
50 
52 {
53 }
54 
55 //-------------------------------------------------------------------
56 
58 ComputeStep ( 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 
69  G4ErrorPropagatorData* g4edata
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
119  if( G4ErrorPropagatorData::verbose() >= 3 )
120  {
121  G4cout << "G4ErrorPropagationNavigator::ComputeStep()" << G4endl
122  << " Step: " << Step << ", ComputeSafety: " << pNewSafety
123  << G4endl;
124  }
125 #endif
126 
127  return Step;
128 }
129 
130 //-------------------------------------------------------------------
131 
133 TargetSafetyFromPoint( 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 
154 ComputeSafety( 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 
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  {
192  normal = G4Navigator::GetGlobalExitNormal(point, valid);
193  }
194  else
195  {
196  switch( target->GetType() )
197  {
199  // The volume is in the 'real' mass geometry
200  normal = G4Navigator::GetGlobalExitNormal(point, valid);
201  break;
202  case G4ErrorTarget_TrkL:
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