You need to sign in or sign up before continuing.
Newer
Older
Classes and functions for TraceWin
- Note for clean-up
* Old LATTICE and MATCH classes can be deleted once trajectory
correction is established with new classes.
from __future__ import print_function
from itertools import chain
from subprocess import check_output
"""
"""
def __init__(self, file_name_lat, file_name_fmap=[], freq=352.21, gamma=1.0):
"""
:param file_name_lat: name of lattice file
:param file_name_fmap: list of field map file(-s)
:type file_name_fmap: list or str
:param freq: RF frequency
:param gamma: relativistic gamma
if isinstance(file_name_fmap, str):
file_name_fmap = [file_name_fmap]
"DRIFT": lib_tw_elem.DRIFT,
"QUAD": lib_tw_elem.QUAD,
"THIN_STEERING": lib_tw_elem.THIN_STEERING,
"GAP": lib_tw_elem.GAP,
"DTL_CEL": lib_tw_elem.DTL_CEL,
"BEND": lib_tw_elem.BEND,
"EDGE": lib_tw_elem.EDGE,
"APERTURE": lib_tw_elem.APERTURE,
"DIAG_POSITION": lib_tw_elem.DIAG_POSITION,
"STEERER": lib_tw_elem.STEERER,
"CHOPPER": lib_tw_elem.CHOPPER,
"ADJUST": lib_tw_elem.ADJUST,
"FREQ": lib_tw_elem.FREQ,
"MARKER": lib_tw_elem.MARKER,
"ERROR_BEAM_STAT": lib_tw_elem.ERROR_BEAM_STAT,
"ERROR_BEAM_DYN": lib_tw_elem.ERROR_BEAM_DYN,
"ERROR_QUAD_NCPL_STAT": lib_tw_elem.ERROR_QUAD_NCPL_STAT,
"ERROR_QUAD_CPL_STAT": lib_tw_elem.ERROR_QUAD_CPL_STAT,
"ERROR_CAV_NCPL_STAT": lib_tw_elem.ERROR_CAV_NCPL_STAT,
"ERROR_CAV_NCPL_DYN": lib_tw_elem.ERROR_CAV_NCPL_DYN,
"ERROR_CAV_CPL_STAT": lib_tw_elem.ERROR_CAV_CPL_STAT,
"ERROR_CAV_CPL_DYN": lib_tw_elem.ERROR_CAV_CPL_DYN,
"ERROR_STAT_FILE": lib_tw_elem.ERROR_STAT_FILE,
"ERROR_DYN_FILE": lib_tw_elem.ERROR_DYN_FILE,
name_fmap = ".".join(
file_name_fmap_i.split("/")[-1].split(".")[:-1]
) # Remove / and extension
dic_fmap[name_fmap] = lib_tw_elem.FIELD_MAP_DATA(file_name_fmap_i)
# In case the lattice file is in a different folder:
_update_field_map_dict(dic_fmap, basefolder)
# Go through the lat file
with open(file_name_lat) as file:
lin = lin.partition(";")[0] # Remove comment
if lin.split() != []: # Remove empty line
if ":" in lin:
name = lin.partition(":")[0].split()[0]
typ = lin.partition(":")[2].split()[0].upper()
para = lin.partition(":")[2].split()[1:]
name = ""
typ = lin.split()[0].upper()
para = lin.split()[1:]
lst.append(lib_tw_elem.FIELD_MAP(name, typ, para, dic_fmap))
elif typ in dic_cls.keys():
lst.append(dic_cls[typ](name, typ, para))
elif "DIAG" in typ:
# in case of field map path, update dictionary with new path
if typ == "FIELD_MAP_PATH":
_update_field_map_dict(dic_fmap, para[0])
self.gamma = gamma
self.freq = freq
self.lst = lst
self.fmap = dic_fmap # Maybe not needed ...
# Assign idx, idx_elem, s, freq, apt
self.update_idx()
Get correctors associated to corrector index i
if found:
# WARNING I worry that there could be an inactive comment/element between the ADJUST and actual corrector
logging.debug(
"Found element {} for corrector family {}".format(element.typ, i)
)
correctors.append(element)
if element.typ in ["ADJUST", "ADJUST_STEERER"]:
if int(element.para[0]) == i: # next element is the corrector
found = True
Get a TraceWin index number
Note: We start counting from 0, TW starts from 1
for element in self.lst:
return element
def get_steerer_for(self, idx_elem):
"""
Returns the steerer object for an element (e.g. quad)
for element in self.lst:
if element.idx_elem + 1 == idx_elem:
if previous.typ == "STEERER":
return previous
return None
def update_idx(self):
# Assign/update idx, idx_elem, s, freq
for i in range(len(self.lst)):
if i == 0:
self.lst[0].idx = -1
self.lst[0].idx_elem = -1
self.lst[0].s = 0.0
self.lst[0].freq = self.freq
if i != 0:
self.lst[i].idx = self.lst[i - 1].idx
self.lst[i].idx_elem = self.lst[i - 1].idx_elem
self.lst[i].s = self.lst[i - 1].s
self.lst[i].freq = self.lst[i - 1].freq
# Assign apt (using apt of the previous elem for diag elem)
for i in range(len(self.lst)):
try:
Loading
Loading full blame...