Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:55

0001 #!/usr/bin/env bash
0002 
0003 set -e
0004 
0005 
0006 SEED=42
0007 TOLERANCE=113
0008 PASS=true
0009 
0010 check_hits() {
0011     local label=$1
0012     local actual=$2
0013     local expected=$3
0014     local lo=$((expected - TOLERANCE))
0015     local hi=$((expected + TOLERANCE))
0016     if [ "$actual" -ge "$lo" ] && [ "$actual" -le "$hi" ]; then
0017         echo "PASSED: $label ($actual) is within [$lo, $hi]"
0018     else
0019         echo "FAILED: $label ($actual) is outside [$lo, $hi]"
0020         PASS=false
0021     fi
0022 }
0023 
0024 # ---- Test 1: Cerenkov only (opticks_raindrop.gdml) ----
0025 echo "=== Test 1: Cerenkov only (opticks_raindrop.gdml) ==="
0026 echo "Running GPURaytrace with seed $SEED ..."
0027 OUTPUT=$(USER=fakeuser GEOM=fakegeom GPURaytrace \
0028     -g "$OPTICKS_HOME/tests/geom/opticks_raindrop.gdml" \
0029     -m "$OPTICKS_HOME/tests/run.mac" \
0030     -s "$SEED" 2>&1)
0031 
0032 G4_HITS=$(echo "$OUTPUT" | grep "Geant4: NumHits:" | awk '{print $NF}')
0033 OPTICKS_HITS=$(echo "$OUTPUT" | grep "Opticks: NumHits:" | awk '{print $NF}')
0034 
0035 echo "Geant4:  NumHits: $G4_HITS  (expected 12672 +/- $TOLERANCE)"
0036 echo "Opticks: NumHits: $OPTICKS_HITS  (expected 12664 +/- $TOLERANCE)"
0037 
0038 check_hits "Geant4 NumHits"  "$G4_HITS"      12672
0039 check_hits "Opticks NumHits" "$OPTICKS_HITS"  12664
0040 
0041 # ---- Test 2: Cerenkov + Scintillation (opticks_raindrop_with_scintillation.gdml) ----
0042 echo ""
0043 echo "=== Test 2: Cerenkov + Scintillation (opticks_raindrop_with_scintillation.gdml) ==="
0044 echo "Running GPURaytrace with seed $SEED ..."
0045 OUTPUT=$(USER=fakeuser GEOM=fakegeom GPURaytrace \
0046     -g "$OPTICKS_HOME/tests/geom/opticks_raindrop_with_scintillation.gdml" \
0047     -m "$OPTICKS_HOME/tests/run.mac" \
0048     -s "$SEED" 2>&1)
0049 
0050 G4_HITS=$(echo "$OUTPUT" | grep "Geant4: NumHits:" | awk '{print $NF}')
0051 OPTICKS_HITS=$(echo "$OUTPUT" | grep "Opticks: NumHits:" | awk '{print $NF}')
0052 
0053 echo "Geant4:  NumHits: $G4_HITS  (expected 17473 +/- $TOLERANCE)"
0054 echo "Opticks: NumHits: $OPTICKS_HITS  (expected 17443 +/- $TOLERANCE)"
0055 
0056 check_hits "Geant4 NumHits"  "$G4_HITS"      17473
0057 check_hits "Opticks NumHits" "$OPTICKS_HITS"  17443
0058 
0059 # ---- Summary ----
0060 echo ""
0061 if [ "$PASS" = true ]; then
0062     echo "All tests passed"
0063     exit 0
0064 else
0065     echo "Some tests FAILED"
0066     exit 1
0067 fi