Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-26 07:50:30

0001 #!/usr/bin/env bash
0002 #
0003 # G4Trap / G4Trd geometry validation test suite.
0004 #
0005 # Compares Geant4 (CPU) and Opticks (GPU) photon hits on identical inputs,
0006 # for each of the new convex-polyhedron-based solids. The branch under test
0007 # is g4trap-to-convexpolyhedron; this script runs every check that was used
0008 # to validate it.
0009 #
0010 # Usage:
0011 #   ./tests/g4trap_validation.sh                          # all tests
0012 #   ./tests/g4trap_validation.sh trap                     # trap iso-source only
0013 #   ./tests/g4trap_validation.sh trd                      # trd iso-source only
0014 #   ./tests/g4trap_validation.sh scintillation            # scint+Cherenkov (trap & trd)
0015 #   ./tests/g4trap_validation.sh scintillation_trap       # scint+Cherenkov trap only
0016 #   ./tests/g4trap_validation.sh scintillation_trd        # scint+Cherenkov trd only
0017 #
0018 # Pre-requisites: GPUPhotonSource and GPURaytrace on PATH (any standard
0019 # install of simphony puts them in the chosen install prefix's `bin/`,
0020 # which is added to PATH in the Dockerfile and devcontainer).
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 # run helpers
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 # tests
0047 # ------------------------------------------------------------------
0048 # (1) Simple test class: isotropic torch source in the new solid, no
0049 #     scintillation / Cherenkov physics. Validates the convex-polyhedron
0050 #     conversion under heavy TIR / multi-bounce. Runs on BOTH trap and trd
0051 #     so each new solid is exercised.
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 # (2) Full-physics test: 5 GeV electrons in synthetic-scintillator Quartz
0067 #     solid with finite ABSLENGTH=100m. Folds Cerenkov + Scintillation +
0068 #     absorption + slanted walls + multi-bounce. Run on BOTH trap and trd
0069 #     so each solid sees the full physics chain. Single-thread G4 for
0070 #     deterministic file output; ~3 min wall time per solid.
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 # dispatch
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