File indexing completed on 2026-04-10 07:50:28
0001
0002 """
0003 U4SimulateTest_pr.py
0004 ========================
0005
0006 ::
0007
0008 u4t
0009 ./U4SimulateTest.sh pr
0010 ./U4SimulateTest.sh npr
0011
0012 """
0013 import os, numpy as np
0014 from opticks.ana.fold import Fold
0015 from opticks.ana.p import *
0016 from opticks.sysrap.sevt import SEvt
0017
0018
0019 SCRIPT = "./U4SimulateTest.sh pr"
0020 os.environ["SCRIPT"] = SCRIPT
0021 ENVOUT = os.environ.get("ENVOUT", None)
0022
0023
0024 N = int(os.environ.get("N", "-1"))
0025 MODE = int(os.environ.get("MODE", "2"))
0026 assert MODE in [0,2,-2,3,-3]
0027 FLIP = int(os.environ.get("FLIP", "0")) == 1
0028 TIGHT = int(os.environ.get("TIGHT", "0")) == 1
0029
0030 if MODE != 0:
0031
0032 from opticks.ana.pvplt import *
0033 WM = mp.pyplot.get_current_fig_manager()
0034 else:
0035 WM = None
0036 pass
0037
0038 if __name__ == '__main__':
0039
0040 if N == -1:
0041 a = SEvt.Load("$AFOLD",symbol="a")
0042 b = SEvt.Load("$BFOLD",symbol="b")
0043 syms = ['a','b']
0044 elif N == 0:
0045 a = SEvt.Load("$AFOLD",symbol="a")
0046 b = None
0047 syms = ['a']
0048 elif N == 1:
0049 a = None
0050 b = SEvt.Load("$BFOLD",symbol="b")
0051 syms = ['b']
0052 else:
0053 assert(0)
0054 pass
0055
0056 if not a is None:print(repr(a))
0057 if not b is None:print(repr(b))
0058
0059 print( "MODE:%d" % (MODE) )
0060
0061 if FLIP == False:
0062 H,V = 0, 2
0063 else:
0064 H,V = 2, 0
0065 pass
0066
0067 scale = 0.8 if TIGHT else 1.0
0068
0069 LIM = {
0070 0:np.array([-500,500])*scale,
0071 1:np.array([-500,500])*scale,
0072 2:np.array([-250,250])*scale
0073 }
0074
0075
0076
0077
0078 ppos0_ = "t.f.record[:,0,0,:3] # 0-position "
0079
0080
0081 ppos1_ = "t.f.record[:,1,0,:3] # 1-position "
0082
0083
0084 ppos2_ = "t.f.record[t.n>2,2,0,:3] # 2-position "
0085
0086
0087 ppos3_ = "t.f.photon[:,0,:3]"
0088
0089 tlabel_ = "t.TITLE"
0090 tid_ = "t.ID"
0091 version_ = "t.VERSION"
0092
0093
0094 elem = []
0095 if not ppos0_ is "None": elem.append("b:%s" % ppos0_)
0096 if not ppos1_ is "None": elem.append("r:%s" % ppos1_)
0097 if not ppos2_ is "None": elem.append("g:%s" % ppos2_)
0098 if not ppos3_ is "None": elem.append("c:%s" % ppos3_)
0099
0100 ppos0 = {}
0101 ppos1 = {}
0102 ppos2 = {}
0103 ppos3 = {}
0104 tlabel = {}
0105 tid = {}
0106 version = {}
0107
0108 for i,sym in enumerate(syms):
0109 t = eval(sym)
0110 ppos0[sym] = eval(ppos0_)
0111 ppos1[sym] = eval(ppos1_)
0112 ppos2[sym] = eval(ppos2_)
0113 ppos3[sym] = eval(ppos3_)
0114 tlabel[sym] = eval(tlabel_)
0115 tid[sym] = eval(tid_)
0116 version[sym] = eval(version_)
0117 pass
0118
0119 if MODE == 0:
0120 print("not plotting as MODE 0 in environ")
0121 elif MODE == 2:
0122 for sym in syms:
0123 if TIGHT:
0124 label = tlabel[sym]
0125 else:
0126 label = "\n".join([tlabel[sym]] + elem)
0127 pass
0128 fig, axs = mpplt_plotter(nrows=1, ncols=1, label=label)
0129 ax = axs[0]
0130 ax.set_ylim(*LIM[V])
0131 ax.set_xlim(*LIM[H])
0132 if TIGHT:ax.axis('off')
0133
0134 if not ppos0[sym] is None: ax.scatter( ppos0[sym][:,H], ppos0[sym][:,V], s=1, c="b" )
0135 if not ppos1[sym] is None: ax.scatter( ppos1[sym][:,H], ppos1[sym][:,V], s=1, c="r" )
0136 if not ppos2[sym] is None: ax.scatter( ppos2[sym][:,H], ppos2[sym][:,V], s=1, c="g" )
0137 if not ppos3[sym] is None: ax.scatter( ppos3[sym][:,H], ppos3[sym][:,V], s=1, c="c" )
0138 pass
0139 if TIGHT:fig.tight_layout()
0140
0141 if not ENVOUT is None:
0142 envout = "\n".join([
0143 "export ENVOUT_PATH=%s" % ENVOUT,
0144 "export ENVOUT_SYM=%s" % sym,
0145 "export ENVOUT_TID=%s" % tid[sym],
0146 "export ENVOUT_CAP_STEM=%s" % tid[sym],
0147 "export ENVOUT_VERSION=%s" % version[sym],
0148 ""
0149 ])
0150 open(ENVOUT, "w").write(envout)
0151 print(envout)
0152 pass
0153 fig.show()
0154 pass
0155
0156 if len(syms) > 1:
0157 print("WARNING : MULTIPLE FIGS SHOWN : PROBABLY WINDOWS ARE OVERLAPPED")
0158 pass
0159
0160
0161
0162 elif MODE == -2:
0163
0164
0165 fig, axs = mpplt_plotter(nrows=1, ncols=2, label=label)
0166 for i,ax in enumerate(axs):
0167 sym = syms[i]
0168
0169 ax.set_ylim(*LIM[V])
0170 ax.set_xlim(*LIM[H])
0171 if TIGHT:ax.axis('off')
0172
0173 if not ppos0[sym] is None: ax.scatter( ppos0[sym][:,H], ppos0[sym][:,V], s=1, c="b" )
0174 if not ppos1[sym] is None: ax.scatter( ppos1[sym][:,H], ppos1[sym][:,V], s=1, c="r" )
0175 if not ppos2[sym] is None: ax.scatter( ppos2[sym][:,H], ppos2[sym][:,V], s=1, c="g" )
0176 if not ppos3[sym] is None: ax.scatter( ppos3[sym][:,H], ppos3[sym][:,V], s=1, c="c" )
0177 pass
0178 if TIGHT:fig.tight_layout()
0179 fig.show()
0180 elif MODE == 3:
0181 pl = pvplt_plotter(label)
0182 os.environ["EYE"] = "0,100,165"
0183 os.environ["LOOK"] = "0,0,165"
0184 pvplt_viewpoint(pl)
0185 pl.add_points(ppos )
0186 pl.show()
0187 pass
0188 pass