Import Geant4 11.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2025-06-26 09:17:29 +02:00
parent 20a218bbe1
commit a499fb82e9
1941 changed files with 203285 additions and 95593 deletions
@@ -23,18 +23,17 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// class G4MultiNavigator
// G4MultiNavigator
//
// Class description:
//
// Utility class for polling the navigators of several geometries to
// identify the next boundary.
// History:
// - Created. John Apostolakis, November 2006
// Author: John Apostolakis (CERN), November 2006
// --------------------------------------------------------------------
#ifndef G4MULTINAVIGATOR_HH
#define G4MULTINAVIGATOR_HH
#define G4MULTINAVIGATOR_HH 1
#include <iostream>
@@ -51,152 +50,243 @@ enum ELimited { kDoNot,kUnique,kSharedTransport,kSharedOther,kUndefLimited };
class G4TransportationManager;
class G4VPhysicalVolume;
/**
* @brief G4MultiNavigator is a utility class for polling the navigators
* of several geometries to identify the next boundary.
*/
class G4MultiNavigator : public G4Navigator
{
public: // with description
public:
friend std::ostream& operator << (std::ostream& os, const G4Navigator& n);
friend std::ostream& operator << (std::ostream& os, const G4Navigator& n);
G4MultiNavigator();
// Constructor - initialisers and setup.
/**
* Constructor and default Destructor.
*/
G4MultiNavigator();
~G4MultiNavigator() override = default;
~G4MultiNavigator() override;
// Destructor. No actions.
/**
* Computes the distance to the next boundary of any geometry.
* @param[in] pGlobalPoint The point in global coordinates system.
* @param[in] pDirection The normalised vector direction.
* @param[in] pCurrentProposedStepLength Current proposed step length.
* @param[in,out] newSafety New safety.
* @returns Length from current point to next boundary surface along
* @p pDirection.
*/
G4double ComputeStep( const G4ThreeVector& pGlobalPoint,
const G4ThreeVector& pDirection,
const G4double pCurrentProposedStepLength,
G4double& pNewSafety ) override;
G4double ComputeStep( const G4ThreeVector& pGlobalPoint,
const G4ThreeVector& pDirection,
const G4double pCurrentProposedStepLength,
G4double& pNewSafety ) override;
// Return the distance to the next boundary of any geometry
/**
* Gets values for a single geometry.
* @param[in] navigatorId The navigator identifier.
* @param[in,out] pnewSafety New safety for this geometry.
* @param[in,out] minStepLast The last minimum step returned.
* @param[in,out] limitedStep The step characterisation returned.
* @returns The step size for the geometry associated to 'navigatorId'.
*/
G4double ObtainFinalStep( G4int navigatorId,
G4double& pNewSafety, // for this geom
G4double& minStepLast,
ELimited& limitedStep );
G4double ObtainFinalStep( G4int navigatorId,
G4double& pNewSafety, // for this geom
G4double& minStepLast,
ELimited& limitedStep );
// Get values for a single geometry
/**
* Finds which geometries are registered for this particles, and keeps info.
*/
void PrepareNavigators();
void PrepareNavigators();
// Find which geometries are registered for this particles, and keep info
void PrepareNewTrack( const G4ThreeVector& position,
const G4ThreeVector direction );
// Prepare Navigators and locate
/**
* Prepares Navigators and locates.
* @param[in] position The position point in global coordinates system.
* @param[in] direction The normalised vector direction.
*/
void PrepareNewTrack( const G4ThreeVector& position,
const G4ThreeVector direction );
G4VPhysicalVolume* ResetHierarchyAndLocate( const G4ThreeVector& point,
const G4ThreeVector& direction,
const G4TouchableHistory& h ) override;
// Reset the geometrical hierarchy for all geometries.
// Use the touchable history for the first (mass) geometry.
// Return the volume in the first (mass) geometry.
//
// Important Note: In order to call this the geometries MUST be closed.
/**
* Resets the geometrical hierarchy for all geometries.
* Use the touchable history for the first (mass) geometry.
* @note In order to call this the geometries MUST be closed.
* @param[in] point The point in global coordinates system.
* @param[in] direction The normalised vector direction.
* @param[in] h The touchable history to be used for initialisation.
* @returns The pointer to the volume in the first (mass) geometry.
*/
G4VPhysicalVolume* ResetHierarchyAndLocate( const G4ThreeVector& point,
const G4ThreeVector& direction,
const G4TouchableHistory& h ) override;
G4VPhysicalVolume* LocateGlobalPointAndSetup( const G4ThreeVector& point,
const G4ThreeVector* direction = nullptr,
const G4bool pRelativeSearch = true,
const G4bool ignoreDirection = true) override;
// Locate in all geometries.
// Return the volume in the first (mass) geometry
// Maintain vector of other volumes, to be returned separately
//
// Important Note: In order to call this the geometry MUST be closed.
/**
* Locates the point in all geometries.
* Maintains a vector of other volumes, to be returned separately.
* @note In order to call this the geometry MUST be closed.
* @param[in] point The point in global coordinates system.
* @param[in] direction The normalised vector direction.
* @param[in] pRelativeSearch Flag to specify where search starts from.
* @param[in] ignoreDirection Flag to specify if to use direction or not.
* @returns The volume in the first (mass) geometry.
*/
G4VPhysicalVolume* LocateGlobalPointAndSetup( const G4ThreeVector& point,
const G4ThreeVector* direction = nullptr,
const G4bool pRelativeSearch = true,
const G4bool ignoreDirection = true) override;
void LocateGlobalPointWithinVolume( const G4ThreeVector& position ) override;
// Relocate in all geometries for point that has not changed volume
// (ie is within safety in all geometries or is distance less that
// along the direction of a computed step.
/**
* Relocates in all geometries for point that has not changed volume,
* i.e. is within safety in all geometries or its distance is less that
* along the direction of a computed step.
* @param[in] position The position point in global coordinates system.
*/
void LocateGlobalPointWithinVolume( const G4ThreeVector& position ) override;
G4double ComputeSafety( const G4ThreeVector& globalpoint,
const G4double pProposedMaxLength = DBL_MAX,
const G4bool keepState = false ) override;
// Calculate the isotropic distance to the nearest boundary
// in any geometry from the specified point in the global coordinate
// system. The geometry must be closed.
/**
* Calculates the isotropic distance to the nearest boundary in any
* geometry from the specified point in the global coordinates system.
* @note The geometry must be closed.
* @param[in] globalpoint The point in global coordinates system.
* The point must be within the current volume.
* @param[in] pProposedMaxLength The proposed maximum length is used
* to avoid volume safety calculations.
* @param[in] keepState Flag to instruct keeping the state (default false)
* to ensure minimum side effects from the call.
* @returns Length from current point to closest boundary surface.
* The value returned is usually an underestimate.
*/
G4double ComputeSafety( const G4ThreeVector& globalpoint,
const G4double pProposedMaxLength = DBL_MAX,
const G4bool keepState = false ) override;
G4TouchableHandle CreateTouchableHistoryHandle() const override;
// Returns a reference counted handle to a touchable history.
/**
* Returns a reference counted handle to a touchable history.
*/
G4TouchableHandle CreateTouchableHistoryHandle() const override;
G4ThreeVector GetLocalExitNormal( G4bool* obtained ) override; // const
G4ThreeVector GetLocalExitNormalAndCheck( const G4ThreeVector &E_Pt,
G4bool* obtained ) override; // const
G4ThreeVector GetGlobalExitNormal( const G4ThreeVector &E_Pt,
G4bool* obtained ) override; // const
// Return Exit Surface Normal and validity too.
// Can only be called if the Navigator's last Step either
// - has just crossed a volume geometrical boundary and relocated, or
// - has arrived at a boundary in a ComputeStep
// It returns the Normal to the surface pointing out of the volume that
// was left behind and/or into the volume that was entered.
// Convention:x
// The *local* normal is in the coordinate system of the *final* volume.
// Restriction:
// Normals are not available for replica volumes (returns obtained= false)
/**
* Obtains the Normal vector to a surface (in local coordinates)
* pointing out of previous volume and into current volume
* Convention: the *local* normal is in the coordinate system of the
* *final* volume. The method takes full care about how to calculate
* this normal, but if the surfaces are not convex it will return
* valid=false.
* @param[in,out] obtained Flag indicating if normal is valid.
* @returns A Exit Surface Normal vector and validity too.
*/
G4ThreeVector GetLocalExitNormal( G4bool* obtained ) override;
public: // without description
/**
* Obtains the Normal vector to a surface (in local coordinates)
* pointing out of previous volume and into current volume, and
* checks the current point against expected 'local' value.
* Convention: the *local* normal is in the coordinate system of the
* *final* volume. The method takes full care about how to calculate
* this normal, but if the surfaces are not convex it will return
* valid=false.
* @param[in] point Point in global coordinates system to compare to.
* @param[in,out] obtained Flag indicating if normal is valid.
* @returns A Exit Surface Normal vector and validity too.
*/
G4ThreeVector GetLocalExitNormalAndCheck( const G4ThreeVector& point,
G4bool* obtained ) override;
inline G4Navigator* GetNavigator( G4int n ) const
{
if( (n>fNoActiveNavigators) || (n<0) ) { n=0; }
return fpNavigator[n];
}
/**
* Obtains the Normal vector to a surface (in global coordinates)
* pointing out of previous volume and into current volume
* The method takes full care about how to calculate the normal,
* but if the surfaces are not convex it will return valid=false.
* @param[in] point Point in global coordinates system to compare to.
* @param[in,out] obtained Flag indicating if normal is valid.
* @returns A Exit Surface Normal vector and validity too.
*/
G4ThreeVector GetGlobalExitNormal( const G4ThreeVector& point,
G4bool* obtained ) override;
protected: // with description
/**
* Returns a pointer to a navigator, given its index.
*/
inline G4Navigator* GetNavigator( G4int n ) const;
void ResetState() override;
// Utility method to reset the navigator state machine.
protected:
void SetupHierarchy() override;
// Renavigate & reset hierarchy described by current history
// o Reset volumes
// o Recompute transforms and/or solids of replicated/parameterised
// volumes.
/**
* Utility method to reset the navigator state machine.
*/
void ResetState() override;
void WhichLimited(); // Flag which processes limited the step
void PrintLimited(); // Auxiliary, debugging printing
void CheckMassWorld();
/**
* Renavigates & resets hierarchy described by the current history,
* i.e. resets volumes and recomputes transforms and/or solids of
* replicated/parameterised volumes.
*/
void SetupHierarchy() override;
private:
/**
* Flags which processes limited the step.
*/
void WhichLimited();
// STATE Information
/**
* Auxiliary, debugging printing.
*/
void PrintLimited();
G4int fNoActiveNavigators = 0;
static const G4int fMaxNav = 16;
G4VPhysicalVolume* fLastMassWorld = nullptr;
/**
* Checks if mass world pointed has been changed => issues and exception.
*/
void CheckMassWorld();
G4Navigator* fpNavigator[fMaxNav];
// Global state (retained during stepping for one track
private:
// State after a step computation
//
ELimited fLimitedStep[fMaxNav];
G4bool fLimitTruth[fMaxNav];
G4double fCurrentStepSize[fMaxNav];
G4double fNewSafety[ fMaxNav ]; // Safety for starting point
G4int fNoLimitingStep = -1; // How many geometries limited the step
G4int fIdNavLimiting = -1; // Id of Navigator limiting step
// STATE Information
// Lowest values - determine step length, and safety
//
G4double fMinStep = -kInfinity; // As reported by Navigators
G4double fMinSafety = -kInfinity;
G4double fTrueMinStep = -kInfinity; // Corrected if fMinStep>=proposed
G4int fNoActiveNavigators = 0;
static const G4int fMaxNav = 16;
G4VPhysicalVolume* fLastMassWorld = nullptr;
// State after calling 'locate'
//
G4VPhysicalVolume* fLocatedVolume[fMaxNav];
G4ThreeVector fLastLocatedPosition;
/** Global state (retained during stepping for one track). */
G4Navigator* fpNavigator[fMaxNav];
// Cache of safety information
//
G4ThreeVector fSafetyLocation;
// point where ComputeSafety is called
G4double fMinSafety_atSafLocation = -1.0;
// - corresponding value of safety
G4ThreeVector fPreStepLocation;
// point where last ComputeStep called
G4double fMinSafety_PreStepPt = -1.0;
// - corresponding value of safety
// State after a step computation
//
ELimited fLimitedStep[fMaxNav];
G4bool fLimitTruth[fMaxNav];
G4double fCurrentStepSize[fMaxNav];
G4double fNewSafety[ fMaxNav ]; // Safety for starting point
G4int fNoLimitingStep = -1; // How many geometries limited the step
G4int fIdNavLimiting = -1; // Id of Navigator limiting step
G4TransportationManager* pTransportManager; // Cache for frequent use
// Lowest values - determine step length, and safety
//
G4double fMinStep = -kInfinity; // As reported by Navigators
G4double fMinSafety = -kInfinity;
G4double fTrueMinStep = -kInfinity; // Corrected if fMinStep>=proposed
// State after calling 'locate'
//
G4VPhysicalVolume* fLocatedVolume[fMaxNav];
G4ThreeVector fLastLocatedPosition;
// Cache of safety information
//
G4ThreeVector fSafetyLocation; // point where ComputeSafety() is called
G4double fMinSafety_atSafLocation = -1.0; // - corresponding value of safety
G4ThreeVector fPreStepLocation; // point where last ComputeStep() called
G4double fMinSafety_PreStepPt = -1.0; // - corresponding value of safety
G4TransportationManager* pTransportManager; // Cache for frequent use
};
// --------------------------------------------------------------------
// Inline methods
// --------------------------------------------------------------------
inline G4Navigator* G4MultiNavigator::GetNavigator( G4int n ) const
{
if( (n>fNoActiveNavigators) || (n<0) ) { n=0; }
return fpNavigator[n];
}
#endif