Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:54

0001 #!/bin/bash -l 
0002 msg="=== $BASH_SOURCE :"
0003 usage(){ cat << EOU
0004 csg_geochain.sh : CPU Opticks equivalent to cxs_geochain.sh with OptiX on GPU using test/CSGIntersectSolidTest.cc tests/CSGIntersectSolidTest.py
0005 ==================================================================================================================================================
0006 
0007 The idea behind this is to provide a convenient way to test code primarily intended to run on GPU 
0008 in the more friendly debugging environment of the CPU.::
0009 
0010 
0011     PUB=unbalanced_ok ./csg_geochain.sh  ana 
0012 
0013 
0014     IXYZ=4,0,0 ./csg_geochain.sh  ana
0015         selecting single genstep with IXYZ 
0016 
0017     IXYZ=5,0,0 ./csg_geochain.sh  ana
0018 
0019     IXYZ=0,6,0 ./csg_geochain.sh  ana      
0020 
0021 
0022     SPUR=1 GEOM=CylinderFourBoxUnion_YX ./csg_geochain.sh ana
0023          56/20997 spurious intersects all exiting the cylinder 
0024          within the +Y and -X boxes
0025 
0026          Curious that are no such issues with the other two boxes
0027          despite the symmetry. 
0028 
0029          TODO: test with CSG balancing disabled
0030 
0031     SPUR=1 GEOM=AnnulusFourBoxUnion_YX ./csg_geochain.sh ana
0032           181/20997 spurious all exiting the cylinder with all 4 boxes
0033 
0034     SPUR=1 IXYZ=-6,0,0 GEOM=AnnulusFourBoxUnion_YX ./csg_geochain.sh ana
0035           select single genstep   
0036 
0037     SPUR=1 IXYZ=-6,0,0 IW=17 GEOM=AnnulusFourBoxUnion_YX SAVE_SELECTED_ISECT=1 ./csg_geochain.sh ana
0038 
0039     SELECTED_ISECT=/tmp/selected_isect.npy GEOM=AnnulusFourBoxUnion_YX ./csg_geochain.sh run
0040           run again just with selected isects, with CSGRecord enabled 
0041           will need to use same geometry to get same results     
0042 
0043     SPUR=1 IXYZ=-6,0,0 IW=17 GEOM=AnnulusFourBoxUnion_YX  ./csg_geochain.sh ana
0044 
0045 
0046     TMIN=50 ./csg_geochain.sh 
0047         NB can only change TMIN at C++ level not ana level 
0048 
0049         Note that TMIN is currently absolute, it is not extent relative like with cxr_geochain.sh  
0050         rendereing   
0051 
0052 
0053     IXYZ=8,0,0 TMIN=50 ./csg_geochain.sh ana
0054         at python analysis level the highlighted genstep can be changed using IXYZ 
0055         TMIN does nothing at analysis level the intersects from the prior run are loaded and plotted
0056            
0057     SXYZW=4,4,0,80 ./csg_geochain.sh run
0058         re-run with a single photon 
0059         do this after recompiling with DEBUG flag allows to see the details of the single photon 
0060 
0061 EOU
0062 }
0063 
0064 geom=AltXJfixtureConstruction_YZ
0065 #geom=AltXJfixtureConstruction_XZ
0066 #geom=AltXJfixtureConstruction_XY
0067 #geom=AltXJfixtureConstructionU_XY
0068 
0069 
0070 #geom=UnionBoxSphere_XY
0071 #geom=UnionListBoxSphere_XY
0072 #geom=UnionLLBoxSphere_XY
0073 
0074 #geom=AnnulusBoxUnion_XY
0075 #geom=AnnulusTwoBoxUnion_XY
0076 #geom=AnnulusOtherTwoBoxUnion_XY
0077 
0078 #geom=AnnulusFourBoxUnion_XY
0079 #geom=AnnulusFourBoxUnion_YX
0080 #geom=CylinderFourBoxUnion_YX
0081 #geom=AnnulusCrossTwoBoxUnion_YX
0082 
0083 #geom=BoxFourBoxUnion_YX
0084 #geom=BoxFourBoxContiguous_YX
0085 #geom=SphereWithPhiCutDEV_YX
0086 
0087 #geom=BoxCrossTwoBoxUnion_YX
0088 #geom=BoxThreeBoxUnion_YX
0089 
0090 #geom=XJfixtureConstruction_YZ
0091 #geom=XJfixtureConstruction_XZ
0092 #geom=XJfixtureConstruction_XY
0093 
0094 #geom=iphi_YX
0095 
0096 #geom=ithe_XZ
0097 #geom=ithl_XZ
0098 
0099 #geom=ithe_YZ
0100 #geom=ithl_YZ
0101 
0102 #geom=ithe_XYZ
0103 #geom=ithl_XYZ
0104 
0105 #geom=GeneralSphereDEV_XZ
0106 #geom=GeneralSphereDEV_XYZ
0107 #geom=GeneralSphereDEV_XZ
0108 #geom=GeneralSphereDEV_YZ
0109 #geom=GeneralSphereDEV_XY
0110 
0111 #geom=OverlapBoxSphere_XY
0112 #geom=ContiguousBoxSphere_XY
0113 #geom=DiscontiguousBoxSphere_XY
0114 #geom=IntersectionBoxSphere_XY
0115 
0116 #geom=OverlapThreeSphere_XY
0117 #geom=ContiguousThreeSphere_XY
0118 
0119 
0120 catgeom=$(cat ~/.opticks/GEOM.txt 2>/dev/null | grep -v \#) && [ -n "$catgeom" ] && echo $msg catgeom $catgeom override of default geom $geom && geom=$(echo ${catgeom}) 
0121 export GEOM=${GEOM:-$geom}
0122 gcn=${GEOM%%_*}   ## name up to the first underscore, assuming use of axis suffix  _XZ _YZ _XY _ZX _ZY _YX 
0123 
0124 cfbase=$(SOpticksResourceTest --cfbase)
0125 
0126 #  moved this into SOpticksResource::CFBase by adding GEOM envvar sensitivity there 
0127 #
0128 #if [ "$(uname)" == "Darwin" ] ; then
0129 #   cfbase=$TMP/GeoChain_Darwin/$gcn 
0130 #else
0131 #   cfbase=$TMP/GeoChain/$gcn 
0132 #fi 
0133 
0134 
0135 case $gcn in 
0136    AnnulusFourBoxUnion)     gridscale=0.1  ;; 
0137    AnnulusCrossTwoBoxUnion) gridscale=0.1  ;; 
0138   CylinderFourBoxUnion)     gridscale=0.1  ;; 
0139    BoxCrossTwoBoxUnion)     gridscale=0.07 ;; 
0140    BoxThreeBoxUnion)        gridscale=0.07 ;; 
0141    BoxFourBoxUnion)         gridscale=0.07 ;; 
0142                      *)     gridscale=0.15 ;;
0143 esac
0144 
0145 case $GEOM in 
0146        AnnulusFourBoxUnion_YX) note="see spurious with IXYZ=5,0,0 and 0,6,0 " ;;
0147    AnnulusCrossTwoBoxUnion_YX) note="no spurious despite same apparent geom on ray path" ;;
0148       CylinderFourBoxUnion_YX) note="see spurious" ;;
0149            BoxThreeBoxUnion_YX) note="no spurious" ;; 
0150            BoxFourBoxUnion_YX) note="see spurious in the +Y and -X small boxes " ;; 
0151           GeneralSphereDEV_XY) note="phicut bug from \"t_cand <  t_min\" that should be \"t_cand <= t_min \" : SPHI selects spurious in bad phi range "  ;;
0152                             *) note="" ;;
0153 esac
0154 
0155 case $GEOM in 
0156    *_XYZ)   is3d=1 ;; 
0157        *)   is3d=0 ;;
0158 esac
0159 
0160 if [ $is3d -eq 1 ]; then 
0161    echo $msg is3d for GEOM $GEOM setting NO_GS and EDL 
0162    export NO_GS=1
0163    export ESL=1
0164 fi 
0165 
0166 
0167 dx=0
0168 dy=0
0169 dz=0
0170 
0171 case $GEOM in
0172       XJfixtureConstruction*)  dz=1 ;;
0173    AltXJfixtureConstruction*)  dz=1 ;;
0174 esac
0175 
0176 DZ=${DZ:-$dz}
0177 pho=${PHO:--100} 
0178 
0179 case $pho in
0180   -*)  echo $msg using regular bicycle spoke photon directions ;; 
0181    *)  echo $msg using random photon directions                ;;
0182 esac
0183 
0184 case $GEOM in  
0185    *_XZ) cegs=16:0:9:$dx:$dy:$DZ:$pho  ;;  
0186    *_YZ) cegs=0:16:9:$dx:$dy:$DZ:$pho  ;;  
0187    *_XY) cegs=16:9:0:$dx:$dy:$DZ:$pho  ;;  
0188    *_ZX) cegs=9:0:16:$dx:$dy:$DZ:$pho  ;;  
0189    *_ZY) cegs=0:9:16:$dx:$dy:$DZ:$pho  ;;  
0190    *_YX) cegs=9:16:0:$dx:$dy:$DZ:$pho  ;;  
0191    *_XYZ) cegs=9:16:9:$dx:$dy:$DZ:$pho ;;  
0192        *) echo $msg UNEXPECTED SUFFIX FOR GEOM $GEOM WHICH DOES NOT END WITH ONE OF : _XZ _YZ _XY _ZX _ZY _YX _XYZ  && exit 1   ;; 
0193 esac
0194 
0195 echo $msg GEOM $GEOM gcn $gcn gridscale $gridscale ixiyiz $ixiyiz
0196 
0197 
0198 topline="GEOM=$GEOM ./csg_geochain.sh "
0199 [ -n "$SPHI" ] && topline="SPHI=$SPHI $topline" 
0200 [ -n "$IXYZ" ] && topline="IXYZ=$IXYZ $topline" 
0201 [ -n "$SXYZW" ] && topline="SXYZW=$SXYZW $topline" 
0202 [ "$DZ" != "0" ] && topline="DZ=$DZ $topline"
0203 [ -n "$ZOOM" ] && topline="ZOOM=$ZOOM $topline" 
0204 
0205 
0206 cmdline="GEOM=$GEOM ./csg_geochain.sh "
0207 [ -n "$SPHI" ] && cmdline="SPHI=$SPHI $cmdline" 
0208 [ -n "$IXYZ" ] && cmdline="IXYZ=$IXYZ $cmdline" 
0209 [ -n "$SPUR" ] && cmdline="SPUR=$SPUR $cmdline" 
0210 [ "$DZ" != "0" ] && cmdline="DZ=$DZ $cmdline"
0211 [ -n "$ZOOM" ] && cmdline="ZOOM=$ZOOM $cmdline" 
0212 
0213 export CMDLINE=$cmdline
0214 export NOTE=$note 
0215 export GRIDSCALE=${GRIDSCALE:-$gridscale}
0216 export CEGS=${CEGS:-$cegs}
0217 export CFBASE=${CFBASE:-$cfbase}  ## moved GEOM sensitivity into SOpticksResource::CFBase : BUT still need this for the script
0218 export CEGS=${CEGS:-$cegs}
0219 export TOPLINE="$topline"
0220 export BOTLINE="$note"
0221 export THIRDLINE="CEGS=$CEGS"
0222 
0223 check_cegs()
0224 {
0225     local msg="=== $FUNCNAME :"
0226     IFS=: read -a cegs_arr <<< "$CEGS"
0227     local cegs_elem=${#cegs_arr[@]}
0228 
0229     case $cegs_elem in
0230        4) echo $msg 4 element CEGS $CEGS ;;
0231        7) echo $msg 7 element CEGS $CEGS ;;
0232        *) echo $msg ERROR UNEXPECTED $cegs_elem element CEGS $CEGS && return 1  ;;
0233     esac
0234     return 0 
0235 }
0236 
0237 
0238 check_cfbase_how_to_create(){ cat << EOH
0239 
0240 How to Create CSGFoundry Geometry
0241 ======================================
0242 
0243 A. From converted G4VSolid 
0244 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0245 
0246 Apply GeoChain conversion to a named geometry::
0247 
0248     b7  # when using OptiX 7
0249     cd ~/opticks/GeoChain     # or use "gc" shortcut function 
0250     GEOM=${GEOM%%_*} ./translate.sh 
0251 
0252 
0253 B. Directly from CSGSolid/CSGPrim/CSGNode
0254 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0255 
0256 Create and persists into CSGFoundry folders one OR all CSGMaker solids::
0257 
0258     cd ~/opticks/CSG
0259 
0260     CSGMakerTest     
0261     GEOM=${GEOM%%_*} CSGMakerTest
0262 
0263 Alternatively use the script::
0264 
0265     cd ~/opticks/CSG
0266     ./CSGMakerTest.sh  # gets GEOM value from ~/.opticks/GEOM.txt if that file exists
0267 
0268 
0269 EOH
0270 }
0271 
0272 
0273 check_cfbase()
0274 {
0275     local msg="=== $FUNCNAME :"
0276     if [ -n "$cfbase" -a ! -d "$cfbase/CSGFoundry" ]; then
0277 
0278        echo $msg : ERROR cfbase $cfbase is defined signalling to use a non-standard CSGFoundry geometry 
0279        echo $msg : BUT no such CSGFoundry directory exists 
0280        echo $msg :
0281        echo $msg : Possibilities: 
0282        echo $msg :
0283        echo $msg : 1. you intended to use the standard geometry but the GEOM $GEOM envvar does not match any of the if branches 
0284        echo $msg : 2. you want to use a non-standard geometry but have not yet created it
0285        echo $msg :
0286        check_cfbase_how_to_create 
0287        return 1
0288     fi
0289     return 0 
0290 }
0291 
0292 check_cfbase_file()
0293 {
0294     local msg="=== $FUNCNAME :"
0295     if [ -n "$cfbase" -a -d "$cfbase/CSGFoundry" -a ! -f "$cfbase/CSGFoundry/meshname.txt" ]; then
0296        echo $msg : ERROR cfbase $cfbase is defined and the $cfbase/CSGFoundry directory exists
0297        echo $msg : BUT it misses expected files such as $cfbase/CSGFoundry/meshname.txt 
0298        echo $msg :
0299        check_cfbase_how_to_create 
0300        return 1 
0301     fi 
0302     return 0 
0303 }
0304 
0305 dumpvars(){ for var in $* ; do printf "%20s : %s \n" $var "${!var}" ; done ; }
0306 
0307 check_cegs        || exit 1 
0308 check_cfbase      || exit 1 
0309 check_cfbase_file || exit 1 
0310 dumpvars GEOM CEGS GRIDSCALE TOPLINE BOTLINE CFBASE NOTE IXYZ 
0311 
0312 bin=CSGIntersectSolidTest
0313 script=tests/CSGIntersectSolidTest.py 
0314 
0315 arg=${1:-run_ana}
0316 
0317 if [ "${arg/dump}" != "$arg" ]; then 
0318    echo $msg CSGGeometryTest dump
0319    CSGGeometryTest
0320    exit 0 
0321 
0322 elif [ "${arg/run}" != "$arg" ]; then
0323 
0324     if [ -n "$DEBUG" ]; then 
0325         echo $msg running binary $bin under debugger
0326         if [ "$(uname)" == "Darwin" ]; then
0327             lldb__ $bin
0328         else
0329             gdb $bin
0330         fi 
0331         [ $? -ne 0 ] && echo $msg error while running binary $bin under debugger  && exit 1
0332     else
0333         echo $msg running binary $bin
0334         $bin
0335         [ $? -ne 0 ] && echo $msg error while running binary $bin  && exit 1
0336     fi 
0337 fi
0338 
0339 if [ "${arg/ana}" != "$arg" ]; then
0340     echo $msg running script $script
0341     ${IPYTHON:-ipython} --pdb -i $script
0342     [ $? -ne 0 ] && echo $msg script error && exit 2
0343 
0344     figdir=$cfbase/$bin/$GEOM/figs
0345     ls -l $figdir 
0346 
0347     if [ -n "$PUB" ]; then 
0348 
0349        reldir=/env/presentation/CSG/$bin/$GEOM/figs 
0350        pubdir=$HOME/simoncblyth.bitbucket.io$reldir
0351 
0352        figname=out.png 
0353        pubname=${GEOM}_${PUB}.png       
0354 
0355        echo $msg figdir $figdir
0356        echo $msg reldir $reldir
0357        echo $msg pubdir $pubdir
0358        echo $msg pubname $pubname
0359 
0360        if [ ! -d "$pubdir" ]; then 
0361           mkdir -p $pubdir
0362        fi  
0363 
0364        cmd="cp $figdir/$figname $pubdir/$pubname"
0365        echo $msg cmd $cmd
0366        eval $cmd
0367        echo $msg add below with a title to s5_background_image.txt for presenation 
0368        echo $msg $reldir/$pubname 1280px_720px
0369     fi 
0370 fi
0371 
0372 exit 0