forked from sergey-tomin/manul
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulator.py
77 lines (64 loc) · 2.63 KB
/
simulator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Sergey Tomin, XFEL/DESY, 2017
"""
class Simulator:
def __init__(self):
pass
def intro_misal(self):
#lat = MagneticLattice(cell)
for elem in self.parent.lat.sequence:
if elem.id == 'CKX.23.I1':
elem.angle = 0.1*0.001
if elem.id == 'CKX.24.I1':
elem.angle = -0.2 * 0.001
#if elem.__class__ == Quadrupole:
# elem.dx = np.random.normal(0, 200e-6)
# elem.dx = np.random.normal(0, 200e-6)
self.parent.lat.update_transfer_maps()
def read_traj(self):
self.orbit = Orbit(self.parent.lat)
X0, Y0 = self.orbit.read_virtual_orbit(p_init=Particle(x=0.00, y=-0.00, px=0.000, E=self.parent.tws0.E))
def read_orbit_sim(self):
self.intro_misal()
self.read_traj()
self.online_calc = False
for elem in self.corrs:
elem.kick_mrad = elem.angle*1000.
#angle = elem.kick_mrad*1e-3
elem.angle = 0.
elem.angle_read = elem.kick_mrad*1e-3
elem.i_kick = elem.kick_mrad
#print(elem.id, elem.angle)
elem.ui.set_init_value(elem.kick_mrad)
elem.ui.set_value(elem.kick_mrad)
self.online_calc = True
self.parent.lat.update_transfer_maps()
for elem in self.bpms:
try:
x_mm, y_mm = elem.x*1000, elem.y*1000
print(elem.id, x_mm, y_mm)
elem.x = x_mm/1000.
elem.y = y_mm/1000.
elem.ui.set_value((x_mm, y_mm))
except:
print("deleted BPM", elem.id)
self.bpms.remove(elem)
self.update_plot()
def calc_misalignment_rm(self):
for elem in self.corrs:
print("angle = ", elem.angle)
#self.orbit = Orbit(self.parent.lat, empty=True)
self.misal_resp_mat = self.orbit.misalignment_rm(p_init=Particle(E=self.parent.tws0.E),
elem_types=[Quadrupole, Bend, SBend,RBend], remove_elem=[])
p = self.orbit.elem_correction(self.misal_resp_mat, elem_types=[Quadrupole, Bend, SBend, RBend], remove_elems=[])
p.E=self.parent.tws0.E
self.p_init = p
self.calc_orbit()
def create_orbit(self):
self.orbit = Orbit(self.parent.lat)
resp_m = self.orbit.misalignment_rm(p_init=Particle(E=self.parent.tws0.E),
elem_types=[Quadrupole, Bend, SBend,RBend], remove_elem=[])
self.orbit.elem_correction(resp_m, elem_types=[Quadrupole, Bend, SBend,RBend], remove_elems=[])
self.calc_orbit()
def func(self):
pass