|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# G4Trap / G4Trd geometry validation test suite. |
| 4 | +# |
| 5 | +# Compares Geant4 (CPU) and Opticks (GPU) photon hits on identical inputs, |
| 6 | +# for each of the new convex-polyhedron-based solids. The branch under test |
| 7 | +# is g4trap-to-convexpolyhedron; this script runs every check that was used |
| 8 | +# to validate it. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# ./tests/g4trap_validation.sh # all tests |
| 12 | +# ./tests/g4trap_validation.sh trap # trap iso-source only |
| 13 | +# ./tests/g4trap_validation.sh trd # trd iso-source only |
| 14 | +# ./tests/g4trap_validation.sh scintillation # scint+Cherenkov (trap & trd) |
| 15 | +# ./tests/g4trap_validation.sh scintillation_trap # scint+Cherenkov trap only |
| 16 | +# ./tests/g4trap_validation.sh scintillation_trd # scint+Cherenkov trd only |
| 17 | +# |
| 18 | +# Pre-requisites: GPUPhotonSource and GPURaytrace on PATH (any standard |
| 19 | +# install of simphony puts them in OPTICKS_PREFIX/bin which is added to |
| 20 | +# PATH in the Dockerfile and devcontainer). |
| 21 | + |
| 22 | +set -e |
| 23 | + |
| 24 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 25 | +GEOM_DIR="${SCRIPT_DIR}/geom" |
| 26 | +OUT_DIR=${OUT_DIR:-/tmp/g4trap_validation} |
| 27 | + |
| 28 | +mkdir -p "${OUT_DIR}" |
| 29 | + |
| 30 | +COMPARE_PY="${SCRIPT_DIR}/g4trap_compare.py" |
| 31 | + |
| 32 | +# ------------------------------------------------------------------ |
| 33 | +# run helpers |
| 34 | +# ------------------------------------------------------------------ |
| 35 | +G4_MACRO="${SCRIPT_DIR}/run_validate.mac" |
| 36 | +G4_MACRO_5EVT="${SCRIPT_DIR}/run_validate_5evt_1t.mac" |
| 37 | + |
| 38 | +run_torch_test () { |
| 39 | + local case=$1; local gdml=$2; local cfg=$3; local seed=${4:-42} |
| 40 | + local outd="${OUT_DIR}/${case}" |
| 41 | + mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt |
| 42 | + GPUPhotonSource -g "${gdml}" -c "${cfg}" -m "${G4_MACRO}" -s ${seed} > run.log 2>&1 |
| 43 | +} |
| 44 | + |
| 45 | +# ------------------------------------------------------------------ |
| 46 | +# tests |
| 47 | +# ------------------------------------------------------------------ |
| 48 | +# (1) Simple test class: isotropic torch source in the new solid, no |
| 49 | +# scintillation / Cherenkov physics. Validates the convex-polyhedron |
| 50 | +# conversion under heavy TIR / multi-bounce. Runs on BOTH trap and trd |
| 51 | +# so each new solid is exercised. |
| 52 | +test_trap_iso () { |
| 53 | + echo |
| 54 | + echo "----- Test: trap, isotropic source (probes slanted walls) -----" |
| 55 | + run_torch_test trap_iso "${GEOM_DIR}/test_trap.gdml" trap_iso |
| 56 | + python3 "${COMPARE_PY}" "${OUT_DIR}/trap_iso/g4_hits_output.txt" "${OUT_DIR}/trap_iso/opticks_hits_output.txt" "trap iso" |
| 57 | +} |
| 58 | + |
| 59 | +test_trd_iso () { |
| 60 | + echo |
| 61 | + echo "----- Test: trd, isotropic source -----" |
| 62 | + run_torch_test trd_iso "${GEOM_DIR}/test_trd.gdml" trap_iso |
| 63 | + python3 "${COMPARE_PY}" "${OUT_DIR}/trd_iso/g4_hits_output.txt" "${OUT_DIR}/trd_iso/opticks_hits_output.txt" "trd iso" |
| 64 | +} |
| 65 | + |
| 66 | +# (2) Full-physics test: 5 GeV electrons in synthetic-scintillator Quartz |
| 67 | +# solid with finite ABSLENGTH=100m. Folds Cerenkov + Scintillation + |
| 68 | +# absorption + slanted walls + multi-bounce. Run on BOTH trap and trd |
| 69 | +# so each solid sees the full physics chain. Single-thread G4 for |
| 70 | +# deterministic file output; ~3 min wall time per solid. |
| 71 | +test_scintillation_trap () { |
| 72 | + echo |
| 73 | + echo "----- Test: Scintillation+Cherenkov on trap, 5 x 5 GeV electrons -----" |
| 74 | + local outd="${OUT_DIR}/scintillation_trap" |
| 75 | + mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt |
| 76 | + GPURaytrace -g "${GEOM_DIR}/test_trap_scint.gdml" -m "${G4_MACRO_5EVT}" -s 42 > run.log 2>&1 |
| 77 | + python3 "${COMPARE_PY}" "${outd}/g4_hits_output.txt" "${outd}/opticks_hits_output.txt" "scintillation trap" 10 50 |
| 78 | +} |
| 79 | + |
| 80 | +test_scintillation_trd () { |
| 81 | + echo |
| 82 | + echo "----- Test: Scintillation+Cherenkov on trd, 5 x 5 GeV electrons -----" |
| 83 | + local outd="${OUT_DIR}/scintillation_trd" |
| 84 | + mkdir -p "${outd}"; cd "${outd}"; rm -f *_hits_output.txt |
| 85 | + GPURaytrace -g "${GEOM_DIR}/test_trd_scint.gdml" -m "${G4_MACRO_5EVT}" -s 42 > run.log 2>&1 |
| 86 | + python3 "${COMPARE_PY}" "${outd}/g4_hits_output.txt" "${outd}/opticks_hits_output.txt" "scintillation trd" 10 50 |
| 87 | +} |
| 88 | + |
| 89 | +# ------------------------------------------------------------------ |
| 90 | +# dispatch |
| 91 | +# ------------------------------------------------------------------ |
| 92 | +case "${1:-all}" in |
| 93 | + trap|iso_trap) test_trap_iso ;; |
| 94 | + trd|iso_trd) test_trd_iso ;; |
| 95 | + scintillation|sc) test_scintillation_trap; test_scintillation_trd ;; |
| 96 | + scintillation_trap|sc_trap) test_scintillation_trap ;; |
| 97 | + scintillation_trd|sc_trd) test_scintillation_trd ;; |
| 98 | + all|*) |
| 99 | + test_trap_iso |
| 100 | + test_trd_iso |
| 101 | + test_scintillation_trap |
| 102 | + test_scintillation_trd |
| 103 | + ;; |
| 104 | +esac |
0 commit comments