File indexing completed on 2026-06-26 07:50:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 set -e
0023
0024 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
0025 GEOM_DIR="${SCRIPT_DIR}/geom"
0026 OUT_DIR=${OUT_DIR:-/tmp/g4trap_validation}
0027
0028 mkdir -p "${OUT_DIR}"
0029
0030 COMPARE_PY="${SCRIPT_DIR}/g4trap_compare.py"
0031
0032
0033
0034
0035 G4_MACRO="${SCRIPT_DIR}/run_validate.mac"
0036 G4_MACRO_5EVT="${SCRIPT_DIR}/run_validate_5evt_1t.mac"
0037
0038 run_torch_test () {
0039 local case=$1; local gdml=$2; local cfg=$3; local seed=${4:-42}
0040 local outd="${OUT_DIR}/${case}"
0041 mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt
0042 GPUPhotonSource -g "${gdml}" -c "${cfg}" -m "${G4_MACRO}" -s ${seed} > run.log 2>&1
0043 }
0044
0045
0046
0047
0048
0049
0050
0051
0052 test_trap_iso () {
0053 echo
0054 echo "----- Test: trap, isotropic source (probes slanted walls) -----"
0055 run_torch_test trap_iso "${GEOM_DIR}/test_trap.gdml" trap_iso
0056 python3 "${COMPARE_PY}" "${OUT_DIR}/trap_iso/g4_hits_output.txt" "${OUT_DIR}/trap_iso/opticks_hits_output.txt" "trap iso"
0057 }
0058
0059 test_trd_iso () {
0060 echo
0061 echo "----- Test: trd, isotropic source -----"
0062 run_torch_test trd_iso "${GEOM_DIR}/test_trd.gdml" trap_iso
0063 python3 "${COMPARE_PY}" "${OUT_DIR}/trd_iso/g4_hits_output.txt" "${OUT_DIR}/trd_iso/opticks_hits_output.txt" "trd iso"
0064 }
0065
0066
0067
0068
0069
0070
0071 test_scintillation_trap () {
0072 echo
0073 echo "----- Test: Scintillation+Cherenkov on trap, 5 x 5 GeV electrons -----"
0074 local outd="${OUT_DIR}/scintillation_trap"
0075 mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt
0076 GPURaytrace -g "${GEOM_DIR}/test_trap_scint.gdml" -m "${G4_MACRO_5EVT}" -s 42 > run.log 2>&1
0077 python3 "${COMPARE_PY}" "${outd}/g4_hits_output.txt" "${outd}/opticks_hits_output.txt" "scintillation trap" 10 50
0078 }
0079
0080 test_scintillation_trd () {
0081 echo
0082 echo "----- Test: Scintillation+Cherenkov on trd, 5 x 5 GeV electrons -----"
0083 local outd="${OUT_DIR}/scintillation_trd"
0084 mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt
0085 GPURaytrace -g "${GEOM_DIR}/test_trd_scint.gdml" -m "${G4_MACRO_5EVT}" -s 42 > run.log 2>&1
0086 python3 "${COMPARE_PY}" "${outd}/g4_hits_output.txt" "${outd}/opticks_hits_output.txt" "scintillation trd" 10 50
0087 }
0088
0089
0090
0091
0092 case "${1:-all}" in
0093 trap|iso_trap) test_trap_iso ;;
0094 trd|iso_trd) test_trd_iso ;;
0095 scintillation|sc) test_scintillation_trap; test_scintillation_trd ;;
0096 scintillation_trap|sc_trap) test_scintillation_trap ;;
0097 scintillation_trd|sc_trd) test_scintillation_trd ;;
0098 all|*)
0099 test_trap_iso
0100 test_trd_iso
0101 test_scintillation_trap
0102 test_scintillation_trd
0103 ;;
0104 esac