Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash -l 
0002 usage(){ cat << EOU
0003 U4SimulateTest.sh  (formerly U4PMTFastSimTest.sh)
0004 ===================================================
0005 
0006 Covering the PMT*POM quadrants (POM:PMT Optical Model)::
0007 
0008     u4t
0009 
0010     N=0 POM=0 ./U4SimulateTest.sh   # unnatural geom , traditional POM 
0011     N=1 POM=0 ./U4SimulateTest.sh   # natural geom   , traditional POM
0012 
0013     N=0 POM=1 ./U4SimulateTest.sh   # unnatural geom , multifilm POM 
0014     N=1 POM=1 ./U4SimulateTest.sh   # natural geom   , multifilm POM
0015 
0016 
0017 Analysis loading saved results::
0018 
0019     PID=726 ./U4SimulateTest.sh nana
0020 
0021     N=1 MODE=0 ./U4SimulateTest.sh ph  # no GUI with NumPy 
0022     N=1 MODE=2 ./U4SimulateTest.sh ph  # 2D GUI with matplotlib
0023     N=1 MODE=3 ./U4SimulateTest.sh ph  # 3D GUI with pyvista
0024 
0025 
0026 Rerunning single photons off the same g4state is a bit delicate to arrange.
0027 This incantation succeeds to rerun the N=0 big bouncer with N=1::
0028 
0029      u4t                       ## cd ~/opticks/u4/tests
0030 
0031      vi U4SimulateTest.sh      ## switch to running_mode=SRM_G4STATE_SAVE
0032 
0033      N=0 ./U4SimulateTest.sh   ## saves g4state into /tmp/blyth/opticks/GEOM/hamaLogicalPMT/U4SimulateTest/ALL0
0034 
0035      vi U4SimulateTest.sh      ## switch to running_mode=SRM_G4STATE_RERUN for PID 726 
0036     
0037      N=1 ./U4SimulateTest.sh   ## saves to /tmp/blyth/opticks/GEOM/hamaLogicalPMT/U4SimulateTest/SEL1
0038 
0039 
0040 After that can compare timings::
0041 
0042     ./U4SimulateTest.sh cf 
0043 
0044 EOU
0045 }
0046 
0047 DIR=$(cd $(dirname $BASH_SOURCE) && pwd)
0048 bin=U4SimulateTest
0049 
0050 
0051 export VERSION=${N:-0}
0052 source $HOME/.opticks/GEOM/GEOM.sh  # set GEOM : this script was used for FewPMT tests
0053 origin=$HOME/.opticks/GEOM/$GEOM/origin.gdml
0054 if [ -f "$origin" ]; then
0055    export ${GEOM}_GDMLPathFromGEOM=$origin
0056 fi 
0057 
0058 
0059 
0060 
0061 
0062 geomscript=$DIR/$GEOM.sh 
0063 
0064 if [ -f "$geomscript" ]; then  
0065     source $geomscript
0066 else
0067     echo $BASH_SOURCE : no geomscript $geomscript
0068 fi 
0069 
0070 ## moved LAYOUT and FAKES control inside geomscript so its in common 
0071 ## between U4SimulateTest.sh and U4SimtraceTest.sh 
0072 ## makes sense for everything that is very GEOM specific to be within the geomscript
0073 
0074 _GEOMList=${GEOM}_GEOMList
0075 GEOMList=${!_GEOMList}
0076 
0077 
0078 export BASE=/tmp/$USER/opticks/GEOM/$GEOM/$bin
0079 
0080 ## process DISABLE/ENABLE controlling u4/tests/U4Physics.cc U4Physics::ConstructOp
0081 export Local_G4Cerenkov_modified_DISABLE=1
0082 export Local_DsG4Scintillation_DISABLE=1
0083 #export G4OpAbsorption_DISABLE=1
0084 #export G4OpRayleigh_DISABLE=1
0085 #export G4OpBoundaryProcess_DISABLE=1
0086 
0087 export U4App__PRIMARY_MODE=torch  # hmm seems iphoton and torch do same thing internally 
0088 export BeamOn=${BeamOn:-1}
0089 export U4Recorder__PIDX_ENABLED=1 
0090 #export U4Recorder__UserSteppingAction_Optical_ClearNumberOfInteractionLengthLeft=1  ## makes easier to randmn align 
0091 
0092 
0093 
0094 evt=n001
0095 export EVT=${EVT:-$evt}       # used for FOLD envvars
0096 
0097 
0098 
0099 
0100 # python ana level presentation 
0101 export LOC=skip
0102 
0103 log=${bin}.log
0104 logN=${bin}_$VERSION.log
0105 
0106 #num_photons=1
0107 #num_photons=10
0108 #num_photons=100
0109 #num_photons=1000      # 1k
0110 num_photons=10000    # 10k
0111 #num_photons=50000    # 50k 
0112 #num_photons=100000   # 100k
0113 #num_photons=1000000  # 1M
0114 
0115 NUM_PHOTONS=${NUM_PHOTONS:-$num_photons}
0116 
0117 if [ -n "$RERUN" ]; then 
0118    export OPTICKS_G4STATE_RERUN=$RERUN
0119    running_mode=SRM_G4STATE_RERUN
0120 else
0121    running_mode=SRM_G4STATE_SAVE  
0122 fi 
0123 
0124 case $running_mode in 
0125    SRM_G4STATE_SAVE)  reldir=ALL$VERSION ;; 
0126    SRM_G4STATE_RERUN) reldir=SEL$VERSION ;; 
0127 esac
0128 
0129 ## sysrap/SEventConfig 
0130 export OPTICKS_RUNNING_MODE=$running_mode   # see SEventConfig::RunningMode
0131 export OPTICKS_MAX_BOUNCE=31                # can go upto 31 now that extended sseq.h 
0132 export OPTICKS_EVENT_MODE=DebugLite
0133 export OPTICKS_G4STATE_SPEC=${NUM_PHOTONS}:38       # default is only 1000:38 to keep state files small 
0134 
0135 export SEvent_MakeGenstep_num_ph=${NUM_PHOTONS}
0136 source $DIR/storch_FillGenstep.sh 
0137 
0138 
0139 loglevel(){
0140    export U4VolumeMaker=INFO
0141    export U4Recorder=INFO
0142    export U4Physics=INFO
0143    export junoPMTOpticalModel=INFO
0144    export junoPMTOpticalModelSimple=INFO
0145    #export SEvt=INFO     ## thus is exceedingly verbose
0146    export SEventConfig=INFO
0147    export InstrumentedG4OpBoundaryProcess=INFO
0148    export ShimG4OpAbsorption=INFO
0149    export ShimG4OpRayleigh=INFO
0150 }
0151 
0152 
0153 if [ "$running_mode" == "SRM_G4STATE_RERUN" ]; then 
0154    echo $BASH_SOURCE : switch on logging when doing single photon RERUN
0155    loglevel  
0156 else
0157    #echo $BASH_SOURCE : switch on some logging anyhow : THIS WILL BE VERBOSE
0158    #export junoPMTOpticalModel=INFO
0159    #export CustomG4OpBoundaryProcess=INFO
0160 
0161    export U4Physics=INFO
0162    export U4Recorder=INFO
0163    #export SEvt=INFO
0164    export C4OpBoundaryProcess__PIDX_ENABLED=1
0165 fi 
0166 
0167 
0168 if [ -n "$SIMTRACE" ]; then
0169    export U4Recorder__EndOfRunAction_Simtrace=1  
0170    export SFrameGenstep=INFO
0171 fi 
0172 
0173 
0174 ## analysis modes beginning with n: nfs/ncf/naf/nph are NumPy only (without matplotlib and pyvista)
0175 ## envout is used to communicate from some python scripts back into this bash script 
0176 ## this only makes sense for single N=0, N=1 running 
0177 
0178 export ENVOUT=/tmp/$USER/opticks/U4SimulateTest/envout.sh
0179 mkdir -p $(dirname $ENVOUT)
0180 
0181 export FOLD=$BASE/$reldir/$EVT
0182 export AFOLD=$BASE/ALL0/$EVT     ## for comparisons 
0183 export BFOLD=$BASE/ALL1/$EVT
0184 
0185 
0186 
0187 
0188 vars="BASH_SOURCE GEOM _GEOMList GEOMList BASE EVT FOLD NUM_PHOTONS script"
0189 
0190 
0191 
0192 
0193 
0194 
0195 
0196 
0197 
0198 
0199 defarg="run_ph"
0200 #defarg="run_mt"
0201 [ -n "$BP" ] && defarg="dbg"
0202 
0203 arg=${1:-$defarg}
0204 [ "${arg:0:1}" == "n" ] && export MODE=0
0205 
0206 if [ "${arg/fs}" != "$arg" -o "${arg/nfs}" != "$arg" ]; then
0207     script=$DIR/${bin}_fs.py  
0208 elif [ "${arg/cf}" != "$arg" -o "${arg/ncf}" != "$arg" ]; then
0209     script=$DIR/${bin}_cf.py 
0210 elif [ "${arg/af}" != "$arg" -o "${arg/naf}" != "$arg" ]; then
0211     script=$DIR/${bin}_af.py 
0212 elif [ "${arg/ph}" != "$arg" -o "${arg/nph}" != "$arg" ]; then
0213     script=$DIR/${bin}_ph.py 
0214 elif [ "${arg/mt}" != "$arg" -o "${arg/nmt}" != "$arg" ]; then
0215     script=$DIR/${bin}_mt.py 
0216 elif [ "${arg/fk}" != "$arg" -o "${arg/nfk}" != "$arg" ]; then
0217     script=$DIR/${bin}_fk.py 
0218 elif [ "${arg/ck}" != "$arg" -o "${arg/nck}" != "$arg" ]; then
0219     script=$DIR/${bin}_ck.py 
0220 elif [ "${arg/pr}" != "$arg" -o "${arg/npr}" != "$arg" ]; then
0221     script=$DIR/${bin}_pr.py 
0222 elif [ "${arg/tt}" != "$arg" -o "${arg/ntt}" != "$arg" ]; then
0223     script=$OPTICKS_HOME/sysrap/sevt_tt.py 
0224 elif [ "${arg/__}" != "$arg" -o "${arg/n__}" != "$arg" ]; then
0225     script=$DIR/${bin}.py 
0226 fi 
0227 
0228 
0229 if [ "${arg/info}" != "$arg" ]; then
0230     for var in $vars ; do printf "%-30s : %s \n" "$var" "${!var}" ; done
0231 fi
0232 
0233 if [ "${arg/run}" != "$arg" ]; then
0234     [ -f "$log" ] && rm $log 
0235     $bin
0236     [ $? -ne 0 ] && echo $BASH_SOURCE run error && exit 1 
0237     [ -f "$log" ] && echo $BASH_SOURCE rename log $log to logN $logN && mv $log $logN    
0238 fi 
0239 
0240 
0241 if [ "$arg" == "dbg" ]; then
0242    bp=MixMaxRng::flat
0243    #bp="$bp CustomG4OpBoundaryProcess::DielectricMetal"
0244    #bp="$bp CustomG4OpBoundaryProcess::ChooseReflection" 
0245    #bp="$bp CustomG4OpBoundaryProcess::DoAbsorption" 
0246    #bp="$bp CustomG4OpBoundaryProcess::DoReflection"
0247    #export BP=${BP:-$bp}
0248 fi 
0249 
0250 if [ "${arg/dbg}" != "$arg" ]; then
0251     [ -f "$log" ] && rm $log 
0252     case $(uname) in 
0253         Darwin) lldb__ $bin ;;
0254         Linux)   gdb__ $bin ;;
0255     esac
0256     [ $? -ne 0 ] && echo $BASH_SOURCE dbg error && exit 2
0257 fi 
0258 
0259 if [ -n "$script" -a -f "$script" ]; then 
0260     ${IPYTHON:-ipython} --pdb -i $script 
0261     [ $? -ne 0 ] && echo $BASH_SOURCE script $script error && exit 4
0262 else
0263     echo $BASH_SOURCE no ana script $script is defined OR does not exist for arg $arg 
0264 fi 
0265 
0266 
0267 if [ -f "$ENVOUT" ]; then 
0268     if [ "$arg" == "pvcap" -o "$arg" == "pvpub" -o "$arg" == "mpcap" -o "$arg" == "mppub" ]; then
0269         echo $BASH_SOURCE : detected that python wrote ENVOUT $ENVOUT : sourcing this
0270         cat $ENVOUT
0271         source $ENVOUT
0272         env | grep ENVOUT 
0273     else
0274         echo $BASH_SOURCE : remove prior ENVOUT $ENVOUT 
0275         rm $ENVOUT
0276     fi 
0277 fi
0278 
0279 
0280 notes(){ cat << EON
0281 ENVOUT COMMUNICATION FROM PYTHON BACK TO BASH
0282 -----------------------------------------------
0283 
0284 The U4SimulateTest_pr.py script writes ENVOUT 
0285 
0286 
0287 NOTICE HOW ENVOUT COMMUNICATION RELIES ON OVERLAPPED RUNNING OF THIS BASH SCRIPT
0288 
0289 1. IPYTHON PLOTTING RUNS AND WRITES THE ENVOUT FILE, POPS UP THE GUI WINDOW AND BLOCKS
0290 
0291 2. THEN IN A DIFFERENT TAB THE MPCAP/MPPUB IS RUN THAT SOURCES THE ENVOUT
0292    IN ORDER TO CONFIGURE CAPTURE NAMING
0293 
0294 3. FINALLY THE FIRST PYTHON PLOTTER SESSION IS EXITED THAT CLEANS UP THE ENVOUT FILE.  
0295 
0296 So the ENVOUT file just contains the config for the currently displayed plot, and 
0297 should only exist when a plot is being displayed. More than one plot of the same 
0298 type displayed at the same time is not handled. 
0299 
0300 EON
0301 }
0302 
0303 if [ "$arg" == "pvcap" -o "$arg" == "pvpub" -o "$arg" == "mpcap" -o "$arg" == "mppub" ]; then
0304     if [ -n "$ENVOUT_VERSION" ]; then
0305         echo $BASH_SOURCE picking up ENVOUT_VERSION $ENVOUT_VERSION 
0306         VERSION=$ENVOUT_VERSION
0307     fi 
0308 
0309     if [ -n "$ENVOUT_CAP_STEM" ]; then
0310         echo $BASH_SOURCE picking up ENVOUT_CAP_STEM $ENVOUT_CAP_STEM 
0311         export CAP_STEM=$ENVOUT_CAP_STEM
0312     else
0313         export CAP_STEM=$GEOM
0314     fi 
0315 
0316     export CAP_BASE=$BASE/$VERSION/figs
0317     export CAP_REL=U4SimulateTest
0318     case $arg in  
0319        pvcap) source pvcap.sh cap  ;;  
0320        mpcap) source mpcap.sh cap  ;;  
0321        pvpub) source pvcap.sh env  ;;  
0322        mppub) source mpcap.sh env  ;;  
0323     esac
0324     if [ "$arg" == "pvpub" -o "$arg" == "mppub" ]; then 
0325         source epub.sh 
0326     fi  
0327 fi 
0328 
0329 exit 0 
0330