Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 QSimTest.sh
0004 =============
0005 
0006 ::
0007 
0008     ~/o/qudarap/tests/QSimTest.sh
0009         runs the executable and invoke the python script
0010 
0011     PIDX=0 ~/o/qudarap/tests/QSimTest.sh
0012     PIDX=2 ~/o/qudarap/tests/QSimTest.sh
0013         assuming QUDARap was compiled with DEBUG_PIDX this
0014         provides debug output for the provided photon id
0015 
0016     TEST=fill_state_cf ~/o/qudarap/tests/QSimTest.sh ana
0017         just invoke the analysis script for the named TEST
0018 
0019 EOU
0020 }
0021 
0022 cd $(dirname $(realpath $BASH_SOURCE))
0023 
0024 name=QSimTest
0025 
0026 bin=$name
0027 
0028 
0029 
0030 source $HOME/.opticks/GEOM/GEOM.sh
0031 msg="=== $BASH_SOURCE :"
0032 
0033 
0034 #export QSim__photon_launch_mutate_DEBUG_NUM_PHOTON=1
0035 
0036 
0037 #test=rng_sequence
0038 
0039 #test=boundary_lookup_all
0040 #test=boundary_lookup_water
0041 #test=boundary_lookup_ls
0042 
0043 #test=wavelength_scintillation
0044 #test=wavelength_cerenkov         ### non-active moved to QSim_dbg.cu
0045 
0046 #test=scint_generate
0047 #test=cerenkov_generate
0048 
0049 #test=fill_state_0
0050 #test=fill_state_1
0051 
0052 #test=rayleigh_scatter_align
0053 
0054 #test=propagate_to_boundary
0055 
0056 #test=hemisphere_s_polarized
0057 #test=hemisphere_p_polarized
0058 #test=hemisphere_x_polarized
0059 
0060 #test=propagate_at_boundary_s_polarized
0061 #test=propagate_at_boundary_p_polarized
0062 #test=propagate_at_boundary_x_polarized
0063 
0064 #test=propagate_at_boundary
0065 #test=propagate_at_boundary_normal_incidence
0066 
0067 #test=random_direction_marsaglia
0068 #test=lambertian_direction
0069 #test=reflect_diffuse
0070 #test=reflect_specular
0071 #test=propagate_at_surface
0072 #test=randgaussq_shoot
0073 
0074 test=fake_propagate
0075 #test=gentorch
0076 
0077 #test=smear_normal_sigma_alpha
0078 
0079 export TEST=${TEST:-$test}
0080 export BASE=/tmp/QSimTest         ## BASE NEEDED BY QSimTest::photon_launch_mutate
0081                                   ## AS U::Resolve DOES NOT YET SUPPORT "$FOLD/.."
0082                                   ## TODO:bring it over, done it elsewhere?
0083 
0084 export FOLD=/tmp/QSimTest/$TEST   ## CAUTION clean subcommand deletes this directory and contents
0085 mkdir -p $FOLD
0086 
0087 
0088 
0089 defarg=run_ana
0090 if [ "$(uname)" == "Darwin" ]; then
0091    defarg="run_ana"
0092 fi
0093 
0094 if [ -n "$BP" ]; then
0095    defarg="dbg"
0096 fi
0097 
0098 if [ "$TEST" == "rng_sequence" ]; then
0099    defarg="run_ana_clean"  # delete FOLD after test as writes almost 1GB
0100 fi
0101 
0102 
0103 arg=${1:-$defarg}
0104 
0105 
0106 
0107 M1=1000000
0108 K2=100000
0109 
0110 #num=8
0111 num=$K2
0112 #num=$M1
0113 
0114 nrm=0,0,1
0115 #nrm=0,0,-1
0116 
0117 case $TEST in
0118     rng_sequence) num=$M1 ;;
0119     random_direction_marsaglia) num=$M1 ;;
0120     lambertian_direction) num=$M1 ;;
0121     randgaussq_shoot) num=$M1 ;;
0122      wavelength*) num=$M1 ;;
0123      randgaussq*) num=$M1 ;;
0124   scint_generate) num=$M1 ;;
0125   cerenkov_generate) num=$M1 ;;
0126    hemisphere_s_polarized|propagate_at_boundary_s_polarized) num=$M1 ;;
0127    hemisphere_p_polarized|propagate_at_boundary_p_polarized) num=$M1 ;;
0128    hemisphere_x_polarized|propagate_at_boundary_x_polarized) num=$M1 ;;
0129    propagate_at_multifilm_s_polarized) num=$M1;;
0130    propagate_at_multifilm_p_polarized) num=$M1;;
0131    propagate_at_multifilm_x_polarized) num=$M1;;
0132 
0133 esac
0134 
0135 
0136 case $TEST in
0137           X_rng_sequence)   script=rng_sequence.py   ;;
0138           rng_sequence)   script=QSimTest.py   ;;
0139            X_rng_sequence_with_skipahead)   script=rng_sequence_with_skipahead.py   ;;
0140 random_direction_marsaglia) script=random_direction_marsaglia.py ;;
0141    boundary_lookup_all)    script=boundary_lookup_all.py ;;
0142    boundary_lookup_water)  script=boundary_lookup_line.py ;;
0143    boundary_lookup_ls)     script=boundary_lookup_line.py ;;
0144        scint_generate)     script=scint_generate.py  ;;
0145     cerenkov_generate)     script=cerenkov_generate.py  ;;
0146 
0147    fill_state_0)           script=fill_state.py ;;
0148    fill_state_1)           script=fill_state.py ;;
0149    fill_state_cf)          script=fill_state_cf.py ;;
0150 
0151    hemisphere_s_polarized) script=hemisphere_polarized.py ;;
0152    hemisphere_p_polarized) script=hemisphere_polarized.py ;;
0153    hemisphere_x_polarized) script=hemisphere_polarized.py ;;
0154 
0155    propagate_at_boundary*) script=propagate_at_boundary.py ;;
0156    propagate_at_multifilm*) script=propagate_at_multifilm.py ;;
0157 
0158     lambertian_direction)  script=lambertian_direction.py ;;
0159          fake_propagate*)  script=fake_propagate.py ;;
0160          randgaussq_shoot) script=randgaussq_shoot.py ;;
0161             smear_normal*) script=smear_normal.py ;;
0162                         *) script=generic.py      ;;
0163 esac
0164 
0165 
0166 export NUM=${NUM:-$num}
0167 export NRM=${NRM:-$nrm}
0168 
0169 loglevels()
0170 {
0171     #export SEvent=INFO
0172     export SEvt=INFO
0173     #export QBnd=INFO
0174     #export QSim=INFO
0175     #export QEvt=INFO
0176     export QNonExisting=INFO
0177 }
0178 [ -n "$LOG" ] && loglevels
0179 
0180 
0181 export SPRD_BND=$(cat << EOV
0182 Water///Water
0183 Water///Water
0184 Water///Water
0185 Water///Water
0186 EOV
0187 )
0188 
0189 
0190 source fill_state.sh
0191 source ephoton.sh    # branching on TEST inside ephoton.sh
0192 source eprd.sh
0193 source dbg__.sh
0194 
0195 
0196 if [ "$TEST" == "smear_normal_sigma_alpha" ]; then
0197    export DBG_VALUE=0.1
0198 elif [ "$TEST" == "rng_sequence_with_skipahead" ]; then
0199 
0200    eventID=0
0201    export QSimTest__rng_sequence_with_skipahead__eventID=${QSimTest__rng_sequence_with_skipahead__eventID:-$eventID}
0202    export OPTICKS_EVENT_MODE=Nothing
0203 fi
0204 
0205 
0206 
0207 TMP=${TMP:-/tmp/$USER/opticks}
0208 export EBASE=$TMP/GEOM/$GEOM/QSimTest/ALL/p001
0209 
0210 vars="BASH_SOURCE arg TEST script NUM NRM FOLD GEOM TMP EBASE"
0211 
0212 if [ "${arg/info}" != "$arg" ]; then
0213     for var in $vars ; do printf "%30s : %s \n" "$var" "${!var}" ; done
0214 fi
0215 
0216 if [ "${arg/grab}" != "$arg" ]; then
0217     echo $BASH_SOURCE EBASE $EBASE
0218     source ../../bin/rsync.sh $EBASE
0219 fi
0220 
0221 if [ "${arg/run}" != "$arg" ]; then
0222    $bin
0223    [ $? -ne 0 ] && echo $msg run error && exit 1
0224 fi
0225 
0226 if [ "${arg/dbg}" != "$arg" ]; then
0227    dbg__ $bin
0228    [ $? -ne 0 ] && echo $msg dbg error && exit 2
0229 fi
0230 
0231 if [ "${arg/pdb}" != "$arg" ]; then
0232    echo $BASH_SOURCE pdb script $script
0233    ${IPYTHON:-ipython} --pdb -i $script
0234    [ $? -ne 0 ] && echo $msg pdb error && exit 2
0235 fi
0236 
0237 if [ "${arg/ana}" != "$arg" ]; then
0238    echo $BASH_SOURCE ana script $script
0239    ${PYTHON:-python} $script
0240    [ $? -ne 0 ] && echo $msg ana error && exit 3
0241 fi
0242 
0243 
0244 if [ "${arg/clean}" != "$arg" ]; then
0245    iwd=$PWD
0246    cd $(dirname $FOLD)
0247 
0248    if [ -d "$TEST" ]; then
0249        if [ ${#TEST} -gt 3 ]; then
0250            echo $msg : delete TEST [$TEST] folder from $(dirname $FOLD) namelength ${#TEST}
0251            rm -rf $TEST
0252        else
0253             echo $msg : TEST [$TEST] name too short ${#TEST} : NOT DELETING
0254        fi
0255    else
0256        echo $msg : TEST [$TEST] folder not present within $(dirname $FOLD)
0257    fi
0258    cd $iwd
0259 fi
0260 
0261 
0262 
0263 
0264 
0265 relative_stem(){   ## THIS IS USING OBSOLETE GEOCACHE PATHS
0266    local img=$1
0267 
0268    local geocache=${OPTICKS_GEOCACHE_PREFIX:-$HOME/.opticks}/geocache/
0269    local oktmp=/tmp/$USER/opticks/
0270 
0271    local rel
0272    case $img in
0273       ${geocache}*)  rel=${img/$geocache/} ;;
0274       ${oktmp}*)     rel=${img/$oktmp/} ;;
0275    esac
0276    rel=${rel/\.jpg}
0277    rel=${rel/\.png}
0278 
0279    echo $rel
0280 }
0281 
0282 
0283 if [ "${arg/OLDana}" != "$arg" ]; then
0284 
0285     # PYVISTA_KILL_DISPLAY envvar is observed to speedup exiting from ipython after pyvista plotting
0286     # see https://github.com/pyvista/pyvista/blob/main/pyvista/plotting/plotting.py
0287     export PYVISTA_KILL_DISPLAY=1
0288 
0289     if [ -f "$script" ]; then
0290 
0291         export FOLD="/tmp/QSimTest/$TEST"
0292 
0293         export EYE=-1,-1,1
0294         export LOOK=0,0,0
0295         export UP=0,0,1
0296         export PARA=1
0297 
0298         echo $msg invoking analysis script $script
0299         ${IPYTHON:-ipython} --pdb -i $script
0300         [ $? -ne 0 ] && echo $msg ana error && exit 2
0301 
0302 
0303         if [ -n "$PUB" ]; then
0304 
0305             png=$FOLD/figs/pvplt_polarized.png
0306             rel=$(relative_stem $png)
0307 
0308             if [ "$PUB" == "1" ]; then
0309                 ext=""
0310             else
0311                 ext="_${PUB}"
0312             fi
0313 
0314             s5p=/env/presentation/${rel}${ext}.png
0315             pub=$HOME/simoncblyth.bitbucket.io$s5p
0316 
0317             if [ -f "$png" ]; then
0318 
0319                 echo $msg PUB $PUB
0320                 echo $msg png $png
0321                 echo $msg rel $rel
0322                 echo $msg ext $ext
0323                 echo $msg pub $pub
0324                 echo $msg s5p $s5p
0325 
0326                 if [ -f "$pub" ]; then
0327                     echo $msg pub $pub exists already : not copying
0328                 elif [ "$ext" == "" ]; then
0329                     echo $msg set PUB to short descriptive string
0330                 else
0331                     mkdir -p $(dirname $pub)
0332                     echo $msg copy to pub $pub
0333                     cp $png $pub
0334                     echo
0335                     echo $msg s5p $s5p 1280px_720px
0336                 fi
0337             fi
0338         fi
0339 
0340 
0341     else
0342         echo $msg there is no analysis script $script
0343     fi
0344 fi
0345 
0346 exit 0
0347