Skip to content

Commit 081534e

Browse files
committed
Merge branch 'feature/studies' into develop
This was more of a feature/study-tripleterrors than feature/studies, but we learn from experience. To be merged, destroyed and the next one will be more accurate.
2 parents 649928f + d176613 commit 081534e

File tree

8 files changed

+882
-12
lines changed

8 files changed

+882
-12
lines changed

pyhdtoolkit/cpymadtools/lattice_generators.py

Lines changed: 196 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LatticeGenerator:
1515
def generate_base_cas_lattice() -> str:
1616
"""
1717
Simple function to help unclutter the notebook.
18-
:return: string you can input into your cpymadtools instance.
18+
:return: string you can input into your `cpymad.madx.Madx` object.
1919
"""
2020
mystring = """
2121
option, -info, -warn;
@@ -86,7 +86,7 @@ def generate_base_cas_lattice() -> str:
8686
def generate_onesext_cas_lattice() -> str:
8787
"""
8888
Simple function to help unclutter the notebook.
89-
:return: string you can input into your cpymadtools instance.
89+
:return: string you can input into your `cpymad.madx.Madx` object.
9090
"""
9191
mystring = """
9292
option, -info, -warn;
@@ -174,7 +174,7 @@ def generate_onesext_cas_lattice() -> str:
174174
def generate_oneoct_cas_lattice() -> str:
175175
"""
176176
Simple function to help unclutter the notebook.
177-
:return: string you can input into your cpymadtools instance.
177+
:return: string you can input into your `cpymad.madx.Madx` object.
178178
"""
179179
mystring = """
180180
option, -info, -warn;
@@ -258,6 +258,199 @@ def generate_oneoct_cas_lattice() -> str:
258258
"""
259259
return mystring
260260

261+
@staticmethod
262+
def generate_tripleterrors_study_reference() -> str:
263+
"""
264+
Generate generic script for reference Twiss, to use in a `cpymad.madx.Madx` object.
265+
:return: string you can input into your `cpymad.madx.Madx` object.
266+
"""
267+
script = f"""
268+
!####################### Make macros available #######################
269+
270+
option, -echo, -warn, -info;
271+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/beta_beat.macros.madx";
272+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/lhc.macros.madx";
273+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/hllhc.macros.madx";
274+
275+
title, "HLLHC Triplet TFErrors to Beta-Beating";
276+
277+
!####################### Call optics files #######################
278+
279+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/lhcrunIII.seq";
280+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/main.seq";
281+
call, file = "/afs/cern.ch/eng/lhc/optics/V6.5/errors/Esubroutines.madx";
282+
283+
!####################### Calling modifiers for 15cm optics #######################
284+
285+
call, file = "/afs/cern.ch/eng/lhc/optics/HLLHCV1.3/opt_150_150_150_150.madx";
286+
287+
!####################### Create beam #######################
288+
289+
exec, define_nominal_beams();
290+
291+
!####################### Flatten and set START point at ? #######################
292+
293+
exec, cycle_sequences();
294+
295+
!####################### Default crossing scheme #######################
296+
297+
exec, set_default_crossing_scheme();
298+
299+
!####################### Selecting to use Beam 1 #######################
300+
301+
use, period = LHCB1;
302+
303+
!####################### Tune matching and Twiss nominal #######################
304+
305+
option, echo, warn, info;
306+
exec, match_tunes(62.31, 60.32, 1); ! Since we're using beam 1
307+
twiss;
308+
"""
309+
return script
310+
311+
@staticmethod
312+
def generate_tripleterrors_study_tferror_job(rand_seed: str, tf_error: str) -> str:
313+
"""
314+
Generate generic script for tf_error Twiss, to use in a `cpymad.madx.Madx` object.
315+
:param rand_seed: the random seed to provide MAD for the errors distributions.
316+
:param tf_error: the misalignment error value (along the s axis).
317+
:return: string you can input into your `cpymad.madx.Madx` object.
318+
"""
319+
320+
tferror_script = f"""
321+
!####################### Make macros available #######################
322+
323+
option, -echo, -warn, -info;
324+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/beta_beat.macros.madx";
325+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/lhc.macros.madx";
326+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/hllhc.macros.madx";
327+
328+
title, "HLLHC Triplet TFErrors to Beta-Beating";
329+
330+
!####################### Call optics files #######################
331+
332+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/lhcrunIII.seq";
333+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/main.seq";
334+
call, file = "/afs/cern.ch/eng/lhc/optics/V6.5/errors/Esubroutines.madx";
335+
336+
!####################### Calling modifiers for 15cm optics #######################
337+
338+
call, file = "/afs/cern.ch/eng/lhc/optics/HLLHCV1.3/opt_150_150_150_150.madx";
339+
340+
!####################### Create beam #######################
341+
342+
exec, define_nominal_beams();
343+
344+
!####################### Flatten and set START point at ? #######################
345+
346+
exec, cycle_sequences();
347+
348+
!####################### Default crossing scheme #######################
349+
350+
exec, set_default_crossing_scheme();
351+
352+
!####################### Selecting to use Beam 1 #######################
353+
354+
use, period = LHCB1;
355+
356+
!####################### Tune matching and Twiss nominal #######################
357+
358+
option, echo, warn, info;
359+
exec, match_tunes(62.31, 60.32, 1); ! Since we're using beam 1
360+
exec, do_twiss_elements(LHCB1, "./twiss_nominal.dat", 0.0);
361+
362+
!####################### For field errors #######################
363+
364+
eoption, add, seed = {rand_seed}; ! Different seed every time
365+
select, flag=error, clear;
366+
select, flag=error, pattern = ^MQXF.*[RL][15]; ! Only triplets quadrupoles around IP1 and IP5
367+
GCUTR = 3; ! Cut gaussians at 3 sigma
368+
Rr = 0.05; ! Radius for field errors (??)
369+
ON_B2R = 1; ! Activate field errors
370+
B2r = {tf_error}; ! Set field errors magnitude -> Units of B2 error (will be in 1E-4)
371+
exec, SetEfcomp_Q; ! Assign field errors
372+
373+
!####################### Saving errors to file #######################
374+
375+
!esave, file="./errors_file.dat"; ! Will save the errors of chosen type.
376+
377+
!####################### Tune matching and Twiss with errors #######################
378+
379+
exec, match_tunes(62.31, 60.32, 1);
380+
exec, do_twiss_elements(LHCB1, "./twiss_errors.dat", 0.0);
381+
"""
382+
return tferror_script
383+
384+
@staticmethod
385+
def generate_tripleterrors_study_mserror_job(rand_seed: str, ms_error: str) -> str:
386+
"""
387+
Generate generic script for ms_error Twiss, to use in a `cpymad.madx.Madx` object.
388+
:param rand_seed: the random seed to provide MAD for the errors distributions.
389+
:param ms_error: the misalignment error value (along the s axis).
390+
:return: string you can input into your `cpymad.madx.Madx` object.
391+
"""
392+
393+
mserror_script = f"""
394+
!####################### Make macros available #######################
395+
396+
option, -echo, -warn, -info;
397+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/beta_beat.macros.madx";
398+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/lhc.macros.madx";
399+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/madx/lib/hllhc.macros.madx";
400+
401+
title, "HLLHC Triplet MSErrors to Beta-Beating";
402+
403+
!####################### Call optics files #######################
404+
405+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/lhcrunIII.seq";
406+
call, file = "/afs/cern.ch/work/f/fesoubel/public/Beta-Beat.src/model/accelerators/lhc/hllhc1.3/main.seq";
407+
call, file = "/afs/cern.ch/eng/lhc/optics/V6.5/errors/Esubroutines.madx";
408+
409+
!####################### Calling modifiers for 15cm optics #######################
410+
411+
call, file = "/afs/cern.ch/eng/lhc/optics/HLLHCV1.3/opt_150_150_150_150.madx";
412+
413+
!####################### Create beam #######################
414+
415+
exec, define_nominal_beams();
416+
417+
!####################### Flatten and set START point at ? #######################
418+
419+
exec, cycle_sequences();
420+
421+
!####################### Default crossing scheme #######################
422+
423+
exec, set_default_crossing_scheme();
424+
425+
!####################### Selecting to use Beam 1 #######################
426+
427+
use, period = LHCB1;
428+
429+
!####################### Tune matching and Twiss nominal #######################
430+
431+
option, echo, warn, info;
432+
exec, match_tunes(62.31, 60.32, 1); ! Since we're using beam 1
433+
exec, do_twiss_elements(LHCB1, "./twiss_nominal.dat", 0.0);
434+
435+
!####################### For longitudinal missalignments #######################
436+
437+
eoption, add, seed = {rand_seed}; ! Different seed every time
438+
select, flag=error, clear;
439+
select, flag=error, pattern = ^MQXF.*[RL][15]; ! Only triplets quadrupoles around IP1 and IP5
440+
GCUTR = 3; ! Cut gaussians at 3 sigma
441+
ealign, ds := {ms_error} * 1E-3 * TGAUSS(GCUTR); ! Gaussian missalignments in meters
442+
443+
!####################### Saving errors to file #######################
444+
445+
!esave, file="./errors_file.dat"; ! Will save the errors of chosen type.
446+
447+
!####################### Tune matching and Twiss with errors #######################
448+
449+
exec, match_tunes(62.31, 60.32, 1);
450+
exec, do_twiss_elements(LHCB1, "./twiss_errors.dat", 0.0);
451+
"""
452+
return mserror_script
453+
261454

262455
if __name__ == "__main__":
263456
raise NotImplementedError("This module is meant to be imported.")

pyhdtoolkit/studies/__init__.py

Whitespace-only changes.

pyhdtoolkit/studies/triplet_errors/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)