19 \namespace xboa::tracking::_matrix_tracking
21 Should be imported directly from the xboa::tracking namespace
26 from xboa
import common
as Common
28 from _tracking_base
import TrackingBase
32 Class to mimic tracking using simple, user-supplied transfer matrices
33 Each transfer matrix M_i0 must be of type numpy.matrix, where M is defined
34 by u_i = M_i*(u_in-v_in) + v_i and u, v are matrices with shape (1, 6)
35 going like (x, px, y, py, t, energy)
37 def __init__(self, list_of_transfer_matrices, list_of_offsets, offset_in):
40 - list_of_transfer_matrices list of transfer matrices. Each element
41 should be a numpy matrix of shape (6,6)
42 - list_of_offsets list of offsets v_i. Each element should be a numpy
44 - offset_in offset v_in. Should be a numpy matrix of shape (1,6)
46 TrackingBase.__init__(self)
47 if len(list_of_offsets) != len(list_of_transfer_matrices):
49 "list_of_offsets must be same length as list_of_tranfer_matrices")
50 mat_type = type(numpy.matrix([0.]))
51 for offset
in list_of_offsets+[offset_in]:
52 if type(offset) != mat_type:
53 raise TypeError(
"Offset should be of type "+str(mat_type)+\
54 " not "+str(type(offset)))
55 if offset.shape != (1, 6):
56 raise TypeError(
"Offset should be of shape (1,6) not "+\
58 for tm
in list_of_transfer_matrices:
59 if type(tm) != mat_type:
60 raise TypeError(
"Matrix should be of type "+str(mat_type)+\
61 " not "+str(type(tm)))
62 if tm.shape != (6, 6):
63 raise TypeError(
"Matrix should be of shape (6,6) not "+\
65 self.
tm_list = list_of_transfer_matrices
71 Track a hit and return a list of output hits
72 - hit initial particle coordinates to be tracked
74 Return a list of hits, with the first hit being equal to the input hit
75 and subsequent hits given by u_i = M_i0 * u_0 with
76 u = (x, px, y, py, t, energy)
78 hit_list = [hit.deepcopy()]
79 for i, tm
in enumerate(self.
tm_list):
81 vec_in = numpy.matrix([hit[
'x'], hit[
'px'],
83 hit[
't'], hit[
'energy']])
85 vec_out = tm * vec_in.transpose() + offset_out.transpose()
86 hit_out = hit.deepcopy()
87 for i, key
in enumerate([
"x",
"px",
"y",
"py",
"t",
"energy"]):
88 hit_out[key] = float(vec_out[i])
89 hit_out.mass_shell_condition(
"pz")
90 hit_list.append(hit_out)
def track_one
Track a hit and return a list of output hits.
Class to mimic tracking using simple, user-supplied transfer matrices Each transfer matrix M_i0 must ...
Implemented within this module: