2 from argparse
import ArgumentParser
as ap
4 from scipy.spatial
import Delaunay
5 import matplotlib.pyplot
as plt
8 parser.add_argument(
"-i", type=str, help=
'Input')
9 parser.add_argument(
"-o", type=str, help=
'Output string')
10 args = parser.parse_args()
14 for i
in range(1, hx.GetNbinsX()+1):
15 x = hx.GetXaxis().GetBinCenter(i)
16 for j
in range(1, hx.GetNbinsY()+1):
17 y = hx.GetYaxis().GetBinCenter(j)
18 for k
in range(1, hx.GetNbinsZ()+1):
19 z = hx.GetZaxis().GetBinCenter(k)
21 [x + hx.GetBinContent(i, j, k),
22 y + hy.GetBinContent(i, j, k),
23 z + hz.GetBinContent(i, j, k)])
28 for i
in range(1, h.GetNbinsX()+1):
29 x = h.GetXaxis().GetBinCenter(i)
30 for j
in range(1, h.GetNbinsY()+1):
31 y = h.GetYaxis().GetBinCenter(j)
32 for k
in range(1, h.GetNbinsZ()+1):
33 z = h.GetZaxis().GetBinCenter(k)
34 results.append([x, y, z])
39 for i
in range(1, hx.GetNbinsX()+1):
40 x = hx.GetXaxis().GetBinCenter(i)
41 for j
in range(1, hx.GetNbinsY()+1):
42 y = hx.GetYaxis().GetBinCenter(j)
43 for k
in range(1, hx.GetNbinsZ()+1):
44 z = hx.GetZaxis().GetBinCenter(k)
45 hx.SetBinContent(i, j, k, pts[a][0] - x)
46 hy.SetBinContent(i, j, k, pts[a][1] - y)
47 hz.SetBinContent(i, j, k, pts[a][2] - z)
52 i = tri_in.find_simplex(pt)
53 s = tri_in.simplices[i]
54 r = tri_in.transform[i,3]
55 b = tri_in.transform[i,:3].
dot(np.transpose(pt - r))
56 b = np.append(b, 1. - b.sum())
61 for j, bi
in zip(s,b):
62 new_point_x += grid_pts[j][0]*bi
63 new_point_y += grid_pts[j][1]*bi
64 new_point_z += grid_pts[j][2]*bi
66 results.append([new_point_x, new_point_y, new_point_z])
70 fIn = RT.TFile(args.i,
"OPEN")
71 bkwd_z_pos = fIn.Get(
"RecoBkwd_Displacement_Z_Pos")
72 bkwd_z_neg = fIn.Get(
"RecoBkwd_Displacement_Z_Neg")
73 bkwd_x_pos = fIn.Get(
"RecoBkwd_Displacement_X_Pos")
74 bkwd_x_neg = fIn.Get(
"RecoBkwd_Displacement_X_Neg")
75 bkwd_y_pos = fIn.Get(
"RecoBkwd_Displacement_Y_Pos")
76 bkwd_y_neg = fIn.Get(
"RecoBkwd_Displacement_Y_Neg")
78 fwd_z_pos = bkwd_z_pos.Clone(
"RecoFwd_Displacement_Z_Pos")
79 fwd_z_neg = bkwd_z_neg.Clone(
"RecoFwd_Displacement_Z_Neg")
80 fwd_x_pos = bkwd_x_pos.Clone(
"RecoFwd_Displacement_X_Pos")
81 fwd_x_neg = bkwd_x_neg.Clone(
"RecoFwd_Displacement_X_Neg")
82 fwd_y_pos = bkwd_y_pos.Clone(
"RecoFwd_Displacement_Y_Pos")
83 fwd_y_neg = bkwd_y_neg.Clone(
"RecoFwd_Displacement_Y_Neg")
91 bkwd_pos_corrected_array = np.array(bkwd_pos_corrected)
92 bkwd_neg_corrected_array = np.array(bkwd_neg_corrected)
94 tri_pos_corr = Delaunay(bkwd_pos_corrected_array)
95 tri_neg_corr = Delaunay(bkwd_neg_corrected_array)
103 fOut = RT.TFile(args.o,
"RECREATE")
111 bkwd_x_pos.Write(
"RecoBkwd_Displacement_X_Pos")
112 bkwd_y_pos.Write(
"RecoBkwd_Displacement_Y_Neg")
113 bkwd_z_pos.Write(
"RecoBkwd_Displacement_Z_Pos")
114 bkwd_x_neg.Write(
"RecoBkwd_Displacement_X_Neg")
115 bkwd_y_neg.Write(
"RecoBkwd_Displacement_Y_Pos")
116 bkwd_z_neg.Write(
"RecoBkwd_Displacement_Z_Neg")
118 ex_pos = fIn.Get(
"Reco_ElecField_X_Pos")
119 ey_pos = fIn.Get(
"Reco_ElecField_Y_Pos")
120 ez_pos = fIn.Get(
"Reco_ElecField_Z_Pos")
121 ex_neg = fIn.Get(
"Reco_ElecField_X_Neg")
122 ey_neg = fIn.Get(
"Reco_ElecField_Y_Neg")
123 ez_neg = fIn.Get(
"Reco_ElecField_Z_Neg")
138 points = np.array([[0, 0], [0, 1.0], [1, 0], [1.0, 1.0]]) 139 corr_points = np.array([[.15, .15], [.2, 1.3], [1.3, .3], [1.3, 1.4]]) 141 tri = Delaunay(points) 142 tri_corr = Delaunay(corr_points) 143 plt.triplot(points[:,0], points[:,1], tri_corr.simplices) 144 plt.plot(points[:,0], points[:,1], 'o') 147 #plt.triplot(corr_points[:,0], corr_points[:,1], tri_disp.simplices) 148 plt.triplot(corr_points[:,0], corr_points[:,1], tri_corr.simplices) 149 plt.plot(corr_points[:,0], corr_points[:,1], 'o') 152 #for i in range(0, 12): 153 # for j in range(0, 12): 154 # true_pts.append([i*.1, j*.1]) 155 #true_grid = np.array(true_pts) 156 true_grid = np.array([[.25, .5], [.75, .5]]) 157 plt.plot(true_grid[:,0], true_grid[:,1], 'o') 160 print(tri_corr.simplices) 165 i = tri_corr.find_simplex(pt) 167 s = tri_corr.simplices[i] 170 r = tri_corr.transform[i,2] 171 b = tri_corr.transform[i,:2].dot(np.transpose(pt - r)) 172 b = np.append(b, 1. - b.sum()) 177 for j, bi in zip(s,b): 178 new_point_x += points[j][0]*bi 179 new_point_y += points[j][1]*bi 180 print([new_point_x, new_point_y]) 181 distorted_grid.append([new_point_x, new_point_y]) 183 distorted_array = np.array(distorted_grid) 185 deltas = [ [d[0] - t[0], d[1] - t[1]] for d, t in zip(distorted_grid, true_grid)] 186 #plt.plot(distorted_array[:,0], distorted_array[:,1], 'o') 187 delta_array = np.array(deltas) 188 for pt, d in zip(true_grid, deltas): 189 plt.arrow(pt[0], pt[1], d[0], d[1], head_width=.01)
def set_distortions(hx, hy, hz, pts)
def get_corr_points(hx, hy, hz)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
def get_distorted_pts(grid_pts, tri_in)