Import Geant4 11.4.0.beta source tree
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
///\file "parameterisations/Par03/.README.txt"
|
||||
///\file "parameterisations/Par04/.README.txt"
|
||||
///\brief Example Par04 README page
|
||||
|
||||
/*! \page ExamplePar04 Example Par04
|
||||
@@ -118,10 +118,18 @@ account all energy from the parameterisation.
|
||||
The macro file examplePar04.mac is used to run full simulation. It will simulate 100
|
||||
events, for single 10 GeV electron beams.
|
||||
If CMake is able to find inference libraries (LWTNN and/or ONNX Runtime and/or LibTorch), a configuration
|
||||
macro will be available for that library (examplePar04_lwtnn.mac and/or examplePar04_onnx.mac
|
||||
and/or examplePar04_torch.mac). It will use a trained model to run inference and create showers
|
||||
macro will be available for that library (examplePar04_lwtnn_vae.mac and/or examplePar04_onnx_vae.mac
|
||||
and/or examplePar04_torch_vae.mac and/or examplePar04_onnx_calodit.mac and/or
|
||||
examplePar04_torch_calodit.mac). It will use a trained model to run inference and create showers
|
||||
in the detector by directly depositing energy.
|
||||
|
||||
There are two models available VAE and CaloDiT-2. CaloDiT-2 is a more sophisticated transformer-based
|
||||
diffusion model which gives much better accuracy, especially on the cell energy distribution, and
|
||||
also can be easily adapted to new detectors.
|
||||
Notes for CaloDiT-2; first, it operates on a lower granular cylindrical virtual mesh than VAE (which became
|
||||
from this release also the default for full simulation).
|
||||
Second, we do not support LWTNN inference, as PyTorch to LWTNN conversion is not straightforward.
|
||||
|
||||
## 8. How to build and run the example
|
||||
|
||||
- LWTNN, ONNX Runtime, and LibTorch are available on LCG. In order to use them, you can set a `CMAKE_PREFIX_PATH`:
|
||||
@@ -150,29 +158,33 @@ account all energy from the parameterisation.
|
||||
|
||||
- If ONNX Runtime is available:
|
||||
\verbatim
|
||||
% ./examplePar04 -m examplePar04_onnx.mac
|
||||
% ./examplePar04 -m examplePar04_onnx_vae.mac
|
||||
% ./examplePar04 -m examplePar04_onnx_calodit.mac
|
||||
\endverbatim
|
||||
For interactive mode with visualization:
|
||||
\verbatim
|
||||
% ./examplePar04 -i -m vis_onnx.mac
|
||||
% ./examplePar04 -i -m vis_onnx_vae.mac
|
||||
% ./examplePar04 -i -m vis_onnx_calodit.mac
|
||||
\endverbatim
|
||||
|
||||
- If LWTNN is available:
|
||||
\verbatim
|
||||
% ./examplePar04 -m examplePar04_lwtnn.mac
|
||||
% ./examplePar04 -m examplePar04_lwtnn_vae.mac
|
||||
\endverbatim
|
||||
For interactive mode with visualization:
|
||||
\verbatim
|
||||
% ./examplePar04 -i -m vis_lwtnn.mac
|
||||
% ./examplePar04 -i -m vis_lwtnn_vae.mac
|
||||
\endverbatim
|
||||
|
||||
- If LibTorch is available:
|
||||
\verbatim
|
||||
% ./examplePar04 -m examplePar04_torch.mac
|
||||
% ./examplePar04 -m examplePar04_torch_vae.mac
|
||||
% ./examplePar04 -m examplePar04_torch_calodit.mac
|
||||
\endverbatim
|
||||
For interactive mode with visualization:
|
||||
\verbatim
|
||||
% ./examplePar04 -i -m vis_torch.mac
|
||||
% ./examplePar04 -i -m vis_torch_vae.mac
|
||||
% ./examplePar04 -i -m vis_torch_calodit.mac
|
||||
\endverbatim
|
||||
|
||||
- Additional options available:
|
||||
@@ -195,31 +207,51 @@ For tasking run manager mode with number of tasks that can be change via env var
|
||||
|
||||
## 9. Macros
|
||||
|
||||
common_settings.mac - A macro with common settings, executed by all other macros (e.g. detector settings).
|
||||
common_settings_lowgran.mac - A macro with common settings, executed by all other macros that use low granularity
|
||||
(e.g. detector settings). This can be used directly by fast simulation, and for full sim
|
||||
the sensitivity of absorber must be set to false (it's done in examplePar04.mac or vis.mac).
|
||||
|
||||
common_settings_highgran.mac - A macro with common settings, executed by all other macros that use high granularity
|
||||
(e.g. detector settings). This can be used directly by fast simulation, and for full sim
|
||||
the sensitivity of absorber must be set to false.
|
||||
|
||||
common_settings_vis.mac - A macro with common settings, executed by all visualisation macros.
|
||||
|
||||
common_settings_postInit.mac - A macro with common settings, executed after initialization, e.g. for particle gun settings.
|
||||
|
||||
vis.mac - Allows to run visualization. Pass it to the example in interactive mode ("-i" passed to the executable).
|
||||
It can be used to visualize full simulation.
|
||||
It can be used to visualize full simulation. Lower granularity is used for visualisation. To be compared to CaloDiT-2.
|
||||
|
||||
vis_onnx.mac - Allows to run visualization with ONNX Runtime inference. Pass it to the example in interactive mode
|
||||
vis_onnx_vae.mac - Allows to run visualization with ONNX Runtime inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
vis_lwtnn.mac - Allows to run visualization with LWTNN inference. Pass it to the example in interactive mode
|
||||
vis_lwtnn_vae.mac - Allows to run visualization with LWTNN inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
vis_torch.mac - Allows to run visualization with LibTorch inference. Pass it to the example in interactive mode
|
||||
vis_torch_vae.mac - Allows to run visualization with LibTorch inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
examplePar04.mac - Runs full simulation. It will run 100 events with single electrons, 10 GeV and
|
||||
along y axis.
|
||||
along y axis. Lower granularity is used, to be compared with CaloDiT-2.
|
||||
|
||||
examplePar04_onnx.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file.
|
||||
examplePar04_onnx_vae.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file for VAE.
|
||||
|
||||
examplePar04_lwtnn.mac - Available only if LWTNN is found by CMake. Runs fast simulation with
|
||||
a NN stored in json file.
|
||||
examplePar04_lwtnn_vae.mac - Available only if LWTNN is found by CMake. Runs fast simulation with
|
||||
a NN stored in json file for VAE.
|
||||
|
||||
examplePar04_torch.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file.
|
||||
examplePar04_torch_vae.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file for VAE.
|
||||
|
||||
vis_onnx_calodit.mac - Allows to run visualization with ONNX Runtime inference using CaloDiT-2.
|
||||
|
||||
vis_torch_calodit.mac - Allows to run visualization with LibTorch inference using CaloDiT-2.
|
||||
|
||||
examplePar04_onnx_calodit.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file for CaloDiT-2.
|
||||
|
||||
examplePar04_torch_calodit.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file for CaloDiT-2.
|
||||
|
||||
## 10. UI commands
|
||||
|
||||
@@ -251,10 +283,10 @@ common_settings.mac - A macro with common settings, executed by all other macros
|
||||
|
||||
- readout mesh
|
||||
\verbatim
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm # (4.65 for CaloDiT-2)
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfRhoCells 18 # (9 for CaloDiT-2)
|
||||
/Par04/mesh/setNbOfPhiCells 50 # (16 for CaloDiT-2)
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
\endverbatim
|
||||
|
||||
@@ -262,14 +294,14 @@ common_settings.mac - A macro with common settings, executed by all other macros
|
||||
\verbatim
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx # (or cd.onnx for CaloDiT-2)
|
||||
/Par04/inference/setProfileFlag 0
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm # (4.65 for CaloDiT-2)
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfRhoCells 18 # (9 for CaloDiT-2)
|
||||
/Par04/inference/setNbOfPhiCells 50 # (16 for CaloDiT-2)
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
\endverbatim
|
||||
|
||||
@@ -278,11 +310,19 @@ common_settings.mac - A macro with common settings, executed by all other macros
|
||||
The scripts available in the training folder were used to firstly convert
|
||||
the ROOT files to the h5 files, preprocess the data and then train
|
||||
the VAE model of this example. More details can be found in
|
||||
training/README.
|
||||
training_vae/README.
|
||||
|
||||
|
||||
## 12. Public data
|
||||
|
||||
Data generated with full simulation with this example has been published on <a href="https://doi.org/10.5281/zenodo.6082201">zenodo</a>.
|
||||
Data generated with full simulation with this example has been published on
|
||||
<a href="https://doi.org/10.5281/zenodo.6082201">zenodo</a>.
|
||||
It was used (as well as VAE) for this publication:
|
||||
<a href="https://doi.org/10.1016/j.physletb.2023.138079">doi.org/10.1016/j.physletb.2023.138079</a>.
|
||||
|
||||
Data generated with low granularity (so-called dataset2) and high granularity (so-called dataset3) are
|
||||
released for the CaloChallenge:
|
||||
dataset2 (lowgran): <a href="https://doi.org/10.5281/zenodo.6366271">doi.org/10.5281/zenodo.6366271</a>.
|
||||
dataset3 (highgran): <a href="https://doi.org/10.5281/zenodo.6366324">doi.org/10.5281/zenodo.6366324</a>.
|
||||
|
||||
*/
|
||||
|
||||
@@ -45,12 +45,12 @@ endif()
|
||||
# ONNX
|
||||
if(INFERENCE_LIB)
|
||||
find_package(OnnxRuntime QUIET)
|
||||
find_package(CUDA QUIET)
|
||||
find_package(CUDAToolkit QUIET)
|
||||
if(OnnxRuntime_FOUND)
|
||||
message("ONNX Runtime inference library found.")
|
||||
add_definitions(-DUSE_INFERENCE)
|
||||
add_definitions(-DUSE_INFERENCE_ONNX)
|
||||
if(CUDA_FOUND)
|
||||
if(CUDAToolkit_FOUND)
|
||||
message("Cuda found.")
|
||||
add_definitions(-DUSE_CUDA)
|
||||
else()
|
||||
@@ -98,13 +98,12 @@ if(OnnxRuntime_FOUND)
|
||||
target_include_directories(examplePar04 PUBLIC ${OnnxRuntime_INCLUDE_DIR})
|
||||
target_link_libraries(examplePar04 ${OnnxRuntime_LIBRARY})
|
||||
# Cuda_FOUND
|
||||
if(CUDA_FOUND)
|
||||
target_include_directories(examplePar04 PUBLIC ${CUDA_INCLUDE_DIRS})
|
||||
include_directories(${CUDA_INCLUDE_DIRS})
|
||||
target_link_libraries(examplePar04 ${CUDA_LIBRARIES})
|
||||
if(CUDAToolkit_FOUND)
|
||||
target_link_libraries(examplePar04 CUDA::cudart)
|
||||
endif()
|
||||
# Depend on data for runtime
|
||||
add_dependencies(examplePar04 examplePar04onnxdata)
|
||||
add_dependencies(examplePar04 examplePar04onnxVAEdata)
|
||||
add_dependencies(examplePar04 examplePar04onnxCaloDiTdata)
|
||||
endif()
|
||||
|
||||
if(Torch_FOUND)
|
||||
@@ -112,7 +111,8 @@ if(Torch_FOUND)
|
||||
target_link_libraries(examplePar04 ${TORCH_LIBRARIES})
|
||||
message(STATUS "${TORCH_LIBRARIES}")
|
||||
# Depend on data for runtime
|
||||
add_dependencies(examplePar04 examplePar04torchdata)
|
||||
add_dependencies(examplePar04 examplePar04torchVAEdata)
|
||||
add_dependencies(examplePar04 examplePar04torchCaloDiTdata)
|
||||
endif()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
@@ -121,16 +121,16 @@ endif()
|
||||
# relies on these scripts being in the current working directory.
|
||||
#
|
||||
set(Par04_SCRIPTS
|
||||
examplePar04.mac vis.mac common_settings.mac
|
||||
examplePar04.mac vis.mac common_settings_lowgran.mac common_settings_highgran.mac common_settings_vis.mac common_settings_postInit.mac
|
||||
)
|
||||
if(lwtnn_FOUND)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_lwtnn.mac vis_lwtnn.mac)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_lwtnn_vae.mac vis_lwtnn_vae.mac)
|
||||
endif()
|
||||
if(OnnxRuntime_FOUND)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_onnx.mac vis_onnx.mac)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_onnx_calodit.mac examplePar04_onnx_vae.mac vis_onnx_calodit.mac vis_onnx_vae.mac)
|
||||
endif()
|
||||
if(Torch_FOUND)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_torch.mac vis_torch.mac)
|
||||
set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_torch_calodit.mac examplePar04_torch_vae.mac vis_torch_calodit.mac vis_torch_vae.mac)
|
||||
endif()
|
||||
|
||||
foreach(_script ${Par04_SCRIPTS})
|
||||
@@ -158,7 +158,7 @@ if(lwtnn_FOUND)
|
||||
)
|
||||
endif()
|
||||
if(OnnxRuntime_FOUND)
|
||||
ExternalProject_Add(examplePar04onnxdata
|
||||
ExternalProject_Add(examplePar04onnxVAEdata
|
||||
DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
|
||||
URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.onnx
|
||||
URL_MD5 cacd07c24b704decca28de990850287e
|
||||
@@ -167,9 +167,18 @@ if(OnnxRuntime_FOUND)
|
||||
INSTALL_COMMAND ""
|
||||
DOWNLOAD_NO_EXTRACT true
|
||||
)
|
||||
ExternalProject_Add(examplePar04onnxCaloDiTdata
|
||||
DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
|
||||
URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/cd.onnx
|
||||
URL_MD5 eb0fa86fc53d9baf72414410a4a9e3c9
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
DOWNLOAD_NO_EXTRACT true
|
||||
)
|
||||
endif()
|
||||
if(Torch_FOUND)
|
||||
ExternalProject_Add(examplePar04torchdata
|
||||
ExternalProject_Add(examplePar04torchVAEdata
|
||||
DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
|
||||
URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.pt
|
||||
URL_MD5 a43337f7f976e976f1127015f2ba61db
|
||||
@@ -178,6 +187,15 @@ if(Torch_FOUND)
|
||||
INSTALL_COMMAND ""
|
||||
DOWNLOAD_NO_EXTRACT true
|
||||
)
|
||||
ExternalProject_Add(examplePar04torchCaloDiTdata
|
||||
DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
|
||||
URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/cd_cpu.pt
|
||||
URL_MD5 c812651390bfc2a4f4a88b3c7f945c56
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
DOWNLOAD_NO_EXTRACT true
|
||||
)
|
||||
endif()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
@@ -5,6 +5,9 @@ which **must** added in reverse chronological order (newest at the top).
|
||||
It must **not** be used as a substitute for writing good git commit messages!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
## 2025-05-27 Anna Zaborowska, Piyush Raikwar (expar04-V11-03-00)
|
||||
- Update of VAE training with the new translation script and condor scripts
|
||||
- Introduction of the CaloDiT pre-trained model which offers far greater accuracy
|
||||
|
||||
## 2024-10-22 Ben Morgan (expar04-V11-02-03)
|
||||
- Bump tensorflow version from [GitHub Dependabot PR](https://github.com/Geant4/geant4/pull/75)
|
||||
|
||||
@@ -130,10 +130,18 @@ account all energy from the parameterisation.
|
||||
The macro file examplePar04.mac is used to run full simulation. It will simulate 100
|
||||
events, for single 10 GeV electron beams.
|
||||
If CMake is able to find inference libraries (LWTNN and/or ONNX Runtime and/or LibTorch), a configuration
|
||||
macro will be available for that library (examplePar04_lwtnn.mac and/or examplePar04_onnx.mac
|
||||
and/or examplePar04_torch.mac). It will use a trained model to run inference and create showers
|
||||
macro will be available for that library (examplePar04_lwtnn_vae.mac and/or examplePar04_onnx_vae.mac
|
||||
and/or examplePar04_torch_vae.mac and/or examplePar04_onnx_calodit.mac and/or
|
||||
examplePar04_torch_calodit.mac). It will use a trained model to run inference and create showers
|
||||
in the detector by directly depositing energy.
|
||||
|
||||
There are two models available VAE and CaloDiT-2. CaloDiT-2 is a more sophisticated transformer-based
|
||||
diffusion model which gives much better accuracy, especially on the cell energy distribution, and
|
||||
also can be easily adapted to new detectors.
|
||||
Notes for CaloDiT-2; first, it operates on a lower granular cylindrical virtual mesh than VAE (which became
|
||||
from this release also the default for full simulation).
|
||||
Second, we do not support LWTNN inference, as PyTorch to LWTNN conversion is not straightforward.
|
||||
|
||||
8. How to build and run the example
|
||||
-----------------------------------
|
||||
- LWTNN, ONNX Runtime, and LibTorch are available on LCG. In order to use them, you can set a CMAKE_PREFIX_PATH:
|
||||
@@ -153,18 +161,23 @@ account all energy from the parameterisation.
|
||||
which allows to visualize hits (from full simulation).
|
||||
|
||||
- If ONNX Runtime is available:
|
||||
% ./examplePar04 -m examplePar04_onnx.mac
|
||||
% ./examplePar04 -m examplePar04_onnx_vae.mac
|
||||
% ./examplePar04 -m examplePar04_onnx_calodit.mac
|
||||
For interactive mode with visualization:
|
||||
% ./examplePar04 -i -m vis_onnx.mac
|
||||
% ./examplePar04 -i -m vis_onnx_vae.mac
|
||||
% ./examplePar04 -i -m vis_onnx_calodit.mac
|
||||
|
||||
- If LWTNN is available:
|
||||
% ./examplePar04 -m examplePar04_lwtnn.mac
|
||||
% ./examplePar04 -m examplePar04_lwtnn_vae.mac
|
||||
For interactive mode with visualization:
|
||||
% ./examplePar04 -i -m vis_lwtnn.mac
|
||||
% ./examplePar04 -i -m vis_lwtnn_vae.mac
|
||||
|
||||
- If LibTorch is available:
|
||||
% ./examplePar04 -m examplePar04_torch.mac
|
||||
% ./examplePar04 -m examplePar04_torch_vae.mac
|
||||
% ./examplePar04 -m examplePar04_torch_calodit.mac
|
||||
For interactive mode with visualization:
|
||||
% ./examplePar04 -i -m vis_torch.mac
|
||||
% ./examplePar04 -i -m vis_torch_vae.mac
|
||||
% ./examplePar04 -i -m vis_torch_calodit.mac
|
||||
|
||||
- Additional options available:
|
||||
% ./examplePar04 -m examplePar04.mac -r 0
|
||||
@@ -182,31 +195,51 @@ account all energy from the parameterisation.
|
||||
9. Macros
|
||||
---------
|
||||
|
||||
common_settings.mac - A macro with common settings, executed by all other macros (e.g. detector settings).
|
||||
common_settings_lowgran.mac - A macro with common settings, executed by all other macros that use low granularity
|
||||
(e.g. detector settings). This can be used directly by fast simulation, and for full sim
|
||||
the sensitivity of absorber must be set to false (it's done in examplePar04.mac or vis.mac).
|
||||
|
||||
common_settings_highgran.mac - A macro with common settings, executed by all other macros that use high granularity
|
||||
(e.g. detector settings). This can be used directly by fast simulation, and for full sim
|
||||
the sensitivity of absorber must be set to false.
|
||||
|
||||
common_settings_vis.mac - A macro with common settings, executed by all visualisation macros.
|
||||
|
||||
common_settings_postInit.mac - A macro with common settings, executed after initialization, e.g. for particle gun settings.
|
||||
|
||||
vis.mac - Allows to run visualization. Pass it to the example in interactive mode ("-i" passed to the executable).
|
||||
It can be used to visualize full simulation.
|
||||
It can be used to visualize full simulation. Lower granularity is used for visualisation. To be compared to CaloDiT-2.
|
||||
|
||||
vis_onnx.mac - Allows to run visualization with ONNX Runtime inference. Pass it to the example in interactive mode
|
||||
vis_onnx_vae.mac - Allows to run visualization with ONNX Runtime inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
vis_lwtnn.mac - Allows to run visualization with LWTNN inference. Pass it to the example in interactive mode
|
||||
vis_lwtnn_vae.mac - Allows to run visualization with LWTNN inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
vis_torch.mac - Allows to run visualization with LibTorch inference. Pass it to the example in interactive mode
|
||||
vis_torch_vae.mac - Allows to run visualization with LibTorch inference using VAE. Pass it to the example in interactive mode
|
||||
("-i" passed to the executable). It contains necessary settings of the inference.
|
||||
|
||||
examplePar04.mac - Runs full simulation. It will run 100 events with single electrons, 10 GeV and
|
||||
along y axis.
|
||||
along y axis. Lower granularity is used, to be compared with CaloDiT-2.
|
||||
|
||||
examplePar04_onnx.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file.
|
||||
examplePar04_onnx_vae.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file for VAE.
|
||||
|
||||
examplePar04_lwtnn.mac - Available only if LWTNN is found by CMake. Runs fast simulation with
|
||||
a NN stored in json file.
|
||||
examplePar04_lwtnn_vae.mac - Available only if LWTNN is found by CMake. Runs fast simulation with
|
||||
a NN stored in json file for VAE.
|
||||
|
||||
examplePar04_torch.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file.
|
||||
examplePar04_torch_vae.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file for VAE.
|
||||
|
||||
vis_onnx_calodit.mac - Allows to run visualization with ONNX Runtime inference using CaloDiT-2.
|
||||
|
||||
vis_torch_calodit.mac - Allows to run visualization with LibTorch inference using CaloDiT-2.
|
||||
|
||||
examplePar04_onnx_calodit.mac - Available only if ONNX Runtime is found by CMake. Runs fast simulation with
|
||||
a NN stored in onnx file for CaloDiT-2.
|
||||
|
||||
examplePar04_torch_calodit.mac - Available only if LibTorch is found by CMake. Runs fast simulation with
|
||||
a NN stored in pt file for CaloDiT-2.
|
||||
|
||||
10. UI commands
|
||||
--------------
|
||||
@@ -232,23 +265,23 @@ common_settings.mac - A macro with common settings, executed by all other macros
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
|
||||
- readout mesh
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm # (4.65 for CaloDiT-2)
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfRhoCells 18 # (9 for CaloDiT-2)
|
||||
/Par04/mesh/setNbOfPhiCells 50 # (16 for CaloDiT-2)
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
|
||||
- inference setup
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx # (or cd.onnx for CaloDiT-2)
|
||||
/Par04/inference/setProfileFlag 0
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm # (4.65 for CaloDiT-2)
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfRhoCells 18 # (9 for CaloDiT-2)
|
||||
/Par04/inference/setNbOfPhiCells 50 # (16 for CaloDiT-2)
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
11. Python scripts for training
|
||||
@@ -257,11 +290,20 @@ common_settings.mac - A macro with common settings, executed by all other macros
|
||||
The scripts available in the training folder were used to firstly convert
|
||||
the ROOT files to the h5 files, preprocess the data and then train
|
||||
the VAE model of this example. More details can be found in
|
||||
training/README.
|
||||
training_vae/README.
|
||||
|
||||
For CaloDiT-2 training and adaptation to new detectors, refer training_calodit/README.
|
||||
|
||||
|
||||
12. Public data
|
||||
--------------
|
||||
|
||||
Data generated with full simulation with this example has been published on zenodo:
|
||||
Data generated with full simulation with higher granularity, with this example has been published on zenodo:
|
||||
https://doi.org/10.5281/zenodo.6082201
|
||||
It was used (as well as VAE) for this publication:
|
||||
https://doi.org/10.1016/j.physletb.2023.138079
|
||||
|
||||
Data generated with low granularity (so-called dataset2) and high granularity (so-called dataset3) are
|
||||
released for the CaloChallenge:
|
||||
dataset2 (lowgran): https://doi.org/10.5281/zenodo.6366271
|
||||
dataset3 (highgran): https://doi.org/10.5281/zenodo.6366324
|
||||
@@ -11,8 +11,8 @@ find_library(
|
||||
|
||||
find_path(
|
||||
OnnxRuntime_INCLUDE_DIR
|
||||
NAMES core/session/onnxruntime_cxx_api.h
|
||||
PATH_SUFFIXES include include/onnxruntime
|
||||
NAMES onnxruntime_cxx_api.h
|
||||
PATH_SUFFIXES include include/onnxruntime include/core/session
|
||||
DOC "The ONNXRuntime include directory")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
+2
-8
@@ -4,7 +4,7 @@
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 2 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm false
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm true
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
## 2.325 mm of tungsten =~ 0.25 * 9.327 mm = 0.25 * R_Moliere
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
@@ -17,10 +17,4 @@
|
||||
## 32 slices in 2 pi
|
||||
/Par04/parallel/setNbOfSlices 320
|
||||
## detector length / 100 rows = 4m / 100 = 4cm
|
||||
/Par04/parallel/setNbOfRows 100
|
||||
|
||||
# Initialize
|
||||
/run/initialize
|
||||
/gun/energy 10 GeV
|
||||
/gun/position 0 0 0
|
||||
/gun/direction 0 1 0
|
||||
/Par04/parallel/setNbOfRows 100
|
||||
@@ -0,0 +1,20 @@
|
||||
# Supress output of physics list initialization
|
||||
/process/had/verbose 0
|
||||
# Detector Construction
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 2 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm true
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
## 2.325 mm of tungsten =~ 0.25 * 9.327 mm = 0.25 * R_Moliere
|
||||
/Par04/mesh/setSizeOfRhoCells 4.65 mm
|
||||
## 2 * 1.4 mm of tungsten =~ 0.65 X_0
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 9
|
||||
/Par04/mesh/setNbOfPhiCells 16
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
## Parallel world
|
||||
## 32 slices in 2 pi
|
||||
/Par04/parallel/setNbOfSlices 320
|
||||
## detector length / 100 rows = 4m / 100 = 4cm
|
||||
/Par04/parallel/setNbOfRows 100
|
||||
@@ -0,0 +1,3 @@
|
||||
/gun/energy 10 GeV
|
||||
/gun/position 0 0 0
|
||||
/gun/direction 0 1 0
|
||||
+16
-45
@@ -1,25 +1,17 @@
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 4 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm true
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
/Par04/detector/print
|
||||
|
||||
# Use default detector dimensions and initialize
|
||||
/run/initialize
|
||||
|
||||
# If inference model is active, de-activate it because it needs configuration
|
||||
/param/InActivateModel inferenceModel
|
||||
|
||||
# Open a viewer
|
||||
/vis/open
|
||||
# This opens the default viewer - see examples/basic/B1/vis.mac for a
|
||||
# more comprehensive overview of options. Also the documentation.
|
||||
# Use this open statement to create an OpenGL view:
|
||||
/vis/open OGL 600x600-0+0
|
||||
#
|
||||
# Use this open statement to create a .prim file suitable for
|
||||
# viewing in DAWN:
|
||||
#/vis/open DAWNFILE
|
||||
#
|
||||
# Use this open statement to create a .heprep file suitable for
|
||||
# viewing in HepRApp:
|
||||
#/vis/open HepRepFile
|
||||
#
|
||||
# Use this open statement to create a .wrl file suitable for
|
||||
# viewing in a VRML viewer:
|
||||
#/vis/open VRML2FILE
|
||||
#
|
||||
# Disable auto refresh and quieten vis messages whilst scene and
|
||||
# trajectories are established:
|
||||
@@ -27,14 +19,14 @@
|
||||
/vis/verbose errors
|
||||
#
|
||||
# Draw geometry:
|
||||
/vis/drawVolume worlds
|
||||
/vis/drawVolume world
|
||||
#
|
||||
# Specify view angle:
|
||||
/vis/viewer/set/viewpointThetaPhi 0 90 deg
|
||||
/vis/viewer/set/targetPoint 0 850 0 mm
|
||||
#
|
||||
# Specify zoom value:
|
||||
/vis/viewer/zoomTo 40
|
||||
/vis/viewer/zoom 20
|
||||
#
|
||||
# Specify style (surface or wireframe):
|
||||
#/vis/viewer/set/style wireframe
|
||||
@@ -84,24 +76,3 @@
|
||||
# For file-based drivers, use this to create an empty detector view:
|
||||
#/vis/viewer/flush
|
||||
/vis/viewer/set/background 1 1 1
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.json
|
||||
/Par04/inference/setInferenceLibrary LWTNN
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
@@ -143,8 +143,12 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// Initialization of default Run manager
|
||||
auto* runManager = G4RunManagerFactory::CreateRunManager(runManagerType);
|
||||
if (runManagerTypeInt == 1) runManager->SetNumberOfThreads(numOfThreadsOrTasks);
|
||||
auto* runManager =
|
||||
G4RunManagerFactory::CreateRunManager(runManagerType);
|
||||
if(runManagerTypeInt == 1 || runManagerTypeInt == 2) {
|
||||
runManager->SetNumberOfThreads(numOfThreadsOrTasks);
|
||||
}
|
||||
|
||||
// Detector geometry:
|
||||
auto detector = new Par04DetectorConstruction();
|
||||
auto parallelWorldFull = new Par04ParallelFullWorld("parallelWorldFullSim", detector);
|
||||
@@ -174,15 +178,16 @@ int main(int argc, char** argv)
|
||||
// UserAction classes
|
||||
//-------------------------------
|
||||
runManager->SetUserInitialization(new Par04ActionInitialisation(detector, parallelWorldFull));
|
||||
//----------------
|
||||
// Visualization:
|
||||
//----------------
|
||||
G4cout << "Instantiating Visualization Manager......." << G4endl;
|
||||
G4VisManager* visManager = new G4VisExecutive;
|
||||
visManager->Initialize();
|
||||
G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
||||
|
||||
if (useInteractiveMode) {
|
||||
//----------------
|
||||
// Visualization:
|
||||
//----------------
|
||||
G4cout << "Instantiating Visualization Manager......." << G4endl;
|
||||
G4VisManager* visManager = new G4VisExecutive;
|
||||
visManager->Initialize();
|
||||
|
||||
if (batchMacroName.empty()) {
|
||||
G4Exception("main", "Unknown macro name", FatalErrorInArgument,
|
||||
("No macro name passed to " + G4String(argv[0])).c_str());
|
||||
@@ -190,7 +195,7 @@ int main(int argc, char** argv)
|
||||
G4String command = "/control/execute ";
|
||||
UImanager->ApplyCommand(command + batchMacroName);
|
||||
ui->SessionStart();
|
||||
delete ui;
|
||||
delete visManager;
|
||||
}
|
||||
else {
|
||||
G4String command = "/control/execute ";
|
||||
@@ -200,8 +205,7 @@ int main(int argc, char** argv)
|
||||
// Free the store: user actions, physics_list and detector_description are
|
||||
// owned and deleted by the run manager, so they should not
|
||||
// be deleted in the main() program !
|
||||
|
||||
delete visManager;
|
||||
delete ui;
|
||||
delete runManager;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
# examplePar04.mac
|
||||
#
|
||||
/control/execute common_settings.mac
|
||||
/control/execute common_settings_lowgran.mac
|
||||
|
||||
# Overwrite the sensitivity of the absorber to account for the passive material
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm false
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Full Simulation
|
||||
/analysis/setFileName 10GeV_100events_fullsim.root
|
||||
|
||||
@@ -11,7 +11,7 @@ Environment variable "G4FORCE_RUN_MANAGER_TYPE" enabled with value == Serial. Fo
|
||||
|
||||
|
||||
**************************************************************
|
||||
Geant4 version Name: geant4-11-03-patch-02 (25-April-2025)
|
||||
Geant4 version Name: geant4-11-03-ref-06 (30-June-2025)
|
||||
Copyright : Geant4 Collaboration
|
||||
References : NIM A 506 (2003), 250-303
|
||||
: IEEE-TNS 53 (2006), 270-278
|
||||
@@ -21,76 +21,6 @@ Environment variable "G4FORCE_RUN_MANAGER_TYPE" enabled with value == Serial. Fo
|
||||
|
||||
<<< Geant4 Physics List simulation engine: FTFP_BERT
|
||||
|
||||
Instantiating Visualization Manager.......
|
||||
Visualization Manager instantiating with verbosity "warnings (3)"...
|
||||
Visualization Manager initialising...
|
||||
Registering graphics systems...
|
||||
|
||||
You have successfully registered the following graphics systems.
|
||||
Registered graphics systems are:
|
||||
ASCIITree (ATree)
|
||||
DAWNFILE (DAWNFILE)
|
||||
G4HepRepFile (HepRepFile)
|
||||
RayTracer (RayTracer)
|
||||
VRML2FILE (VRML2FILE)
|
||||
gMocrenFile (gMocrenFile)
|
||||
TOOLSSG_OFFSCREEN (TSG_OFFSCREEN, TSG_FILE)
|
||||
OpenGLImmediateQt (OGLIQt, OGLI)
|
||||
OpenGLStoredQt (OGLSQt, OGL, OGLS)
|
||||
OpenGLImmediateXm (OGLIXm, OGLIQt_FALLBACK)
|
||||
OpenGLStoredXm (OGLSXm, OGLSQt_FALLBACK)
|
||||
OpenGLImmediateX (OGLIX, OGLIQt_FALLBACK, OGLIXm_FALLBACK)
|
||||
OpenGLStoredX (OGLSX, OGLSQt_FALLBACK, OGLSXm_FALLBACK)
|
||||
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)
|
||||
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...
|
||||
|
||||
You have successfully registered the following model factories.
|
||||
Registered model factories:
|
||||
generic
|
||||
drawByAttribute
|
||||
drawByCharge
|
||||
drawByOriginVolume
|
||||
drawByParticleID
|
||||
drawByEncounteredVolume
|
||||
|
||||
Registered models:
|
||||
None
|
||||
|
||||
Registered filter factories:
|
||||
attributeFilter
|
||||
chargeFilter
|
||||
originVolumeFilter
|
||||
particleFilter
|
||||
encounteredVolumeFilter
|
||||
|
||||
Registered filters:
|
||||
None
|
||||
|
||||
You have successfully registered the following user vis actions.
|
||||
Run Duration User Vis Actions: none
|
||||
End of Event User Vis Actions: none
|
||||
End of Run User Vis Actions: none
|
||||
|
||||
Some /vis commands (optionally) take a string to specify colour.
|
||||
"/vis/list" to see available colours.
|
||||
|
||||
------------------------------------------------------
|
||||
--- Detector length: 2 m
|
||||
@@ -162,5 +92,3 @@ Setting was ignored.
|
||||
*** This is just a warning message. ***
|
||||
-------- WWWW -------- G4Exception-END --------- WWWW -------
|
||||
|
||||
Graphics systems deleted.
|
||||
Visualization Manager deleting...
|
||||
|
||||
+7
-3
@@ -1,6 +1,10 @@
|
||||
# examplePar04_lwtnn.mac
|
||||
# examplePar04_lwtnn_vae.mac
|
||||
#
|
||||
/control/execute common_settings.mac
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
@@ -19,7 +23,7 @@
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
# Fast Simulation
|
||||
/analysis/setFileName 10GeV_100events_fastsim_lwtnn.root
|
||||
/analysis/setFileName 10GeV_100events_vae_lwtnn.root
|
||||
## dynamically set readout mesh from particle direction
|
||||
## needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
@@ -0,0 +1,42 @@
|
||||
# examplePar04_onnx_calodit.mac
|
||||
#
|
||||
/control/execute common_settings_lowgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Inference Setup
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/cd.onnx
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType CaloDiT-2
|
||||
/Par04/inference/setProfileFlag 0
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
## cuda flag
|
||||
/Par04/inference/setCudaFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 4.65 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 9
|
||||
/Par04/inference/setNbOfPhiCells 16
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
# cuda options
|
||||
/Par04/inference/cuda/setDeviceId 0
|
||||
/Par04/inference/cuda/setGpuMemLimit 2147483648
|
||||
/Par04/inference/cuda/setArenaExtendedStrategy kSameAsRequested
|
||||
/Par04/inference/cuda/setCudnnConvAlgoSearch DEFAULT
|
||||
/Par04/inference/cuda/setDoCopyInDefaultStream 1
|
||||
/Par04/inference/cuda/setCudnnConvUseMaxWorkspace 1
|
||||
|
||||
# Fast Simulation
|
||||
/analysis/setFileName 10GeV_100events_calodit_onnx.root
|
||||
## dynamically set readout mesh from particle direction
|
||||
## needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 100
|
||||
+10
-4
@@ -1,6 +1,10 @@
|
||||
# examplePar04_onnx.mac
|
||||
# examplePar04_onnx_vae.mac
|
||||
#
|
||||
/control/execute common_settings.mac
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
@@ -9,7 +13,9 @@
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx
|
||||
/Par04/inference/setProfileFlag 1
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType VAE
|
||||
/Par04/inference/setProfileFlag 0
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
## cuda flag
|
||||
/Par04/inference/setCudaFlag 0
|
||||
@@ -31,7 +37,7 @@
|
||||
/Par04/inference/cuda/setCudnnConvUseMaxWorkspace 1
|
||||
|
||||
# Fast Simulation
|
||||
/analysis/setFileName 10GeV_100events_fastsim_onnx.root
|
||||
/analysis/setFileName 10GeV_100events_vae_onnx.root
|
||||
## dynamically set readout mesh from particle direction
|
||||
## needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
@@ -0,0 +1,31 @@
|
||||
# examplePar04_torch_calodit.mac
|
||||
#
|
||||
|
||||
/control/execute common_settings_lowgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Inference Setup
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/cd_cpu.pt
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType CaloDiT-2
|
||||
/Par04/inference/setInferenceLibrary TORCH
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 4.65 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 9
|
||||
/Par04/inference/setNbOfPhiCells 16
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
# Fast Simulation
|
||||
/analysis/setFileName 10GeV_100events_calodit_torch.root
|
||||
## dynamically set readout mesh from particle direction
|
||||
## needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 100
|
||||
+9
-3
@@ -1,7 +1,11 @@
|
||||
# examplePar04_torch.mac
|
||||
# examplePar04_torch_vae.mac
|
||||
#
|
||||
|
||||
/control/execute common_settings.mac
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
@@ -10,6 +14,8 @@
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.pt
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType VAE
|
||||
/Par04/inference/setInferenceLibrary TORCH
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
@@ -20,7 +26,7 @@
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
# Fast Simulation
|
||||
/analysis/setFileName 10GeV_100events_fastsim_libtorch.root
|
||||
/analysis/setFileName 10GeV_100events_vae_torch.root
|
||||
## dynamically set readout mesh from particle direction
|
||||
## needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
@@ -70,6 +70,8 @@ class Par04InferenceMessenger : public G4UImessenger
|
||||
G4UIcmdWithAString* fInferenceLibraryCmd = nullptr;
|
||||
/// Command to set fModelPathNameCmd
|
||||
G4UIcmdWithAString* fModelPathNameCmd = nullptr;
|
||||
/// Command to set fModelTypeCmd
|
||||
G4UIcmdWithAString *fModelTypeCmd = nullptr;
|
||||
/// Command to set the fSizeLatentVectorCmd
|
||||
G4UIcmdWithAnInteger* fSizeLatentVectorCmd = nullptr;
|
||||
/// Command to set the fSizeConditionVectorCmd
|
||||
|
||||
@@ -93,6 +93,10 @@ class Par04InferenceSetup
|
||||
inline void SetModelPathName(G4String aName) { fModelPathName = aName; };
|
||||
/// Get path and name of the model
|
||||
inline G4String GetModelPathName() const { return fModelPathName; };
|
||||
/// Set model type
|
||||
inline void SetModelType(G4String aName) { fModelType = aName; };
|
||||
/// Get model type
|
||||
inline G4String GetModelType() const { return fModelType; };
|
||||
/// Set profiling flag
|
||||
inline void SetProfileFlag(G4int aNumber) { fProfileFlag = aNumber; };
|
||||
/// Get profiling flag
|
||||
@@ -161,7 +165,7 @@ class Par04InferenceSetup
|
||||
/// detector
|
||||
/// @param[in] aParticleEnergy Energy of initial particle
|
||||
void GetEnergies(std::vector<G4double>& aEnergies, G4double aParticleEnergy,
|
||||
G4float aInitialAngle);
|
||||
G4float aTheta, G4float aPhi);
|
||||
|
||||
/// Calculate positions
|
||||
/// @param[out] aDepositsPositions Vector of positions corresponding to
|
||||
@@ -200,6 +204,8 @@ class Par04InferenceSetup
|
||||
G4int fSizeConditionVector = 4;
|
||||
/// Name of the inference library
|
||||
G4String fModelPathName = "MLModels/Generator.onnx";
|
||||
/// Model type
|
||||
G4String fModelType = "VAE";
|
||||
/// ONNX specific
|
||||
/// Profiling flag
|
||||
G4bool fProfileFlag = false;
|
||||
|
||||
@@ -28,15 +28,14 @@
|
||||
# ifndef PAR04ONNXINFERENCE_HH
|
||||
# define PAR04ONNXINFERENCE_HH
|
||||
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
|
||||
# include "core/session/onnxruntime_cxx_api.h" // for Env, Session, SessionO...
|
||||
# include "onnxruntime_c_api.h" // for OrtMemoryInfo
|
||||
# include "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.
|
||||
*
|
||||
|
||||
@@ -104,7 +104,7 @@ int Par04Hit::operator==(const Par04Hit& aRight) const
|
||||
void Par04Hit::Draw()
|
||||
{
|
||||
/// Arbitrary size corresponds to the example macros
|
||||
G4ThreeVector meshSize(2.325 * mm, 2 * CLHEP::pi / 50. * CLHEP::rad, 3.4 * mm);
|
||||
G4ThreeVector meshSize(4.65 * mm, 2 * CLHEP::pi / 18. * CLHEP::rad, 3.4 * mm);
|
||||
G4int numPhiCells = CLHEP::pi * 2. / meshSize.y();
|
||||
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
||||
// Hits can be filtered out in visualisation
|
||||
@@ -166,7 +166,7 @@ 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;
|
||||
G4cout << "\tHit " << fEdep / MeV << " MeV from " << fNdep << " deposits at " << fPos / cm
|
||||
<< " cm with rotation " << fRot << " (R,phi,z)= (" << fRhoId << ", " << fPhiId << ", "
|
||||
<< fZId << "), " << fTime << " ns" << G4endl;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,12 @@ Par04InferenceMessenger::Par04InferenceMessenger(Par04InferenceSetup* aInference
|
||||
fModelPathNameCmd->AvailableForStates(G4State_Idle);
|
||||
fModelPathNameCmd->SetToBeBroadcasted(true);
|
||||
|
||||
fModelTypeCmd = new G4UIcmdWithAString("/Par04/inference/setModelType", this);
|
||||
fModelTypeCmd->SetGuidance("Model type");
|
||||
fModelTypeCmd->SetParameterName("Name", false);
|
||||
fModelTypeCmd->AvailableForStates(G4State_Idle);
|
||||
fModelTypeCmd->SetToBeBroadcasted(true);
|
||||
|
||||
fProfileFlagCmd = new G4UIcmdWithAnInteger("/Par04/inference/setProfileFlag", this);
|
||||
fProfileFlagCmd->SetGuidance("Flag to save a json file for model execution profiling.");
|
||||
fProfileFlagCmd->SetParameterName("ProfileFlag", false);
|
||||
@@ -193,6 +199,7 @@ Par04InferenceMessenger::~Par04InferenceMessenger()
|
||||
delete fSizeLatentVectorCmd;
|
||||
delete fSizeConditionVectorCmd;
|
||||
delete fModelPathNameCmd;
|
||||
delete fModelTypeCmd;
|
||||
delete fProfileFlagCmd;
|
||||
delete fOptimizationFlagCmd;
|
||||
delete fMeshNbRhoCellsCmd;
|
||||
@@ -218,6 +225,9 @@ void Par04InferenceMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewVa
|
||||
if (aCommand == fModelPathNameCmd) {
|
||||
fInference->SetModelPathName(aNewValue);
|
||||
}
|
||||
if (aCommand == fModelTypeCmd) {
|
||||
fInference->SetModelType(aNewValue);
|
||||
}
|
||||
if (aCommand == fProfileFlagCmd) {
|
||||
fInference->SetProfileFlag(std::stoi(aNewValue));
|
||||
}
|
||||
@@ -284,6 +294,9 @@ G4String Par04InferenceMessenger::GetCurrentValue(G4UIcommand* aCommand)
|
||||
if (aCommand == fModelPathNameCmd) {
|
||||
cv = fModelPathNameCmd->ConvertToString(fInference->GetModelPathName());
|
||||
}
|
||||
if (aCommand == fModelTypeCmd) {
|
||||
cv = fModelTypeCmd->ConvertToString(fInference->GetModelType());
|
||||
}
|
||||
if (aCommand == fProfileFlagCmd) {
|
||||
cv = fSizeLatentVectorCmd->ConvertToString(fInference->GetProfileFlag());
|
||||
}
|
||||
|
||||
@@ -119,15 +119,19 @@ void Par04InferenceSetup::CheckInferenceLibrary()
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void Par04InferenceSetup::GetEnergies(std::vector<G4double>& aEnergies, G4double aInitialEnergy,
|
||||
G4float aInitialAngle)
|
||||
G4float aTheta, G4float aPhi)
|
||||
{
|
||||
// First check if inference library was set correctly
|
||||
CheckInferenceLibrary();
|
||||
// size represents the size of the output vector
|
||||
int size = fMeshNumber.x() * fMeshNumber.y() * fMeshNumber.z();
|
||||
std::vector<G4float> genVector;
|
||||
|
||||
if (fModelType == "VAE")
|
||||
{
|
||||
genVector.assign(fSizeLatentVector + fSizeConditionVector, 0);
|
||||
|
||||
// randomly sample from a gaussian distribution in the latent space
|
||||
std::vector<G4float> genVector(fSizeLatentVector + fSizeConditionVector, 0);
|
||||
for (int i = 0; i < fSizeLatentVector; ++i) {
|
||||
genVector[i] = CLHEP::RandGauss::shoot(0., 1.);
|
||||
}
|
||||
@@ -144,18 +148,49 @@ void Par04InferenceSetup::GetEnergies(std::vector<G4double>& aEnergies, G4double
|
||||
// 1. energy
|
||||
genVector[fSizeLatentVector] = aInitialEnergy / fMaxEnergy;
|
||||
// 2. angle
|
||||
genVector[fSizeLatentVector + 1] = (aInitialAngle / (CLHEP::deg)) / fMaxAngle;
|
||||
genVector[fSizeLatentVector + 1] = (aTheta / (CLHEP::deg)) / fMaxAngle;
|
||||
// 3. geometry
|
||||
genVector[fSizeLatentVector + 2] = 0;
|
||||
genVector[fSizeLatentVector + 3] = 1;
|
||||
} else if (fModelType == "CaloDiT-2")
|
||||
{
|
||||
// fSizeLatentVector & fSizeConditionVector are ignored for CaloDiT-2
|
||||
// Conditions (dim) are energy (1), phi (1), theta (1) and geo (5)
|
||||
// The energy range here is 1 GeV - 1TeV, phi goes from 0 to 2pi,
|
||||
// and theta goes from 0.87 to 2.27.
|
||||
// And, geo is one-hot encoding describing the 4 geometries the model
|
||||
// is trained on.
|
||||
// Order of the geo condition is Par04SiW (this one), Par04SciPb, ODD, FCCeeCLD
|
||||
// As CaloDiT-2 is trained on these 4 detectors, it can be quickly adapted to
|
||||
// any new detector (see CaloDiT-2 readme for adaptation) of your choice. Thus
|
||||
// reusing the knowledge from these previous detectors.
|
||||
// To use the adapted model, make the following changes for inference:
|
||||
// genVector[3] = 0.0; (turning OFF Par04SiW)
|
||||
// genVector[7] = 1.0; (turning ON a new detector)
|
||||
genVector.assign(8, 0);
|
||||
|
||||
genVector[0] = aInitialEnergy / 1000; // convert to GeV
|
||||
genVector[1] = aPhi;
|
||||
genVector[2] = aTheta;
|
||||
genVector[3] = 1.0; //Par04SiW
|
||||
}
|
||||
// Run the inference
|
||||
fInferenceInterface->RunInference(genVector, aEnergies, size);
|
||||
|
||||
// After the inference rescale back to the initial energy (in this example the
|
||||
// energies of cells were normalized to the energy of the particle)
|
||||
// After the inference rescale back to the initial energy
|
||||
|
||||
if (fModelType == "VAE")
|
||||
// For VAE, energies of cells were normalized to the energy of the particle
|
||||
{
|
||||
for (int i = 0; i < size; ++i) {
|
||||
aEnergies[i] = aEnergies[i] * aInitialEnergy;
|
||||
}
|
||||
} else if (fModelType == "CaloDiT-2")
|
||||
// For CaloDiT-2, energies were scaled by a factor of 1000
|
||||
{
|
||||
for (int i = 0; i < size; ++i){
|
||||
aEnergies[i] = aEnergies[i] * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,18 +90,19 @@ void Par04MLFastSimModel::DoIt(const G4FastTrack& aFastTrack, G4FastStep& aFastS
|
||||
{
|
||||
// remove particle from further processing by G4
|
||||
aFastStep.KillPrimaryTrack();
|
||||
aFastStep.SetPrimaryTrackPathLength(0.0);
|
||||
aFastStep.ProposePrimaryTrackPathLength(0.);
|
||||
G4double energy = aFastTrack.GetPrimaryTrack()->GetKineticEnergy();
|
||||
aFastStep.SetTotalEnergyDeposited(energy);
|
||||
aFastStep.ProposeTotalEnergyDeposited(energy);
|
||||
G4ThreeVector position = aFastTrack.GetPrimaryTrack()->GetPosition();
|
||||
G4ThreeVector direction = aFastTrack.GetPrimaryTrack()->GetMomentumDirection();
|
||||
|
||||
// calculate the incident angle
|
||||
G4float angle = direction.theta();
|
||||
// calculate the incident angles
|
||||
G4float theta = direction.theta();
|
||||
G4float phi = direction.phi();
|
||||
|
||||
// calculate how to deposit energy within the detector
|
||||
// get it from inference model
|
||||
fInference->GetEnergies(fEnergies, energy, angle);
|
||||
fInference->GetEnergies(fEnergies, energy, theta, phi);
|
||||
fInference->GetPositions(fPositions, position, direction);
|
||||
|
||||
// deposit energy in the detector using calculated values of energy deposits
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
|
||||
# include "Par04InferenceInterface.hh" // for Par04InferenceInterface
|
||||
|
||||
# include <onnxruntime_cxx_api.h> // for Value, Session, Env
|
||||
# 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
|
||||
|
||||
@@ -48,35 +48,44 @@ Par04TorchInference::Par04TorchInference(G4String modelPath) : Par04InferenceInt
|
||||
void Par04TorchInference::RunInference(std::vector<float> aGenVector,
|
||||
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++) {
|
||||
latent.push_back(aGenVector[i]);
|
||||
}
|
||||
std::vector<float> energy;
|
||||
energy.push_back(aGenVector[latentSize + 1]);
|
||||
std::vector<float> angle;
|
||||
energy.push_back(aGenVector[latentSize + 2]);
|
||||
std::vector<float> geo;
|
||||
for (int i = latentSize + 2; i < latentSize + 4; i++) {
|
||||
geo.push_back(aGenVector[i]);
|
||||
}
|
||||
|
||||
// convert vectors to tensors
|
||||
torch::Tensor latentVector = torch::tensor(latent);
|
||||
torch::Tensor eTensor = torch::tensor(energy);
|
||||
torch::Tensor angleTensor = torch::tensor(angle);
|
||||
torch::Tensor geoTensor = torch::tensor(geo);
|
||||
|
||||
std::vector<torch::jit::IValue> genInput;
|
||||
|
||||
genInput.push_back(latentVector);
|
||||
genInput.push_back(eTensor);
|
||||
genInput.push_back(angleTensor);
|
||||
genInput.push_back(geoTensor);
|
||||
if (aGenVector.size()!=8) {
|
||||
// VAE
|
||||
// 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++) {
|
||||
latent.push_back(aGenVector[i]);
|
||||
}
|
||||
std::vector<float> energy;
|
||||
energy.push_back(aGenVector[latentSize + 1]);
|
||||
std::vector<float> angle;
|
||||
angle.push_back(aGenVector[latentSize + 2]);
|
||||
std::vector<float> geo;
|
||||
for (int i = latentSize + 2; i < latentSize + 4; i++) {
|
||||
geo.push_back(aGenVector[i]);
|
||||
}
|
||||
|
||||
// convert vectors to tensors
|
||||
torch::Tensor latentVector = torch::tensor(latent);
|
||||
torch::Tensor eTensor = torch::tensor(energy);
|
||||
torch::Tensor angleTensor = torch::tensor(angle);
|
||||
torch::Tensor geoTensor = torch::tensor(geo);
|
||||
|
||||
genInput.push_back(latentVector);
|
||||
genInput.push_back(eTensor);
|
||||
genInput.push_back(angleTensor);
|
||||
genInput.push_back(geoTensor);
|
||||
} else {
|
||||
// CaloDiT-2
|
||||
torch::Tensor conditions = torch::tensor(aGenVector);
|
||||
genInput.push_back(conditions);
|
||||
}
|
||||
// equivalent to torch.no_grad()
|
||||
torch::NoGradGuard no_grad;
|
||||
|
||||
at::Tensor outTensor = fModule.forward(genInput).toTensor().contiguous();
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
tensorflow==2.12.1
|
||||
numpy==1.23.1
|
||||
h5py==3.7.0
|
||||
matplotlib==3.5.2
|
||||
optuna==2.10.1
|
||||
mysqlclient==2.1.1
|
||||
pymysql==1.1.1
|
||||
scikit-learn==1.5.0
|
||||
scipy==1.11.1
|
||||
wandb==0.13.1
|
||||
tf2onnx==1.12.0
|
||||
onnxruntime==1.12.1
|
||||
@@ -0,0 +1,13 @@
|
||||
## CaloDiT-2
|
||||
|
||||
CaloDiT-2 is transformer-based diffusion model, which can be easily adapted to a new detector geometry.
|
||||
This Par04 repository contains the ONNX and TorchScript versions of the model and how to use them for
|
||||
Par04-SiW detector. *Note that the virtual cylindrical mesh is less granular than VAE.*
|
||||
|
||||
The source code for CaloDiT-2 can be found [here](https://gitlab.cern.ch/fastsim/diffusion4sim/-/tree/CaloDiT_v1?ref_type=tags).
|
||||
It contains the training, adaptation, and distillation scripts along with the pretrained models. You can download the
|
||||
pretrained models (not the .onnx/.pt files available with this repository), which acts as a checkpoint and finetune
|
||||
it on the new dataset.
|
||||
|
||||
You can also modify the virtual mesh size and hence the architecture if needed. But in that case, you won't be able
|
||||
to use the pretrained models. Pretrained models adopt a mesh as in [CaloChallenge Dataset-2](https://calochallenge.github.io/homepage/).
|
||||
+6
-2
@@ -1,7 +1,8 @@
|
||||
This repository contains the set of scripts used to train, generate and validate the generative model used
|
||||
in this example.
|
||||
|
||||
- root2h5.py: translation of ROOT file with showers to h5 files.
|
||||
- root2h5_for_vae.py: translation of ROOT file with showers to h5 files usable in the VAE model.
|
||||
- root2h5.py: translation of ROOT file with showers to h5 files, more general version (recommended). It allows to simulate non-discrete energies and stores showers in 3D tensors (R x phi x z).
|
||||
- core/constants.py: defines the set of common variables.
|
||||
- core/model.py: defines the VAE model class and a handler to construct the model.
|
||||
- utils/preprocess.py: defines the data loading and preprocessing functions.
|
||||
@@ -28,7 +29,7 @@ python3 setup.py
|
||||
|
||||
The full simulation dataset can be downloaded from/linked to [Zenodo](https://zenodo.org/record/6082201#.Ypo5UeDRaL4).
|
||||
|
||||
If custom simulation is used, the output of full simulation must be translated to h5 files using `root2h5.py` script. Please see the header of that script to see what name of the root file is expected.
|
||||
If custom simulation is used, the output of full simulation must be translated to h5 files using `root2h5_for_vae.py` script. This file is recommended for use with the provided VAE model. For all other usecases script `root2h5.py` is recommended, as it does not assume that simulation is run with discrete energies (e.g. GPS can be used within Geant4 simulation instead of the particle gun).
|
||||
|
||||
## Training
|
||||
|
||||
@@ -50,6 +51,9 @@ training.
|
||||
```--study-name``` specifies a study name. This name is used as an experiment name in W&B dashboard and as a name of
|
||||
directory for saving models.
|
||||
|
||||
See ```run.sh``` and ```condor.sub``` for training on HTCondor.
|
||||
Note: wandb api key is hardcoded and needs to be added manually in order to log stats to weights and biases.
|
||||
|
||||
## Hyperparameters tuning
|
||||
|
||||
If you want to tune hyperparameters, specify in `tune_model.py` parameters to be tuned. There are three types of
|
||||
@@ -0,0 +1,12 @@
|
||||
executable = run.sh
|
||||
arguments = test par04_check 0 $(ClusterID) $(ProcId)
|
||||
output = output/test.$(ClusterID).$(ProcId).txt
|
||||
error = error/test.$(ClusterID).$(ProcId).txt
|
||||
log = log/test.$(ClusterID).$(ProcId).txt
|
||||
requirements = (OpSysAndVer =?= "AlmaLinux9")
|
||||
+JobFlavour = "workday"
|
||||
request_gpus = 1
|
||||
request_cpus = 16
|
||||
requirements = TARGET.GPUs_DeviceName =?= "NVIDIA A100-PCIE-40GB"
|
||||
queue 1
|
||||
|
||||
+2
-2
@@ -16,14 +16,14 @@ SIZE_Z = 3.4
|
||||
MIN_ENERGY = 1
|
||||
MAX_ENERGY = 1024
|
||||
# Minimum and maximum primary particle angle to consider for training in degrees units.
|
||||
MIN_ANGLE = 50
|
||||
MIN_ANGLE = 90
|
||||
MAX_ANGLE = 90
|
||||
|
||||
"""
|
||||
Directories.
|
||||
"""
|
||||
# Directory to load the full simulation dataset.
|
||||
INIT_DIR = "./dataset/"
|
||||
INIT_DIR = "/eos/geant4/fastSim/Par04_public/HDF5_Zenodo/"
|
||||
# Directory to save VAE checkpoints
|
||||
GLOBAL_CHECKPOINT_DIR = "./checkpoint"
|
||||
# Directory to save model after conversion to a format that can be used in C++.
|
||||
+23
-19
@@ -10,6 +10,7 @@ from tensorflow.keras import backend as K
|
||||
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, History, Callback
|
||||
from tensorflow.keras.layers import BatchNormalization, Input, Dense, Layer, concatenate
|
||||
from tensorflow.keras.losses import BinaryCrossentropy, Reduction
|
||||
from tensorflow.keras.utils import Sequence
|
||||
from tensorflow.keras.models import Model
|
||||
from tensorflow.python.data import Dataset
|
||||
from tensorflow.python.distribute.distribute_lib import Strategy
|
||||
@@ -47,6 +48,22 @@ class _KLDivergenceLayer(Layer):
|
||||
return inputs
|
||||
|
||||
|
||||
class DataGenerator(Sequence):
|
||||
def __init__(self, x_set, y_set, batch_size):
|
||||
self.x, self.y = x_set, y_set
|
||||
self.batch_size = batch_size
|
||||
|
||||
def __len__(self):
|
||||
return int(np.ceil(len(self.x[0]) / float(self.batch_size))) # x[0] for actual showers
|
||||
|
||||
def __getitem__(self, idx):
|
||||
batch_x = []
|
||||
for i in range(len(self.x)):
|
||||
batch_x.append(self.x[i][idx * self.batch_size:(idx + 1) * self.batch_size])
|
||||
batch_y = self.y[idx * self.batch_size:(idx + 1) * self.batch_size]
|
||||
return tuple(batch_x), batch_y
|
||||
|
||||
|
||||
class VAE(Model):
|
||||
def get_config(self):
|
||||
config = super().get_config()
|
||||
@@ -72,6 +89,7 @@ class VAEHandler:
|
||||
Class to handle building and training VAE models.
|
||||
"""
|
||||
_wandb_project_name: str = None
|
||||
_wandb_run_name: str = None
|
||||
_wandb_tags: List[str] = field(default_factory=list)
|
||||
_original_dim: int = ORIGINAL_DIM
|
||||
latent_dim: int = LATENT_DIM
|
||||
@@ -114,7 +132,7 @@ class VAEHandler:
|
||||
}
|
||||
# Reinit flag is needed for hyperparameter tuning. Whenever new training is started, new Wandb run should be
|
||||
# created.
|
||||
wandb.init(project=self._wandb_project_name, entity=WANDB_ENTITY, reinit=True, config=config,
|
||||
wandb.init(name=self._wandb_run_name, project=self._wandb_project_name, entity=WANDB_ENTITY, reinit=True, config=config,
|
||||
tags=self._wandb_tags)
|
||||
|
||||
def _build_and_compile_new_model(self) -> None:
|
||||
@@ -257,6 +275,7 @@ class VAEHandler:
|
||||
-> Tuple[Dataset, Dataset]:
|
||||
"""
|
||||
Splits data into train and validation set based on given lists of indexes.
|
||||
Load batches to the GPU instead of entire dataset.
|
||||
|
||||
"""
|
||||
|
||||
@@ -280,24 +299,9 @@ class VAEHandler:
|
||||
val_x = (val_dataset, val_e_cond, val_angle_cond, val_geo_cond, val_noise)
|
||||
val_y = val_dataset
|
||||
|
||||
# Wrap data in Dataset objects.
|
||||
# TODO(@mdragula): This approach requires loading the whole data set to RAM. It
|
||||
# would be better to read the data partially when needed. Also one should bare in mind that using tf.Dataset
|
||||
# slows down training process.
|
||||
train_data = Dataset.from_tensor_slices((train_x, train_y))
|
||||
val_data = Dataset.from_tensor_slices((val_x, val_y))
|
||||
|
||||
# The batch size must now be set on the Dataset objects.
|
||||
train_data = train_data.batch(self._batch_size)
|
||||
val_data = val_data.batch(self._batch_size)
|
||||
|
||||
# Disable AutoShard.
|
||||
options = tf.data.Options()
|
||||
options.experimental_distribute.auto_shard_policy = tf.data.experimental.AutoShardPolicy.DATA
|
||||
train_data = train_data.with_options(options)
|
||||
val_data = val_data.with_options(options)
|
||||
|
||||
return train_data, val_data
|
||||
train_gen = DataGenerator(train_x, train_y, self._batch_size)
|
||||
val_gen = DataGenerator(val_x, val_y, self._batch_size)
|
||||
return train_gen, val_gen
|
||||
|
||||
def _k_fold_training(self, dataset: np.array, e_cond: np.array, angle_cond: np.array, geo_cond: np.array,
|
||||
noise: np.array, callbacks: List[Callback], verbose: bool = True) -> List[History]:
|
||||
@@ -0,0 +1,15 @@
|
||||
tensorflow==2.12.1
|
||||
tensorflow-probability==0.17.0
|
||||
keras==2.9.0
|
||||
numpy==1.23.5
|
||||
h5py==3.7.0
|
||||
matplotlib==3.5.2
|
||||
scikit-learn==1.1.1
|
||||
scipy==1.9.0
|
||||
wandb==0.13.1
|
||||
tf2onnx==1.14.0
|
||||
onnxruntime==1.16.3
|
||||
gast==0.4.0
|
||||
lz4==3.1
|
||||
idna==2.10
|
||||
protobuf==3.19
|
||||
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Converts an EDM4HEP ROOT file to an HDF5 file, saving the shower energy in a 3D array and shower data in a 2D array.
|
||||
Units: Energy values are stored in MeV and angles are stored in radians.
|
||||
|
||||
"""
|
||||
|
||||
#!/bin/env python
|
||||
import sys
|
||||
import argparse
|
||||
import numpy as np
|
||||
import os
|
||||
import uproot
|
||||
import h5py
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--outputDir", '-o', type=str, default="./", help="Path to the output directory")
|
||||
p.add_argument("--inputFile", '-i', type=str, required=True, help="Name of the EDM4hep file to translate")
|
||||
p.add_argument("--numR", type=int, default=18, help="Number of cells in R")
|
||||
p.add_argument("--numPhi", type=int, default=50, help="Number of cells in phi")
|
||||
p.add_argument("--numZ", type=int, default=45, help="Number of cells in z")
|
||||
p.add_argument("--samplingFraction", type=float, default=1., help="Sampling fraction to use to rescale cell energy. Defined as f=active/(active+absorber)")
|
||||
args = p.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def main(argv):
|
||||
# Parse commandline arguments
|
||||
args = parse_args(argv)
|
||||
input_file = args.inputFile
|
||||
output_dir = args.outputDir
|
||||
|
||||
# Number of cells in the r, phi & z directions
|
||||
num_cells_R = args.numR
|
||||
num_cells_phi = args.numPhi
|
||||
num_cells_z = args.numZ
|
||||
|
||||
# Sampling fraction that rescales energy of each cell
|
||||
sampling_fraction = args.samplingFraction
|
||||
|
||||
if os.stat(input_file).st_size > 0:
|
||||
h5_file = h5py.File(
|
||||
f"{output_dir}/{os.path.splitext(os.path.basename(input_file))[0]}.h5", "w"
|
||||
)
|
||||
print(f"Creating output file {output_dir}/{os.path.splitext(os.path.basename(input_file))[0]}.h5")
|
||||
# Read Root file
|
||||
file = uproot.open(input_file)
|
||||
energy_particle = file["global"]["EnergyMC"].array()
|
||||
# For future once theta,phi are implemented in Par04 event/run action
|
||||
#phi_particle = file["global"]["PhiMC"].array()
|
||||
#theta_particle = file["global"]["ThetaMC"].array()
|
||||
cell_r = file["virtualReadout"]["rhoCell"].array()
|
||||
cell_phi = file["virtualReadout"]["phiCell"].array()
|
||||
cell_energy = file["virtualReadout"]["EnergyCell"].array()
|
||||
cell_z = file["virtualReadout"]["zCell"].array()
|
||||
all_events = []
|
||||
num_showers = len(energy_particle)
|
||||
# loop over events
|
||||
for event in range(num_showers):
|
||||
# Initialize a 3D array with shape nb_events, nb_cells in x,y,z (rho,phi,z)
|
||||
shower = np.zeros((num_cells_R, num_cells_phi, num_cells_z))
|
||||
for cell in range(len(cell_r[event])):
|
||||
# This if statement is added to avoid having cells outside of desired cylinder size
|
||||
if (
|
||||
(cell_r[event][cell] < num_cells_R)
|
||||
and (cell_phi[event][cell] < num_cells_phi)
|
||||
and (cell_z[event][cell] < num_cells_z)
|
||||
):
|
||||
shower[cell_r[event][cell]][cell_phi[event][cell]][
|
||||
cell_z[event][cell]
|
||||
] = cell_energy[event][cell]
|
||||
all_events.append(shower)
|
||||
# Save dataset
|
||||
print(f"Creating datasets with shape {np.shape(energy_particle)} and {np.shape(all_events)} ")
|
||||
h5_file.create_dataset("incident_energy", data=energy_particle, compression="gzip", compression_opts=9,)
|
||||
# For future once theta,phi are implemented in Par04 event/run action
|
||||
#h5_file.create_dataset("incident_phi", data=phi_particle, compression="gzip", compression_opts=9,)
|
||||
#h5_file.create_dataset("incident_theta", data=theta_particle, compression="gzip", compression_opts=9,)
|
||||
h5_file.create_dataset("showers", data=all_events, compression="gzip", compression_opts=9,)
|
||||
h5_file.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main(sys.argv[1:]))
|
||||
+9
-3
@@ -72,7 +72,7 @@ def main(argv):
|
||||
h5_file = h5py.File(
|
||||
f"{output_dir}/{energy_particle}_Angle_{angle_particle}_{num_showers}showers_{file_id}.h5", "w"
|
||||
)
|
||||
# Read the Root file
|
||||
# Read Root file
|
||||
file = uproot.open(file_name)
|
||||
energy_particle = file["global"]["EnergyMC"].array()
|
||||
cell_r = file["virtualReadout"]["rhoCell"].array()
|
||||
@@ -95,14 +95,20 @@ def main(argv):
|
||||
cell_z[event][ind]
|
||||
] = cell_energy[event][ind]
|
||||
all_events.append(data)
|
||||
# Save dataset
|
||||
# first check if we indeed have only single E
|
||||
if len(np.unique(np.array(energy_particle))) > 1:
|
||||
print("ERROR: provided list of energies contains more than one incident energy")
|
||||
exit(-1)
|
||||
# Save dataset with Energy MC in GeV
|
||||
h5_file.create_dataset(
|
||||
f"{energy_particle}",
|
||||
f"{int(np.unique(np.array(energy_particle))[0]/1000)}",
|
||||
data=all_events,
|
||||
compression="gzip",
|
||||
compression_opts=9,
|
||||
)
|
||||
h5_file.close()
|
||||
print(f"Created a dataset for incident angle {angle_particle} with energy (and a dataset key)\
|
||||
{int(np.unique(np.array(energy_particle))[0]/1000)} GeV with a shape {np.shape(all_events)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
## To be run with 3 arguments defining the run name and the study name for wandb, and gpu_id
|
||||
|
||||
source /cvmfs/sft.cern.ch/lcg/views/LCG_105_cuda/x86_64-el9-gcc11-opt/setup.sh
|
||||
|
||||
nvidia-smi
|
||||
|
||||
pip install numpy h5py matplotlib scipy scikit-learn wandb tf2onnx onnxruntime
|
||||
|
||||
## Provide your wandb api key here
|
||||
export WANDB_API_KEY=<WANDB-API-KEY>
|
||||
|
||||
mkdir -p validation checkpoint conversion generation
|
||||
python /afs/cern.ch/user/p/praikwar/public/par04/training/train.py --run-name $1 --study-name $2 --gpu-ids $3
|
||||
|
||||
+5
-2
@@ -10,6 +10,7 @@ def parse_args():
|
||||
argument_parser.add_argument("--max-gpu-memory-allocation", type=int, default=MAX_GPU_MEMORY_ALLOCATION)
|
||||
argument_parser.add_argument("--gpu-ids", type=str, default=GPU_IDS)
|
||||
argument_parser.add_argument("--study-name", type=str, default="default_study_name")
|
||||
argument_parser.add_argument("--run-name", type=str, default=None) # randomly chosen by wandb
|
||||
args = argument_parser.parse_args()
|
||||
return args
|
||||
|
||||
@@ -19,8 +20,10 @@ def main():
|
||||
args = parse_args()
|
||||
max_gpu_memory_allocation = args.max_gpu_memory_allocation
|
||||
gpu_ids = args.gpu_ids
|
||||
print(f"Running on GPU ID {gpu_ids}")
|
||||
study_name = args.study_name
|
||||
checkpoint_dir = f"{GLOBAL_CHECKPOINT_DIR}/{study_name}"
|
||||
run_name = args.run_name
|
||||
checkpoint_dir = f"{GLOBAL_CHECKPOINT_DIR}/{study_name}/{run_name}"
|
||||
|
||||
# 1. Set GPU memory limits.
|
||||
GPULimiter(_gpu_ids=gpu_ids, _max_gpu_memory_allocation=max_gpu_memory_allocation)()
|
||||
@@ -35,7 +38,7 @@ def main():
|
||||
|
||||
# This import must be local because otherwise it is impossible to call GPULimiter.
|
||||
from core.model import VAEHandler
|
||||
vae = VAEHandler(_wandb_project_name=study_name, _wandb_tags=["single training"], _checkpoint_dir=checkpoint_dir)
|
||||
vae = VAEHandler(_wandb_project_name=study_name, _wandb_run_name=run_name, _wandb_tags=["single training"], _checkpoint_dir=checkpoint_dir)
|
||||
|
||||
# 4. Train model.
|
||||
histories = vae.train(energies_train,
|
||||
@@ -1,86 +1,16 @@
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 4 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/control/execute common_settings_lowgran.mac
|
||||
# Overwrite the sensitivity of the absorber to account for the passive material
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm false
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
/Par04/detector/print
|
||||
|
||||
# Use default detector dimensions and initialize
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
# If inference model is active, de-activate it because it needs configuration
|
||||
/param/InActivateModel inferenceModel
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Open a viewer
|
||||
/vis/open
|
||||
# This opens the default viewer - see examples/basic/B1/vis.mac for a
|
||||
# more comprehensive overview of options. Also the documentation.
|
||||
#
|
||||
# Disable auto refresh and quieten vis messages whilst scene and
|
||||
# trajectories are established:
|
||||
/vis/viewer/set/autoRefresh false
|
||||
/vis/verbose errors
|
||||
#
|
||||
# Draw geometry:
|
||||
/vis/drawVolume worlds
|
||||
#
|
||||
# Specify view angle:
|
||||
/vis/viewer/set/viewpointThetaPhi 0 90 deg
|
||||
/vis/viewer/set/targetPoint 0 800 0 mm
|
||||
#
|
||||
# Specify zoom value:
|
||||
/vis/viewer/zoom 10
|
||||
#
|
||||
# Specify style (surface or wireframe):
|
||||
#/vis/viewer/set/style wireframe
|
||||
#
|
||||
# Draw coordinate axes:
|
||||
#/vis/scene/add/axes 0 0 0 1 m
|
||||
#
|
||||
# Draw smooth trajectories at end of event, showing trajectory points
|
||||
# as markers 2 pixels wide:
|
||||
#/vis/scene/add/trajectories smooth
|
||||
/vis/scene/add/trajectories
|
||||
/vis/modeling/trajectories/create/drawByCharge
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
|
||||
# (if too many tracks cause core dump => /tracking/storeTrajectory 0)
|
||||
#
|
||||
# Draw hits at end of event:
|
||||
/vis/scene/add/hits
|
||||
#
|
||||
# To draw only gammas:
|
||||
#/vis/filtering/trajectories/create/particleFilter
|
||||
#/vis/filtering/trajectories/particleFilter-0/add gamma
|
||||
#
|
||||
# To invert the above, drawing all particles except gammas,
|
||||
# keep the above two lines but also add:
|
||||
#/vis/filtering/trajectories/particleFilter-0/invert true
|
||||
#
|
||||
# Many other options are available with /vis/modeling and /vis/filtering.
|
||||
# For example, to select colour by particle ID:
|
||||
#/vis/modeling/trajectories/create/drawByParticleID
|
||||
#/vis/modeling/trajectories/drawByParticleID-0/set e- blue
|
||||
#
|
||||
# Create an attribute filter to draw only particles with certain (high) momentum
|
||||
/vis/filtering/trajectories/create/attributeFilter
|
||||
# Select attribute "IMag"
|
||||
/vis/filtering/trajectories/attributeFilter-0/setAttribute IMag
|
||||
# Select trajectories with 25 MeV <= IMag < 1000 GeV
|
||||
/vis/filtering/trajectories/attributeFilter-0/addInterval 25 MeV 1000 GeV
|
||||
#
|
||||
# To superimpose all of the events from a given run:
|
||||
/vis/scene/endOfEventAction accumulate
|
||||
#
|
||||
# Re-establish auto refreshing and verbosity:
|
||||
/vis/viewer/set/autoRefresh true
|
||||
/vis/verbose warnings
|
||||
#
|
||||
# For file-based drivers, use this to create an empty detector view:
|
||||
#/vis/viewer/flush
|
||||
/vis/viewer/set/background 1 1 1
|
||||
## dynamically set readout mesh from particle direction
|
||||
/param/ActivateModel defineMesh
|
||||
## we do not use ML fast sim
|
||||
/param/InActivateModel inferenceModel
|
||||
/param/InActivateModel dummyModel
|
||||
/run/beamOn 1
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.json
|
||||
/Par04/inference/setInferenceLibrary LWTNN
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 1
|
||||
@@ -1,109 +0,0 @@
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 4 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm true
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
/Par04/detector/print
|
||||
|
||||
# Use default detector dimensions and initialize
|
||||
/run/initialize
|
||||
|
||||
# If inference model is active, de-activate it because it needs configuration
|
||||
/param/InActivateModel inferenceModel
|
||||
|
||||
# Open a viewer
|
||||
/vis/open
|
||||
# This opens the default viewer - see examples/basic/B1/vis.mac for a
|
||||
# more comprehensive overview of options. Also the documentation.
|
||||
#
|
||||
# Disable auto refresh and quieten vis messages whilst scene and
|
||||
# trajectories are established:
|
||||
/vis/viewer/set/autoRefresh false
|
||||
/vis/verbose errors
|
||||
#
|
||||
# Draw geometry:
|
||||
/vis/drawVolume worlds
|
||||
#
|
||||
# Specify view angle:
|
||||
/vis/viewer/set/viewpointThetaPhi 0 90 deg
|
||||
/vis/viewer/set/targetPoint 0 800 0 mm
|
||||
#
|
||||
# Specify zoom value:
|
||||
/vis/viewer/zoom 10
|
||||
#
|
||||
# Specify style (surface or wireframe):
|
||||
#/vis/viewer/set/style wireframe
|
||||
#
|
||||
# Draw coordinate axes:
|
||||
#/vis/scene/add/axes 0 0 0 1 m
|
||||
#
|
||||
# Draw smooth trajectories at end of event, showing trajectory points
|
||||
# as markers 2 pixels wide:
|
||||
#/vis/scene/add/trajectories smooth
|
||||
/vis/scene/add/trajectories
|
||||
/vis/modeling/trajectories/create/drawByCharge
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
|
||||
# (if too many tracks cause core dump => /tracking/storeTrajectory 0)
|
||||
#
|
||||
# Draw hits at end of event:
|
||||
/vis/scene/add/hits
|
||||
#
|
||||
# To draw only gammas:
|
||||
#/vis/filtering/trajectories/create/particleFilter
|
||||
#/vis/filtering/trajectories/particleFilter-0/add gamma
|
||||
#
|
||||
# To invert the above, drawing all particles except gammas,
|
||||
# keep the above two lines but also add:
|
||||
#/vis/filtering/trajectories/particleFilter-0/invert true
|
||||
#
|
||||
# Many other options are available with /vis/modeling and /vis/filtering.
|
||||
# For example, to select colour by particle ID:
|
||||
#/vis/modeling/trajectories/create/drawByParticleID
|
||||
#/vis/modeling/trajectories/drawByParticleID-0/set e- blue
|
||||
#
|
||||
# Create an attribute filter to draw only particles with certain (high) momentum
|
||||
/vis/filtering/trajectories/create/attributeFilter
|
||||
# Select attribute "IMag"
|
||||
/vis/filtering/trajectories/attributeFilter-0/setAttribute IMag
|
||||
# Select trajectories with 25 MeV <= IMag < 1000 GeV
|
||||
/vis/filtering/trajectories/attributeFilter-0/addInterval 25 MeV 1000 GeV
|
||||
#
|
||||
# To superimpose all of the events from a given run:
|
||||
/vis/scene/endOfEventAction accumulate
|
||||
#
|
||||
# Re-establish auto refreshing and verbosity:
|
||||
/vis/viewer/set/autoRefresh true
|
||||
/vis/verbose warnings
|
||||
#
|
||||
# For file-based drivers, use this to create an empty detector view:
|
||||
#/vis/viewer/flush
|
||||
/vis/viewer/set/background 1 1 1
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx
|
||||
/Par04/inference/setProfileFlag 1
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
@@ -0,0 +1,28 @@
|
||||
/control/execute common_settings_lowgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/cd.onnx
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType CaloDiT-2
|
||||
/Par04/inference/setProfileFlag 1
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 4.65 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 9
|
||||
/Par04/inference/setNbOfPhiCells 16
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 1
|
||||
@@ -0,0 +1,32 @@
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.onnx
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType VAE
|
||||
/Par04/inference/setProfileFlag 1
|
||||
/Par04/inference/setOptimizationFlag 0
|
||||
/Par04/inference/setInferenceLibrary ONNX
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 1
|
||||
@@ -1,108 +0,0 @@
|
||||
/Par04/detector/setDetectorInnerRadius 80 cm
|
||||
/Par04/detector/setDetectorLength 4 m
|
||||
/Par04/detector/setNbOfLayers 90
|
||||
/Par04/detector/setAbsorber 0 G4_W 1.4 mm true
|
||||
/Par04/detector/setAbsorber 1 G4_Si 0.3 mm true
|
||||
/Par04/mesh/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/mesh/setSizeOfZCells 3.4 mm
|
||||
/Par04/mesh/setNbOfRhoCells 18
|
||||
/Par04/mesh/setNbOfPhiCells 50
|
||||
/Par04/mesh/setNbOfZCells 45
|
||||
/Par04/detector/print
|
||||
|
||||
# Use default detector dimensions and initialize
|
||||
/run/initialize
|
||||
|
||||
# If inference model is active, de-activate it because it needs configuration
|
||||
/param/InActivateModel inferenceModel
|
||||
|
||||
# Open a viewer
|
||||
/vis/open
|
||||
# This opens the default viewer - see examples/basic/B1/vis.mac for a
|
||||
# more comprehensive overview of options. Also the documentation.
|
||||
#
|
||||
# Disable auto refresh and quieten vis messages whilst scene and
|
||||
# trajectories are established:
|
||||
/vis/viewer/set/autoRefresh false
|
||||
/vis/verbose errors
|
||||
#
|
||||
# Draw geometry:
|
||||
/vis/drawVolume worlds
|
||||
#
|
||||
# Specify view angle:
|
||||
/vis/viewer/set/viewpointThetaPhi 0 90 deg
|
||||
/vis/viewer/set/targetPoint 0 800 0 mm
|
||||
#
|
||||
# Specify zoom value:
|
||||
/vis/viewer/zoom 10
|
||||
#
|
||||
# Specify style (surface or wireframe):
|
||||
#/vis/viewer/set/style wireframe
|
||||
#
|
||||
# Draw coordinate axes:
|
||||
#/vis/scene/add/axes 0 0 0 1 m
|
||||
#
|
||||
# Draw smooth trajectories at end of event, showing trajectory points
|
||||
# as markers 2 pixels wide:
|
||||
#/vis/scene/add/trajectories smooth
|
||||
/vis/scene/add/trajectories
|
||||
/vis/modeling/trajectories/create/drawByCharge
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
|
||||
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
|
||||
# (if too many tracks cause core dump => /tracking/storeTrajectory 0)
|
||||
#
|
||||
# Draw hits at end of event:
|
||||
/vis/scene/add/hits
|
||||
#
|
||||
# To draw only gammas:
|
||||
#/vis/filtering/trajectories/create/particleFilter
|
||||
#/vis/filtering/trajectories/particleFilter-0/add gamma
|
||||
#
|
||||
# To invert the above, drawing all particles except gammas,
|
||||
# keep the above two lines but also add:
|
||||
#/vis/filtering/trajectories/particleFilter-0/invert true
|
||||
#
|
||||
# Many other options are available with /vis/modeling and /vis/filtering.
|
||||
# For example, to select colour by particle ID:
|
||||
#/vis/modeling/trajectories/create/drawByParticleID
|
||||
#/vis/modeling/trajectories/drawByParticleID-0/set e- blue
|
||||
#
|
||||
# Create an attribute filter to draw only particles with certain (high) momentum
|
||||
/vis/filtering/trajectories/create/attributeFilter
|
||||
# Select attribute "IMag"
|
||||
/vis/filtering/trajectories/attributeFilter-0/setAttribute IMag
|
||||
# Select trajectories with 25 MeV <= IMag < 1000 GeV
|
||||
/vis/filtering/trajectories/attributeFilter-0/addInterval 25 MeV 1000 GeV
|
||||
#
|
||||
# To superimpose all of the events from a given run:
|
||||
/vis/scene/endOfEventAction accumulate
|
||||
#
|
||||
# Re-establish auto refreshing and verbosity:
|
||||
/vis/viewer/set/autoRefresh true
|
||||
/vis/verbose warnings
|
||||
#
|
||||
# For file-based drivers, use this to create an empty detector view:
|
||||
#/vis/viewer/flush
|
||||
/vis/viewer/set/background 1 1 1
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.pt
|
||||
/Par04/inference/setInferenceLibrary TORCH
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
@@ -0,0 +1,27 @@
|
||||
/control/execute common_settings_lowgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/cd_cpu.pt
|
||||
## Set ML model to use (VAE, CaloDiT-2)
|
||||
/Par04/inference/setModelType CaloDiT-2
|
||||
/Par04/inference/setInferenceLibrary TORCH
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 4.65 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 9
|
||||
/Par04/inference/setNbOfPhiCells 16
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 1
|
||||
@@ -0,0 +1,29 @@
|
||||
/control/execute common_settings_highgran.mac
|
||||
# Initialize
|
||||
/run/initialize
|
||||
|
||||
/control/execute common_settings_postInit.mac
|
||||
/control/execute common_settings_vis.mac
|
||||
|
||||
# Fast Simulation
|
||||
# Inference Setup
|
||||
## dimension of the latent vector (encoded vector in a Variational Autoencoder model)
|
||||
/Par04/inference/setSizeLatentVector 10
|
||||
## size of the condition vector (energy, angle and geometry)
|
||||
/Par04/inference/setSizeConditionVector 4
|
||||
## path to the model which is set to download by cmake
|
||||
/Par04/inference/setModelPathName MLModels/Generator.pt
|
||||
/Par04/inference/setInferenceLibrary TORCH
|
||||
## set mesh size for inference == mesh size of a full sim that
|
||||
## was used for training; it coincides with readout mesh size
|
||||
/Par04/inference/setSizeOfRhoCells 2.325 mm
|
||||
/Par04/inference/setSizeOfZCells 3.4 mm
|
||||
/Par04/inference/setNbOfRhoCells 18
|
||||
/Par04/inference/setNbOfPhiCells 50
|
||||
/Par04/inference/setNbOfZCells 45
|
||||
|
||||
## Dynamic readout mesh from particle direction needs to be the first fast sim model!
|
||||
/param/ActivateModel defineMesh
|
||||
## ML fast sim, configured with the inference setup /Par04/inference
|
||||
/param/ActivateModel inferenceModel
|
||||
/run/beamOn 1
|
||||
Reference in New Issue
Block a user