Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash -l 
0002 cxs_msg="=== $BASH_SOURCE : "
0003 case $(uname) in 
0004    Linux)  argdef="run" ;; 
0005    Darwin) argdef="ana" ;;
0006 esac 
0007 cxs_arg=${1:-$argdef}
0008 
0009 BASH_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
0010 
0011 usage(){ cat << EOU
0012 cxs.sh : hybrid rendering/simulation machinery, eg creating 2D ray trace cross sections
0013 ========================================================================================
0014 
0015 DONT FOLLOW THIS : PREFER cxt_min.sh 
0016 
0017 
0018 TODO: partition creation and analysis more clearly... currently some 
0019       stuff comes from metadata written during creation and 
0020       cannot be updated during analysis
0021 
0022 ::
0023 
0024     ISEL=0,1,3,4,5 ./cxs.sh ana       # select which boundaries to include in plot 
0025 
0026     XX=-208,208 ZZ=-15.2,15.2 ./cxs.sh 
0027 
0028     NOMASK=1 ./cxs.sh
0029         Do not mask intersect positions by the limits of the genstep grid
0030         (so see distant intersects) 
0031 
0032     PVG=1 ./cxs.sh 
0033         Show the pyvista grid scale 
0034 
0035 
0036 Two envvars MOI and CEGS configure the gensteps.
0037 
0038 The MOI string has form meshName:meshOrdinal:instanceIdx 
0039 and is used to lookup the center extent from the CSGFoundry 
0040 geometry. Examples::
0041 
0042     MOI=Hama
0043     MOI=Hama:0:0   
0044     CEGS=16:0:9:200                 # nx:ny:nz:num_photons
0045     CEGS=16:0:9:200:17700:0:0:200   # nx:ny:nz:num_photons:cx:cy:cz:ew
0046 
0047 The CEGS envvar configures an *(nx,ny,nz)* grid from -nx->nx -ny->ny -nz->nz
0048 of integers which are used to mutiply the extent from the MOI center-extent.
0049 The *num_photons* is the number of photons for each of the grid gensteps.
0050 
0051 * as the gensteps are currently xz-planar it makes sense to use *ny=0*
0052 * to get a non-distorted jpg the nx:nz should follow the aspect ratio of the frame 
0053 
0054 ::
0055 
0056     In [1]: sz = np.array( [1920,1080] )
0057     In [5]: 9*sz/1080
0058     Out[5]: array([16.,  9.])
0059 
0060 Instead of using the center-extent of the MOI selected solid, it is 
0061 possible to directly enter the center-extent in integer mm for 
0062 example adding "17700:0:0:200"
0063 
0064 As the extent determines the spacing of the grid of gensteps, it is 
0065 good to set a value of slightly less than the extent of the smallest
0066 piece of geometry to try to get a genstep to land inside. 
0067 Otherwise inner layers can be missed. 
0068 
0069 EOU
0070 }
0071 
0072 
0073 export GEOM=${GEOM:-$geom}
0074 
0075 if [ -z "$moi" -o -z "$cegs" -o -z "$ce_offset" -o -z "$gridscale" ]; then 
0076 
0077     echo $cxs_msg the cxs.sh script must now be sourced from other scripts that define a set of local variables
0078     echo $cxs_msg see for example cxs_solidXJfixture.sh
0079 
0080     [ -z "$moi" ]  && echo $cxs_msg missing moi 
0081     [ -z "$cegs" ] && echo $cxs_msg missing cegs
0082     [ -z "$ce_offset" ] && echo $cxs_msg missing ce_offset
0083    # [ -z "$ce_scale" ] && echo $cxs_msg missing ce_scale
0084     [ -z "$gridscale" ] && echo $cxs_msg missing gridscale 
0085 
0086     exit 1     
0087 fi 
0088 
0089 
0090 cvd=0
0091 export CUDA_VISIBLE_DEVICES=${CVD:-$cvd}
0092 export CVDLabel="CVD${CUDA_VISIBLE_DEVICES}" 
0093 
0094 
0095 export MOI=${MOI:-$moi}
0096 export CEGS=${CEGS:-$cegs}
0097 export CE_OFFSET=${CE_OFFSET:-$ce_offset}
0098 #export CE_SCALE=${CE_SCALE:-$ce_scale}
0099 export GRIDSCALE=${GRIDSCALE:-$gridscale}
0100 export GSPLOT=${GSPLOT:-$gsplot}
0101 export NOTE=${NOTE:-$note}
0102 export NOTE1=${NOTE1:-$note1}
0103 
0104 export ISEL=${ISEL:-$isel}
0105 export XX=${XX:-$xx}
0106 export YY=${YY:-$yy}
0107 export ZZ=${ZZ:-$zz}
0108 export OPTICKS_GEOM=$GEOM 
0109 
0110 
0111 loglevels()
0112 {
0113     export Dummy=INFO
0114     export SEvt=INFO
0115     export CSGOptiX=INFO
0116 }
0117 loglevels
0118 
0119 
0120 
0121 
0122 
0123 
0124 
0125 IFS=: read -a cegs_arr <<< "$CEGS"
0126 
0127 # quotes on the in variable due to bug fixed in bash 4.3 according to 
0128 # https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
0129 
0130 cegs_elem=${#cegs_arr[@]}
0131 
0132 case $cegs_elem in 
0133    4) echo $cxs_msg 4 element CEGS $CEGS ;; 
0134    7) echo $cxs_msg 7 element CEGS $CEGS ;; 
0135    *) echo $cxs_msg ERROR UNEXPECTED $cegs_elem element CEGS $CEGS && exit 1  ;; 
0136 esac
0137 
0138 
0139 if [ "$(uname)" == "Linux" ]; then
0140     if [ -n "$cfbase" -a ! -d "$cfbase/CSGFoundry" ]; then
0141 
0142        echo $cxs_msg : ERROR cfbase $cfbase is defined signalling to use a non-standard CSGFoundry geometry 
0143        echo $cxs_msg : BUT no such CSGFoundry directory exists 
0144        echo $cxs_msg :
0145        echo $cxs_msg : Possibilities: 
0146        echo $cxs_msg :
0147        echo $cxs_msg : 1. you intended to use the standard geometry but the GEOM $GEOM envvar does not match any of the if branches 
0148        echo $cxs_msg : 2. you want to use a non-standard geometry but have not yet created it : do so as shown below
0149        echo $cxs_msg :
0150        echo $cxs_msg :    \"b7 \; cd ~/opticks/GeoChain\"  
0151        echo $cxs_msg :    \"gc \; GEOM=$GEOM ./translate.sh\" 
0152        echo $cxs_msg :   
0153        exit 1 
0154     fi 
0155 fi
0156 
0157 
0158 
0159 pkg=CSGOptiX
0160 bin=CSGOptiXSimtraceTest 
0161 export TMPDIR=/tmp/$USER/opticks
0162 export LOGDIR=$TMPDIR/$pkg/$bin
0163 mkdir -p $LOGDIR 
0164 
0165 
0166 if [ -n "$cfbase" ]; then 
0167     echo $cxs_msg cfbase $cfbase defined setting CFBASE to override standard geometry default 
0168     export CFBASE=${CFBASE:-$cfbase}   ## setting CFBASE only appropriate for non-standard geometry 
0169 fi 
0170 
0171 export OPTICKS_OUT_FOLD=${CFBASE:-$TMPDIR}/$pkg/$bin/$CVDLabel/$(CSGOptiXVersion)
0172 
0173 botline="MOI $MOI CEGS $CEGS GRIDSCALE $GRIDSCALE"
0174 
0175 
0176 [ -n "$ZOOM" ] && botline="$botline ZOOM $ZOOM"
0177 [ -n "$LOOK" ] && botline="$botline LOOK $LOOK"
0178 [ -n "$XX" ]   && botline="$botline XX $XX"
0179 [ -n "$YY" ]   && botline="$botline YY $YY"
0180 [ -n "$ZZ" ]   && botline="$botline ZZ $ZZ"
0181 
0182 
0183 topline="cxs.sh MOI $MOI CEGS $CEGS GRIDSCALE $GRIDSCALE"
0184 [ -n "$LOOKCE" ] && topline="$topline LOOKCE $LOOKCE"
0185 
0186 
0187 export BOTLINE="${BOTLINE:-$botline}"
0188 export TOPLINE="${TOPLINE:-$topline}"
0189 
0190 
0191 ## CAUTION : CURRENTLY THE BOTLINE and TOPLINE from generation which comes from metadata
0192 ##  trumps any changes from analysis running
0193 ## ... hmm that is kinda not appropriate for cosmetic presentation changes like differnt XX ZZ etc.. 
0194 
0195 vars="GEOM CFBASE LOGDIR BASH_FOLDER MOI CE_OFFSET CE_SCALE CXS_CEGS CXS_OVERRIDE_CE GRIDSCALE TOPLINE BOTLINE NOTE GSPLOT ISEL XX YY ZZ FOLD OPTICKS_GEOM OPTICKS_RELDIR OPTICKS_OUT_FOLD"
0196 cxs_dumpvars(){  local var ; local vars=$1 ; shift ; echo $* ; for var in $vars ; do printf "%20s : %s\n" "$var" "${!var}" ; done  ; }
0197 cxs_dumpvars "$vars" initial
0198 
0199 cxs_relative_stem()
0200 {
0201    local path=$1
0202    local geocache=$HOME/.opticks/geocache/
0203    local rel 
0204    case $path in 
0205       ${geocache}*)  rel=${path/$geocache/} ;;
0206    esac 
0207    rel=${rel/\.jpg}
0208    rel=${rel/\.png}
0209    echo $rel 
0210 }
0211 
0212 
0213 cxs_pub()
0214 {
0215     local msg="$FUNCNAME :"
0216     local cap_path=$1
0217     local cap_ext=$2
0218     local rel_stem=$(cxs_relative_stem ${cap_path})
0219 
0220     if [ "$PUB" == "1" ]; then 
0221         local extra=""    ## use PUB=1 to debug the paths 
0222     else
0223         local extra="_${PUB}" 
0224     fi 
0225 
0226     local s5p=/env/presentation/${rel_stem}${extra}${cap_ext}
0227     local pub=$HOME/simoncblyth.bitbucket.io$s5p
0228     local s5p_line="$s5p 1280px_720px"
0229 
0230     local vars="cap_path cap_ext rel_stem PUB extra s5p pub s5p_line"
0231     for var in $vars ; do printf "%20s : %s\n" $var "${!var}" ; done  
0232 
0233     mkdir -p $(dirname $pub)
0234 
0235     if [ "$PUB" == "" ]; then 
0236         echo $msg skipping copy : to do the copy you must set PUB to some descriptive string 
0237     elif [ "$PUB" == "1" ]; then 
0238         echo $msg skipping copy : to do the copy you must set PUB to some descriptive string 
0239     elif [ -f "$pub" ]; then 
0240         echo $msg published path exists already : NOT COPYING : delete it or set PUB to some different extra string to distinguish the name 
0241         echo $msg skipping copy : to do the copy you must set PUB to some descriptive string rather than just using PUB=1
0242     else
0243         echo $msg copying cap_path to pub 
0244         cp $cap_path $pub
0245         echo $msg add s5p_line to s5_background_image.txt
0246     fi 
0247 }
0248 
0249 
0250 
0251 bin=CSGOptiXSimtraceTest
0252 
0253 if [ "$(uname)" == "Linux" ]; then 
0254 
0255     if [ "${cxs_arg}" == "run" ]; then
0256 
0257         cd $LOGDIR 
0258         $GDB $bin 
0259         [ $? -ne 0 ] && echo $cxs_msg RUN ERROR at LINENO $LINENO && exit 1 
0260 
0261         source ${bin}_OUTPUT_DIR.sh || exit 1  
0262 
0263     elif [ "${cxs_arg}" == "dbg" ]; then 
0264 
0265         cd $LOGDIR 
0266         gdb $bin 
0267         [ $? -ne 0 ] && echo $cxs_msg RUN ERROR at LINENO $LINENO && exit 1 
0268 
0269         source ${bin}_OUTPUT_DIR.sh || exit 1  
0270 
0271 
0272     elif [ "${cxs_arg}" == "ana" ]; then 
0273 
0274         cd $LOGDIR 
0275         source ${bin}_OUTPUT_DIR.sh || exit 1  
0276         NOGUI=1 ${IPYTHON:-ipython} ${BASH_FOLDER}/tests/$bin.py 
0277 
0278     elif [ "${cxs_arg}" == "run_ana" ]; then 
0279 
0280         cd $LOGDIR 
0281         $GDB $bin
0282         [ $? -ne 0 ] && echo $cxs_msg RUN ERROR at LINENO $LINENO && exit 1 
0283         source ${bin}_OUTPUT_DIR.sh || exit 1  
0284 
0285         if [ -n "$PDB" ]; then
0286             NOGUI=1 ${IPYTHON:-ipython} --pdb -i ${BASH_FOLDER}/tests/$bin.py 
0287         else
0288             NOGUI=1 ${IPYTHON:-ipython}          ${BASH_FOLDER}/tests/$bin.py 
0289         fi 
0290 
0291     fi
0292 
0293 elif [ "$(uname)" == "Darwin" ]; then
0294 
0295     echo $cxs_msg Darwin $(pwd) LINENO $LINENO
0296 
0297 
0298     if [ "${cxs_arg}" == "grab" ]; then 
0299         echo $cxs_msg grab LINENO $LINENO 
0300         EXECUTABLE=$bin       source cachegrab.sh grab
0301         EXECUTABLE=CSGFoundry source cachegrab.sh grab
0302     else
0303         echo $cxs_msg cxs_arg $cxs_arg LINENO $LINENO
0304         EXECUTABLE=$bin       source cachegrab.sh env
0305 
0306         cxs_dumpvars "FOLD CFBASE" after cachegrab.sh env
0307 
0308         case ${cxs_arg} in 
0309            ana) ${IPYTHON:-ipython} --pdb -i ${BASH_FOLDER}/tests/$bin.py  ;; 
0310            pvcap) source pvcap.sh cap ;;  
0311            mpcap) source mpcap.sh cap ;;  
0312            pvpub) source pvcap.sh env ;;
0313            mppub) source mpcap.sh env ;;
0314         esac
0315 
0316         echo $cxs_msg cxs_arg $cxs_arg LINENO $LINENO
0317 
0318         if [ "${cxs_arg/pub}" != "${cxs_arg}" ]; then
0319            cxs_dumpvars "cxs_msg cxs_arg CAP_BASE CAP_REL CAP_PATH CAP_EXT" 
0320            cxs_pub $CAP_PATH $CAP_EXT 
0321         else
0322            echo not pub cxs_arg $cxs_arg
0323         fi 
0324     fi  
0325 
0326 fi 
0327 
0328 exit 0