-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path006_lattice_imperfections.py
39 lines (34 loc) · 1.39 KB
/
006_lattice_imperfections.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
import xtrack as xt
from simulation_parameters import parameters as p
print('*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~**~*~*~**~*~*~**~*~*~*')
print('006_lattice_imperfections.py')
print('*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~**~*~*~**~*~*~**~*~*~*')
#########################################
# Load PSB line in xsuite
#########################################
line = xt.Line.from_json('psb/psb_line_thin.json') # to get the lengths of the injection bumpers
#########################################
# Correct vertical chromaticity
#########################################
if p['correct_chroma']:
print('Correcting chromaticity in %s plane.'%(p['chroma_plane']))
line.match(vary=[xt.Vary('kbr1xnoh0', step=1e-8)],
targets = [xt.Target('dq%s'%(p['chroma_plane']), 0.0, tol=1e-5)])
print('Chromaticity corrected.')
else:
print('Natural chromaticity.')
#########################################
# Add field errors
#########################################
if p['include_field_errors']:
print('Adding field errors.')
for key in p['field_errors']:
line.vars[key] = p['field_errors'][key]
print('Added %s = %s to the lattice.'%(key, p['field_errors'][key]))
else:
print('No field errors.')
#########################################
# Save line to .json
#########################################
line.to_json('psb/psb_line_thin.json')
print('Line saved to psb/psb_line_thin.json')