Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
@@ -41,20 +41,20 @@ class Par04ParallelFullWorld;
class Par04ActionInitialisation : public G4VUserActionInitialization
{
public:
Par04ActionInitialisation(Par04DetectorConstruction* aDetector,
Par04ParallelFullWorld* aParallel);
~Par04ActionInitialisation();
/// Create all user actions.
virtual void Build() const final;
/// Create run action in the master thread to allow analysis merging.
virtual void BuildForMaster() const final;
public:
Par04ActionInitialisation(Par04DetectorConstruction* aDetector,
Par04ParallelFullWorld* aParallel);
~Par04ActionInitialisation();
/// Create all user actions.
virtual void Build() const final;
/// Create run action in the master thread to allow analysis merging.
virtual void BuildForMaster() const final;
private:
/// Pointer to detector to be passed to event and run actions in order to
/// retrieve detector dimensions
Par04DetectorConstruction* fDetector = nullptr;
Par04ParallelFullWorld* fParallel = nullptr;
private:
/// Pointer to detector to be passed to event and run actions in order to
/// retrieve detector dimensions
Par04DetectorConstruction* fDetector = nullptr;
Par04ParallelFullWorld* fParallel = nullptr;
};
#endif /* PAR04ACTIONINITIALISATION_HH */
@@ -26,9 +26,10 @@
#ifndef PAR04DEFINEMESHMODEL_HH
#define PAR04DEFINEMESHMODEL_HH
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool
#include "G4VFastSimulationModel.hh" // for G4VFastSimulationModel
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool
class G4FastStep;
class G4FastTrack;
class G4ParticleDefinition;
@@ -46,20 +47,20 @@ class G4Region;
class Par04DefineMeshModel : public G4VFastSimulationModel
{
public:
Par04DefineMeshModel(G4String, G4Region*);
Par04DefineMeshModel(G4String);
~Par04DefineMeshModel();
public:
Par04DefineMeshModel(G4String, G4Region*);
Par04DefineMeshModel(G4String);
~Par04DefineMeshModel();
/// Check if particle is entering the volume. Check particle energy. It must be
/// no smaller than 99% of the primary particle energy. This is to ensure that in case of
/// prior interactions, particle energy does not differ (much) from the assumed
/// energy.
virtual G4bool ModelTrigger(const G4FastTrack&) final;
/// Model is applicable to all particles.
virtual G4bool IsApplicable(const G4ParticleDefinition&) final;
/// Check particle direction, entrance point, and store it in event information.
/// Then go back to the full simulation.
virtual void DoIt(const G4FastTrack&, G4FastStep&) final;
/// Check if particle is entering the volume. Check particle energy. It must be
/// no smaller than 99% of the primary particle energy. This is to ensure that in case of
/// prior interactions, particle energy does not differ (much) from the assumed
/// energy.
virtual G4bool ModelTrigger(const G4FastTrack&) final;
/// Model is applicable to all particles.
virtual G4bool IsApplicable(const G4ParticleDefinition&) final;
/// Check particle direction, entrance point, and store it in event information.
/// Then go back to the full simulation.
virtual void DoIt(const G4FastTrack&, G4FastStep&) final;
};
#endif /* PAR04DEFINEMESHMODEL_HH */
@@ -26,16 +26,17 @@
#ifndef PAR04DETECTORCONSTRUCTION_H
#define PAR04DETECTORCONSTRUCTION_H
#include <CLHEP/Units/SystemOfUnits.h> // for cm, mm, pi, rad
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4double, G4bool, G4int
#include <array> // for array
#include <cstddef> // for size_t
#include <vector> // for vector
#include "G4Material.hh" // for G4Material
#include "G4SystemOfUnits.hh" // for cm, mm, rad
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4Material.hh" // for G4Material
#include "G4SystemOfUnits.hh" // for cm, mm, rad
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VUserDetectorConstruction.hh" // for G4VUserDetectorConstruction
#include <CLHEP/Units/SystemOfUnits.h> // for cm, mm, pi, rad
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4double, G4bool, G4int
#include <array> // for array
#include <cstddef> // for size_t
#include <vector> // for vector
class G4LogicalVolume;
class G4VPhysicalVolume;
class Par04DetectorMessenger;
@@ -71,88 +72,93 @@ class Par04DetectorMessenger;
class Par04DetectorConstruction : public G4VUserDetectorConstruction
{
public:
Par04DetectorConstruction();
virtual ~Par04DetectorConstruction();
public:
Par04DetectorConstruction();
virtual ~Par04DetectorConstruction();
virtual G4VPhysicalVolume* Construct() final;
virtual void ConstructSDandField() final;
virtual G4VPhysicalVolume* Construct() final;
virtual void ConstructSDandField() final;
/// Set inner radius of the cylindrical detector
void SetInnerRadius(G4double aInnerRadius);
/// Get inner radius of the cylindrical detector
inline G4double GetInnerRadius() const { return fDetectorInnerRadius; };
/// Set length radius of the cylindrical detector
void SetLength(G4double aLength);
/// Get length of the cylindrical detector (along z-axis)
inline G4double GetLength() const { return fDetectorLength; };
/// Set number of layers
inline void SetNbOfLayers(G4int aNumber) { fNbOfLayers = aNumber; };
/// Get number of layers
inline G4int GetNbOfLayers() const { return fNbOfLayers; };
/// Set inner radius of the cylindrical detector
void SetInnerRadius(G4double aInnerRadius);
/// Get inner radius of the cylindrical detector
inline G4double GetInnerRadius() const { return fDetectorInnerRadius; };
/// Set length radius of the cylindrical detector
void SetLength(G4double aLength);
/// Get length of the cylindrical detector (along z-axis)
inline G4double GetLength() const { return fDetectorLength; };
/// Set number of layers
inline void SetNbOfLayers(G4int aNumber) { fNbOfLayers = aNumber; };
/// Get number of layers
inline G4int GetNbOfLayers() const { return fNbOfLayers; };
/// Set material of the layer (from NIST materials)
void SetAbsorberMaterial(const std::size_t aLayer, const G4String& aMaterial);
/// Get name of the material of the layer
inline G4String GetAbsorberMaterial(const std::size_t aLayer) const
{
return fAbsorberMaterial[aLayer]->GetName();
};
/// Set thickness of the layer
void SetAbsorberThickness(const std::size_t aLayer, const G4double aThickness);
/// Get thickness of the layer
inline G4double GetAbsorberThickness(const std::size_t aLayer) const
{
return fAbsorberThickness[aLayer];
};
/// Set sensitivity of the layer
void SetAbsorberSensitivity(const std::size_t aLayer, const G4bool aSensitivity);
/// Get sensitivity of the layer
inline G4bool GetAbsorberSensitivity(const std::size_t aLayer) const
{
return fAbsorberSensitivity[aLayer];
};
/// Set material of the layer (from NIST materials)
void SetAbsorberMaterial(const std::size_t aLayer, const G4String& aMaterial);
/// Get name of the material of the layer
inline G4String GetAbsorberMaterial(const std::size_t aLayer) const
{
return fAbsorberMaterial[aLayer]->GetName();
};
/// Set thickness of the layer
void SetAbsorberThickness(const std::size_t aLayer, const G4double aThickness);
/// Get thickness of the layer
inline G4double GetAbsorberThickness(const std::size_t aLayer) const
{
return fAbsorberThickness[aLayer];
};
/// Set sensitivity of the layer
void SetAbsorberSensitivity(const std::size_t aLayer, const G4bool aSensitivity);
/// Get sensitivity of the layer
inline G4bool GetAbsorberSensitivity(const std::size_t aLayer) const
{
return fAbsorberSensitivity[aLayer];
};
/// Set number of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshNbOfCells(G4ThreeVector aNb) { fMeshNbOfCells = aNb; };
/// Set number of Mesh cells in cylindrical coordinates along one of the axis
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshNbOfCells(std::size_t aIndex, G4double aNb) { fMeshNbOfCells[aIndex] = aNb; };
/// Get number of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshNbOfCells() const { return fMeshNbOfCells; };
/// Set size of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshSizeOfCells(G4ThreeVector aNb) { fMeshSizeOfCells = aNb; };
/// Set size of Mesh cells in cylindrical coordinates along one of the axis
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshSizeOfCells(std::size_t aIndex, G4double aNb)
{ fMeshSizeOfCells[aIndex] = aNb; };
/// Get size of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshSizeOfCells() const { return fMeshSizeOfCells; };
/// Set number of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshNbOfCells(G4ThreeVector aNb) { fMeshNbOfCells = aNb; };
/// Set number of Mesh cells in cylindrical coordinates along one of the axis
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshNbOfCells(std::size_t aIndex, G4double aNb)
{
fMeshNbOfCells[aIndex] = aNb;
};
/// Get number of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshNbOfCells() const { return fMeshNbOfCells; };
/// Set size of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshSizeOfCells(G4ThreeVector aNb) { fMeshSizeOfCells = aNb; };
/// Set size of Mesh cells in cylindrical coordinates along one of the axis
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshSizeOfCells(std::size_t aIndex, G4double aNb)
{
fMeshSizeOfCells[aIndex] = aNb;
};
/// Get size of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshSizeOfCells() const { return fMeshSizeOfCells; };
/// Print detector information
void Print() const;
/// Print detector information
void Print() const;
private:
/// Messenger that allows to modify geometry
Par04DetectorMessenger* fDetectorMessenger = nullptr;
/// Inner radius of the cylindrical detector
G4double fDetectorInnerRadius = 80 * cm;
/// Length of the cylindrical detector (along z axis)
G4double fDetectorLength = 24 * cm;
/// Logical volume(s) of the sensitive absorbers
std::vector<G4LogicalVolume*> fLayerLogical;
/// Material(s) of the layers
std::array<G4Material*, 2> fAbsorberMaterial = { nullptr, nullptr };
/// Thickness(es) of the layers
std::array<G4double, 2> fAbsorberThickness = { 1 * cm, 0 };
/// Sensitivity of the layers
std::array<G4bool, 2> fAbsorberSensitivity = { true, 0 };
/// Number of layers = slices along z axis
G4int fNbOfLayers = 24;
/// Mesh number of cells (Nr, Nphi, Nz)
G4ThreeVector fMeshNbOfCells = { 40, 50, 48 };
/// Mesh size of cells (dr, dphi, dz).
G4ThreeVector fMeshSizeOfCells = { 5 * mm, 2 * CLHEP::pi / 50 * CLHEP::rad, 5 * mm };
private:
/// Messenger that allows to modify geometry
Par04DetectorMessenger* fDetectorMessenger = nullptr;
/// Inner radius of the cylindrical detector
G4double fDetectorInnerRadius = 80 * cm;
/// Length of the cylindrical detector (along z axis)
G4double fDetectorLength = 24 * cm;
/// Logical volume(s) of the sensitive absorbers
std::vector<G4LogicalVolume*> fLayerLogical;
/// Material(s) of the layers
std::array<G4Material*, 2> fAbsorberMaterial = {nullptr, nullptr};
/// Thickness(es) of the layers
std::array<G4double, 2> fAbsorberThickness = {1 * cm, 0};
/// Sensitivity of the layers
std::array<G4bool, 2> fAbsorberSensitivity = {true, 0};
/// Number of layers = slices along z axis
G4int fNbOfLayers = 24;
/// Mesh number of cells (Nr, Nphi, Nz)
G4ThreeVector fMeshNbOfCells = {40, 50, 48};
/// Mesh size of cells (dr, dphi, dz).
G4ThreeVector fMeshSizeOfCells = {5 * mm, 2 * CLHEP::pi / 50 * CLHEP::rad, 5 * mm};
};
#endif /* PAR04DETECTORCONSTRUCTION_H */
@@ -27,8 +27,9 @@
#ifndef PAR04DETECTORMESSENGER_H
#define PAR04DETECTORMESSENGER_H
#include <G4String.hh> // for G4String
#include "G4UImessenger.hh" // for G4UImessenger
#include <G4String.hh> // for G4String
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAnInteger;
class G4UIcmdWithoutParameter;
@@ -47,45 +48,45 @@ class Par04DetectorConstruction;
class Par04DetectorMessenger : public G4UImessenger
{
public:
Par04DetectorMessenger(Par04DetectorConstruction*);
~Par04DetectorMessenger();
public:
Par04DetectorMessenger(Par04DetectorConstruction*);
~Par04DetectorMessenger();
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
private:
/// Detector construction to setup
Par04DetectorConstruction* fDetector = nullptr;
/// Command to set the directory common to all messengers in this example
/// /Par04
G4UIdirectory* fExampleDir = nullptr;
/// Command to set the directory for detector settings /Par04/detector
G4UIdirectory* fDetectorDir = nullptr;
/// Command printing current settings
G4UIcmdWithoutParameter* fPrintCmd;
/// Command to set the detector inner radius
G4UIcmdWithADoubleAndUnit* fDetectorInnerRadiusCmd = nullptr;
/// Command to set the detector length
G4UIcmdWithADoubleAndUnit* fDetectorLengthCmd = nullptr;
/// Command to set the number of layers
G4UIcmdWithAnInteger* fNbLayersCmd = nullptr;
/// Commanbd to set the absorbers within layers (material, thickness, sensitivity)
G4UIcommand* fAbsorCmd = nullptr;
/// Command to set the directory for sensitive detector settings /Par04/mesh
G4UIdirectory* fMeshDir = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along rho axis)
G4UIcmdWithAnInteger* fMeshNbRhoCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along phi axis)
G4UIcmdWithAnInteger* fMeshNbPhiCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along z axis)
G4UIcmdWithAnInteger* fMeshNbZCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along rho axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeRhoCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along z axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeZCellsCmd = nullptr;
private:
/// Detector construction to setup
Par04DetectorConstruction* fDetector = nullptr;
/// Command to set the directory common to all messengers in this example
/// /Par04
G4UIdirectory* fExampleDir = nullptr;
/// Command to set the directory for detector settings /Par04/detector
G4UIdirectory* fDetectorDir = nullptr;
/// Command printing current settings
G4UIcmdWithoutParameter* fPrintCmd;
/// Command to set the detector inner radius
G4UIcmdWithADoubleAndUnit* fDetectorInnerRadiusCmd = nullptr;
/// Command to set the detector length
G4UIcmdWithADoubleAndUnit* fDetectorLengthCmd = nullptr;
/// Command to set the number of layers
G4UIcmdWithAnInteger* fNbLayersCmd = nullptr;
/// Commanbd to set the absorbers within layers (material, thickness, sensitivity)
G4UIcommand* fAbsorCmd = nullptr;
/// Command to set the directory for sensitive detector settings /Par04/mesh
G4UIdirectory* fMeshDir = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along rho axis)
G4UIcmdWithAnInteger* fMeshNbRhoCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along phi axis)
G4UIcmdWithAnInteger* fMeshNbPhiCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along z axis)
G4UIcmdWithAnInteger* fMeshNbZCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along rho axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeRhoCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along z axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeZCellsCmd = nullptr;
};
#endif
@@ -26,10 +26,11 @@
#ifndef PAR04EVENTACTION_HH
#define PAR04EVENTACTION_HH
#include <G4Types.hh> // for G4int, G4double
#include <vector> // for vector
#include "G4Timer.hh" // for G4Timer
#include "G4Timer.hh" // for G4Timer
#include "G4UserEventAction.hh" // for G4UserEventAction
#include <G4Types.hh> // for G4int, G4double
#include <vector> // for vector
class G4Event;
class Par04DetectorConstruction;
class Par04ParallelFullWorld;
@@ -46,69 +47,70 @@ class Par04ParallelFullWorld;
class Par04EventAction : public G4UserEventAction
{
public:
Par04EventAction(Par04DetectorConstruction* aDetector, Par04ParallelFullWorld* aParallel);
virtual ~Par04EventAction();
public:
Par04EventAction(Par04DetectorConstruction* aDetector, Par04ParallelFullWorld* aParallel);
virtual ~Par04EventAction();
/// Timer is started
virtual void BeginOfEventAction(const G4Event* aEvent) final;
/// Hits collection is retrieved, analysed, and histograms are filled.
virtual void EndOfEventAction(const G4Event* aEvent) final;
inline std::vector<G4double>& GetCalEdep() { return fCalEdep; }
inline std::vector<G4int>& GetCalRho() { return fCalRho; }
inline std::vector<G4int>& GetCalPhi() { return fCalPhi; }
inline std::vector<G4int>& GetCalZ() { return fCalZ; }
inline std::vector<G4double>& GetPhysicalCalEdep() { return fCalPhysicalEdep; }
inline std::vector<G4int>& GetPhysicalCalLayer() { return fCalPhysicalLayer; }
inline std::vector<G4int>& GetPhysicalCalSlice() { return fCalPhysicalSlice; }
inline std::vector<G4int>& GetPhysicalCalRow() { return fCalPhysicalRow; }
void StartTimer();
void StopTimer();
private:
/// ID of a hit collection to analyse
G4int fHitCollectionID = -1;
G4int fPhysicalFullHitCollectionID = -1;
G4int fPhysicalFastHitCollectionID = -1;
/// Timer measurement from Geant4
G4Timer fTimer;
/// Pointer to detector construction to retrieve (once) the detector
/// dimensions and size of readout
Par04DetectorConstruction* fDetector = nullptr;
Par04ParallelFullWorld* fParallel = nullptr;
/// Size of cell along Z axis
G4double fCellSizeZ = 0;
/// Size of cell along radius of cylinder
G4double fCellSizeRho = 0;
/// Size of cell in azimuthal angle
G4double fCellSizePhi = 0;
/// Number of readout cells along radius
G4int fCellNbRho = 0;
/// Number of readout cells in azimuthal angle
G4int fCellNbPhi = 0;
/// Number of readout cells along z axis
G4int fCellNbZ = 0;
/// Number of physical readout layers
G4int fPhysicalNbLayers = 0;
/// Number of physical readout slices
G4int fPhysicalNbSlices = 0;
/// Number of physical readout rows
G4int fPhysicalNbRows = 0;
/// Cell energy deposits to be stored in ntuple
std::vector<G4double> fCalEdep;
/// Cell ID of radius to be stored in ntuple
std::vector<G4int> fCalRho;
/// Cell ID of azimuthal angle to be stored in ntuple
std::vector<G4int> fCalPhi;
/// Cell ID of z axis to be stored in ntuple
std::vector<G4int> fCalZ;
/// Physical cell energy deposits to be stored in ntuple
std::vector<G4double> fCalPhysicalEdep;
/// Physical layer ID to be stored in ntuple
std::vector<G4int> fCalPhysicalLayer;
/// Physical slice ID to be stored in ntuple
std::vector<G4int> fCalPhysicalSlice;
/// Physical row ID to be stored in ntuple
std::vector<G4int> fCalPhysicalRow;
/// Timer is started
virtual void BeginOfEventAction(const G4Event* aEvent) final;
/// Hits collection is retrieved, analysed, and histograms are filled.
virtual void EndOfEventAction(const G4Event* aEvent) final;
inline std::vector<G4double>& GetCalEdep() { return fCalEdep; }
inline std::vector<G4int>& GetCalRho() { return fCalRho; }
inline std::vector<G4int>& GetCalPhi() { return fCalPhi; }
inline std::vector<G4int>& GetCalZ() { return fCalZ; }
inline std::vector<G4double>& GetPhysicalCalEdep() { return fCalPhysicalEdep; }
inline std::vector<G4int>& GetPhysicalCalLayer() { return fCalPhysicalLayer; }
inline std::vector<G4int>& GetPhysicalCalSlice() { return fCalPhysicalSlice; }
inline std::vector<G4int>& GetPhysicalCalRow() { return fCalPhysicalRow; }
void StartTimer();
void StopTimer();
private:
/// ID of a hit collection to analyse
G4int fHitCollectionID = -1;
G4int fPhysicalFullHitCollectionID = -1;
G4int fPhysicalFastHitCollectionID = -1;
/// Timer measurement from Geant4
G4Timer fTimer;
/// Pointer to detector construction to retrieve (once) the detector
/// dimensions and size of readout
Par04DetectorConstruction* fDetector = nullptr;
Par04ParallelFullWorld* fParallel = nullptr;
/// Size of cell along Z axis
G4double fCellSizeZ = 0;
/// Size of cell along radius of cylinder
G4double fCellSizeRho = 0;
/// Size of cell in azimuthal angle
G4double fCellSizePhi = 0;
/// Number of readout cells along radius
G4int fCellNbRho = 0;
/// Number of readout cells in azimuthal angle
G4int fCellNbPhi = 0;
/// Number of readout cells along z axis
G4int fCellNbZ = 0;
/// Number of physical readout layers
G4int fPhysicalNbLayers = 0;
/// Number of physical readout slices
G4int fPhysicalNbSlices = 0;
/// Number of physical readout rows
G4int fPhysicalNbRows = 0;
/// Cell energy deposits to be stored in ntuple
std::vector<G4double> fCalEdep;
/// Cell ID of radius to be stored in ntuple
std::vector<G4int> fCalRho;
/// Cell ID of azimuthal angle to be stored in ntuple
std::vector<G4int> fCalPhi;
/// Cell ID of z axis to be stored in ntuple
std::vector<G4int> fCalZ;
/// Physical cell energy deposits to be stored in ntuple
std::vector<G4double> fCalPhysicalEdep;
/// Physical layer ID to be stored in ntuple
std::vector<G4int> fCalPhysicalLayer;
/// Physical slice ID to be stored in ntuple
std::vector<G4int> fCalPhysicalSlice;
/// Physical row ID to be stored in ntuple
std::vector<G4int> fCalPhysicalRow;
};
#endif /* PAR04EVENTACTION_HH */
@@ -26,9 +26,10 @@
#ifndef PAR04EVENTINFORMATION_HH
#define PAR04EVENTINFORMATION_HH
#include <G4Types.hh> // for G4bool
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VUserEventInformation.hh" // for G4VUserEventInformation
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VUserEventInformation.hh" // for G4VUserEventInformation
#include <G4Types.hh> // for G4bool
/**
* @brief Event information
@@ -41,32 +42,32 @@
class Par04EventInformation : public G4VUserEventInformation
{
public:
Par04EventInformation();
virtual ~Par04EventInformation();
public:
Par04EventInformation();
virtual ~Par04EventInformation();
/// Set particle direction
inline void SetDirection(const G4ThreeVector& aDirection) { fDirection = aDirection; };
/// Get particle direction
inline G4ThreeVector GetDirection() const { return fDirection; };
/// Set particle position
inline void SetPosition(const G4ThreeVector& aPosition) { fPosition = aPosition; };
/// Get particle position
inline G4ThreeVector GetPosition() const { return fPosition; };
/// Set flag
inline void SetFlag(G4bool aFlag) { fIfSet = aFlag; };
/// Get flag
inline G4bool GetFlag() const { return fIfSet; };
/// Print
void Print() const final;
/// Set particle direction
inline void SetDirection(const G4ThreeVector& aDirection) { fDirection = aDirection; };
/// Get particle direction
inline G4ThreeVector GetDirection() const { return fDirection; };
/// Set particle position
inline void SetPosition(const G4ThreeVector& aPosition) { fPosition = aPosition; };
/// Get particle position
inline G4ThreeVector GetPosition() const { return fPosition; };
/// Set flag
inline void SetFlag(G4bool aFlag) { fIfSet = aFlag; };
/// Get flag
inline G4bool GetFlag() const { return fIfSet; };
/// Print
void Print() const final;
private:
/// Particle direction. By default equal to the default particle gun direction.
G4ThreeVector fDirection = { 0, 1, 0 };
/// Particle position. By default equal to the default inner radius.
G4ThreeVector fPosition = { 0, 800, 0 };
/// Flag
G4bool fIfSet = false;
private:
/// Particle direction. By default equal to the default particle gun direction.
G4ThreeVector fDirection = {0, 1, 0};
/// Particle position. By default equal to the default inner radius.
G4ThreeVector fPosition = {0, 800, 0};
/// Flag
G4bool fIfSet = false;
};
#endif /* PAR04EVENTINFORMATION_HH */
@@ -26,16 +26,17 @@
#ifndef PAR04HIT_HH
#define PAR04HIT_HH
#include <stddef.h> // for size_t
#include <G4Types.hh> // for G4int, G4double
#include <map> // for map
#include <tls.hh> // for G4ThreadLocal
#include <vector> // for vector
#include "G4Allocator.hh" // for G4Allocator
#include "G4RotationMatrix.hh" // for G4RotationMatrix
#include "G4THitsCollection.hh" // for G4THitsCollection
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VHit.hh" // for G4VHit
#include "G4Allocator.hh" // for G4Allocator
#include "G4RotationMatrix.hh" // for G4RotationMatrix
#include "G4THitsCollection.hh" // for G4THitsCollection
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VHit.hh" // for G4VHit
#include <G4Types.hh> // for G4int, G4double
#include <map> // for map
#include <stddef.h> // for size_t
#include <tls.hh> // for G4ThreadLocal
#include <vector> // for vector
class G4AttDef;
class G4AttValue;
class G4LogicalVolume;
@@ -55,91 +56,91 @@ class G4String;
class Par04Hit : public G4VHit
{
public:
Par04Hit();
Par04Hit(const Par04Hit& aRight);
virtual ~Par04Hit();
public:
Par04Hit();
Par04Hit(const Par04Hit& aRight);
virtual ~Par04Hit();
const Par04Hit& operator=(const Par04Hit& aRight);
int operator==(const Par04Hit& aRight) const;
const Par04Hit& operator=(const Par04Hit& aRight);
int operator==(const Par04Hit& aRight) const;
inline void* operator new(size_t);
inline void operator delete(void* aHit);
/// Visualise hits. If pointer to the logical volume was set, cell shape is
/// drawn taking into account proper radial position (taken from fRhoId)
virtual void Draw() final;
/// Retrieve atributes' names in order to allow filtering
virtual const std::map<G4String, G4AttDef>* GetAttDefs() const final;
/// Create attributes for the visualisation.
virtual std::vector<G4AttValue>* CreateAttValues() const final;
/// Print hit properties.
virtual void Print() final;
/// Set position
inline void SetPos(G4ThreeVector aXYZ) { fPos = aXYZ; }
/// Get position
inline G4ThreeVector GetPos() const { return fPos; }
/// Set rotation
inline void SetRot(G4RotationMatrix aXYZ) { fRot = aXYZ; }
/// Get rotation
inline G4RotationMatrix GetRot() const { return fRot; }
/// Set energy
inline void SetEdep(G4double aEdep) { fEdep = aEdep; }
/// Add energy to previous value
inline void AddEdep(G4double aEdep) { fEdep += aEdep; }
/// Get energy
inline G4double GetEdep() const { return fEdep; }
/// Set number of deposits per hit/cell
inline void SetNdep(G4int aNdep) { fNdep = aNdep; }
/// Add number of deposits to previous value, by defualt increment
inline void AddNdep(G4int aNdep = 1) { fNdep += aNdep; }
/// Get number of deposits per hit/cell
inline G4int GetNdep() const { return fNdep; }
/// Set Z id of the cell in the readout segmentation
inline void SetZid(G4int aZ) { fZId = aZ; }
/// Get Z id of the cell in the readout segmentation
inline G4int GetZid() const { return fZId; }
/// Set Rho id of the cell in the readout segmentation
inline void SetRhoId(G4int aRho) { fRhoId = aRho; }
/// Get rho id of the cell in the readout segmentation
inline G4int GetRhoId() const { return fRhoId; }
/// Set phi id of the cell in the readout segmentation
inline void SetPhiId(G4int aPhi) { fPhiId = aPhi; }
/// Get phi id of the cell in the readout segmentation
inline G4int GetPhiId() const { return fPhiId; }
/// Set time
inline void SetTime(G4double aTime) { fTime = aTime; }
/// Get time
inline G4double GetTime() const { return fTime; }
/// Set type (0 = full sim, 1 = fast sim)
inline void SetType(G4int aType) { fType = aType; }
/// Get type (0 = full sim, 1 = fast sim)
inline G4int GetType() const { return fType; }
// Set pointer to cell logical volume
inline void SetLogV(G4LogicalVolume* aLogVol) { fLogVol = aLogVol; }
// Get pointer to cell logical volume
inline const G4LogicalVolume* GetLogVol() { return fLogVol; }
inline void* operator new(size_t);
inline void operator delete(void* aHit);
/// Visualise hits. If pointer to the logical volume was set, cell shape is
/// drawn taking into account proper radial position (taken from fRhoId)
virtual void Draw() final;
/// Retrieve atributes' names in order to allow filtering
virtual const std::map<G4String, G4AttDef>* GetAttDefs() const final;
/// Create attributes for the visualisation.
virtual std::vector<G4AttValue>* CreateAttValues() const final;
/// Print hit properties.
virtual void Print() final;
/// Set position
inline void SetPos(G4ThreeVector aXYZ) { fPos = aXYZ; }
/// Get position
inline G4ThreeVector GetPos() const { return fPos; }
/// Set rotation
inline void SetRot(G4RotationMatrix aXYZ) { fRot = aXYZ; }
/// Get rotation
inline G4RotationMatrix GetRot() const { return fRot; }
/// Set energy
inline void SetEdep(G4double aEdep) { fEdep = aEdep; }
/// Add energy to previous value
inline void AddEdep(G4double aEdep) { fEdep += aEdep; }
/// Get energy
inline G4double GetEdep() const { return fEdep; }
/// Set number of deposits per hit/cell
inline void SetNdep(G4int aNdep) { fNdep = aNdep; }
/// Add number of deposits to previous value, by defualt increment
inline void AddNdep(G4int aNdep = 1) { fNdep += aNdep; }
/// Get number of deposits per hit/cell
inline G4int GetNdep() const { return fNdep; }
/// Set Z id of the cell in the readout segmentation
inline void SetZid(G4int aZ) { fZId = aZ; }
/// Get Z id of the cell in the readout segmentation
inline G4int GetZid() const { return fZId; }
/// Set Rho id of the cell in the readout segmentation
inline void SetRhoId(G4int aRho) { fRhoId = aRho; }
/// Get rho id of the cell in the readout segmentation
inline G4int GetRhoId() const { return fRhoId; }
/// Set phi id of the cell in the readout segmentation
inline void SetPhiId(G4int aPhi) { fPhiId = aPhi; }
/// Get phi id of the cell in the readout segmentation
inline G4int GetPhiId() const { return fPhiId; }
/// Set time
inline void SetTime(G4double aTime) { fTime = aTime; }
/// Get time
inline G4double GetTime() const { return fTime; }
/// Set type (0 = full sim, 1 = fast sim)
inline void SetType(G4int aType) { fType = aType; }
/// Get type (0 = full sim, 1 = fast sim)
inline G4int GetType() const { return fType; }
// Set pointer to cell logical volume
inline void SetLogV(G4LogicalVolume* aLogVol) { fLogVol = aLogVol; }
// Get pointer to cell logical volume
inline const G4LogicalVolume* GetLogVol() { return fLogVol; }
public:
/// Energy deposit
G4double fEdep = 0;
/// Counter of deposits in a hit/cell
G4int fNdep = 0;
/// Z ID of readout cell
G4int fZId = -1;
/// Rho ID of readout cell
G4int fRhoId = -1;
/// Phi ID of readout cell
G4int fPhiId = -1;
/// Position
G4ThreeVector fPos = { -1, -1, -1 };
/// Rotation
G4RotationMatrix fRot;
/// Time
G4double fTime = -1;
/// Type: 0 = full sim, 1 = fast sim
G4int fType = -1;
/// Pointer to logical volume for visualisation
G4LogicalVolume* fLogVol = nullptr;
public:
/// Energy deposit
G4double fEdep = 0;
/// Counter of deposits in a hit/cell
G4int fNdep = 0;
/// Z ID of readout cell
G4int fZId = -1;
/// Rho ID of readout cell
G4int fRhoId = -1;
/// Phi ID of readout cell
G4int fPhiId = -1;
/// Position
G4ThreeVector fPos = {-1, -1, -1};
/// Rotation
G4RotationMatrix fRot;
/// Time
G4double fTime = -1;
/// Type: 0 = full sim, 1 = fast sim
G4int fType = -1;
/// Pointer to logical volume for visualisation
G4LogicalVolume* fLogVol = nullptr;
};
typedef G4THitsCollection<Par04Hit> Par04HitsCollection;
@@ -148,14 +149,13 @@ extern G4ThreadLocal G4Allocator<Par04Hit>* Par04HitAllocator;
inline void* Par04Hit::operator new(size_t)
{
if(!Par04HitAllocator)
Par04HitAllocator = new G4Allocator<Par04Hit>;
return (void*) Par04HitAllocator->MallocSingle();
if (!Par04HitAllocator) Par04HitAllocator = new G4Allocator<Par04Hit>;
return (void*)Par04HitAllocator->MallocSingle();
}
inline void Par04Hit::operator delete(void* aHit)
{
Par04HitAllocator->FreeSingle((Par04Hit*) aHit);
Par04HitAllocator->FreeSingle((Par04Hit*)aHit);
}
#endif /* PAR04HIT_HH */
@@ -24,11 +24,12 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#ifndef PAR04INFERENCEINTERFACE_HH
#define PAR04INFERENCEINTERFACE_HH
# ifndef PAR04INFERENCEINTERFACE_HH
# define PAR04INFERENCEINTERFACE_HH
#include "globals.hh"
#include <vector>
# include "globals.hh"
# include <vector>
/**
* @brief Inference interface
@@ -39,16 +40,16 @@
class Par04InferenceInterface
{
public:
virtual ~Par04InferenceInterface(){};
public:
virtual ~Par04InferenceInterface() {};
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
virtual void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies,
int aSize) = 0;
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
virtual void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies,
int aSize) = 0;
};
#endif /* PAR04INFERENCEINTERFACE_HH */
# endif /* PAR04INFERENCEINTERFACE_HH */
#endif
@@ -24,11 +24,12 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#ifndef PAR04INFERENCEMESSENGER_H
#define PAR04INFERENCEMESSENGER_H
# ifndef PAR04INFERENCEMESSENGER_H
# define PAR04INFERENCEMESSENGER_H
#include "G4UImessenger.hh" // for G4UImessenger
#include <G4String.hh> // for G4String
# include "G4UImessenger.hh" // for G4UImessenger
# include <G4String.hh> // for G4String
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
@@ -47,62 +48,63 @@ class Par04InferenceSetup;
*
*/
class Par04InferenceMessenger : public G4UImessenger {
public:
Par04InferenceMessenger(Par04InferenceSetup *);
~Par04InferenceMessenger();
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand *, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand *) final;
class Par04InferenceMessenger : public G4UImessenger
{
public:
Par04InferenceMessenger(Par04InferenceSetup*);
~Par04InferenceMessenger();
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
private:
/// Inference to setup
Par04InferenceSetup *fInference = nullptr;
/// Command to set the directory common to all inference messengers in this
/// example /Par04
G4UIdirectory *fExampleDir = nullptr;
/// Command to set the directory for inference settings /Par04/inference
G4UIdirectory *fInferenceDir = nullptr;
/// Command to set the inference library
G4UIcmdWithAString *fInferenceLibraryCmd = nullptr;
/// Command to set fModelPathNameCmd
G4UIcmdWithAString *fModelPathNameCmd = nullptr;
/// Command to set the fSizeLatentVectorCmd
G4UIcmdWithAnInteger *fSizeLatentVectorCmd = nullptr;
/// Command to set the fSizeConditionVectorCmd
G4UIcmdWithAnInteger *fSizeConditionVectorCmd = nullptr;
/// Command to set the fProfileFlagCmd
G4UIcmdWithAnInteger *fProfileFlagCmd = nullptr;
/// Command to set the fOptimizationFlagCmd
G4UIcmdWithAnInteger *fOptimizationFlagCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// rho axis)
G4UIcmdWithAnInteger *fMeshNbRhoCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// phi axis)
G4UIcmdWithAnInteger *fMeshNbPhiCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// z axis)
G4UIcmdWithAnInteger *fMeshNbZCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along rho
/// axis)
G4UIcmdWithADoubleAndUnit *fMeshSizeRhoCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along z
/// axis)
G4UIcmdWithADoubleAndUnit *fMeshSizeZCellsCmd = nullptr;
/// Commands to set execution provider flags
/// GPU
G4UIcmdWithAnInteger *fCudaFlagCmd = nullptr;
/// Cuda Commands
G4UIdirectory *fCudaOptionsDir = nullptr;
G4UIcmdWithAString *fCudaDeviceIdCmd = nullptr;
G4UIcmdWithAString *fCudaGpuMemLimitCmd = nullptr;
G4UIcmdWithAString *fCudaArenaExtendedStrategyCmd = nullptr;
G4UIcmdWithAString *fCudaCudnnConvAlgoSearchCmd = nullptr;
G4UIcmdWithAString *fCudaDoCopyInDefaultStreamCmd = nullptr;
G4UIcmdWithAString *fCudaCudnnConvUseMaxWorkspaceCmd = nullptr;
private:
/// Inference to setup
Par04InferenceSetup* fInference = nullptr;
/// Command to set the directory common to all inference messengers in this
/// example /Par04
G4UIdirectory* fExampleDir = nullptr;
/// Command to set the directory for inference settings /Par04/inference
G4UIdirectory* fInferenceDir = nullptr;
/// Command to set the inference library
G4UIcmdWithAString* fInferenceLibraryCmd = nullptr;
/// Command to set fModelPathNameCmd
G4UIcmdWithAString* fModelPathNameCmd = nullptr;
/// Command to set the fSizeLatentVectorCmd
G4UIcmdWithAnInteger* fSizeLatentVectorCmd = nullptr;
/// Command to set the fSizeConditionVectorCmd
G4UIcmdWithAnInteger* fSizeConditionVectorCmd = nullptr;
/// Command to set the fProfileFlagCmd
G4UIcmdWithAnInteger* fProfileFlagCmd = nullptr;
/// Command to set the fOptimizationFlagCmd
G4UIcmdWithAnInteger* fOptimizationFlagCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// rho axis)
G4UIcmdWithAnInteger* fMeshNbRhoCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// phi axis)
G4UIcmdWithAnInteger* fMeshNbPhiCellsCmd = nullptr;
/// Command to set the number of cells in the cylindrical readout mesh (along
/// z axis)
G4UIcmdWithAnInteger* fMeshNbZCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along rho
/// axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeRhoCellsCmd = nullptr;
/// Command to the size of cells in the cylindrical readout mesh (along z
/// axis)
G4UIcmdWithADoubleAndUnit* fMeshSizeZCellsCmd = nullptr;
/// Commands to set execution provider flags
/// GPU
G4UIcmdWithAnInteger* fCudaFlagCmd = nullptr;
/// Cuda Commands
G4UIdirectory* fCudaOptionsDir = nullptr;
G4UIcmdWithAString* fCudaDeviceIdCmd = nullptr;
G4UIcmdWithAString* fCudaGpuMemLimitCmd = nullptr;
G4UIcmdWithAString* fCudaArenaExtendedStrategyCmd = nullptr;
G4UIcmdWithAString* fCudaCudnnConvAlgoSearchCmd = nullptr;
G4UIcmdWithAString* fCudaDoCopyInDefaultStreamCmd = nullptr;
G4UIcmdWithAString* fCudaCudnnConvUseMaxWorkspaceCmd = nullptr;
};
#endif
# endif
#endif
@@ -24,16 +24,18 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#ifndef PAR04INFEERENCESETUP_HH
#define PAR04INFEERENCESETUP_HH
# ifndef PAR04INFEERENCESETUP_HH
# define PAR04INFEERENCESETUP_HH
#include "CLHEP/Units/SystemOfUnits.h" // for mm
#include "G4ThreeVector.hh" // for G4ThreeVector
#include <G4String.hh> // for G4String
#include <G4SystemOfUnits.hh> // for mm
#include <G4Types.hh> // for G4int, G4double, G4bool, G4f...
#include <memory> // for unique_ptr
#include <vector> // for vector
# include "CLHEP/Units/SystemOfUnits.h" // for mm
# include "G4ThreeVector.hh" // for G4ThreeVector
# include <G4String.hh> // for G4String
# include <G4SystemOfUnits.hh> // for mm
# include <G4Types.hh> // for G4int, G4double, G4bool, G4f...
# include <memory> // for unique_ptr
# include <vector> // for vector
class Par04DetectorConstruction;
class Par04InferenceInterface;
class Par04InferenceMessenger;
@@ -53,206 +55,190 @@ class Par04InferenceMessenger;
*
**/
class Par04InferenceSetup {
public:
Par04InferenceSetup();
~Par04InferenceSetup();
class Par04InferenceSetup
{
public:
Par04InferenceSetup();
~Par04InferenceSetup();
/// Geometry setup
/// Check if inference should be performed for the particle
/// @param[in] aEnergy Particle's energy
G4bool IfTrigger(G4double aEnergy);
/// Set mesh size.
/// @param aSize (x,y,x) size for Carthesian coordinates, or (R, phi, z) for
/// cylindrical coordinates.
inline void SetMeshSize(const G4ThreeVector &aSize) { fMeshSize = aSize; };
/// Get mesh size.
/// @return G4ThreeVector (x,y,x) size for Carthesian coordinates, or (R, phi,
/// z) for cylindrical coordinates.
inline G4ThreeVector GetMeshSize() const { return fMeshSize; };
/// Set number of mesh cells.
/// @param aSize (x,y,x) size for Carthesian coordinates, or (R, phi, z) for
/// cylindrical coordinates.
inline void SetMeshNumber(const G4ThreeVector &aSize) {
fMeshNumber = aSize;
};
/// Get number of mesh cells.
/// @return G4ThreeVector (x,y,x) size for Carthesian coordinates, or (R, phi,
/// z) for cylindrical coordinates.
inline G4ThreeVector GetMeshNumber() const { return fMeshNumber; };
/// Set size of the condition vector
inline void SetSizeConditionVector(G4int aNumber) {
fSizeConditionVector = aNumber;
};
/// Get size of the condition vector
inline G4int GetSizeConditionVector() const { return fSizeConditionVector; };
/// Set size of the latent space vector
inline void SetSizeLatentVector(G4int aNumber) {
fSizeLatentVector = aNumber;
};
/// Get size of the latent space vector
inline G4int GetSizeLatentVector() const { return fSizeLatentVector; };
/// Set path and name of the model
inline void SetModelPathName(G4String aName) { fModelPathName = aName; };
/// Get path and name of the model
inline G4String GetModelPathName() const { return fModelPathName; };
/// Set profiling flag
inline void SetProfileFlag(G4int aNumber) { fProfileFlag = aNumber; };
/// Get profiling flag
inline G4int GetProfileFlag() const { return fProfileFlag; };
/// Set optimization flag
inline void SetOptimizationFlag(G4int aNumber) {
fOptimizationFlag = aNumber;
};
/// Get optimization flag
inline G4int GetOptimizationFlag() const { return fOptimizationFlag; };
/// Get name of the inference library
inline G4String GetInferenceLibrary() const { return fInferenceLibrary; };
/// Set name of the inference library and create a pointer to chosen inference
/// interface
void SetInferenceLibrary(G4String aName);
/// Check settings of the inference library
void CheckInferenceLibrary();
/// Set number of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshNbOfCells(G4ThreeVector aNb) { fMeshNumber = aNb; };
/// Set number of Mesh cells in cylindrical coordinates
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshNbOfCells(G4int aIndex, G4double aNb) {
fMeshNumber[aIndex] = aNb;
};
/// Get number of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshNbOfCells() const { return fMeshNumber; };
/// Set size of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshSizeOfCells(G4ThreeVector aNb) { fMeshSize = aNb; };
/// Set size of Mesh cells in cylindrical coordinates
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshSizeOfCells(G4int aIndex, G4double aNb) {
fMeshSize[aIndex] = aNb;
};
/// Get size of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshSizeOfCells() const { return fMeshSize; };
/// Setting execution providers flags
/// GPU
inline void SetCudaFlag(G4int aNumber) { fCudaFlag = aNumber; };
inline G4int GetCudaFlag() const { return fCudaFlag; };
/// Setting execution providers Options
/// Cuda
inline void SetCudaDeviceId(G4String aNumber) { fCudaDeviceId = aNumber; };
inline G4String GetCudaDeviceId() const { return fCudaDeviceId; };
inline void SetCudaGpuMemLimit(G4String aNumber) {
fCudaGpuMemLimit = aNumber;
};
inline G4String GetCudaGpuMemLimit() const { return fCudaGpuMemLimit; };
inline void SetCudaArenaExtendedStrategy(G4String aNumber) {
fCudaArenaExtendedStrategy = aNumber;
};
inline G4String GetCudaArenaExtendedStrategy() const {
return fCudaArenaExtendedStrategy;
};
inline void SetCudaCudnnConvAlgoSearch(G4String aNumber) {
fCudaCudnnConvAlgoSearch = aNumber;
};
inline G4String GetCudaCudnnConvAlgoSearch() const {
return fCudaCudnnConvAlgoSearch;
};
inline void SetCudaDoCopyInDefaultStream(G4String aNumber) {
fCudaDoCopyInDefaultStream = aNumber;
};
inline G4String GetCudaDoCopyInDefaultStream() const {
return fCudaDoCopyInDefaultStream;
};
inline void SetCudaCudnnConvUseMaxWorkspace(G4String aNumber) {
fCudaCudnnConvUseMaxWorkspace = aNumber;
};
inline G4String GetCudaCudnnConvUseMaxWorkspace() const {
return fCudaCudnnConvUseMaxWorkspace;
};
/// Geometry setup
/// Check if inference should be performed for the particle
/// @param[in] aEnergy Particle's energy
G4bool IfTrigger(G4double aEnergy);
/// Set mesh size.
/// @param aSize (x,y,x) size for Carthesian coordinates, or (R, phi, z) for
/// cylindrical coordinates.
inline void SetMeshSize(const G4ThreeVector& aSize) { fMeshSize = aSize; };
/// Get mesh size.
/// @return G4ThreeVector (x,y,x) size for Carthesian coordinates, or (R, phi,
/// z) for cylindrical coordinates.
inline G4ThreeVector GetMeshSize() const { return fMeshSize; };
/// Set number of mesh cells.
/// @param aSize (x,y,x) size for Carthesian coordinates, or (R, phi, z) for
/// cylindrical coordinates.
inline void SetMeshNumber(const G4ThreeVector& aSize) { fMeshNumber = aSize; };
/// Get number of mesh cells.
/// @return G4ThreeVector (x,y,x) size for Carthesian coordinates, or (R, phi,
/// z) for cylindrical coordinates.
inline G4ThreeVector GetMeshNumber() const { return fMeshNumber; };
/// Set size of the condition vector
inline void SetSizeConditionVector(G4int aNumber) { fSizeConditionVector = aNumber; };
/// Get size of the condition vector
inline G4int GetSizeConditionVector() const { return fSizeConditionVector; };
/// Set size of the latent space vector
inline void SetSizeLatentVector(G4int aNumber) { fSizeLatentVector = aNumber; };
/// Get size of the latent space vector
inline G4int GetSizeLatentVector() const { return fSizeLatentVector; };
/// Set path and name of the model
inline void SetModelPathName(G4String aName) { fModelPathName = aName; };
/// Get path and name of the model
inline G4String GetModelPathName() const { return fModelPathName; };
/// Set profiling flag
inline void SetProfileFlag(G4int aNumber) { fProfileFlag = aNumber; };
/// Get profiling flag
inline G4int GetProfileFlag() const { return fProfileFlag; };
/// Set optimization flag
inline void SetOptimizationFlag(G4int aNumber) { fOptimizationFlag = aNumber; };
/// Get optimization flag
inline G4int GetOptimizationFlag() const { return fOptimizationFlag; };
/// Get name of the inference library
inline G4String GetInferenceLibrary() const { return fInferenceLibrary; };
/// Set name of the inference library and create a pointer to chosen inference
/// interface
void SetInferenceLibrary(G4String aName);
/// Check settings of the inference library
void CheckInferenceLibrary();
/// Set number of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshNbOfCells(G4ThreeVector aNb) { fMeshNumber = aNb; };
/// Set number of Mesh cells in cylindrical coordinates
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshNbOfCells(G4int aIndex, G4double aNb) { fMeshNumber[aIndex] = aNb; };
/// Get number of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshNbOfCells() const { return fMeshNumber; };
/// Set size of Mesh cells in cylindrical coordinates (r, phi, z)
inline void SetMeshSizeOfCells(G4ThreeVector aNb) { fMeshSize = aNb; };
/// Set size of Mesh cells in cylindrical coordinates
/// @param[in] aIndex index of cylindrical axis (0,1,2) = (r, phi, z)
inline void SetMeshSizeOfCells(G4int aIndex, G4double aNb) { fMeshSize[aIndex] = aNb; };
/// Get size of Mesh cells in cylindrical coordinates (r, phi, z)
inline G4ThreeVector GetMeshSizeOfCells() const { return fMeshSize; };
/// Setting execution providers flags
/// GPU
inline void SetCudaFlag(G4int aNumber) { fCudaFlag = aNumber; };
inline G4int GetCudaFlag() const { return fCudaFlag; };
/// Setting execution providers Options
/// Cuda
inline void SetCudaDeviceId(G4String aNumber) { fCudaDeviceId = aNumber; };
inline G4String GetCudaDeviceId() const { return fCudaDeviceId; };
inline void SetCudaGpuMemLimit(G4String aNumber) { fCudaGpuMemLimit = aNumber; };
inline G4String GetCudaGpuMemLimit() const { return fCudaGpuMemLimit; };
inline void SetCudaArenaExtendedStrategy(G4String aNumber)
{
fCudaArenaExtendedStrategy = aNumber;
};
inline G4String GetCudaArenaExtendedStrategy() const { return fCudaArenaExtendedStrategy; };
inline void SetCudaCudnnConvAlgoSearch(G4String aNumber)
{
fCudaCudnnConvAlgoSearch = aNumber;
};
inline G4String GetCudaCudnnConvAlgoSearch() const { return fCudaCudnnConvAlgoSearch; };
inline void SetCudaDoCopyInDefaultStream(G4String aNumber)
{
fCudaDoCopyInDefaultStream = aNumber;
};
inline G4String GetCudaDoCopyInDefaultStream() const { return fCudaDoCopyInDefaultStream; };
inline void SetCudaCudnnConvUseMaxWorkspace(G4String aNumber)
{
fCudaCudnnConvUseMaxWorkspace = aNumber;
};
inline G4String GetCudaCudnnConvUseMaxWorkspace() const
{
return fCudaCudnnConvUseMaxWorkspace;
};
/// Execute inference
/// @param[out] aDepositsEnergies of inferred energies deposited in the
/// detector
/// @param[in] aParticleEnergy Energy of initial particle
void GetEnergies(std::vector<G4double> &aEnergies, G4double aParticleEnergy,
G4float aInitialAngle);
/// Execute inference
/// @param[out] aDepositsEnergies of inferred energies deposited in the
/// detector
/// @param[in] aParticleEnergy Energy of initial particle
void GetEnergies(std::vector<G4double>& aEnergies, G4double aParticleEnergy,
G4float aInitialAngle);
/// Calculate positions
/// @param[out] aDepositsPositions Vector of positions corresponding to
/// energies deposited in the detector
/// @param[in] aParticlePosition Initial particle position which is centre of
/// transverse plane of the mesh
/// and beginning of the mesh in the longitudinal direction
/// @param[in] aParticleDirection Initial particle direction for the mesh
/// rotation
void GetPositions(std::vector<G4ThreeVector> &aDepositsPositions,
G4ThreeVector aParticlePosition,
G4ThreeVector aParticleDirection);
/// Calculate positions
/// @param[out] aDepositsPositions Vector of positions corresponding to
/// energies deposited in the detector
/// @param[in] aParticlePosition Initial particle position which is centre of
/// transverse plane of the mesh
/// and beginning of the mesh in the longitudinal direction
/// @param[in] aParticleDirection Initial particle direction for the mesh
/// rotation
void GetPositions(std::vector<G4ThreeVector>& aDepositsPositions,
G4ThreeVector aParticlePosition, G4ThreeVector aParticleDirection);
private:
/// Cell's size: (x,y,x) for Carthesian, and (R, phi, z) for cylindrical
/// coordinates Can be changed with UI command `/example/mesh/size <x y z>/<r
/// phi z> <unit>`. For cylindrical coordinates phi is ignored and calculated
/// from fMeshNumber.
G4ThreeVector fMeshSize =
G4ThreeVector(2.325 * CLHEP::mm, 1, 3.4 * CLHEP::mm);
/// Number of cells: (x,y,x) for Carthesian, and (R, phi, z) for cylindrical
/// coordinates. Can be changed with UI command `/example/mesh/number <Nx Ny
/// Nz>/<Nr Nphi Nz>`
G4ThreeVector fMeshNumber = G4ThreeVector(18, 50, 45);
/// Inference interface
std::unique_ptr<Par04InferenceInterface> fInferenceInterface;
/// Inference messenger
Par04InferenceMessenger *fInferenceMessenger;
/// Maximum particle energy value (in MeV) in the training range
float fMaxEnergy = 1024000.0;
/// Maximum particle angle (in degrees) in the training range
float fMaxAngle = 90.0;
/// Name of the inference library
G4String fInferenceLibrary = "ONNX";
/// Size of the latent space vector
G4int fSizeLatentVector = 10;
/// Size of the condition vector
G4int fSizeConditionVector = 4;
/// Name of the inference library
G4String fModelPathName = "MLModels/Generator.onnx";
/// ONNX specific
/// Profiling flag
G4bool fProfileFlag = false;
/// Optimization flag
G4bool fOptimizationFlag = false;
/// Optimization file
G4String fModelSavePath = "MLModels/Optimized-Generator.onnx";
/// Profiling file
G4String fProfilingOutputSavePath = "opt.json";
/// Intra-operation number of threads
G4int fIntraOpNumThreads = 1;
/// Flags for execution providers
/// GPU
G4bool fCudaFlag = false;
/// Execution Provider Options
/// Cuda options
G4String fCudaDeviceId = "0";
G4String fCudaGpuMemLimit = "2147483648";
G4String fCudaArenaExtendedStrategy = "kSameAsRequested";
G4String fCudaCudnnConvAlgoSearch = "DEFAULT";
G4String fCudaDoCopyInDefaultStream = "1";
G4String fCudaCudnnConvUseMaxWorkspace = "1";
std::vector<const char *> cuda_keys{
private:
/// Cell's size: (x,y,x) for Carthesian, and (R, phi, z) for cylindrical
/// coordinates Can be changed with UI command `/example/mesh/size <x y z>/<r
/// phi z> <unit>`. For cylindrical coordinates phi is ignored and calculated
/// from fMeshNumber.
G4ThreeVector fMeshSize = G4ThreeVector(2.325 * CLHEP::mm, 1, 3.4 * CLHEP::mm);
/// Number of cells: (x,y,x) for Carthesian, and (R, phi, z) for cylindrical
/// coordinates. Can be changed with UI command `/example/mesh/number <Nx Ny
/// Nz>/<Nr Nphi Nz>`
G4ThreeVector fMeshNumber = G4ThreeVector(18, 50, 45);
/// Inference interface
std::unique_ptr<Par04InferenceInterface> fInferenceInterface;
/// Inference messenger
Par04InferenceMessenger* fInferenceMessenger;
/// Maximum particle energy value (in MeV) in the training range
float fMaxEnergy = 1024000.0;
/// Maximum particle angle (in degrees) in the training range
float fMaxAngle = 90.0;
/// Name of the inference library
G4String fInferenceLibrary = "ONNX";
/// Size of the latent space vector
G4int fSizeLatentVector = 10;
/// Size of the condition vector
G4int fSizeConditionVector = 4;
/// Name of the inference library
G4String fModelPathName = "MLModels/Generator.onnx";
/// ONNX specific
/// Profiling flag
G4bool fProfileFlag = false;
/// Optimization flag
G4bool fOptimizationFlag = false;
/// Optimization file
G4String fModelSavePath = "MLModels/Optimized-Generator.onnx";
/// Profiling file
G4String fProfilingOutputSavePath = "opt.json";
/// Intra-operation number of threads
G4int fIntraOpNumThreads = 1;
/// Flags for execution providers
/// GPU
G4bool fCudaFlag = false;
/// Execution Provider Options
/// Cuda options
G4String fCudaDeviceId = "0";
G4String fCudaGpuMemLimit = "2147483648";
G4String fCudaArenaExtendedStrategy = "kSameAsRequested";
G4String fCudaCudnnConvAlgoSearch = "DEFAULT";
G4String fCudaDoCopyInDefaultStream = "1";
G4String fCudaCudnnConvUseMaxWorkspace = "1";
std::vector<const char*> cuda_keys{
"device_id",
"gpu_mem_limit",
"arena_extend_strategy",
"cudnn_conv_algo_search",
"do_copy_in_default_stream",
"cudnn_conv_use_max_workspace",
};
std::vector<const char *> cuda_values{
};
std::vector<const char*> cuda_values{
fCudaDeviceId.c_str(),
fCudaGpuMemLimit.c_str(),
fCudaArenaExtendedStrategy.c_str(),
fCudaCudnnConvAlgoSearch.c_str(),
fCudaDoCopyInDefaultStream.c_str(),
fCudaCudnnConvUseMaxWorkspace.c_str(),
};
};
};
#endif /* PAR04INFEERENCESETUP_HH */
# endif /* PAR04INFEERENCESETUP_HH */
#endif
@@ -25,17 +25,18 @@
//
#ifdef USE_INFERENCE_LWTNN
#ifndef PAR04LWTNNINFERENCE_HH
#define PAR04LWTNNINFERENCE_HH
# ifndef PAR04LWTNNINFERENCE_HH
# define PAR04LWTNNINFERENCE_HH
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4double
#include <map> // for map, map<>::value_compare
#include <memory> // for unique_ptr
#include <string> // for string, basic_string, operator<
#include <vector> // for vector
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include "lwtnn/LightweightGraph.hh" // for LightweightGraph
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include "lwtnn/LightweightGraph.hh" // for LightweightGraph
# include <G4String.hh> // for G4String
# include <G4Types.hh> // for G4double
# include <map> // for map, map<>::value_compare
# include <memory> // for unique_ptr
# include <string> // for string, basic_string, operator<
# include <vector> // for vector
/**
* @brief Inference using the LWTNN library.
@@ -48,22 +49,22 @@
class Par04LwtnnInference : public Par04InferenceInterface
{
public:
Par04LwtnnInference(G4String);
Par04LwtnnInference();
public:
Par04LwtnnInference(G4String);
Par04LwtnnInference();
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
private:
/// LWTNN graph , Network input and output vectors
std::unique_ptr<lwt::LightweightGraph> fGraph;
typedef std::map<std::string, std::map<std::string, double>> fNetworkInputs;
typedef std::map<std::string, double> fNetworkOutputs;
private:
/// LWTNN graph , Network input and output vectors
std::unique_ptr<lwt::LightweightGraph> fGraph;
typedef std::map<std::string, std::map<std::string, double>> fNetworkInputs;
typedef std::map<std::string, double> fNetworkOutputs;
};
#endif /* PAR04LWTNNINFERENCE_HH */
# endif /* PAR04LWTNNINFERENCE_HH */
#endif
@@ -24,15 +24,16 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#ifndef PAR04MLFASTSIMMODEL_HH
#define PAR04MLFASTSIMMODEL_HH
# ifndef PAR04MLFASTSIMMODEL_HH
# define PAR04MLFASTSIMMODEL_HH
#include <G4String.hh> // for G4String
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4bool, G4double
#include <memory> // for unique_ptr
#include <vector> // for vector
#include "G4VFastSimulationModel.hh" // for G4VFastSimulationModel
# include "G4VFastSimulationModel.hh" // for G4VFastSimulationModel
# include <G4String.hh> // for G4String
# include <G4ThreeVector.hh> // for G4ThreeVector
# include <G4Types.hh> // for G4bool, G4double
# include <memory> // for unique_ptr
# include <vector> // for vector
class G4FastSimHitMaker;
class G4FastStep;
class G4FastHit;
@@ -53,31 +54,31 @@ class Par04InferenceSetup;
class Par04MLFastSimModel : public G4VFastSimulationModel
{
public:
Par04MLFastSimModel(G4String, G4Region*);
Par04MLFastSimModel(G4String);
~Par04MLFastSimModel();
/// There are no kinematics constraints. True is returned.
virtual G4bool ModelTrigger(const G4FastTrack&) final;
/// Model is applicable to electrons, positrons, and photons.
virtual G4bool IsApplicable(const G4ParticleDefinition&) final;
/// Take particle out of the full simulation (kill it at the entrance
/// depositing all the energy). Calculate energy deposited in the detector
/// from the NN model inference.
virtual void DoIt(const G4FastTrack&, G4FastStep&) final;
public:
Par04MLFastSimModel(G4String, G4Region*);
Par04MLFastSimModel(G4String);
~Par04MLFastSimModel();
/// There are no kinematics constraints. True is returned.
virtual G4bool ModelTrigger(const G4FastTrack&) final;
/// Model is applicable to electrons, positrons, and photons.
virtual G4bool IsApplicable(const G4ParticleDefinition&) final;
/// Take particle out of the full simulation (kill it at the entrance
/// depositing all the energy). Calculate energy deposited in the detector
/// from the NN model inference.
virtual void DoIt(const G4FastTrack&, G4FastStep&) final;
private:
/// Inference model that is NN aware
Par04InferenceSetup* fInference;
/// Inference model that is NN aware
/// Helper class for creation of hits within the sensitive detector
std::unique_ptr<G4FastSimHitMaker> fHitMaker;
std::unique_ptr<G4FastSimHitMaker> fParallelHitMaker;
/// Vector of energy values
std::vector<G4double> fEnergies;
/// Vector of positions corresponding to energy values (const for one NN
/// model)
std::vector<G4ThreeVector> fPositions;
private:
/// Inference model that is NN aware
Par04InferenceSetup* fInference;
/// Inference model that is NN aware
/// Helper class for creation of hits within the sensitive detector
std::unique_ptr<G4FastSimHitMaker> fHitMaker;
std::unique_ptr<G4FastSimHitMaker> fParallelHitMaker;
/// Vector of energy values
std::vector<G4double> fEnergies;
/// Vector of positions corresponding to energy values (const for one NN
/// model)
std::vector<G4ThreeVector> fPositions;
};
#endif /* PAR04INFERENCEMODEL_HH */
# endif /* PAR04INFERENCEMODEL_HH */
#endif
@@ -25,15 +25,17 @@
//
#ifdef USE_INFERENCE_ONNX
#ifndef PAR04ONNXINFERENCE_HH
#define PAR04ONNXINFERENCE_HH
#include <core/session/onnxruntime_c_api.h> // for OrtMemoryInfo
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4int, G4double
#include <memory> // for unique_ptr
#include <vector> // for vector
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include "core/session/onnxruntime_cxx_api.h" // for Env, Session, SessionO...
# ifndef PAR04ONNXINFERENCE_HH
# define PAR04ONNXINFERENCE_HH
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include "core/session/onnxruntime_cxx_api.h" // for Env, Session, SessionO...
# include <G4String.hh> // for G4String
# include <G4Types.hh> // for G4int, G4double
# include <memory> // for unique_ptr
# include <vector> // for vector
# include <core/session/onnxruntime_c_api.h> // for OrtMemoryInfo
/**
* @brief Inference using the ONNX runtime.
@@ -46,36 +48,35 @@
class Par04OnnxInference : public Par04InferenceInterface
{
public:
Par04OnnxInference(G4String, G4int, G4int, G4int,
G4int, // For Execution Provider Runtime Flags (for now only CUDA)
std::vector<const char *> &cuda_keys,
std::vector<const char *> &cuda_values,
G4String, G4String);
public:
Par04OnnxInference(G4String, G4int, G4int, G4int,
G4int, // For Execution Provider Runtime Flags (for now only CUDA)
std::vector<const char*>& cuda_keys, std::vector<const char*>& cuda_values,
G4String, G4String);
Par04OnnxInference();
Par04OnnxInference();
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
private:
/// Pointer to the ONNX enviroment
std::unique_ptr<Ort::Env> fEnv;
/// Pointer to the ONNX inference session
std::unique_ptr<Ort::Session> fSession;
/// ONNX settings
Ort::SessionOptions fSessionOptions;
/// ONNX memory info
const OrtMemoryInfo* fInfo;
struct MemoryInfo;
/// the input names represent the names given to the model
/// when defining the model's architecture (if applicable)
/// they can also be retrieved from model.summary()
std::vector<const char*> fInames;
private:
/// Pointer to the ONNX enviroment
std::unique_ptr<Ort::Env> fEnv;
/// Pointer to the ONNX inference session
std::unique_ptr<Ort::Session> fSession;
/// ONNX settings
Ort::SessionOptions fSessionOptions;
/// ONNX memory info
const OrtMemoryInfo* fInfo;
struct MemoryInfo;
/// the input names represent the names given to the model
/// when defining the model's architecture (if applicable)
/// they can also be retrieved from model.summary()
std::vector<const char*> fInames;
};
#endif /* PAR04ONNXINFERENCE_HH */
# endif /* PAR04ONNXINFERENCE_HH */
#endif
@@ -26,14 +26,16 @@
#ifndef PAR04PARALLELFASTSENSITIVEDETECTOR_HH
#define PAR04PARALLELFASTSENSITIVEDETECTOR_HH
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include <unordered_map>
class G4FastHit;
class G4FastTrack;
@@ -47,33 +49,30 @@ class G4TouchableHistory;
*
*/
class Par04ParallelFastSensitiveDetector
: public G4VSensitiveDetector,
public G4VFastSimSensitiveDetector
class Par04ParallelFastSensitiveDetector : public G4VSensitiveDetector,
public G4VFastSimSensitiveDetector
{
public:
Par04ParallelFastSensitiveDetector(G4String aName);
Par04ParallelFastSensitiveDetector(G4String aName,
G4int aNbOfLayers,
G4int aNbOfSlices);
virtual ~Par04ParallelFastSensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
virtual G4bool ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
G4TouchableHistory* aROhist) final;
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
public:
Par04ParallelFastSensitiveDetector(G4String aName);
Par04ParallelFastSensitiveDetector(G4String aName, G4int aNbOfLayers, G4int aNbOfSlices);
virtual ~Par04ParallelFastSensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
virtual G4bool ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
G4TouchableHistory* aROhist) final;
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of readout cells
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of readout cells
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
};
#endif /* PAR04PARALLELSENSITIVEDETECTOR_HH */
@@ -27,6 +27,7 @@
#define PAR04PARALLELFASTWORLD_HH
#include "Par04DetectorConstruction.hh"
#include "G4VUserParallelWorld.hh"
#include "globals.hh"
@@ -37,26 +38,25 @@ class G4VPhysicalVolume;
class Par04ParallelFastWorld : public G4VUserParallelWorld
{
public:
Par04ParallelFastWorld(G4String aWorldName,
const Par04DetectorConstruction* aMassDetector,
const Par04ParallelFullWorld* aParallelFull);
~Par04ParallelFastWorld();
virtual void Construct() final;
virtual void ConstructSD() final;
void Print();
public:
Par04ParallelFastWorld(G4String aWorldName, const Par04DetectorConstruction* aMassDetector,
const Par04ParallelFullWorld* aParallelFull);
~Par04ParallelFastWorld();
private:
/// Messenger that allows to modify geometry
const Par04DetectorConstruction* fMassDetector;
const Par04ParallelFullWorld* fParallelFull;
std::vector<G4LogicalVolume*> fLogicalCell;
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
G4double fLayerThickness = 0;
virtual void Construct() final;
virtual void ConstructSD() final;
void Print();
private:
/// Messenger that allows to modify geometry
const Par04DetectorConstruction* fMassDetector;
const Par04ParallelFullWorld* fParallelFull;
std::vector<G4LogicalVolume*> fLogicalCell;
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
G4double fLayerThickness = 0;
};
#endif
@@ -26,14 +26,16 @@
#ifndef PAR04PARALLELFULLSENSITIVEDETECTOR_HH
#define PAR04PARALLELFULLSENSITIVEDETECTOR_HH
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include <unordered_map>
class G4HCofThisEvent;
class G4Step;
@@ -45,30 +47,29 @@ class G4TouchableHistory;
*
*/
class Par04ParallelFullSensitiveDetector
: public G4VSensitiveDetector
class Par04ParallelFullSensitiveDetector : public G4VSensitiveDetector
{
public:
Par04ParallelFullSensitiveDetector(G4String aName);
Par04ParallelFullSensitiveDetector(G4String aName,
G4int aNbOfLayers, G4int aNbOfSlices, G4int aNbOfRows);
virtual ~Par04ParallelFullSensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
public:
Par04ParallelFullSensitiveDetector(G4String aName);
Par04ParallelFullSensitiveDetector(G4String aName, G4int aNbOfLayers, G4int aNbOfSlices,
G4int aNbOfRows);
virtual ~Par04ParallelFullSensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of readout cells
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of readout cells
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
};
#endif /* PAR04PARALLELSENSITIVEDETECTOR_HH */
@@ -27,6 +27,7 @@
#define PAR04PARALLELFULLWORLD_HH
#include "Par04DetectorConstruction.hh"
#include "G4VUserParallelWorld.hh"
#include "globals.hh"
@@ -36,36 +37,35 @@ class G4VPhysicalVolume;
class Par04ParallelFullWorld : public G4VUserParallelWorld
{
public:
Par04ParallelFullWorld(G4String aWorldName, const Par04DetectorConstruction* aMassDetector);
~Par04ParallelFullWorld();
virtual void Construct() final;
virtual void ConstructSD() final;
public:
Par04ParallelFullWorld(G4String aWorldName, const Par04DetectorConstruction* aMassDetector);
~Par04ParallelFullWorld();
/// Set number of slices
inline void SetNbOfSlices(G4int aNumber) { fNbOfSlices = aNumber; };
/// Get number of slices
inline G4int GetNbOfSlices() const { return fNbOfSlices; };
/// Set number of rows
inline void SetNbOfRows(G4int aNumber) { fNbOfRows = aNumber; };
/// Get number of rows
inline G4int GetNbOfRows() const { return fNbOfRows; };
/// Get number of layers
inline G4int GetNbOfLayers() const { return fNbOfLayers; };
void Print();
virtual void Construct() final;
virtual void ConstructSD() final;
private:
/// Messenger that allows to modify geometry
Par04ParallelMessenger* fParallelMessenger = nullptr;
const Par04DetectorConstruction* fMassDetector;
std::vector<G4LogicalVolume*> fLogicalCell;
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
G4double fLayerThickness = 0;
/// Set number of slices
inline void SetNbOfSlices(G4int aNumber) { fNbOfSlices = aNumber; };
/// Get number of slices
inline G4int GetNbOfSlices() const { return fNbOfSlices; };
/// Set number of rows
inline void SetNbOfRows(G4int aNumber) { fNbOfRows = aNumber; };
/// Get number of rows
inline G4int GetNbOfRows() const { return fNbOfRows; };
/// Get number of layers
inline G4int GetNbOfLayers() const { return fNbOfLayers; };
void Print();
private:
/// Messenger that allows to modify geometry
Par04ParallelMessenger* fParallelMessenger = nullptr;
const Par04DetectorConstruction* fMassDetector;
std::vector<G4LogicalVolume*> fLogicalCell;
G4int fNbOfLayers = 1;
G4int fNbOfSlices = 1;
G4int fNbOfRows = 1;
G4double fLayerThickness = 0;
};
#endif
@@ -27,8 +27,9 @@
#ifndef PAR04PARALLELMESSENGER_H
#define PAR04PARALLELMESSENGER_H
#include <G4String.hh> // for G4String
#include "G4UImessenger.hh" // for G4UImessenger
#include <G4String.hh> // for G4String
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAnInteger;
class G4UIcmdWithoutParameter;
@@ -47,29 +48,29 @@ class Par04ParallelFullWorld;
class Par04ParallelMessenger : public G4UImessenger
{
public:
Par04ParallelMessenger(Par04ParallelFullWorld*);
~Par04ParallelMessenger();
public:
Par04ParallelMessenger(Par04ParallelFullWorld*);
~Par04ParallelMessenger();
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
private:
/// Parallel world to setup
Par04ParallelFullWorld* fParallel = nullptr;
/// Command to set the directory common to all messengers in this example
/// /Par04
G4UIdirectory* fExampleDir = nullptr;
/// Command to set the directory for parallel settings /Par04/parallel
G4UIdirectory* fParallelDir = nullptr;
/// Command printing current settings
G4UIcmdWithoutParameter* fPrintCmd;
/// Command to set the number of slices
G4UIcmdWithAnInteger* fNbSlicesCmd = nullptr;
/// Command to set the number of rows
G4UIcmdWithAnInteger* fNbRowsCmd = nullptr;
private:
/// Parallel world to setup
Par04ParallelFullWorld* fParallel = nullptr;
/// Command to set the directory common to all messengers in this example
/// /Par04
G4UIdirectory* fExampleDir = nullptr;
/// Command to set the directory for parallel settings /Par04/parallel
G4UIdirectory* fParallelDir = nullptr;
/// Command printing current settings
G4UIcmdWithoutParameter* fPrintCmd;
/// Command to set the number of slices
G4UIcmdWithAnInteger* fNbSlicesCmd = nullptr;
/// Command to set the number of rows
G4UIcmdWithAnInteger* fNbRowsCmd = nullptr;
};
#endif
@@ -40,16 +40,16 @@ class G4ParticleGun;
class Par04PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
Par04PrimaryGeneratorAction();
virtual ~Par04PrimaryGeneratorAction();
public:
Par04PrimaryGeneratorAction();
virtual ~Par04PrimaryGeneratorAction();
/// Generate primary particles
virtual void GeneratePrimaries(G4Event*) final;
/// Generate primary particles
virtual void GeneratePrimaries(G4Event*) final;
private:
/// Particle gun
G4ParticleGun* fParticleGun = nullptr;
private:
/// Particle gun
G4ParticleGun* fParticleGun = nullptr;
};
#endif /* PAR04PRIMARYGENERATORACTION_HH */
@@ -26,19 +26,21 @@
#ifndef PAR04RUNACTION_HH
#define PAR04RUNACTION_HH
#include "G4UserRunAction.hh"
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04PrimaryGeneratorAction.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for GeV
#include <G4String.hh> // for G4String
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4int
#include "G4Event.hh" // for G4Event
#include "G4ParticleGun.hh" // for G4ParticleGun
#include "G4ParticleTable.hh" // for G4ParticleTable
#include "G4SystemOfUnits.hh" // for GeV
#include "G4UserRunAction.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for GeV
#include <G4String.hh> // for G4String
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4int
#include <G4VUserPrimaryGeneratorAction.hh> // for G4VUserPrimaryGeneratorA...
#include <string> // for basic_string
#include "G4Event.hh" // for G4Event
#include "G4ParticleGun.hh" // for G4ParticleGun
#include "G4ParticleTable.hh" // for G4ParticleTable
#include "G4SystemOfUnits.hh" // for GeV
#include "Par04EventInformation.hh" // for Par04EventInformation
#include <string> // for basic_string
class G4ParticleDefinition;
class Par04EventAction;
class G4Run;
@@ -56,25 +58,25 @@ class Par04DetectorConstruction;
class Par04RunAction : public G4UserRunAction
{
public:
/// Constructor. Defines the histograms.
Par04RunAction(Par04DetectorConstruction* aDetector, Par04EventAction* aEventAction);
virtual ~Par04RunAction();
public:
/// Constructor. Defines the histograms.
Par04RunAction(Par04DetectorConstruction* aDetector, Par04EventAction* aEventAction);
virtual ~Par04RunAction();
/// Open the file for the analysis
virtual void BeginOfRunAction(const G4Run*) final;
/// Write and close the file
virtual void EndOfRunAction(const G4Run*) final;
/// Open the file for the analysis
virtual void BeginOfRunAction(const G4Run*) final;
/// Write and close the file
virtual void EndOfRunAction(const G4Run*) final;
private:
/// Pointer to detector construction to retrieve the detector dimensions to
/// setup the histograms
Par04DetectorConstruction* fDetector;
/// Pointer to event action to save hits
Par04EventAction* fEventAction;
/// Timer measurement
std::chrono::steady_clock::time_point fChronoStart;
std::chrono::steady_clock::time_point fChronoEnd;
private:
/// Pointer to detector construction to retrieve the detector dimensions to
/// setup the histograms
Par04DetectorConstruction* fDetector;
/// Pointer to event action to save hits
Par04EventAction* fEventAction;
/// Timer measurement
std::chrono::steady_clock::time_point fChronoStart;
std::chrono::steady_clock::time_point fChronoEnd;
};
#endif /* PAR04RUNACTION_HH */
@@ -26,14 +26,16 @@
#ifndef PAR04SENSITIVEDETECTOR_HH
#define PAR04SENSITIVEDETECTOR_HH
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4SystemOfUnits.hh" // for m
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include <CLHEP/Units/SystemOfUnits.h> // for m, pi
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4bool, G4int
#include <unordered_map>
class G4FastHit;
class G4FastTrack;
@@ -55,43 +57,41 @@ class G4TouchableHistory;
*
*/
class Par04SensitiveDetector
: public G4VSensitiveDetector
, public G4VFastSimSensitiveDetector
class Par04SensitiveDetector : public G4VSensitiveDetector, public G4VFastSimSensitiveDetector
{
public:
Par04SensitiveDetector(G4String aName);
Par04SensitiveDetector(G4String aName, G4ThreeVector aNbOfCells, G4ThreeVector aNSizeOfCells);
virtual ~Par04SensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
/// Process energy deposit from the fast simulation.
virtual G4bool ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
G4TouchableHistory* aROhist) final;
/// Process energy deposit - common part for full and fast simulation
/// It is invoked from ProcessHits() methods, and sets basic hit properties
/// (position, etc.), common for hit from fast and full simulation.
Par04Hit* RetrieveAndSetupHit(G4ThreeVector aPosition);
/// Rewrite hits map to a vector
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
public:
Par04SensitiveDetector(G4String aName);
Par04SensitiveDetector(G4String aName, G4ThreeVector aNbOfCells, G4ThreeVector aNSizeOfCells);
virtual ~Par04SensitiveDetector();
/// Create hit collection
virtual void Initialize(G4HCofThisEvent* HCE) final;
/// Process energy deposit from the full simulation.
virtual G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* aROhist) final;
/// Process energy deposit from the fast simulation.
virtual G4bool ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
G4TouchableHistory* aROhist) final;
/// Process energy deposit - common part for full and fast simulation
/// It is invoked from ProcessHits() methods, and sets basic hit properties
/// (position, etc.), common for hit from fast and full simulation.
Par04Hit* RetrieveAndSetupHit(G4ThreeVector aPosition);
/// Rewrite hits map to a vector
virtual void EndOfEvent(G4HCofThisEvent* aHC) final;
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
/// Map of hits to be used in runtime
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of mesh readout cells in cylindrical coordinates
G4ThreeVector fMeshNbOfCells = { 10, 10, 10 };
/// Size of mesh readout cells in cylindrical coordinates.
G4ThreeVector fMeshSizeOfCells = { 1 * m, 2 * CLHEP::pi / 10., 1 * m };
/// Retrieved once per event: position of entering particle
G4ThreeVector fEntrancePosition = { -1, -1, -1 };
/// Retrieved once per event: direction of entering particle
G4ThreeVector fEntranceDirection = { -1, -1, -1 };
private:
/// Collection of hits
Par04HitsCollection* fHitsCollection = nullptr;
/// Map of hits to be used in runtime
std::unordered_map<G4int, std::unique_ptr<Par04Hit>> fHitsMap;
/// ID of collection of hits
G4int fHitCollectionID = -1;
/// Number of mesh readout cells in cylindrical coordinates
G4ThreeVector fMeshNbOfCells = {10, 10, 10};
/// Size of mesh readout cells in cylindrical coordinates.
G4ThreeVector fMeshSizeOfCells = {1 * m, 2 * CLHEP::pi / 10., 1 * m};
/// Retrieved once per event: position of entering particle
G4ThreeVector fEntrancePosition = {-1, -1, -1};
/// Retrieved once per event: direction of entering particle
G4ThreeVector fEntranceDirection = {-1, -1, -1};
};
#endif /* PAR04SENSITIVEDETECTOR_HH */
@@ -25,14 +25,15 @@
//
#ifdef USE_INFERENCE_TORCH
#ifndef PAR04TORCHINFERENCE_HH
#define PAR04TORCHINFERENCE_HH
#include <G4String.hh> // for G4String
#include <G4Types.hh> // for G4int, G4double
#include <memory> // for unique_ptr
#include <vector> // for vector
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include <torch/script.h>
# ifndef PAR04TORCHINFERENCE_HH
# define PAR04TORCHINFERENCE_HH
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include <G4String.hh> // for G4String
# include <G4Types.hh> // for G4int, G4double
# include <memory> // for unique_ptr
# include <torch/script.h>
# include <vector> // for vector
/**
* @brief Inference using the TORCH.
@@ -43,20 +44,19 @@
class Par04TorchInference : public Par04InferenceInterface
{
public:
Par04TorchInference(G4String);
Par04TorchInference();
public:
Par04TorchInference(G4String);
Par04TorchInference();
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
private:
torch::jit::script::Module fModule;
/// Run inference
/// @param[in] aGenVector Input latent space and conditions
/// @param[out] aEnergies Model output = generated shower energies
/// @param[in] aSize Size of the output
void RunInference(std::vector<float> aGenVector, std::vector<G4double>& aEnergies, int aSize);
private:
torch::jit::script::Module fModule;
};
#endif /* PAR04TORCHINFERENCE_HH */
# endif /* PAR04TORCHINFERENCE_HH */
#endif