Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 cxr_min.sh : Ray trace geometry rendering script
0004 ====================================================
0005 
0006 
0007 Bash args
0008 ------------
0009 
0010 info
0011    dump vars
0012 
0013 open
0014    write context file, use this to control where screenshots are copied to, accepts 2nd
0015    argument to backdate the context opening, eg::
0016 
0017         cxr_min.sh open "09:00"
0018         cxr_min.sh open "Fri Aug 22 09:00"
0019 
0020         EVT # set EVT envvar to identify AFOLD/BFOLD or just to identify some snapshots
0021         cxr_min.sh open "yesterday 09:00"
0022 
0023         pic   # lists screenshots within the context
0024 
0025 run
0026    run executable
0027 
0028 dbg
0029    run under gdb
0030 
0031 close
0032    delete context file
0033 
0034 
0035 
0036 Notes
0037 ------
0038 
0039 
0040 Formerly described as "minimal script for shakedown"
0041 but has become the first visualization script to use.
0042 This uses one of two executables:
0043 
0044 CSGOptiXRenderInteractiveTest
0045    interactive ray trace executable using OpenGL/CUDA interop
0046 
0047 CSGOptiXRMTest
0048    single image ray trace executable with no OpenGL dependency is
0049    used when SNAP envvar is defined
0050 
0051 
0052 Related for debug:
0053 
0054 sysrap/tests/SGLM_set_frame_test.sh
0055    fast standalone SGLM::set_frame cycling using persisted sframe
0056 
0057 Example commandlines using installed script::
0058 
0059     EYE=0.2,0.2,0.2 TMIN=0.1 cxr_min.sh
0060     EYE=0.3,0.3,0.3 TMIN=0.1 cxr_min.sh
0061 
0062     ELV=t:Water_solid,Rock_solid  cxr_min.sh
0063 
0064     ELV=t:sWorld,sBottomRock,sTopRock,sExpHall,sExpRockBox,sDomeRockBox,sAirGap,sDeadWater_shell,sTyvek_shell,sOuterWaterPool,sPoolLining MOI=sTarget EYE=0,-2,0  cxr_min.sh
0065        ## excluding large volumes can be illustrative, however must not remove the MOI volume
0066 
0067 
0068     MOI=PMT_20inch_veto:0:1000 cxr_min.sh
0069 
0070     EMM=2,3,4 EYE=3,3,0 cxr_min.sh
0071 
0072 
0073 Animation, lowering T1 from default of full range slows down the animation::
0074 
0075     EYE=0,2,0 T1=10 cxr_min.sh
0076 
0077 
0078 
0079 Use ELV to exclude virtual PMT wrapper volumes::
0080 
0081     ELV=t:HamamatsuR12860sMask_virtual,NNVTMCPPMTsMask_virtual,mask_PMT_20inch_vetosMask_virtual cxr_min.sh
0082 
0083 
0084 EMM EnabledMergedMesh examples selecting compound solids::
0085 
0086     EMM=0, cxr_min.sh   ## only 0, "rem"
0087 
0088     EMM=t0, cxr_min.sh    ## exclude 0 "rem"
0089     EMM=t:0, cxr_min.sh   ## exclude 0 "rem"
0090 
0091     EMM=10, cxr_min.sh   ## only 10 "tri"
0092 
0093     EMM=10  cxr_min.sh   ## NB: WITHOUT COMMA IS VERY DIFFERENT TO ABOVE : BIT PATTERN FROM DECIMAL 10
0094 
0095     EMM=1,2,3,4 cxr_min.sh
0096 
0097     EMM=1,2,3,4,5,6,7,8,9 cxr_min.sh
0098 
0099 
0100 NB presence of comma in EMM switches to bit position input, not binary value
0101 
0102 
0103 EOU
0104 }
0105 
0106 cd $(dirname $(realpath $BASH_SOURCE))
0107 export SCRIPT=cxr_min
0108 
0109 defarg=run_info
0110 [ -n "$BP" ] && defarg=dbg_info
0111 arg=${1:-$defarg}
0112 arg2=$2
0113 
0114 
0115 bin=CSGOptiXRenderInteractiveTest
0116 [ -n "$SNAP" ] && bin=CSGOptiXRMTest
0117 which_bin=$(which $bin)
0118 
0119 logging(){
0120    type $FUNCNAME
0121    #export CSGFoundry__Load_DUMP=1   # report the directory loaded
0122    #export CSGOptiX__prepareParamRender_DEBUG=1
0123    #export SGLM__updateProjection_DEBUG=1
0124    #export CSGFoundry=INFO
0125    #export CSGOptiX=INFO
0126    #export PIP=INFO
0127    #export SOpticksResource=INFO
0128    export SBT=INFO
0129 }
0130 [ -n "$LOG" ] && logging
0131 
0132 
0133 anim()
0134 {
0135    type $FUNCNAME
0136    export SGLM__init_time_DUMP=1
0137 }
0138 [ -n "$ANIM" ] && anim
0139 
0140 
0141 
0142 
0143 
0144 
0145 External_CFBaseFromGEOM=${GEOM}_CFBaseFromGEOM
0146 if [ -n "$GEOM" -a -n "${!External_CFBaseFromGEOM}" -a -d "${!External_CFBaseFromGEOM}" -a -f "${!External_CFBaseFromGEOM}/CSGFoundry/prim.npy" ]; then
0147     echo $BASH_SOURCE - External GEOM setup detected
0148     vv="External_CFBaseFromGEOM ${External_CFBaseFromGEOM}"
0149     for v in $vv ; do printf "%40s : %s \n" "$v" "${!v}" ; done
0150 else
0151     source ~/.opticks/GEOM/GEOM.sh  ## sets GEOM envvar, use GEOM bash function to setup/edit
0152 fi
0153 
0154 source $HOME/.opticks/GEOM/EVT.sh 2>/dev/null  ## optionally sets EVT name and corresponding AFOLD BFOLD where event arrays are loaded from
0155 source $HOME/.opticks/GEOM/MOI.sh 2>/dev/null  ## optionally sets MOI envvar, controlling initial view, use MOI bash function to setup/edit
0156 source $HOME/.opticks/GEOM/ELV.sh 2>/dev/null  ## optionally set ELV envvar controlling included/excluded LV by name
0157 source $HOME/.opticks/GEOM/SDR.sh 2>/dev/null  ## optionally configure OpenGL shader
0158 source $HOME/.opticks/GEOM/CUR.sh 2>/dev/null  ## optionally configure current context file writing
0159 
0160 
0161 
0162 
0163 if [ -f "$HOME/.opticks/GEOM/VUE.sh" ]; then
0164     source $HOME/.opticks/GEOM/VUE.sh
0165 else
0166 
0167     #eye=1000,1000,1000
0168     #eye=3.7878,3.7878,3.7878
0169     #eye=-1,-1,0
0170     #eye=-1,0,0
0171     #eye=1,0,0
0172     eye=0,1,0
0173     #eye=3,0,0
0174     #eye=3,0,-1.5
0175     #eye=0,3,-1.5
0176     #eye=0,-1,0
0177     #eye=-1,-1,3
0178     #eye=-1,-1,3
0179 
0180     look=0,0,0
0181 
0182     up=0,0,1
0183     #up=0,0,-1    ## inverted is useful for PMT
0184 
0185 
0186     wh=2560,1440
0187     fullscreen=1
0188 
0189     zoom=1
0190     tmin=0.5
0191     cam=perspective
0192     #cam=orthographic   # needs work to set param to make view start closer to perspective
0193 
0194     #escale=asis
0195     escale=extent
0196 
0197     traceyflip=0
0198 
0199 
0200     vizmask=t    # 0xff default, no masking
0201     #vizmask=t0  # 0xfe mask global, only instanced geometry in both OpenGL and OptiX renders
0202 
0203 
0204 
0205     export WH=${WH:-$wh}
0206     export FULLSCREEN=${FULLSCREEN:-$fullscreen}
0207 
0208     export ESCALE=${ESCALE:-$escale}
0209     export EYE=${EYE:-$eye}
0210     export LOOK=${LOOK:-$look}
0211     export UP=${UP:-$up}
0212     export ZOOM=${ZOOM:-$zoom}
0213     export TMIN=${TMIN:-$tmin}
0214     export CAM=${CAM:-$cam}
0215     export TRACEYFLIP=${TRACEYFLIP:-$traceyflip}
0216 
0217     ## VIZMASK may be ssst.sh ONLY ?
0218     export VIZMASK=${VIZMASK:-$vizmask}
0219 
0220 
0221     nameprefix=${SCRIPT}_
0222     nameprefix=${nameprefix}_eye_${EYE}_
0223     nameprefix=${nameprefix}_zoom_${ZOOM}_
0224     nameprefix=${nameprefix}_tmin_${TMIN}_
0225 
0226     # moi appended within CSGOptiX::render_snap ?
0227     export NAMEPREFIX=$nameprefix
0228     ## NAMEPREFIX used in CSGOptiX::getRenderStemDefault
0229 
0230 
0231     topline="ESCALE=$ESCALE EYE=$EYE TMIN=$TMIN MOI=$MOI ZOOM=$ZOOM CAM=$CAM $SCRIPT.sh "
0232     botline="$(date)"
0233     export TOPLINE=${TOPLINE:-$topline}
0234     export BOTLINE=${BOTLINE:-$botline}
0235 
0236     #export CSGOptiXRenderInteractiveTest__SGLM_DESC=1
0237     #export SGLFW__DEPTH=1   # dump _depth.jpg together with screenshots
0238 
0239 
0240     soptix__handle=-1  # default, full geometry
0241     #soptix__handle`=0  #  only non-instanced global geometry
0242     #soptix__handle=1  #  single CSGSolid
0243     #soptix__handle=2  #
0244     export SOPTIX__HANDLE=${SOPTIX__HANDLE:-$soptix__handle}
0245 
0246     #export SOPTIX_Options__LEVEL=1
0247 
0248 fi
0249 
0250 
0251 
0252 
0253 
0254 TMP=${TMP:-/tmp/$USER/opticks}
0255 
0256 export PBAS=${TMP}/    # note trailing slash
0257 export BASE=$TMP/GEOM/$GEOM/$bin
0258 export LOGDIR=$BASE
0259 mkdir -p $LOGDIR
0260 cd $LOGDIR
0261 
0262 LOG=$bin.log
0263 
0264 vv="bin which_bin GEOM MOI EMM ELV TMIN VUE EYE LOOK UP ZOOM LOGDIR BASE PBAS NAMEPREFIX OPTICKS_HASH TOPLINE BOTLINE CUDA_VISIBLE_DEVICES"
0265 vv="$vv AFOLD AFOLD_RECORD_SLICE BFOLD BFOLD_RECORD_SLICE _CUR"
0266 
0267 Resolve_CFBaseFromGEOM()
0268 {
0269    : LOOK FOR CFBase directory containing CSGFoundry geometry
0270    : HMM COULD PUT INTO GEOM.sh TO AVOID DUPLICATION ? BUT TOO MUCH HIDDEN ?
0271    : G4CXOpticks_setGeometry_Test GEOM TAKES PRECEDENCE OVER .opticks/GEOM
0272    : HMM : FOR SOME TESTS WANT TO LOAD GDML BUT FOR OTHERS CSGFoundry
0273    : to handle that added gdml resolution to eg g4cx/tests/GXTestRunner.sh
0274 
0275    local External_CFBaseFromGEOM=${GEOM}_CFBaseFromGEOM
0276 
0277    local A_CFBaseFromGEOM=$HOME/.opticks/GEOM/$GEOM
0278    local B_CFBaseFromGEOM=$TMP/G4CXOpticks_setGeometry_Test/$GEOM
0279    local C_CFBaseFromGEOM=/cvmfs/opticks.ihep.ac.cn/.opticks/GEOM/$GEOM
0280 
0281    local TestPath=CSGFoundry/prim.npy
0282    local GDMLPathFromGEOM=$HOME/.opticks/GEOM/$GEOM/origin.gdml
0283 
0284 
0285     if [ -d "${!External_CFBaseFromGEOM}" -a -f "${!External_CFBaseFromGEOM}/$TestPath" ]; then
0286         echo $BASH_SOURCE : USING EXTERNALLY SETUP GEOMETRY ENVIRONMENT : EG FROM OJ DISTRIBUTION
0287     elif [ -d "$A_CFBaseFromGEOM" -a -f "$A_CFBaseFromGEOM/$TestPath" ]; then
0288         export ${GEOM}_CFBaseFromGEOM=$A_CFBaseFromGEOM
0289         echo $BASH_SOURCE : FOUND A_CFBaseFromGEOM $A_CFBaseFromGEOM containing $TestPath
0290     elif [ -d "$B_CFBaseFromGEOM" -a -f "$B_CFBaseFromGEOM/$TestPath" ]; then
0291         export ${GEOM}_CFBaseFromGEOM=$B_CFBaseFromGEOM
0292         echo $BASH_SOURCE : FOUND B_CFBaseFromGEOM $B_CFBaseFromGEOM containing $TestPath
0293     elif [ -d "$C_CFBaseFromGEOM" -a -f "$C_CFBaseFromGEOM/$TestPath" ]; then
0294         export ${GEOM}_CFBaseFromGEOM=$C_CFBaseFromGEOM
0295         echo $BASH_SOURCE : FOUND C_CFBaseFromGEOM $C_CFBaseFromGEOM containing $TestPath
0296     elif [ -f "$GDMLPathFromGEOM" ]; then
0297         export ${GEOM}_GDMLPathFromGEOM=$GDMLPathFromGEOM
0298         echo $BASH_SOURCE : FOUND GDMLPathFromGEOM $GDMLPathFromGEOM
0299     else
0300         echo $BASH_SOURCE : NOT-FOUND A_CFBaseFromGEOM $A_CFBaseFromGEOM containing $TestPath
0301         echo $BASH_SOURCE : NOT-FOUND B_CFBaseFromGEOM $B_CFBaseFromGEOM containing $TestPath
0302         echo $BASH_SOURCE : NOT-FOUND C_CFBaseFromGEOM $C_CFBaseFromGEOM containing $TestPath
0303         echo $BASH_SOURCE : NOT-FOUND GDMLPathFromGEOM $GDMLPathFromGEOM
0304     fi
0305 }
0306 Resolve_CFBaseFromGEOM
0307 
0308 
0309 # NB EVT is not necessaryily used to pick between SEvt AFOLD/BFOLD it can just be a name to identify context of some snapshots
0310 _CUR=GEOM/$GEOM/$SCRIPT/$EVT
0311 
0312 if [ "${arg/info}" != "$arg" ]; then
0313    for v in $vv ; do printf "%20s : %s \n" "$v" "${!v}" ; done
0314 fi
0315 
0316 
0317 if [ "${arg/open}" != "$arg" ]; then
0318     # open to define current context string which controls where screenshots are copied to by ~/j/bin/pic.sh
0319     ## HMM : maybe should not overwrite when prefixing ?
0320     echo $BASH_SOURCE CUR_open ${_CUR}
0321     CUR_open ${_CUR}
0322 
0323     # second time argument like 11:00 to back date the context to include earlier snaps
0324     if [ -n "$arg2" ]; then
0325         echo $BASH_SOURCE CUR_touch "$arg2" \# use pic to see which snaps are included in the contect
0326         CUR_touch "$arg2"
0327     else
0328         echo $BASH_SOURCE arg2 needs to be a datetime accepted by CUR_touch eg "cxr_min.sh open 11:00" OR "cxr_min.sh open \"Fri Aug 22 11:00\" "
0329     fi
0330 fi
0331 
0332 if [ "${arg/run}" != "$arg" ]; then
0333    if [ -f "$LOG" ]; then
0334        echo $BASH_SOURCE : run : delete prior LOG $LOG
0335        rm "$LOG"
0336    fi
0337    $bin
0338    [ $? -ne 0 ] && echo $BASH_SOURCE run error && exit 1
0339 fi
0340 
0341 if [ "${arg/dbg}" != "$arg" ]; then
0342    if [ -f "$LOG" ]; then
0343        echo $BASH_SOURCE : dbg : delete prior LOG $LOG
0344        rm "$LOG"
0345    fi
0346    ## use installed script, not the source one so works from distribution
0347    source dbg__.sh
0348    dbg__ $bin
0349    [ $? -ne 0 ] && echo $BASH_SOURCE dbg error && exit 1
0350 fi
0351 
0352 if [ "${arg/gdb}" != "$arg" ]; then
0353    if [ -f "$LOG" ]; then
0354        echo $BASH_SOURCE : gdb : delete prior LOG $LOG
0355        rm "$LOG"
0356    fi
0357    gdb -ex "watch SGLM::UP.w" -ex r  $bin
0358    [ $? -ne 0 ] && echo $BASH_SOURCE gdb error && exit 1
0359 fi
0360 
0361 
0362 if [ "${arg/close}" != "$arg" ]; then
0363     # close to invalidate the context
0364     CUR_close
0365 fi
0366 
0367