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 G4CXTest_GEOM.sh : Standalone optical only bi-simulation with G4CXApp::Main and current GEOM
0004 ================================================================================================
0005 
0006 Standalone optical Geant4 initialization is faster than embedded Geant4 + Opticks but still ~120s to voxelize.
0007 
0008 
0009 Usage examples
0010 ----------------
0011 
0012 Typically on workstation::
0013 
0014     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh
0015     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh dbg
0016     LOG=1 BP=C4CustomART::doIt ~/opticks/g4cx/tests/G4CXTest_GEOM.sh dbg
0017 
0018     PRECOOKED=1 ~/o/G4CXTest_GEOM.sh
0019 
0020     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh info
0021     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh chi2
0022 
0023 
0024 Following inclusion of _${TEST} in LOGDIR can compare different tests easily
0025 -----------------------------------------------------------------------------
0026 
0027 ::
0028 
0029     TEST=jan20 ~/opticks/g4cx/tests/G4CXTest_GEOM.sh chi2
0030 
0031     TEST=feb20 ~/opticks/g4cx/tests/G4CXTest_GEOM.sh chi2  ## small diffs only following DEBUG_TAG switch off from different randoms
0032     TEST=ref1  ~/opticks/g4cx/tests/G4CXTest_GEOM.sh chi2  ## same as feb20
0033 
0034 
0035 
0036 Reporting on the nature of the geometry conversion
0037 ------------------------------------------------------
0038 
0039 Q: This is running from GDML, is the force triangulation done ?
0040 A: probably not without the config::
0041 
0042    export stree__force_triangulate_solid='filepath:$HOME/.opticks/GEOM/${GEOM}_meshname_stree__force_triangulate_solid.txt'
0043 
0044 
0045 TODO: confirmation in metadata of what is triangulated in the geometry, stree level for details and CSGFoundry::descSolidIntent
0046 for the collective situation
0047 
0048 
0049 The info would be persisted with the stree info, but no persist ? Can be reported by stree::desc_lvid::
0050 
0051      318     const char*      force_triangulate_solid ;
0052      319     std::vector<int> force_triangulate_lvid ;
0053 
0054 
0055 
0056 
0057 Laptop::
0058 
0059     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh grab
0060     EYE=0,-400,0 ~/opticks/g4cx/tests/G4CXTest_GEOM.sh ana
0061     ~/opticks/g4cx/tests/G4CXTest_GEOM.sh pvcap
0062 
0063 
0064 Where possible its better to use pure Opticks simulation (no bi-simulation)
0065 booting from a persisted geometry during testing due to the ~2s initialization time, eg with::
0066 
0067     ~/opticks/CSGOptiX/cxs_min.sh
0068 
0069 
0070 chi2 subcommand uses a faster C++ sseq index comparison implementation of the python/NumPy chi2 calc
0071 ---------------------------------------------------------------------------------------------------------
0072 
0073 Uses::
0074 
0075    $SDIR/../../sysrap/tests/sseq_index_test.sh info_run_ana
0076 
0077 *  ~/opticks/sysrap/tests/sseq_index_test.sh
0078 
0079 
0080 
0081 storch::generate is used for both GPU and CPU generation
0082 ---------------------------------------------------------
0083 
0084 * On GPU the generation is invoked at highest level CSGOptiX7.cu:simulate
0085 * On CPU for example the stack is below, using MOCK_CURAND::
0086 
0087   G4RunManager::BeamOn
0088   ...
0089   G4RunManager::GenerateEvent
0090   G4CXApp::GeneratePrimaries
0091   U4VPrimaryGenerator::GeneratePrimaries
0092   SGenerate::GeneratePhotons
0093   storch::generate
0094 
0095 
0096 
0097 EOU
0098 }
0099 
0100 SDIR=$(dirname $(realpath $BASH_SOURCE))
0101 ## not the normal cd to the SDIR, as need to cd to LOGDIR but use scripts from SDIR
0102 
0103 bin=G4CXTest
0104 ana_script=$SDIR/G4CXTest_GEOM.py
0105 dna_script=$SDIR/G4CXTest.py
0106 
0107 source $HOME/.opticks/GEOM/GEOM.sh   # set GEOM and associated envvars for finding geometry
0108 #export ${GEOM}_GDMLPathFromGEOM=$HOME/.opticks/GEOM/$GEOM/origin.gdml
0109 # no longer needed as using spath::GDMLPathFromGEOM
0110 
0111 _cfb=${GEOM}_CFBaseFromGEOM
0112 cfb=${!_cfb}
0113 tessname=$cfb/CSGFoundry/tessname.txt
0114 
0115 if [ -f "$tessname" ]; then
0116     export stree__force_triangulate_solid="filepath:$tessname"
0117     export SSim__stree_level=1
0118 else
0119     echo $BASH_SOURCE tessname $tessname DOES NOT EXIST
0120 fi
0121 
0122 
0123 
0124 
0125 
0126 ## CURRENTLY CAN MANUALLY CHECK WHAT IS TRIANGULATED BY UPPING THE LOGGING
0127 ## TODO: some reporting in metadata of which solids are triangulated that gets saved with event metadata
0128 
0129 
0130 #test=small
0131 test=ref1
0132 #test=ref5
0133 #test=large_scan
0134 TEST=${TEST:-$test}
0135 
0136 if [ "$TEST" == "ref1" ]; then
0137 
0138    opticks_num_event=1
0139    opticks_num_genstep=1
0140    opticks_num_photon=M1
0141    opticks_max_slot=M1
0142 
0143 elif [ "$TEST" == "ref5" ]; then
0144 
0145    opticks_num_event=1
0146    opticks_num_genstep=1
0147    opticks_num_photon=M5
0148    opticks_max_slot=M5
0149 
0150 
0151 elif [ "$TEST" == "one" ]; then
0152 
0153    opticks_num_event=1
0154    opticks_num_genstep=1
0155    opticks_num_photon=1
0156    opticks_max_slot=1
0157 
0158 elif [ "$TEST" == "two" ]; then
0159 
0160    opticks_num_event=1
0161    opticks_num_genstep=1
0162    opticks_num_photon=2
0163    opticks_max_slot=2
0164 
0165 elif [ "$TEST" == "small" ]; then
0166 
0167    opticks_num_event=1
0168    opticks_num_genstep=1
0169    opticks_num_photon=H1
0170    opticks_max_slot=M1
0171 
0172 elif [ "$TEST" == "tiny_scan" ]; then
0173 
0174    opticks_num_event=10
0175    opticks_num_genstep=1x10
0176    opticks_num_photon=K1:10
0177    opticks_max_slot=M1
0178 
0179 elif [ "$TEST" == "large_scan" ]; then
0180 
0181    opticks_num_event=20
0182    opticks_num_genstep=1x10,10x10
0183    opticks_num_photon=H1:10,M2,3,5,7,10,20,40,60,80,100
0184    opticks_max_slot=M100
0185 
0186 elif [ "$TEST" == "large_evt" ]; then
0187 
0188    opticks_num_event=1
0189    opticks_num_genstep=40
0190    opticks_num_photon=M180   ## M200 gives OOM with TITAN RTX 24G with debug arrays enabled
0191    opticks_max_slot=M180
0192 
0193 else
0194 
0195    echo $BASH_SOURCE ERROR TEST $TEST IS NOT HANDLED
0196    echo $BASH_SOURCE ERROR TEST $TEST IS NOT HANDLED
0197    echo $BASH_SOURCE ERROR TEST $TEST IS NOT HANDLED ... SLEEPING
0198    sleep 100
0199 fi
0200 
0201 
0202 
0203 version=98
0204 VERSION=${VERSION:-$version}
0205 export VERSION    ## used in SEvt output directory name ALL$VERSION
0206 
0207 
0208 #ctx=$(TEST=ContextString sbuild_test)  ## eg Debug_Philox see sbuild.h
0209 ctx=Debug_Philox
0210 #export OPTICKS_EVENT_NAME=$ctx  # used by SEventConfig::EventReldir "OPTICKS_EVENT_RELDIR"
0211 export OPTICKS_EVENT_NAME=${ctx}_${TEST}
0212 
0213 
0214 opticks_event_reldir=ALL${VERSION:-0}_${OPTICKS_EVENT_NAME:-none}
0215 export OPTICKS_EVENT_RELDIR='ALL${VERSION:-0}_${OPTICKS_EVENT_NAME:-none}'  ## this is the default in SEventConfig
0216 ## above two lines match SEventConfig::_DefaultEventReldir
0217 ## resolution of first line happens here for bash consumption, resolution of 2nd done in SEventConfig
0218 ## HMM: MAYBE SIMPLIFY BY JUST DEFINING RELDIR HERE, BUT THE CODE DEFAULT IS HANDY ?
0219 
0220 TMP=${TMP:-/tmp/$USER/opticks}
0221 
0222 # /data1/blyth/tmp/GEOM/J25_3_0_Opticks_v0_3_5/G4CXTest/ALL98_Debug_Philox_ref5
0223 
0224 export SCRIPT=$(basename $BASH_SOURCE)
0225 export BASE=$TMP/GEOM/$GEOM
0226 export LOGDIR=$BASE/$bin/$opticks_event_reldir
0227 export AFOLD=$LOGDIR/A000
0228 export BFOLD=$LOGDIR/B000
0229 #export BFOLD=$TMP/GEOM/$GEOM/CSGOptiXSMTest/ALL/A000  ## TMP OVERRIDE COMPARE A-WITH-A from CSGOptiXSMTest
0230 
0231 pick=A
0232 export PICK=${PICK:-$pick}  ## PICK is only used by ana, not running
0233 case $PICK in
0234     A) FOLD=$AFOLD ;;
0235     B) FOLD=$BFOLD ;;
0236    AB) FOLD=$AFOLD ;;
0237 esac
0238 export FOLD    ## changed sreport to use SREPORT_FOLD to avoid clash
0239 export STEM=G4CXTest_GEOM_${PICK}
0240 
0241 mkdir -p $LOGDIR
0242 cd $LOGDIR            ## logfile written in invoking directory
0243 
0244 
0245 #export G4CXOpticks__SaveGeometry_DIR=$BASE  ## optionally save geom into BASE for debug
0246 export G4CXApp__SensDet=PMTSDMgr             ## used for post GDML SensDet hookup
0247 
0248 
0249 
0250 knobs()
0251 {
0252    type $FUNCNAME
0253 
0254    local exceptionFlags
0255    local debugLevel
0256    local optLevel
0257 
0258    #exceptionFlags=STACK_OVERFLOW
0259    exceptionFlags=NONE
0260 
0261    #debugLevel=DEFAULT
0262    debugLevel=NONE
0263    #debugLevel=FULL
0264 
0265    #optLevel=DEFAULT
0266    #optLevel=LEVEL_0
0267    optLevel=LEVEL_3
0268 
0269 
0270    #export PIP__max_trace_depth=1
0271    export PIP__CreatePipelineOptions_exceptionFlags=$exceptionFlags # NONE/STACK_OVERFLOW/TRACE_DEPTH/USER/DEBUG
0272    export PIP__CreateModule_debugLevel=$debugLevel  # DEFAULT/NONE/MINIMAL/MODERATE/FULL   (DEFAULT is MINIMAL)
0273    export PIP__linkPipeline_debugLevel=$debugLevel  # DEFAULT/NONE/MINIMAL/MODERATE/FULL
0274    export PIP__CreateModule_optLevel=$optLevel      # DEFAULT/LEVEL_0/LEVEL_1/LEVEL_2/LEVEL_3
0275 
0276    #export Ctx=INFO
0277    #export PIP=INFO
0278    #export CSGOptiX=INFO
0279 }
0280 knobs
0281 
0282 
0283 case $VERSION in
0284  0) opticks_event_mode=Minimal ;;
0285  1) opticks_event_mode=Hit ;;
0286  2) opticks_event_mode=HitPhoton ;;
0287  3) opticks_event_mode=HitPhoton ;;    ## USING 3 FOR LEAK TEST
0288  4) opticks_event_mode=HitPhotonSeq ;;
0289  5) opticks_event_mode=HitSeq ;;
0290 98) opticks_event_mode=DebugLite ;;
0291 99) opticks_event_mode=DebugHeavy ;;
0292 esac
0293 
0294 
0295 
0296 
0297 opticks_start_index=0
0298 opticks_max_bounce=31
0299 opticks_integration_mode=3
0300 
0301 #opticks_running_mode=SRM_DEFAULT
0302 opticks_running_mode=SRM_TORCH
0303 #opticks_running_mode=SRM_INPUT_PHOTON
0304 #opticks_running_mode=SRM_INPUT_GENSTEP    ## NOT IMPLEMENTED FOR GEANT4
0305 #opticks_running_mode=SRM_GUN
0306 
0307 
0308 export OPTICKS_NUM_EVENT=${OPTICKS_NUM_EVENT:-$opticks_num_event}
0309 export OPTICKS_NUM_GENSTEP=${OPTICKS_NUM_GENSTEP:-$opticks_num_genstep}
0310 export OPTICKS_NUM_PHOTON=${OPTICKS_NUM_PHOTON:-$opticks_num_photon}
0311 
0312 export OPTICKS_RUNNING_MODE=${OPTICKS_RUNNING_MODE:-$opticks_running_mode}   # SRM_TORCH/SRM_INPUT_PHOTON/SRM_INPUT_GENSTEP
0313 export OPTICKS_EVENT_MODE=${OPTICKS_EVENT_MODE:-$opticks_event_mode}         # what arrays are saved eg Hit,HitPhoton,HitPhotonSeq
0314 
0315 
0316 export OPTICKS_MAX_SLOT=${OPTICKS_MAX_SLOT:-$opticks_max_slot}
0317 export OPTICKS_START_INDEX=${OPTICKS_START_INDEX:-$opticks_start_index}
0318 export OPTICKS_MAX_BOUNCE=${OPTICKS_MAX_BOUNCE:-$opticks_max_bounce}
0319 export OPTICKS_INTEGRATION_MODE=${OPTICKS_INTEGRATION_MODE:-$opticks_integration_mode}
0320 
0321 
0322 if [ -n "$PRECOOKED" ]; then
0323     ## SPECIAL SETTING TO GET G4CXApp::GeneratePrimaries
0324     ## TO USE THE SAME RANDOMS AS CURAND : SO CAN COMPARE
0325     ## WITH THE SAME START PHOTONS
0326     export SGenerate__GeneratePhotons_RNG_PRECOOKED=1
0327     export s_seq__SeqPath_DEFAULT_LARGE=1   ## enable M1, without this are limited to K100
0328 fi
0329 
0330 
0331 if [ "$OPTICKS_RUNNING_MODE" == "SRM_TORCH" ]; then
0332     #export SEvent_MakeGenstep_num_ph=$NUM   ## trumped by OPTICKS_NUM_PHOTON
0333     #src="rectangle"
0334     #src="disc"
0335     src="sphere"
0336 
0337     if [ "$src" == "rectangle" ]; then
0338         export storch_FillGenstep_pos=0,0,0
0339         export storch_FillGenstep_type=rectangle
0340         export storch_FillGenstep_zenith=-20,20
0341         export storch_FillGenstep_azimuth=-20,20
0342     elif [ "$src" == "disc" ]; then
0343         export storch_FillGenstep_type=disc
0344         export storch_FillGenstep_radius=50
0345         export storch_FillGenstep_zenith=0,1       # radial range scale
0346         export storch_FillGenstep_azimuth=0,1      # phi segment twopi fraction
0347         export storch_FillGenstep_mom=1,0,0
0348         export storch_FillGenstep_pos=-80,0,0
0349     elif [ "$src" == "sphere" ]; then
0350         export storch_FillGenstep_type=sphere
0351         export storch_FillGenstep_radius=100    # +ve for outwards
0352         export storch_FillGenstep_pos=0,0,0
0353         export storch_FillGenstep_distance=1.00 # frac_twopi control of polarization phase(tangent direction)
0354     fi
0355 
0356 elif [ "$OPTICKS_RUNNING_MODE" == "SRM_INPUT_PHOTON" ]; then
0357     echo -n
0358 
0359     ## UNTESTED
0360     export OPTICKS_INPUT_PHOTON=RainXZ_Z230_10k_f8.npy
0361     export OPTICKS_INPUT_PHOTON_FRAME=NNVT:0:1000
0362 
0363 elif [ "$OPTICKS_RUNNING_MODE" == "SRM_INPUT_GENSTEP" ]; then
0364     echo -n
0365 
0366 elif [ "$OPTICKS_RUNNING_MODE" == "SRM_GUN" ]; then
0367     echo -n
0368 fi
0369 
0370 logging()
0371 {
0372    #export SSim=INFO
0373    #export QSim=INFO
0374    #export QPMT=INFO
0375    #export SEvt=INFO
0376    #export U4Recorder=INFO
0377    #export U4StepPoint=INFO
0378    #export U4Physics=INFO
0379    #export CSGFoundry=INFO
0380    #export CSGTarget=INFO
0381 
0382    #export U4GDML__VERBOSE=1
0383    #export SPMTAccessor__VERBOSE=1
0384    #export SEvt__LIFECYCLE=1  ## sparse SEvt debug output, works well alone
0385 
0386    export G4CXOpticks=INFO
0387 
0388 }
0389 [ -n "$LOG" ] && logging
0390 [ -n "$LIFECYCLE" ] && export SEvt__LIFECYCLE=1
0391 
0392 allarg="info_env_run_dbg_report_plot_grab_gevt_chi2_ana_dna_mpcap_mppub_pvcap_pvpub"
0393 defarg="info_env_run_report_ana"
0394 #defarg="info_dbg_ana"
0395 [ -n "$BP" ] && defarg="info_dbg"
0396 
0397 arg=${1:-$defarg}
0398 
0399 
0400 
0401 vars="BASH_SOURCE allarg defarg arg SDIR GEOM ${GEOM}_CFBaseFromGEOM ${GEOM}_GDMLPathFromGEOM bin VERSION"
0402 vars="$vars TMP BASE PWD"
0403 vars="$vars OPTICKS_EVENT_NAME OPTICKS_EVENT_RELDIR"
0404 vars="$vars LOGDIR AFOLD BFOLD CUDA_VISIBLE_DEVICES ana_script dna_script TEST"
0405 
0406 
0407 if [ "${arg/info}" != "$arg" ]; then
0408     for var in $vars ; do printf "%50s : %s \n" "$var" "${!var}" ; done
0409 fi
0410 
0411 if [ "${arg/env}" != "$arg" ]; then
0412     env | grep OPTICKS | perl -n -e 'm/(\S*)=(\S*)/ && printf("%50s : %s\n", $1, $2) ' -
0413 fi
0414 
0415 if [ "${arg/run}" != "$arg" ]; then
0416     rm -f $bin.log
0417     $bin
0418     [ $? -ne 0 ] && echo $BASH_SOURCE run error && exit 1
0419     pwd
0420     ls -alst $bin.log
0421 fi
0422 
0423 if [ "${arg/dbg}" != "$arg" ]; then
0424     source dbg__.sh
0425     dbg__ $bin
0426     [ $? -ne 0 ] && echo $BASH_SOURCE dbg error && exit 2
0427 fi
0428 
0429 if [ "${arg/report}" != "$arg" ]; then
0430     sreport
0431     [ $? -ne 0 ] && echo $BASH_SOURCE sreport error && exit 1
0432 fi
0433 
0434 if [ "${arg/plot}" != "$arg" ]; then
0435     runprof=1 $SDIR/../../sysrap/tests/sreport.sh ana
0436     [ $? -ne 0 ] && echo $BASH_SOURCE sreport.plot error && exit 1
0437 fi
0438 
0439 if [ "${arg/grab}" != "$arg" ]; then
0440     echo $FUNCNAME - grab - WARNING - debug events can be VERY LARGE - use gevt to rsync single event
0441     source $SDIR/../../bin/rsync.sh $LOGDIR
0442     [ $? -ne 0 ] && echo $BASH_SOURCE grab error && exit 3
0443 fi
0444 
0445 if [ "${arg/gevt}" != "$arg" ]; then
0446     source $SDIR/../../bin/rsync.sh $AFOLD
0447     source $SDIR/../../bin/rsync.sh $BFOLD
0448 fi
0449 
0450 if [ "${arg/chi2}" != "$arg" ]; then
0451     #$SDIR/../../sysrap/tests/sseq_index_test.sh info_run_ana
0452     sseq_index_test.sh info_run_ana
0453     [ $? -ne 0 ] && echo $BASH_SOURCE sseq_index_test chi2 ERROR && exit 3
0454 fi
0455 
0456 if [ "${arg/pdb}" != "$arg" ]; then
0457     export SAB=1
0458     PYTHONPATH=$OPTICKS_PREFIX/py ${IPYTHON:-ipython} --pdb -i $ana_script
0459     [ $? -ne 0 ] && echo $BASH_SOURCE pdb error with ana_script $ana_script && exit 4
0460 fi
0461 
0462 if [ "${arg/ana}" != "$arg" ]; then
0463     ${PYTHON:-python} $ana_script
0464     [ $? -ne 0 ] && echo $BASH_SOURCE ana error with ana_script $ana_script && exit 4
0465 fi
0466 
0467 if [ "${arg/dna}" != "$arg" ]; then
0468     ${IPYTHON:-ipython} --pdb -i $dna_script
0469     [ $? -ne 0 ] && echo $BASH_SOURCE dna error with dna_script $dna_script && exit 4
0470 fi
0471 
0472 
0473 
0474 
0475 if [ "$arg" == "mpcap" -o "$arg" == "mppub" -o "$arg" == "pvcap" -o "$arg" == "pvpub" ]; then
0476     export CAP_BASE=$FOLD/figs
0477     export CAP_REL=G4CXTest_GEOM
0478     export CAP_STEM=$STEM
0479     case $arg in
0480        mpcap) source mpcap.sh cap  ;;
0481        pvcap) source pvcap.sh cap  ;;
0482        mppub) source mpcap.sh env  ;;
0483        pvpub) source pvcap.sh env  ;;
0484     esac
0485     if [ "$arg" == "mppub" -o "$arg" == "pvpub" ]; then
0486         source epub.sh
0487     fi
0488 fi
0489 
0490 exit 0
0491