Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:28

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 U4SimtraceTest.sh
0004 =====================
0005 
0006 Uses U4SimtraceTest.cc which creates Geant4 geometry
0007 with U4VolumeMaker::PV depending on GEOM envvar
0008 and scans the geometry using U4SimtraceTest::scan
0009 saving the intersects into the folder configured with FOLD envvar.
0010 
0011 In addition to plotting intersects showing geometry this 
0012 can also show photon paths from U4SimulateTest.
0013 
0014 
0015 
0016 FewPMT.sh/tub3LogicalPMT::
0017 
0018     MODE=2 FOCUS=0,0,80 ~/opticks/u4/tests/U4SimtraceTest.sh ana
0019 
0020     MODE=2 ~/opticks/u4/tests/U4SimtraceTest.sh
0021 
0022 TODO
0023 ------
0024 
0025 * add metadata checks that plotted U4SimulateTest photons are from a geometry matching the U4SimtraceTest geometry
0026 
0027 
0028 Commands
0029 -----------
0030 
0031 run/dbg
0032     simtrace intersects against geometry
0033 ana
0034     presentation of simtrace intersects using python matplotlib OR pyvista
0035 mpcap/pvcap
0036     screenshot current matplotlib/pyvista window with chrome cropped
0037 mppub/pvpub
0038     publication by copying matplotlib/pyvista screenshot png into presentation tree
0039 
0040 
0041 Workflow to add plots to presentations
0042 -----------------------------------------
0043 
0044 1. check matplotlib window plot and annotations are presentable::
0045 
0046      APID=2563 AOPT=idx N=0 SUBTITLE="7:SD at vac/vac" ./U4SimtraceTest.sh ana
0047 
0048 2. whilst some part of the matplotlib window is still visible, in a separate tab run::
0049 
0050        u4t ; ./U4SimtraceTest.sh mpcap
0051 
0052    * If capture environment depends on envvars make sure that is consistent with above command
0053    * NB have to click on the matplotlib window (so it must be visible before running mpcap), that
0054      turns it blue targetting the window screen capture
0055 
0056 3. publish that, coping the .png into presentation tree::
0057 
0058      u4t ; PUB=2563_Unphysical_SD_in_vacuum ./U4SimtraceTest.sh mppub
0059      ## ensure PUB is a distinct identifier
0060 
0061 4. reference the .png by copy/paste the "s5p_line" from the output of the above step
0062    into ~/env/presentation/s5_background_image.txt (use presentation-e)
0063    and reference that by adding a presentation page with matching title
0064 
0065 5. it is good to include the primary commandline from step 1 in the presentation, even if
0066    not presented, in order to allow reproducing the plot
0067 
0068 
0069 
0070 Suggested Workflow To Find Photons to Compare and plot
0071 --------------------------------------------------------
0072 
0073 Use two U4SimulateTest.sh sessions for N=0 and N=1::
0074 
0075     u4t
0076     N=0 POM=1 ./U4SimulateTest.sh    ## "a" in Simtrace session
0077     N=1 POM=1 ./U4SimulateTest.sh    ## "b" in Simtrace session
0078 
0079 And a third U4SimtraceTest.sh session::
0080 
0081     u4t
0082     N=1 ./U4SimtraceTest.sh ana
0083 
0084 Check a and b in simtrace session::
0085 
0086     In [1]: a.f.base, b.f.base
0087     Out[1]:
0088     ('/tmp/blyth/opticks/GEOM/FewPMT/U4SimulateTest/ALL0',
0089      '/tmp/blyth/opticks/GEOM/FewPMT/U4SimulateTest/ALL1')
0090 
0091 Pick some APID, BPID expected to be similar by comparing
0092 histories as visible in the first two sessions (eg np.c_[np.arange(40),q[:40]] ).
0093 Use AOFF or BOFF to offset to make similar paths visible, eg AOFF=0,0,10
0094 Keep starting and stopping the third session as change APID, BPID (-ve disables)::
0095 
0096     APID=17 BPID=7  N=1 ./U4SimtraceTest.sh ana
0097 
0098 Examples
0099 -----------
0100 
0101 ::
0102 
0103     N=0 ./U4SimtraceTest.sh
0104     N=1 ./U4SimtraceTest.sh
0105 
0106     APID=173 PLAB=1 BGC=yellow ./U4SimtraceTest.sh ana
0107 
0108 Z-changing big bouncers::
0109 
0110     N=0 APID=256 PLAB=1 BGC=white ./U4SimtraceTest.sh ana
0111     N=1 APID=261 PLAB=1 BGC=white ./U4SimtraceTest.sh ana
0112 
0113 Grab the custom boundary status for each point::
0114 
0115     In [25]: t.aux[261,:32,1,3].copy().view(np.int8)[::4].copy().view("|S32")
0116     Out[25]: array([b'TTTZNZRZNZA'], dtype='|S32')
0117 
0118 ::
0119 
0120     N=0 APID=726 BPID=-1 AOPT=nrm FOCUS=0,10,185 ./U4SimtraceTest.sh ana
0121     N=1 APID=-1 BPID=726 BOPT=nrm FOCUS=0,10,185 ./U4SimtraceTest.sh ana
0122 
0123 
0124 two_pmt::
0125 
0126     FOCUS=0,0,255 ./U4SimtraceTest.sh ana
0127 
0128     N=0 APID=813 AOPT=idx BGC=yellow FOCUS=0,0,255 ./U4SimtraceTest.sh ana
0129     N=0 APID=813 AOPT=ast BGC=yellow FOCUS=0,0,255 ./U4SimtraceTest.sh ana
0130 
0131     N=1 BPID=748 BOPT=ast,nrm BGC=yellow FOCUS=0,0,255 ./U4SimtraceTest.sh ana
0132     N=1 BPID=150 BOPT=nrm,ast BGC=yellow FOCUS=0,0,255 ./U4SimtraceTest.sh ana
0133 
0134 
0135 MODE 3 pyvista 3D plotting::
0136 
0137     MODE=3 EYE=0,-1000,0 LOOK=0,0,0 UP=0,0,1 ./U4SimtraceTest.sh ana
0138 
0139 Questions
0140 -----------
0141 
0142 Q: Where is the N envvar to control natural geometry acted upon ?
0143 A: j/PMTSim/IGeomManager.h:IGeomManager::declProp interprets envvar to set values::
0144 
0145     epsilon:tests blyth$ grep UseNaturalGeometry *.*
0146     FewPMT.sh:export hama_UseNaturalGeometry=$version
0147     FewPMT.sh:export nnvt_UseNaturalGeometry=$version
0148 
0149 
0150 Q: Where is the SEventConfig::IsRGModeSimtrace flipped ?
0151 
0152 
0153 EOU
0154 }
0155 
0156 DIR=$(dirname $BASH_SOURCE)
0157 bin=U4SimtraceTest
0158 apid=-1
0159 bpid=-1
0160 geom=FewPMT
0161 evt=000
0162 eye=0,1000,0   # +Y 1000mm
0163 
0164 #cegs=16:0:9:1000   # default used from SFrameGenstep::MakeCenterExtentGensteps
0165 cegs=16:0:9:5000    # increase photon count for more precise detail
0166 
0167 export VERSION=${N:-0}
0168 export GEOM=${GEOM:-$geom}
0169 
0170 tmp=/tmp/$USER/opticks
0171 export TMP=${TMP:-$tmp}
0172 
0173 export GEOMFOLD=$TMP/GEOM/$GEOM
0174 export BASE=$GEOMFOLD/$bin
0175 
0176 export FOLD=$BASE/$VERSION   ## controls where the U4SimtraceTest.cc executable writes intersects
0177 
0178 export EVT=${EVT:-$evt}
0179 export AFOLD=$GEOMFOLD/U4SimulateTest/ALL0/$EVT
0180 export BFOLD=$GEOMFOLD/U4SimulateTest/ALL1/$EVT   # SEL1 another possibility
0181 export APID=${APID:-$apid}                        # APID for photons from ALL0
0182 export BPID=${BPID:-$bpid}                        # BPID for photons from ALL1
0183 
0184 export EYE=${EYE:-$eye}       # not extent scaled, just mm
0185 export CEGS=${CEGS:-$cegs}
0186 export CEHIGH_0=-1:1:0:0:7:8:1000:4
0187 
0188 
0189 geomscript=$DIR/$GEOM.sh
0190 if [ -f "$geomscript" ]; then
0191     source $geomscript
0192 else
0193     echo $BASH_SOURCE : no geomscript $geomscript
0194 fi
0195 
0196 # GEOMList for the GEOM is set for example in the FewPMT.sh geomscript
0197 _GEOMList=${GEOM}_GEOMList
0198 GEOMList=${!_GEOMList}
0199 
0200 echo $BASH_SOURCE GEOMList : $GEOMList
0201 
0202 
0203 logging()
0204 {
0205    type $FUNCNAME
0206    export U4VolumeMaker=INFO
0207 }
0208 [ -n "$LOG" ] && logging
0209 
0210 
0211 log=${bin}.log
0212 logN=${bin}_$VERSION.log
0213 
0214 defarg="run_ana"
0215 arg=${1:-$defarg}
0216 
0217 if [ "${arg/run}" != "$arg" ]; then
0218     [ -f "$log" ] && rm $log
0219     $bin
0220     [ $? -ne 0 ] && echo $BASH_SOURCE run error && exit 1
0221     [ -f "$log" ] && echo $BASH_SOURCE rename log $log to logN $logN && mv $log $logN
0222 fi
0223 
0224 if [ "${arg/dbg}" != "$arg" ]; then
0225     [ -f "$log" ] && rm $log
0226     dbg__ $bin
0227     [ $? -ne 0 ] && echo $BASH_SOURCE dbg error && exit 2
0228 fi
0229 
0230 if [ "${arg/ana}" != "$arg"  ]; then
0231     [ "$arg" == "nana" ] && export MODE=0
0232     ${IPYTHON:-ipython} --pdb -i $DIR/$bin.py
0233     [ $? -ne 0 ] && echo $BASH_SOURCE ana error && exit 3
0234 fi
0235 
0236 if [ "$arg" == "pvcap" -o "$arg" == "pvpub" -o "$arg" == "mpcap" -o "$arg" == "mppub" ]; then
0237     export CAP_BASE=$FOLD/figs
0238     export CAP_REL=U4SimtraceTest
0239     export CAP_STEM=$GEOM
0240     case $arg in
0241        pvcap) source pvcap.sh cap  ;;
0242        mpcap) source mpcap.sh cap  ;;
0243        pvpub) source pvcap.sh env  ;;
0244        mppub) source mpcap.sh env  ;;
0245     esac
0246     if [ "$arg" == "pvpub" -o "$arg" == "mppub" ]; then
0247         source epub.sh
0248     fi
0249 fi
0250 
0251 exit 0