Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
@@ -29,6 +29,7 @@
#include "G4VUserActionInitialization.hh"
class Par04DetectorConstruction;
class Par04ParallelFullWorld;
/**
* @brief Initialization of user actions.
@@ -41,7 +42,8 @@ class Par04DetectorConstruction;
class Par04ActionInitialisation : public G4VUserActionInitialization
{
public:
Par04ActionInitialisation(Par04DetectorConstruction* aDetector);
Par04ActionInitialisation(Par04DetectorConstruction* aDetector,
Par04ParallelFullWorld* aParallel);
~Par04ActionInitialisation();
/// Create all user actions.
virtual void Build() const final;
@@ -52,6 +54,7 @@ class Par04ActionInitialisation : public G4VUserActionInitialization
/// 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 */
@@ -124,7 +124,8 @@ class Par04DetectorConstruction : public G4VUserDetectorConstruction
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; };
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; };
@@ -32,6 +32,7 @@
#include "G4UserEventAction.hh" // for G4UserEventAction
class G4Event;
class Par04DetectorConstruction;
class Par04ParallelFullWorld;
/**
* @brief Event action class for hits' analysis.
@@ -46,7 +47,7 @@ class Par04DetectorConstruction;
class Par04EventAction : public G4UserEventAction
{
public:
Par04EventAction(Par04DetectorConstruction* aDetector);
Par04EventAction(Par04DetectorConstruction* aDetector, Par04ParallelFullWorld* aParallel);
virtual ~Par04EventAction();
/// Timer is started
@@ -57,15 +58,23 @@ class Par04EventAction : public G4UserEventAction
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;
/// Timer measurement
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
@@ -78,6 +87,12 @@ class Par04EventAction : public G4UserEventAction
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
@@ -86,6 +101,14 @@ class Par04EventAction : public G4UserEventAction
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 */
@@ -88,6 +88,12 @@ class Par04Hit : public G4VHit
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
@@ -116,6 +122,8 @@ class Par04Hit : public G4VHit
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
@@ -27,8 +27,8 @@
#ifndef PAR04INFERENCEMESSENGER_H
#define PAR04INFERENCEMESSENGER_H
#include <G4String.hh> // for G4String
#include "G4UImessenger.hh" // for G4UImessenger
#include "G4UImessenger.hh" // for G4UImessenger
#include <G4String.hh> // for G4String
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
@@ -40,53 +40,68 @@ class Par04InferenceSetup;
* @brief Inference messenger.
*
* Provides UI commands to setup the inference: name of the inference library,
* path to the ML model, size of the latent space, the size of the condition vector and
* flags for optimization and profiling.
* It allows to specify the mesh size (in cylindrical coordinates) that was used in training dataset
* path to the ML model, size of the latent space, the size of the condition
* vector and flags for optimization and profiling. It allows to specify the
* mesh size (in cylindrical coordinates) that was used in training dataset
* (full simulation).
*
*/
class Par04InferenceMessenger : public G4UImessenger
{
public:
Par04InferenceMessenger(Par04InferenceSetup*);
class Par04InferenceMessenger : public G4UImessenger {
public:
Par04InferenceMessenger(Par04InferenceSetup *);
~Par04InferenceMessenger();
/// Invokes appropriate methods based on the typed command
virtual void SetNewValue(G4UIcommand*, G4String) final;
virtual void SetNewValue(G4UIcommand *, G4String) final;
/// Retrieves the current settings
virtual G4String GetCurrentValue(G4UIcommand*) final;
virtual G4String GetCurrentValue(G4UIcommand *) final;
private:
private:
/// Inference to setup
Par04InferenceSetup* fInference = nullptr;
/// Command to set the directory common to all inference messengers in this example
/// /Par04
G4UIdirectory* fExampleDir = nullptr;
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;
G4UIdirectory *fInferenceDir = nullptr;
/// Command to set the inference library
G4UIcmdWithAString* fInferenceLibraryCmd = nullptr;
G4UIcmdWithAString *fInferenceLibraryCmd = nullptr;
/// Command to set fModelPathNameCmd
G4UIcmdWithAString* fModelPathNameCmd = nullptr;
G4UIcmdWithAString *fModelPathNameCmd = nullptr;
/// Command to set the fSizeLatentVectorCmd
G4UIcmdWithAnInteger* fSizeLatentVectorCmd = nullptr;
G4UIcmdWithAnInteger *fSizeLatentVectorCmd = nullptr;
/// Command to set the fSizeConditionVectorCmd
G4UIcmdWithAnInteger* fSizeConditionVectorCmd = nullptr;
G4UIcmdWithAnInteger *fSizeConditionVectorCmd = nullptr;
/// Command to set the fProfileFlagCmd
G4UIcmdWithAnInteger* fProfileFlagCmd = nullptr;
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;
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
@@ -27,13 +27,13 @@
#ifndef PAR04INFEERENCESETUP_HH
#define PAR04INFEERENCESETUP_HH
#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 "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;
@@ -41,20 +41,20 @@ class Par04InferenceMessenger;
/**
* @brief Inference setup.
*
* Constructs the input vector of size b+c to run the inference, b represents the size of
* the latent space (or the encoded space in a Variational Autoencoder based model),
* c represents the size of the conditional vector. The b values of the input vector
* are randomly sampled from b-dimensional Gaussian distribution. The c values
* represent respectively the condition values of the particle energy, angle and
* detector geometry. These condition values are user-specific application.
* The energy rescaling is used to retrieve the original energy scale in MeV.
* Computes the cell position in the detector of each inferred energy value.
* Constructs the input vector of size b+c to run the inference, b represents
* the size of the latent space (or the encoded space in a Variational
* Autoencoder based model), c represents the size of the conditional vector.
*The b values of the input vector are randomly sampled from b-dimensional
*Gaussian distribution. The c values represent respectively the condition
*values of the particle energy, angle and detector geometry. These condition
*values are user-specific application. The energy rescaling is used to retrieve
*the original energy scale in MeV. Computes the cell position in the detector
*of each inferred energy value.
*
**/
class Par04InferenceSetup
{
public:
class Par04InferenceSetup {
public:
Par04InferenceSetup();
~Par04InferenceSetup();
@@ -65,7 +65,7 @@ class Par04InferenceSetup
/// 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; };
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.
@@ -73,17 +73,23 @@ class Par04InferenceSetup
/// 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; };
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; };
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; };
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
@@ -95,12 +101,15 @@ class Par04InferenceSetup
/// Get profiling flag
inline G4int GetProfileFlag() const { return fProfileFlag; };
/// Set optimization flag
inline void SetOptimizationFlag(G4int aNumber) { fOptimizationFlag = aNumber; };
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
/// 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();
@@ -108,22 +117,62 @@ class Par04InferenceSetup
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; };
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; };
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,
void GetEnergies(std::vector<G4double> &aEnergies, G4double aParticleEnergy,
G4float aInitialAngle);
/// Calculate positions
@@ -134,15 +183,17 @@ class Par04InferenceSetup
/// 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,
void GetPositions(std::vector<G4ThreeVector> &aDepositsPositions,
G4ThreeVector aParticlePosition,
G4ThreeVector aParticleDirection);
private:
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);
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>`
@@ -150,7 +201,7 @@ class Par04InferenceSetup
/// Inference interface
std::unique_ptr<Par04InferenceInterface> fInferenceInterface;
/// Inference messenger
Par04InferenceMessenger* fInferenceMessenger;
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
@@ -168,8 +219,39 @@ class Par04InferenceSetup
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{
fCudaDeviceId.c_str(),
fCudaGpuMemLimit.c_str(),
fCudaArenaExtendedStrategy.c_str(),
fCudaCudnnConvAlgoSearch.c_str(),
fCudaDoCopyInDefaultStream.c_str(),
fCudaCudnnConvUseMaxWorkspace.c_str(),
};
};
#endif /* PAR04INFEERENCESETUP_HH */
@@ -35,6 +35,7 @@
#include "G4VFastSimulationModel.hh" // for G4VFastSimulationModel
class G4FastSimHitMaker;
class G4FastStep;
class G4FastHit;
class G4FastTrack;
class G4ParticleDefinition;
class G4Region;
@@ -71,6 +72,7 @@ class Par04MLFastSimModel : public G4VFastSimulationModel
/// 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
@@ -47,7 +47,12 @@
class Par04OnnxInference : public Par04InferenceInterface
{
public:
Par04OnnxInference(G4String, G4int, G4int, G4int);
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();
/// Run inference
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#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 "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include <unordered_map>
class G4FastHit;
class G4FastTrack;
class G4HCofThisEvent;
class G4Step;
class G4TouchableHistory;
/**
* @brief Sensitive detector.
*
*
*/
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;
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 */
@@ -0,0 +1,62 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#ifndef PAR04PARALLELFASTWORLD_HH
#define PAR04PARALLELFASTWORLD_HH
#include "Par04DetectorConstruction.hh"
#include "G4VUserParallelWorld.hh"
#include "globals.hh"
class Par04ParallelMessenger;
class Par04ParallelFullWorld;
class G4LogicalVolume;
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();
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
@@ -0,0 +1,74 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#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 "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include <unordered_map>
class G4HCofThisEvent;
class G4Step;
class G4TouchableHistory;
/**
* @brief Sensitive detector.
*
*
*/
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;
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 */
@@ -0,0 +1,71 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#ifndef PAR04PARALLELFULLWORLD_HH
#define PAR04PARALLELFULLWORLD_HH
#include "Par04DetectorConstruction.hh"
#include "G4VUserParallelWorld.hh"
#include "globals.hh"
class Par04ParallelMessenger;
class G4LogicalVolume;
class G4VPhysicalVolume;
class Par04ParallelFullWorld : public G4VUserParallelWorld
{
public:
Par04ParallelFullWorld(G4String aWorldName, const Par04DetectorConstruction* aMassDetector);
~Par04ParallelFullWorld();
virtual void Construct() final;
virtual void ConstructSD() final;
/// 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
@@ -0,0 +1,75 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
#ifndef PAR04PARALLELMESSENGER_H
#define PAR04PARALLELMESSENGER_H
#include <G4String.hh> // for G4String
#include "G4UImessenger.hh" // for G4UImessenger
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAnInteger;
class G4UIcmdWithoutParameter;
class G4UIcmdWithABool;
class G4UIcommand;
class G4UIdirectory;
class Par04ParallelFullWorld;
/**
* @brief Parallel messenger.
*
* Provides UI commands to setup readout geometry in parallel world (prior to
* initialization). Number of layers is taken from detector construction.
*
*/
class Par04ParallelMessenger : public G4UImessenger
{
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;
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
@@ -72,6 +72,9 @@ class Par04RunAction : public G4UserRunAction
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 */
@@ -34,6 +34,7 @@
#include "G4VFastSimSensitiveDetector.hh" // for G4VFastSimSensitiveDetector
#include "G4VSensitiveDetector.hh" // for G4VSensitiveDetector
#include "Par04Hit.hh" // for Par04Hit (ptr only), Par04...
#include <unordered_map>
class G4FastHit;
class G4FastTrack;
class G4HCofThisEvent;
@@ -73,10 +74,14 @@ class Par04SensitiveDetector
/// 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