Initial tracking done, needs check for other twiss parameters in user defined

This commit is contained in:
2026-01-12 13:29:22 +01:00
parent 39ae60b9ec
commit 608c7286b7
4 changed files with 50 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ class MatchMaker:
def __init__(self):
self.matchlist={'Reference-SwissFEL':'Scripts/Reference-SwissFEL','SwissFEL+':'Scripts/SFPlus'}
self.referencePoints={}
self.variables={}
self.scriptdir = None
def initScripts(self,target):
self.scriptdir = self.matchlist[target]
@@ -22,6 +24,7 @@ class MatchMaker:
def parseReferencePoints(self):
file = self.scriptdir+'/initTwiss.madx'
self.referencePoints.clear()
self.variables.clear()
with open(file,'r') as f:
lines = f.readlines()
for line in lines:
@@ -31,10 +34,18 @@ class MatchMaker:
fields_all = tags[0].split(',')
fields = [fld.split(';')[0].strip() for fld in fields_all if "=" in fld]
self.referencePoints[location] = {twiss.split('=')[0].strip().lower():float(twiss.split('=')[1].strip()) for twiss in fields}
if 'Description:' in line:
tags = line.split('Description:')
description = tags[1].strip()
flds=tags[0].split('=')
name = flds[0].split(':')[0].strip()
val = float(flds[1].split(';')[0].strip())
self.variables[name] = {'Value':val,'Description':description}
print('Found Variable',name,'with value',val)
print('##### Reference Twiss values parsed')
def match(self, om, Injector=True, Athos = True, Aramis = False, Porthos = False):
def match(self, om, variables = None, Injector=True, Athos = True, Aramis = False, Porthos = False):
if Athos:
target = 'SATBD01'
@@ -46,6 +57,8 @@ class MatchMaker:
madx.updateLattice(om, target) # write lattice
madx.commonHeader('SwissFEL', '#s/#e', None) # sets header
madx.madx.call(self.scriptdir + '/initTwiss.madx')
if not variables is None:
madx.definePresets(variables)
if Injector:
madx.madx.call(self.scriptdir+'/matchInjector.madx', chdir=True)
self.updateOnlineModel(om,madx.madx, 's[i1].*k1|s20sy01.*k1')