File indexing completed on 2026-04-10 07:49:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 """
0022 genstep_merge.py : combine Cerenkov and scintillation gensteps in natural ones
0023 ================================================================================
0024
0025 NumPy level merging of gensteps with slicing of inputs.
0026 Slicing is done as scintillation is already a bit heavy for mobile GPU.
0027
0028 Note the input gensteps are read from paths within the
0029 installed opticksdata (canonically within /usr/local/opticks/opticksdata/gensteps/)
0030 whereas the output gensteps are in the "input" opticksdata clone
0031 in ~/opticksdata/gensteps.
0032
0033 Used for testing the "natural" genstep event type prior to
0034 implementing actual Geant4 level natural genstep collection.
0035
0036 ::
0037
0038 ./genstep_merge.py
0039 [2016-08-23 17:57:05,323] p77451 {./genstep_merge.py:63} INFO - loaded a : (7836, 6, 4) /usr/local/opticks/opticksdata/gensteps/dayabay/cerenkov/1.npy
0040 [2016-08-23 17:57:05,323] p77451 {./genstep_merge.py:64} INFO - loaded b : (13898, 6, 4) /usr/local/opticks/opticksdata/gensteps/dayabay/scintillation/1.npy
0041 [2016-08-23 17:57:05,323] p77451 {./genstep_merge.py:70} INFO - sliced aa : (2612, 6, 4)
0042 [2016-08-23 17:57:05,323] p77451 {./genstep_merge.py:71} INFO - sliced bb : (4633, 6, 4)
0043 [2016-08-23 17:57:05,325] p77451 {./genstep_merge.py:82} INFO - merged (7245, 6, 4) /Users/blyth/opticksdata/gensteps/dayabay/natural/1.npy exists already skipping
0044
0045 """
0046 import os, logging
0047 import numpy as np
0048
0049 from opticks.ana.base import opticks_main
0050 from opticks.ana.nload import A, gspath_
0051
0052 log = logging.getLogger(__name__)
0053
0054 if __name__ == '__main__':
0055
0056 args = opticks_main(det="dayabay", src="cerenkov,scintillation", tag="1", sli="::3")
0057
0058 srcs = args.src.split(",")
0059 assert len(srcs) == 2
0060
0061
0062 sli = args.sli
0063
0064 try:
0065 a = A.load_("gensteps",srcs[0],args.tag,args.det)
0066 b = A.load_("gensteps",srcs[1],args.tag,args.det)
0067 except IOError as err:
0068 log.fatal(err)
0069 sys.exit(args.mrc)
0070
0071
0072 log.info("loaded a : %s %s " % (repr(a.shape),a.path))
0073 log.info("loaded b : %s %s " % (repr(b.shape),b.path))
0074
0075 aa = a[sli]
0076 bb = b[sli]
0077 assert aa.shape[1:] == (6,4) and bb.shape[1:] == (6,4)
0078
0079 log.info("sliced aa : %s " % (repr(aa.shape)))
0080 log.info("sliced bb : %s " % (repr(bb.shape)))
0081
0082
0083 cc = np.empty((len(aa)+len(bb),6,4), dtype=np.float32)
0084 cc[0:len(aa)] = aa
0085 cc[len(aa):len(aa)+len(bb)] = bb
0086
0087 gsp = gspath_("natural", args.tag, args.det, gsbase=os.path.expanduser("~/opticksdata/gensteps"))
0088 gsd = os.path.dirname(gsp)
0089
0090 if os.path.exists(gsp):
0091 log.info("merged %s %s exists already skipping " % (repr(cc.shape),gsp))
0092 else:
0093 if not os.path.isdir(gsd):
0094 log.info("creating directory gsd %s " % gsd )
0095 os.makedirs(gsd)
0096 pass
0097 log.info("saving merged gensteps to %s " % gsp )
0098 np.save(gsp, cc )
0099
0100
0101
0102