Skip to content

Commit ad9d099

Browse files
authored
Merge pull request #82 from lhcopt/adapt_to_new_xfield_interface
Adapt to new xfield interface
2 parents 1d12465 + 0c459d1 commit ad9d099

File tree

5 files changed

+104
-107
lines changed

5 files changed

+104
-107
lines changed

make_it.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
22
bash Miniconda3-latest-Linux-x86_64.sh -b -p ./miniconda -f
33
source miniconda/bin/activate
4-
python -m pip install ipython numpy scipy pandas psutil xsuite
4+
python -m pip install ipython numpy scipy pandas psutil xsuite matplotlib
55
git clone -b release/v0.1.0 [email protected]:xsuite/tree_maker.git
66
python -m pip install -e tree_maker
77
git clone [email protected]:lhcopt/lhcmask.git -b release/v1.3.3
88
python -m pip install -e lhcmask
9+
python -m pip install sixtracktools
10+
python -m pip install NAFFlib
911
git clone [email protected]:lhcopt/lhcerrors.git
1012
git clone [email protected]:lhcopt/lhctoolkit.git
1113
git clone [email protected]:lhcopt/hllhc15.git
1214
git clone [email protected]:lhcopt/hllhc14.git
15+
# you need gfortran
16+
# `sudo yum install gcc-gfortran`
17+
# then `cd beambeam_macros`
18+
# and `gfortran headonslice.f -o headonslice`
1319
git clone [email protected]:lhcopt/beambeam_macros.git
1420
git clone $(whoami)@lxplus.cern.ch:/afs/cern.ch/eng/lhc/optics/runIII

pymask/beambeam.py

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -624,54 +624,40 @@ def setup_beam_beam_in_line(
624624

625625
for ii, (ee, eename) in enumerate(zip(line.elements, line.element_names)):
626626
if isinstance(ee, xf.BeamBeamBiGaussian2D):
627-
ee.n_particles=bb_df.loc[eename, 'other_num_particles']
628-
ee.q0 = bb_df.loc[eename, 'other_particle_charge']
629-
ee.sigma_x = np.sqrt(bb_df.loc[eename, 'other_Sigma_11'])
630-
ee.sigma_y = np.sqrt(bb_df.loc[eename, 'other_Sigma_33'])
631-
ee.beta0 = bb_df.loc[eename, 'other_relativistic_beta']
632-
ee.mean_x = bb_df.loc[eename, 'separation_x']
633-
ee.mean_y = bb_df.loc[eename, 'separation_y']
627+
ee.other_beam_num_particles=bb_df.loc[eename, 'other_num_particles']
628+
ee.other_beam_q0 = bb_df.loc[eename, 'other_particle_charge']
629+
ee.other_beam_Sigma_11 = bb_df.loc[eename, 'other_Sigma_11']
630+
ee.other_beam_Sigma_33 = bb_df.loc[eename, 'other_Sigma_33']
631+
ee.other_beam_beta0 = bb_df.loc[eename, 'other_relativistic_beta']
632+
ee.other_beam_shift_x = bb_df.loc[eename, 'separation_x']
633+
ee.other_beam_shift_y = bb_df.loc[eename, 'separation_y']
634634
if isinstance(ee, xf.BeamBeamBiGaussian3D):
635635
params = {}
636636
params['phi'] = bb_df.loc[eename, 'phi']
637637
params['alpha'] = bb_df.loc[eename, 'alpha']
638-
params['x_bb_co'] = bb_df.loc[eename, 'separation_x']
639-
params['y_bb_co'] = bb_df.loc[eename, 'separation_y']
640-
# TODO update xtrack interface to separate charge and b. population
641-
params['charge_slices'] = [(bb_df.loc[eename, 'other_num_particles']
642-
* bb_df.loc[eename, 'other_particle_charge'])]
643-
params['zeta_slices'] = [0.0]
644-
params['sigma_11'] = bb_df.loc[eename, 'other_Sigma_11']
645-
params['sigma_12'] = bb_df.loc[eename, 'other_Sigma_12']
646-
params['sigma_13'] = bb_df.loc[eename, 'other_Sigma_13']
647-
params['sigma_14'] = bb_df.loc[eename, 'other_Sigma_14']
648-
params['sigma_22'] = bb_df.loc[eename, 'other_Sigma_22']
649-
params['sigma_23'] = bb_df.loc[eename, 'other_Sigma_23']
650-
params['sigma_24'] = bb_df.loc[eename, 'other_Sigma_24']
651-
params['sigma_33'] = bb_df.loc[eename, 'other_Sigma_33']
652-
params['sigma_34'] = bb_df.loc[eename, 'other_Sigma_34']
653-
params['sigma_44'] = bb_df.loc[eename, 'other_Sigma_44']
638+
params['other_beam_shift_x'] = bb_df.loc[eename, 'separation_x']
639+
params['other_beam_shift_y'] = bb_df.loc[eename, 'separation_y']
640+
params['slices_other_beam_num_particles'] = [bb_df.loc[eename, 'other_num_particles']]
641+
params['other_beam_q0'] = bb_df.loc[eename, 'other_particle_charge']
642+
params['slices_other_beam_zeta_center'] = [0.0]
643+
params['slices_other_beam_Sigma_11'] = [bb_df.loc[eename, 'other_Sigma_11']]
644+
params['slices_other_beam_Sigma_12'] = [bb_df.loc[eename, 'other_Sigma_12']]
645+
params['slices_other_beam_Sigma_13'] = [bb_df.loc[eename, 'other_Sigma_13']]
646+
params['slices_other_beam_Sigma_14'] = [bb_df.loc[eename, 'other_Sigma_14']]
647+
params['slices_other_beam_Sigma_22'] = [bb_df.loc[eename, 'other_Sigma_22']]
648+
params['slices_other_beam_Sigma_23'] = [bb_df.loc[eename, 'other_Sigma_23']]
649+
params['slices_other_beam_Sigma_24'] = [bb_df.loc[eename, 'other_Sigma_24']]
650+
params['slices_other_beam_Sigma_33'] = [bb_df.loc[eename, 'other_Sigma_33']]
651+
params['slices_other_beam_Sigma_34'] = [bb_df.loc[eename, 'other_Sigma_34']]
652+
params['slices_other_beam_Sigma_44'] = [bb_df.loc[eename, 'other_Sigma_44']]
654653

655654
if not (bb_coupling):
656-
params['sigma_13'] = 0.0
657-
params['sigma_14'] = 0.0
658-
params['sigma_23'] = 0.0
659-
params['sigma_24'] = 0.0
660-
661-
params["x_co"] = 0
662-
params["px_co"] = 0
663-
params["y_co"] = 0
664-
params["py_co"] = 0
665-
params["zeta_co"] = 0
666-
params["delta_co"] = 0
667-
params["d_x"] = 0
668-
params["d_px"] = 0
669-
params["d_y"] = 0
670-
params["d_py"] = 0
671-
params["d_zeta"] = 0
672-
params["d_delta"] = 0
673-
674-
newee = xf.BeamBeamBiGaussian3D(old_interface=params)
655+
params['slices_other_beam_Sigma_13'] = [0.0]
656+
params['slices_other_beam_Sigma_14'] = [0.0]
657+
params['slices_other_beam_Sigma_23'] = [0.0]
658+
params['slices_other_beam_Sigma_24'] = [0.0]
659+
660+
newee = xf.BeamBeamBiGaussian3D(**params)
675661
line.element_dict[eename] = newee
676662

677663

pymask/pymasktools.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -498,52 +498,52 @@ def save_mad_sequence_and_error(mad, seq_name, filename='lhc'):
498498
def _disable_beam_beam(line):
499499
for ee in line.elements:
500500
if ee.__class__.__name__.startswith('BeamBeam'):
501-
ee._temp_q0 = ee.q0
502-
ee.q0 = 0
501+
ee._temp_q0 = ee.other_beam_q0
502+
ee.other_beam_q0 = 0
503503
if ee.__class__.__name__ == 'BeamBeamBiGaussian2D':
504-
ee._temp_d_px = ee.d_px
505-
ee._temp_d_py = ee.d_py
506-
ee.d_px = 0.
507-
ee.d_py = 0.
504+
ee._temp_d_px = ee.post_subtract_px
505+
ee._temp_d_py = ee.post_subtract_py
506+
ee.post_subtract_px = 0.
507+
ee.post_subtract_py = 0.
508508
elif ee.__class__.__name__ == 'BeamBeamBiGaussian3D':
509-
ee._temp_Dx_sub = ee.Dx_sub
510-
ee._temp_Dpx_sub = ee.Dpx_sub
511-
ee._temp_Dy_sub = ee.Dy_sub
512-
ee._temp_Dpy_sub = ee.Dpy_sub
513-
ee._temp_Dsigma_sub = ee.Dsigma_sub
514-
ee._temp_Ddelta_sub = ee.Ddelta_sub
515-
ee.Dx_sub = 0.
516-
ee.Dpx_sub = 0.
517-
ee.Dy_sub = 0.
518-
ee.Dpy_sub = 0.
519-
ee.Dsigma_sub = 0.
520-
ee.Ddelta_sub = 0.
509+
ee._temp_Dx_sub = ee.post_subtract_x
510+
ee._temp_Dpx_sub = ee.post_subtract_px
511+
ee._temp_Dy_sub = ee.post_subtract_y
512+
ee._temp_Dpy_sub = ee.post_subtract_py
513+
ee._temp_Dzeta_sub = ee.post_subtract_zeta
514+
ee._temp_Dpzeta_sub = ee.post_subtract_pzeta
515+
ee.post_subtract_x = 0.
516+
ee.post_subtract_px = 0.
517+
ee.post_subtract_y = 0.
518+
ee.post_subtract_py = 0.
519+
ee.post_subtract_zeta = 0.
520+
ee.post_subtract_pzeta = 0.
521521
else:
522522
raise ValueError('What?!')
523523

524524
def _restore_beam_beam(line):
525525
for ee in line.elements:
526526
if ee.__class__.__name__.startswith('BeamBeam'):
527-
ee.q0 = ee._temp_q0
527+
ee.other_beam_q0 = ee._temp_q0
528528
del(ee._temp_q0)
529529
if ee.__class__.__name__ == 'BeamBeamBiGaussian2D':
530-
ee.d_px = ee._temp_d_px
531-
ee.d_py = ee._temp_d_py
530+
ee.post_subtract_px = ee._temp_d_px
531+
ee.post_subtract_py = ee._temp_d_py
532532
del(ee._temp_d_px)
533533
del(ee._temp_d_py)
534534
elif ee.__class__.__name__ == 'BeamBeamBiGaussian3D':
535-
ee.Dx_sub = ee._temp_Dx_sub
536-
ee.Dpx_sub = ee._temp_Dpx_sub
537-
ee.Dy_sub = ee._temp_Dy_sub
538-
ee.Dpy_sub = ee._temp_Dpy_sub
539-
ee.Dsigma_sub = ee._temp_Dsigma_sub
540-
ee.Ddelta_sub = ee._temp_Ddelta_sub
535+
ee.post_subtract_x = ee._temp_Dx_sub
536+
ee.post_subtract_px = ee._temp_Dpx_sub
537+
ee.post_subtract_y = ee._temp_Dy_sub
538+
ee.post_subtract_py = ee._temp_Dpy_sub
539+
ee.post_subtract_zeta = ee._temp_Dzeta_sub
540+
ee.post_subtract_pzeta = ee._temp_Dpzeta_sub
541541
del(ee._temp_Dx_sub)
542542
del(ee._temp_Dpx_sub)
543543
del(ee._temp_Dy_sub)
544544
del(ee._temp_Dpy_sub)
545-
del(ee._temp_Dsigma_sub)
546-
del(ee._temp_Ddelta_sub)
545+
del(ee._temp_Dzeta_sub)
546+
del(ee._temp_Dpzeta_sub)
547547
else:
548548
raise ValueError('What?!')
549549

python_examples/hl_lhc_collisions_python/checks_and_doc/t004_check_output_consistency.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def prepare_line(path, input_type):
194194
if kk == "length":
195195
if np.abs(ee_test.hxl) + np.abs(ee_test.hyl) == 0.0:
196196
continue
197-
if kk == "order":
197+
if kk == "order" or kk == "inv_factorial_order":
198198
# Checked through bal
199199
continue
200200
if kk == 'knl' or kk == 'ksl' or kk == 'bal':
@@ -250,43 +250,46 @@ def prepare_line(path, input_type):
250250

251251
# Exceptions BB4D (separations are recalculated)
252252
if not(strict) and isinstance(ee_test, xf.BeamBeamBiGaussian2D):
253-
if kk == "x_bb":
254-
if diff_abs / dtest["sigma_x"] < 0.01: # This is neede to accommodate different leveling routines (1% difference)
253+
if kk == "other_beam_shift_x":
254+
if diff_abs / np.sqrt(dtest["other_beam_Sigma_11"]) < 0.01: # This is neede to accommodate different leveling routines (1% difference)
255255
continue
256-
if kk == "y_bb":
257-
if diff_abs / dtest["sigma_y"] < 0.01:
256+
if kk == "other_beam_shift_y":
257+
if diff_abs / np.sqrt(dtest["other_beam_Sigma_33"]) < 0.01:
258258
continue
259-
if kk == "sigma_x":
260-
if diff_rel < 1e-5:
259+
if kk == "other_beam_Sigma_11":
260+
if diff_rel < (1e-5)**2:
261261
continue
262-
if kk == "sigma_y":
263-
if diff_rel < 1e-5:
262+
if kk == "other_beam_Sigma_33":
263+
if diff_rel < (1e-5)**2:
264264
continue
265265
if isinstance(ee_test, xf.BeamBeamBiGaussian2D):
266-
if kk == 'q0' or kk == 'n_particles':
266+
if kk == 'other_beam_q0' or kk == 'other_beam_num_particles':
267267
# ambiguity due to old interface
268-
if np.abs(ee_test.n_particles*ee_test.q0 -
269-
ee_six.n_particles*ee_six.q0 ) < 1.: # charges
268+
if np.abs(ee_test.other_beam_num_particles*ee_test.other_beam_q0 -
269+
ee_six.other_beam_num_particles*ee_six.other_beam_q0 ) < 1.: # charges
270270
continue
271271

272272
# Exceptions BB6D (angles and separations are recalculated)
273273
if not(strict) and isinstance(ee_test, xf.BeamBeamBiGaussian3D):
274-
if kk == "alpha":
274+
if kk == "_cos_alpha":
275275
if diff_abs < 10e-6:
276276
continue
277-
if kk == "x_co" or kk == "x_bb_co" or kk == 'delta_x':
278-
if diff_abs / np.sqrt(dtest["sigma_11"]) < 0.015:
277+
if kk == "_sin_alpha":
278+
if diff_abs < 10e-6:
279+
continue
280+
if kk == "ref_shift_x" or kk == "other_beam_shift_x":
281+
if diff_abs / np.sqrt(dtest["slices_other_beam_Sigma_11_star"][0]) < 0.015:
279282
continue
280-
if kk == "y_co" or kk == "y_bb_co" or kk == 'delta_y':
281-
if diff_abs / np.sqrt(dtest["sigma_33"]) < 0.015:
283+
if kk == "ref_shift_y" or kk == "other_beam_shift_y":
284+
if diff_abs / np.sqrt(dtest["slices_other_beam_Sigma_33_star"][0]) < 0.015:
282285
continue
283-
if kk == "zeta_co":
286+
if kk == "ref_shift_zeta":
284287
if diff_abs <1e-5:
285288
continue
286-
if kk == "delta_co":
289+
if kk == "ref_shift_pzeta":
287290
if diff_abs <1e-5:
288291
continue
289-
if kk == "px_co" or kk == 'py_co':
292+
if kk == "ref_shift_px" or kk == 'ref_shift_py':
290293
if diff_abs <30e-9:
291294
continue
292295
if isinstance(ee_test, xt.XYShift):

python_examples/hl_lhc_collisions_python/checks_and_doc/t005_check_crabs.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
phi_weak = Phi
2929
phi_c_weak = Phi_c
3030

31-
# B4 ip5
32-
beam_track = 'b4'
33-
ip_choice = 5
34-
plane = 'y'
35-
phi_weak = Phi
36-
phi_c_weak = Phi_c
37-
38-
# B4 ip1
39-
beam_track = 'b4'
40-
ip_choice = 1
41-
plane = 'x'
42-
phi_weak = -Phi
43-
phi_c_weak = -Phi_c
31+
## B4 ip5
32+
#beam_track = 'b4'
33+
#ip_choice = 5
34+
#plane = 'y'
35+
#phi_weak = Phi
36+
#phi_c_weak = Phi_c
37+
#
38+
## B4 ip1
39+
#beam_track = 'b4'
40+
#ip_choice = 1
41+
#plane = 'x'
42+
#phi_weak = -Phi
43+
#phi_c_weak = -Phi_c
4444

4545
phi_strong = -phi_weak
4646
phi_c_strong = -phi_c_weak
@@ -105,7 +105,8 @@ def prepare_line(path, input_type):
105105
R1_orbit = phi_weak * s_rel
106106

107107
axcrab.plot(s_rel, np.array(
108-
[getattr(bb, f'delta_{plane}') for bb in bb_elems])+R1_orbit,
108+
#[getattr(bb, f'delta_{plane}') for bb in bb_elems])+R1_orbit,
109+
[getattr(bb, f'other_beam_shift_{plane}') for bb in bb_elems])+R1_orbit,
109110
'o', color = 'r', alpha=.5, label='strong xsuite')
110111
plt.plot(s_rel, R_no_crab + R_crab, '*', color='darkred', label='strong formula')
111112

@@ -125,7 +126,8 @@ def prepare_line(path, input_type):
125126
bb_all, _ = ltest.get_elements_of_type([xf.BeamBeamBiGaussian2D,
126127
xf.BeamBeamBiGaussian3D])
127128
for bb in bb_all:
128-
bb.q0 = 0
129+
#bb.q0 = 0
130+
bb.other_beam_q0 = 0
129131

130132
# # Switch off all beam-beam lenses
131133
crabs, crab_names = ltest.get_elements_of_type([xt.RFMultipole])

0 commit comments

Comments
 (0)