Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 cxt_min.sh : Simtrace Geometry Intersect Creation and Plotting
0004 ===============================================================
0005 
0006 ::
0007 
0008      GSGRID=0 KEY=blue,orange,lightblue cxt_min.sh pdb
0009      GSGRID=0 GRID=1 GLOBAL=1 XKEY=blue,orange,lightblue cxt_min.sh pdb
0010      GSGRID=0 GRID=1 GLOBAL=1 KEY=blue,lightblue,cornflowerblue cxt_min.sh pdb
0011      GSGRID=0 GRID=0 GLOBAL=0 KEY=blue,lightblue,cornflowerblue,orange cxt_min.sh pdb
0012 
0013      GSGRID=0 GRID=0 GLOBAL=0 XKEY=blue,lightblue,cornflowerblue,orange KEY=magenta cxt_min.sh pdb
0014      GSGRID=0 GRID=0 GLOBAL=0 KEY=blue,lightblue,cornflowerblue,orange,magenta,tomato cxt_min.sh pdb
0015          ## illuminating re the Tyvek:magenta,tomato L shape at top of LowerChimney
0016 
0017      PRIMTAB=1 NORMAL=1 cxt_min.sh pdb
0018 
0019      PRIMTAB=1 NORMAL=1 NORMAL_FILTER=100 KEY=~yellow,green ./cxt_min.sh pdb
0020            ## inverted key selection
0021 
0022 
0023 TODO: add option to draw a spinkle of intersect normal direction arrows
0024 
0025 
0026 
0027 Issue
0028 ------
0029 
0030 LOG=1 shows are writing to different dir from MFOLD where python looks::
0031 
0032     /data1/blyth/tmp/GEOM/J25_4_0_opticks_Debug/CSGOptiXTMTest/ALL0_no_opticks_event_name/A000
0033     /data1/blyth/tmp/GEOM/J25_4_0_opticks_Debug/CSGOptiXTMTest/PMT_20inch_veto:0:1000/A000
0034 
0035 
0036 
0037 Coincident surface checking
0038 ------------------------------
0039 
0040 Take a very close look, will see color variation as zoom
0041 in/out when there are coincident intersects with different
0042 boundaries
0043 
0044 
0045 
0046 Former label "CSGOptiXTMTest Simtrace minimal executable and script for shakedown"
0047 but has become the standard simtrace script.
0048 Uses CSGOptiXTMTest which just does "CSGOptiX::SimtraceMain()".
0049 
0050 Envar controls:
0051 
0052 GEOM
0053    picks the geometry together with ${GEOM}_CFBaseFromGEOM
0054 
0055 MOI
0056    specify the frame in which simtrace gensteps will be generated,
0057    which sets the region where most of the intersects will be found
0058 
0059 CEGS
0060    "CE-center-extent-Gensteps" specifies orientatation of the grid of
0061    gensteps and the number of simtrace rays from each genstep origin
0062 
0063 
0064 Usage pattern assuming analysis python environment with
0065 matplotlib and/or pyvista on laptop::
0066 
0067    cxt_min.sh info_run               ## on workstation
0068    cxt_min.sh grab                   ## on laptop
0069    GRID=1 MODE=2 cxt_min.sh ana      ## on laptop
0070 
0071 
0072 Command arguments:
0073 
0074 info
0075    output many vars
0076 fold
0077    output just $FOLD where simtrace SEvt are persisted
0078 run
0079    executes the CSGOptiXTMTest executable with main being just "CSGOptiX::SimtraceMain()"
0080 
0081    1. loads envvar configured geometry
0082    2. generates envvar configured simtrace gensteps
0083    3. runs CSGOptiX:simtrace which uses OptiX on GPU to intersect
0084       simtrace rays with the gometry, saving them into the simtrace array
0085    4. saves SEVt including simtrace array to $FOLD
0086 
0087 dbg
0088    runs the above under gdb
0089 
0090 brab
0091    old grab for rsyncing the SEvt FOLD between machines
0092 grab
0093    rsync an SEvt FOLD from remote to local machine
0094 
0095 
0096 pdb
0097    ${IPYTHON:-ipython} plotting of simtrace intersects, typically
0098    giving 2D cross section through geometry with matplotlib (MODE:2)
0099    OR 3D intersect view with pyvista (MODE:3)
0100 
0101 ana
0102    as above but with ${PYTHON:-python}
0103 
0104 
0105 About IPYTHON/PYTHON ipython/python overrides
0106 -----------------------------------------------
0107 
0108 "Official" python environments might not include the
0109 matplotlib/pyvista plotting packages which
0110 will cause MODE 2/3 to give errors for "pdb" and "ana".
0111 Workaround this by defining IPYTHON/PYTHON envvars
0112 to pick a python install (eg from miniconda)
0113 which does include the plotting libraries.
0114 
0115 matplotlib wayland warning but pdb succeeds to plot
0116 ------------------------------------------------------
0117 
0118 ::
0119 
0120    qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
0121 
0122 
0123 EOU
0124 }
0125 
0126 cd $(dirname $(realpath $BASH_SOURCE))
0127 script=$(realpath $PWD/cxt_min.py)   ## use python script that is sibling to the bash script
0128 
0129 allarg="info_fold_run_dbg_brab_grab_ana"
0130 
0131 defarg=info_run_info_pdb
0132 [ -n "$BP" ] && defarg="info_dbg"
0133 arg=${1:-$defarg}
0134 arg2=$2
0135 
0136 bin=CSGOptiXTMTest   ## just calls CSGOptiX::SimtraceMain()
0137 which_bin=$(which $bin)
0138 
0139 External_CFBaseFromGEOM=${GEOM}_CFBaseFromGEOM
0140 if [ -n "$GEOM" -a -n "${!External_CFBaseFromGEOM}" -a -d "${!External_CFBaseFromGEOM}" -a -f "${!External_CFBaseFromGEOM}/CSGFoundry/prim.npy" ]; then
0141     ## distributed usage : where have one fixed geometry for each distribution
0142     echo $BASH_SOURCE - External GEOM setup detected
0143     vv="External_CFBaseFromGEOM ${External_CFBaseFromGEOM}"
0144     for v in $vv ; do printf "%40s : %s \n" "$v" "${!v}" ; done
0145 else
0146     ## development source tree usage : where need to often switch between geometries
0147     source ~/.opticks/GEOM/GEOM.sh   # sets GEOM envvar, use GEOM bash function to setup/edit
0148 fi
0149 
0150 source $HOME/.opticks/GEOM/MOI.sh 2>/dev/null  ## optionally sets MOI envvar, use MOI bash function to setup/edit
0151 source $HOME/.opticks/GEOM/CUR.sh 2>/dev/null  ## optionally define CUR_ bash function, for controlling directory for screenshots
0152 source $HOME/.opticks/GEOM/EVT.sh 2>/dev/null  ## optionally define AFOLD and/or BFOLD for adding event tracks to simtrace plots
0153 
0154 tmp=/tmp/$USER/opticks
0155 TMP=${TMP:-$tmp}
0156 
0157 mode=3
0158 eye=0,10000,0
0159 
0160 export MODE=${MODE:-$mode}
0161 export EYE=${EYE:-$eye}
0162 
0163 
0164 export EVT=${EVT:-A000}
0165 export BASE=$TMP/GEOM/$GEOM
0166 export BINBASE=$BASE/$bin
0167 export LOGDIR=$BINBASE/$MOI
0168 
0169 #rel=${MOI:-0}
0170 rel=ALL0_no_opticks_event_name   ## SOMEHOW THE DIRECTORY WRITTEN TO HAS CHANGED ?
0171 export MFOLD=$TMP/GEOM/$GEOM/$bin/$rel/$EVT
0172 
0173 
0174 export SCRIPT=$(basename $BASH_SOURCE)
0175 SCRIPT=${SCRIPT/.sh}
0176 
0177 version=1
0178 VERSION=${VERSION:-$version}
0179 
0180 export OPTICKS_EVENT_MODE=DebugLite
0181 export OPTICKS_INTEGRATION_MODE=1
0182 
0183 mkdir -p $LOGDIR
0184 cd $LOGDIR
0185 LOGNAME=$bin.log
0186 
0187 
0188 ## see SFrameGenstep::StandardizeCEGS for CEGS/CEHIGH [4]/[7]/[8] layouts
0189 
0190 export CEGS=16:0:9:2000   # [4] XZ default
0191 #export CEGS=16:0:9:1000  # [4] XZ default
0192 #export CEGS=16:0:9:100   # [4] XZ reduce rays for faster rsync
0193 #export CEGS=16:9:0:1000  # [4] try XY
0194 
0195 export CEHIGH_0=-16:16:0:0:-4:4:2000:4
0196 export CEHIGH_1=-16:16:0:0:4:8:2000:4
0197 
0198 #export CEHIGH_0=16:0:9:0:0:10:2000     ## [7] dz:10 aim to land another XZ grid above in Z 16:0:9:2000
0199 #export CEHIGH_1=-4:4:0:0:-9:9:2000:5   ## [8]
0200 #export CEHIGH_2=-4:4:0:0:10:28:2000:5  ## [8]
0201 
0202 
0203 
0204 ## base photon count without any CEHIGH for 16:0:9:2000 is (2*16+1)*(2*9+1)*2000 = 1,254,000
0205 #export CE_OFFSET=CE    ## offsets the grid by the CE
0206 
0207 logging(){
0208     type $FUNCNAME
0209     export CSGOptiX=INFO
0210     export QEvt=INFO
0211     #export QSim=INFO
0212     #export SFrameGenstep=INFO
0213     #export CSGTarget=INFO
0214     #export SEvt=INFO
0215     export SEvt__LIFECYCLE=INFO
0216 }
0217 
0218 debug()
0219 {
0220     type $FUNCNAME
0221     export CSGFoundry__getFrameE_VERBOSE=1
0222     export SEvt__FRAME=1
0223 }
0224 
0225 [ "$LOG" == "1" ] && logging
0226 [ "$DBG" == "1" ] && debug
0227 
0228 
0229 _CUR=GEOM/$GEOM/$SCRIPT/${MOI//:/_}
0230 
0231 vars="BASH_SOURCE script bin which_bin allarg defarg arg GEOM ${GEOM}_CFBaseFromGEOM MFOLD MOI SCRIPT _CUR LOG LOGDIR BASE CUDA_VISIBLE_DEVICES CEGS TITLE"
0232 
0233 ## define TITLE based on ana/pdb control envvars
0234 title="cxt_min.sh pdb"
0235 ee="LINE GLOBAL PRESEL KEY NORMAL NORMAL_FILTER GRID GSGRID PRIMTAB"
0236 for e in $ee ; do
0237    #printf "%20s : %s \n" "$e" "${!e}"
0238    [ -n "${!e}" ] && title="$e=${!e} $title"
0239 done
0240 export TITLE="$title"
0241 
0242 
0243 if [ "${arg/info}" != "$arg" ]; then
0244    for var in $vars ; do printf "%20s : %s \n" "$var" "${!var}" ; done
0245 fi
0246 
0247 if [ "${arg/fold}" != "$arg" ]; then
0248     echo $FOLD
0249 fi
0250 
0251 if [ "${arg/ls}" != "$arg" ]; then
0252     ff="MFOLD"
0253     for f in $ff ; do printf "%20s : ls -alst %s \n" "$f" "${!f}"  && ls -alst ${!f} ; done
0254 fi
0255 
0256 
0257 if [ "${arg/run}" != "$arg" -o "${arg/dbg}" != "$arg" ]; then
0258 
0259    if [ -f "$LOGNAME" ]; then
0260        echo $BASH_SOURCE : run/dbg : delete prior LOGNAME $LOGNAME
0261        rm "$LOGNAME"
0262    fi
0263 
0264    if [ "${arg/run}" != "$arg" ]; then
0265        $bin
0266    elif [ "${arg/dbg}" != "$arg" ]; then
0267        source dbg__.sh
0268        dbg__ $bin
0269    fi
0270    [ $? -ne 0 ] && echo $BASH_SOURCE run/dbg error && exit 1
0271 fi
0272 
0273 
0274 if [ "${arg/brab}" != "$arg" -o "${arg/list}" != "$arg" -o "${arg/pub}" != "$arg" ]; then
0275     ## THIS OLD BASE_grab.sh SYNCS TOO MUCH : BUT IT DOES OTHER THINGS LIKE list and pub
0276     source BASE_grab.sh $arg
0277 fi
0278 
0279 if [ "${arg/grab}" != "$arg" ]; then
0280     source rsync.sh $MFOLD
0281 fi
0282 
0283 
0284 
0285 if [ "${arg/open}" != "$arg" ]; then
0286     # open to define current context string which controls where screenshots are copied to
0287     CUR_open ${_CUR}
0288 fi
0289 
0290 if [ "${arg/pdb}" != "$arg" ]; then
0291     ${IPYTHON:-ipython} --pdb -i $script
0292 fi
0293 
0294 if [ "${arg/ana}" != "$arg" ]; then
0295     ${PYTHON:-python} $script
0296 fi
0297 
0298 if [ "${arg/close}" != "$arg" ]; then
0299     # close to invalidate the context
0300     CUR_close
0301 fi
0302 
0303 if [ "$arg" == "touch"  ]; then
0304     if [ -n "$arg2" ]; then
0305         CUR_touch "$arg2"
0306     else
0307         echo $BASH_SOURCE:touch needs arg2 datetime accepted by CUR_touch eg "cxt_min.sh touch 11:00"
0308     fi
0309 fi
0310 
0311 if [ "${arg/cfg}" != "$arg" ]; then
0312     cfgpath=$(realpath ~/.opticks/GEOM/cxt_min.ini)
0313     cmd="vim $cfgpath"
0314     echo $cmd
0315     eval  $cmd
0316 fi
0317 
0318 
0319 
0320