2 // ********************************************************************
3 // * License and Disclaimer *
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. *
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. *
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 // ********************************************************************
27 // $Id: G4VIntersectionLocator.icc 66356 2012-12-18 09:02:32Z gcosmo $
30 // Class G4VIntersectionLocator inline methods
32 // 27.10.07 - John Apostolakis, Tatiana Nikitina
33 // ---------------------------------------------------------------------------
35 inline G4double G4VIntersectionLocator::GetDeltaIntersectionFor()
37 return fiDeltaIntersection;
40 inline G4double G4VIntersectionLocator::GetEpsilonStepFor()
45 inline G4Navigator* G4VIntersectionLocator::GetNavigatorFor()
50 inline G4ChordFinder* G4VIntersectionLocator::GetChordFinderFor()
55 inline G4int G4VIntersectionLocator::GetVerboseFor()
60 inline G4bool G4VIntersectionLocator::GetAdjustementOfFoundIntersection()
62 return fUseNormalCorrection;
65 inline void G4VIntersectionLocator::
66 AddAdjustementOfFoundIntersection(G4bool UseCorrection )
68 fUseNormalCorrection=UseCorrection;
71 inline void G4VIntersectionLocator::SetEpsilonStepFor( G4double EpsilonStep )
73 fiEpsilonStep=EpsilonStep;
76 inline void G4VIntersectionLocator::
77 SetDeltaIntersectionFor( G4double deltaIntersection )
79 fiDeltaIntersection=deltaIntersection;
82 inline void G4VIntersectionLocator::SetNavigatorFor( G4Navigator *fNavigator )
84 fiNavigator=fNavigator;
87 inline void G4VIntersectionLocator::SetChordFinderFor(G4ChordFinder *fCFinder )
89 fiChordFinder=fCFinder;
92 inline void G4VIntersectionLocator::SetSafetyParametersFor(G4bool UseSafety )
94 fiUseSafety=UseSafety;
97 inline void G4VIntersectionLocator::SetVerboseFor(G4int fVerbose)
99 fVerboseLevel=fVerbose;
103 G4VIntersectionLocator::IntersectChord( const G4ThreeVector& StartPointA,
104 const G4ThreeVector& EndPointB,
106 G4double &PreviousSafety,
107 G4ThreeVector &PreviousSftOrigin,
108 G4double &LinearStepLength,
109 G4ThreeVector &IntersectionPoint,
110 G4bool *ptrCalledNavigator )
112 G4bool CalledNavigator = false;
114 // Calculate the direction and length of the chord AB
116 G4ThreeVector ChordAB_Vector = EndPointB - StartPointA;
117 G4double ChordAB_Length = ChordAB_Vector.mag(); // Magnitude (norm)
118 G4ThreeVector ChordAB_Dir = ChordAB_Vector.unit();
120 G4ThreeVector OriginShift = StartPointA - PreviousSftOrigin ;
121 G4double MagSqShift = OriginShift.mag2() ;
122 G4double currentSafety;
124 if( MagSqShift >= sqr(PreviousSafety) )
126 currentSafety = 0.0 ;
130 currentSafety = PreviousSafety - std::sqrt(MagSqShift) ;
133 if( fiUseSafety && (ChordAB_Length <= currentSafety) )
135 // The Step is guaranteed to be taken
137 LinearStepLength = ChordAB_Length;
139 NewSafety= currentSafety;
140 CalledNavigator= false;
141 // G4cout << " IntersectChord> Step 'guaranteed' taken: safety= " << currentSafety << " chordAB-len= " << ChordAB_Length << G4endl;
145 // G4cout << " IntersectChord> Step asking Navigator: safety= " << currentSafety << " chordAB-len= " << ChordAB_Length << G4endl;
147 // Check whether any volumes are encountered by the chord AB
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
155 // G4cout << "G4VIntersectionLocator: intersect= " << intersects
156 // << " step= " << LinearStepLength << " Chord length= " << ChordAB_Length;
158 LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
159 CalledNavigator = true;
161 // Save the last calculated safety!
163 PreviousSftOrigin = StartPointA;
164 PreviousSafety = NewSafety;
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;
173 if( ptrCalledNavigator )
175 *ptrCalledNavigator = CalledNavigator;