Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 gxt.sh : G4CXSimtraceTest
0004 =============================================================================================================
0005 
0006 MOI targetting
0007 -----------------
0008 
0009 MOI envvar such as Hama:0:1000 changes the target sframe
0010 focussing the simtrace gensteps in a grid close to the sframe position.
0011 In addition the MOI value replaces the default SEvt::setReldir of "ALL"
0012 in order to keep result arrays separate for different targets.
0013 
0014 * TODO: extras within reldir eg for wider/narrower/offset views
0015 
0016 * an example output directory /Users/blyth/.opticks/GEOM/J004/G4CXSimtraceTest/Hama:0:1000/
0017 
0018 MOI acts within the configured GEOM::
0019 
0020     MOI=Hama:0:1000 LOGLEVEL=none ~/opticks/g4cx/gxt.sh run
0021     MOI=NNVT:0:1000 LOGLEVEL=none ~/opticks/g4cx/gxt.sh run
0022 
0023     MOI=Hama:0:1000 ~/opticks/g4cx/gxt.sh grab
0024     MOI=NNVT:0:1000 ~/opticks/g4cx/gxt.sh grab
0025 
0026     MOI=Hama:0:1000                     ~/opticks/g4cx/gxt.sh ana
0027     MOI=Hama:0:1000 NOLEGEND=1          ~/opticks/g4cx/gxt.sh ana
0028     MOI=Hama:0:1000 NOLEGEND=1 GSPLOT=1 ~/opticks/g4cx/gxt.sh ana
0029 
0030     MOI=Hama:0:1000 NOLEGEND=1 FOCUS=-100,-100,100  ~/opticks/g4cx/gxt.sh ana
0031 
0032     MOI=NNVT:0:1000                     ~/opticks/g4cx/gxt.sh ana
0033     MOI=NNVT:0:1000 NOLEGEND=1          ~/opticks/g4cx/gxt.sh ana
0034     MOI=NNVT:0:1000 NOLEGEND=1 GSPLOT=1 ~/opticks/g4cx/gxt.sh ana
0035 
0036 
0037 NB for naming consistency must remember to reuse the same MOI
0038 when doing captures and publication copies::
0039 
0040     gx
0041     MOI=Hama:0:1000 ./gxt.sh ana
0042     MOI=Hama:0:1000 ./gxt.sh mpcap
0043     MOI=Hama:0:1000 ./gxt.sh mppub
0044 
0045     MOI=NNVT:0:1000 ./gxt.sh mpcap
0046     MOI=NNVT:0:1000 ./gxt.sh mppub
0047 
0048 
0049 * *run* time with full JUNO geometry < 1 second
0050 * *grab* time depends on network, can be minutes to rsync the simtrace.npy intersects
0051 * *ana* plotting takes a few seconds
0052 * when MOI is not defined the sframe::DEFAULT_FRS value is -1 which corresponds to the entire geometry.
0053 
0054 
0055 * TODO: bring over support for FOCUS control as with CSG/ct.sh
0056 
0057 
0058 Without MOI targetting
0059 -------------------------
0060 
0061 ::
0062 
0063     cd ~/opticks/g4cx   # gx
0064 
0065     ./gxt.sh
0066     ./gxt.sh info
0067     ./gxt.sh fold
0068 
0069     ./gxt.sh run       ## on workstation
0070     ./gxt.sh dbg
0071 
0072     ./gxt.sh grab      ## on laptop
0073     ./gxt.sh ana
0074 
0075 
0076 
0077 To capture pyvista or matplotlib screens::
0078 
0079     ./gxt.sh pvcap
0080     ./gxt.sh pvpub           # check the paths used by pvpub
0081     PUB=chk ./gxt.sh pvpub   # copy into /env/presentation
0082 
0083     ./gxt.sh mpcap
0084     ./gxt.sh mppub           # check the paths used by mppub
0085     PUB=chk ./gxt.sh mppub   # copy into /env/presentation
0086 
0087 ana imp::
0088 
0089     vi tests/G4CXSimtraceTest.py ../ana/simtrace_plot.py ../ana/pvplt.py ../ana/feature.py
0090 
0091 
0092 
0093 As B uses A and T uses A+B the running order is:
0094 
0095 A. gx ; ./gxs.sh
0096 B. u4 ; ./u4s.sh
0097 T. gx ; ./gxt.sh
0098 
0099 
0100 analog timings : showing log lines taking more than 2 percent of total time
0101 -------------------------------------------------------------------------------
0102 
0103 ::
0104 
0105     In [1]: log[2]
0106     Out[1]:
0107                      timestamp :        DTS-prev :        DFS-frst :msg
0108     2022-08-23 23:46:16.288000 :      0.3370[34] :      0.3370[34] : INFO  [57430] [main@20] ] cu first
0109     2022-08-23 23:46:16.504000 :      0.1780[18] :      0.5530[56] : INFO  [57430] [QSim::UploadComponents@111] ] new QRng
0110     2022-08-23 23:46:16.613000 :      0.0800[ 8] :      0.6620[67] : INFO  [57430] [CSGOptiX::initCtx@322] ]
0111     2022-08-23 23:46:16.640000 :      0.0270[ 3] :      0.6890[69] : INFO  [57430] [CSGOptiX::initPIP@333] ]
0112     2022-08-23 23:46:16.740000 :      0.0360[ 4] :      0.7890[80] : INFO  [57430] [CSGFoundry::getFrame@2880]  fr sframe::desc inst 0 frs -1
0113     2022-08-23 23:46:16.910000 :      0.1140[11] :      0.9590[97] : INFO  [57430] [SEvt::gather@1378]  k        simtrace a  <f4(627000, 4, 4, )
0114     2022-08-23 23:46:16.942000 :      0.0320[ 3] :      0.9910[100] : INFO  [57430] [SEvt::save@1505] ] fold.save
0115 
0116 
0117                              - :                 :                 :G4CXSimtraceTest.log
0118     2022-08-23 23:46:15.951000 :                 :                 :start
0119     2022-08-23 23:46:16.943000 :                 :                 :end
0120                              - :                 :      0.9920[100] :total seconds
0121                              - :                 :      2.0000[100] :pc_cut
0122 
0123 ::
0124 
0125     CUDA_VISIBLE_DEVICES=0,1 ./gxt.sh       ## appears to give same timings as default
0126     CUDA_VISIBLE_DEVICES=0 ./gxt.sh         ## slightly reduced CUDA latency from 0.31s down to 0.25s
0127     CUDA_VISIBLE_DEVICES=1 ./gxt.sh         ## slightly reduced CUDA latency from 0.31s down to 0.23s
0128 
0129 
0130 EOU
0131 }
0132 
0133 cd $(dirname $(realpath $BASH_SOURCE))
0134 
0135 msg="=== $BASH_SOURCE :"
0136 
0137 case $(uname) in
0138   Linux)  defarg="run"  ;;
0139   Darwin) defarg="ana"  ;;
0140 esac
0141 
0142 arg=${1:-$defarg}
0143 
0144 case $arg in
0145   fold) QUIET=1 ;;
0146   analog)  QUIET=1 ;;
0147 esac
0148 
0149 bin=G4CXSimtraceTest
0150 log=$bin.log
0151 home=$(dirname $BASH_SOURCE)/..
0152 
0153 source $HOME/.opticks/GEOM/GEOM.sh
0154 
0155 if [ -n "$OPTICKS_INPUT_PHOTON" ]; then
0156    echo $msg WARNING : simtrace running and input photons cannot be used together  : unset OPTICKS_INPUT_PHOTON
0157    unset OPTICKS_INPUT_PHOTON
0158 fi
0159 
0160 
0161 UGEOMDIR=${GEOMDIR//$HOME\/}
0162 
0163 
0164 BASE=$GEOMDIR/$bin
0165 UBASE=${BASE//$HOME\/}    # UBASE relative to HOME to handle rsync between different HOME
0166 FOLD=$BASE/${MOI:-ALL}    # corresponds SEvt::save() with SEvt::SetReldir("ALL")
0167 
0168 # analysis/plotting uses A_FOLD B_FOLD for comparison together with the simtrace
0169 
0170 T_FOLD=$FOLD
0171 A_FOLD=$($home/g4cx/gxs.sh fold)
0172 B_FOLD=$($home/u4/u4s.sh fold)
0173 
0174 
0175 source $home/bin/upfind_cfbase.sh
0176 T_CFBASE=$(upfind_cfbase $T_FOLD)
0177 A_CFBASE=$(upfind_cfbase $A_FOLD)
0178 B_CFBASE=$(upfind_cfbase $B_FOLD)
0179 
0180 
0181 export A_FOLD
0182 export A_CFBASE
0183 export B_FOLD
0184 
0185 if [ "${arg/info}" != "$arg" ]; then
0186     vars="BASH_SOURCE arg bin home defarg GEOM GEOMDIR UGEOMDIR BASE UBASE FOLD A_FOLD A_CFBASE B_FOLD B_CFBASE T_FOLD T_CFBASE J001_GDMLPath"
0187     for var in $vars ; do printf "%30s : %s \n" $var ${!var} ; done
0188     source $home/bin/AB_FOLD.sh   # just lists dir content
0189 fi
0190 
0191 if [ "$arg" == "fold" ]; then
0192     echo $FOLD
0193 fi
0194 
0195 
0196 cehigh_Notes(){ cat << EON
0197 
0198 increase genstep resolution, see sysrap/tests/SFrameGenstep_MakeCenterExtentGensteps_Test.sh
0199 see SFrameGenstep::StandardizeCEGS
0200 
0201 ix0:ix1:iy0:iy1:iz0:iz1:num_photons:high
0202 
0203 * the i are original grid ranges, high increases the resolution by dividing the grid
0204 
0205 EON
0206 }
0207 
0208 cehigh_MaskLip()
0209 {
0210     echo === $FUNCNAME
0211     export CEHIGH_0=-11:-9:0:0:-2:0:1000:4
0212     export CEHIGH_1=9:11:0:0:-2:0:1000:4
0213     export CEHIGH_2=-1:1:0:0:-2:0:1000:4
0214 }
0215 
0216 cehigh_PMT()
0217 {
0218     echo === $FUNCNAME
0219     export CEHIGH_0=-8:8:0:0:-6:-4:1000:4   # across the bottom to check for insitu overlaps
0220     export CEHIGH_1=-8:8:0:0:4:6:1000:4     # across the top
0221     export CEHIGH_2=-8:-6:0:0:-4:4:1000:4   # left side
0222     export CEHIGH_3=6:8:0:0:-4:4:1000:4     # right side
0223     export CEHIGH_4=-6:-4:0:0:2:4:1000:4    # inner top left corner
0224     export CEHIGH_5=4:6:0:0:2:4:1000:4      # inner top right corner
0225     export CEHIGH_6=-6:-4:0:0:-4:-2:1000:4  # inner bottom left corner
0226     export CEHIGH_7=4:6:0:0:-4:-2:1000:4    # inner bottom right corner
0227     ## see SFrameGenstep::MakeCenterExtentGensteps for where the CEHIGH_ are acted on
0228 }
0229 
0230 cehigh()
0231 {
0232     echo === $FUNCNAME : GEOM $GEOM MOI $MOI
0233     case $MOI in
0234        Hama*|NNVT*) cehigh_PMT  ;;
0235     esac
0236     env | grep CEHIGH
0237 }
0238 cehigh
0239 
0240 
0241 
0242 loglevel_none()
0243 {
0244     echo $FUNCNAME
0245 }
0246 loglevel_minimal()
0247 {
0248     echo $FUNCNAME
0249     export G4CXOpticks=INFO
0250     export SEvt=INFO
0251     export CSGTarget=INFO
0252 }
0253 loglevel_verbose()
0254 {
0255     echo $FUNCNAME
0256     export Dummy=INFO
0257     #export SGeoConfig=INFO
0258     export SEventConfig=INFO
0259     export SEvt=INFO
0260     #export Ctx=INFO
0261     export QSim=INFO
0262     export QBase=INFO
0263     export SSim=INFO
0264     export SBT=INFO
0265     export IAS_Builder=INFO
0266     #export QEvt=INFO
0267     export CSGOptiX=INFO
0268     export G4CXOpticks=INFO
0269     export CSGFoundry=INFO
0270     #export GInstancer=INFO
0271     #export X4PhysicalVolume=INFO
0272     #export U4VolumeMaker=INFO
0273 }
0274 
0275 
0276 loglevel()
0277 {
0278     if [ -n "$LOGLEVEL" ]; then
0279         echo $FUNCNAME : LOGLEVEL $LOGLEVEL : is defined
0280         case $LOGLEVEL in
0281                none) loglevel_none ;;
0282             minimal) loglevel_minimal ;;
0283             verbose) loglevel_verbose ;;
0284                   *) loglevel_verbose ;;
0285         esac
0286     else
0287         echo $FUNCNAME : LOGLEVEL not defined not setting any loglevels
0288     fi
0289     env | grep =INFO
0290 }
0291 loglevel
0292 
0293 
0294 
0295 
0296 if [ "${arg/run}" != "$arg" ]; then
0297     echo $msg run $bin log $log
0298     if [ -f "$log" ]; then
0299        rm $log
0300     fi
0301 
0302     $bin
0303     [ $? -ne 0 ] && echo $BASH_SOURCE run $bin error && exit 1
0304 fi
0305 
0306 if [ "grablog" == "$arg" ]; then
0307     scp P:opticks/g4cx/$log .
0308 fi
0309 
0310 if [ "analog" == "$arg" ]; then
0311     echo $msg analog log $log
0312     if [ -f "$log" ]; then
0313         LOG=$log $home/bin/log.sh
0314     fi
0315 fi
0316 
0317 if [ "${arg/dbg}" != "$arg" ]; then
0318     source ../bin/dbg__.sh
0319     dbg__ $bin
0320     [ $? -ne 0 ] && echo $BASH_SOURCE dbg $bin error && exit 2
0321 fi
0322 
0323 if [ "ana" == "$arg" ]; then
0324     export FOLD
0325     export CFBASE=$T_CFBASE    ## T_CFBASE would seem better otherwise assumes have rerun A with same geom at T (and B)
0326     export MASK=${MASK:-pos}
0327 
0328     topline="gxt.sh/$bin.py : GEOM $GEOM "
0329     [ -n "$MOI" ] && topline="$topline MOI $MOI"
0330     export TOPLINE="$topline"
0331 
0332     botline=""
0333     [ -n "$FOCUS" ] && botline="$botline FOCUS $FOCUS"
0334     export BOTLINE="$botline"
0335 
0336     ${IPYTHON:-ipython} --pdb -i $home/g4cx/tests/$bin.py
0337     [ $? -ne 0 ] && echo $BASH_SOURCE ana $bin error && exit 3
0338 fi
0339 
0340 if [ "anachk" == "$arg" ]; then
0341     export FOLD
0342     export CFBASE=$T_CFBASE    ## T_CFBASE would seem better otherwise assumes have rerun A with same geom at T (and B)
0343     export MASK=${MASK:-pos}
0344 
0345     ${IPYTHON:-ipython} --pdb -i $home/g4cx/tests/CSGFoundryLoadTest.py
0346     [ $? -ne 0 ] && echo $BASH_SOURCE anachk $bin error && exit 3
0347 fi
0348 
0349 
0350 
0351 
0352 if [ "grab" == "$arg" ]; then
0353     source $home/bin/rsync.sh $UGEOMDIR
0354     [ $? -ne 0 ] && echo $BASH_SOURCE grab error && exit 4
0355 fi
0356 
0357 
0358 
0359 if [ "$arg" == "pvcap" -o "$arg" == "pvpub" -o "$arg" == "mpcap" -o "$arg" == "mppub" ]; then
0360 
0361 
0362     stem=$GEOM
0363     [ -n "$MOI" ] && stem="${stem}_$MOI"
0364 
0365     echo == $BASH_SOURCE arg $arg GEOM $GEOM MOI $MOI stem $stem
0366 
0367     export CAP_BASE=$FOLD/figs
0368     export CAP_REL=gxt
0369     export CAP_STEM=$stem
0370     case $arg in
0371        pvcap) source pvcap.sh cap  ;;
0372        mpcap) source mpcap.sh cap  ;;
0373        pvpub) source pvcap.sh env  ;;
0374        mppub) source mpcap.sh env  ;;
0375     esac
0376 
0377     if [ "$arg" == "pvpub" -o "$arg" == "mppub" ]; then
0378         source epub.sh
0379     fi
0380 fi
0381 
0382 exit 0
0383