Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:47

0001 #!/usr/bin/env python
0002 """
0003 dxplt.py : pyvista 3d plotting G4 dx.npy photon step points within selections
0004 =============================================================================== 
0005 
0006 ::
0007 
0008    run dxplt.py 
0009 
0010 
0011 
0012 * https://docs.pyvista.org/examples/00-load/create-spline.html
0013 
0014 """
0015 import numpy as np
0016 from opticks.ana.ab import AB
0017 import pyvista as pv
0018 
0019 
0020 def lines_from_points(points):
0021     """
0022     See ~/env/python/pv/create-spline.py 
0023 
0024     https://docs.pyvista.org/examples/00-load/create-spline.html
0025 
0026     Given an array of points, make a line set
0027 
0028     array([[2, 0, 1],
0029            [2, 1, 2],
0030            [2, 2, 3],
0031            [2, 3, 4],
0032            [2, 4, 5],
0033            [2, 5, 6]])
0034 
0035     """
0036     poly = pv.PolyData()
0037     poly.points = points
0038     cells = np.full((len(points)-1, 3), 2, dtype=np.int_)
0039     cells[:, 1] = np.arange(0, len(points)-1, dtype=np.int_)
0040     cells[:, 2] = np.arange(1, len(points), dtype=np.int_)
0041     poly.lines = cells
0042     return poly
0043 
0044 
0045 
0046 if __name__ == '__main__':
0047     from opticks.ana.main import opticks_main
0048 
0049     #pfx = "tds3ip"
0050     pfx = "tds3gun"
0051 
0052     ok = opticks_main(pfx=pfx, src="natural")
0053     ab = AB(ok)  
0054     a = ab.a    # dx only filled for G4:b 
0055     b = ab.b 
0056 
0057     #a_sel = "TO SC BT SR BT SA"     # 0x8cac6d
0058     #b_sel = "TO SC BT SR BT BT SA"  # 0x8ccac6d
0059 
0060     #sel = "TO SC BT BT AB"   # scatters that get back into the LS from the Water
0061 
0062     sel = "SI BT BT BT BT SD"
0063 
0064     n = len(sel.split())   
0065 
0066     a.sel = sel 
0067     b.sel = sel
0068 
0069     pos = b.dx[:,:n,0,:3]      ## deluxe double buffer is G4 only 
0070     #pos = b.rpost()[:,:,:3]    ## rpost from rx buffer has same info with domain compression   
0071     #pos = a.rpost()[:,:,:3]      
0072 
0073     pl = pv.Plotter()
0074 
0075     for i in range(len(pos)):
0076         line = lines_from_points(pos[i])
0077         line["scalars"] = np.arange(line.n_points)
0078         tube = line.tube(radius=3)
0079         pl.add_mesh(tube)
0080     pass
0081     pl.show()
0082