Skip to content

Commit 8448a67

Browse files
author
elwaagaa
committed
Plotting update and new O scan
1 parent ad280f4 commit 8448a67

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

data/acc-models-sps

Submodule acc-models-sps updated from beb2353 to 83418f1

fma_ions/plotting/sps_plotting_classes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def fit_and_plot_transverse_profiles(self,
685685
# Convert to m, normalize height
686686
x_pos *= 1e-3
687687
x_measured_bin_heights_sorted = np.array(sorted(x_prof_avg, reverse=True))
688-
x_measured_height_max_avg = np.mean(x_measured_bin_heights_sorted[:3]) # take average of top 3 values
688+
x_measured_height_max_avg = np.mean(x_measured_bin_heights_sorted[:2]) # take average of top 3 values
689689
x_prof_avg_norm = x_prof_avg / x_measured_height_max_avg
690690

691691
# Fit Gaussian, center the profile and re-adjust heights
@@ -705,7 +705,7 @@ def fit_and_plot_transverse_profiles(self,
705705
# Convert to m, normalize height
706706
y_pos *= 1e-3
707707
y_measured_bin_heights_sorted = np.array(sorted(y_prof_avg, reverse=True))
708-
y_measured_height_max_avg = np.mean(y_measured_bin_heights_sorted[:3]) # take average of top 3 values
708+
y_measured_height_max_avg = np.mean(y_measured_bin_heights_sorted[:2]) # take average of top 3 values
709709
y_prof_avg_norm = y_prof_avg / y_measured_height_max_avg
710710
# Fit Gaussian, center the profile and re-adjust heights
711711
popt_Y_meas, _ = fits.fit_Gaussian(y_pos, y_prof_avg_norm, p0=(1.0, 0.0, 0.02))
@@ -740,7 +740,7 @@ def fit_and_plot_transverse_profiles(self,
740740
for j, ind in enumerate(index_to_plot):
741741
# Normalize bin heights
742742
y_bin_heights_sorted = np.array(sorted(tbt_dict['monitorV_y_intensity'][ind], reverse=True))
743-
y_height_max_avg = np.mean(y_bin_heights_sorted[:3]) # take average of top 3 values
743+
y_height_max_avg = np.mean(y_bin_heights_sorted[:2]) # take average of top 3 values
744744
Y_pos_data = tbt_dict['monitorV_y_grid']
745745
if ind == 0:
746746
Y0_profile_data = tbt_dict['monitorV_y_intensity'][ind] / y_height_max_avg ### if changes fast, take particle histogram instead
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""
2+
Launcher script to HTCondor for GPU - generate python scripts for tune scan
3+
"""
4+
import fma_ions
5+
import os
6+
import pathlib
7+
import numpy as np
8+
import datetime
9+
10+
# Find path of script being run
11+
dir_path = pathlib.Path(__file__).parent.absolute()
12+
13+
# Define run files and which parameters to change
14+
master_name = 'Q26_O_ions_bunch_intensity_scan_adaptive_sc_ibs_with_compensated_50_150_300_600_Hz_ripple_130k_turns_TRANSFER_FUNCTION_high_Nb_same_emittance'
15+
num_turns = 130_000 # corresponds to about 3 s for SPS ions at flat bottom
16+
Qy = 26.19
17+
Qx = 26.31
18+
19+
# Assume same emittances as Pb, but scaling from 28e8 as the SPS space charge limit
20+
# 28e8/3.94e8 = 7.1, so use this as scaling factor
21+
22+
no_LEIR_inj = [2, 3, 4, 5, 6, 8]
23+
Nb_array = ['2*1.3e8', '2*1.75e8', '2*2.215e8', '2*2.93e8', '2*3.202e8', '2*3.94e8']
24+
exn_array = ['0.73e-6', '0.89e-6', '1.11e-6', '1.4e-6', '1.75e-6', '2.1e-6']
25+
eyn_array = ['0.48e-6', '0.63e-6', '0.74e-6', '0.85e-6', '1.05e-6', '1.175e-6']
26+
run_files = ['sps_run_leir_inj_{}.py'.format(i+1) for i in range(len(no_LEIR_inj))]
27+
28+
# Define script and folder names
29+
script_names = run_files.copy()
30+
folder_names = ['sps_no_leir_inj_{}'.format(no_LEIR_inj[i]) for i in range(len(no_LEIR_inj))]
31+
string_array = ['No. LEIR inj. = {}'.format(no_LEIR_inj[i]) for i in range(len(no_LEIR_inj))]
32+
33+
# Generate the scripts to be submitted
34+
for i, run_file in enumerate(run_files):
35+
36+
# Write run file for given tune
37+
print('Generating launch script {}\n'.format(run_file))
38+
run_file = open(run_file, 'w')
39+
run_file.truncate(0) # remove existing content, if any
40+
run_file.write(
41+
'''import fma_ions
42+
import numpy as np
43+
output_dir = './'
44+
45+
n_turns = {}
46+
num_part = 20_000
47+
48+
beamParams=fma_ions.BeamParameters_SPS()
49+
beamParams.Nb = {}*7.24399203
50+
beamParams.exn = {}
51+
beamParams.eyn = {}
52+
53+
# Transfer function factors
54+
a_50 = 1.0 #1.7170
55+
a_150 = 0.5098
56+
a_300 = 0.2360
57+
a_600 = 0.1095
58+
59+
# Desired ripple frequencies and amplitudes - from DCCT measurements 2024-10-30
60+
ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0])
61+
kqf_amplitudes = np.array([1.79381965522221e-07*a_50, 1.7917856960711038e-07*a_150, 1.717715125357188e-07*a_300, 1.0613897587376263e-07*a_600])
62+
kqd_amplitudes = np.array([3.1433458408493135e-07*a_50, 4.125645646596158e-07*a_150, 2.6325770762187453e-07*a_300, 8.302889259074001e-08*a_600])
63+
kqf_phases = np.array([2.5699456856082965, -1.2707524434033985, 1.1509405507521766, -2.3897351868985552])
64+
kqd_phases = np.array([-1.6168418898711074, -1.5349070763197448, -2.145386063404577, 0.7431459693919794])
65+
66+
# Tracking on GPU context
67+
sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
68+
tbt = sps.track_SPS(ion_type='O', which_context='gpu', distribution_type='qgaussian', beamParams=beamParams, install_SC_on_line=True, add_beta_beat=True,
69+
add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True, ripple_freqs = ripple_freqs,
70+
kqf_amplitudes = kqf_amplitudes, kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases,
71+
SC_adaptive_interval_during_tracking=100)
72+
tbt.to_json(output_dir)
73+
'''.format(num_turns, Nb_array[i], exn_array[i], eyn_array[i], Qx, Qy)
74+
)
75+
run_file.close()
76+
77+
78+
# Instantiate the submitter class and launch the jobs
79+
sub = fma_ions.Submitter()
80+
master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}'.format(datetime.datetime.now(), master_name)
81+
82+
# Launch the Python scripts in this folder
83+
for i, script in enumerate(script_names):
84+
file_name = os.path.join(dir_path, script)
85+
print(f"Submitting {file_name}")
86+
sub.submit_GPU(file_name, master_job_name=master_job_name, job_name=folder_names[i])
87+
sub.copy_master_plot_script(folder_names, string_array)
88+
sub.copy_plot_script_emittances_for_scan(master_name, folder_names, scan_array_for_x_axis=Nb_array,
89+
label_for_x_axis='Injected Pb ions per bunch',
90+
extra_text_string='$Q_{x, y}$ = 26.31, 26.19 - q-Gaussian beam\\nAdaptive SC, ~10% $\\beta$-beat + non-linear magnet errors')

0 commit comments

Comments
 (0)