Geant4  10.00.p03
G4VIntersectionLocator.icc
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 //
27 // $Id: G4VIntersectionLocator.icc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 //
30 // Class G4VIntersectionLocator inline methods
31 //
32 // 27.10.07 - John Apostolakis, Tatiana Nikitina
33 // ---------------------------------------------------------------------------
34 
35 inline G4double G4VIntersectionLocator::GetDeltaIntersectionFor()
36 {
37  return fiDeltaIntersection;
38 }
39 
40 inline G4double G4VIntersectionLocator::GetEpsilonStepFor()
41 {
42  return fiEpsilonStep;
43 }
44 
45 inline G4Navigator* G4VIntersectionLocator::GetNavigatorFor()
46 {
47  return fiNavigator;
48 }
49 
50 inline G4ChordFinder* G4VIntersectionLocator::GetChordFinderFor()
51 {
52  return fiChordFinder;
53 }
54 
55 inline G4int G4VIntersectionLocator::GetVerboseFor()
56 {
57  return fVerboseLevel;
58 }
59 
60 inline G4bool G4VIntersectionLocator::GetAdjustementOfFoundIntersection()
61 {
62  return fUseNormalCorrection;
63 }
64 
65 inline void G4VIntersectionLocator::
66 AddAdjustementOfFoundIntersection(G4bool UseCorrection )
67 {
68  fUseNormalCorrection=UseCorrection;
69 }
70 
71 inline void G4VIntersectionLocator::SetEpsilonStepFor( G4double EpsilonStep )
72 {
73  fiEpsilonStep=EpsilonStep;
74 }
75 
76 inline void G4VIntersectionLocator::
77 SetDeltaIntersectionFor( G4double deltaIntersection )
78 {
79  fiDeltaIntersection=deltaIntersection;
80 }
81 
82 inline void G4VIntersectionLocator::SetNavigatorFor( G4Navigator *fNavigator )
83 {
84  fiNavigator=fNavigator;
85 }
86 
87 inline void G4VIntersectionLocator::SetChordFinderFor(G4ChordFinder *fCFinder )
88 {
89  fiChordFinder=fCFinder;
90 }
91 
92 inline void G4VIntersectionLocator::SetSafetyParametersFor(G4bool UseSafety )
93 {
94  fiUseSafety=UseSafety;
95 }
96 
97 inline void G4VIntersectionLocator::SetVerboseFor(G4int fVerbose)
98 {
99  fVerboseLevel=fVerbose;
100 }
101 
102 inline G4bool
103 G4VIntersectionLocator::IntersectChord( const G4ThreeVector& StartPointA,
104  const G4ThreeVector& EndPointB,
105  G4double &NewSafety,
106  G4double &PreviousSafety,
107  G4ThreeVector &PreviousSftOrigin,
108  G4double &LinearStepLength,
109  G4ThreeVector &IntersectionPoint,
110  G4bool *ptrCalledNavigator )
111 {
112  G4bool CalledNavigator = false;
113 
114  // Calculate the direction and length of the chord AB
115 
116  G4ThreeVector ChordAB_Vector = EndPointB - StartPointA;
117  G4double ChordAB_Length = ChordAB_Vector.mag(); // Magnitude (norm)
118  G4ThreeVector ChordAB_Dir = ChordAB_Vector.unit();
119  G4bool intersects;
120  G4ThreeVector OriginShift = StartPointA - PreviousSftOrigin ;
121  G4double MagSqShift = OriginShift.mag2() ;
122  G4double currentSafety;
123 
124  if( MagSqShift >= sqr(PreviousSafety) )
125  {
126  currentSafety = 0.0 ;
127  }
128  else
129  {
130  currentSafety = PreviousSafety - std::sqrt(MagSqShift) ;
131  }
132 
133  if( fiUseSafety && (ChordAB_Length <= currentSafety) )
134  {
135  // The Step is guaranteed to be taken
136 
137  LinearStepLength = ChordAB_Length;
138  intersects = false;
139  NewSafety= currentSafety;
140  CalledNavigator= false;
141  // G4cout << " IntersectChord> Step 'guaranteed' taken: safety= " << currentSafety << " chordAB-len= " << ChordAB_Length << G4endl;
142  }
143  else
144  {
145  // G4cout << " IntersectChord> Step asking Navigator: safety= " << currentSafety << " chordAB-len= " << ChordAB_Length << G4endl;
146 
147  // Check whether any volumes are encountered by the chord AB
148 
149  LinearStepLength = GetNavigatorFor()->ComputeStep( StartPointA,
150  ChordAB_Dir, ChordAB_Length, NewSafety );
151  intersects = (LinearStepLength <= ChordAB_Length);
152  // G4Navigator contracts to return k_infinity if len==asked
153  // and it did not find a surface boundary at that length
154 
155  // G4cout << "G4VIntersectionLocator: intersect= " << intersects
156  // << " step= " << LinearStepLength << " Chord length= " << ChordAB_Length;
157 
158  LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
159  CalledNavigator = true;
160 
161  // Save the last calculated safety!
162 
163  PreviousSftOrigin = StartPointA;
164  PreviousSafety = NewSafety;
165 
166  if( intersects )
167  {
168  // Intersection Point of chord AB and either volume A's surface
169  // or a daughter volume's surface ..
170  IntersectionPoint = StartPointA + LinearStepLength * ChordAB_Dir;
171  }
172  }
173  if( ptrCalledNavigator )
174  {
175  *ptrCalledNavigator = CalledNavigator;
176  }
177 
178  return intersects;
179 }