11import numpy as np
2+
23import xmask .lhc as xmlhc
4+ import xobjects as xo
5+
36
47def check_optics_orbit_etc (collider , line_names , sep_h_ip2 , sep_v_ip8 ):
58
69 for line_name in line_names :
710
811 assert collider [line_name ].particle_ref .q0 == 1
9- assert np . isclose (collider [line_name ].particle_ref .p0c , 7e12 ,
12+ xo . assert_allclose (collider [line_name ].particle_ref .p0c , 7e12 ,
1013 atol = 0 , rtol = 1e-5 )
11- assert np . isclose (collider [line_name ].particle_ref .mass0 , 0.9382720813e9 ,
14+ xo . assert_allclose (collider [line_name ].particle_ref .mass0 , 0.9382720813e9 ,
1215 atol = 0 , rtol = 1e-5 )
1316
1417 tw = collider [line_name ].twiss ()
1518
1619 if line_name == 'lhcb1' :
17- assert np . isclose (tw .qx , 62.31 , atol = 1e-4 , rtol = 0 )
18- assert np . isclose (tw .qy , 60.32 , atol = 1e-4 , rtol = 0 )
19- assert np . isclose (tw .dqx , 5 , atol = 0.1 , rtol = 0 )
20- assert np . isclose (tw .dqy , 7 , atol = 0.1 , rtol = 0 )
20+ xo . assert_allclose (tw .qx , 62.31 , atol = 1e-4 , rtol = 0 )
21+ xo . assert_allclose (tw .qy , 60.32 , atol = 1e-4 , rtol = 0 )
22+ xo . assert_allclose (tw .dqx , 5 , atol = 0.1 , rtol = 0 )
23+ xo . assert_allclose (tw .dqy , 7 , atol = 0.1 , rtol = 0 )
2124 elif line_name == 'lhcb2' :
22- assert np . isclose (tw .qx , 62.315 , atol = 1e-4 , rtol = 0 )
23- assert np . isclose (tw .qy , 60.325 , atol = 1e-4 , rtol = 0 )
24- assert np . isclose (tw .dqx , 6 , atol = 0.1 , rtol = 0 )
25- assert np . isclose (tw .dqy , 8 , atol = 0.1 , rtol = 0 )
25+ xo . assert_allclose (tw .qx , 62.315 , atol = 1e-4 , rtol = 0 )
26+ xo . assert_allclose (tw .qy , 60.325 , atol = 1e-4 , rtol = 0 )
27+ xo . assert_allclose (tw .dqx , 6 , atol = 0.1 , rtol = 0 )
28+ xo . assert_allclose (tw .dqy , 8 , atol = 0.1 , rtol = 0 )
2629 else :
2730 raise ValueError (f'Unknown line name { line_name } ' )
2831
29- assert np . isclose (tw .qs , 0.00212 , atol = 1e-4 , rtol = 0 ) # Checks that RF is well set
32+ xo . assert_allclose (tw .qs , 0.00212 , atol = 1e-4 , rtol = 0 ) # Checks that RF is well set
3033
31- assert np . isclose (tw .c_minus , 0 , atol = 1e-4 , rtol = 0 )
34+ xo . assert_allclose (tw .c_minus , 0 , atol = 1e-4 , rtol = 0 )
3235 assert np .allclose (tw .zeta , 0 , rtol = 0 , atol = 1e-4 ) # Check RF phase
3336
3437 # Check separations
35- assert np . isclose (tw ['x' , 'ip1' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
36- assert np . isclose (tw ['y' , 'ip1' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
37- assert np . isclose (tw ['x' , 'ip5' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
38- assert np . isclose (tw ['y' , 'ip5' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
38+ xo . assert_allclose (tw ['x' , 'ip1' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
39+ xo . assert_allclose (tw ['y' , 'ip1' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
40+ xo . assert_allclose (tw ['x' , 'ip5' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
41+ xo . assert_allclose (tw ['y' , 'ip5' ], 0 , rtol = 0 , atol = 5e-8 ) # sigma is 4e-6
3942
4043 if sep_h_ip2 is not None :
41- assert np . isclose (tw ['x' , 'ip2' ],
44+ xo . assert_allclose (tw ['x' , 'ip2' ],
4245 #-0.138e-3 * {'lhcb1': 1, 'lhcb2': 1}[line_name], # set separation
4346 sep_h_ip2 * {'lhcb1' : 1 , 'lhcb2' : 1 }[line_name ],
4447 rtol = 0 , atol = 4e-6 )
45- assert np . isclose (tw ['y' , 'ip2' ], 0 , rtol = 0 , atol = 5e-8 )
48+ xo . assert_allclose (tw ['y' , 'ip2' ], 0 , rtol = 0 , atol = 5e-8 )
4649
47- assert np . isclose (tw ['x' , 'ip8' ], 0 , rtol = 0 , atol = 5e-8 )
50+ xo . assert_allclose (tw ['x' , 'ip8' ], 0 , rtol = 0 , atol = 5e-8 )
4851 if sep_v_ip8 is not None :
49- assert np . isclose (tw ['y' , 'ip8' ],
52+ xo . assert_allclose (tw ['y' , 'ip8' ],
5053 #-0.043e-3 * {'lhcb1': 1, 'lhcb2': -1}[line_name], # set separation
5154 sep_v_ip8 * {'lhcb1' : 1 , 'lhcb2' : - 1 }[line_name ],
5255 rtol = 0 , atol = 5e-8 )
5356
5457 # Check crossing angles
55- assert np . isclose (tw ['px' , 'ip1' ],
58+ xo . assert_allclose (tw ['px' , 'ip1' ],
5659 250e-6 * {'lhcb1' : 1 , 'lhcb2' : - 1 }[line_name ], rtol = 0 , atol = 0.5e-6 )
57- assert np . isclose (tw ['py' , 'ip1' ], 0 , rtol = 0 , atol = 0.5e-6 )
58- assert np . isclose (tw ['px' , 'ip5' ], 0 , rtol = 0 , atol = 0.5e-6 )
59- assert np . isclose (tw ['py' , 'ip5' ], 250e-6 , rtol = 0 , atol = 0.5e-6 )
60+ xo . assert_allclose (tw ['py' , 'ip1' ], 0 , rtol = 0 , atol = 0.5e-6 )
61+ xo . assert_allclose (tw ['px' , 'ip5' ], 0 , rtol = 0 , atol = 0.5e-6 )
62+ xo . assert_allclose (tw ['py' , 'ip5' ], 250e-6 , rtol = 0 , atol = 0.5e-6 )
6063
61- assert np . isclose (tw ['px' , 'ip2' ], 0 , rtol = 0 , atol = 0.5e-6 )
62- assert np . isclose (tw ['py' , 'ip2' ], - 100e-6 , rtol = 0 , atol = 0.5e-6 ) # accounts for spectrometer
64+ xo . assert_allclose (tw ['px' , 'ip2' ], 0 , rtol = 0 , atol = 0.5e-6 )
65+ xo . assert_allclose (tw ['py' , 'ip2' ], - 100e-6 , rtol = 0 , atol = 0.5e-6 ) # accounts for spectrometer
6366
64- assert np . isclose (tw ['px' , 'ip8' ],
67+ xo . assert_allclose (tw ['px' , 'ip8' ],
6568 - 115e-6 * {'lhcb1' : 1 , 'lhcb2' : - 1 }[line_name ], rtol = 0 , atol = 0.5e-6 ) # accounts for spectrometer
66- assert np . isclose (tw ['py' , 'ip8' ], 2e-6 , rtol = 0 , atol = 0.5e-6 ) # small effect from spectrometer (titled)
69+ xo . assert_allclose (tw ['py' , 'ip8' ], 2e-6 , rtol = 0 , atol = 0.5e-6 ) # small effect from spectrometer (titled)
6770
68- assert np . isclose (tw ['betx' , 'ip1' ], 15e-2 , rtol = 2e-2 , atol = 0 ) # beta beating coming from on_disp
69- assert np . isclose (tw ['bety' , 'ip1' ], 15e-2 , rtol = 3e-2 , atol = 0 )
70- assert np . isclose (tw ['betx' , 'ip5' ], 15e-2 , rtol = 2e-2 , atol = 0 )
71- assert np . isclose (tw ['bety' , 'ip5' ], 15e-2 , rtol = 2e-2 , atol = 0 )
71+ xo . assert_allclose (tw ['betx' , 'ip1' ], 15e-2 , rtol = 2e-2 , atol = 0 ) # beta beating coming from on_disp
72+ xo . assert_allclose (tw ['bety' , 'ip1' ], 15e-2 , rtol = 3e-2 , atol = 0 )
73+ xo . assert_allclose (tw ['betx' , 'ip5' ], 15e-2 , rtol = 2e-2 , atol = 0 )
74+ xo . assert_allclose (tw ['bety' , 'ip5' ], 15e-2 , rtol = 2e-2 , atol = 0 )
7275
73- assert np . isclose (tw ['betx' , 'ip2' ], 10. , rtol = 4e-2 , atol = 0 )
74- assert np . isclose (tw ['bety' , 'ip2' ], 10. , rtol = 3e-2 , atol = 0 )
76+ xo . assert_allclose (tw ['betx' , 'ip2' ], 10. , rtol = 4e-2 , atol = 0 )
77+ xo . assert_allclose (tw ['bety' , 'ip2' ], 10. , rtol = 3e-2 , atol = 0 )
7578
76- assert np . isclose (tw ['betx' , 'ip8' ], 1.5 , rtol = 3e-2 , atol = 0 )
77- assert np . isclose (tw ['bety' , 'ip8' ], 1.5 , rtol = 2e-2 , atol = 0 )
79+ xo . assert_allclose (tw ['betx' , 'ip8' ], 1.5 , rtol = 3e-2 , atol = 0 )
80+ xo . assert_allclose (tw ['bety' , 'ip8' ], 1.5 , rtol = 2e-2 , atol = 0 )
7881
7982 # Check crab cavities
8083 z_crab_test = 1e-2
@@ -88,16 +91,16 @@ def check_optics_orbit_etc(collider, line_names, sep_h_ip2, sep_v_ip8):
8891 - collider [line_name ].twiss (method = '4d' , zeta0 = - z_crab_test )['y' , 'ip5' ])
8992 / 2 / z_crab_test )
9093
91- assert np . isclose (phi_crab_1 , - 190e-6 * {'lhcb1' : 1 , 'lhcb2' : - 1 }[line_name ],
94+ xo . assert_allclose (phi_crab_1 , - 190e-6 * {'lhcb1' : 1 , 'lhcb2' : - 1 }[line_name ],
9295 rtol = 1e-2 , atol = 0 )
93- assert np . isclose (phi_crab_5 , - 170e-6 , rtol = 1e-2 , atol = 0 )
96+ xo . assert_allclose (phi_crab_5 , - 170e-6 , rtol = 1e-2 , atol = 0 )
9497
9598 # Check one octupole strength
9699 if line_name == 'lhcb1' :
97- assert np . isclose (collider ['lhcb1' ]['mo.33l4.b1' ].knl [3 ], - 2.2169 * 200 / 235 ,
100+ xo . assert_allclose (collider ['lhcb1' ]['mo.33l4.b1' ].knl [3 ], - 2.2169 * 200 / 235 ,
98101 rtol = 1e-3 , atol = 0 )
99102 elif line_name == 'lhcb2' :
100- assert np . isclose (collider ['lhcb2' ]['mo.33r4.b2' ].knl [3 ], - 2.2169 ,
103+ xo . assert_allclose (collider ['lhcb2' ]['mo.33r4.b2' ].knl [3 ], - 2.2169 ,
101104 rtol = 1e-3 , atol = 0 )
102105
103106
0 commit comments