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
@@ -6,13 +6,13 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2024-06-18 Gabriele Cosmo (expar04-V11-01-04)
## 2024-06-18 Gabriele Cosmo (expar04-V11-02-02)
- Bump scikit-learn version from [GitHub Dependabot PR](https://github.com/Geant4/geant4/pull/73)
## 2024-06-13 Gabriele Cosmo (expar04-V11-01-03)
## 2024-06-13 Gabriele Cosmo (expar04-V11-02-01)
- Bump pymysql version from [GitHub Dependabot PR](https://github.com/Geant4/geant4/pull/72)
## 2024-03-11 Ben Morgan
## 2024-03-11 Ben Morgan (expar04-V11-02-00)
- Bump scipy version from [GitHub Dependabot PR](https://github.com/Geant4/geant4/pull/66)
## 2023-10-25 Dalila Salamani (expar04-V11-01-02)
@@ -35,31 +35,31 @@
// for fast simulation in calorimeters.
//
//-------------------------------------------------------------------
#include "FTFP_BERT.hh" // for FTFP_BERT
#include "FTFP_BERT.hh" // for FTFP_BERT
#include "Par04ActionInitialisation.hh" // for Par04ActionInitialisation
#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
#include "Par04ParallelFastWorld.hh"
#include "Par04ParallelFullWorld.hh"
#include "G4EmParameters.hh" // for G4EmParameters
#include "G4FastSimulationPhysics.hh" // for G4FastSimulationPhysics
#include "G4HadronicProcessStore.hh" // for G4HadronicProcessStore
#include "G4EmParameters.hh" // for G4EmParameters
#include "G4Exception.hh" // for G4Exception
#include "G4ExceptionSeverity.hh" // for FatalErrorInArgument
#include "G4FastSimulationPhysics.hh" // for G4FastSimulationPhysics
#include "G4HadronicProcessStore.hh" // for G4HadronicProcessStore
#include "G4ParallelWorldPhysics.hh"
#include "G4RunManagerFactory.hh" // for G4RunManagerFactory, G4RunMa...
#include "G4Types.hh" // for G4bool, G4int
#include "G4UIExecutive.hh" // for G4UIExecutive
#include "G4UImanager.hh" // for G4UImanager
#include "G4VisExecutive.hh" // for G4VisExecutive
#include "G4RunManager.hh" // for G4RunManager
#include "G4RunManagerFactory.hh" // for G4RunManagerFactory, G4RunMa...
#include "G4String.hh" // for G4String
#include "G4Types.hh" // for G4bool, G4int
#include "G4UIExecutive.hh" // for G4UIExecutive
#include "G4UImanager.hh" // for G4UImanager
#include "G4VisExecutive.hh" // for G4VisExecutive
#include "G4VisManager.hh" // for G4VisManager
#include "G4ios.hh" // for G4cout, G4endl
#include "G4Exception.hh" // for G4Exception
#include "G4ExceptionSeverity.hh" // for FatalErrorInArgument
#include "G4RunManager.hh" // for G4RunManager
#include "G4String.hh" // for G4String
#include "G4VisManager.hh" // for G4VisManager
#include "G4ios.hh" // for G4cout, G4endl
#include <ctime> // for time
#include <sstream> // for char_traits, operator<<, bas...
#include <string> // for allocator, operator+, operat...
#include <ctime> // for time
#include <sstream> // for char_traits, operator<<, bas...
#include <string> // for allocator, operator+, operat...
int main(int argc, char** argv)
{
@@ -77,90 +77,79 @@ int main(int argc, char** argv)
"\n\t-r\t\trun manager type (0=serial,1=MT,2=tasking)"
"\n\t-t\t\tnumber of threads for MT mode (no change for other modes)."
);
if(argc < 2 ) {
if (argc < 2) {
G4Exception("main", "No arguments", FatalErrorInArgument,
("No arguments passed to " + G4String(argv[0]) + "\n" + helpMsg)
.c_str());
("No arguments passed to " + G4String(argv[0]) + "\n" + helpMsg).c_str());
}
for(G4int i = 1; i < argc; ++i)
{
for (G4int i = 1; i < argc; ++i) {
G4String argument(argv[i]);
if(argument == "-h" || argument == "--help")
{
if (argument == "-h" || argument == "--help") {
G4cout << helpMsg << G4endl;
return 0;
}
else if(argument == "-m")
{
batchMacroName = G4String(argv[i + 1]);
else if (argument == "-m") {
batchMacroName = G4String(argv[i + 1]);
++i;
}
else if(argument == "-i")
{
else if (argument == "-i") {
useInteractiveMode = true;
}
else if(argument == "-r")
{
else if (argument == "-r") {
G4int tmp = atoi(argv[i + 1]);
++i;
switch (tmp) {
case 0:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::Serial;
break;
case 1:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::MTOnly;
break;
case 2:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::Tasking;
break;
default:
G4Exception("main", "Wrong Run Manager type", FatalErrorInArgument,
"Choose 0 (serial, default), 1 (MT), 2 (tasking)");
break;
case 0:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::Serial;
break;
case 1:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::MTOnly;
break;
case 2:
runManagerTypeInt = tmp;
runManagerType = G4RunManagerType::Tasking;
break;
default:
G4Exception("main", "Wrong Run Manager type", FatalErrorInArgument,
"Choose 0 (serial, default), 1 (MT), 2 (tasking)");
break;
}
}
else if(argument == "-t")
{
else if (argument == "-t") {
numOfThreadsOrTasks = atoi(argv[i + 1]);
++i;
}
else
{
G4Exception("main", "Unknown argument", FatalErrorInArgument,
("Unknown argument passed to " + G4String(argv[0]) + " : " +
argument + "\n" + helpMsg)
.c_str());
else {
G4Exception(
"main", "Unknown argument", FatalErrorInArgument,
("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg)
.c_str());
}
}
//choose the Random engine
// choose the Random engine
CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
//set random seed with system time
// set random seed with system time
G4long seed = time(NULL);
CLHEP::HepRandom::setTheSeed(seed);
// Instantiate G4UIExecutive if interactive mode
G4UIExecutive* ui = nullptr;
if(useInteractiveMode)
{
if (useInteractiveMode) {
ui = new G4UIExecutive(argc, argv);
runManagerType = G4RunManagerType::Serial;
}
// Initialization of default Run manager
auto* runManager =
G4RunManagerFactory::CreateRunManager(runManagerType);
if(runManagerTypeInt == 1)
runManager->SetNumberOfThreads(numOfThreadsOrTasks);
auto* runManager = G4RunManagerFactory::CreateRunManager(runManagerType);
if (runManagerTypeInt == 1) runManager->SetNumberOfThreads(numOfThreadsOrTasks);
// Detector geometry:
auto detector = new Par04DetectorConstruction();
auto parallelWorldFull = new Par04ParallelFullWorld("parallelWorldFullSim", detector);
auto parallelWorldFast = new Par04ParallelFastWorld("parallelWorldFastSim", detector,
parallelWorldFull);
auto parallelWorldFast =
new Par04ParallelFastWorld("parallelWorldFastSim", detector, parallelWorldFull);
detector->RegisterParallelWorld(parallelWorldFull);
detector->RegisterParallelWorld(parallelWorldFast);
runManager->SetUserInitialization(detector);
@@ -175,8 +164,8 @@ int main(int argc, char** argv)
fastSimulationPhysics->ActivateFastSimulation("gamma");
physicsList->RegisterPhysics(fastSimulationPhysics);
// Add parallel world for readout
physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFullSim") );
physicsList->RegisterPhysics( new G4ParallelWorldPhysics("parallelWorldFastSim") );
physicsList->RegisterPhysics(new G4ParallelWorldPhysics("parallelWorldFullSim"));
physicsList->RegisterPhysics(new G4ParallelWorldPhysics("parallelWorldFastSim"));
// reduce verbosity of physics lists
G4EmParameters::Instance()->SetVerbose(0);
runManager->SetUserInitialization(physicsList);
@@ -193,21 +182,17 @@ int main(int argc, char** argv)
visManager->Initialize();
G4UImanager* UImanager = G4UImanager::GetUIpointer();
if(useInteractiveMode)
{
if(batchMacroName.empty())
{
if (useInteractiveMode) {
if (batchMacroName.empty()) {
G4Exception("main", "Unknown macro name", FatalErrorInArgument,
("No macro name passed to " + G4String(argv[0]))
.c_str());
("No macro name passed to " + G4String(argv[0])).c_str());
}
G4String command = "/control/execute ";
UImanager->ApplyCommand(command + batchMacroName);
ui->SessionStart();
delete ui;
}
else
{
else {
G4String command = "/control/execute ";
UImanager->ApplyCommand(command + batchMacroName);
}
@@ -11,7 +11,7 @@ Environment variable "G4FORCE_RUN_MANAGER_TYPE" enabled with value == Serial. Fo
**************************************************************
Geant4 version Name: geant4-11-02-patch-02 (21-June-2024)
Geant4 version Name: geant4-11-02-ref-06 (28-June-2024)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
@@ -45,14 +45,21 @@ Registered graphics systems are:
RayTracerX (RayTracerX)
Qt3D (Qt3D)
TOOLSSG_X11_GLES (TSG_X11_GLES, TSGX11, TSG_XT_GLES_FALLBACK)
TOOLSSG_X11_ZB (TSG_X11_ZB, TSGX11ZB)
TOOLSSG_XT_GLES (TSG_XT_GLES, TSGXt, TSG_QT_GLES_FALLBACK)
TOOLSSG_XT_ZB (TSG_XT_ZB, TSGXtZB)
TOOLSSG_QT_GLES (TSG_QT_GLES, TSGQt, TSG)
TOOLSSG_QT_ZB (TSG_QT_ZB, TSGQtZB)
Default graphics system is: TSG_OFFSCREEN (based on batch session).
Default window size hint is: 600x600-0+0 (based on G4VisManager initialisation).
Note: Parameters specified on the command line will override these defaults.
Use "vis/open" without parameters to get these defaults.
You may choose a graphics system (driver) with a parameter of
the command "/vis/open" or "/vis/sceneHandler/create",
or you may omit the driver parameter and choose at run time:
- by argument in the construction of G4VisExecutive
- by environment variable "G4VIS_DEFAULT_DRIVER"
- by entry in "~/.g4session"
- by build flags.
- Note: This feature is not allowed in batch mode.
For further information see "examples/basic/B1/exampleB1.cc"
and "vis.mac".
Registering model factories...
@@ -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
@@ -24,18 +24,18 @@
// ********************************************************************
//
#include "Par04ActionInitialisation.hh"
#include <G4VUserActionInitialization.hh> // for G4VUserActionInitialization
#include "Par04EventAction.hh" // for Par04EventAction
#include "Par04EventAction.hh" // for Par04EventAction
#include "Par04PrimaryGeneratorAction.hh" // for Par04PrimaryGeneratorAction
#include "Par04RunAction.hh" // for Par04RunAction
#include "Par04RunAction.hh" // for Par04RunAction
#include <G4VUserActionInitialization.hh> // for G4VUserActionInitialization
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04ActionInitialisation::Par04ActionInitialisation(Par04DetectorConstruction* aDetector,
Par04ParallelFullWorld* aParallel)
: G4VUserActionInitialization()
, fDetector(aDetector)
, fParallel(aParallel)
: G4VUserActionInitialization(), fDetector(aDetector), fParallel(aParallel)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -24,13 +24,16 @@
// ********************************************************************
//
#include "Par04DefineMeshModel.hh"
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4Track.hh> // for G4Track
#include <G4VFastSimulationModel.hh> // for G4VFastSimulationModel
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4Track.hh> // for G4Track
#include <G4VFastSimulationModel.hh> // for G4VFastSimulationModel
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "Par04EventInformation.hh" // for Par04EventInformation
class G4FastStep;
class G4ParticleDefinition;
class G4Region;
@@ -43,8 +46,7 @@ Par04DefineMeshModel::Par04DefineMeshModel(G4String aModelName, G4Region* aEnvel
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04DefineMeshModel::Par04DefineMeshModel(G4String aModelName)
: G4VFastSimulationModel(aModelName)
Par04DefineMeshModel::Par04DefineMeshModel(G4String aModelName) : G4VFastSimulationModel(aModelName)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -62,10 +64,10 @@ G4bool Par04DefineMeshModel::IsApplicable(const G4ParticleDefinition&)
G4bool Par04DefineMeshModel::ModelTrigger(const G4FastTrack&)
{
auto info = dynamic_cast<Par04EventInformation*>(
auto info = dynamic_cast<Par04EventInformation*>(
G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation());
// check if particle direction and position were already set for this event
if(info != nullptr)
if (info != nullptr)
return !info->GetFlag();
else
return true;
@@ -75,10 +77,9 @@ G4bool Par04DefineMeshModel::ModelTrigger(const G4FastTrack&)
void Par04DefineMeshModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep&)
{
auto info = dynamic_cast<Par04EventInformation*>(
auto info = dynamic_cast<Par04EventInformation*>(
G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation());
if(info == nullptr)
{
if (info == nullptr) {
info = new Par04EventInformation();
G4EventManager::GetEventManager()->GetNonconstCurrentEvent()->SetUserInformation(info);
}
@@ -24,45 +24,47 @@
// ********************************************************************
//
#include "Par04DetectorConstruction.hh"
#include <G4Colour.hh> // for G4Colour
#include <G4Exception.hh> // for G4Exception
#include <G4ExceptionSeverity.hh> // for FatalException
#include <G4SystemOfUnits.hh> // for rad
#include <G4ThreeVector.hh> // for G4ThreeVector
#include "Par04DefineMeshModel.hh" // for Par04DefineMeshModel
#include "Par04DetectorMessenger.hh" // for Par04DetectorMessenger
#include "Par04SensitiveDetector.hh" // for Par04SensitiveDetector
#include "G4Box.hh" // for G4Box
#include "G4LogicalVolume.hh" // for G4LogicalVolume
#include "G4Material.hh" // for G4Material
#include "G4NistManager.hh" // for G4NistManager
#include "G4PVPlacement.hh" // for G4PVPlacement
#include "G4Region.hh" // for G4Region
#include "G4RegionStore.hh" // for G4RegionStore
#include "G4RunManager.hh" // for G4RunManager
#include "G4SDManager.hh" // for G4SDManager
#include "G4Tubs.hh" // for G4Tubs
#include "G4UnitsTable.hh" // for operator<<, G4BestUnit
#include "G4VisAttributes.hh" // for G4VisAttributes
#include <G4Colour.hh> // for G4Colour
#include <G4Exception.hh> // for G4Exception
#include <G4ExceptionSeverity.hh> // for FatalException
#include <G4SystemOfUnits.hh> // for rad
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VUserDetectorConstruction.hh> // for G4VUserDetectorConstruction
#include <G4ios.hh> // for G4endl, G4cout
#include <algorithm> // for max
#include <numeric> // for accumulate
#include <ostream> // for operator<<, basic_ostream
#include <string> // for allocator, char_traits
#include "G4Box.hh" // for G4Box
#include "G4LogicalVolume.hh" // for G4LogicalVolume
#include "G4Material.hh" // for G4Material
#include "G4NistManager.hh" // for G4NistManager
#include "G4PVPlacement.hh" // for G4PVPlacement
#include "G4Region.hh" // for G4Region
#include "G4RegionStore.hh" // for G4RegionStore
#include "G4RunManager.hh" // for G4RunManager
#include "G4SDManager.hh" // for G4SDManager
#include "G4Tubs.hh" // for G4Tubs
#include "G4UnitsTable.hh" // for operator<<, G4BestUnit
#include "G4VisAttributes.hh" // for G4VisAttributes
#include "Par04DefineMeshModel.hh" // for Par04DefineMeshModel
#include "Par04DetectorMessenger.hh" // for Par04DetectorMessenger
#include "Par04SensitiveDetector.hh" // for Par04SensitiveDetector
#include <G4ios.hh> // for G4endl, G4cout
#include <algorithm> // for max
#include <numeric> // for accumulate
#include <ostream> // for operator<<, basic_ostream
#include <string> // for allocator, char_traits
class G4VPhysicalVolume;
#ifdef USE_INFERENCE
#include "Par04MLFastSimModel.hh"
# include "Par04MLFastSimModel.hh"
#endif
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04DetectorConstruction::Par04DetectorConstruction()
: G4VUserDetectorConstruction()
Par04DetectorConstruction::Par04DetectorConstruction() : G4VUserDetectorConstruction()
{
fDetectorMessenger = new Par04DetectorMessenger(this);
fDetectorMessenger = new Par04DetectorMessenger(this);
G4NistManager* nistManager = G4NistManager::Instance();
fAbsorberMaterial[0] = nistManager->FindOrBuildMaterial("G4_PbWO4");
fAbsorberMaterial[0] = nistManager->FindOrBuildMaterial("G4_PbWO4");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -75,59 +77,57 @@ G4VPhysicalVolume* Par04DetectorConstruction::Construct()
{
//--------- Material definition ---------
G4NistManager* nistManager = G4NistManager::Instance();
G4Material* air = nistManager->FindOrBuildMaterial("G4_AIR");
G4Material* air = nistManager->FindOrBuildMaterial("G4_AIR");
//--------- Derived dimensions ---------
G4double full2Pi = 2. * CLHEP::pi * rad;
G4double layerThickness =
std::accumulate(fAbsorberThickness.begin(), fAbsorberThickness.end(), 0.);
G4double detectorOuterRadius = fDetectorInnerRadius + fNbOfLayers * layerThickness;
G4double worldSizeXY = detectorOuterRadius * 4.;
G4double worldSizeZ = fDetectorLength * 2;
G4double worldSizeXY = detectorOuterRadius * 4.;
G4double worldSizeZ = fDetectorLength * 2;
// check number of materials: (1 = homogeneous calo, 2 = sampling calo)
G4int nbOfMaterials = 0;
for(const auto material : fAbsorberMaterial)
{
if(material != nullptr)
nbOfMaterials++;
for (const auto material : fAbsorberMaterial) {
if (material != nullptr) nbOfMaterials++;
}
//--------- World ---------
auto fSolidWorld = new G4Box("World", // name
worldSizeXY / 2., // half-width in X
worldSizeXY / 2., // half-width in Y
worldSizeZ / 2.); // half-width in Z
auto fLogicWorld = new G4LogicalVolume(fSolidWorld, // solid
air, // material
"World"); // name
auto fPhysicWorld = new G4PVPlacement(0, // no rotation
auto fSolidWorld = new G4Box("World", // name
worldSizeXY / 2., // half-width in X
worldSizeXY / 2., // half-width in Y
worldSizeZ / 2.); // half-width in Z
auto fLogicWorld = new G4LogicalVolume(fSolidWorld, // solid
air, // material
"World"); // name
auto fPhysicWorld = new G4PVPlacement(0, // no rotation
G4ThreeVector(), // at (0,0,0)
fLogicWorld, // logical volume
"World", // name
0, // mother volume
false, // not used
99999, // copy number
false); // check overlaps
fLogicWorld, // logical volume
"World", // name
0, // mother volume
false, // not used
99999, // copy number
false); // check overlaps
fLogicWorld->SetVisAttributes(G4VisAttributes::GetInvisible());
//--------- Detector envelope ---------
auto fSolidDetector = new G4Tubs("Detector", // name
fDetectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
fDetectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto fSolidDetector = new G4Tubs("Detector", // name
fDetectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
fDetectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto fLogicDetector = new G4LogicalVolume(fSolidDetector, // solid
air, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
fLogicDetector, // logical volume
"Detector", // name
fLogicWorld, // mother volume
false, // not used
999, // copy number
false); // check overlaps
air, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
fLogicDetector, // logical volume
"Detector", // name
fLogicWorld, // mother volume
false, // not used
999, // copy number
false); // check overlaps
// Region for fast simulation
auto detectorRegion = new G4Region("DetectorRegion");
@@ -141,31 +141,28 @@ G4VPhysicalVolume* Par04DetectorConstruction::Construct()
attribs[1].SetForceSolid(true);
/// useful variable
G4double innerRadius = fDetectorInnerRadius;
for(G4int iLayer = 0; iLayer < fNbOfLayers; iLayer++)
{
for(G4int iMaterial = 0; iMaterial < nbOfMaterials; iMaterial++)
{
auto fSolidLayer = new G4Tubs("Layer", // name
for (G4int iLayer = 0; iLayer < fNbOfLayers; iLayer++) {
for (G4int iMaterial = 0; iMaterial < nbOfMaterials; iMaterial++) {
auto fSolidLayer = new G4Tubs("Layer", // name
innerRadius, // inner radius
innerRadius + fAbsorberThickness[iMaterial], // outer radius
fDetectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
0, // start angle
full2Pi); // delta angle
G4LogicalVolume* logical = new G4LogicalVolume(fSolidLayer, // solid
fAbsorberMaterial[iMaterial], // material
"Layer"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(), // place at centre of mother volume
logical, // logical volume
"Layer", // name
fLogicDetector, // mother volume
false, // not used
"Layer"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(), // place at centre of mother volume
logical, // logical volume
"Layer", // name
fLogicDetector, // mother volume
false, // not used
iLayer * nbOfMaterials + iMaterial, // copy number
false); // check overlaps
false); // check overlaps
logical->SetVisAttributes(attribs[iMaterial]);
innerRadius += fAbsorberThickness[iMaterial];
if(fAbsorberSensitivity[iMaterial])
{
if (fAbsorberSensitivity[iMaterial]) {
fLayerLogical.push_back(logical);
}
}
@@ -182,8 +179,7 @@ void Par04DetectorConstruction::ConstructSDandField()
Par04SensitiveDetector* caloSD =
new Par04SensitiveDetector("sensitiveDetector", fMeshNbOfCells, fMeshSizeOfCells);
G4SDManager::GetSDMpointer()->AddNewDetector(caloSD);
for(const auto logical : fLayerLogical)
{
for (const auto logical : fLayerLogical) {
SetSensitiveDetector(logical, caloSD);
}
@@ -206,7 +202,7 @@ void Par04DetectorConstruction::Print() const
<< G4BestUnit(fAbsorberThickness[0], "Length") << " of "
<< (fAbsorberSensitivity[0] ? "active " : "passive ") << fAbsorberMaterial[0]->GetName()
<< G4endl;
if(fAbsorberMaterial[1] != nullptr)
if (fAbsorberMaterial[1] != nullptr)
G4cout << "--- 2nd layer: \t" << G4BestUnit(fAbsorberThickness[1], "Length") << " of "
<< (fAbsorberSensitivity[1] ? "active " : "passive ") << fAbsorberMaterial[1]->GetName()
<< G4endl;
@@ -219,7 +215,7 @@ void Par04DetectorConstruction::SetAbsorberMaterial(const std::size_t aLayer, co
{
// search material by its name
G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(aName);
if(material)
if (material)
fAbsorberMaterial[aLayer] = material;
else
G4Exception("Par04DetectorConstruction::SetAbsorberMaterial()", "InvalidSetup", FatalException,
@@ -232,13 +228,13 @@ void Par04DetectorConstruction::SetAbsorberMaterial(const std::size_t aLayer, co
void Par04DetectorConstruction::SetAbsorberThickness(const std::size_t aLayer,
const G4double aThickness)
{
if(aLayer < fAbsorberThickness.size())
if (aLayer < fAbsorberThickness.size())
fAbsorberThickness[aLayer] = aThickness;
else
G4Exception("Par04DetectorConstruction::SetAbsorberThickness()", "InvalidSetup", FatalException,
("Requested layer " + std::to_string(aLayer) +
" is larger than number of available layers (" +
std::to_string(fAbsorberThickness.size()) + ").")
("Requested layer " + std::to_string(aLayer)
+ " is larger than number of available layers ("
+ std::to_string(fAbsorberThickness.size()) + ").")
.c_str());
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
@@ -248,21 +244,27 @@ void Par04DetectorConstruction::SetAbsorberThickness(const std::size_t aLayer,
void Par04DetectorConstruction::SetAbsorberSensitivity(const std::size_t aLayer,
const G4bool aSensitivity)
{
if(aLayer < fAbsorberSensitivity.size())
if (aLayer < fAbsorberSensitivity.size())
fAbsorberSensitivity[aLayer] = aSensitivity;
else
G4Exception(
"Par04DetectorConstruction::SetAbsorberSensitivity()", "InvalidSetup", FatalException,
("Requested layer " + std::to_string(aLayer) + " is larger than number of available layers ("+
std::to_string(fAbsorberSensitivity.size()) + ").")
("Requested layer " + std::to_string(aLayer) + " is larger than number of available layers ("
+ std::to_string(fAbsorberSensitivity.size()) + ").")
.c_str());
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04DetectorConstruction::SetInnerRadius(G4double aRadius) { fDetectorInnerRadius = aRadius; }
void Par04DetectorConstruction::SetInnerRadius(G4double aRadius)
{
fDetectorInnerRadius = aRadius;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04DetectorConstruction::SetLength(G4double aLength) { fDetectorLength = aLength; }
void Par04DetectorConstruction::SetLength(G4double aLength)
{
fDetectorLength = aLength;
}
@@ -24,26 +24,28 @@
// ********************************************************************
//
#include "Par04DetectorMessenger.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4bool, G4double, G4int
#include <G4UIcommand.hh> // for G4UIcommand
#include <G4UImessenger.hh> // for G4UImessenger
#include <G4UIparameter.hh> // for G4UIparameter
#include <istream> // for basic_istream, basic_istream...
#include <string> // for operator>>
#include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
#include "G4UIdirectory.hh" // for G4UIdirectory
#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
#include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
#include "G4UIdirectory.hh" // for G4UIdirectory
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4bool, G4double, G4int
#include <G4UIcommand.hh> // for G4UIcommand
#include <G4UImessenger.hh> // for G4UImessenger
#include <G4UIparameter.hh> // for G4UIparameter
#include <istream> // for basic_istream, basic_istream...
#include <string> // for operator>>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04DetectorMessenger::Par04DetectorMessenger(Par04DetectorConstruction* aDetector)
: G4UImessenger()
, fDetector(aDetector)
: G4UImessenger(), fDetector(aDetector)
{
fExampleDir = new G4UIdirectory("/Par04/");
fExampleDir->SetGuidance("UI commands specific to this example");
@@ -84,23 +86,23 @@ Par04DetectorMessenger::Par04DetectorMessenger(Par04DetectorConstruction* aDetec
fAbsorCmd->SetGuidance(" material name");
fAbsorCmd->SetGuidance(" thickness (with unit) : t>0");
fAbsorCmd->SetGuidance(" if sensitive : true/false.");
auto absNbPrm = new G4UIparameter("AbsorNb", 'i', false);
auto absNbPrm = new G4UIparameter("AbsorNb", 'i', false);
absNbPrm->SetGuidance("absor number : from 0 to 1");
absNbPrm->SetParameterRange("AbsorNb>-1&AbsoNb<2");
fAbsorCmd->SetParameter(absNbPrm);
auto matPrm = new G4UIparameter("material", 's', false);
auto matPrm = new G4UIparameter("material", 's', false);
matPrm->SetGuidance("material name");
fAbsorCmd->SetParameter(matPrm);
auto thickPrm = new G4UIparameter("thickness", 'd', false);
auto thickPrm = new G4UIparameter("thickness", 'd', false);
thickPrm->SetGuidance("thickness of absorber");
thickPrm->SetParameterRange("thickness>0.");
fAbsorCmd->SetParameter(thickPrm);
auto unitPrm = new G4UIparameter("unit", 's', false);
auto unitPrm = new G4UIparameter("unit", 's', false);
unitPrm->SetGuidance("unit of thickness");
G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
unitPrm->SetParameterCandidates(unitList);
fAbsorCmd->SetParameter(unitPrm);
auto sensitivePrm = new G4UIparameter("sensitive", 'b', false);
auto sensitivePrm = new G4UIparameter("sensitive", 'b', false);
sensitivePrm->SetGuidance("if absorber is sensitive (registers energy deposits)");
fAbsorCmd->SetParameter(sensitivePrm);
@@ -171,24 +173,19 @@ Par04DetectorMessenger::~Par04DetectorMessenger()
void Par04DetectorMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewValue)
{
if(aCommand == fPrintCmd)
{
if (aCommand == fPrintCmd) {
fDetector->Print();
}
else if(aCommand == fDetectorInnerRadiusCmd)
{
else if (aCommand == fDetectorInnerRadiusCmd) {
fDetector->SetInnerRadius(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
}
else if(aCommand == fDetectorLengthCmd)
{
else if (aCommand == fDetectorLengthCmd) {
fDetector->SetLength(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
}
else if(aCommand == fNbLayersCmd)
{
else if (aCommand == fNbLayersCmd) {
fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(aNewValue));
}
else if(aCommand == fAbsorCmd)
{
else if (aCommand == fAbsorCmd) {
G4int num;
G4double thick;
G4String unt, mat;
@@ -201,26 +198,21 @@ void Par04DetectorMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewVal
fDetector->SetAbsorberThickness(num, thick);
fDetector->SetAbsorberSensitivity(num, sensitive);
}
else if(aCommand == fMeshNbRhoCellsCmd)
{
else if (aCommand == fMeshNbRhoCellsCmd) {
fDetector->SetMeshNbOfCells(0, fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue));
}
else if(aCommand == fMeshNbPhiCellsCmd)
{
else if (aCommand == fMeshNbPhiCellsCmd) {
fDetector->SetMeshNbOfCells(1, fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
fDetector->SetMeshSizeOfCells(1,
2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
}
else if(aCommand == fMeshNbZCellsCmd)
{
else if (aCommand == fMeshNbZCellsCmd) {
fDetector->SetMeshNbOfCells(2, fMeshNbZCellsCmd->GetNewIntValue(aNewValue));
}
else if(aCommand == fMeshSizeRhoCellsCmd)
{
else if (aCommand == fMeshSizeRhoCellsCmd) {
fDetector->SetMeshSizeOfCells(0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue));
}
else if(aCommand == fMeshSizeZCellsCmd)
{
else if (aCommand == fMeshSizeZCellsCmd) {
fDetector->SetMeshSizeOfCells(2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue));
}
}
@@ -231,36 +223,28 @@ G4String Par04DetectorMessenger::GetCurrentValue(G4UIcommand* aCommand)
{
G4String cv;
if(aCommand == fDetectorInnerRadiusCmd)
{
if (aCommand == fDetectorInnerRadiusCmd) {
cv = fDetectorInnerRadiusCmd->ConvertToString(fDetector->GetInnerRadius(), "mm");
}
else if(aCommand == fDetectorLengthCmd)
{
else if (aCommand == fDetectorLengthCmd) {
cv = fDetectorLengthCmd->ConvertToString(fDetector->GetLength(), "mm");
}
else if(aCommand == fNbLayersCmd)
{
else if (aCommand == fNbLayersCmd) {
cv = fNbLayersCmd->ConvertToString(fDetector->GetNbOfLayers());
}
else if(aCommand == fMeshNbRhoCellsCmd)
{
else if (aCommand == fMeshNbRhoCellsCmd) {
cv = fMeshNbRhoCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[0]);
}
else if(aCommand == fMeshNbPhiCellsCmd)
{
else if (aCommand == fMeshNbPhiCellsCmd) {
cv = fMeshNbPhiCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[1]);
}
else if(aCommand == fMeshNbZCellsCmd)
{
else if (aCommand == fMeshNbZCellsCmd) {
cv = fMeshNbZCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[2]);
}
else if(aCommand == fMeshSizeRhoCellsCmd)
{
else if (aCommand == fMeshSizeRhoCellsCmd) {
cv = fMeshSizeRhoCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[0]);
}
else if(aCommand == fMeshSizeZCellsCmd)
{
else if (aCommand == fMeshSizeZCellsCmd) {
cv = fMeshSizeZCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[2]);
}
return cv;
@@ -26,47 +26,47 @@
#include "Par04EventAction.hh"
#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include "Par04ParallelFullWorld.hh"
#include "G4AnalysisManager.hh" // for G4AnalysisManager
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4AnalysisManager.hh" // for G4AnalysisManager
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4Exception.hh" // for G4Exception, G4ExceptionDesc...
#include "G4ExceptionSeverity.hh" // for FatalException
#include "G4GenericAnalysisManager.hh" // for G4GenericAnalysisManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4PrimaryParticle.hh" // for G4PrimaryParticle
#include "G4PrimaryVertex.hh" // for G4PrimaryVertex
#include "G4SDManager.hh" // for G4SDManager
#include "G4SystemOfUnits.hh" // for GeV
#include "G4THitsCollection.hh" // for G4THitsCollection
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4Timer.hh" // for G4Timer
#include "G4UserEventAction.hh" // for G4UserEventAction
#include <CLHEP/Units/SystemOfUnits.h> // for GeV
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include "G4Exception.hh" // for G4Exception, G4ExceptionDesc...
#include "G4ExceptionSeverity.hh" // for FatalException
#include "G4GenericAnalysisManager.hh" // for G4GenericAnalysisManager
#include "G4PrimaryParticle.hh" // for G4PrimaryParticle
#include "G4PrimaryVertex.hh" // for G4PrimaryVertex
#include "G4SystemOfUnits.hh" // for GeV
#include "G4THitsCollection.hh" // for G4THitsCollection
#include "G4ThreeVector.hh" // for G4ThreeVector
#include "G4Timer.hh" // for G4Timer
#include "G4UserEventAction.hh" // for G4UserEventAction
#include <algorithm> // for max
#include <cmath> // for log10
#include <cstddef> // for size_t
#include <ostream> // for basic_ostream::operator<<
#include <CLHEP/Units/SystemOfUnits.h> // for GeV
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <algorithm> // for max
#include <cmath> // for log10
#include <cstddef> // for size_t
#include <ostream> // for basic_ostream::operator<<
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04EventAction::Par04EventAction(Par04DetectorConstruction* aDetector,
Par04ParallelFullWorld* aParallel)
: G4UserEventAction()
, fHitCollectionID(-1)
, fPhysicalFullHitCollectionID(-1)
, fPhysicalFastHitCollectionID(-1)
, fTimer()
, fDetector(aDetector)
, fParallel(aParallel)
: G4UserEventAction(),
fHitCollectionID(-1),
fPhysicalFullHitCollectionID(-1),
fPhysicalFastHitCollectionID(-1),
fTimer(),
fDetector(aDetector),
fParallel(aParallel)
{
fCellNbRho = aDetector->GetMeshNbOfCells().x();
fCellNbPhi = aDetector->GetMeshNbOfCells().y();
fCellNbZ = aDetector->GetMeshNbOfCells().z();
fCellNbZ = aDetector->GetMeshNbOfCells().z();
fCalEdep.reserve(fCellNbRho * fCellNbPhi * fCellNbZ);
fCalRho.reserve(fCellNbRho * fCellNbPhi * fCellNbZ);
fCalPhi.reserve(fCellNbRho * fCellNbPhi * fCellNbZ);
@@ -83,19 +83,22 @@ Par04EventAction::~Par04EventAction() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04EventAction::BeginOfEventAction(const G4Event*) {
void Par04EventAction::BeginOfEventAction(const G4Event*)
{
StartTimer();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04EventAction::StartTimer() {
void Par04EventAction::StartTimer()
{
fTimer.Start();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04EventAction::StopTimer() {
void Par04EventAction::StopTimer()
{
fTimer.Stop();
}
@@ -107,44 +110,36 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
StopTimer();
// Get hits collection ID (only once)
if(fHitCollectionID == -1)
{
if (fHitCollectionID == -1) {
fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("hits");
}
if(fPhysicalFullHitCollectionID == -1)
{
if (fPhysicalFullHitCollectionID == -1) {
fPhysicalFullHitCollectionID =
G4SDManager::GetSDMpointer()->GetCollectionID("physicalCellsFullSim");
}
if(fPhysicalFastHitCollectionID == -1)
{
if (fPhysicalFastHitCollectionID == -1) {
fPhysicalFastHitCollectionID =
G4SDManager::GetSDMpointer()->GetCollectionID("physicalCellsFastSim");
}
// Get hits collection
auto hitsCollection =
static_cast<Par04HitsCollection*>(aEvent->GetHCofThisEvent()->GetHC(fHitCollectionID));
auto physicalFullHitsCollection =
static_cast<Par04HitsCollection*>(aEvent->GetHCofThisEvent()
->GetHC(fPhysicalFullHitCollectionID));
auto physicalFastHitsCollection =
static_cast<Par04HitsCollection*>(aEvent->GetHCofThisEvent()
->GetHC(fPhysicalFastHitCollectionID));
auto physicalFullHitsCollection = static_cast<Par04HitsCollection*>(
aEvent->GetHCofThisEvent()->GetHC(fPhysicalFullHitCollectionID));
auto physicalFastHitsCollection = static_cast<Par04HitsCollection*>(
aEvent->GetHCofThisEvent()->GetHC(fPhysicalFastHitCollectionID));
if(hitsCollection == nullptr)
{
if (hitsCollection == nullptr) {
G4ExceptionDescription msg;
msg << "Cannot access hitsCollection ID " << fHitCollectionID;
G4Exception("Par04EventAction::GetHitsCollection()", "MyCode0001", FatalException, msg);
}
if(physicalFullHitsCollection == nullptr)
{
if (physicalFullHitsCollection == nullptr) {
G4ExceptionDescription msg;
msg << "Cannot access physical full sim hitsCollection ID " << fPhysicalFullHitCollectionID;
G4Exception("Par04EventAction::GetHitsCollection()", "MyCode0001", FatalException, msg);
}
if(physicalFastHitsCollection == nullptr)
{
if (physicalFastHitsCollection == nullptr) {
G4ExceptionDescription msg;
msg << "Cannot access physical fast sim hitsCollection ID " << fPhysicalFastHitCollectionID;
G4Exception("Par04EventAction::GetHitsCollection()", "MyCode0001", FatalException, msg);
@@ -152,17 +147,15 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
// Get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
// Retrieve only once detector dimensions
if(fCellSizeZ == 0)
{
fCellSizeZ = fDetector->GetMeshSizeOfCells().z();
if (fCellSizeZ == 0) {
fCellSizeZ = fDetector->GetMeshSizeOfCells().z();
fCellSizePhi = fDetector->GetMeshSizeOfCells().y();
fCellSizeRho = fDetector->GetMeshSizeOfCells().x();
fCellNbRho = fDetector->GetMeshNbOfCells().x();
fCellNbPhi = fDetector->GetMeshNbOfCells().y();
fCellNbZ = fDetector->GetMeshNbOfCells().z();
fCellNbRho = fDetector->GetMeshNbOfCells().x();
fCellNbPhi = fDetector->GetMeshNbOfCells().y();
fCellNbZ = fDetector->GetMeshNbOfCells().z();
}
if(fPhysicalNbLayers == 0)
{
if (fPhysicalNbLayers == 0) {
fPhysicalNbLayers = fParallel->GetNbOfLayers();
fPhysicalNbSlices = fParallel->GetNbOfSlices();
fPhysicalNbRows = fParallel->GetNbOfRows();
@@ -172,7 +165,7 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
// To calculate shower axis and entry point to the detector
auto primaryVertex =
G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetPrimaryVertex();
auto primaryParticle = primaryVertex->GetPrimary(0);
auto primaryParticle = primaryVertex->GetPrimary(0);
G4double primaryEnergy = primaryParticle->GetTotalEnergy();
// Estimate from vertex and particle direction the entry point to the detector
// Calculate entrance point to the detector located at z = 0
@@ -181,41 +174,39 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
primaryVertex->GetPosition() - primaryVertex->GetPosition().z() * primaryDirection;
// Resize back to initial mesh size
fCalEdep.resize(fCellNbRho * fCellNbPhi * fCellNbZ,0);
fCalRho.resize(fCellNbRho * fCellNbPhi * fCellNbZ,0);
fCalPhi.resize(fCellNbRho * fCellNbPhi * fCellNbZ,0);
fCalZ.resize(fCellNbRho * fCellNbPhi * fCellNbZ,0);
fCalPhysicalEdep.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices,0);
fCalPhysicalLayer.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices,0);
fCalPhysicalSlice.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices,0);
fCalPhysicalRow.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices,0);
fCalEdep.resize(fCellNbRho * fCellNbPhi * fCellNbZ, 0);
fCalRho.resize(fCellNbRho * fCellNbPhi * fCellNbZ, 0);
fCalPhi.resize(fCellNbRho * fCellNbPhi * fCellNbZ, 0);
fCalZ.resize(fCellNbRho * fCellNbPhi * fCellNbZ, 0);
fCalPhysicalEdep.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices, 0);
fCalPhysicalLayer.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices, 0);
fCalPhysicalSlice.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices, 0);
fCalPhysicalRow.resize(fPhysicalNbLayers * fPhysicalNbRows * fPhysicalNbSlices, 0);
// Fill histograms
Par04Hit* hit = nullptr;
G4double hitEn = 0;
G4double totalEnergy = 0;
G4int hitNum = 0;
G4int totalNum = 0;
G4int hitZ = -1;
G4int hitRho = -1;
G4int hitPhi = -1;
G4int hitType = -1;
Par04Hit* hit = nullptr;
G4double hitEn = 0;
G4double totalEnergy = 0;
G4int hitNum = 0;
G4int totalNum = 0;
G4int hitZ = -1;
G4int hitRho = -1;
G4int hitPhi = -1;
G4int hitType = -1;
G4int numNonZeroThresholdCells = 0;
G4double tDistance = 0., rDistance = 0., phiDistance = 0.;
G4double tFirstMoment = 0., tSecondMoment = 0.;
G4double rFirstMoment = 0., rSecondMoment = 0.;
G4double phiMean = 0.;
for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++)
{
hit = static_cast<Par04Hit*>(hitsCollection->GetHit(iHit));
hitZ = hit->GetZid();
hitRho = hit->GetRhoId();
hitPhi = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
for (size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) {
hit = static_cast<Par04Hit*>(hitsCollection->GetHit(iHit));
hitZ = hit->GetZid();
hitRho = hit->GetRhoId();
hitPhi = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
hitType = hit->GetType();
if(hitEn > 0)
{
if (hitEn > 0) {
totalEnergy += hitEn;
totalNum += hitNum;
tDistance = hitZ * fCellSizeZ;
@@ -227,12 +218,11 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
analysisManager->FillH1(4, tDistance, hitEn);
analysisManager->FillH1(5, rDistance, hitEn);
analysisManager->FillH1(10, hitType);
if(hitEn > 0.0005)
{ // e > 0.5 keV
if (hitEn > 0.0005) { // e > 0.5 keV
fCalEdep[numNonZeroThresholdCells] = hitEn;
fCalRho[numNonZeroThresholdCells] = hitRho;
fCalPhi[numNonZeroThresholdCells] = hitPhi;
fCalZ[numNonZeroThresholdCells] = hitZ;
fCalRho[numNonZeroThresholdCells] = hitRho;
fCalPhi[numNonZeroThresholdCells] = hitPhi;
fCalZ[numNonZeroThresholdCells] = hitZ;
numNonZeroThresholdCells++;
analysisManager->FillH1(13, std::log10(hitEn));
analysisManager->FillH1(15, hitNum);
@@ -258,15 +248,13 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
analysisManager->FillNtupleDColumn(0, 0, primaryEnergy);
analysisManager->FillNtupleDColumn(0, 1, fTimer.GetRealElapsed());
// Second loop over hits to calculate second moments
for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++)
{
hit = static_cast<Par04Hit*>(hitsCollection->GetHit(iHit));
hitEn = hit->GetEdep();
hitZ = hit->GetZid();
for (size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) {
hit = static_cast<Par04Hit*>(hitsCollection->GetHit(iHit));
hitEn = hit->GetEdep();
hitZ = hit->GetZid();
hitRho = hit->GetRhoId();
hitPhi = hit->GetPhiId();
if(hitEn > 0)
{
if (hitEn > 0) {
tDistance = hitZ * fCellSizeZ;
rDistance = hitRho * fCellSizeRho;
phiDistance = hitPhi * fCellSizePhi;
@@ -281,55 +269,50 @@ void Par04EventAction::EndOfEventAction(const G4Event* aEvent)
analysisManager->FillH1(9, rSecondMoment);
// Fill ntuple with physical readout data
G4double totalPhysicalEnergy = 0;
G4double totalPhysicalEnergy = 0;
totalNum = 0;
hitEn = 0;
hitNum = 0;
G4int hitLayer = -1;
G4int hitRow = -1;
G4int hitSlice = -1;
G4int hitLayer = -1;
G4int hitRow = -1;
G4int hitSlice = -1;
numNonZeroThresholdCells = 0;
for(size_t iHit = 0; iHit < physicalFullHitsCollection->entries(); iHit++)
{
hit = static_cast<Par04Hit*>(physicalFullHitsCollection->GetHit(iHit));
for (size_t iHit = 0; iHit < physicalFullHitsCollection->entries(); iHit++) {
hit = static_cast<Par04Hit*>(physicalFullHitsCollection->GetHit(iHit));
hitLayer = hit->GetRhoId();
hitRow = hit->GetZid();
hitSlice = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
if(hitEn > 0)
{
hitRow = hit->GetZid();
hitSlice = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
if (hitEn > 0) {
totalPhysicalEnergy += hitEn;
totalNum += hitNum;
if(hitEn > 0.0005)
{ // e > 0.5 keV
if (hitEn > 0.0005) { // e > 0.5 keV
fCalPhysicalEdep[numNonZeroThresholdCells] = hitEn;
fCalPhysicalLayer[numNonZeroThresholdCells] = hitLayer;
fCalPhysicalRow[numNonZeroThresholdCells] = hitRow;
fCalPhysicalSlice[numNonZeroThresholdCells] = hitSlice;
fCalPhysicalLayer[numNonZeroThresholdCells] = hitLayer;
fCalPhysicalRow[numNonZeroThresholdCells] = hitRow;
fCalPhysicalSlice[numNonZeroThresholdCells] = hitSlice;
numNonZeroThresholdCells++;
analysisManager->FillH1(19, std::log10(hitEn));
analysisManager->FillH1(21, hitNum);
}
}
}for(size_t iHit = 0; iHit < physicalFastHitsCollection->entries(); iHit++)
{
hit = static_cast<Par04Hit*>(physicalFastHitsCollection->GetHit(iHit));
}
for (size_t iHit = 0; iHit < physicalFastHitsCollection->entries(); iHit++) {
hit = static_cast<Par04Hit*>(physicalFastHitsCollection->GetHit(iHit));
hitLayer = hit->GetRhoId();
hitRow = hit->GetZid();
hitSlice = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
if(hitEn > 0)
{
hitRow = hit->GetZid();
hitSlice = hit->GetPhiId();
hitEn = hit->GetEdep();
hitNum = hit->GetNdep();
if (hitEn > 0) {
totalPhysicalEnergy += hitEn;
totalNum += hitNum;
if(hitEn > 0.0005)
{ // e > 0.5 keV
if (hitEn > 0.0005) { // e > 0.5 keV
fCalPhysicalEdep[numNonZeroThresholdCells] = hitEn;
fCalPhysicalLayer[numNonZeroThresholdCells] = hitLayer;
fCalPhysicalRow[numNonZeroThresholdCells] = hitRow;
fCalPhysicalSlice[numNonZeroThresholdCells] = hitSlice;
fCalPhysicalLayer[numNonZeroThresholdCells] = hitLayer;
fCalPhysicalRow[numNonZeroThresholdCells] = hitRow;
fCalPhysicalSlice[numNonZeroThresholdCells] = hitSlice;
numNonZeroThresholdCells++;
analysisManager->FillH1(19, std::log10(hitEn));
analysisManager->FillH1(21, hitNum);
@@ -24,17 +24,16 @@
// ********************************************************************
//
#include "Par04EventInformation.hh"
#include <CLHEP/Vector/ThreeVector.h> // for operator<<
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
#include <G4ios.hh> // for G4cout, G4endl
#include <ostream> // for operator<<, basic_ostream, ost...
#include <G4ios.hh> // for G4cout, G4endl
#include <ostream> // for operator<<, basic_ostream, ost...
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04EventInformation::Par04EventInformation()
: G4VUserEventInformation()
, fDirection()
, fPosition()
: G4VUserEventInformation(), fDirection(), fPosition()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -24,35 +24,36 @@
// ********************************************************************
//
#include "Par04Hit.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for mm, pi, MeV, cm, rad
#include <CLHEP/Vector/ThreeVector.h> // for operator/, operator<<, Hep...
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4String.hh> // for G4String
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Transform3D.hh> // for G4Transform3D
#include <G4VHit.hh> // for G4VHit
#include <algorithm> // for max
#include <iostream> // for operator<<, basic_ostream:...
#include <string> // for operator<
#include "G4AttDef.hh" // for G4AttDef
#include "G4AttDefStore.hh" // for GetInstance
#include "G4AttValue.hh" // for G4AttValue
#include "G4Colour.hh" // for G4Colour
#include "G4SystemOfUnits.hh" // for mm, MeV, cm, rad
#include "G4Tubs.hh" // for G4Tubs
#include "G4UnitsTable.hh" // for G4BestUnit
#include "G4VVisManager.hh" // for G4VVisManager
#include "G4VisAttributes.hh" // for G4VisAttributes
#include <cmath> // for log10
template <class Type> class G4Allocator;
#include "G4AttDef.hh" // for G4AttDef
#include "G4AttDefStore.hh" // for GetInstance
#include "G4AttValue.hh" // for G4AttValue
#include "G4Colour.hh" // for G4Colour
#include "G4SystemOfUnits.hh" // for mm, MeV, cm, rad
#include "G4Tubs.hh" // for G4Tubs
#include "G4UnitsTable.hh" // for G4BestUnit
#include "G4VVisManager.hh" // for G4VVisManager
#include "G4VisAttributes.hh" // for G4VisAttributes
#include <CLHEP/Units/SystemOfUnits.h> // for mm, pi, MeV, cm, rad
#include <CLHEP/Vector/ThreeVector.h> // for operator/, operator<<, Hep...
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4String.hh> // for G4String
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Transform3D.hh> // for G4Transform3D
#include <G4VHit.hh> // for G4VHit
#include <algorithm> // for max
#include <cmath> // for log10
#include <iostream> // for operator<<, basic_ostream:...
#include <string> // for operator<
template<class Type>
class G4Allocator;
G4ThreadLocal G4Allocator<Par04Hit>* Par04HitAllocator;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04Hit::Par04Hit()
: G4VHit()
{}
Par04Hit::Par04Hit() : G4VHit() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -60,18 +61,17 @@ Par04Hit::~Par04Hit() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04Hit::Par04Hit(const Par04Hit& aRight)
: G4VHit()
Par04Hit::Par04Hit(const Par04Hit& aRight) : G4VHit()
{
fEdep = aRight.fEdep;
fNdep = aRight.fNdep;
fZId = aRight.fZId;
fRhoId = aRight.fRhoId;
fPhiId = aRight.fPhiId;
fTime = aRight.fTime;
fPos = aRight.fPos;
fRot = aRight.fRot;
fType = aRight.fType;
fEdep = aRight.fEdep;
fNdep = aRight.fNdep;
fZId = aRight.fZId;
fRhoId = aRight.fRhoId;
fPhiId = aRight.fPhiId;
fTime = aRight.fTime;
fPos = aRight.fPos;
fRot = aRight.fRot;
fType = aRight.fType;
fLogVol = aRight.fLogVol;
}
@@ -79,15 +79,15 @@ Par04Hit::Par04Hit(const Par04Hit& aRight)
const Par04Hit& Par04Hit::operator=(const Par04Hit& aRight)
{
fEdep = aRight.fEdep;
fNdep = aRight.fNdep;
fZId = aRight.fZId;
fRhoId = aRight.fRhoId;
fPhiId = aRight.fPhiId;
fTime = aRight.fTime;
fPos = aRight.fPos;
fRot = aRight.fRot;
fType = aRight.fType;
fEdep = aRight.fEdep;
fNdep = aRight.fNdep;
fZId = aRight.fZId;
fRhoId = aRight.fRhoId;
fPhiId = aRight.fPhiId;
fTime = aRight.fTime;
fPos = aRight.fPos;
fRot = aRight.fRot;
fType = aRight.fType;
fLogVol = aRight.fLogVol;
return *this;
}
@@ -105,22 +105,17 @@ void Par04Hit::Draw()
{
/// Arbitrary size corresponds to the example macros
G4ThreeVector meshSize(2.325 * mm, 2 * CLHEP::pi / 50. * CLHEP::rad, 3.4 * mm);
G4int numPhiCells = CLHEP::pi * 2. / meshSize.y();
G4int numPhiCells = CLHEP::pi * 2. / meshSize.y();
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
// Hits can be filtered out in visualisation
if(!pVVisManager->FilterHit(*this))
return;
if (!pVVisManager->FilterHit(*this)) return;
// Do not plot hits from parallel world
if(fType >= 2)
return;
if (fType >= 2) return;
// Do not draw empty hits
if(fEdep <= 0)
return;
if (fEdep <= 0) return;
// Do not plot if default values were not changed
if(fRhoId == -1 && fZId == -1 && fPhiId == -1)
return;
if(pVVisManager)
{
if (fRhoId == -1 && fZId == -1 && fPhiId == -1) return;
if (pVVisManager) {
G4Transform3D trans(fRot, fPos);
G4VisAttributes attribs;
G4Tubs solid("draw", fRhoId * meshSize.x(), (fRhoId + 1) * meshSize.x(), meshSize.z() / 2.,
@@ -145,13 +140,12 @@ const std::map<G4String, G4AttDef>* Par04Hit::GetAttDefs() const
{
G4bool isNew;
std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Par04Hit", isNew);
if(isNew)
{
if (isNew) {
(*store)["HitType"] = G4AttDef("HitType", "Hit Type", "Physics", "", "G4String");
(*store)["Energy"] =
G4AttDef("Energy", "Energy Deposited", "Physics", "G4BestUnit", "G4double");
(*store)["Time"] = G4AttDef("Time", "Time", "Physics", "G4BestUnit", "G4double");
(*store)["Pos"] = G4AttDef("Pos", "Position", "Physics", "G4BestUnit", "G4ThreeVector");
(*store)["Pos"] = G4AttDef("Pos", "Position", "Physics", "G4BestUnit", "G4ThreeVector");
}
return store;
}
@@ -173,6 +167,6 @@ std::vector<G4AttValue>* Par04Hit::CreateAttValues() const
void Par04Hit::Print()
{
std::cout << "\tHit " << fEdep / MeV << " MeV from " << fNdep << " deposits at " << fPos / cm
<< " cm rotation " << fRot << " (R,phi,z)= (" << fRhoId << ", " << fPhiId
<< ", " << fZId << "), " << fTime << " ns" << std::endl;
<< " cm rotation " << fRot << " (R,phi,z)= (" << fRhoId << ", " << fPhiId << ", "
<< fZId << "), " << fTime << " ns" << std::endl;
}
@@ -24,39 +24,40 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
#include "G4UIcmdWithAString.hh" // for G4UIcmdWithAString
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIdirectory.hh" // for G4UIdirectory
#include "Par04InferenceMessenger.hh"
#include "Par04InferenceSetup.hh" // for Par04InferenceSetup
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4UImessenger.hh> // for G4UImessenger
#include <string> // for stoi
# include "Par04InferenceMessenger.hh"
# include "Par04InferenceSetup.hh" // for Par04InferenceSetup
# include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
# include "G4UIcmdWithAString.hh" // for G4UIcmdWithAString
# include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
# include "G4UIdirectory.hh" // for G4UIdirectory
# include <CLHEP/Units/SystemOfUnits.h> // for pi
# include <G4ApplicationState.hh> // for G4State_Idle
# include <G4ThreeVector.hh> // for G4ThreeVector
# include <G4UImessenger.hh> // for G4UImessenger
# include <string> // for stoi
class G4UIcommand;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04InferenceMessenger::Par04InferenceMessenger(
Par04InferenceSetup *aInference)
: G4UImessenger(), fInference(aInference) {
Par04InferenceMessenger::Par04InferenceMessenger(Par04InferenceSetup* aInference)
: G4UImessenger(), fInference(aInference)
{
fExampleDir = new G4UIdirectory("/Par04/");
fExampleDir->SetGuidance("UI commands specific to this example");
fInferenceDir = new G4UIdirectory("/Par04/inference/");
fInferenceDir->SetGuidance("Inference construction UI commands");
fInferenceLibraryCmd =
new G4UIcmdWithAString("/Par04/inference/setInferenceLibrary", this);
fInferenceLibraryCmd = new G4UIcmdWithAString("/Par04/inference/setInferenceLibrary", this);
fInferenceLibraryCmd->SetGuidance("Inference library.");
fInferenceLibraryCmd->SetParameterName("InferenceLibrary", false);
fInferenceLibraryCmd->AvailableForStates(G4State_Idle);
fInferenceLibraryCmd->SetToBeBroadcasted(true);
fSizeLatentVectorCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setSizeLatentVector", this);
fSizeLatentVectorCmd = new G4UIcmdWithAnInteger("/Par04/inference/setSizeLatentVector", this);
fSizeLatentVectorCmd->SetGuidance("Set size of the latent space vector.");
fSizeLatentVectorCmd->SetParameterName("SizeLatentVector", false);
fSizeLatentVectorCmd->SetRange("SizeLatentVector>0");
@@ -64,78 +65,64 @@ Par04InferenceMessenger::Par04InferenceMessenger(
fSizeLatentVectorCmd->SetToBeBroadcasted(true);
fSizeConditionVectorCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setSizeConditionVector", this);
new G4UIcmdWithAnInteger("/Par04/inference/setSizeConditionVector", this);
fSizeConditionVectorCmd->SetGuidance("Set size of the condition vector.");
fSizeConditionVectorCmd->SetParameterName("SizeConditionVector", false);
fSizeConditionVectorCmd->SetRange("SizeConditionVector>0");
fSizeConditionVectorCmd->AvailableForStates(G4State_Idle);
fSizeConditionVectorCmd->SetToBeBroadcasted(true);
fModelPathNameCmd =
new G4UIcmdWithAString("/Par04/inference/setModelPathName", this);
fModelPathNameCmd = new G4UIcmdWithAString("/Par04/inference/setModelPathName", this);
fModelPathNameCmd->SetGuidance("Model path and name.");
fModelPathNameCmd->SetParameterName("Name", false);
fModelPathNameCmd->AvailableForStates(G4State_Idle);
fModelPathNameCmd->SetToBeBroadcasted(true);
fProfileFlagCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setProfileFlag", this);
fProfileFlagCmd->SetGuidance(
"Flag to save a json file for model execution profiling.");
fProfileFlagCmd = new G4UIcmdWithAnInteger("/Par04/inference/setProfileFlag", this);
fProfileFlagCmd->SetGuidance("Flag to save a json file for model execution profiling.");
fProfileFlagCmd->SetParameterName("ProfileFlag", false);
fProfileFlagCmd->SetRange("ProfileFlag>-1");
fProfileFlagCmd->AvailableForStates(G4State_Idle);
fProfileFlagCmd->SetToBeBroadcasted(true);
fOptimizationFlagCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setOptimizationFlag", this);
fOptimizationFlagCmd = new G4UIcmdWithAnInteger("/Par04/inference/setOptimizationFlag", this);
fOptimizationFlagCmd->SetGuidance("Set optimization flag");
fOptimizationFlagCmd->SetParameterName("OptimizationFlag", false);
fOptimizationFlagCmd->SetRange("OptimizationFlag>-1");
fOptimizationFlagCmd->AvailableForStates(G4State_Idle);
fOptimizationFlagCmd->SetToBeBroadcasted(true);
fMeshNbRhoCellsCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setNbOfRhoCells", this);
fMeshNbRhoCellsCmd->SetGuidance(
"Set number of rho cells in the cylindrical mesh readout.");
fMeshNbRhoCellsCmd = new G4UIcmdWithAnInteger("/Par04/inference/setNbOfRhoCells", this);
fMeshNbRhoCellsCmd->SetGuidance("Set number of rho cells in the cylindrical mesh readout.");
fMeshNbRhoCellsCmd->SetParameterName("NbRhoCells", false);
fMeshNbRhoCellsCmd->SetRange("NbRhoCells>0");
fMeshNbRhoCellsCmd->AvailableForStates(G4State_Idle);
fMeshNbRhoCellsCmd->SetToBeBroadcasted(true);
fMeshNbPhiCellsCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setNbOfPhiCells", this);
fMeshNbPhiCellsCmd->SetGuidance(
"Set number of phi cells in the cylindrical mesh readout.");
fMeshNbPhiCellsCmd = new G4UIcmdWithAnInteger("/Par04/inference/setNbOfPhiCells", this);
fMeshNbPhiCellsCmd->SetGuidance("Set number of phi cells in the cylindrical mesh readout.");
fMeshNbPhiCellsCmd->SetParameterName("NbPhiCells", false);
fMeshNbPhiCellsCmd->SetRange("NbPhiCells>0");
fMeshNbPhiCellsCmd->AvailableForStates(G4State_Idle);
fMeshNbPhiCellsCmd->SetToBeBroadcasted(true);
fMeshNbZCellsCmd =
new G4UIcmdWithAnInteger("/Par04/inference/setNbOfZCells", this);
fMeshNbZCellsCmd->SetGuidance(
"Set number of z cells in the cylindrical mesh readout.");
fMeshNbZCellsCmd = new G4UIcmdWithAnInteger("/Par04/inference/setNbOfZCells", this);
fMeshNbZCellsCmd->SetGuidance("Set number of z cells in the cylindrical mesh readout.");
fMeshNbZCellsCmd->SetParameterName("NbZCells", false);
fMeshNbZCellsCmd->SetRange("NbZCells>0");
fMeshNbZCellsCmd->AvailableForStates(G4State_Idle);
fMeshNbZCellsCmd->SetToBeBroadcasted(true);
fMeshSizeRhoCellsCmd =
new G4UIcmdWithADoubleAndUnit("/Par04/inference/setSizeOfRhoCells", this);
fMeshSizeRhoCellsCmd->SetGuidance(
"Set size of rho cells in the cylindrical readout mesh");
fMeshSizeRhoCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/inference/setSizeOfRhoCells", this);
fMeshSizeRhoCellsCmd->SetGuidance("Set size of rho cells in the cylindrical readout mesh");
fMeshSizeRhoCellsCmd->SetParameterName("Size", false);
fMeshSizeRhoCellsCmd->SetRange("Size>0.");
fMeshSizeRhoCellsCmd->SetUnitCategory("Length");
fMeshSizeRhoCellsCmd->AvailableForStates(G4State_Idle);
fMeshSizeRhoCellsCmd->SetToBeBroadcasted(true);
fMeshSizeZCellsCmd =
new G4UIcmdWithADoubleAndUnit("/Par04/inference/setSizeOfZCells", this);
fMeshSizeZCellsCmd->SetGuidance(
"Set size of z cells in the cylindrical readout mesh");
fMeshSizeZCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/inference/setSizeOfZCells", this);
fMeshSizeZCellsCmd->SetGuidance("Set size of z cells in the cylindrical readout mesh");
fMeshSizeZCellsCmd->SetParameterName("Size", false);
fMeshSizeZCellsCmd->SetRange("Size>0.");
fMeshSizeZCellsCmd->SetUnitCategory("Length");
@@ -145,8 +132,7 @@ Par04InferenceMessenger::Par04InferenceMessenger(
// Onnx Runtime Execution Provider flag commands
fCudaFlagCmd = new G4UIcmdWithAnInteger("/Par04/inference/setCudaFlag", this);
G4cout << "f CudaFlagCmd " << fCudaFlagCmd << G4endl;
fCudaFlagCmd->SetGuidance(
"Whether to use CUDA Execution Provider for Onnx Runtime or not");
fCudaFlagCmd->SetGuidance("Whether to use CUDA Execution Provider for Onnx Runtime or not");
fCudaFlagCmd->SetParameterName("CudaFlag", false);
fCudaFlagCmd->SetRange("CudaFlag>-1");
fCudaFlagCmd->AvailableForStates(G4State_Idle);
@@ -155,64 +141,54 @@ Par04InferenceMessenger::Par04InferenceMessenger(
/// OnnxRuntime Execution Provider Options
/// Cuda
fCudaOptionsDir = new G4UIdirectory("/Par04/inference/cuda/");
fCudaOptionsDir->SetGuidance(
"Commands for setting options for Cuda execution provider");
fCudaOptionsDir->SetGuidance("Commands for setting options for Cuda execution provider");
fCudaDeviceIdCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setDeviceId", this);
fCudaDeviceIdCmd->SetGuidance(
"Device ID of Device on which to run CUDA code");
fCudaDeviceIdCmd = new G4UIcmdWithAString("/Par04/inference/cuda/setDeviceId", this);
fCudaDeviceIdCmd->SetGuidance("Device ID of Device on which to run CUDA code");
fCudaDeviceIdCmd->SetParameterName("CudaDeviceId", false);
fCudaDeviceIdCmd->AvailableForStates(G4State_Idle);
fCudaDeviceIdCmd->SetToBeBroadcasted(true);
fCudaGpuMemLimitCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setGpuMemLimit", this);
fCudaGpuMemLimitCmd = new G4UIcmdWithAString("/Par04/inference/cuda/setGpuMemLimit", this);
fCudaGpuMemLimitCmd->SetGuidance("GPU Memory limit for CUDA");
fCudaGpuMemLimitCmd->SetParameterName("CudaGpuMemLimit", false);
fCudaGpuMemLimitCmd->AvailableForStates(G4State_Idle);
fCudaGpuMemLimitCmd->SetToBeBroadcasted(true);
fCudaArenaExtendedStrategyCmd = new G4UIcmdWithAString(
"/Par04/inference/cuda/setArenaExtendedStrategy", this);
fCudaArenaExtendedStrategyCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setArenaExtendedStrategy", this);
fCudaArenaExtendedStrategyCmd->SetGuidance(
"Strategy for extending the device memory arena for CUDA");
fCudaArenaExtendedStrategyCmd->SetParameterName("CudaArenaExtendedStrategy",
false);
"Strategy for extending the device memory arena for CUDA");
fCudaArenaExtendedStrategyCmd->SetParameterName("CudaArenaExtendedStrategy", false);
fCudaArenaExtendedStrategyCmd->AvailableForStates(G4State_Idle);
fCudaArenaExtendedStrategyCmd->SetToBeBroadcasted(true);
fCudaCudnnConvAlgoSearchCmd = new G4UIcmdWithAString(
"/Par04/inference/cuda/setCudnnConvAlgoSearch", this);
fCudaCudnnConvAlgoSearchCmd->SetGuidance(
"Set which cuDNN Convolution Operation to use");
fCudaCudnnConvAlgoSearchCmd->SetParameterName("CudaCudnnConvAlgoSearch",
false);
fCudaCudnnConvAlgoSearchCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setCudnnConvAlgoSearch", this);
fCudaCudnnConvAlgoSearchCmd->SetGuidance("Set which cuDNN Convolution Operation to use");
fCudaCudnnConvAlgoSearchCmd->SetParameterName("CudaCudnnConvAlgoSearch", false);
fCudaCudnnConvAlgoSearchCmd->AvailableForStates(G4State_Idle);
fCudaCudnnConvAlgoSearchCmd->SetToBeBroadcasted(true);
fCudaDoCopyInDefaultStreamCmd = new G4UIcmdWithAString(
"/Par04/inference/cuda/setDoCopyInDefaultStream", this);
fCudaDoCopyInDefaultStreamCmd->SetGuidance(
"Whether to use same stream for copying");
fCudaDoCopyInDefaultStreamCmd->SetParameterName("CudaDoCopyInDefaultStream",
false);
fCudaDoCopyInDefaultStreamCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setDoCopyInDefaultStream", this);
fCudaDoCopyInDefaultStreamCmd->SetGuidance("Whether to use same stream for copying");
fCudaDoCopyInDefaultStreamCmd->SetParameterName("CudaDoCopyInDefaultStream", false);
fCudaDoCopyInDefaultStreamCmd->AvailableForStates(G4State_Idle);
fCudaDoCopyInDefaultStreamCmd->SetToBeBroadcasted(true);
fCudaCudnnConvUseMaxWorkspaceCmd = new G4UIcmdWithAString(
"/Par04/inference/cuda/setCudnnConvUseMaxWorkspace", this);
fCudaCudnnConvUseMaxWorkspaceCmd->SetGuidance(
"Memory Limit for cuDNN convolution operations");
fCudaCudnnConvUseMaxWorkspaceCmd->SetParameterName(
"CudaCudnnConvUseMaxWorkspace", false);
fCudaCudnnConvUseMaxWorkspaceCmd =
new G4UIcmdWithAString("/Par04/inference/cuda/setCudnnConvUseMaxWorkspace", this);
fCudaCudnnConvUseMaxWorkspaceCmd->SetGuidance("Memory Limit for cuDNN convolution operations");
fCudaCudnnConvUseMaxWorkspaceCmd->SetParameterName("CudaCudnnConvUseMaxWorkspace", false);
fCudaCudnnConvUseMaxWorkspaceCmd->AvailableForStates(G4State_Idle);
fCudaCudnnConvUseMaxWorkspaceCmd->SetToBeBroadcasted(true);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04InferenceMessenger::~Par04InferenceMessenger() {
Par04InferenceMessenger::~Par04InferenceMessenger()
{
delete fInferenceLibraryCmd;
delete fSizeLatentVectorCmd;
delete fSizeConditionVectorCmd;
@@ -228,8 +204,8 @@ Par04InferenceMessenger::~Par04InferenceMessenger() {
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04InferenceMessenger::SetNewValue(G4UIcommand *aCommand,
G4String aNewValue) {
void Par04InferenceMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewValue)
{
if (aCommand == fInferenceLibraryCmd) {
fInference->SetInferenceLibrary(aNewValue);
}
@@ -247,23 +223,23 @@ void Par04InferenceMessenger::SetNewValue(G4UIcommand *aCommand,
}
if (aCommand == fOptimizationFlagCmd) {
fInference->SetOptimizationFlag(std::stoi(aNewValue));
} else if (aCommand == fMeshNbRhoCellsCmd) {
fInference->SetMeshNbOfCells(0,
fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue));
} else if (aCommand == fMeshNbPhiCellsCmd) {
fInference->SetMeshNbOfCells(1,
fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
fInference->SetMeshSizeOfCells(
1, 2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
} else if (aCommand == fMeshNbZCellsCmd) {
fInference->SetMeshNbOfCells(2,
fMeshNbZCellsCmd->GetNewIntValue(aNewValue));
} else if (aCommand == fMeshSizeRhoCellsCmd) {
fInference->SetMeshSizeOfCells(
0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue));
} else if (aCommand == fMeshSizeZCellsCmd) {
fInference->SetMeshSizeOfCells(
2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue));
}
else if (aCommand == fMeshNbRhoCellsCmd) {
fInference->SetMeshNbOfCells(0, fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue));
}
else if (aCommand == fMeshNbPhiCellsCmd) {
fInference->SetMeshNbOfCells(1, fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
fInference->SetMeshSizeOfCells(1,
2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
}
else if (aCommand == fMeshNbZCellsCmd) {
fInference->SetMeshNbOfCells(2, fMeshNbZCellsCmd->GetNewIntValue(aNewValue));
}
else if (aCommand == fMeshSizeRhoCellsCmd) {
fInference->SetMeshSizeOfCells(0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue));
}
else if (aCommand == fMeshSizeZCellsCmd) {
fInference->SetMeshSizeOfCells(2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue));
}
/// Onnx Runtime Execution Provider Flags
/// Cuda
@@ -272,35 +248,38 @@ void Par04InferenceMessenger::SetNewValue(G4UIcommand *aCommand,
}
if (aCommand == fCudaDeviceIdCmd) {
fInference->SetCudaDeviceId(aNewValue);
} else if (aCommand == fCudaGpuMemLimitCmd) {
}
else if (aCommand == fCudaGpuMemLimitCmd) {
fInference->SetCudaGpuMemLimit(aNewValue);
} else if (aCommand == fCudaArenaExtendedStrategyCmd) {
}
else if (aCommand == fCudaArenaExtendedStrategyCmd) {
fInference->SetCudaArenaExtendedStrategy(aNewValue);
} else if (aCommand == fCudaCudnnConvAlgoSearchCmd) {
}
else if (aCommand == fCudaCudnnConvAlgoSearchCmd) {
fInference->SetCudaCudnnConvAlgoSearch(aNewValue);
} else if (aCommand == fCudaDoCopyInDefaultStreamCmd) {
}
else if (aCommand == fCudaDoCopyInDefaultStreamCmd) {
fInference->SetCudaDoCopyInDefaultStream(aNewValue);
} else if (aCommand == fCudaCudnnConvUseMaxWorkspaceCmd) {
}
else if (aCommand == fCudaCudnnConvUseMaxWorkspaceCmd) {
fInference->SetCudaCudnnConvUseMaxWorkspace(aNewValue);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4String Par04InferenceMessenger::GetCurrentValue(G4UIcommand *aCommand) {
G4String Par04InferenceMessenger::GetCurrentValue(G4UIcommand* aCommand)
{
G4String cv;
if (aCommand == fInferenceLibraryCmd) {
cv = fInferenceLibraryCmd->ConvertToString(
fInference->GetInferenceLibrary());
cv = fInferenceLibraryCmd->ConvertToString(fInference->GetInferenceLibrary());
}
if (aCommand == fSizeLatentVectorCmd) {
cv = fSizeLatentVectorCmd->ConvertToString(
fInference->GetSizeLatentVector());
cv = fSizeLatentVectorCmd->ConvertToString(fInference->GetSizeLatentVector());
}
if (aCommand == fSizeConditionVectorCmd) {
cv = fSizeConditionVectorCmd->ConvertToString(
fInference->GetSizeConditionVector());
cv = fSizeConditionVectorCmd->ConvertToString(fInference->GetSizeConditionVector());
}
if (aCommand == fModelPathNameCmd) {
cv = fModelPathNameCmd->ConvertToString(fInference->GetModelPathName());
@@ -309,39 +288,43 @@ G4String Par04InferenceMessenger::GetCurrentValue(G4UIcommand *aCommand) {
cv = fSizeLatentVectorCmd->ConvertToString(fInference->GetProfileFlag());
}
if (aCommand == fOptimizationFlagCmd) {
cv = fSizeLatentVectorCmd->ConvertToString(
fInference->GetOptimizationFlag());
} else if (aCommand == fMeshNbRhoCellsCmd) {
cv = fSizeLatentVectorCmd->ConvertToString(fInference->GetOptimizationFlag());
}
else if (aCommand == fMeshNbRhoCellsCmd) {
cv = fMeshNbRhoCellsCmd->ConvertToString(fInference->GetMeshNbOfCells()[0]);
} else if (aCommand == fMeshNbPhiCellsCmd) {
}
else if (aCommand == fMeshNbPhiCellsCmd) {
cv = fMeshNbPhiCellsCmd->ConvertToString(fInference->GetMeshNbOfCells()[1]);
} else if (aCommand == fMeshNbZCellsCmd) {
}
else if (aCommand == fMeshNbZCellsCmd) {
cv = fMeshNbZCellsCmd->ConvertToString(fInference->GetMeshNbOfCells()[2]);
} else if (aCommand == fMeshSizeRhoCellsCmd) {
cv = fMeshSizeRhoCellsCmd->ConvertToString(
fInference->GetMeshSizeOfCells()[0]);
} else if (aCommand == fMeshSizeZCellsCmd) {
cv = fMeshSizeZCellsCmd->ConvertToString(
fInference->GetMeshSizeOfCells()[2]);
}
else if (aCommand == fMeshSizeRhoCellsCmd) {
cv = fMeshSizeRhoCellsCmd->ConvertToString(fInference->GetMeshSizeOfCells()[0]);
}
else if (aCommand == fMeshSizeZCellsCmd) {
cv = fMeshSizeZCellsCmd->ConvertToString(fInference->GetMeshSizeOfCells()[2]);
}
/// Onnx Runtime Execution Provider Flags
/// Cuda
if (aCommand == fCudaDeviceIdCmd) {
cv = fCudaDeviceIdCmd->ConvertToString(fInference->GetCudaDeviceId());
} else if (aCommand == fCudaGpuMemLimitCmd) {
}
else if (aCommand == fCudaGpuMemLimitCmd) {
cv = fCudaGpuMemLimitCmd->ConvertToString(fInference->GetCudaGpuMemLimit());
} else if (aCommand == fCudaArenaExtendedStrategyCmd) {
cv = fCudaArenaExtendedStrategyCmd->ConvertToString(
fInference->GetCudaArenaExtendedStrategy());
} else if (aCommand == fCudaCudnnConvAlgoSearchCmd) {
cv = fCudaCudnnConvAlgoSearchCmd->ConvertToString(
fInference->GetCudaCudnnConvAlgoSearch());
} else if (aCommand == fCudaDoCopyInDefaultStreamCmd) {
cv = fCudaDoCopyInDefaultStreamCmd->ConvertToString(
fInference->GetCudaDoCopyInDefaultStream());
} else if (aCommand == fCudaCudnnConvUseMaxWorkspaceCmd) {
}
else if (aCommand == fCudaArenaExtendedStrategyCmd) {
cv = fCudaArenaExtendedStrategyCmd->ConvertToString(fInference->GetCudaArenaExtendedStrategy());
}
else if (aCommand == fCudaCudnnConvAlgoSearchCmd) {
cv = fCudaCudnnConvAlgoSearchCmd->ConvertToString(fInference->GetCudaCudnnConvAlgoSearch());
}
else if (aCommand == fCudaDoCopyInDefaultStreamCmd) {
cv = fCudaDoCopyInDefaultStreamCmd->ConvertToString(fInference->GetCudaDoCopyInDefaultStream());
}
else if (aCommand == fCudaCudnnConvUseMaxWorkspaceCmd) {
cv = fCudaCudnnConvUseMaxWorkspaceCmd->ConvertToString(
fInference->GetCudaCudnnConvUseMaxWorkspace());
fInference->GetCudaCudnnConvUseMaxWorkspace());
}
return cv;
@@ -24,35 +24,39 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include "Par04InferenceMessenger.hh" // for Par04InferenceMessenger
#include "Par04InferenceSetup.hh"
#ifdef USE_INFERENCE_ONNX
#include "Par04OnnxInference.hh" // for Par04OnnxInference
#endif
#ifdef USE_INFERENCE_LWTNN
#include "Par04LwtnnInference.hh" // for Par04LwtnnInference
#endif
#ifdef USE_INFERENCE_TORCH
#include "Par04TorchInference.hh" // for Par04TorchInference
#endif
#include "CLHEP/Random/RandGauss.h" // for RandGauss
#include "G4RotationMatrix.hh" // for G4RotationMatrix
#include <CLHEP/Units/SystemOfUnits.h> // for pi, GeV, deg
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <G4Exception.hh> // for G4Exception
#include <G4ExceptionSeverity.hh> // for FatalException
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <algorithm> // for max, copy
#include <cmath> // for cos, sin
#include <ext/alloc_traits.h> // for __alloc_traits<>::value_type
#include <string> // for char_traits, basic_string
# include "Par04InferenceSetup.hh"
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include "Par04InferenceMessenger.hh" // for Par04InferenceMessenger
# ifdef USE_INFERENCE_ONNX
# include "Par04OnnxInference.hh" // for Par04OnnxInference
# endif
# ifdef USE_INFERENCE_LWTNN
# include "Par04LwtnnInference.hh" // for Par04LwtnnInference
# endif
# ifdef USE_INFERENCE_TORCH
# include "Par04TorchInference.hh" // for Par04TorchInference
# endif
# include "CLHEP/Random/RandGauss.h" // for RandGauss
# include "G4RotationMatrix.hh" // for G4RotationMatrix
# include <CLHEP/Units/SystemOfUnits.h> // for pi, GeV, deg
# include <CLHEP/Vector/Rotation.h> // for HepRotation
# include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
# include <G4Exception.hh> // for G4Exception
# include <G4ExceptionSeverity.hh> // for FatalException
# include <G4ThreeVector.hh> // for G4ThreeVector
# include <algorithm> // for max, copy
# include <cmath> // for cos, sin
# include <string> // for char_traits, basic_string
# include <ext/alloc_traits.h> // for __alloc_traits<>::value_type
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04InferenceSetup::Par04InferenceSetup()
: fInferenceMessenger(new Par04InferenceMessenger(this)) {}
Par04InferenceSetup::Par04InferenceSetup() : fInferenceMessenger(new Par04InferenceMessenger(this))
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -63,8 +67,7 @@ Par04InferenceSetup::~Par04InferenceSetup() {}
G4bool Par04InferenceSetup::IfTrigger(G4double aEnergy)
{
/// Energy of electrons used in training dataset
if (aEnergy > 1 * CLHEP::GeV || aEnergy < 1024 * CLHEP::GeV)
return true;
if (aEnergy > 1 * CLHEP::GeV || aEnergy < 1024 * CLHEP::GeV) return true;
return false;
}
@@ -74,24 +77,22 @@ void Par04InferenceSetup::SetInferenceLibrary(G4String aName)
{
fInferenceLibrary = aName;
#ifdef USE_INFERENCE_ONNX
# ifdef USE_INFERENCE_ONNX
if (fInferenceLibrary == "ONNX")
fInferenceInterface =
std::unique_ptr<Par04InferenceInterface>(new Par04OnnxInference(
fModelPathName, fProfileFlag, fOptimizationFlag, fIntraOpNumThreads,
fCudaFlag, cuda_keys, cuda_values, fModelSavePath,
fProfilingOutputSavePath));
#endif
#ifdef USE_INFERENCE_LWTNN
fInferenceInterface = std::unique_ptr<Par04InferenceInterface>(new Par04OnnxInference(
fModelPathName, fProfileFlag, fOptimizationFlag, fIntraOpNumThreads, fCudaFlag, cuda_keys,
cuda_values, fModelSavePath, fProfilingOutputSavePath));
# endif
# ifdef USE_INFERENCE_LWTNN
if (fInferenceLibrary == "LWTNN")
fInferenceInterface = std::unique_ptr<Par04InferenceInterface>(
new Par04LwtnnInference(fModelPathName));
#endif
#ifdef USE_INFERENCE_TORCH
fInferenceInterface =
std::unique_ptr<Par04InferenceInterface>(new Par04LwtnnInference(fModelPathName));
# endif
# ifdef USE_INFERENCE_TORCH
if (fInferenceLibrary == "TORCH")
fInferenceInterface = std::unique_ptr<Par04InferenceInterface>(
new Par04TorchInference(fModelPathName));
#endif
fInferenceInterface =
std::unique_ptr<Par04InferenceInterface>(new Par04TorchInference(fModelPathName));
# endif
CheckInferenceLibrary();
}
@@ -101,25 +102,23 @@ void Par04InferenceSetup::SetInferenceLibrary(G4String aName)
void Par04InferenceSetup::CheckInferenceLibrary()
{
G4String msg = "Please choose inference library from available libraries (";
#ifdef USE_INFERENCE_ONNX
# ifdef USE_INFERENCE_ONNX
msg += "ONNX,";
#endif
#ifdef USE_INFERENCE_LWTNN
# endif
# ifdef USE_INFERENCE_LWTNN
msg += "LWTNN,";
#endif
#ifdef USE_INFERENCE_TORCH
# endif
# ifdef USE_INFERENCE_TORCH
msg += "TORCH";
#endif
# endif
if (fInferenceInterface == nullptr)
G4Exception("Par04InferenceSetup::CheckInferenceLibrary()", "InvalidSetup",
FatalException,
G4Exception("Par04InferenceSetup::CheckInferenceLibrary()", "InvalidSetup", FatalException,
(msg + "). Current name: " + fInferenceLibrary).c_str());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04InferenceSetup::GetEnergies(std::vector<G4double> &aEnergies,
G4double aInitialEnergy,
void Par04InferenceSetup::GetEnergies(std::vector<G4double>& aEnergies, G4double aInitialEnergy,
G4float aInitialAngle)
{
// First check if inference library was set correctly
@@ -129,8 +128,7 @@ void Par04InferenceSetup::GetEnergies(std::vector<G4double> &aEnergies,
// randomly sample from a gaussian distribution in the latent space
std::vector<G4float> genVector(fSizeLatentVector + fSizeConditionVector, 0);
for (int i = 0; i < fSizeLatentVector; ++i)
{
for (int i = 0; i < fSizeLatentVector; ++i) {
genVector[i] = CLHEP::RandGauss::shoot(0., 1.);
}
@@ -156,16 +154,14 @@ void Par04InferenceSetup::GetEnergies(std::vector<G4double> &aEnergies,
// After the inference rescale back to the initial energy (in this example the
// energies of cells were normalized to the energy of the particle)
for (int i = 0; i < size; ++i)
{
for (int i = 0; i < size; ++i) {
aEnergies[i] = aEnergies[i] * aInitialEnergy;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04InferenceSetup::GetPositions(std::vector<G4ThreeVector> &aPositions,
G4ThreeVector pos0,
void Par04InferenceSetup::GetPositions(std::vector<G4ThreeVector>& aPositions, G4ThreeVector pos0,
G4ThreeVector direction)
{
aPositions.resize(fMeshNumber.x() * fMeshNumber.y() * fMeshNumber.z());
@@ -180,24 +176,18 @@ void Par04InferenceSetup::GetPositions(std::vector<G4ThreeVector> &aPositions,
G4RotationMatrix rotMatrixInv = CLHEP::inverseOf(rotMatrix);
int cpt = 0;
for (G4int iCellR = 0; iCellR < fMeshNumber.x(); iCellR++)
{
for (G4int iCellPhi = 0; iCellPhi < fMeshNumber.y(); iCellPhi++)
{
for (G4int iCellZ = 0; iCellZ < fMeshNumber.z(); iCellZ++)
{
for (G4int iCellR = 0; iCellR < fMeshNumber.x(); iCellR++) {
for (G4int iCellPhi = 0; iCellPhi < fMeshNumber.y(); iCellPhi++) {
for (G4int iCellZ = 0; iCellZ < fMeshNumber.z(); iCellZ++) {
aPositions[cpt] =
pos0 +
rotMatrixInv *
G4ThreeVector((iCellR + 0.5) * fMeshSize.x() *
std::cos((iCellPhi + 0.5) * 2 * CLHEP::pi /
fMeshNumber.y() -
CLHEP::pi),
(iCellR + 0.5) * fMeshSize.x() *
std::sin((iCellPhi + 0.5) * 2 * CLHEP::pi /
fMeshNumber.y() -
CLHEP::pi),
(iCellZ + 0.5) * fMeshSize.z());
pos0
+ rotMatrixInv
* G4ThreeVector(
(iCellR + 0.5) * fMeshSize.x()
* std::cos((iCellPhi + 0.5) * 2 * CLHEP::pi / fMeshNumber.y() - CLHEP::pi),
(iCellR + 0.5) * fMeshSize.x()
* std::sin((iCellPhi + 0.5) * 2 * CLHEP::pi / fMeshNumber.y() - CLHEP::pi),
(iCellZ + 0.5) * fMeshSize.z());
cpt++;
}
}
@@ -24,15 +24,17 @@
// ********************************************************************
//
#ifdef USE_INFERENCE_LWTNN
#include "Par04LwtnnInference.hh"
#include <fstream> // for ifstream
#include <lwtnn/parse_json.hh> // for parse_json_graph
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include "Par04LwtnnInference.hh"
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include <fstream> // for ifstream
# include <lwtnn/parse_json.hh> // for parse_json_graph
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04LwtnnInference::Par04LwtnnInference(G4String modelPath)
: Par04InferenceInterface()
Par04LwtnnInference::Par04LwtnnInference(G4String modelPath) : Par04InferenceInterface()
{
// file to read
std::ifstream input(modelPath);
@@ -44,20 +46,18 @@ Par04LwtnnInference::Par04LwtnnInference(G4String modelPath)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04LwtnnInference::RunInference(std::vector<float> aGenVector,
std::vector<G4double>& aEnergies,
int aSize)
std::vector<G4double>& aEnergies, int aSize)
{
// generation vector
fNetworkInputs inputs;
for(std::size_t i = 0; i < aGenVector.size(); ++i)
{
for (std::size_t i = 0; i < aGenVector.size(); ++i) {
inputs["node_0"]["variable_" + std::to_string(i)] = aGenVector[i];
}
// run the inference
fNetworkOutputs outputs = fGraph->compute(inputs);
aEnergies.assign(aSize, 0);
for(int i = 0; i < aSize; i++)
for (int i = 0; i < aSize; i++)
aEnergies[i] = outputs["out_" + std::to_string(i)];
}
@@ -24,38 +24,43 @@
// ********************************************************************
//
#ifdef USE_INFERENCE
#include "Par04MLFastSimModel.hh"
#include <stddef.h> // for size_t
#include <G4FastStep.hh> // for G4FastStep
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4Track.hh> // for G4Track
#include <G4VFastSimulationModel.hh> // for G4VFastSimulationModel
#include "G4Electron.hh" // for G4Electron
#include "G4FastHit.hh" // for G4FastHit
#include "G4FastSimHitMaker.hh" // for G4FastSimHitMaker
#include "G4Gamma.hh" // for G4Gamma
#include "G4Positron.hh" // for G4Positron
#include "Par04InferenceSetup.hh" // for Par04InferenceSetup
# include "Par04MLFastSimModel.hh"
# include "Par04InferenceSetup.hh" // for Par04InferenceSetup
# include "G4Electron.hh" // for G4Electron
# include "G4FastHit.hh" // for G4FastHit
# include "G4FastSimHitMaker.hh" // for G4FastSimHitMaker
# include "G4Gamma.hh" // for G4Gamma
# include "G4Positron.hh" // for G4Positron
# include <G4FastStep.hh> // for G4FastStep
# include <G4FastTrack.hh> // for G4FastTrack
# include <G4Track.hh> // for G4Track
# include <G4VFastSimulationModel.hh> // for G4VFastSimulationModel
# include <stddef.h> // for size_t
class G4ParticleDefinition;
class G4Region;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04MLFastSimModel::Par04MLFastSimModel(G4String aModelName, G4Region* aEnvelope)
: G4VFastSimulationModel(aModelName, aEnvelope)
, fInference(new Par04InferenceSetup)
, fHitMaker(new G4FastSimHitMaker)
, fParallelHitMaker(new G4FastSimHitMaker) {
: G4VFastSimulationModel(aModelName, aEnvelope),
fInference(new Par04InferenceSetup),
fHitMaker(new G4FastSimHitMaker),
fParallelHitMaker(new G4FastSimHitMaker)
{
fParallelHitMaker->SetNameOfWorldWithSD("parallelWorldFastSim");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04MLFastSimModel::Par04MLFastSimModel(G4String aModelName)
: G4VFastSimulationModel(aModelName)
, fInference(new Par04InferenceSetup)
, fHitMaker(new G4FastSimHitMaker)
, fParallelHitMaker(new G4FastSimHitMaker) {
: G4VFastSimulationModel(aModelName),
fInference(new Par04InferenceSetup),
fHitMaker(new G4FastSimHitMaker),
fParallelHitMaker(new G4FastSimHitMaker)
{
fParallelHitMaker->SetNameOfWorldWithSD("parallelWorldFastSim");
}
@@ -67,9 +72,9 @@ Par04MLFastSimModel::~Par04MLFastSimModel() {}
G4bool Par04MLFastSimModel::IsApplicable(const G4ParticleDefinition& aParticleType)
{
return &aParticleType == G4Electron::ElectronDefinition() ||
&aParticleType == G4Positron::PositronDefinition() ||
&aParticleType == G4Gamma::GammaDefinition();
return &aParticleType == G4Electron::ElectronDefinition()
|| &aParticleType == G4Positron::PositronDefinition()
|| &aParticleType == G4Gamma::GammaDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -88,7 +93,7 @@ void Par04MLFastSimModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastS
aFastStep.SetPrimaryTrackPathLength(0.0);
G4double energy = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
aFastStep.SetTotalEnergyDeposited(energy);
G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
G4ThreeVector direction = aFastTrack.GetPrimaryTrack()->GetMomentumDirection();
// calculate the incident angle
@@ -101,8 +106,7 @@ void Par04MLFastSimModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastS
// deposit energy in the detector using calculated values of energy deposits
// and positions
for(size_t iHit = 0; iHit < fPositions.size(); iHit++)
{
for (size_t iHit = 0; iHit < fPositions.size(); iHit++) {
if (fEnergies[iHit] > 0.0005) {
// Place hit in the physical readout of the detector
fParallelHitMaker->make(G4FastHit(fPositions[iHit], fEnergies[iHit]), aFastTrack);
@@ -24,35 +24,37 @@
// ********************************************************************
//
#ifdef USE_INFERENCE_ONNX
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include "Par04OnnxInference.hh"
#include <algorithm> // for copy, max
#include <cassert> // for assert
#include <core/session/onnxruntime_cxx_api.h> // for Value, Session, Env
#include <cstddef> // for size_t
#include <cstdint> // for int64_t
#include <utility> // for move
#ifdef USE_CUDA
#include "cuda_runtime_api.h"
#endif
# include "Par04OnnxInference.hh"
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include <algorithm> // for copy, max
# include <cassert> // for assert
# include <cstddef> // for size_t
# include <cstdint> // for int64_t
# include <utility> // for move
# include <core/session/onnxruntime_cxx_api.h> // for Value, Session, Env
# ifdef USE_CUDA
# include "cuda_runtime_api.h"
# endif
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04OnnxInference::Par04OnnxInference(G4String modelPath, G4int profileFlag,
G4int optimizeFlag,
Par04OnnxInference::Par04OnnxInference(G4String modelPath, G4int profileFlag, G4int optimizeFlag,
G4int intraOpNumThreads, G4int cudaFlag,
std::vector<const char *> &cuda_keys,
std::vector<const char *> &cuda_values,
G4String ModelSavePath,
G4String profilingOutputSavePath)
std::vector<const char*>& cuda_keys,
std::vector<const char*>& cuda_values,
G4String ModelSavePath, G4String profilingOutputSavePath)
: Par04InferenceInterface() {
: Par04InferenceInterface()
{
// initialization of the enviroment and inference session
auto envLocal = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, "ENV");
fEnv = std::move(envLocal);
// Creating a OrtApi Class variable for getting access to C api, necessary for
// CUDA
const auto &ortApi = Ort::GetApi();
const auto& ortApi = Ort::GetApi();
fSessionOptions.SetIntraOpNumThreads(intraOpNumThreads);
// graph optimizations of the model
// if the flag is not set to true none of the optimizations will be applied
@@ -61,104 +63,97 @@ Par04OnnxInference::Par04OnnxInference(G4String modelPath, G4int profileFlag,
fSessionOptions.SetOptimizedModelFilePath("opt-graph");
fSessionOptions.SetGraphOptimizationLevel(ORT_ENABLE_ALL);
// ORT_ENABLE_BASIC #### ORT_ENABLE_EXTENDED
} else
}
else
fSessionOptions.SetGraphOptimizationLevel(ORT_DISABLE_ALL);
#ifdef USE_CUDA
# ifdef USE_CUDA
if (cudaFlag) {
OrtCUDAProviderOptionsV2 *fCudaOptions = nullptr;
OrtCUDAProviderOptionsV2* fCudaOptions = nullptr;
// Initialize the CUDA provider options, fCudaOptions should now point to a
// valid CUDA configuration.
(void)ortApi.CreateCUDAProviderOptions(&fCudaOptions);
// Update the CUDA provider options
(void)ortApi.UpdateCUDAProviderOptions(
fCudaOptions, cuda_keys.data(), cuda_values.data(), cuda_keys.size());
(void)ortApi.UpdateCUDAProviderOptions(fCudaOptions, cuda_keys.data(), cuda_values.data(),
cuda_keys.size());
// Append the CUDA execution provider to the session options, indicating to
// use CUDA for execution
(void)ortApi.SessionOptionsAppendExecutionProvider_CUDA_V2(fSessionOptions,
fCudaOptions);
(void)ortApi.SessionOptionsAppendExecutionProvider_CUDA_V2(fSessionOptions, fCudaOptions);
}
#endif
# endif
// save json file for model execution profiling
if (profileFlag)
fSessionOptions.EnableProfiling("opt.json");
if (profileFlag) fSessionOptions.EnableProfiling("opt.json");
auto sessionLocal =
std::make_unique<Ort::Session>(*fEnv, modelPath, fSessionOptions);
auto sessionLocal = std::make_unique<Ort::Session>(*fEnv, modelPath, fSessionOptions);
fSession = std::move(sessionLocal);
fInfo = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator,
OrtMemTypeDefault);
fInfo = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemTypeDefault);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04OnnxInference::RunInference(std::vector<float> aGenVector,
std::vector<G4double> &aEnergies,
int aSize) {
std::vector<G4double>& aEnergies, int aSize)
{
// input nodes
Ort::AllocatorWithDefaultOptions allocator;
#if ORT_API_VERSION < 13
# if ORT_API_VERSION < 13
// Before 1.13 we have to roll our own unique_ptr wrapper here
auto allocDeleter = [&allocator](char *p) { allocator.Free(p); };
auto allocDeleter = [&allocator](char* p) {
allocator.Free(p);
};
using AllocatedStringPtr = std::unique_ptr<char, decltype(allocDeleter)>;
#endif
# endif
std::vector<int64_t> input_node_dims;
size_t num_input_nodes = fSession->GetInputCount();
std::vector<const char *> input_node_names(num_input_nodes);
std::vector<const char*> input_node_names(num_input_nodes);
for (std::size_t i = 0; i < num_input_nodes; i++) {
#if ORT_API_VERSION < 13
# if ORT_API_VERSION < 13
const auto input_name =
AllocatedStringPtr(fSession->GetInputName(i, allocator), allocDeleter)
.release();
#else
const auto input_name =
fSession->GetInputNameAllocated(i, allocator).release();
#endif
AllocatedStringPtr(fSession->GetInputName(i, allocator), allocDeleter).release();
# else
const auto input_name = fSession->GetInputNameAllocated(i, allocator).release();
# endif
fInames = {input_name};
input_node_names[i] = input_name;
Ort::TypeInfo type_info = fSession->GetInputTypeInfo(i);
auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
input_node_dims = tensor_info.GetShape();
for (std::size_t j = 0; j < input_node_dims.size(); j++) {
if (input_node_dims[j] < 0)
input_node_dims[j] = 1;
if (input_node_dims[j] < 0) input_node_dims[j] = 1;
}
}
// output nodes
std::vector<int64_t> output_node_dims;
size_t num_output_nodes = fSession->GetOutputCount();
std::vector<const char *> output_node_names(num_output_nodes);
std::vector<const char*> output_node_names(num_output_nodes);
for (std::size_t i = 0; i < num_output_nodes; i++) {
#if ORT_API_VERSION < 13
# if ORT_API_VERSION < 13
const auto output_name =
AllocatedStringPtr(fSession->GetOutputName(i, allocator), allocDeleter)
.release();
#else
const auto output_name =
fSession->GetOutputNameAllocated(i, allocator).release();
#endif
AllocatedStringPtr(fSession->GetOutputName(i, allocator), allocDeleter).release();
# else
const auto output_name = fSession->GetOutputNameAllocated(i, allocator).release();
# endif
output_node_names[i] = output_name;
Ort::TypeInfo type_info = fSession->GetOutputTypeInfo(i);
auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
output_node_dims = tensor_info.GetShape();
for (std::size_t j = 0; j < output_node_dims.size(); j++) {
if (output_node_dims[j] < 0)
output_node_dims[j] = 1;
if (output_node_dims[j] < 0) output_node_dims[j] = 1;
}
}
// create input tensor object from data values
std::vector<int64_t> dims = {1, (unsigned)(aGenVector.size())};
Ort::Value Input_noise_tensor = Ort::Value::CreateTensor<float>(
fInfo, aGenVector.data(), aGenVector.size(), dims.data(), dims.size());
fInfo, aGenVector.data(), aGenVector.size(), dims.data(), dims.size());
assert(Input_noise_tensor.IsTensor());
std::vector<Ort::Value> ort_inputs;
ort_inputs.push_back(std::move(Input_noise_tensor));
// run the inference session
std::vector<Ort::Value> ort_outputs = fSession->Run(
Ort::RunOptions{nullptr}, fInames.data(), ort_inputs.data(),
ort_inputs.size(), output_node_names.data(), output_node_names.size());
std::vector<Ort::Value> ort_outputs =
fSession->Run(Ort::RunOptions{nullptr}, fInames.data(), ort_inputs.data(), ort_inputs.size(),
output_node_names.data(), output_node_names.size());
// get pointer to output tensor float values
float *floatarr = ort_outputs.front().GetTensorMutableData<float>();
float* floatarr = ort_outputs.front().GetTensorMutableData<float>();
aEnergies.assign(aSize, 0);
for (int i = 0; i < aSize; ++i)
aEnergies[i] = floatarr[i];
@@ -24,33 +24,36 @@
// ********************************************************************
//
#include "Par04ParallelFastSensitiveDetector.hh"
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <cmath> // for floor
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
#include <cstddef> // for size_t
#include <vector> // for vector
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include <cmath> // for floor
#include <cstddef> // for size_t
#include <vector> // for vector
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04ParallelFastSensitiveDetector::Par04ParallelFastSensitiveDetector(G4String aName)
: G4VSensitiveDetector(aName)
: G4VSensitiveDetector(aName)
{
collectionName.insert("physicalCellsFastSim");
}
@@ -59,9 +62,7 @@ Par04ParallelFastSensitiveDetector::Par04ParallelFastSensitiveDetector(G4String
Par04ParallelFastSensitiveDetector::Par04ParallelFastSensitiveDetector(G4String aName,
G4int aNbOfLayers,
G4int aNbOfSlices)
: G4VSensitiveDetector(aName)
, fNbOfLayers(aNbOfLayers)
, fNbOfSlices(aNbOfSlices)
: G4VSensitiveDetector(aName), fNbOfLayers(aNbOfLayers), fNbOfSlices(aNbOfSlices)
{
collectionName.insert("physicalCellsFastSim");
}
@@ -75,35 +76,32 @@ Par04ParallelFastSensitiveDetector::~Par04ParallelFastSensitiveDetector() = defa
void Par04ParallelFastSensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
{
fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
if(fHitCollectionID < 0)
{
if (fHitCollectionID < 0) {
fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
}
aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool Par04ParallelFastSensitiveDetector::ProcessHits(G4Step*, G4TouchableHistory* )
G4bool Par04ParallelFastSensitiveDetector::ProcessHits(G4Step*, G4TouchableHistory*)
{
return true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool Par04ParallelFastSensitiveDetector::ProcessHits(const G4FastHit* aHit,
const G4FastTrack*,
G4bool Par04ParallelFastSensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTrack*,
G4TouchableHistory* aTouchable)
{
G4double edep = aHit->GetEnergy();
if(edep == 0.)
return true;
if (edep == 0.) return true;
G4int layerNo = aTouchable->GetCopyNumber(0);
G4int sliceNo = aTouchable->GetCopyNumber(1);
G4int rowNo = aTouchable->GetCopyNumber(2);
G4int hitID = fNbOfLayers*fNbOfSlices*rowNo+fNbOfLayers*sliceNo+layerNo;
G4int hitID = fNbOfLayers * fNbOfSlices * rowNo + fNbOfLayers * sliceNo + layerNo;
auto hit = fHitsMap[hitID].get();
if (hit==nullptr) {
if (hit == nullptr) {
fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
hit = fHitsMap[hitID].get();
hit->SetPhiId(sliceNo);
@@ -137,7 +135,7 @@ G4bool Par04ParallelFastSensitiveDetector::ProcessHits(const G4FastHit* aHit,
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04ParallelFastSensitiveDetector::EndOfEvent(G4HCofThisEvent*)
{
for(const auto& hits: fHitsMap){
for (const auto& hits : fHitsMap) {
fHitsCollection->insert(new Par04Hit(*hits.second.get()));
}
fHitsMap.clear();
@@ -26,33 +26,34 @@
// User Classes
#include "Par04ParallelFastWorld.hh"
#include "Par04ParallelFullWorld.hh"
#include "Par04ParallelFastSensitiveDetector.hh"
#include "Par04ParallelFullWorld.hh"
// G4 Classes
#include "G4NistManager.hh"
#include "G4AutoDelete.hh"
#include "G4Colour.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4ThreeVector.hh"
#include "G4NistManager.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Tubs.hh"
#include "G4SDManager.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4SystemOfUnits.hh"
#include "G4AutoDelete.hh"
#include "globals.hh"
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4UnitsTable.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VisAttributes.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04ParallelFastWorld::Par04ParallelFastWorld(G4String aWorldName,
const Par04DetectorConstruction* aMassDetector,
const Par04ParallelFullWorld* aParallelFull)
:G4VUserParallelWorld(aWorldName), fMassDetector(aMassDetector), fParallelFull(aParallelFull) {
: G4VUserParallelWorld(aWorldName), fMassDetector(aMassDetector), fParallelFull(aParallelFull)
{
fNbOfLayers = fMassDetector->GetNbOfLayers();
}
@@ -65,15 +66,15 @@ Par04ParallelFastWorld::~Par04ParallelFastWorld() = default;
void Par04ParallelFastWorld::Construct()
{
// In parallel world material does not matter
G4Material* dummy = nullptr;
G4Material* dummy = nullptr;
// Build parallel geometry:
auto parallelLogicalVolume = GetWorld()->GetLogicalVolume();
G4double detectorInnerRadius = fMassDetector->GetInnerRadius();
G4double detectorLength = fMassDetector->GetLength();
G4double fullLayerThickness = fMassDetector->GetAbsorberThickness(0)
+ fMassDetector->GetAbsorberThickness(1);
G4double fullLayerThickness =
fMassDetector->GetAbsorberThickness(0) + fMassDetector->GetAbsorberThickness(1);
fLayerThickness = fullLayerThickness;
// Get an updated value
fNbOfLayers = fMassDetector->GetNbOfLayers();
@@ -82,105 +83,68 @@ void Par04ParallelFastWorld::Construct()
G4double detectorRadius = fNbOfLayers * fullLayerThickness;
G4double detectorOuterRadius = detectorInnerRadius + detectorRadius;
G4double rowThickness = detectorLength / fNbOfRows;
G4double full2Pi = 2.* CLHEP::pi * rad;
G4double full2Pi = 2. * CLHEP::pi * rad;
Print();
// Insert cells to create a readout structure that contains both passive and active materials
// Mostly a copy from the detector construction
auto solidDetector = new G4Tubs("Detector", // name
detectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
detectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto logicDetector = new G4LogicalVolume(solidDetector, // solid
dummy, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
logicDetector, // logical volume
"Detector", // name
parallelLogicalVolume, // mother volume
false, // not used
9999, // copy number
true); // check overlaps
auto solidDetector = new G4Tubs("Detector", // name
detectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
detectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto logicDetector = new G4LogicalVolume(solidDetector, // solid
dummy, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
logicDetector, // logical volume
"Detector", // name
parallelLogicalVolume, // mother volume
false, // not used
9999, // copy number
true); // check overlaps
//--------- Detector cylinder (division along z axis) ---------
auto solidRow = new G4Tubs("Row", detectorInnerRadius, detectorOuterRadius, rowThickness / 2.,
0, full2Pi);
auto solidRow =
new G4Tubs("Row", detectorInnerRadius, detectorOuterRadius, rowThickness / 2., 0, full2Pi);
auto logicRow = new G4LogicalVolume(solidRow, dummy, "Row");
if (fNbOfRows > 1)
new G4PVReplica("Row",
logicRow,
logicDetector,
kZAxis,
fNbOfRows,
rowThickness);
new G4PVReplica("Row", logicRow, logicDetector, kZAxis, fNbOfRows, rowThickness);
else
new G4PVPlacement(0,
G4ThreeVector(),
logicRow,
"Row",
logicDetector,
false,
0);
new G4PVPlacement(0, G4ThreeVector(), logicRow, "Row", logicDetector, false, 0);
//--------- Detector slices (division in azimuthal angle) ---------
G4double cellPhi = full2Pi / fNbOfSlices;
auto solidSlice = new G4Tubs("Slice", detectorInnerRadius, detectorOuterRadius, rowThickness/2,
0, cellPhi);
auto logicSlice = new G4LogicalVolume(solidSlice,
dummy,
"Slice");
if(fNbOfSlices>1) {
new G4PVReplica("Slice",
logicSlice,
logicRow,
kPhi,
fNbOfSlices,
cellPhi,
-cellPhi);
} else {
new G4PVPlacement(0,
G4ThreeVector(),
logicSlice,
"Slice",
logicRow,
false,
0);
auto solidSlice =
new G4Tubs("Slice", detectorInnerRadius, detectorOuterRadius, rowThickness / 2, 0, cellPhi);
auto logicSlice = new G4LogicalVolume(solidSlice, dummy, "Slice");
if (fNbOfSlices > 1) {
new G4PVReplica("Slice", logicSlice, logicRow, kPhi, fNbOfSlices, cellPhi, -cellPhi);
}
else {
new G4PVPlacement(0, G4ThreeVector(), logicSlice, "Slice", logicRow, false, 0);
}
//--------- Detector cells (division along radial axis) ---------
G4VisAttributes attribs;
attribs.SetColour(G4Colour(0, 1, 0, 0.1));
attribs.SetForceSolid(true);
if(fNbOfLayers>1) {
auto solidCell = new G4Tubs("Cell", detectorInnerRadius,
detectorInnerRadius + fLayerThickness,
rowThickness/2, 0, cellPhi);
if (fNbOfLayers > 1) {
auto solidCell = new G4Tubs("Cell", detectorInnerRadius, detectorInnerRadius + fLayerThickness,
rowThickness / 2, 0, cellPhi);
fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell_0"));
new G4PVReplica("Cell",
fLogicalCell.back(),
logicSlice,
kRho,
fNbOfLayers,
fLayerThickness,
new G4PVReplica("Cell", fLogicalCell.back(), logicSlice, kRho, fNbOfLayers, fLayerThickness,
detectorInnerRadius);
} else {
auto solidCell = new G4Tubs("Cell", detectorInnerRadius,
detectorInnerRadius + fLayerThickness,
rowThickness/2, 0, cellPhi);
fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell"));
fLogicalCell.back()->SetVisAttributes(attribs);
new G4PVPlacement(0,
G4ThreeVector(),
fLogicalCell.back(),
"Cell",
logicSlice,
false,
0);
}
else {
auto solidCell = new G4Tubs("Cell", detectorInnerRadius, detectorInnerRadius + fLayerThickness,
rowThickness / 2, 0, cellPhi);
fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell"));
fLogicalCell.back()->SetVisAttributes(attribs);
new G4PVPlacement(0, G4ThreeVector(), fLogicalCell.back(), "Cell", logicSlice, false, 0);
}
Print();
}
@@ -194,13 +158,14 @@ void Par04ParallelFastWorld::ConstructSD()
Par04ParallelFastSensitiveDetector* caloSD =
new Par04ParallelFastSensitiveDetector("parallelFastSD", fNbOfLayers, fNbOfSlices);
SDman->AddNewDetector(caloSD);
for(const auto& logicalCell: fLogicalCell)
logicalCell->SetSensitiveDetector(caloSD);
for (const auto& logicalCell : fLogicalCell)
logicalCell->SetSensitiveDetector(caloSD);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04ParallelFastWorld::Print() {
void Par04ParallelFastWorld::Print()
{
G4cout << "\n------------------------------------------------------"
<< "\n Readout geometry with physics layout is set in parallel geometry:\t"
<< "\n Cylindrical detector is divided along radius (layers), phi (slices), and z (rows)."
@@ -208,6 +173,7 @@ void Par04ParallelFastWorld::Print() {
<< "\n- Number of layers: " << fNbOfLayers << "\n------- Number of slices: " << fNbOfSlices
<< "\n- Number of rows: " << fNbOfRows;
G4cout << "\n Readout will collect energy from fast simulation.\n------- Thickness is "
<< "a sum of all absorbers" << " = " << G4BestUnit(fLayerThickness, "Length")
<< "a sum of all absorbers"
<< " = " << G4BestUnit(fLayerThickness, "Length")
<< "\n-----------------------------------------------------" << G4endl;
}
@@ -24,28 +24,31 @@
// ********************************************************************
//
#include "Par04ParallelFullSensitiveDetector.hh"
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <cmath> // for floor
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
#include <cstddef> // for size_t
#include <vector> // for vector
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include <cmath> // for floor
#include <cstddef> // for size_t
#include <vector> // for vector
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -60,10 +63,10 @@ Par04ParallelFullSensitiveDetector::Par04ParallelFullSensitiveDetector(G4String
G4int aNbOfLayers,
G4int aNbOfSlices,
G4int aNbOfRows)
: G4VSensitiveDetector(aName)
, fNbOfLayers(aNbOfLayers)
, fNbOfSlices(aNbOfSlices)
, fNbOfRows(aNbOfRows)
: G4VSensitiveDetector(aName),
fNbOfLayers(aNbOfLayers),
fNbOfSlices(aNbOfSlices),
fNbOfRows(aNbOfRows)
{
collectionName.insert("physicalCellsFullSim");
}
@@ -77,8 +80,7 @@ Par04ParallelFullSensitiveDetector::~Par04ParallelFullSensitiveDetector() = defa
void Par04ParallelFullSensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
{
fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
if(fHitCollectionID < 0)
{
if (fHitCollectionID < 0) {
fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
}
aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
@@ -89,16 +91,15 @@ void Par04ParallelFullSensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
G4bool Par04ParallelFullSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
{
G4double edep = aStep->GetTotalEnergyDeposit();
if(edep == 0.)
return true;
if (edep == 0.) return true;
auto touchable = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
auto touchable = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
G4int layerNo = touchable->GetCopyNumber(0);
G4int sliceNo = touchable->GetCopyNumber(1);
G4int rowNo = touchable->GetCopyNumber(2);
G4int hitID = fNbOfLayers*fNbOfSlices*rowNo+fNbOfLayers*sliceNo+layerNo;
G4int hitID = fNbOfLayers * fNbOfSlices * rowNo + fNbOfLayers * sliceNo + layerNo;
if (layerNo >= fNbOfLayers) {
G4cout << "ERROR, problem with Layer IDs: " << layerNo << " > " << fNbOfLayers << G4endl;
return false;
@@ -112,7 +113,7 @@ G4bool Par04ParallelFullSensitiveDetector::ProcessHits(G4Step* aStep, G4Touchabl
return false;
}
auto hit = fHitsMap[hitID].get();
if (hit==nullptr) {
if (hit == nullptr) {
fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
hit = fHitsMap[hitID].get();
hit->SetPhiId(sliceNo);
@@ -127,7 +128,7 @@ G4bool Par04ParallelFullSensitiveDetector::ProcessHits(G4Step* aStep, G4Touchabl
// Fill time information from G4Step
// If it's already filled, choose hit with earliest global time
if(hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
hit->SetTime(aStep->GetTrack()->GetGlobalTime());
// Set type to parallel world full hit
@@ -136,11 +137,10 @@ G4bool Par04ParallelFullSensitiveDetector::ProcessHits(G4Step* aStep, G4Touchabl
return true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04ParallelFullSensitiveDetector::EndOfEvent(G4HCofThisEvent*)
{
for(const auto& hits: fHitsMap){
for (const auto& hits : fHitsMap) {
fHitsCollection->insert(new Par04Hit(*hits.second.get()));
}
fHitsMap.clear();
@@ -26,33 +26,34 @@
// User Classes
#include "Par04ParallelFullWorld.hh"
#include "Par04ParallelMessenger.hh"
#include "Par04ParallelFullSensitiveDetector.hh"
#include "Par04ParallelMessenger.hh"
// G4 Classes
#include "G4NistManager.hh"
#include "G4AutoDelete.hh"
#include "G4Colour.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4ThreeVector.hh"
#include "G4NistManager.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Tubs.hh"
#include "G4SDManager.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4SystemOfUnits.hh"
#include "G4AutoDelete.hh"
#include "globals.hh"
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4UnitsTable.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VisAttributes.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04ParallelFullWorld::Par04ParallelFullWorld(G4String aWorldName,
const Par04DetectorConstruction* aMassDetector)
:G4VUserParallelWorld(aWorldName), fMassDetector(aMassDetector) {
fParallelMessenger = new Par04ParallelMessenger(this);
: G4VUserParallelWorld(aWorldName), fMassDetector(aMassDetector)
{
fParallelMessenger = new Par04ParallelMessenger(this);
fNbOfLayers = fMassDetector->GetNbOfLayers();
}
@@ -65,99 +66,75 @@ Par04ParallelFullWorld::~Par04ParallelFullWorld() = default;
void Par04ParallelFullWorld::Construct()
{
// In parallel world material does not matter
G4Material* dummy = nullptr;
G4Material* dummy = nullptr;
// Build parallel geometry:
auto parallelLogicalVolume = GetWorld()->GetLogicalVolume();
G4double detectorInnerRadius = fMassDetector->GetInnerRadius();
G4double detectorLength = fMassDetector->GetLength();
G4double fullLayerThickness = fMassDetector->GetAbsorberThickness(0)
+ fMassDetector->GetAbsorberThickness(1);
G4double fullLayerThickness =
fMassDetector->GetAbsorberThickness(0) + fMassDetector->GetAbsorberThickness(1);
G4double sensitiveLayerOffset = 0;
if(fMassDetector->GetAbsorberSensitivity(0))
if (fMassDetector->GetAbsorberSensitivity(0))
fLayerThickness = fMassDetector->GetAbsorberThickness(0);
else
sensitiveLayerOffset = fMassDetector->GetAbsorberThickness(0);
if(fMassDetector->GetAbsorberSensitivity(1))
if (fMassDetector->GetAbsorberSensitivity(1))
fLayerThickness += fMassDetector->GetAbsorberThickness(1);
fNbOfLayers = fMassDetector->GetNbOfLayers(); // Get an updated value
fNbOfLayers = fMassDetector->GetNbOfLayers(); // Get an updated value
G4double detectorRadius = fNbOfLayers * fullLayerThickness;
G4double detectorOuterRadius = detectorInnerRadius + detectorRadius;
G4double rowThickness = detectorLength / fNbOfRows;
G4double full2Pi = 2.* CLHEP::pi * rad;
G4double full2Pi = 2. * CLHEP::pi * rad;
Print();
// Insert cells to create a readout structure that contains both passive and active materials
// Mostly a copy from the detector construction
auto solidDetector = new G4Tubs("Detector", // name
detectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
detectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto logicDetector = new G4LogicalVolume(solidDetector, // solid
dummy, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
logicDetector, // logical volume
"Detector", // name
parallelLogicalVolume, // mother volume
false, // not used
9999, // copy number
true); // check overlaps
auto solidDetector = new G4Tubs("Detector", // name
detectorInnerRadius, // inner radius
detectorOuterRadius, // outer radius
detectorLength / 2., // half-width in Z
0, // start angle
full2Pi); // delta angle
auto logicDetector = new G4LogicalVolume(solidDetector, // solid
dummy, // material
"Detector"); // name
new G4PVPlacement(0, // no rotation
G4ThreeVector(0, 0, 0), // detector centre at (0,0,0)
logicDetector, // logical volume
"Detector", // name
parallelLogicalVolume, // mother volume
false, // not used
9999, // copy number
true); // check overlaps
//--------- Detector cylinder (division along z axis) ---------
auto solidRow = new G4Tubs("Row", detectorInnerRadius, detectorOuterRadius, rowThickness / 2.,
0, full2Pi);
auto solidRow =
new G4Tubs("Row", detectorInnerRadius, detectorOuterRadius, rowThickness / 2., 0, full2Pi);
auto logicRow = new G4LogicalVolume(solidRow, dummy, "Row");
if (fNbOfRows > 1)
new G4PVReplica("Row",
logicRow,
logicDetector,
kZAxis,
fNbOfRows,
rowThickness);
new G4PVReplica("Row", logicRow, logicDetector, kZAxis, fNbOfRows, rowThickness);
else
new G4PVPlacement(0,
G4ThreeVector(),
logicRow,
"Row",
logicDetector,
false,
0);
new G4PVPlacement(0, G4ThreeVector(), logicRow, "Row", logicDetector, false, 0);
//--------- Detector slices (division in azimuthal angle) ---------
G4double cellPhi = full2Pi / fNbOfSlices;
auto solidSlice = new G4Tubs("Slice", detectorInnerRadius, detectorOuterRadius, rowThickness/2,
0, cellPhi);
auto logicSlice = new G4LogicalVolume(solidSlice,
dummy,
"Slice");
if(fNbOfLayers>1 && fullLayerThickness == fLayerThickness) {
new G4PVReplica("Slice",
logicSlice,
logicRow,
kPhi,
fNbOfSlices,
cellPhi,
-cellPhi);
} else {
auto solidSlice =
new G4Tubs("Slice", detectorInnerRadius, detectorOuterRadius, rowThickness / 2, 0, cellPhi);
auto logicSlice = new G4LogicalVolume(solidSlice, dummy, "Slice");
if (fNbOfLayers > 1 && fullLayerThickness == fLayerThickness) {
new G4PVReplica("Slice", logicSlice, logicRow, kPhi, fNbOfSlices, cellPhi, -cellPhi);
}
else {
// full simulation readout, cannot use replica because of gaps between absorbers
for (int iSlice = 0; iSlice<fNbOfSlices; iSlice++) {
auto rotation = new G4RotationMatrix();
rotation->setPhi((iSlice+0.5)*cellPhi);
new G4PVPlacement(rotation,
G4ThreeVector(),
logicSlice,
"Slice_"+std::to_string(iSlice),
logicRow,
false,
iSlice);
for (int iSlice = 0; iSlice < fNbOfSlices; iSlice++) {
auto rotation = new G4RotationMatrix();
rotation->setPhi((iSlice + 0.5) * cellPhi);
new G4PVPlacement(rotation, G4ThreeVector(), logicSlice, "Slice_" + std::to_string(iSlice),
logicRow, false, iSlice);
}
}
@@ -165,36 +142,27 @@ void Par04ParallelFullWorld::Construct()
G4VisAttributes attribs;
attribs.SetColour(G4Colour(0, 1, 0, 0.1));
attribs.SetForceSolid(true);
if(fNbOfLayers>1 && fullLayerThickness == fLayerThickness) {
if (fNbOfLayers > 1 && fullLayerThickness == fLayerThickness) {
auto solidCell = new G4Tubs("Cell", detectorInnerRadius + sensitiveLayerOffset,
detectorInnerRadius + sensitiveLayerOffset + fLayerThickness,
rowThickness/2, 0, cellPhi);
rowThickness / 2, 0, cellPhi);
fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell_0"));
new G4PVReplica("Cell",
fLogicalCell.back(),
logicSlice,
kRho,
fNbOfLayers,
fLayerThickness,
new G4PVReplica("Cell", fLogicalCell.back(), logicSlice, kRho, fNbOfLayers, fLayerThickness,
detectorInnerRadius);
} else {
}
else {
// full simulation readout, cannot use replica because of gaps between absorbers
for (int iLayer = 0; iLayer<fNbOfLayers; iLayer++) {
auto solidCell = new G4Tubs("Cell_"+std::to_string(iLayer),
detectorInnerRadius + iLayer * fullLayerThickness
+ sensitiveLayerOffset,
detectorInnerRadius + iLayer * fullLayerThickness
+ sensitiveLayerOffset + fLayerThickness,
rowThickness/2, 0, cellPhi);
fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell_"+std::to_string(iLayer)));
for (int iLayer = 0; iLayer < fNbOfLayers; iLayer++) {
auto solidCell = new G4Tubs(
"Cell_" + std::to_string(iLayer),
detectorInnerRadius + iLayer * fullLayerThickness + sensitiveLayerOffset,
detectorInnerRadius + iLayer * fullLayerThickness + sensitiveLayerOffset + fLayerThickness,
rowThickness / 2, 0, cellPhi);
fLogicalCell.push_back(
new G4LogicalVolume(solidCell, dummy, "Cell_" + std::to_string(iLayer)));
fLogicalCell.back()->SetVisAttributes(attribs);
new G4PVPlacement(0,
G4ThreeVector(),
fLogicalCell.back(),
"Cell_"+std::to_string(iLayer),
logicSlice,
false,
iLayer);
new G4PVPlacement(0, G4ThreeVector(), fLogicalCell.back(), "Cell_" + std::to_string(iLayer),
logicSlice, false, iLayer);
}
}
Print();
@@ -209,13 +177,14 @@ void Par04ParallelFullWorld::ConstructSD()
Par04ParallelFullSensitiveDetector* caloSD =
new Par04ParallelFullSensitiveDetector("parallelFullSD", fNbOfLayers, fNbOfSlices, fNbOfRows);
SDman->AddNewDetector(caloSD);
for(const auto& logicalCell: fLogicalCell)
for (const auto& logicalCell : fLogicalCell)
logicalCell->SetSensitiveDetector(caloSD);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04ParallelFullWorld::Print() {
void Par04ParallelFullWorld::Print()
{
G4cout << "\n------------------------------------------------------"
<< "\n Readout geometry with physics layout is set in parallel geometry:\t"
<< "\n Cylindrical detector is divided along radius (layers), phi (slices), and z (rows)."
@@ -24,26 +24,28 @@
// ********************************************************************
//
#include "Par04ParallelMessenger.hh"
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4bool, G4double, G4int
#include <G4UIcommand.hh> // for G4UIcommand
#include <G4UImessenger.hh> // for G4UImessenger
#include <G4UIparameter.hh> // for G4UIparameter
#include <istream> // for basic_istream, basic_istream...
#include <string> // for operator>>
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
#include "G4UIcmdWithABool.hh" // for G4UIcmdWithABool
#include "G4UIdirectory.hh" // for G4UIdirectory
#include "Par04ParallelFullWorld.hh" // for Par04ParallelFullWorld
#include "Par04ParallelFullWorld.hh" // for Par04ParallelFullWorld
#include "G4UIcmdWithABool.hh" // for G4UIcmdWithABool
#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
#include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
#include "G4UIdirectory.hh" // for G4UIdirectory
#include <CLHEP/Units/SystemOfUnits.h> // for pi
#include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4bool, G4double, G4int
#include <G4UIcommand.hh> // for G4UIcommand
#include <G4UImessenger.hh> // for G4UImessenger
#include <G4UIparameter.hh> // for G4UIparameter
#include <istream> // for basic_istream, basic_istream...
#include <string> // for operator>>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04ParallelMessenger::Par04ParallelMessenger(Par04ParallelFullWorld* aParallel)
: G4UImessenger()
, fParallel(aParallel)
: G4UImessenger(), fParallel(aParallel)
{
fExampleDir = new G4UIdirectory("/Par04/");
fExampleDir->SetGuidance("UI commands specific to this example");
@@ -84,16 +86,13 @@ Par04ParallelMessenger::~Par04ParallelMessenger()
void Par04ParallelMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewValue)
{
if(aCommand == fPrintCmd)
{
if (aCommand == fPrintCmd) {
fParallel->Print();
}
else if(aCommand == fNbSlicesCmd)
{
else if (aCommand == fNbSlicesCmd) {
fParallel->SetNbOfSlices(fNbSlicesCmd->GetNewIntValue(aNewValue));
}
else if(aCommand == fNbRowsCmd)
{
else if (aCommand == fNbRowsCmd) {
fParallel->SetNbOfRows(fNbRowsCmd->GetNewIntValue(aNewValue));
}
}
@@ -104,12 +103,10 @@ G4String Par04ParallelMessenger::GetCurrentValue(G4UIcommand* aCommand)
{
G4String cv;
if(aCommand == fNbSlicesCmd)
{
if (aCommand == fNbSlicesCmd) {
cv = fNbSlicesCmd->ConvertToString(fParallel->GetNbOfSlices());
}
else if(aCommand == fNbRowsCmd)
{
else if (aCommand == fNbRowsCmd) {
cv = fNbRowsCmd->ConvertToString(fParallel->GetNbOfRows());
}
return cv;
@@ -24,26 +24,28 @@
// ********************************************************************
//
#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 "Par04EventInformation.hh" // for Par04EventInformation
#include "G4Event.hh" // for G4Event
#include "G4ParticleGun.hh" // for G4ParticleGun
#include "G4ParticleTable.hh" // for G4ParticleTable
#include "G4SystemOfUnits.hh" // for GeV
#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;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04PrimaryGeneratorAction::Par04PrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction()
Par04PrimaryGeneratorAction::Par04PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction()
{
G4int n_particle = 1;
fParticleGun = new G4ParticleGun(n_particle);
fParticleGun = new G4ParticleGun(n_particle);
// Default particle properties
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
@@ -56,7 +58,10 @@ Par04PrimaryGeneratorAction::Par04PrimaryGeneratorAction()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04PrimaryGeneratorAction::~Par04PrimaryGeneratorAction() { delete fParticleGun; }
Par04PrimaryGeneratorAction::~Par04PrimaryGeneratorAction()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -24,20 +24,21 @@
// ********************************************************************
//
#include "Par04RunAction.hh"
#include <G4GenericAnalysisManager.hh> // for G4GenericAnalysisManager
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4int, G4double
#include <G4UserRunAction.hh> // for G4UserRunAction
#include "G4AnalysisManager.hh" // for G4AnalysisManager
#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
#include "Par04EventAction.hh" // for Par04EventAction
#include "Par04EventAction.hh" // for Par04EventAction
#include "G4AnalysisManager.hh" // for G4AnalysisManager
#include <G4GenericAnalysisManager.hh> // for G4GenericAnalysisManager
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4Types.hh> // for G4int, G4double
#include <G4UserRunAction.hh> // for G4UserRunAction
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04RunAction::Par04RunAction(Par04DetectorConstruction* aDetector, Par04EventAction* aEventAction)
: G4UserRunAction()
, fDetector(aDetector)
, fEventAction(aEventAction)
: G4UserRunAction(), fDetector(aDetector), fEventAction(aEventAction)
{
// Create analysis manager
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
@@ -63,10 +64,10 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
analysisManager->SetVerboseLevel(0);
// Get detector dimensions
G4int cellNumZ = fDetector->GetMeshNbOfCells().z();
G4int cellNumRho = fDetector->GetMeshNbOfCells().x();
G4int cellNumPhi = fDetector->GetMeshNbOfCells().y();
G4double cellSizeZ = fDetector->GetMeshSizeOfCells().z();
G4int cellNumZ = fDetector->GetMeshNbOfCells().z();
G4int cellNumRho = fDetector->GetMeshNbOfCells().x();
G4int cellNumPhi = fDetector->GetMeshNbOfCells().y();
G4double cellSizeZ = fDetector->GetMeshSizeOfCells().z();
G4double cellSizeRho = fDetector->GetMeshSizeOfCells().x();
G4double cellSizePhi = fDetector->GetMeshSizeOfCells().y();
// Default max value of energy stored in histogram (in GeV)
@@ -77,9 +78,9 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
1.1 * maxEnergy);
analysisManager->CreateH1("energyDepositedInVirtual", "Deposited energy;E_{MC} (GeV);Entries",
1024, 0, 1.1 * maxEnergy);
analysisManager->CreateH1(
"energyRatioInVirtual", "Ratio of energy deposited to primary;E_{dep} / E_{MC};Entries",
1024, 0, 1);
analysisManager->CreateH1("energyRatioInVirtual",
"Ratio of energy deposited to primary;E_{dep} / E_{MC};Entries", 1024,
0, 1);
analysisManager->CreateH1("time", "Simulation time; time (s);Entries", 2048, 0, 100);
analysisManager->CreateH1("longProfile", "Longitudinal profile;t (mm);#LTE#GT (MeV)", cellNumZ,
-0.5 * cellSizeZ, (cellNumZ - 0.5) * cellSizeZ);
@@ -93,8 +94,8 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
"First moment of transverse distribution;#LTr#GT "
"(mm);Entries",
1024, -0.5 * cellSizeRho,
cellNumRho * cellSizeRho /
1); // arbitrary scaling of max value on axis
cellNumRho * cellSizeRho
/ 1); // arbitrary scaling of max value on axis
analysisManager->CreateH1(
"longSecondMoment",
"Second moment of longitudinal distribution;#LT#lambda^{2}#GT "
@@ -104,13 +105,12 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
"transSecondMoment", "Second moment of transverse distribution;#LTr^{2}#GT (mm^{2});Entries",
1024, 0, std::pow(cellNumRho * cellSizeRho, 2) / 5); // arbitrary scaling of max value on axis
analysisManager->CreateH1("hitType", "hit type;type (0=full, 1= fast);Entries", 2, -0.5, 1.5);
analysisManager->CreateH1("phiProfile",
"Azimuthal angle profile, centred at mean;phi;#LTE#GT (MeV)",
cellNumPhi, - (cellNumPhi - 0.5) * cellSizePhi,
(cellNumPhi - 0.5) * cellSizePhi);
analysisManager->CreateH1(
"phiProfile", "Azimuthal angle profile, centred at mean;phi;#LTE#GT (MeV)", cellNumPhi,
-(cellNumPhi - 0.5) * cellSizePhi, (cellNumPhi - 0.5) * cellSizePhi);
analysisManager->CreateH1("numHitsInVirtual", "Number of hits above 0.5 keV", 4048, 0, 20000);
analysisManager->CreateH1("cellEnergy", "Cell energy distribution;log10(E/MeV);Entries",
1024, -4, 2);
analysisManager->CreateH1("cellEnergy", "Cell energy distribution;log10(E/MeV);Entries", 1024, -4,
2);
analysisManager->CreateH1("numDepositsInVirtual", "Number of deposits in all cells per event",
4048, 0, 40000);
analysisManager->CreateH1("cellDepositsInVirtual",
@@ -118,9 +118,10 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
analysisManager->CreateH1("energyDepositedInPhysical",
"Deposited energy in physical detector readout;E_{MC} (GeV);Entries",
1024, 0, 1.1 * maxEnergy);
analysisManager->CreateH1("energyRatioInPhysical",
"Ratio of energy deposited in physical readout to primary; E_{dep} / E_{MC};Entries",
1024, 0, 1);
analysisManager->CreateH1(
"energyRatioInPhysical",
"Ratio of energy deposited in physical readout to primary; E_{dep} / E_{MC};Entries", 1024, 0,
1);
analysisManager->CreateH1("numHitsInPhysical", "Number of hits in physical readout above 0.5 keV",
4048, 0, 5000);
analysisManager->CreateH1("cellEnergyInPhysical",
@@ -128,8 +129,8 @@ void Par04RunAction::BeginOfRunAction(const G4Run*)
analysisManager->CreateH1("numDepositsInPhysical",
"Number of deposits in all physical cells per event", 4048, 0, 40000);
analysisManager->CreateH1("cellDepositsInPhysical",
"Distribution of number of deposits per physical cell per event",
4048, 0, 1024);
"Distribution of number of deposits per physical cell per event", 4048,
0, 1024);
// Creating ntuple
analysisManager->CreateNtuple("global", "Event data");
@@ -24,33 +24,35 @@
// ********************************************************************
//
#include "Par04SensitiveDetector.hh"
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include <CLHEP/Vector/Rotation.h> // for HepRotation
#include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
#include <cmath> // for floor
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4CollectionNameVector.hh> // for G4CollectionNameVector
#include <G4FastHit.hh> // for G4FastHit
#include <G4FastTrack.hh> // for G4FastTrack
#include <G4RotationMatrix.hh> // for G4RotationMatrix
#include <G4StepPoint.hh> // for G4StepPoint
#include <G4THitsCollection.hh> // for G4THitsCollection
#include <G4ThreeVector.hh> // for G4ThreeVector
#include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
#include <G4VUserEventInformation.hh> // for G4VUserEventInformation
#include <cstddef> // for size_t
#include <vector> // for vector
#include "G4Event.hh" // for G4Event
#include "G4EventManager.hh" // for G4EventManager
#include "G4HCofThisEvent.hh" // for G4HCofThisEvent
#include "G4SDManager.hh" // for G4SDManager
#include "G4Step.hh" // for G4Step
#include "G4Track.hh" // for G4Track
#include "Par04EventInformation.hh" // for Par04EventInformation
#include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
#include <cmath> // for floor
#include <cstddef> // for size_t
#include <vector> // for vector
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName)
: G4VSensitiveDetector(aName)
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName) : G4VSensitiveDetector(aName)
{
collectionName.insert("hits");
}
@@ -58,9 +60,7 @@ Par04SensitiveDetector::Par04SensitiveDetector(G4String aName)
Par04SensitiveDetector::Par04SensitiveDetector(G4String aName, G4ThreeVector aNb,
G4ThreeVector aSize)
: G4VSensitiveDetector(aName)
, fMeshNbOfCells(aNb)
, fMeshSizeOfCells(aSize)
: G4VSensitiveDetector(aName), fMeshNbOfCells(aNb), fMeshSizeOfCells(aSize)
{
collectionName.insert("hits");
}
@@ -74,8 +74,7 @@ Par04SensitiveDetector::~Par04SensitiveDetector() = default;
void Par04SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
{
fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
if(fHitCollectionID < 0)
{
if (fHitCollectionID < 0) {
fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
}
aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
@@ -90,12 +89,10 @@ void Par04SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
G4bool Par04SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
{
G4double edep = aStep->GetTotalEnergyDeposit();
if(edep == 0.)
return true;
if (edep == 0.) return true;
auto hit = RetrieveAndSetupHit(aStep->GetPostStepPoint()->GetPosition());
if(hit == nullptr)
return true;
if (hit == nullptr) return true;
// Add energy deposit from G4Step
hit->AddEdep(edep);
@@ -104,13 +101,12 @@ G4bool Par04SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
// Fill time information from G4Step
// If it's already filled, choose hit with earliest global time
if(hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
hit->SetTime(aStep->GetTrack()->GetGlobalTime());
// Set hit type to full simulation (only if hit is not already marked as fast
// sim)
if(hit->GetType() != 1)
hit->SetType(0);
if (hit->GetType() != 1) hit->SetType(0);
return true;
}
@@ -121,12 +117,10 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
G4TouchableHistory*)
{
G4double edep = aHit->GetEnergy();
if(edep == 0.)
return true;
if (edep == 0.) return true;
auto hit = RetrieveAndSetupHit(aHit->GetPosition());
if(hit == nullptr)
return true;
if (hit == nullptr) return true;
// Add energy deposit from G4FastHit
hit->AddEdep(edep);
@@ -135,8 +129,7 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
// Fill time information from G4FastTrack
// If it's already filled, choose hit with earliest global time
if(hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime())
{
if (hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime()) {
hit->SetTime(aTrack->GetPrimaryTrack()->GetGlobalTime());
}
@@ -151,13 +144,11 @@ G4bool Par04SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTr
Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosition)
{
if(fEntrancePosition.x() == -1)
{
auto info = dynamic_cast<Par04EventInformation*>(
if (fEntrancePosition.x() == -1) {
auto info = dynamic_cast<Par04EventInformation*>(
G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation());
if(info == nullptr)
return nullptr;
fEntrancePosition = info->GetPosition();
if (info == nullptr) return nullptr;
fEntrancePosition = info->GetPosition();
fEntranceDirection = info->GetDirection();
}
@@ -166,8 +157,8 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
// Calculate rotation matrix along the particle momentum direction
// It will rotate the shower axes to match the incoming particle direction
G4RotationMatrix rotMatrix = G4RotationMatrix();
double particleTheta = fEntranceDirection.theta();
double particlePhi = fEntranceDirection.phi();
double particleTheta = fEntranceDirection.theta();
double particlePhi = fEntranceDirection.phi();
rotMatrix.rotateZ(-particlePhi);
rotMatrix.rotateY(-particleTheta);
G4RotationMatrix rotMatrixInv = CLHEP::inverseOf(rotMatrix);
@@ -176,27 +167,25 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
G4int rhoNo = std::floor(delta.perp() / fMeshSizeOfCells.x());
G4int phiNo = std::floor((CLHEP::pi + delta.phi()) / fMeshSizeOfCells.y());
G4int zNo = std::floor(delta.z() / fMeshSizeOfCells.z());
G4int zNo = std::floor(delta.z() / fMeshSizeOfCells.z());
std::size_t hitID =
fMeshNbOfCells.x() * fMeshNbOfCells.z() * phiNo + fMeshNbOfCells.z() * rhoNo + zNo;
if(zNo >= fMeshNbOfCells.z() || rhoNo >= fMeshNbOfCells.x() || zNo < 0)
{
if (zNo >= fMeshNbOfCells.z() || rhoNo >= fMeshNbOfCells.x() || zNo < 0) {
return nullptr;
}
auto hit = fHitsMap[hitID].get();
if (hit==nullptr) {
if (hit == nullptr) {
fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
hit = fHitsMap[hitID].get();
hit->SetPhiId(phiNo);
hit->SetRhoId(rhoNo);
hit->SetZid(zNo);
hit->SetRot(rotMatrixInv);
hit->SetPos(fEntrancePosition +
rotMatrixInv * G4ThreeVector(0, 0, (zNo + 0.5) * fMeshSizeOfCells.z()));
hit->SetPos(fEntrancePosition
+ rotMatrixInv * G4ThreeVector(0, 0, (zNo + 0.5) * fMeshSizeOfCells.z()));
}
return hit;
}
@@ -205,7 +194,7 @@ Par04Hit* Par04SensitiveDetector::RetrieveAndSetupHit(G4ThreeVector aGlobalPosit
void Par04SensitiveDetector::EndOfEvent(G4HCofThisEvent*)
{
for(const auto& hits: fHitsMap){
for (const auto& hits : fHitsMap) {
fHitsCollection->insert(new Par04Hit(*hits.second.get()));
}
fHitsMap.clear();
@@ -25,43 +25,43 @@
//
#ifdef USE_INFERENCE_TORCH
#include "Par04TorchInference.hh"
#include <algorithm> // for copy, max
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <cstdint> // for int64_t
#include <utility> // for move
#include "Par04InferenceInterface.hh" // for Par04InferenceInterface
#include <torch/torch.h>
# include "Par04TorchInference.hh"
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
# include <algorithm> // for copy, max
# include <cassert> // for assert
# include <cstddef> // for size_t
# include <cstdint> // for int64_t
# include <torch/torch.h>
# include <utility> // for move
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Par04TorchInference::Par04TorchInference(G4String modelPath)
: Par04InferenceInterface()
Par04TorchInference::Par04TorchInference(G4String modelPath) : Par04InferenceInterface()
{
fModule = torch::jit::load( modelPath );
fModule = torch::jit::load(modelPath);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void Par04TorchInference::RunInference(std::vector<float> aGenVector,
std::vector<G4double>& aEnergies,
int aSize)
std::vector<G4double>& aEnergies, int aSize)
{
// latentSize : size of the latent space
// 4 is the size of the condition vector
int latentSize = aGenVector.size() - 4;
// split into latent and condition vectors
std::vector<float> latent;
for ( int i=0;i<latentSize;i++) {
for (int i = 0; i < latentSize; i++) {
latent.push_back(aGenVector[i]);
}
std::vector<float> energy;
energy.push_back(aGenVector[latentSize+1]);
energy.push_back(aGenVector[latentSize + 1]);
std::vector<float> angle;
energy.push_back(aGenVector[latentSize+2]);
energy.push_back(aGenVector[latentSize + 2]);
std::vector<float> geo;
for ( int i=latentSize+2;i<latentSize+4;i++) {
for (int i = latentSize + 2; i < latentSize + 4; i++) {
geo.push_back(aGenVector[i]);
}
@@ -73,18 +73,18 @@ void Par04TorchInference::RunInference(std::vector<float> aGenVector,
std::vector<torch::jit::IValue> genInput;
genInput.push_back( latentVector );
genInput.push_back( eTensor );
genInput.push_back( angleTensor );
genInput.push_back( geoTensor );
genInput.push_back(latentVector);
genInput.push_back(eTensor);
genInput.push_back(angleTensor);
genInput.push_back(geoTensor);
at::Tensor outTensor = fModule.forward( genInput).toTensor().contiguous();
at::Tensor outTensor = fModule.forward(genInput).toTensor().contiguous();
std::vector<G4double> output( outTensor.data_ptr<float>(),
outTensor.data_ptr<float>() + outTensor.numel() );
std::vector<G4double> output(outTensor.data_ptr<float>(),
outTensor.data_ptr<float>() + outTensor.numel());
aEnergies.assign(aSize, 0);
for(int i = 0; i < aSize; i++) {
for (int i = 0; i < aSize; i++) {
aEnergies[i] = output[i];
}
}