File indexing completed on 2026-04-09 07:49:03
0001
0002 usage(){ cat << EOU
0003 G4CXOpticks_setGeometry_Test.sh
0004 ===================================
0005
0006 ::
0007
0008 ~/o/g4cx/tests/G4CXOpticks_setGeometry_Test.sh
0009 LOG=1 ~/o/g4cx/tests/G4CXOpticks_setGeometry_Test.sh
0010
0011
0012 Test of geometry conversion in isolation::
0013
0014 Geant4 --[U4]--> SSim/stree --[CSGImport]-> CSGFoundry
0015
0016
0017 HOW TO LOAD YOUR GDML FILE WITH THIS SCRIPT
0018 ---------------------------------------------
0019
0020 There are several ways to configure GDML loading currently, see "G4CXOpticks::setGeometry()".
0021 However this script uses just one of them. The relevant lines
0022 for this config from this bash script are::
0023
0024 source $HOME/.opticks/GEOM/GEOM.sh
0025 origin=$HOME/.opticks/GEOM/$GEOM/origin.gdml
0026 export ${GEOM}_GDMLPathFromGEOM=$origin
0027
0028 So to load your own GDML using this script, without changing this script:
0029
0030 1. decide on identifier string for your geometry, eg Z36
0031 2. create or edit the file $HOME/.opticks/GEOM/GEOM.sh (NB not in repo) for example containing::
0032
0033
0034
0035 geom=Z39
0036 export GEOM=$geom
0037
0038 * the "GEOM" bash function defaults to editing this GEOM.sh as
0039 a shortcut for quickly changing between geometries
0040
0041 3. copy your gdml file to the path that this script expects::
0042
0043 $HOME/.opticks/GEOM/Z36/origin.gdml
0044
0045 4. now you can run the script with::
0046
0047 ~/opticks/g4cx/tests/G4CXOpticks_setGeometry_Test.sh
0048
0049 5. examine translated geometry that is written to folders beneath::
0050
0051 $HOME/.opticks/GEOM/Z36/CSGFoundry/
0052
0053 6. the Opticks CSGFoundry geometry is comprised of NumPy .npy and .txt files
0054 which can all be examined from python, use the below command to
0055 load the geometry into python::
0056
0057 ~/opticks/g4cx/tests/G4CXOpticks_setGeometry_Test.sh ana
0058
0059
0060 For example, the JUNO geometry with Opticks GEOM identifier "V1J011"
0061 is comprised of ~200 .npy and ~150 .txt files::
0062
0063 epsilon:~ blyth$ find ~/.opticks/GEOM/V1J011/CSGFoundry -type f -name '*.npy' | wc -l
0064 199
0065 epsilon:~ blyth$ find ~/.opticks/GEOM/V1J011/CSGFoundry -type f -name '*.txt' | wc -l
0066 146
0067 epsilon:~ blyth$ find ~/.opticks/GEOM/V1J011/CSGFoundry -type f | wc -l
0068 345
0069
0070
0071 Note that following the conventions of this script enables switching
0072 between geometries without changing this script, simply by setting the
0073 GEOM envvar that is exported from $HOME/.opticks/GEOM/GEOM.sh
0074
0075
0076 EOU
0077 }
0078
0079 cd $(dirname $(realpath $BASH_SOURCE))
0080 source dbg__.sh
0081
0082 defarg=info_run_ana
0083 arg=${1:-$defarg}
0084
0085 bin=G4CXOpticks_setGeometry_Test
0086 script=$bin.py
0087
0088 source $HOME/.opticks/GEOM/GEOM.sh
0089 [ -z "$GEOM" ] && echo $BASH_SOURCE : FATAL GEOM $GEOM MUST BE SET && exit 1
0090
0091
0092 case $GEOM in
0093 FewPMT) geomscript=../../u4/tests/FewPMT.sh ;;
0094 esac
0095
0096 if [ -n "$geomscript" -a -f "$geomscript" ]; then
0097 echo $BASH_SOURCE : GEOM $GEOM : sourcing geomscript $geomscript
0098 source $geomscript
0099 else
0100 echo $BASH_SOURCE : GEOM $GEOM : no geomscript
0101 fi
0102
0103
0104
0105
0106 vars="BASH_SOURCE arg SDIR GEOM savedir FOLD bin geomscript script origin"
0107
0108
0109 export GProperty_SIGINT=1
0110
0111
0112
0113
0114 savedir=~/.opticks/GEOM/$GEOM
0115
0116 export FOLD=$savedir
0117 export G4CXOpticks__setGeometry_saveGeometry=$savedir
0118 export G4CXOpticks__saveGeometry_saveGGeo=1
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 logging(){
0130 type $FUNCNAME
0131 export Dummy=INFO
0132 export G4CXOpticks=INFO
0133 export U4Tree=INFO
0134
0135
0136 }
0137 [ -n "$LOG" ] && logging
0138 env | grep =INFO
0139
0140
0141 if [ "${arg/info}" != "$arg" ]; then
0142 for var in $vars ; do printf "%30s : %s \n" "$var" "${!var}" ; done
0143 fi
0144
0145 if [ "${arg/run}" != "$arg" ]; then
0146
0147 ./GXTestRunner.sh $bin
0148 [ $? -ne 0 ] && echo $BASH_SOURCE : run error && exit 1
0149 fi
0150
0151 if [ "${arg/dbg}" != "$arg" ]; then
0152
0153 source dbg__.sh
0154 origin=$HOME/.opticks/GEOM/$GEOM/origin.gdml
0155 if [ -f "$origin" ]; then
0156 export ${GEOM}_GDMLPathFromGEOM=$origin
0157 fi
0158
0159 dbg__ $bin
0160 [ $? -ne 0 ] && echo $BASH_SOURCE : dbg error && exit 2
0161 fi
0162
0163 if [ "${arg/pdb}" != "$arg" ]; then
0164 ${IPYTHON:-ipython} --pdb -i $script
0165 [ $? -ne 0 ] && echo $BASH_SOURCE : pdb error && exit 3
0166 fi
0167
0168 if [ "${arg/ana}" != "$arg" ]; then
0169 ${PYTHON:-python} $script
0170 [ $? -ne 0 ] && echo $BASH_SOURCE : ana error && exit 4
0171 fi
0172
0173 exit 0
0174