Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-04 07:59:12

0001 #!/usr/bin/env bash
0002 # Demonstrate SELECTIVE, per-solid triangulation. opticks_two_spheres.gdml holds
0003 # two curved water detectors on the 5 GeV e- track: WATER_A at the beam origin
0004 # and WATER_B downstream. stree__force_triangulate_solid takes a comma-separated
0005 # list of EXACT solid names and triangulates only those; everything else stays
0006 # analytic CSG. Coarsening every G4Orb to 12 rotation steps
0007 # (U4Mesh__NumberOfRotationSteps_entityType_G4Orb=12) makes a triangulated
0008 # detector lose a clear, deterministic number of hits, so the four runs separate:
0009 #
0010 #   analytic   : 51087
0011 #   force A    : 50522   (only A triangulated)
0012 #   force B    : 50338   (only B triangulated)
0013 #   force A,B  : 49706   (both)
0014 #
0015 # Selectivity check: forceA and forceB each sit strictly BETWEEN analytic and
0016 # forceA,B. If naming A also triangulated B, forceA would equal forceA,B -- so
0017 # this ordering proves each named solid triangulates only itself.
0018 set -e
0019 
0020 GDML="$OPTICKS_HOME/tests/geom/opticks_two_spheres.gdml"
0021 MAC="$OPTICKS_HOME/tests/run.mac"
0022 SEED=42
0023 RES=U4Mesh__NumberOfRotationSteps_entityType_G4Orb=12
0024 hits(){ awk '/Opticks: NumHits:/ {print $NF}'; }
0025 
0026 ANA=$(GPURaytrace -g "$GDML" -m "$MAC" -s "$SEED" 2>&1 | hits)
0027 A=$( env "$RES" stree__force_triangulate_solid=WATER_A_solid               GPURaytrace -g "$GDML" -m "$MAC" -s "$SEED" 2>&1 | hits)
0028 B=$( env "$RES" stree__force_triangulate_solid=WATER_B_solid               GPURaytrace -g "$GDML" -m "$MAC" -s "$SEED" 2>&1 | hits)
0029 AB=$(env "$RES" stree__force_triangulate_solid=WATER_A_solid,WATER_B_solid GPURaytrace -g "$GDML" -m "$MAC" -s "$SEED" 2>&1 | hits)
0030 
0031 echo "analytic=$ANA forceA=$A forceB=$B forceAB=$AB"
0032 for v in "$ANA" "$A" "$B" "$AB"; do
0033     [ -n "$v" ] || { echo "FAILED: missing hit count (analytic=$ANA A=$A B=$B AB=$AB)"; exit 1; }
0034 done
0035 
0036 OK=$(awk -v ana="$ANA" -v a="$A" -v b="$B" -v ab="$AB" \
0037     'BEGIN{ print (ana>a && ana>b && a>ab && b>ab) ? 1 : 0 }')
0038 [ "$OK" = "1" ] || { echo "FAILED: expected analytic > forceA,forceB > forceA,B (selective triangulation)"; exit 1; }
0039 echo "PASSED"