File indexing completed on 2026-04-09 07:49:03
0001
0002 """
0003 G4CXSimtraceMinTest.py : simtrace plot backdrop with APID, BPID onephotonplot on top
0004 =======================================================================================
0005
0006 This is now run by G4CXAppTest.sh with eg::
0007
0008 APID=62 MODE=2 ~/opticks/g4cx/tests/G4CXAppTest.sh tra
0009
0010 This aims to do similar to G4CXSimtraceTest.py but in a more minimal way,
0011 drawing on developments from cx/cxs_min.py
0012
0013 """
0014
0015 import os, logging, numpy as np
0016 from opticks.sysrap.sevt import SEvt, SAB
0017 log = logging.getLogger(__name__)
0018
0019 GLOBAL = int(os.environ.get("GLOBAL","0")) == 1
0020 MODE = int(os.environ.get("MODE","3"))
0021 SEL = int(os.environ.get("SEL","0"))
0022
0023
0024 if MODE in [2,3]:
0025 from opticks.ana.pvplt import *
0026
0027 pass
0028
0029
0030 def onephotonplot(pl, e):
0031 if e is None: return
0032 if e.pid < 0: return
0033
0034 if not hasattr(e,'r'): return
0035 if e.r is None: return
0036
0037 r = e.r
0038 off = e.off
0039
0040 rpos = r[:,0,:3] + off
0041
0042 if MODE == 2:
0043 fig, axs = pl
0044 assert len(axs) == 1
0045 ax = axs[0]
0046 if True:
0047 mpplt_add_contiguous_line_segments(ax, rpos, axes=(H,V), label=None )
0048
0049 pass
0050
0051
0052
0053 elif MODE == 3:
0054 pass
0055 pvplt_add_contiguous_line_segments(pl, rpos )
0056 pass
0057
0058
0059
0060
0061 if __name__ == '__main__':
0062 logging.basicConfig(level=logging.INFO)
0063 a = SEvt.Load("$AFOLD", symbol="a")
0064 b = SEvt.Load("$BFOLD", symbol="b")
0065 t = SEvt.Load("$TFOLD", symbol="t")
0066
0067 print(repr(a))
0068 print(repr(b))
0069 print(repr(t))
0070
0071 ab = SAB(a,b)
0072 print(repr(ab))
0073
0074
0075
0076 e = t
0077
0078 label = "APID=%s BPID=%d G4CXSimtraceMinTest.sh # A:%s B:%s " % (a.pid, b.pid, a.label, b.label )
0079
0080 if MODE in [0,1]:
0081 print("not plotting as MODE %d in environ" % MODE )
0082 elif MODE == 2:
0083 pl = mpplt_plotter(label=label)
0084 fig, axs = pl
0085 assert len(axs) == 1
0086 ax = axs[0]
0087
0088 ax.set_xlim(-356,356)
0089 ax.set_ylim(-201,201)
0090
0091 elif MODE == 3:
0092 pl = pvplt_plotter(label)
0093 pvplt_viewpoint(pl)
0094 pvplt_frame(pl, e.f.sframe, local=not GLOBAL )
0095 pass
0096
0097 pp = e.f.simtrace[:,1,:3]
0098
0099 gpos = np.ones( [len(pp), 4 ] )
0100 gpos[:,:3] = pp
0101 lpos = np.dot( gpos, e.f.sframe.w2m )
0102 upos = gpos if GLOBAL else lpos
0103
0104
0105 H,V = 0,2
0106
0107 if SEL == 1:
0108 sel = np.logical_and( np.abs(upos[:,H]) < 500, np.abs(upos[:,V]) < 500 )
0109 spos = upos[sel]
0110 else:
0111 spos = upos
0112 pass
0113
0114
0115 if MODE == 2:
0116 ax.scatter( spos[:,H], spos[:,V], s=0.1 )
0117 elif MODE == 3:
0118 pl.add_points(spos[:,:3])
0119 pass
0120
0121
0122 if not a is None and a.pid > -1:
0123 onephotonplot(pl, a)
0124 pass
0125 if not b is None and b.pid > -1:
0126 onephotonplot(pl, b)
0127 pass
0128
0129
0130 if MODE == 2:
0131 fig.show()
0132 elif MODE == 3:
0133 pl.show()
0134 pass
0135 pass
0136