This repository contains a Geant4-based simulation for optical photon generation, tracking, and detection in a water Cherenkov detector context. It includes Cherenkov and scintillation photon generation, visualization macros, and a ROOT-based Python waveform builder for analysis.
This code was developed quickly based on a prior project, and some files may be unrelated or left over from previous iterations. If anything is unclear or if you plan to use or modify this code for your own project, feel free to contact me for clarification or guidance.
.
├── src/ # Colection of Source files
│ └── src/ # Geant4 source files
│ └── include/ # Geant4 headers
│ └── vis.mac # Visualization setup
│ └── CMakeLists.txt # Build configuration
│
├── scripts/ # Colection of Source files
│ └── photon_histogram_builder.py # ROOT Python script to build waveforms
│
├── .gitignore
└── README.md # This file
- Geant4 (with data sets and visualization options)
- CMake (≥ 3.16)
- ROOT (for waveform analysis)
- Python 3 with
ROOT,numpy, andmatplotlibfor analysis scripts
mkdir build
cd build
cmake ../src
makeRun a simple test using:
./filtroRunning in non-batch mode may require to compile it with single core run manager. Modify filtro.cc if getting errors.
G4RunManager* runManager = new G4RunManager;You can batch run with the following, where N is the PMT to BGO distance (in mm)
./filtro filtro.in NRunning for many events benefit greatly of having multi-core run manager. Modify filtro.cc to use N cores.
G4MTRunManager* runManager = new G4MTRunManager;
runManager->SetNumberOfThreads(N);
runManager->SetVerboseLevel(0);After running the simulation and producing a ROOT output tree:
Make sure you combine all outputs with hadd. Then cleanup removing the unecessary files.
hadd OutPut_merged_0mm.root OutPut_t*.root
rm OutPut_t*.root
rn OutPut.rootThen use the python script to go from the photon arrival histogram to pmt response waveforms:
python photon_histogram_builder.pyThis script builds histograms of photon arrival times per event and separates Cherenkov and scintillation contributions. Ita also applies the PMT QE and simulate PMT response.
From within ROOT, you can explore the output tree using the TBrowser:
TBrowser b;Or plot Cherenkov/scintillation ratios for triggered events:
tree->Draw("n_cher/n_scint:event", "trigger==1", "COLZ")colors in vis.mac:
- Optical photons → Green
- Gammas → Purple
- Electrons → Red
- Positrons → Blue
- Default → Grey