File indexing completed on 2026-04-09 07:49:03
0001
0002 """
0003 cf_G4CXSimtraceTest.py
0004 ==============================
0005
0006 ::
0007
0008 FOCUS=-257,-39,7 ./cf_gxt.sh
0009
0010
0011 """
0012
0013 import os, numpy as np, logging
0014 log = logging.getLogger(__name__)
0015 from opticks.ana.fold import Fold
0016 from opticks.CSG.Values import Values
0017 from opticks.ana.eget import efloatarray_, efloatlist_
0018 from opticks.sysrap.sframe import sframe , X, Y, Z
0019 from opticks.ana.framegensteps import FrameGensteps
0020 from opticks.ana.pvplt import mpplt_focus
0021
0022 import matplotlib.pyplot as mp
0023
0024 SIZE = np.array([1280, 720])
0025 FOCUS = efloatarray_("FOCUS", "0,0,0")
0026
0027
0028 if __name__ == '__main__':
0029 logging.basicConfig(level=logging.INFO)
0030
0031 s_geom = os.environ.get("S_GEOM", None)
0032 t_geom = os.environ.get("T_GEOM", None)
0033 u_geom = os.environ.get("U_GEOM", None)
0034 v_geom = os.environ.get("V_GEOM", None)
0035
0036 s = Fold.Load("$S_FOLD", symbol="s") if not s_geom is None else None
0037 t = Fold.Load("$T_FOLD", symbol="t") if not t_geom is None else None
0038 u = Fold.Load("$U_FOLD", symbol="u") if not u_geom is None else None
0039 v = Fold.Load("$V_FOLD", symbol="v") if not v_geom is None else None
0040
0041 print(repr(s))
0042 print(repr(t))
0043 print(repr(u))
0044 print(repr(v))
0045
0046 sv = Values.Find("$S_FOLD", symbol="sv") if not s_geom is None else None
0047 tv = Values.Find("$T_FOLD", symbol="tv") if not t_geom is None else None
0048 uv = Values.Find("$U_FOLD", symbol="uv") if not u_geom is None else None
0049 vv = Values.Find("$V_FOLD", symbol="vv") if not v_geom is None else None
0050
0051 print(repr(sv))
0052 print(repr(tv))
0053 print(repr(uv))
0054 print(repr(vv))
0055
0056 local = True
0057 s_gs = FrameGensteps(s.genstep, s.sframe, local=local, symbol="s_gs" ) if not s is None else None
0058 t_gs = FrameGensteps(t.genstep, t.sframe, local=local, symbol="t_gs" ) if not t is None else None
0059 u_gs = FrameGensteps(u.genstep, u.sframe, local=local, symbol="u_gs" ) if not u is None else None
0060 v_gs = FrameGensteps(v.genstep, v.sframe, local=local, symbol="v_gs" ) if not v is None else None
0061
0062 lim = FrameGensteps.CombineLim( [s_gs, t_gs, u_gs, v_gs] )
0063
0064 s_frame = s.sframe if not s is None else None
0065 t_frame = t.sframe if not t is None else None
0066 u_frame = u.sframe if not u is None else None
0067 v_frame = v.sframe if not v is None else None
0068
0069 frame = sframe.CombineFrame( [s_frame, t_frame, u_frame, v_frame ] )
0070
0071 s_offset = efloatarray_("S_OFFSET", "0,0,0")
0072 t_offset = efloatarray_("T_OFFSET", "0,0,0")
0073 u_offset = efloatarray_("U_OFFSET", "0,0,0")
0074 v_offset = efloatarray_("V_OFFSET", "0,0,0")
0075
0076 print("S_OFFSET: %s " % repr(s_offset))
0077 print("T_OFFSET: %s " % repr(t_offset))
0078 print("U_OFFSET: %s " % repr(u_offset))
0079 print("V_OFFSET: %s " % repr(v_offset))
0080
0081
0082 s_hit = s.simtrace[:,0,3]>0 if not s is None else None
0083 t_hit = t.simtrace[:,0,3]>0 if not t is None else None
0084 u_hit = u.simtrace[:,0,3]>0 if not u is None else None
0085 v_hit = v.simtrace[:,0,3]>0 if not v is None else None
0086
0087 s_pos = s_offset + s.simtrace[s_hit][:,1,:3] if not s is None else None
0088 t_pos = t_offset + t.simtrace[t_hit][:,1,:3] if not t is None else None
0089 u_pos = u_offset + u.simtrace[u_hit][:,1,:3] if not u is None else None
0090 v_pos = v_offset + v.simtrace[v_hit][:,1,:3] if not v is None else None
0091
0092 topline = os.environ.get("TOPLINE", "cf_G4CXSimtraceTest.py")
0093 botline = os.environ.get("BOTLINE", "S_OFFSET:%s T_OFFSET:%s U_OFFSET:%s V_OFFSET:%s " % (str(s_offset),str(t_offset), str(u_offset), str(v_offset)))
0094 thirdline = os.environ.get("THIRDLINE", "FOCUS:%s " % (str(FOCUS)))
0095 title = [topline, botline, thirdline ]
0096
0097 fig, ax = mp.subplots(figsize=SIZE/100.)
0098 fig.suptitle("\n".join(title))
0099 ax.set_aspect('equal')
0100
0101 if not frame is None and not lim is None:
0102 H,V = frame.axes
0103 _H,_V = frame.axlabels
0104
0105 xlim = lim[H]
0106 ylim = lim[V]
0107 xlim, ylim = mpplt_focus(xlim, ylim)
0108
0109 ax.set_xlim(xlim)
0110 ax.set_ylim(ylim)
0111 ax.set_xlabel(_H)
0112 ax.set_ylabel(_V)
0113 pass
0114
0115 if not s_pos is None:
0116 ax.scatter( s_pos[:,0], s_pos[:,2], label="S:%s" % s_geom, s=1 )
0117 pass
0118 if not t_pos is None:
0119 ax.scatter( t_pos[:,0], t_pos[:,2], label="T:%s" % t_geom, s=1 )
0120 pass
0121 if not u_pos is None:
0122 ax.scatter( u_pos[:,0], u_pos[:,2], label="U:%s" % u_geom, s=1 )
0123 pass
0124 if not v_pos is None:
0125 ax.scatter( v_pos[:,0], v_pos[:,2], label="V:%s" % v_geom, s=1 )
0126 pass
0127
0128
0129 ax.legend()
0130 fig.show()
0131