|
87 | 87 |
|
88 | 88 | # Attach beam to sequences |
89 | 89 | 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 |
91 | 105 | for ss in mad.sequence.keys(): |
92 | 106 | # bv and bv_aux flags |
93 | 107 | if ss == 'lhcb1': |
|
100 | 114 |
|
101 | 115 | mad.globals['bv_aux'] = ss_bv_aux |
102 | 116 | 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}, |
105 | 119 | sigt={configuration['beam_sigt']}, |
106 | 120 | bv={ss_beam_bv}, |
107 | 121 | npart={configuration['beam_npart']}, |
108 | 122 | sige={configuration['beam_sige']}, |
109 | 123 | ex={configuration['beam_norm_emit_x'] * 1e-6 / gamma_rel}, |
110 | 124 | 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}, |
113 | 127 | ''') |
114 | 128 |
|
115 | 129 |
|
|
179 | 193 | if mode=='b4_without_bb': |
180 | 194 | print('Leveling not working in this mode!') |
181 | 195 | 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', |
184 | 200 | 'nco_IP1', 'nco_IP2', 'nco_IP5', 'nco_IP8'] |
185 | 201 | mad.set_variables_from_dict({ |
186 | 202 | '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';") |
221 | 204 | else: |
222 | 205 | print('Start pythonic leveling:') |
223 | 206 | ost.lumi_control(mad, twiss_dfs, configuration, knob_names) |
|
303 | 286 | check_betas_at_ips=check_betas_at_ips, check_separations_at_ips=False) |
304 | 287 |
|
305 | 288 | # 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) |
310 | 295 |
|
311 | 296 | ################################################## |
312 | 297 | # Select mad instance for tracking configuration # |
|
549 | 534 | pickle_lines_in_folder=pysix_fol_name, |
550 | 535 | skip_mad_use=True) |
551 | 536 |
|
552 | | -##### Save final twiss |
| 537 | +############################# |
| 538 | +# Save final twiss # |
| 539 | +############################# |
553 | 540 |
|
554 | 541 | mad_track.globals.on_bb_charge = 0 |
555 | 542 | mad_track.twiss() |
|
0 commit comments