Files
geant4/source/geometry/navigation/include/G4VIntersectionLocator.icc
2025-06-26 09:17:29 +02:00

170 lines
5.5 KiB
Plaintext

//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// Class G4VIntersectionLocator inline methods implementation
//
// Authors: John Apostolakis, Tatiana Nikitina (CERN), 27 October 2008
// --------------------------------------------------------------------
inline G4double G4VIntersectionLocator::GetDeltaIntersectionFor()
{
return fiDeltaIntersection;
}
inline G4double G4VIntersectionLocator::GetEpsilonStepFor()
{
return fiEpsilonStep;
}
inline G4Navigator* G4VIntersectionLocator::GetNavigatorFor()
{
return fiNavigator;
}
inline G4ChordFinder* G4VIntersectionLocator::GetChordFinderFor()
{
return fiChordFinder;
}
inline G4int G4VIntersectionLocator::GetVerboseFor()
{
return fVerboseLevel;
}
inline G4bool G4VIntersectionLocator::GetAdjustementOfFoundIntersection()
{
return fUseNormalCorrection;
}
inline void G4VIntersectionLocator::
AddAdjustementOfFoundIntersection(G4bool UseCorrection )
{
fUseNormalCorrection = UseCorrection;
}
inline void G4VIntersectionLocator::SetEpsilonStepFor( G4double EpsilonStep )
{
fiEpsilonStep = EpsilonStep;
}
inline void G4VIntersectionLocator::
SetDeltaIntersectionFor( G4double deltaIntersection )
{
fiDeltaIntersection = deltaIntersection;
}
inline void G4VIntersectionLocator::SetNavigatorFor( G4Navigator* fNavigator )
{
fiNavigator = fNavigator;
}
inline void G4VIntersectionLocator::SetChordFinderFor(G4ChordFinder* fCFinder )
{
fiChordFinder = fCFinder;
}
inline void G4VIntersectionLocator::SetSafetyParametersFor(G4bool UseSafety )
{
fiUseSafety = UseSafety;
}
inline void G4VIntersectionLocator::SetVerboseFor(G4int fVerbose)
{
fVerboseLevel = fVerbose;
}
inline G4bool
G4VIntersectionLocator::IntersectChord( const G4ThreeVector& StartPointA,
const G4ThreeVector& EndPointB,
G4double& NewSafety,
G4double& PreviousSafety,
G4ThreeVector& PreviousSftOrigin,
G4double& LinearStepLength,
G4ThreeVector& IntersectionPoint,
G4bool* ptrCalledNavigator )
{
G4bool CalledNavigator = false;
// Calculate the direction and length of the chord AB
G4ThreeVector ChordAB_Vector = EndPointB - StartPointA;
G4double ChordAB_Length = ChordAB_Vector.mag(); // Magnitude (norm)
G4ThreeVector ChordAB_Dir = ChordAB_Vector.unit();
G4bool intersects;
G4ThreeVector OriginShift = StartPointA - PreviousSftOrigin ;
G4double MagSqShift = OriginShift.mag2() ;
G4double currentSafety;
if( MagSqShift >= sqr(PreviousSafety) )
{
currentSafety = 0.0 ;
}
else
{
currentSafety = PreviousSafety - std::sqrt(MagSqShift) ;
}
if( fiUseSafety && (ChordAB_Length <= currentSafety) )
{
// The Step is guaranteed to be taken
LinearStepLength = ChordAB_Length;
intersects = false;
NewSafety = currentSafety;
CalledNavigator = false;
}
else
{
// Check whether any volumes are encountered by the chord AB
LinearStepLength = GetNavigatorFor()->ComputeStep( StartPointA,
ChordAB_Dir, ChordAB_Length, NewSafety );
intersects = (LinearStepLength <= ChordAB_Length);
// G4Navigator contracts to return k_infinity if len==asked
// and it did not find a surface boundary at that length
LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
CalledNavigator = true;
// Save the last calculated safety!
PreviousSftOrigin = StartPointA;
PreviousSafety = NewSafety;
if( intersects )
{
// Intersection Point of chord AB and either volume A's surface
// or a daughter volume's surface ..
IntersectionPoint = StartPointA + LinearStepLength * ChordAB_Dir;
}
}
if( ptrCalledNavigator != nullptr )
{
*ptrCalledNavigator = CalledNavigator;
}
return intersects;
}