Skip to content

Commit 5270b23

Browse files
authored
Merge pull request #45 from lhcopt/v0.5
V0.5
2 parents 78df9ce + 1790cea commit 5270b23

File tree

19 files changed

+351
-251
lines changed

19 files changed

+351
-251
lines changed

examples/hl_lhc_collision/main.mask

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ par_o8 = 0; ! [mm]
7575
par_crab1 = -190; ! [urad]
7676
par_crab5 = par_crab1; ! [urad]
7777

78+
! Phase advance
79+
par_mux_ip15 = 0; ! default value 0 implies that phase advance is not matched
80+
par_muy_ip15 = 0; ! default value 0 implies that phase advance is not matched
81+
7882
! Dispersion correction knob
7983
par_on_disp = 1;
8084

@@ -129,22 +133,27 @@ par_correct_for_D2 = 0;
129133
par_correct_for_MCBX = 0;
130134

131135
par_on_errors_LHC = 1;
136+
par_off_errors_Q4_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q4
137+
par_off_errors_Q5_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q5
132138
par_on_errors_MBH = 1;
133-
par_on_errors_Q5 = 1;
134139
par_on_errors_Q4 = 1;
135140
par_on_errors_D2 = 1;
136141
par_on_errors_D1 = 1;
137142
par_on_errors_IT = 1;
138143
par_on_errors_MCBRD = 0;
139144
par_on_errors_MCBXF = 0;
145+
par_on_errors_NLC = 0;
146+
147+
! Create errortable output file
148+
par_write_errortable = 1;
140149

141150

142151
!*************************!
143152
! RUN !
144153
!*************************!
145154

146155
! Build machine and optics
147-
! (the user can intruduce in this section additional custom code
156+
! (the user can introduce in this section additional custom code
148157
! to edit machine and/or optics)
149158
call, file="make_sequence.madx";
150159
call, file="optics.madx";

examples/hl_lhc_collision_nobb_b4/main.mask

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ par_o8 = 0; ! [mm]
7777
par_crab1 = -190; ! [urad]
7878
par_crab5 = par_crab1; ! [urad]
7979

80+
! Phase advance
81+
par_mux_ip15 = 0; ! default value 0 implies that phase advance is not matched
82+
par_muy_ip15 = 0; ! default value 0 implies that phase advance is not matched
83+
8084
! Mimicking leveling
8185
par_sep8 = -0.03425547139366354;
8286
par_sep2 = 0.14471680504084292;
@@ -136,15 +140,19 @@ par_correct_for_D2 = 0;
136140
par_correct_for_MCBX = 0;
137141

138142
par_on_errors_LHC = 1;
143+
par_off_errors_Q4_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q4
144+
par_off_errors_Q5_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q5
139145
par_on_errors_MBH = 1;
140-
par_on_errors_Q5 = 1;
141146
par_on_errors_Q4 = 1;
142147
par_on_errors_D2 = 1;
143148
par_on_errors_D1 = 1;
144149
par_on_errors_IT = 1;
145150
par_on_errors_MCBRD = 0;
146151
par_on_errors_MCBXF = 0;
152+
par_on_errors_NLC = 0;
147153

154+
! Create errortable output file
155+
par_write_errortable = 1;
148156

149157
!*************************!
150158
! RUN !

examples/hl_lhc_injection/main.mask

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,19 @@ par_correct_for_D2 = 0;
129129
par_correct_for_MCBX = 0;
130130

131131
par_on_errors_LHC = 1;
132+
par_off_errors_Q4_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q4
133+
par_off_errors_Q5_inIP15 = 0; ! Set this flag only when errors in IP1 & IP5 need to be removed for Q5
132134
par_on_errors_MBH = 1;
133-
par_on_errors_Q5 = 1;
134135
par_on_errors_Q4 = 1;
135136
par_on_errors_D2 = 1;
136137
par_on_errors_D1 = 1;
137138
par_on_errors_IT = 1;
138139
par_on_errors_MCBRD = 0;
139140
par_on_errors_MCBXF = 0;
141+
par_on_errors_NLC = 0;
140142

143+
! Create errortable output file
144+
par_write_errortable = 1;
141145

142146
!*************************!
143147
! RUN !

module_04_errors.madx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,5 @@ call, file="modules/submodule_04a_preparation.madx";
1212
call, file="modules/submodule_04b_alignsep.madx";
1313
call, file="modules/submodule_04c_errortables.madx";
1414
call, file="modules/submodule_04d_efcomp.madx";
15-
16-
select, flag=error, clear;
17-
select, flag=error, pattern=".";
18-
esave, file="error_all.tfs";
19-
print, text="===============================================";
20-
print, text="====== OPTICS PARAMETERS: AFTER ERRORS ======";
21-
print, text="===============================================";
22-
call, file="tools/get_optics_params.madx";
23-
2415
call, file="modules/submodule_04e_correction.madx";
2516
call, file="modules/submodule_04f_final.madx";
26-
27-
print, text="==================================================";
28-
print, text="====== OPTICS PARAMETERS: BEFORE MATCHING ======";
29-
print, text="==================================================";
30-
call, file="tools/get_optics_params.madx";

pymask/madpoint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def __init__(self, name, mad, use_twiss=True, use_survey=True):
2626
if use_survey:
2727
survey = mad.table.survey
2828
names = survey.name
29+
# patch for this issue https://github.com/hibtc/cpymad/issues/91
30+
for ii, nn in enumerate(names):
31+
if not nn.endswith(':1'):
32+
names[ii] = nn+':1'
2933

3034
idx = np.where(names == name)[0][0]
3135

python_examples/hl_lhc_collisions_python/000_pymask.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,21 @@
8787

8888
# Attach beam to sequences
8989
mad.globals.nrj = configuration['beam_energy_tot']
90-
gamma_rel = configuration['beam_energy_tot']/mad.globals.pmass
90+
particle_type = 'proton'
91+
92+
if 'beam_mass' in configuration.keys():
93+
beam_mass = configuration['beam_mass']
94+
particle_type = 'ion'
95+
else:
96+
beam_mass = mad.globals.pmass # proton mass
97+
98+
if 'beam_charge' in configuration.keys():
99+
beam_charge = configuration['beam_charge']
100+
particle_type = 'ion'
101+
else:
102+
beam_charge = 1.
103+
104+
gamma_rel = (beam_charge*configuration['beam_energy_tot'])/beam_mass
91105
for ss in mad.sequence.keys():
92106
# bv and bv_aux flags
93107
if ss == 'lhcb1':
@@ -100,14 +114,16 @@
100114

101115
mad.globals['bv_aux'] = ss_bv_aux
102116
mad.input(f'''
103-
beam, particle=proton,sequence={ss},
104-
energy={configuration['beam_energy_tot']},
117+
beam, particle={particle_type},sequence={ss},
118+
energy={configuration['beam_energy_tot']*beam_charge},
105119
sigt={configuration['beam_sigt']},
106120
bv={ss_beam_bv},
107121
npart={configuration['beam_npart']},
108122
sige={configuration['beam_sige']},
109123
ex={configuration['beam_norm_emit_x'] * 1e-6 / gamma_rel},
110124
ey={configuration['beam_norm_emit_y'] * 1e-6 / gamma_rel},
125+
mass={beam_mass},
126+
charge={beam_charge},
111127
''')
112128

113129

@@ -177,6 +193,8 @@
177193
if mode=='b4_without_bb':
178194
print('Leveling not working in this mode!')
179195
else:
196+
if particle_type == 'ion': # the legacy macro for BB have been checked but not maintained
197+
raise ValueError
180198
# Luminosity levelling
181199
vars_for_legacy_level = ['lumi_ip8',
182200
'nco_IP1', 'nco_IP2', 'nco_IP5', 'nco_IP8']
@@ -267,6 +285,13 @@
267285
save_twiss_files=save_intermediate_twiss,
268286
check_betas_at_ips=check_betas_at_ips, check_separations_at_ips=False)
269287

288+
# For B1, to be generalized for B4
289+
if 'filling_scheme_json' in configuration.keys():
290+
filling_scheme_json = configuration['filling_scheme_json']
291+
bunch_to_track = configuration['bunch_to_track']
292+
bb_schedule_to_track_b1 = ost.create_bb_shedule_to_track(
293+
filling_scheme_json,bunch_to_track, beam='1')
294+
bb_dfs['b1']=ost.filter_bb_df(bb_dfs['b1'],bb_schedule_to_track_b1)
270295

271296
##################################################
272297
# Select mad instance for tracking configuration #
@@ -508,3 +533,14 @@
508533
closed_orbit_method='from_mad',
509534
pickle_lines_in_folder=pysix_fol_name,
510535
skip_mad_use=True)
536+
537+
#############################
538+
# Save final twiss #
539+
#############################
540+
541+
mad_track.globals.on_bb_charge = 0
542+
mad_track.twiss()
543+
tdf = mad_track.get_twiss_df('twiss')
544+
sdf = mad_track.get_summ_df('summ')
545+
tdf.to_parquet('final_twiss_BBOFF.parquet')
546+
sdf.to_parquet('final_summ_BBOFF.parquet')

python_examples/hl_lhc_collisions_python/checks_and_doc/t003_fc_to_fort.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77
'../../../examples/hl_lhc_collision_nobb_b4']
88

99
for sixtrack_input_folder in folder_list:
10-
for iff in [2,8,16,34]:
11-
os.system(f"rm {sixtrack_input_folder}/fort.{iff}")
12-
try:
13-
shutil.copy(sixtrack_input_folder + f"/fc.{iff}",
14-
sixtrack_input_folder + f"/fort.{iff}")
15-
except Exception:
16-
print(f"/fc.{iff} not found!")
10+
print(sixtrack_input_folder)
11+
try:
12+
for iff in [2,8,16,34]:
13+
os.system(f"rm {sixtrack_input_folder}/fort.{iff}")
14+
try:
15+
shutil.copy(sixtrack_input_folder + f"/fc.{iff}",
16+
sixtrack_input_folder + f"/fort.{iff}")
17+
except Exception:
18+
print(f"/fc.{iff} not found!")
1719

18-
with open(sixtrack_input_folder + "/fort.3", "w") as fout:
19-
with open("fort_parts/fort_beginning.3", "r") as fid_fort3b:
20-
fout.write(fid_fort3b.read())
21-
with open(sixtrack_input_folder + "/fc.3", "r") as fid_fc3:
22-
fout.write(fid_fc3.read())
23-
with open("fort_parts/fort_end.3", "r") as fid_fort3e:
24-
fout.write(fid_fort3e.read())
20+
with open(sixtrack_input_folder + "/fort.3", "w") as fout:
21+
with open("fort_parts/fort_beginning.3", "r") as fid_fort3b:
22+
fout.write(fid_fort3b.read())
23+
with open(sixtrack_input_folder + "/fc.3", "r") as fid_fc3:
24+
fout.write(fid_fc3.read())
25+
with open("fort_parts/fort_end.3", "r") as fid_fort3e:
26+
fout.write(fid_fort3e.read())
27+
except Exception as e:
28+
print('Skipped...')
29+
print(e)
30+
31+
print('Ended.')

python_examples/hl_lhc_collisions_python/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,17 @@
158158
'par_correct_for_D2' : 0,
159159
'par_correct_for_MCBX' : 0,
160160
'par_on_errors_LHC' : 1,
161+
'par_off_errors_Q4_inIP15' : 0,
162+
'par_off_errors_Q5_inIP15' : 0,
161163
'par_on_errors_MBH' : 1,
162-
'par_on_errors_Q5' : 1,
163164
'par_on_errors_Q4' : 1,
164165
'par_on_errors_D2' : 1,
165166
'par_on_errors_D1' : 1,
166167
'par_on_errors_IT' : 1,
167168
'par_on_errors_MCBRD' : 0,
168169
'par_on_errors_MCBXF' : 0,
170+
'par_on_errors_NLC' : 0,
171+
'par_write_errortable' : 1,
169172
},
170173

171174
# Parameters for legacy beam-beam macros (not used in default modes)

python_examples/hl_lhc_collisions_python/optics_specific_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def build_sequence(mad, beam):
4444
call, file="errors/HL-LHC/install_MQXF_fringenl.madx"; ! adding fringe place holder
4545
call, file="errors/HL-LHC/install_MCBXFAB_errors.madx"; ! adding D1 corrector placeholders in IR1/5 (for errors)
4646
call, file="errors/HL-LHC/install_MCBRD_errors.madx"; ! adding D2 corrector placeholders in IR1/5 (for errors)
47+
call, file="errors/HL-LHC/install_NLC_errors.madx"; ! adding non-linear corrector placeholders in IR1/5 (for errors)
4748
4849
!Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors)
4950
if (mylhcbeam<3){

python_examples/ions_python/000_pymask.py

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,21 @@
8787

8888
# Attach beam to sequences
8989
mad.globals.nrj = configuration['beam_energy_tot']
90-
gamma_rel = (configuration['beam_charge']*configuration['beam_energy_tot'])/configuration['beam_mass']
90+
particle_type = 'proton'
91+
92+
if 'beam_mass' in configuration.keys():
93+
beam_mass = configuration['beam_mass']
94+
particle_type = 'ion'
95+
else:
96+
beam_mass = mad.globals.pmass # proton mass
97+
98+
if 'beam_charge' in configuration.keys():
99+
beam_charge = configuration['beam_charge']
100+
particle_type = 'ion'
101+
else:
102+
beam_charge = 1.
103+
104+
gamma_rel = (beam_charge*configuration['beam_energy_tot'])/beam_mass
91105
for ss in mad.sequence.keys():
92106
# bv and bv_aux flags
93107
if ss == 'lhcb1':
@@ -100,16 +114,16 @@
100114

101115
mad.globals['bv_aux'] = ss_bv_aux
102116
mad.input(f'''
103-
beam, particle=ion,sequence={ss},
104-
energy={configuration['beam_energy_tot']*configuration['beam_charge']},
117+
beam, particle={particle_type},sequence={ss},
118+
energy={configuration['beam_energy_tot']*beam_charge},
105119
sigt={configuration['beam_sigt']},
106120
bv={ss_beam_bv},
107121
npart={configuration['beam_npart']},
108122
sige={configuration['beam_sige']},
109123
ex={configuration['beam_norm_emit_x'] * 1e-6 / gamma_rel},
110124
ey={configuration['beam_norm_emit_y'] * 1e-6 / gamma_rel},
111-
mass = {configuration['beam_mass']},
112-
charge={configuration['beam_charge']},
125+
mass={beam_mass},
126+
charge={beam_charge},
113127
''')
114128

115129

@@ -179,45 +193,14 @@
179193
if mode=='b4_without_bb':
180194
print('Leveling not working in this mode!')
181195
else:
182-
# Modified module 2 for offset levelling in IP1,2,5,8
183-
vars_for_legacy_level = ['lumi_ip8','lumi_ip5', 'lumi_ip1', 'lumi_ip2',
196+
if particle_type == 'ion': # the legacy macro for BB have been checked but not maintained
197+
raise ValueError
198+
# Luminosity levelling
199+
vars_for_legacy_level = ['lumi_ip8',
184200
'nco_IP1', 'nco_IP2', 'nco_IP5', 'nco_IP8']
185201
mad.set_variables_from_dict({
186202
'par_'+kk: configuration[kk] for kk in vars_for_legacy_level})
187-
mad.input('''
188-
print, text="";
189-
print, text="";
190-
print, text="+++++++++++++++++++++++++++++++";
191-
print, text="++ START MODULE 2: LEVELLING ++";
192-
print, text="+++++++++++++++++++++++++++++++";
193-
print, text="";
194-
print, text="";
195-
196-
call, file="beambeam_macros/macro_bb.madx"; ! macros for beam-beam
197-
198-
exec, DEFINE_BB_PARAM; !Define main beam-beam parameters
199-
200-
!Switch on Xscheme in precollision
201-
on_disp:=0;
202-
halo1=0;halo2=0;halo5=0;halo8=0; !halo collision at 5 sigma's in Alice
203-
!number of collision/turn at IP1/2/5/8
204-
nco_IP1 = par_nco_IP1;
205-
nco_IP5 = par_nco_IP5;
206-
nco_IP2 = par_nco_IP2;
207-
nco_IP8 = par_nco_IP8;
208-
exec, LEVEL_PARALLEL_OFFSET_FOR(par_lumi_ip8, 8); value,halo8;
209-
exec, LEVEL_PARALLEL_OFFSET_FOR(par_lumi_ip1, 1); value,halo1;
210-
exec, LEVEL_PARALLEL_OFFSET_FOR(par_lumi_ip2, 2); value,halo2;
211-
exec, LEVEL_PARALLEL_OFFSET_FOR(par_lumi_ip5, 5); value,halo5;
212-
!Redefine the on_sep's accordingly
213-
exec, CALCULATE_XSCHEME(halo1,halo2,halo5,halo8);
214-
! Saving new crossing scheme with separation
215-
on_disp=on_dispaux; ! reset on_disp before saving
216-
exec, crossing_save;
217-
218-
if (mylhcbeam==1) { use, sequence=lhcb1; } else { use, sequence=lhcb2; };
219-
220-
''')
203+
mad.input("call, file='modules/module_02_lumilevel.madx';")
221204
else:
222205
print('Start pythonic leveling:')
223206
ost.lumi_control(mad, twiss_dfs, configuration, knob_names)
@@ -303,10 +286,12 @@
303286
check_betas_at_ips=check_betas_at_ips, check_separations_at_ips=False)
304287

305288
# For B1, to be generalized for B4
306-
filling_scheme_json = configuration['filling_scheme_json']
307-
bunch_to_track = configuration['bunch_to_track']
308-
bb_schedule_to_track_b1 = ost.create_bb_shedule_to_track(filling_scheme_json,bunch_to_track, beam='1')
309-
bb_dfs['b1']=ost.filter_bb_df(bb_dfs['b1'],bb_schedule_to_track_b1)
289+
if 'filling_scheme_json' in configuration.keys():
290+
filling_scheme_json = configuration['filling_scheme_json']
291+
bunch_to_track = configuration['bunch_to_track']
292+
bb_schedule_to_track_b1 = ost.create_bb_shedule_to_track(
293+
filling_scheme_json,bunch_to_track, beam='1')
294+
bb_dfs['b1']=ost.filter_bb_df(bb_dfs['b1'],bb_schedule_to_track_b1)
310295

311296
##################################################
312297
# Select mad instance for tracking configuration #
@@ -549,7 +534,9 @@
549534
pickle_lines_in_folder=pysix_fol_name,
550535
skip_mad_use=True)
551536

552-
##### Save final twiss
537+
#############################
538+
# Save final twiss #
539+
#############################
553540

554541
mad_track.globals.on_bb_charge = 0
555542
mad_track.twiss()

0 commit comments

Comments
 (0)