Import Geant4 11.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2025-12-05 08:54:02 +01:00
parent a499fb82e9
commit b4a16de652
6484 changed files with 232674 additions and 221097 deletions
@@ -48,8 +48,8 @@
// Logical volumes self register to the logical volume Store on construction,
// and deregister on destruction.
//
// NOTE: This class is currently *NOT* subclassed, since not meant to
// act as a base class. Therefore, the destructor is NOT virtual.
// NOTE: This class is NOT meant to act as base class, except for exceptional
// circumstances of extended types used in the kernel.
//
// Data members:
//
@@ -91,18 +91,10 @@
// G4bool fIsEnvelope
// - Flags if the Logical Volume is an envelope for a FastSimulationManager.
// 15.01.13 G.Cosmo, A.Dotti: Modified for thread-safety for MT
// 12.11.04 G.Cosmo: Added GetMass() method for computing mass of the tree
// 24.09.02 G.Cosmo: Added flags and accessors for region cuts handling
// 17.05.02 G.Cosmo: Added IsToOptimise() method and related flag
// 18.04.01 G.Cosmo: Migrated to STL vector
// 12.02.99 S.Giani: Added user defined optimisation quality
// 09.11.98 M.Verderi, J.Apostolakis: Added BiasWeight member and accessors
// 10.20.97 P.M.DeFreitas, J.Apostolakis: Added pointer to a FastSimulation
// 11.07.95 P.Kent: Initial version
// Author: Paul Kent (CERN), 11.07.1995 - Initial version
// ------------------------------------------------------------------------
#ifndef G4LOGICALVOLUME_HH
#define G4LOGICALVOLUME_HH 1
#define G4LOGICALVOLUME_HH
#include <vector>
#include <memory>
@@ -125,11 +117,13 @@ class G4FastSimulationManager;
class G4MaterialCutsCouple;
class G4VisAttributes;
/**
* @brief G4LVData encapsulates the fields associated to the class
* G4LogicalVolume that may not be read-only.
*/
class G4LVData
{
// Encapsulates the fields associated to the class
// G4LogicalVolume that may not be read-only.
public:
G4LVData();
@@ -159,6 +153,425 @@ class G4LVData
// Pointer (possibly nullptr) to associated production cuts.
};
/** G4LVManager encapsulates the methods used by both the master thread and
worker threads to allocate memory space for the fields encapsulated by the
class G4LVData. */
using G4LVManager = G4GeomSplitter<G4LVData>;
/**
* @brief G4LogicalVolume represents a leaf node or unpositioned subtree in the
* geometry hierarchy. Logical volumes are named, and may have daughters
* ascribed to them. They are responsible for retrieval of the physical and
* tracking attributes of the physical volume that it represents: solid,
* material, magnetic field, and optionally, user limits, sensitive detectors,
* regions, biasing weights.
*/
class G4LogicalVolume
{
public:
/**
* Constructor for G4LogicalVolume. The solid and material pointer must be
* non null. The parameters for field, detector and user limits are optional.
* The volume also enters itself into the logical volume Store.
* Optimisation of the geometry (voxelisation) for the volume hierarchy is
* applied by default. For parameterised volumes in the hierarchy,
* optimisation is -always- applied.
* @param[in] pSolid Pointer to the associated solid primitive.
* @param[in] pMaterial Pointer to the associated material.
* @param[in] name The volume name.
* @param[in] pFieldMgr Pointer to optional magnetic field manager.
* @param[in] pSDetector Pointer to optional associated sensitive detector.
* @param[in] pULimits Pointer to optional user limits.
* @param[in] optimise Flag to enable/disable optimisation structure.
*/
G4LogicalVolume(G4VSolid* pSolid,
G4Material* pMaterial,
const G4String& name,
G4FieldManager* pFieldMgr = nullptr,
G4VSensitiveDetector* pSDetector = nullptr,
G4UserLimits* pULimits = nullptr,
G4bool optimise = true);
/**
* Destructor. Removes the logical volume from the logical volume Store.
* This class is NOT meant to act as base class, except for exceptional
* circumstances of extended types used in the kernel.
*/
virtual ~G4LogicalVolume();
/**
* Copy-constructor and assignment operator not allowed.
*/
G4LogicalVolume(const G4LogicalVolume&) = delete;
G4LogicalVolume& operator=(const G4LogicalVolume&) = delete;
/**
* Returns and sets the name of the logical volume.
*/
inline const G4String& GetName() const;
void SetName(const G4String& pName);
/**
* Returns the number of daughters (0 to n).
*/
inline std::size_t GetNoDaughters() const;
/**
* Returns the ith daughter. Note numbering starts from 0,
* and no bounds checking is performed.
*/
inline G4VPhysicalVolume* GetDaughter(const std::size_t i) const;
/**
* Adds the volume 'p' as a daughter of the current logical volume.
*/
void AddDaughter(G4VPhysicalVolume* p);
/**
* Returns true if the volume 'p' is a daughter of the current
* logical volume.
*/
inline G4bool IsDaughter(const G4VPhysicalVolume* p) const;
/**
* Returns true if the volume 'p' is part of the hierarchy of volumes
* established by the current logical volume. Scans recursively the volume
* tree.
*/
G4bool IsAncestor(const G4VPhysicalVolume* p) const;
/**
* Removes the volume 'p' from the list of daughters of the current
* logical volume.
*/
void RemoveDaughter(const G4VPhysicalVolume* p);
/**
* Clears the list of daughters. Used by the physical volume store when
* the geometry tree is cleared, since modified at run-time.
*/
void ClearDaughters();
/**
* Returns the total number of physical volumes (replicated or placed)
* in the tree represented by the current logical volume.
*/
G4int TotalVolumeEntities() const;
/**
* Characterises the daughters of this logical volume.
*/
inline EVolume CharacteriseDaughters() const;
/**
* Utility method used by CharacteriseDaughters().
*/
inline EVolume DeduceDaughtersType() const;
/**
* Gets and sets the current solid.
*/
G4VSolid* GetSolid() const;
void SetSolid(G4VSolid* pSolid);
/**
* Gets and sets the current material.
*/
G4Material* GetMaterial() const;
void SetMaterial(G4Material* pMaterial);
/**
* Sets the material and corresponding Material-Cuts-Couple.
* This method is invoked by G4Navigator while it is navigating through
* material parameterisation.
*/
void UpdateMaterial(G4Material* pMaterial);
/**
* Returns the mass of the logical volume tree computed from the
* estimated geometrical volume of each solid and material associated
* to the logical volume and (by default) to its daughters.
* @note The computation may require a considerable amount of time,
* depending from the complexity of the geometry tree.
* The returned value is cached and can be used for successive
* calls (default), unless recomputation is forced by providing
* 'true' for the Boolean argument in input. Computation should
* be forced if the geometry setup has changed after the previous
* call. By setting the 'propagate' Boolean flag to 'false' the
* method returns the mass of the present logical volume only
* (subtracted for the volume occupied by the daughter volumes).
* An optional argument to specify a material is also provided.
* @param[in] forced Flag to force recomputation or use cached value.
* @param[in] propagate Flag to limit or not computation to daughters.
* @param[in] parMaterial Optional pointer to a custom material, usually
* used in parameterisations.
*/
G4double GetMass(G4bool forced = false, G4bool propagate = true,
G4Material* parMaterial = nullptr);
/**
* Resets the cached value of mass. Ensures that cached value of mass is
* invalidated due to change in state, e.g. change of the size of the
* solid, change of the type of solid, or the addition/deletion of a
* daughter volume.
*/
void ResetMass();
/**
* Gets current Field Manager pointer.
*/
G4FieldManager* GetFieldManager() const;
/**
* Sets the Field Manager and propagates it.
* @param[in] pFieldMgr Pointer to the field manager.
* @param[in] forceToAllDaughters Flag to force propagation to all
* daughters (true), or only to daughters having null pointer
* to the field manager (false).
*/
void SetFieldManager(G4FieldManager* pFieldMgr, G4bool forceToAllDaughters);
/**
* Gets and sets the current sensitive detector (can be a null pointer).
*/
G4VSensitiveDetector* GetSensitiveDetector() const;
void SetSensitiveDetector(G4VSensitiveDetector* pSDetector);
/**
* Gets and sets the current User Limits.
*/
inline G4UserLimits* GetUserLimits() const;
inline void SetUserLimits(G4UserLimits *pULimits);
/**
* Gets and sets the current Voxel Header.
*/
inline G4SmartVoxelHeader* GetVoxelHeader() const;
inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel);
/**
* Gets and sets the user defined optimisation quality associated to
* the volume.
*/
inline G4double GetSmartless() const;
inline void SetSmartless(G4double s);
/**
* Replies if the geometry optimisation (voxelisation) is to be applied
* for this volume hierarchy.
*/
inline G4bool IsToOptimise() const;
/**
* Specifies if to apply or not geometry optimisation to the volume
* hierarchy. For parameterised volumes in the hierarchy, optimisation is
* always applied.
*/
inline void SetOptimisation(G4bool optim);
/**
* Replies if the logical volume represents a root region or not.
*/
inline G4bool IsRootRegion() const;
/**
* Sets/unsets the volume as a root region for cuts.
*/
inline void SetRegionRootFlag(G4bool rreg);
/**
* Replies if the logical volume is part of a cuts region or not.
*/
inline G4bool IsRegion() const;
/**
* Sets/unsets the volume as cuts region.
*/
inline void SetRegion(G4Region* reg);
/**
* Returns the region to which the volume belongs, if any.
*/
inline G4Region* GetRegion() const;
/**
* Propagates region pointer to daughters.
*/
inline void PropagateRegion();
/**
* Accessor and modifier for production cuts.
*/
const G4MaterialCutsCouple* GetMaterialCutsCouple() const;
void SetMaterialCutsCouple(G4MaterialCutsCouple* cuts);
/**
* Equality defined by address only.
* Returns true if objects are at same address, else false.
*/
G4bool operator == (const G4LogicalVolume& lv) const;
/**
* Accessor and modifiers for visualization attributes.
* Arguments are converted to shared_ptr.
*/
const G4VisAttributes* GetVisAttributes () const;
void SetVisAttributes (const G4VisAttributes* pVA);
void SetVisAttributes (const G4VisAttributes& VA);
/**
* Gets the current FastSimulationManager pointer if existing,
* otherwise null.
*/
inline G4FastSimulationManager* GetFastSimulationManager () const;
/**
* Sets and gets the bias weight.
*/
inline void SetBiasWeight (G4double w);
inline G4double GetBiasWeight() const;
/**
* Returns true if it is not a base-class object.
*/
virtual G4bool IsExtended() const;
/**
* Returns current Field Manager for the master thread.
*/
inline G4FieldManager* GetMasterFieldManager() const;
/**
* Returns current Sensitive Detector for the master thread.
*/
inline G4VSensitiveDetector* GetMasterSensitiveDetector() const;
/**
* Returns current Solid for the master thread.
*/
inline G4VSolid* GetMasterSolid() const;
/**
* Returns the instance ID.
*/
inline G4int GetInstanceID() const;
/**
* Returns the private data instance manager.
*/
static const G4LVManager& GetSubInstanceManager();
/**
* Clears memory allocated by sub-instance manager.
*/
static void Clean();
/**
* Sets lock identifier for final deletion of entity.
*/
inline void Lock();
/**
* This method is similar to the constructor. It is used by each worker
* thread to achieve the partial effect as that of the master thread.
*/
void InitialiseWorker(G4LogicalVolume* ptrMasterObject,
G4VSolid* pSolid, G4VSensitiveDetector* pSDetector);
/**
* This method is similar to the destructor. It is used by each worker
* thread to achieve the partial effect as that of the master thread.
*/
void TerminateWorker(G4LogicalVolume* ptrMasterObject);
/**
* Sets the Field Manager only at this level (does not push down hierarchy)
*/
void AssignFieldManager(G4FieldManager* fldMgr);
/**
* Optimised methods, passing thread instance of worker data.
*/
static G4VSolid* GetSolid(G4LVData& instLVdata);
static void SetSolid(G4LVData& instLVdata, G4VSolid* pSolid);
/**
* Changes the type of the daughters volume to be of type 'atype'.
* Meant for the user adopting an external navigator for the contents
* of a volume.
* @returns Success (true) or failure (false).
*/
G4bool ChangeDaughtersType(EVolume atype);
/**
* Fake default constructor for usage restricted to direct object
* persistency for clients requiring preallocation of memory for
* persistifiable objects.
*/
G4LogicalVolume(__void__&);
private:
using G4PhysicalVolumeList = std::vector<G4VPhysicalVolume *>;
/** This field helps in the use of the class G4LVManager. */
G4GEOM_DLL static G4LVManager subInstanceManager;
/** Vector of daughters. Given initial size of 0. */
G4PhysicalVolumeList fDaughters;
/** Name of logical volume. */
G4String fName;
/** Pointer (possibly nullptr) to user step limit object for this node. */
G4UserLimits* fUserLimits = nullptr;
/** Pointer (possibly nullptr) to optimisation info objects. */
G4SmartVoxelHeader* fVoxel = nullptr;
/** Optimisation quality, average number of voxels to be spent per content. */
G4double fSmartless = 2.0;
/** Pointer to the cuts region (if any). */
G4Region* fRegion = nullptr;
/** Weight used in the event biasing technique. */
G4double fBiasWeight = 1.0;
/** Pointer to visualization attributes. */
std::shared_ptr<const G4VisAttributes> fVisAttributes;
// Shadow of master pointers.
// Each worker thread can access this field from the master thread
// through these pointers.
//
G4VSolid* fSolid = nullptr;
G4VSensitiveDetector* fSensitiveDetector = nullptr;
G4FieldManager* fFieldManager = nullptr;
G4LVData* lvdata = nullptr; // For use of object persistency
/** This new field is used as instance ID. */
G4int instanceID;
/** Are contents of volume placements, replica, parameterised or external? */
EVolume fDaughtersVolumeType;
/** Flag to identify if optimisation should be applied or not. */
G4bool fOptimise = true;
/** Flag to identify if the logical volume is a root region. */
G4bool fRootRegion = false;
/** Flag to identify if entity is locked for final deletion. */
G4bool fLock = false;
};
#include "G4LogicalVolume.icc"
// NOTE:
//
// The type G4LVManager is introduced to encapsulate the methods used by
// both the master thread and worker threads to allocate memory space for
// the fields encapsulated by the class G4LVData. When each thread
@@ -176,264 +589,5 @@ class G4LVData
// it copies the array of G4LVData instances from the master thread.
// In addition, it invokes a method similiar to the constructor explicitly
// to achieve the partial effect for each instance in the array.
//
using G4LVManager = G4GeomSplitter<G4LVData>;
class G4LogicalVolume
{
public:
G4LogicalVolume(G4VSolid* pSolid,
G4Material* pMaterial,
const G4String& name,
G4FieldManager* pFieldMgr = nullptr,
G4VSensitiveDetector* pSDetector = nullptr,
G4UserLimits* pULimits = nullptr,
G4bool optimise = true);
// Constructor. The solid and material pointer must be non null.
// The parameters for field, detector and user limits are optional.
// The volume also enters itself into the logical volume Store.
// Optimisation of the geometry (voxelisation) for the volume
// hierarchy is applied by default. For parameterised volumes in
// the hierarchy, optimisation is -always- applied.
virtual ~G4LogicalVolume();
// Destructor. Removes the logical volume from the logical volume Store.
// This class is NOT meant to act as base class, except for exceptional
// circumstances of extended types used in the kernel.
G4LogicalVolume(const G4LogicalVolume&) = delete;
G4LogicalVolume& operator=(const G4LogicalVolume&) = delete;
// Copy-constructor and assignment operator not allowed.
inline const G4String& GetName() const;
void SetName(const G4String& pName);
// Returns and sets the name of the logical volume.
inline std::size_t GetNoDaughters() const;
// Returns the number of daughters (0 to n).
inline G4VPhysicalVolume* GetDaughter(const std::size_t i) const;
// Returns the ith daughter. Note numbering starts from 0,
// and no bounds checking is performed.
void AddDaughter(G4VPhysicalVolume* p);
// Adds the volume p as a daughter of the current logical volume.
inline G4bool IsDaughter(const G4VPhysicalVolume* p) const;
// Returns true if the volume p is a daughter of the current
// logical volume.
G4bool IsAncestor(const G4VPhysicalVolume* p) const;
// Returns true if the volume p is part of the hierarchy of
// volumes established by the current logical volume. Scans
// recursively the volume tree.
void RemoveDaughter(const G4VPhysicalVolume* p);
// Removes the volume p from the List of daughter of the current
// logical volume.
void ClearDaughters();
// Clears the list of daughters. Used by the phys-volume store when
// the geometry tree is cleared, since modified at run-time.
G4int TotalVolumeEntities() const;
// Returns the total number of physical volumes (replicated or placed)
// in the tree represented by the current logical volume.
inline EVolume CharacteriseDaughters() const;
// Characterise the daughters of this logical volume.
inline EVolume DeduceDaughtersType() const;
// Used by CharacteriseDaughters().
G4VSolid* GetSolid() const;
void SetSolid(G4VSolid* pSolid);
// Gets and sets the current solid.
G4Material* GetMaterial() const;
void SetMaterial(G4Material* pMaterial);
// Gets and sets the current material.
void UpdateMaterial(G4Material* pMaterial);
// Sets material and corresponding MaterialCutsCouple.
// This method is invoked by G4Navigator while it is navigating through
// material parameterization.
G4double GetMass(G4bool forced = false, G4bool propagate = true,
G4Material* parMaterial = nullptr);
// Returns the mass of the logical volume tree computed from the
// estimated geometrical volume of each solid and material associated
// to the logical volume and (by default) to its daughters.
// NOTE: the computation may require a considerable amount of time,
// depending from the complexity of the geometry tree.
// The returned value is cached and can be used for successive
// calls (default), unless recomputation is forced by providing
// 'true' for the boolean argument in input. Computation should
// be forced if the geometry setup has changed after the previous
// call. By setting the 'propagate' boolean flag to 'false' the
// method returns the mass of the present logical volume only
// (subtracted for the volume occupied by the daughter volumes).
// An optional argument to specify a material is also provided.
void ResetMass();
// Ensure that cached value of Mass is invalidated - due to change in
// state, e.g. change of size of Solid, change of type of solid,
// or the addition/deletion of a daughter volume.
G4FieldManager* GetFieldManager() const;
// Gets current FieldManager.
void SetFieldManager(G4FieldManager* pFieldMgr, G4bool forceToAllDaughters);
// Sets FieldManager and propagates it:
// i) only to daughters with G4FieldManager = nullptr
// if forceToAllDaughters=false
// ii) to all daughters
// if forceToAllDaughters=true
G4VSensitiveDetector* GetSensitiveDetector() const;
// Gets current SensitiveDetector.
void SetSensitiveDetector(G4VSensitiveDetector* pSDetector);
// Sets SensitiveDetector (can be nullptr).
inline G4UserLimits* GetUserLimits() const;
inline void SetUserLimits(G4UserLimits *pULimits);
// Gets and sets current UserLimits.
inline G4SmartVoxelHeader* GetVoxelHeader() const;
inline void SetVoxelHeader(G4SmartVoxelHeader *pVoxel);
// Gets and sets current VoxelHeader.
inline G4double GetSmartless() const;
inline void SetSmartless(G4double s);
// Gets and sets user defined optimisation quality.
inline G4bool IsToOptimise() const;
// Replies if geometry optimisation (voxelisation) is to be
// applied for this volume hierarchy.
inline void SetOptimisation(G4bool optim);
// Specifies if to apply or not geometry optimisation to this
// volume hierarchy. Note that for parameterised volumes in the
// hierarchy, optimisation is always applied.
inline G4bool IsRootRegion() const;
// Replies if the logical volume represents a root region or not.
inline void SetRegionRootFlag(G4bool rreg);
// Sets/unsets the volume as a root region for cuts.
inline G4bool IsRegion() const;
// Replies if the logical volume is part of a cuts region or not.
inline void SetRegion(G4Region* reg);
// Sets/unsets the volume as cuts region.
inline G4Region* GetRegion() const;
// Return the region to which the volume belongs, if any.
inline void PropagateRegion();
// Propagates region pointer to daughters.
const G4MaterialCutsCouple* GetMaterialCutsCouple() const;
void SetMaterialCutsCouple(G4MaterialCutsCouple* cuts);
// Accessors for production cuts.
G4bool operator == (const G4LogicalVolume& lv) const;
// Equality defined by address only.
// Returns true if objects are at same address, else false.
const G4VisAttributes* GetVisAttributes () const;
void SetVisAttributes (const G4VisAttributes* pVA);
void SetVisAttributes (const G4VisAttributes& VA);
// Gets and sets visualization attributes.
// Arguments are converted to shared_ptr.
inline G4FastSimulationManager* GetFastSimulationManager () const;
// Gets current FastSimulationManager pointer if exists, otherwise null.
inline void SetBiasWeight (G4double w);
inline G4double GetBiasWeight() const;
// Sets and gets bias weight.
public:
G4LogicalVolume(__void__&);
// Fake default constructor for usage restricted to direct object
// persistency for clients requiring preallocation of memory for
// persistifiable objects.
virtual G4bool IsExtended() const;
// Return true if it is not a base-class object.
inline G4FieldManager* GetMasterFieldManager() const;
// Gets current FieldManager for the master thread.
inline G4VSensitiveDetector* GetMasterSensitiveDetector() const;
// Gets current SensitiveDetector for the master thread.
inline G4VSolid* GetMasterSolid() const;
// Gets current Solid for the master thread.
inline G4int GetInstanceID() const;
// Returns the instance ID.
static const G4LVManager& GetSubInstanceManager();
// Returns the private data instance manager.
static void Clean();
// Clear memory allocated by sub-instance manager.
inline void Lock();
// Set lock identifier for final deletion of entity.
void InitialiseWorker(G4LogicalVolume* ptrMasterObject,
G4VSolid* pSolid, G4VSensitiveDetector* pSDetector);
// This method is similar to the constructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
void TerminateWorker(G4LogicalVolume* ptrMasterObject);
// This method is similar to the destructor. It is used by each worker
// thread to achieve the partial effect as that of the master thread.
void AssignFieldManager(G4FieldManager* fldMgr);
// Set the FieldManager - only at this level (do not push down hierarchy)
static G4VSolid* GetSolid(G4LVData& instLVdata) ; // const;
static void SetSolid(G4LVData& instLVdata, G4VSolid* pSolid);
// Optimised Methods - passing thread instance of worker data
G4bool ChangeDaughtersType(EVolume atype);
// Change the type of the daughters volume to be of type atype.
// Meant for the user who wants to use the external navigator for
// the contents of a volume.
// Returns: success (true) or failure (false).
private:
using G4PhysicalVolumeList = std::vector<G4VPhysicalVolume *>;
G4GEOM_DLL static G4LVManager subInstanceManager;
// This new field helps to use the class G4LVManager introduced above.
G4PhysicalVolumeList fDaughters;
// Vector of daughters. Given initial size of 0.
G4String fName;
// Name of logical volume.
G4UserLimits* fUserLimits = nullptr;
// Pointer (possibly nullptr) to user Step limit object for this node.
G4SmartVoxelHeader* fVoxel = nullptr;
// Pointer (possibly nullptr) to optimisation info objects.
G4double fSmartless = 2.0;
// Quality for optimisation, average number of voxels to be spent
// per content.
G4Region* fRegion = nullptr;
// Pointer to the cuts region (if any).
G4double fBiasWeight = 1.0;
// Weight used in the event biasing technique.
std::shared_ptr<const G4VisAttributes> fVisAttributes;
// Pointer to visualization attributes.
// Shadow of master pointers.
// Each worker thread can access this field from the master thread
// through these pointers.
//
G4VSolid* fSolid = nullptr;
G4VSensitiveDetector* fSensitiveDetector = nullptr;
G4FieldManager* fFieldManager = nullptr;
G4LVData* lvdata = nullptr; // For use of object persistency
G4int instanceID;
// This new field is used as instance ID.
EVolume fDaughtersVolumeType;
// Are contents of volume placements, replica, parameterised or external?
G4bool fOptimise = true;
// Flag to identify if optimisation should be applied or not.
G4bool fRootRegion = false;
// Flag to identify if the logical volume is a root region.
G4bool fLock = false;
// Flag to identify if entity is locked for final deletion.
};
#include "G4LogicalVolume.icc"
#endif