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

501 lines
15 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. *
// ********************************************************************
//
// G4Navigator class Inline implementation
//
// Author: Paul Kent (CERN), July 1995-1996
// --------------------------------------------------------------------
// ********************************************************************
// GetCurrentLocalCoordinate
//
// Returns the local coordinate of the current track
// ********************************************************************
//
inline
G4ThreeVector G4Navigator::GetCurrentLocalCoordinate() const
{
return fLastLocatedPointLocal;
}
// ********************************************************************
// ComputeLocalAxis
//
// Returns local direction of vector direction in world coord system
// ********************************************************************
//
inline
G4ThreeVector G4Navigator::ComputeLocalAxis(const G4ThreeVector& pVec) const
{
return fHistory.GetTopTransform().TransformAxis(pVec);
}
// ********************************************************************
// ComputeLocalPoint
//
// Returns local coordinates of a point in the world coord system
// ********************************************************************
//
inline
G4ThreeVector
G4Navigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
{
return fHistory.GetTopTransform().TransformPoint(pGlobalPoint);
}
// ********************************************************************
// GetWorldVolume
//
// Returns the current world (`topmost') volume
// ********************************************************************
//
inline
G4VPhysicalVolume* G4Navigator::GetWorldVolume() const
{
return fTopPhysical;
}
// ********************************************************************
// SetWorldVolume
//
// Sets the world (`topmost') volume
// ********************************************************************
//
inline
void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
{
if ( !(pWorld->GetTranslation() == G4ThreeVector(0,0,0)) )
{
G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
FatalException, "Volume must be centered on the origin.");
}
const G4RotationMatrix* rm = pWorld->GetRotation();
if ( (rm != nullptr) && (!rm->isIdentity()) )
{
G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
FatalException, "Volume must not be rotated.");
}
fTopPhysical = pWorld;
fHistory.SetFirstEntry(pWorld);
}
// ********************************************************************
// SetGeometrycallyLimitedStep
//
// Informs the navigator that the previous Step calculated
// by the geometry was taken in its entirety
// ********************************************************************
//
inline
void G4Navigator::SetGeometricallyLimitedStep()
{
fWasLimitedByGeometry = true;
}
// ********************************************************************
// ResetStackAndState
//
// Resets stack and minimum of navigator state `machine'
// ********************************************************************
//
inline
void G4Navigator::ResetStackAndState()
{
fHistory.Reset();
ResetState();
}
// ********************************************************************
// VolumeType
// ********************************************************************
//
inline
EVolume G4Navigator::VolumeType(const G4VPhysicalVolume *pVol) const
{
return pVol->VolumeType();
}
// ********************************************************************
// CharacteriseDaughters
// ********************************************************************
//
inline
EVolume G4Navigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
{
return pLog->CharacteriseDaughters();
}
// ********************************************************************
// GetDaughtersRegularStructureId
// ********************************************************************
//
inline
G4int G4Navigator::
GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
{
G4int regId = 0;
G4VPhysicalVolume *pVol;
if ( pLog->GetNoDaughters() == 1 )
{
pVol = pLog->GetDaughter(0);
regId = pVol->GetRegularStructureId();
}
return regId;
}
// ********************************************************************
// GetGlobalToLocalTransform
//
// Returns local to global transformation.
// I.e. transformation that will take point or axis in world coord system
// and return one in the local coord system
// ********************************************************************
//
inline
const G4AffineTransform& G4Navigator::GetGlobalToLocalTransform() const
{
return fHistory.GetTopTransform();
}
// ********************************************************************
// GetLocalToGlobalTransform
//
// Returns global to local transformation
// ********************************************************************
//
inline
const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
{
return fHistory.GetTopTransform().Inverse();
}
// ********************************************************************
// NetTranslation
//
// Computes+returns the local->global translation of current volume
// ********************************************************************
//
inline
G4ThreeVector G4Navigator::NetTranslation() const
{
return fHistory.GetTopTransform().InverseNetTranslation();
}
// ********************************************************************
// NetRotation
//
// Computes+returns the local->global rotation of current volume
// ********************************************************************
//
inline
G4RotationMatrix G4Navigator::NetRotation() const
{
return fHistory.GetTopTransform().InverseNetRotation();
}
// ********************************************************************
// CreateTouchableHistory
//
// `Touchable' creation method: caller has deletion responsibility
// ********************************************************************
//
inline
G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
{
return new G4TouchableHistory(fHistory);
}
// ********************************************************************
// CreateTouchableHistory(history)
//
// `Touchable' creation method: caller has deletion responsibility
// ********************************************************************
//
inline
G4TouchableHistory*
G4Navigator::CreateTouchableHistory(const G4NavigationHistory* history) const
{
return new G4TouchableHistory(*history);
}
// ********************************************************************
// LocateGlobalPointAndUpdateTouchableHandle
// ********************************************************************
//
inline
void G4Navigator::LocateGlobalPointAndUpdateTouchableHandle(
const G4ThreeVector& position,
const G4ThreeVector& direction,
G4TouchableHandle& oldTouchableToUpdate,
const G4bool RelativeSearch )
{
G4VPhysicalVolume* pPhysVol;
pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
if( fEnteredDaughter || fExitedMother )
{
oldTouchableToUpdate = CreateTouchableHistory();
if( pPhysVol == nullptr )
{
// We want to ensure that the touchable is correct in this case.
// The method below should do this and recalculate a lot more ....
//
oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
}
}
return;
}
// ********************************************************************
// LocateGlobalPointAndUpdateTouchable
//
// Use direction
// ********************************************************************
//
inline
void G4Navigator::LocateGlobalPointAndUpdateTouchable(
const G4ThreeVector& position,
const G4ThreeVector& direction,
G4VTouchable* touchableToUpdate,
const G4bool RelativeSearch )
{
G4VPhysicalVolume* pPhysVol;
pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
}
// ********************************************************************
// LocateGlobalPointAndUpdateTouchable
// ********************************************************************
//
inline
void G4Navigator::LocateGlobalPointAndUpdateTouchable(
const G4ThreeVector& position,
G4VTouchable* touchableToUpdate,
const G4bool RelativeSearch )
{
G4VPhysicalVolume* pPhysVol;
pPhysVol = LocateGlobalPointAndSetup( position, nullptr, RelativeSearch);
touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
}
// ********************************************************************
// GetVerboseLevel
// ********************************************************************
//
inline
G4int G4Navigator::GetVerboseLevel() const
{
return fVerbose;
}
// ********************************************************************
// SetVerboseLevel
// ********************************************************************
//
inline
void G4Navigator::SetVerboseLevel(G4int level)
{
fVerbose = level;
fnormalNav.SetVerboseLevel(level);
GetVoxelNavigator().SetVerboseLevel(level);
fparamNav.SetVerboseLevel(level);
freplicaNav.SetVerboseLevel(level);
fregularNav.SetVerboseLevel(level);
if (fpExternalNav != nullptr) { fpExternalNav->SetVerboseLevel(level); }
}
// ********************************************************************
// IsActive
// ********************************************************************
//
inline
G4bool G4Navigator::IsActive() const
{
return fActive;
}
// ********************************************************************
// Activate
// ********************************************************************
//
inline
void G4Navigator::Activate(G4bool flag)
{
fActive = flag;
}
// ********************************************************************
// EnteredDaughterVolume
//
// To inform the caller if the track is entering a daughter volume
// ********************************************************************
//
inline
G4bool G4Navigator::EnteredDaughterVolume() const
{
return fEnteredDaughter;
}
// ********************************************************************
// ExitedMotherVolume
// ********************************************************************
//
inline
G4bool G4Navigator::ExitedMotherVolume() const
{
return fExitedMother;
}
// ********************************************************************
// CheckMode
// ********************************************************************
//
inline
void G4Navigator::CheckMode(G4bool mode)
{
fCheck = mode;
fnormalNav.CheckMode(mode);
GetVoxelNavigator().CheckMode(mode);
fparamNav.CheckMode(mode);
freplicaNav.CheckMode(mode);
fregularNav.CheckMode(mode);
if (fpExternalNav != nullptr) { fpExternalNav->CheckMode(mode); }
}
// ********************************************************************
// IsCheckModeActive
// ********************************************************************
//
inline
G4bool G4Navigator::IsCheckModeActive() const
{
return fCheck;
}
// ********************************************************************
// SetPushVerbosity
// ********************************************************************
//
inline
void G4Navigator::SetPushVerbosity(G4bool mode)
{
fWarnPush = mode;
}
// ********************************************************************
// SeverityOfZeroStepping
//
// Reports on severity of error in case Navigator is stuck
// and is returning zero steps
// ********************************************************************
//
inline
G4int G4Navigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const
{
G4int severity = 0, noZeros = fNumberZeroSteps;
if( noZeroSteps != nullptr )
{
*noZeroSteps = fNumberZeroSteps;
}
if( noZeros >= fAbandonThreshold_NoZeroSteps )
{
severity = 10;
}
if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
{
severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
}
else if( noZeros == fActionThreshold_NoZeroSteps )
{
severity = 5;
}
else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
{
severity = 9;
}
else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
{
severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
/ fActionThreshold_NoZeroSteps;
}
return severity;
}
// ********************************************************************
// GetVoxelNavigator
// ********************************************************************
//
inline
G4VoxelNavigation& G4Navigator::GetVoxelNavigator()
{
return *fpvoxelNav;
}
// ********************************************************************
// EnableBestSafety
// ********************************************************************
//
inline void G4Navigator::EnableBestSafety( G4bool value )
{
GetVoxelNavigator().EnableBestSafety( value );
}
// ********************************************************************
// SetExternalNavigation
// ********************************************************************
//
inline
G4VExternalNavigation* G4Navigator::GetExternalNavigation() const
{
return fpExternalNav;
}
// ********************************************************************
// Clone
// ********************************************************************
//
inline
G4Navigator* G4Navigator::Clone() const
{
auto clone_nav = new G4Navigator();
clone_nav->SetWorldVolume(fTopPhysical);
if( fpExternalNav != nullptr )
{
clone_nav->SetExternalNavigation(fpExternalNav->Clone());
}
return clone_nav;
}
// ********************************************************************
// GetLastStepEndPoint
// ********************************************************************
//
inline
G4ThreeVector G4Navigator::GetLastStepEndPoint() const
{
return fStepEndPoint;
}