3737LOG = logging .getLogger (__name__ ) # setup in main()
3838LOG_LEVEL = logging .DEBUG
3939
40- ACC_MODELS = "acc-models-lhc"
40+ ACC_MODELS : str = "acc-models-lhc"
4141
42- PATHS = {
43- "db5" : Path ("/afs/cern.ch/eng/lhc/optics/V6.503" ),
44- "optics2016" : Path ("/afs/cern.ch/eng/lhc/optics/runII/2016" ),
42+ PATHS : dict [str , Path ] = {
4543 "optics2018" : Path ("/afs/cern.ch/eng/lhc/optics/runII/2018" ),
4644 "optics_repo" : Path ("/afs/cern.ch/eng/acc-models/lhc" ),
4745 ACC_MODELS : Path (ACC_MODELS ),
@@ -62,45 +60,6 @@ def pathstr(key: str, *args: str) -> str:
6260 return str (PATHS [key ].joinpath (* args ))
6361
6462
65- def get_optics_path (year : int , name : str | Path ):
66- """Get optics by name, i.e. a collection of optics path-strings to the optics files.
67-
68- Args:
69- year (int): Year of the optics
70- name (str, Path): Name for the optics or a path to the optics file.
71-
72- Returns:
73- str: Path to the optics file.
74- """
75- if isinstance (name , Path ):
76- return str (name )
77-
78- # Predefined optics paths ---
79- optics_map = {
80- 2018 : {
81- 'inj' : pathstr ("optics2018" , "PROTON" , "opticsfile.1" ),
82- 'flat6015' : pathstr ("optics2018" , 'MDflatoptics2018' , 'opticsfile_flattele60cm.21' ),
83- 'round3030' : pathstr ("optics2018" , "PROTON" , "opticsfile.22_ctpps2" ),
84- },
85- 2022 : {
86- 'round3030' : pathstr (ACC_MODELS , "strengths" , "ATS_Nominal" , "2022" , "squeeze" , "ats_30cm.madx" )
87- }
88- }
89- return optics_map [year ][name ]
90-
91-
92- def get_wise_path (seed : int ):
93- """Get the wise errordefinition file by seed-number.
94-
95- Args:
96- seed (int): Seed for the error realization.
97-
98- Returns:
99- str: Path to the wise errortable file.
100- """
101- return pathstr ('wise' , f"WISE.errordef.{ seed :04d} .tfs" )
102-
103-
10463def drop_allzero_columns (df : TfsDataFrame , keep : Sequence = ()) -> TfsDataFrame :
10564 """Drop columns that contain only zeros, to save harddrive space.
10665
@@ -145,9 +104,8 @@ class LHCBeam:
145104 beam : int
146105 outputdir : Path
147106 xing : dict
148- optics : str
107+ optics : str | Path | None
149108 year : int = 2018
150- thin : bool = False
151109 tune_x : float = 62.28
152110 tune_y : float = 60.31
153111 chroma : float = 3
@@ -176,6 +134,15 @@ def __post_init__(self):
176134 # Define Sequence to use
177135 self .seq_name , self .seq_file , self .bv_flag = get_lhc_sequence_filename_and_bv (self .beam , accel = "lhc" if self .year < 2020 else "hllhc" ) # `hllhc` just for naming of the sequence file, i.e. without _as_built
178136
137+ self .path_to_use = "optics2018"
138+ if self .year > 2019 : # after 2019, use acc-models
139+ self .path_to_use = ACC_MODELS
140+
141+ acc_models_path = PATHS [ACC_MODELS ]
142+ if acc_models_path .exists ():
143+ acc_models_path .unlink ()
144+ acc_models_path .symlink_to (pathstr ("optics_repo" , str (self .year )))
145+
179146 # Output Helper ---
180147 def output_path (self , type_ : str , output_id : str , dir_ : Path | None = None , suffix : str = ".tfs" ) -> Path :
181148 """Returns the output path for standardized tfs names in the default output directory.
@@ -303,30 +270,13 @@ def setup_machine(self):
303270 Initialized the beam and applies optics, crossing."""
304271 self .reinstate_loggers ()
305272 madx = self .madx # shorthand
306- mvars = madx .globals # shorthand
307273
308274 # Load Macros
309- madx .call (pathstr ("optics2018" , "toolkit" , "macro.madx" ))
275+ madx .call (pathstr (self . path_to_use , "toolkit" , "macro.madx" ))
310276
311277 # Lattice Setup ---------------------------------------
312278 # Load Sequence
313- if self .year > 2019 : # after 2019, use acc-models
314- acc_models_path = PATHS [ACC_MODELS ]
315- if acc_models_path .exists ():
316- acc_models_path .unlink ()
317- acc_models_path .symlink_to (pathstr ("optics_repo" , str (self .year )))
318- madx .call (pathstr (ACC_MODELS , self .seq_file ))
319- else :
320- madx .call (pathstr ("optics2018" , self .seq_file ))
321-
322- # Slice Sequence
323- if self .thin :
324- mvars .slicefactor = 4
325- madx .beam ()
326- madx .call (pathstr ("optics2018" , "toolkit" , "myslice.madx" ))
327- madx .beam ()
328- madx .use (sequence = self .seq_name )
329- madx .makethin (sequence = self .seq_name , style = "teapot" , makedipedge = True )
279+ madx .call (pathstr (self .path_to_use , self .seq_file ))
330280
331281 # Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors)
332282 madx .seqedit (sequence = self .seq_name )
@@ -335,10 +285,7 @@ def setup_machine(self):
335285 madx .endedit ()
336286
337287 # Define Optics and make beam
338- madx .call (get_optics_path (self .year , self .optics ))
339- if self .optics == 'inj' :
340- mvars .NRJ = 450.000 # not defined in injection optics.1 but in the others
341-
288+ madx .call (str (self .optics ))
342289 madx .beam (sequence = self .seq_name , bv = self .bv_flag ,
343290 energy = "NRJ" , particle = "proton" , npart = self .n_particles ,
344291 kbunch = 1 , ex = self .emittance , ey = self .emittance )
0 commit comments