This repository contains a Geant4-based detector simulation project with a Python pipeline for generating macros, running simulations, validating ROOT outputs, analyzing deposited-energy spectra, and producing reference tables and plots.
The project is designed for scintillation detector studies involving solid cylindrical, hollow cylindrical, and soccerball / 4π detector geometries.
.
├── CMakeLists.txt
├── README.md
├── configs/
├── include/
├── src/
├── scripts/
│ └── geant4_pipeline.py
├── macros/
│ ├── examples/
│ │ ├── vrml_solid.mac
│ │ ├── vrml_hollow.mac
│ │ └── vrml_soccerball.mac
│ └── generated/
│ ├── solid_cs137_1M.mac
│ ├── hollow_cs137_1M.mac
│ └── soccerball_cs137_1M.mac
└── results/
├── root/
├── logs/
├── spectra/
├── tables/
└── vrml/
- Geant4 detector simulation using C++
- Python-controlled simulation pipeline
- Automatic macro generation
- Simulation execution from Python
- ROOT output checking
- Analysis of deposited energy in the detector crystal
- Total non-zero count extraction
- Peak count extraction around selected energies
- Spectrum plotting
- CSV and Excel table generation
- VRML geometry export for visual inspection
The project currently supports:
solid solid cylindrical detector
hollow hollow cylindrical detector
layered_hollow layered hollow cylindrical detector
soccerball 4π soccerball-style modular detector geometry
The solid detector uses commands such as:
/det/geometry solid
/det/material NaI
/det/radius 24.900 mm
/det/halfZ 24.900 mm
/det/alThickness 0.400 mm
The hollow detector uses commands such as:
/det/geometry hollow
/det/material NaI
/det/innerRadius 45.720 mm
/det/thickness 50.800 mm
/det/halfZ 76.200 mm
/det/alThickness 0.400 mm
The soccerball geometry uses:
/det/geometry soccerball
/det/material BGO
The soccerball geometry is generated from precomputed tessellated module vertices. The scintillator thickness is controlled in:
tools/soccerball_geometry/generate_soccer_detector_json.py SCINTILLATOR_THICKNESS_INCH = 2.0
After changing this value, regenerate the soccerball geometry files before rebuilding:
cd tools/soccerball_geometry
python3 generate_soccer_detector_json.py
python3 convert_soccer_json_to_header.py
cp SoccerBallGeometryData.hh ../../include/SoccerBallGeometryData.hhThe inner face-plane cavity distance remains fixed at 100 mm. Changing SCINTILLATOR_THICKNESS_INCH only changes the outward scintillator thickness of the soccerball modules.
The layered hollow detector uses commands such as:
/det/geometry layered_hollow
/det/material NaI
/det/innerRadius 52.070 mm
/det/thickness 50.800 mm
/det/halfZ 76.200 mm
/det/alThickness 0.500 mm
/det/layeredAirGap 4.750 mm
/det/endShieldThickness 0.500 mm
For holder/plastic placement, the example macros use:
/geom/usePlastic true
/geom/plasticZ 0.000 mm
/src/usePlastic true
/src/depth 1.000 mm
This repository includes three reference simulations, each with 1,000,000 events:
solid_cs137_1M
hollow_cs137_1M
soccerball_cs137_1M
These are generated and run using the Python pipeline.
The generated macros are stored in:
macros/generated/
The ROOT outputs are stored in:
results/root/
The analyzed tables are stored in:
results/tables/
The spectra are stored in:
results/spectra/
The run logs are stored in:
results/logs/
The VRML geometry files are stored in:
results/vrml/
macros/generated/solid_cs137_1M.mac
macros/generated/hollow_cs137_1M.mac
macros/generated/soccerball_cs137_1M.mac
results/root/solid_cs137_1M.root
results/root/hollow_cs137_1M.root
results/root/soccerball_cs137_1M.root
results/spectra/solid_cs137_1M.png
results/spectra/hollow_cs137_1M.png
results/spectra/soccerball_cs137_1M.png
results/tables/reference_summary_long.csv
results/tables/reference_summary_wide.csv
results/tables/reference_summary.xlsx
results/vrml/solid_geometry.wrl
results/vrml/hollow_geometry.wrl
results/vrml/soccerball_geometry.wrl
- Geant4
- CMake
- C++17 compatible compiler
- ROOT-compatible Python environment for analysis
Install the Python packages using:
pip install -r requirements.txt
From the repository root:
mkdir -p build
cd build
cmake ..
make -j4The executable should be created as:
build/hollowdetectorsim
Return to the repository root:
cd ..python scripts/geant4_pipeline.py --reference --generate
This creates:
macros/generated/solid_cs137_1M.mac
macros/generated/hollow_cs137_1M.mac
macros/generated/soccerball_cs137_1M.mac
python scripts/geant4_pipeline.py --reference --dry-run
This prints the commands that would be executed without running Geant4.
python scripts/geant4_pipeline.py --reference --run
This runs the three reference simulations and saves ROOT files and logs.
python scripts/geant4_pipeline.py --reference --analyze
This creates spectra and summary tables.
python scripts/geant4_pipeline.py --reference --all
This performs:
macro generation
simulation execution
ROOT output checking
spectrum generation
peak-count extraction
table generation
The analysis script reads the ROOT file using uproot.
It expects:
TTree name: events
Branch name: EdepCrystal_keV
For each case, it calculates:
total_nonzero_counts
peak_counts
For the included Cs-137 reference cases, the expected peak is:
662 keV
The default peak-counting window is:
±20 keV
This can be changed using:
python scripts/geant4_pipeline.py --reference --analyze --peak-window-kev 10
The default spectrum bin width is:
2 keV
This can be changed using:
python scripts/geant4_pipeline.py --reference --analyze --bin-width-kev 1
Example VRML macros are provided in:
macros/examples/
Available examples:
vrml_solid.mac
vrml_hollow.mac
vrml_soccerball.mac
These macros produce .wrl files that can be opened in a VRML viewer.
The included reference VRML outputs are:
results/vrml/solid_geometry.wrl
results/vrml/hollow_geometry.wrl
results/vrml/soccerball_geometry.wrl
The hollow and soccerball VRML examples include the plastic holder.
The current committed pipeline demonstrates the workflow using Cs-137-like 662 keV monoenergetic gamma rays.
Future versions are planned to support a larger source library, including:
Cs137
Co60
Sc46
Nb94
Na24
Na22
O14
Y88
Cl38
Artificial6000
Artificial8000
custom mono energies
Example peak definitions planned for analysis:
Cs137: 662 keV
Co60:
1173 keV
1332 keV
2505 keV sum peak
Sc46:
889 keV
1120 keV
2009 keV sum peak
Nb94:
703 keV
870 keV
1573 keV sum peak
Na24:
1368 keV
2754 keV
4122 keV sum peak
Na22:
511 keV
1022 keV
1275 keV
1786 keV
2297 keV
O14:
511 keV
1022 keV
2313 keV
2824 keV
3335 keV
Y88:
898 keV
1836 keV
2734 keV sum peak
Cl38:
1642 keV
2167 keV
3809 keV sum peak
On some systems, Geant4 may produce a segmentation fault during shutdown after a successful run. In this project, the Python runner checks whether the ROOT file was produced successfully and treats the run as valid if the expected ROOT output exists.
This behavior was observed during testing and does not necessarily indicate failure of the simulation output.
Ayush Priyadarshi
Department of Physics
IIT Roorkee