Files
OpticsTools/generateMatchSettings.py
2025-05-15 17:49:45 +02:00

94 lines
5.5 KiB
Python

import json
varypar={'min:':-1e-6,'max:':1e-6,'preset':0}
def MatchStep(ref,id,end, dest,sequence='SwissFEL',saveTwiss=None):
match={'Reference':ref,'MatchID':id,'End':end, 'Destination':dest,'Sequence':sequence,'Save':saveTwiss}
return match
def MatchParameter(var0,tar0):
var={key: varypar for key in var0}
tar= tar0
return {'Variable':var,'Target':tar}
def MatchReference(loc,twiss):
match ={'Location': loc, 'Twiss': twiss}
return match
path ="Settings/"
label='Reference'
order = []
order.append(MatchStep('Start', 'Laser Heater','SINLH02','SATBD01'))
order.append(MatchStep(None, 'SINSB04', None,'SATBD01','SINSB04',True))
order.append(MatchStep('Laser Heater', 'Match to SINSB04','SINSB04','SATBD01'))
order.append(MatchStep('Laser Heater', 'Bunch Compressor 1','SINDI02','SATBD01'))
order.append(MatchStep(None, 'Linac 1', None,'SATBD01','S10CB02',True))
order.append(MatchStep('Bunch Compressor 1', 'Match to Linac 1','S10CB02','SATBD01'))
order.append(MatchStep('Bunch Compressor 1', 'End of Linac 1','S10BC01','SATBD01'))
order.append(MatchStep('Bunch Compressor 1', 'Bunch Compressor 2','S10MA01','SATBD01'))
order.append(MatchStep(None, 'Linac 2', None,'SATBD01',['S20CB01','S20CB02'],True))
order.append(MatchStep('Bunch Compressor 2', 'Match to Linac 2','S20CB04','SATBD01'))
order.append(MatchStep(None, 'Resonant Kicker',None,'SATBD01','S20SY02'))
parameter={}
var = ['SINLH01-MQUA020', 'SINLH01-MQUA040','SINLH01-MQUA050','SINLH01-MQUA070','SINLH02-MQUA010']
parameter['Laser Heater'] = MatchParameter(var,[{'Reference':'Laser Heater'}])
var = ['SINSB04-MQUA130','SINSB04-MQUA230']
parameter['SINSB04'] = MatchParameter(var,[{'Fixed':{'Location':'#e','Twiss':{'MUX':0.2,'MUY':0.2}}}])
var = ['SINLH02-MQUA410','SINLH03-MQUA030','SINLH03-MQUA040','SINLH03-MQUA060','SINLH03-MQUA080','SINSB03-MQUA130']
parameter['Match to SINSB04']=MatchParameter(var,[{'Save':{'Location':'sinsb04$start','SaveID':'SINSB04'}}])
var = ['SINBC01-MQUA020','SINBC01-MQUA050','SINBC01-MQUA070','SINBC01-MQUA090','SINBC01-MQUA110','SINDI01-MQUA020','SINDI01-MQUA070']
parameter['Bunch Compressor 1']=MatchParameter(var,[{'Reference':'Bunch Compressor 1'},
{'Fixed':{'Location':'sinbc02.mbnd400','Limit':1,'Twiss':{'betax':5.1,'betay':100}}},
{'Fixed':{'Location':'sinbc01.mqua110$end','Limit':1,'Twiss':{'betax':100}}}])
var = ['S10CB02-MQUA230','S10CB02-MQUA430']
parameter['Linac 1'] = MatchParameter(var,[{'Fixed':{'Location':'#e','Twiss':{'MUX':0.1883,'MUY':0.1883}}}])
var = ['S10CB01-MQUA230','S10CB01-MQUA430','SINDI02-MQUA020','SINDI02-MQUA030','SINDI02-MQUA050','SINDI02-MQUA060','SINDI02-MQUA090']
parameter['Match to Linac 1']=MatchParameter(var,[{'Save':{'Location':'s10cb02$start','SaveID':'Linac 1'}}])
var = ['S10CB07-MQUA430','S10CB08-MQUA230','S10CB08-MQUA430','S10CB09-MQUA230']
parameter['End of Linac 1']=MatchParameter(var,[{'Fixed':{'Location':'s10bc01.mqua020$start','Twiss':{'betax':4.88,'betay':16.11,'alphax':0.5546,'alphay':-1.81}}}])
var = ['S10BC01-MQUA020','S10BC01-MQUA040','S10BC01-MQUA060','S10BC01-MQUA080','S10BC01-MQUA100']
parameter['Bunch Compressor 2']=MatchParameter(var,[{'Reference':'Bunch Compressor 2'}])
var = ['S20CB02-MQUA430','S20CB02-MQUA430']
parameter['Linac 2'] = MatchParameter(var,[{'Fixed':{'Location':'#e','Twiss':{'MUX':0.2,'MUY':0.2}}}])
var = ['S10MA01-MQUA020','S10MA01-MQUA050','S10MA01-MQUA070','S10MA01-MQUA110','S10MA01-MQUA130']
parameter['Match to Linac 2']=MatchParameter(var,[{'Save':{'Location':'s20cb01$start','SaveID':'Linac 2'}}])
var = ['S20SY02-MQUA070','S20SY02-MQUA100','S20SY02-MQUA140','S20SY02-MQUA180','S20SY02-MKDC010','S20SY02-MKDC020','S20SY02-MKDC030','S20SY02-MKDC040','S20SY02-MKDC050']
parameter['Resonant Kicker']=MatchParameter(var,[{'Script':{'Location':'File','Script':'Scripts/switchyard.madx'}}])
dependence={}
dependence['SINSB04-MQUA230']=['SINSB03-MQUA230']
dependence['S10CB02-MQUA230']=['S10DI01-MQUA120'] + ['S10CB%2.2d-MQUA430' % i for i in range(3,9)]
dependence['S10CB02-MQUA430']=['S10CB%2.2d-MQUA230' % i for i in range(3,9)]
dependence['S20CB01-MQUA430']=['S20CB03-MQUA430']
reference={}
reference['Start'] = MatchReference('start',{'betax':29.971,'alphax':0.003,'betay':26.00,'alphay':-0.288})
reference['Laser Heater'] = MatchReference('sinlh02.mqua410$start',{'betax': 11.2, 'alphax': 3.2,'betay': 0.8, 'alphay': 0.75,})
reference['Bunch Compressor 1'] = MatchReference('sindi02.mqua020$start',{'betax': 11.1557, 'alphax': -1.17,'betay': 50, 'alphay': 0.})
reference['Bunch Compressor 2'] = MatchReference('s10ma01.mqua020$start',{'betax': 6.14, 'alphax': -0.83,'betay': 22.86, 'alphay': -1.18})
reference['Switchyard'] = MatchReference('s20sy02.mqua070$start',{'betax': 12.99, 'alphax': 3.7011,'betay': 46.339, 'alphay': -6.501})
reference['Linac3'] = MatchReference('s30cb10.mqua430$start',{'betax': 8.83,'alphax': 0.548,'betay': 30.44,'alphay': -1.866})
reference['Aramis Stopper'] = MatchReference('sarma01.mqua010$start',{'betax': 2.304, 'alphax': -1.4045, 'betay': 25.929, 'alphay': -6.363})
reference['Athos HERO'] = MatchReference('satdi01.mqua250$start',{'betax': 35.76, 'alphax': -1.166,'betay': 24.087, 'alphay': 0.648})
reference['Athos Deflector'] = MatchReference('satbd01.mqua010$start',{'betax': 50, 'alphax': 0,'betay': 50, 'alphay': 0})
settings={'Label':label,'Order':order,'Dependence':dependence,'Reference':reference,'Parameter':parameter}
with open(path+label+'.json', 'w', encoding='utf-8') as f:
json.dump(settings, f, ensure_ascii=False, indent=4)