Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More features for tracking with collective effects #147

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d65855d
add a some code for the slice monitor (incomplete)
May 7, 2024
905dd79
start moving handling of buffer in sliced element
May 17, 2024
c2282e2
serveral fixes
May 18, 2024
cb6a4ac
remove unwanted commas
May 21, 2024
dc5b8b0
add tests for monitor buffers
May 21, 2024
e76bcb2
more work
lgiacome May 30, 2024
114dffd
Merge branch 'refactor/wake_api' into feature/monitors-for-wakes
lgiacome Jun 6, 2024
7dbe1ed
small cahnges
lgiacome Jun 6, 2024
e430df6
Merge branch 'refactor/wake_api' into feature/monitors-for-wakes
lgiacome Jun 6, 2024
bca6d88
finished up and tested collective monitor
lgiacome Jun 15, 2024
eb33a52
small improvements in documentation
lgiacome Jun 17, 2024
2e27e4d
Merge branch 'feature/monitors-for-wakes' of https://github.com/lgiac…
lgiacome Jun 18, 2024
be5e38c
delete outdated examples
lgiacome Jun 18, 2024
0122bce
delete outdated examples
lgiacome Jun 18, 2024
8247c91
Merge branch 'main' into feature/monitors-for-wakes
lgiacome Jul 18, 2024
65b5595
Merge branch 'refactor/zotter_definition' into feature/monitors-for-w…
lgiacome Jul 18, 2024
db3d53b
fix transverse damper and improve tests
lgiacome Sep 10, 2024
59ab01b
finalize damper
lgiacome Sep 16, 2024
695a180
finalize damper
lgiacome Sep 16, 2024
fd652b7
Merge branch 'xsuite:refactor/zotter_definition' into refactor/zotter…
lgiacome Sep 16, 2024
e949381
Merge branch 'refactor/zotter_definition' into feature/monitors-for-w…
lgiacome Sep 16, 2024
8e4f315
update collective monitor and add mpi test
lgiacome Sep 17, 2024
30492ae
Merge branch 'main' into refactor/zotter_definition
lgiacome Sep 18, 2024
7d2a5ed
fix a typo
lgiacome Sep 18, 2024
9fe5c11
improve transverse damper docstring
lgiacome Sep 20, 2024
156402a
small fix to the collective monitor
lgiacome Sep 20, 2024
f908d9d
handle an error
lgiacome Sep 20, 2024
87e7823
update collective monitor test
lgiacome Sep 20, 2024
5f38dfc
cosmetics
lgiacome Sep 20, 2024
bed07cc
cosmetics
lgiacome Sep 20, 2024
fe32080
flush data to file only if file name is specified
lgiacome Oct 14, 2024
67c0403
default to 1 slice per bunch
lgiacome Oct 14, 2024
1d91ea1
update tests
lgiacome Oct 14, 2024
f74dd27
import h5py only if needed
lgiacome Oct 14, 2024
6bd4d01
fix test
lgiacome Oct 14, 2024
d4e9d30
add bash script to run mpi tests
lgiacome Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into refactor/zotter_definition
lgiacome committed Sep 18, 2024

Verified

This commit was signed with the committer’s verified signature.
MotorTruck1221 MotorTruck1221
commit 30492ae74e69adbf7373acc46af3e273111fd49c
1 change: 1 addition & 0 deletions contributors_and_credits.txt
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ CERN contributors:
- H. Bartosik
- X. Buffat
- R. De Maria
- L. Giacomel
- G. Iadarola
- P. Kicsiny
- S. Lopaciuk
35 changes: 15 additions & 20 deletions examples/002_beambeam/005_beambeam6d_strongstrong_pipeline.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@
#############
# Beam-beam #
#############
slicer = xf.TempSlicer(sigma_z=sigma_z, n_slices=2)
slicer = xf.TempSlicer(sigma_z=sigma_z, n_slices=5)
config_for_update_b1_IP1=xf.ConfigForUpdateBeamBeamBiGaussian3D(
pipeline_manager=pipeline_manager,
element_name='IP1',
@@ -142,19 +142,15 @@
# arcs (here they are all the same with half the phase advance) #
#################################################################

arc12 = xt.LinearTransferMatrix(
alpha_x_0=0.0, beta_x_0=beta_x_IP1, disp_x_0=0.0,
alpha_x_1=0.0, beta_x_1=beta_x_IP2, disp_x_1=0.0,
alpha_y_0=0.0, beta_y_0=beta_y_IP1, disp_y_0=0.0,
alpha_y_1=0.0, beta_y_1=beta_y_IP2, disp_y_1=0.0,
Q_x=Qx/2, Q_y=Qy/2,beta_s=beta_s, Q_s=Qs/2)
arc12 = xt.LineSegmentMap(
betx=[beta_x_IP1, beta_x_IP2],
bety=[beta_y_IP1, beta_y_IP2],
qx=Qx/2, qy=Qy/2, bets=beta_s, qs=Qs/2)

arc21 = xt.LinearTransferMatrix(
alpha_x_0=0.0, beta_x_0=beta_x_IP2, disp_x_0=0.0,
alpha_x_1=0.0, beta_x_1=beta_x_IP1, disp_x_1=0.0,
alpha_y_0=0.0, beta_y_0=beta_y_IP2, disp_y_0=0.0,
alpha_y_1=0.0, beta_y_1=beta_y_IP1, disp_y_1=0.0,
Q_x=Qx/2, Q_y=Qy/2,beta_s=beta_s, Q_s=Qs/2)
arc21 = xt.LineSegmentMap(
betx=[beta_x_IP2, beta_x_IP1],
bety=[beta_y_IP2, beta_y_IP1],
qx=Qx/2, qy=Qy/2, bets=beta_s, qs=Qs/2)

#################################################################
# Tracker #
@@ -168,15 +164,17 @@
line_b2.build_tracker()
branch_b1 = xt.PipelineBranch(line_b1,particles_b1)
branch_b2 = xt.PipelineBranch(line_b2,particles_b2)
multitracker = xt.PipelineMultiTracker(branches=[branch_b1,branch_b2])
multitracker = xt.PipelineMultiTracker(branches=[branch_b1,branch_b2], verbose=True)

#################################################################
# Tracking #
#################################################################
print('Tracking...')
time0 = time.time()
nTurn = 1024
multitracker.track(num_turns=nTurn,turn_by_turn_monitor=True)
multitracker.track(num_turns=nTurn,
log=xt.Log(x_mean=lambda l, p: p.x[p.state>0].mean(),
y_mean=lambda l, p: p.y[p.state>0].mean()))
print('Done with tracking.',(time.time()-time0)/1024,'[s/turn]')

#################################################################
@@ -188,8 +186,8 @@
plt.figure(1000+i)
plt.plot(line_b1.record_last_track.x[i,:],line_b1.record_last_track.px[i,:],'x')

positions_x_b1 = np.average(line_b1.record_last_track.x,axis=0)
positions_y_b1 = np.average(line_b1.record_last_track.y,axis=0)
positions_x_b1 = np.array(line_b1.log_last_track['x_mean'])
positions_y_b1 = np.array(line_b1.log_last_track['y_mean'])
plt.figure(0)
plt.plot(np.arange(nTurn),positions_x_b1/np.sqrt(physemit_x*beta_x_IP1),'x')
plt.plot(np.arange(nTurn),positions_y_b1/np.sqrt(physemit_y*beta_y_IP1),'x')
@@ -201,6 +199,3 @@
myFFT = np.fft.fftshift(np.fft.fft(positions_y_b1))
plt.semilogy(freqs[mask], (np.abs(myFFT[mask])))
plt.show()



98 changes: 98 additions & 0 deletions examples/002_beambeam/011a_inspect_kick_vs_zeta_hirata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import numpy as np

import xfields as xf
import xtrack as xt

constant_charge_slicing_gaussian = \
xf.config_tools.beambeam_config_tools.config_tools.constant_charge_slicing_gaussian

# LHC-like parameter
mass0 = xt.PROTON_MASS_EV
p0c = 7e12
phi = 0#200e-6
betx = 0.15
bety = 0.2
sigma_z = 0.001
nemitt_x = 2e-6
nemitt_y = 1e-6
bunch_intensity = 2e10
num_slices = 11
slice_mode = 'constant_charge'

# # FCC-like parameters
# mass0 = xt.ELECTRON_MASS_EV
# p0c = 50e9
# phi = 15e-3
# betx = 0.15
# bety = 0.001
# sigma_z = 0.01
# nemitt_x = 270e-12
# nemitt_y = 1e-12
# bunch_intensity = 2e11
# num_slices = 100000 # needed to have motion of the particle within one slice
# # smaller that 1 sigma at the ip
# slice_mode = 'uniform'

lntwiss = xt.Line(elements=[xt.Marker()])
lntwiss.particle_ref = xt.Particles(p0c=p0c, mass0=mass0)
twip = lntwiss.twiss(betx=betx, bety=bety)
cov = twip.get_beam_covariance(nemitt_x=nemitt_x, nemitt_y=nemitt_y)

sigma_x = cov.sigma_x[0]
sigma_y = cov.sigma_y[0]


if slice_mode == 'constant_charge':
sigma_z_limi = sigma_z / 2
z_centroids, z_cuts, num_part_per_slice = constant_charge_slicing_gaussian(
bunch_intensity, sigma_z_limi, num_slices)
z_centroids_from_tail = z_centroids[::-1]
elif slice_mode == 'uniform':
z_cuts = np.linspace(-3*sigma_z, 3*sigma_z, num_slices+1)
z_centroids = 0.5 * (z_cuts[1:] + z_cuts[:-1])
z_centroids_from_tail = z_centroids[::-1]
num_part_per_slice = 0 * z_centroids
from scipy.special import erf
for ii in range(num_slices):
num_part_per_slice[ii] = bunch_intensity / 2 * (erf(z_cuts[ii+1]/sigma_z) - erf(z_cuts[ii]/sigma_z))
else:
raise ValueError


bbg = xf.BeamBeamBiGaussian3D(
phi=phi,
alpha=0,
other_beam_q0=1.,
slices_other_beam_num_particles=num_part_per_slice,
slices_other_beam_zeta_center=z_centroids_from_tail,
slices_other_beam_Sigma_11=cov.Sigma11[0],
slices_other_beam_Sigma_12=cov.Sigma12[0],
slices_other_beam_Sigma_22=cov.Sigma22[0],
slices_other_beam_Sigma_33=cov.Sigma33[0],
slices_other_beam_Sigma_34=cov.Sigma34[0],
slices_other_beam_Sigma_44=cov.Sigma44[0],
)

particles = lntwiss.build_particles(x=1.2 * sigma_x, y=1.3 * sigma_y,
zeta=np.linspace(-2 * sigma_z, 2 * sigma_z, 10000))

p1 = particles.copy()
bbg._track_non_collective(particles)
bbg.track(p1)

p_test = lntwiss.build_particles(x=1.2 * sigma_x, y=1.3 * sigma_y,
zeta=[0.00553, 0.00557])
bbg._track_non_collective(p_test, i_slices=[1])

import matplotlib.pyplot as plt

plt.close('all')
plt.figure(1)
plt.plot(particles.zeta, particles.px)
plt.plot(particles.zeta, p1.px)

plt.grid()
# for zz in z_centroids:
# plt.axvline(zz, color='r', alpha=0.1)

plt.show()
65 changes: 65 additions & 0 deletions examples/002_beambeam/011b_lhc_one_bb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import numpy as np
import xtrack as xt

collider = xt.Multiline.from_json(
'../../../xtrack/test_data/hllhc15_thick/hllhc15_collider_thick.json')
collider.lhcb1.twiss_default.clear()
collider.lhcb2.twiss_default.clear()

collider.vars['vrf400'] = 16

collider.install_beambeam_interactions(
clockwise_line='lhcb1',
anticlockwise_line='lhcb2',
harmonic_number=35640,
bunch_spacing_buckets=10,
sigmaz=0.1,
ip_names=['ip1'],
delay_at_ips_slots=[0, 0],
num_long_range_encounters_per_side=[0, 0],
num_slices_head_on=1)

collider.vars['on_x1hl'] = 200
collider.vars['on_x1vl'] = 100


tw = collider.twiss()

collider.configure_beambeam_interactions(crab_strong_beam=False,
num_particles=2.3e11, nemitt_x=2e-6, nemitt_y=2e-6)

fields_to_display = [
'phi',
'alpha',
'other_beam_shift_x',
'other_beam_shift_y',
'post_subtract_px',
'post_subtract_py',
'post_subtract_pzeta',
'post_subtract_x',
'post_subtract_y',
'ref_shift_px',
'ref_shift_py',
'ref_shift_pzeta',
'ref_shift_x',
'ref_shift_y',
'ref_shift_zeta',
]

values_b1 = []
values_b2 = []
for field in fields_to_display:
values_b1.append(getattr(collider.lhcb1['bb_ho.c1b1_00'], field))
values_b2.append(getattr(collider.lhcb2['bb_ho.c1b2_00'], field))

values_b1 = np.array(values_b1)
values_b2 = np.array(values_b2)

values_b1[np.abs(values_b1) < 6e-6] = 0
values_b2[np.abs(values_b2) < 6e-6] = 0

bb_config = xt.Table(
data={'name': np.array(fields_to_display),
'b1': np.array(values_b1),
'b2': np.array(values_b2)})
bb_config.show()
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.