Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #!/bin/bash -l 
0002 usage(){ cat << EOU
0003 u4s.sh : formerly U4RecorderTest.sh : Geant4 simulation with Opticks recording every random consumption of every step of every photon
0004 =========================================================================================================================================
0005 
0006 ::
0007 
0008     cd ~/opticks/u4   # u4
0009     ./u4s.sh 
0010 
0011     BP=DsG4Scintillation::PostStepDoIt ./u4s.sh dbg 
0012 
0013     ./u4s.sh run
0014     DRYRUN=1 ./u4s.sh run  ## eg to check config of input and output folders 
0015 
0016     ./u4s.sh dbg
0017     ./u4s.sh clean
0018     ./u4s.sh ana
0019     ./u4s.sh ab
0020 
0021 
0022 U4RecorderTest requires A_CFBASE and A_FOLD envvars to find inputs::
0023 
0024      U4Material::LoadBnd("$A_CFBASE/CSGFoundry/SSim") ; // booting G4Material from A:bnd.npy
0025    
0026      sframe fr = sframe::Load_("$A_FOLD/sframe.npy");   // for transforming input photons  
0027       
0028 
0029 U4RecorderTest invokes "SEvt::save()" writing .npy to '$DefaultOutputDir/SEvt::reldir' eg::
0030 
0031 
0032 
0033 
0034 EOU
0035 }
0036 msg="=== $BASH_SOURCE :"
0037 
0038 case $(uname) in 
0039    Linux) defarg="run" ;;
0040    Darwin) defarg="ana" ;; 
0041 esac
0042 arg=${1:-$defarg}
0043 
0044 case $arg in 
0045   fold) QUIET=1 ;;
0046 esac
0047 
0048 
0049 bin=U4RecorderTest
0050 u4sdir=$(dirname $BASH_SOURCE)
0051 srcdir=$u4sdir
0052 logdir=/tmp/$USER/opticks/$bin
0053 mkdir -p $logdir 
0054 foldbase=$logdir
0055 
0056 
0057 export DsG4Scintillation_opticksMode=3  # 3:0b11 collect gensteps and do Geant4 generation loop too 
0058 
0059 #export DsG4Scintillation_verboseLevel=3
0060 #export DsG4Scintillation_DISABLE=1
0061 #export G4Cerenkov_verboseLevel=3
0062 #export G4Cerenkov_DISABLE=1
0063 #pidx=0
0064 #gidx=117
0065 #export PIDX=${PIDX:-$pidx}
0066 #export GIDX=${GIDX:-$gidx}
0067 
0068 export U4Random_select_action=interrupt   ## dumps stack and breaks in debugger to check the process
0069 
0070 #mode=gun
0071 #mode=torch
0072 mode=iphoton
0073 export U4RecorderTest__PRIMARY_MODE=$mode
0074 
0075 #source ./IDPath_override.sh   
0076 # IDPath_override.sh : non-standard IDPath to allow U4Material::LoadOri to find material properties 
0077 # HMM probably doing nothing now that are using U4Material::LoadBnd ?
0078 
0079 source $u4sdir/../bin/GEOM_.sh 
0080 
0081 if [ "$U4RecorderTest__PRIMARY_MODE" == "iphoton" ]; then
0082     source $u4sdir/../bin/OPTICKS_INPUT_PHOTON.sh     
0083 fi 
0084 
0085 upfind_cfbase(){
0086     : traverse directory tree upwards 
0087     local dir=$1
0088     while [ ${#dir} -gt 1 -a ! -f "$dir/CSGFoundry/solid.npy" ] ; do dir=$(dirname $dir) ; done 
0089     echo $dir
0090 }
0091 
0092 A_FOLD=$($OPTICKS_HOME/g4cx/gxs.sh fold)
0093 A_CFBASE=$(upfind_cfbase $A_FOLD)  
0094 
0095 if [ -z "$A_CFBASE" ]; then 
0096    echo $msg FAILED TO FIND A_CFBASE starting from A_FOLD $A_FOLD
0097    exit 1
0098 fi 
0099 
0100 export A_FOLD     # A_FOLD is needed for loading "$A_FOLD/sframe.npy" 
0101 export A_CFBASE   # A_CFBASE needed for loading  "$A_CFBASE/CSGFoundry/SSim"
0102 
0103 export ShimG4OpAbsorption_FLOAT=1 
0104 export ShimG4OpRayleigh_FLOAT=1 
0105 
0106 # cf U4Physics::Desc
0107 physdesc=""
0108 [ -n "$ShimG4OpAbsorption_FLOAT" ] && physdesc="${physdesc}ShimG4OpAbsorption_FLOAT" 
0109 [ -z "$ShimG4OpAbsorption_FLOAT" ] && physdesc="${physdesc}ShimG4OpAbsorption_ORIGINAL" 
0110 physdesc="${physdesc}_"
0111 [ -n "$ShimG4OpRayleigh_FLOAT" ]   && physdesc="${physdesc}ShimG4OpRayleigh_FLOAT"
0112 [ -z "$ShimG4OpRayleigh_FLOAT" ]   && physdesc="${physdesc}ShimG4OpRayleigh_ORIGINAL"
0113 
0114 #sel=PIDX_0_
0115 sel=ALL
0116 reldir=$physdesc/$sel     # SEvt::SetReldir 
0117 
0118 
0119 BASE=$GEOMDIR/$bin
0120 UBASE=${BASE//$HOME\/}    # UBASE is BASE relative to HOME to handle rsync between different HOME
0121 FOLD=$BASE/$reldir
0122 
0123 export FOLD
0124 
0125 # for GEOMDIR within /tmp there is no need to override the DefaultOutputDir 
0126 # but for GEOMDIR within geocache an override is necessary to keep A_FOLD and B_FOLD together
0127 case $GEOMDIR in 
0128    $HOME/.opticks/geocache/*) export OPTICKS_OUT_FOLD=$BASE ;;    # SEventConfig::OutFold override SEvt $DefaultOutputDir 
0129 esac
0130 
0131 if [ "${arg/fold}" != "${arg}" ]; then 
0132    echo $FOLD
0133 fi 
0134 
0135 if [ "${arg/info}" != "${arg}" ]; then 
0136     vars="BASH_SOURCE u4sdir GEOM GEOMDIR BASE OPTICKS_OUT_FOLD UBASE CFBASE FOLD A_FOLD A_CFBASE reldir" 
0137     for var in $vars ; do printf "%30s : %s \n" $var ${!var}  ; done 
0138     echo 
0139 fi 
0140 
0141 
0142 
0143 OPTICKS_RANDOM_SEQPATH_NOTES(){ cat << EON
0144 
0145 The default OPTICKS_RANDOM_SEQPATH in the U4Random code is limited to up to 100k photons
0146 as only a single 100k precooked random file is loaded. 
0147 
0148 When simulating more than 100k up to 1M photons it is necessary to uncomment the 
0149 below line to force loading of 10*100k files. 
0150 
0151 Note that OPTICKS_RANDOM_SEQPATH uses single quotes to prevent expansion of the '$PrecookedDir' 
0152 which is an SPath internal variable. 
0153 
0154 TODO: auto detect when this is needed and do the switch without requiring setting the envvar 
0155 
0156 EON
0157 }
0158 
0159 export OPTICKS_RANDOM_SEQPATH='$PrecookedDir/QSimTest/rng_sequence/rng_sequence_f_ni1000000_nj16_nk16_tranche100000'  
0160 
0161 
0162 
0163 loglevels()
0164 {
0165     export Dummy=INFO
0166     export U4VolumeMaker=INFO
0167     #export U4Material=INFO
0168     #export SEvt=INFO
0169     #export U4Random=INFO
0170 }
0171 loglevels
0172 
0173 
0174 
0175 
0176 if [ "${arg/run}" != "${arg}" ]; then 
0177     cd $logdir 
0178     $bin 
0179     [ $? -ne 0 ] && echo $msg run error && exit 1 
0180 
0181     echo $msg logdir $logdir
0182 fi 
0183 
0184 if [ "${arg/dbg}" != "${arg}" ]; then 
0185     cd $logdir 
0186     case $(uname) in 
0187        Linux)  gdb_ $bin;;
0188        Darwin) lldb__ $bin ;;
0189     esac
0190     [ $? -ne 0 ] && echo $msg dbg error && exit 2 
0191     echo $msg logdir $logdir
0192 fi 
0193 
0194 if [ "${arg/clean}" != "${arg}" ]; then
0195    cd $FOLD 
0196    pwd
0197    ls -l *.npy *.txt *.log
0198    read -p "$msg Enter YES to delete these : " ans
0199    if [ "$ans" == "YES" ] ; then 
0200        echo $msg proceeding
0201        rm *.npy *.txt *.log
0202    else
0203        echo $msg skip 
0204    fi 
0205 fi 
0206 
0207 if [ "${arg/ana}" != "${arg}" ]; then 
0208     cd $srcdir 
0209     pwd
0210     ${IPYTHON:-ipython} --pdb -i $u4sdir/tests/$bin.py 
0211 fi 
0212 
0213 if [ "${arg/grab}" != "${arg}" ]; then 
0214     echo $msg grab UBASE $UBASE
0215     source $u4sdir/../bin/rsync.sh $UBASE
0216 fi 
0217 
0218 if [ "${arg}" == "ab" ]; then 
0219     cd $srcdir 
0220     pwd
0221     #fold_mode=TMP
0222     #fold_mode=KEEP
0223     #fold_mode=LOGF
0224     fold_mode=GEOM
0225     export FOLD_MODE=${FOLD_MODE:-$fold_mode}
0226     source $u4sdir/../bin/AB_FOLD.sh 
0227     ${IPYTHON:-ipython} --pdb -i $u4sdir/tests/${bin}_ab.py $*  
0228 fi 
0229 
0230 
0231