-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxs_min.sh
executable file
·475 lines (353 loc) · 13.3 KB
/
cxs_min.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/bin/bash
usage(){ cat << EOU
cxs_min.sh : minimal executable and script for shakedown
============================================================
Usage::
~/o/cxs_min.sh
~/o/cxs_min.sh info
~/o/cxs_min.sh run ## create SEvt
~/o/cxs_min.sh report ## summarize SEvt metadata
Debug::
BP=SEvt::SEvt ~/opticks/CSGOptiX/cxs_min.sh
BP=SEvent::MakeTorchGenstep ~/opticks/CSGOptiX/cxs_min.sh
Analysis/Plotting::
~/o/cxs_min.sh grab
EVT=A000 ~/o/cxs_min.sh ana
MODE=2 SEL=1 ~/o/cxs_min.sh ana
EVT=A005 ~/o/cxs_min.sh ana
EVT=A010 ~/o/cxs_min.sh ana
PLOT=scatter MODE=3 ~/o/cxs_min.sh pvcap
Monitor for GPU memory leaks::
~/o/sysrap/smonitor.sh build_run # start monitor
TEST=large_scan ~/o/cxs_min.sh
# CTRL-C smonitor.sh session sending SIGINT to process which saves smonitor.npy
~/o/sysrap/smonitor.sh grab ## back to laptop
~/o/sysrap/smonitor.sh ana ## plot
EOU
}
SDIR=$(dirname $(realpath $BASH_SOURCE))
case $(uname) in
Linux) defarg=run_report_info ;;
Darwin) defarg=ana ;;
esac
[ -n "$BP" ] && defarg=dbg
[ -n "$PLOT" ] && defarg=ana
arg=${1:-$defarg}
bin=CSGOptiXSMTest
script=$SDIR/cxs_min.py
source ~/.opticks/GEOM/GEOM.sh # sets GEOM envvar
export EVT=${EVT:-A000}
export BASE=${TMP:-/tmp/$USER/opticks}/GEOM/$GEOM
export BINBASE=$BASE/$bin
export SCRIPT=$(basename $BASH_SOURCE)
Resolve_CFBaseFromGEOM()
{
: LOOK FOR CFBase directory containing CSGFoundry geometry
: HMM COULD PUT INTO GEOM.sh TO AVOID DUPLICATION ? BUT TOO MUCH HIDDEN ?
: G4CXOpticks_setGeometry_Test GEOM TAKES PRECEDENCE OVER .opticks/GEOM
: HMM : FOR SOME TESTS WANT TO LOAD GDML BUT FOR OTHERS CSGFoundry
: to handle that added gdml resolution to eg g4cx/tests/GXTestRunner.sh
local C_CFBaseFromGEOM=$TMP/G4CXOpticks_setGeometry_Test/$GEOM
local B_CFBaseFromGEOM=$HOME/.opticks/GEOM/$GEOM
local A_CFBaseFromGEOM=/cvmfs/opticks.ihep.ac.cn/.opticks/GEOM/$GEOM
local TestPath=CSGFoundry/prim.npy
local GDMLPathFromGEOM=$HOME/.opticks/GEOM/$GEOM/origin.gdml
if [ -d "$A_CFBaseFromGEOM" -a -f "$A_CFBaseFromGEOM/$TestPath" ]; then
export ${GEOM}_CFBaseFromGEOM=$A_CFBaseFromGEOM
echo $BASH_SOURCE : FOUND A_CFBaseFromGEOM $A_CFBaseFromGEOM containing $TestPath
elif [ -d "$B_CFBaseFromGEOM" -a -f "$B_CFBaseFromGEOM/$TestPath" ]; then
export ${GEOM}_CFBaseFromGEOM=$B_CFBaseFromGEOM
echo $BASH_SOURCE : FOUND B_CFBaseFromGEOM $B_CFBaseFromGEOM containing $TestPath
elif [ -d "$C_CFBaseFromGEOM" -a -f "$C_CFBaseFromGEOM/$TestPath" ]; then
export ${GEOM}_CFBaseFromGEOM=$C_CFBaseFromGEOM
echo $BASH_SOURCE : FOUND C_CFBaseFromGEOM $C_CFBaseFromGEOM containing $TestPath
elif [ -f "$GDMLPathFromGEOM" ]; then
export ${GEOM}_GDMLPathFromGEOM=$GDMLPathFromGEOM
echo $BASH_SOURCE : FOUND GDMLPathFromFromGEOM $GDMLPathFromFromGEOM
else
echo $BASH_SOURCE : NOT-FOUND A_CFBaseFromGEOM $A_CFBaseFromGEOM containing $TestPath
echo $BASH_SOURCE : NOT-FOUND B_CFBaseFromGEOM $B_CFBaseFromGEOM containing $TestPath
echo $BASH_SOURCE : NOT-FOUND C_CFBaseFromGEOM $C_CFBaseFromGEOM containing $TestPath
echo $BASH_SOURCE : NOT-FOUND GDMLPathFromGEOM $GDMLPathFromGEOM
fi
}
Resolve_CFBaseFromGEOM
knobs()
{
type $FUNCNAME
local exceptionFlags
local debugLevel
local optLevel
#exceptionFlags=STACK_OVERFLOW
exceptionFlags=NONE
#debugLevel=DEFAULT
debugLevel=NONE
#debugLevel=FULL
#optLevel=DEFAULT
#optLevel=LEVEL_0
optLevel=LEVEL_3
#export PIP__max_trace_depth=1
export PIP__CreatePipelineOptions_exceptionFlags=$exceptionFlags # NONE/STACK_OVERFLOW/TRACE_DEPTH/USER/DEBUG
export PIP__CreateModule_debugLevel=$debugLevel # DEFAULT/NONE/MINIMAL/MODERATE/FULL (DEFAULT is MINIMAL)
export PIP__linkPipeline_debugLevel=$debugLevel # DEFAULT/NONE/MINIMAL/MODERATE/FULL
export PIP__CreateModule_optLevel=$optLevel # DEFAULT/LEVEL_0/LEVEL_1/LEVEL_2/LEVEL_3
#export Ctx=INFO
#export PIP=INFO
#export CSGOptiX=INFO
export NPFold__substamp_DUMP=1
}
knobs
version=1
#version=98 ## set to 98 for low stats debugging
VERSION=${VERSION:-$version} ## see below currently using VERSION TO SELECT OPTICKS_EVENT_MODE
export VERSION
## VERSION CHANGES OUTPUT DIRECTORIES : SO USEFUL TO ARRANGE SEPARATE STUDIES
export LOGDIR=$BINBASE/ALL$VERSION
export AFOLD=$BINBASE/ALL$VERSION/$EVT
export STEM=ALL${VERSION}_${PLOT}
#export BFOLD=$BASE/G4CXTest/ALL0/$EVT ## comparison with "A" from another executable
#export BFOLD=$BASE/jok-tds/ALL0/A001 ## comparison with "A" from another executable
mkdir -p $LOGDIR
cd $LOGDIR
LOGFILE=$bin.log
case $VERSION in
0) opticks_event_mode=Minimal ;;
1) opticks_event_mode=Hit ;;
2) opticks_event_mode=HitPhoton ;;
3) opticks_event_mode=HitPhoton ;;
4) opticks_event_mode=HitPhotonSeq ;;
5) opticks_event_mode=HitSeq ;;
98) opticks_event_mode=DebugLite ;;
99) opticks_event_mode=DebugHeavy ;; # formerly StandardFullDebug
esac
#test=debug
#test=ref1
#test=ref5
#test=ref8
test=ref10
#test=input_genstep
#test=input_photon
TEST=${TEST:-$test}
if [ "$TEST" == "debug" ]; then
opticks_num_photon=100
opticks_max_photon=M1
opticks_num_event=1
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "ref1" ]; then
opticks_num_photon=M1
opticks_max_photon=M1
opticks_num_event=1
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "ref5" -o "$TEST" == "ref6" -o "$TEST" == "ref7" -o "$TEST" == "ref8" -o "$TEST" == "ref9" -o "$TEST" == "ref10" ]; then
opticks_num_photon=M${TEST:3}
opticks_max_photon=M10
opticks_num_event=1
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "refX" ]; then
opticks_num_photon=${X:-7500000}
opticks_max_photon=M10
opticks_num_event=1
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "tiny_scan" ]; then
opticks_num_photon=K1:10
opticks_max_photon=M1
opticks_num_event=10
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "large_scan" ]; then
opticks_num_photon=H1:10,M2,3,5,7,10,20,40,60,80,100
opticks_max_photon=M100 ## cost: QRng init time + VRAM
opticks_num_event=20
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "medium_scan" ]; then
opticks_num_photon=M1,1,10,20,30,40,50,60,70,80,90,100 # duplication of M1 is to workaround lack of metadata
opticks_max_photon=M100
opticks_num_event=12
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "larger_scan" ]; then
opticks_num_photon=M1,1,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200 # duplication of M1 is to workaround lack of metadata
opticks_max_photon=M200
opticks_num_event=22
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "large_evt" ]; then
opticks_num_photon=M200 ## OOM with TITAN RTX 24G
opticks_max_photon=M200 ## cost: QRng init time + VRAM
opticks_num_event=1
opticks_running_mode=SRM_TORCH
elif [ "$TEST" == "input_genstep" ]; then
opticks_num_photon= # ignored ?
opticks_max_photon=M1
opticks_num_event=1000
opticks_running_mode=SRM_INPUT_GENSTEP
opticks_event_mode=Nothing
elif [ "$TEST" == "input_photon" ]; then
opticks_num_photon= # ignored ?
opticks_max_photon=M1
opticks_num_event=1
opticks_running_mode=SRM_INPUT_PHOTON
#opticks_event_mode=Nothing
fi
#opticks_running_mode=SRM_DEFAULT
#opticks_running_mode=SRM_INPUT_PHOTON
#opticks_running_mode=SRM_GUN
opticks_start_index=0
opticks_max_bounce=31
opticks_integration_mode=1
export OPTICKS_EVENT_MODE=${OPTICKS_EVENT_MODE:-$opticks_event_mode}
export OPTICKS_NUM_PHOTON=${OPTICKS_NUM_PHOTON:-$opticks_num_photon}
export OPTICKS_NUM_EVENT=${OPTICKS_NUM_EVENT:-$opticks_num_event}
export OPTICKS_MAX_PHOTON=${OPTICKS_MAX_PHOTON:-$opticks_max_photon}
export OPTICKS_START_INDEX=${OPTICKS_START_INDEX:-$opticks_start_index}
export OPTICKS_MAX_BOUNCE=${OPTICKS_MAX_BOUNCE:-$opticks_max_bounce}
export OPTICKS_INTEGRATION_MODE=${OPTICKS_INTEGRATION_MODE:-$opticks_integration_mode}
export OPTICKS_RUNNING_MODE=${OPTICKS_RUNNING_MODE:-$opticks_running_mode}
if [ "$OPTICKS_RUNNING_MODE" == "SRM_INPUT_GENSTEP" ]; then
#igs=$BASE/jok-tds/ALL0/A000/genstep.npy
igs=$BASE/jok-tds/ALL0/A%0.3d/genstep.npy
if [ "${igs/\%}" != "$igs" ]; then
igs0=$(printf "$igs" 0)
else
igs0=$igs
fi
[ ! -f "$igs0" ] && echo $BASH_SOURCE : FATAL : NO SUCH PATH : igs0 $igs0 igs $igs && exit 1
export OPTICKS_INPUT_GENSTEP=$igs
elif [ "$OPTICKS_RUNNING_MODE" == "SRM_INPUT_PHOTON" ]; then
#ipho=RainXZ_Z195_1000_f8.npy ## ok
#ipho=RainXZ_Z230_1000_f8.npy ## ok
#ipho=RainXZ_Z230_10k_f8.npy ## ok
ipho=RainXZ_Z230_100k_f8.npy
#ipho=RainXZ_Z230_X700_10k_f8.npy ## X700 to illuminate multiple PMTs
#ipho=GridXY_X700_Z230_10k_f8.npy
#ipho=GridXY_X1000_Z1000_40k_f8.npy
#moi=-1
#moi=sWorld:0:0
#moi=NNVT:0:0
#moi=NNVT:0:50
moi=NNVT:0:1000
#moi=PMT_20inch_veto:0:1000
#moi=sChimneyAcrylic
# SEventConfig
export OPTICKS_INPUT_PHOTON=${OPTICKS_INPUT_PHOTON:-$ipho};
export OPTICKS_INPUT_PHOTON_FRAME=${MOI:-$moi}
elif [ "$OPTICKS_RUNNING_MODE" == "SRM_TORCH" ]; then
#export SEvent_MakeGenstep_num_ph=100000 NOT USED WHEN USING OPTICKS_NUM_PHOTON
#src="rectangle"
#src="disc"
src="sphere"
if [ "$src" == "rectangle" ]; then
export storch_FillGenstep_pos=0,0,0
export storch_FillGenstep_type=rectangle
export storch_FillGenstep_zenith=-20,20
export storch_FillGenstep_azimuth=-20,20
elif [ "$src" == "disc" ]; then
export storch_FillGenstep_type=disc
export storch_FillGenstep_radius=50
export storch_FillGenstep_zenith=0,1 # radial range scale
export storch_FillGenstep_azimuth=0,1 # phi segment twopi fraction
export storch_FillGenstep_mom=1,0,0
export storch_FillGenstep_pos=-80,0,0
elif [ "$src" == "sphere" ]; then
export storch_FillGenstep_type=sphere
export storch_FillGenstep_radius=100 # +ve for outwards
export storch_FillGenstep_pos=0,0,0
export storch_FillGenstep_distance=1.00 # frac_twopi control of polarization phase(tangent direction)
fi
elif [ "$OPTICKS_RUNNING_MODE" == "SRM_GUN" ]; then
echo -n
fi
gdb__()
{
: prepares and invokes gdb - sets up breakpoints based on BP envvar containing space delimited symbols;
if [ -z "$BP" ]; then
H="";
B="";
T="-ex r";
else
H="-ex \"set breakpoint pending on\"";
B="";
for bp in $BP;
do
B="$B -ex \"break $bp\" ";
done;
T="-ex \"info break\" -ex r";
fi;
local runline="gdb $H $B $T --args $* ";
echo $runline;
date;
eval $runline;
date
}
logging(){
export CSGFoundry=INFO
export CSGOptiX=INFO
export QEvent=INFO
export QSim=INFO
export SEvt__LIFECYCLE=1
}
[ -n "$LOG" ] && logging
[ -n "$LIFECYCLE" ] && export SEvt__LIFECYCLE=1
[ -n "$MEMCHECK" ] && export QU__MEMCHECK=1
#export SEvt__transformInputPhoton_VERBOSE=1
#export CSGFoundry__getFrameE_VERBOSE=1
#export CSGFoundry__getFrame_VERBOSE=1
export QRng__init_VERBOSE=1
vars="GEOM BASE TEST LOGDIR BINBASE CVD CUDA_VISIBLE_DEVICES SDIR FOLD LOG NEVT opticks_num_photon OPTICKS_NUM_PHOTON"
if [ "${arg/info}" != "$arg" ]; then
for var in $vars ; do printf "%20s : %s \n" $var ${!var} ; done
fi
if [ "${arg/env}" != "$arg" ]; then
env | grep OPTICKS | perl -n -e 'm/(\S*)=(\S*)/ && printf("%50s : %s\n", $1, $2) ' -
fi
if [ "${arg/fold}" != "$arg" ]; then
echo $FOLD
fi
if [ "${arg/run}" != "$arg" -o "${arg/dbg}" != "$arg" ]; then
if [ -f "$LOGFILE" ]; then
echo $BASH_SOURCE : run : delete prior LOGFILE $LOGFILE
rm "$LOGFILE"
fi
if [ "${arg/run}" != "$arg" ]; then
date +"%Y-%m-%d %H:%M:%S.%3N %N : [$BASH_SOURCE "
$bin
[ $? -ne 0 ] && echo $BASH_SOURCE run error && exit 1
date +"%Y-%m-%d %H:%M:%S.%3N %N : ]$BASH_SOURCE "
elif [ "${arg/dbg}" != "$arg" ]; then
gdb__ $bin
[ $? -ne 0 ] && echo $BASH_SOURCE dbg error && exit 1
fi
fi
if [ "${arg/meta}" != "$arg" ]; then
if [ -f "run_meta.txt" -a -n "$OPTICKS_SCAN_INDEX" -a -d "$OPTICKS_SCAN_INDEX" ] ; then
cp run_meta.txt $OPTICKS_SCAN_INDEX/run_meta.txt
fi
[ $? -ne 0 ] && echo $BASH_SOURCE meta error && exit 1
fi
if [ "${arg/report}" != "$arg" ]; then
sreport
[ $? -ne 0 ] && echo $BASH_SOURCE sreport error && exit 1
fi
if [ "${arg/grab}" != "$arg" ]; then
source $OPTICKS_HOME/bin/rsync.sh $LOGDIR
fi
if [ "${arg/grep}" != "$arg" ]; then
source $OPTICKS_HOME/bin/rsync.sh ${LOGDIR}_sreport
fi
if [ "${arg/gevt}" != "$arg" ]; then
source $OPTICKS_HOME/bin/rsync.sh $LOGDIR/$EVT
fi
if [ "${arg/ana}" != "$arg" ]; then
${IPYTHON:-ipython} --pdb -i $script
fi
if [ "$arg" == "pvcap" -o "$arg" == "pvpub" -o "$arg" == "mpcap" -o "$arg" == "mppub" ]; then
export CAP_BASE=$AFOLD/figs
export CAP_REL=cxs_min
export CAP_STEM=$STEM
case $arg in
pvcap) source pvcap.sh cap ;;
mpcap) source mpcap.sh cap ;;
pvpub) source pvcap.sh env ;;
mppub) source mpcap.sh env ;;
esac
if [ "$arg" == "pvpub" -o "$arg" == "mppub" ]; then
source epub.sh
fi
fi