Initial test of matching
This commit is contained in:
@@ -6,7 +6,7 @@ from onlinemodel.core import Facility
|
||||
from onlinemodel.madx import CMadX
|
||||
|
||||
converttwiss= {'betax':'betx','betay':'bety','alphax':'alfx','alphay':'alfy',
|
||||
'etax':'dx','etay':'dy','etapx':'dpx','etapy':'dpy',
|
||||
'etax':'dx','etay':'dy','etapx':'dpx','etapy':'dpy','mux':'mux','muy':'muy',
|
||||
'x':'x','y':'y','px':'px','py':'py','energy':'energy'}
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ class Model:
|
||||
# hook up events
|
||||
self.eventHandling()
|
||||
|
||||
def eventHandling(self):
|
||||
self.parent.UITrack.clicked.connect(self.track)
|
||||
self.parent.UIMatchSelected.clicked.connect(self.match)
|
||||
|
||||
|
||||
def getLatticeVersion(self):
|
||||
return self.om.Version
|
||||
|
||||
@@ -123,9 +128,6 @@ class Model:
|
||||
print(settings['Energy']['energy'])
|
||||
print('Energy in system',self.om.EnergyAt(self.energyReference)[0])
|
||||
|
||||
|
||||
|
||||
|
||||
##### very old code should be become obsolete after some nice matching files
|
||||
def updateModel(self):
|
||||
file ='SwissFELRef.json'
|
||||
@@ -165,20 +167,47 @@ class Model:
|
||||
##############################33
|
||||
# tracking
|
||||
|
||||
def eventHandling(self):
|
||||
self.parent.UITrack.clicked.connect(self.track)
|
||||
|
||||
def match(self,sequence,destination, variables,conditions,periodic=False,plot=True):
|
||||
self.setBranch(destination.upper())
|
||||
twiss={'energy0':150.}
|
||||
self.madx.updateVariables(twiss)
|
||||
res,twiss,tar=self.madx.match(sequence,variables,conditions,periodic)
|
||||
energy = self.calcEnergyProfile(twiss)
|
||||
matchtwiss={'betax':twiss.betx[0],'betay':twiss.bety[0],'alphax':twiss.alfx[0],'alphay':twiss.alfy[0]}
|
||||
def match(self):
|
||||
config = self.parent.reference.getMatchingPoint()
|
||||
self.setBranch(config['Destination'])
|
||||
if config['Reference'] is None:
|
||||
start='#s'
|
||||
end='#e'
|
||||
itwiss=None
|
||||
else:
|
||||
start=config['Reference']['Location']
|
||||
if start.upper() == 'START':
|
||||
start='#s'
|
||||
end = config['End']+'$end'
|
||||
itwiss = {converttwiss[key.lower()]:config['Reference']['Twiss'][key] for key in config['Reference']['Twiss'].keys()}
|
||||
var={}
|
||||
for key in config['Variable'].keys():
|
||||
key0=key.replace('-','.').lower()
|
||||
if 'mqua' or 'mqsk' in key0:
|
||||
key0+='.k1'
|
||||
elif 'msex' in key0:
|
||||
key0+='.k2'
|
||||
var[key0]=config['Variable'][key]
|
||||
conf0={}
|
||||
for key in config['Target'].keys():
|
||||
sconf = config['Target'][key]
|
||||
conf0[key] = {converttwiss[key0.lower()]:sconf[key0] for key0 in sconf.keys()}
|
||||
|
||||
|
||||
res,twiss,err=self.madx.match(sequence=config['Sequence'], start=start, end=end,
|
||||
init=itwiss, var=var, const=conf0,
|
||||
preset=False,random=False)
|
||||
print(res)
|
||||
print(err)
|
||||
plot = True
|
||||
if plot:
|
||||
self.parent.plot.newData(twiss, energy)
|
||||
return res, matchtwiss,tar
|
||||
energy = self.calcEnergyProfile(twiss)
|
||||
print('Plotting')
|
||||
self.parent.plot.newData(twiss,energy)
|
||||
|
||||
##################
|
||||
# tracking
|
||||
|
||||
def track(self):
|
||||
start = str(self.parent.UITrackStart.text()).upper()
|
||||
@@ -187,12 +216,11 @@ class Model:
|
||||
start = start[0:7]
|
||||
if len(end)>7:
|
||||
end = end[0:7]
|
||||
twiss0 = self.parent.reference.getReferencePoint()
|
||||
refloc = self.parent.reference.getReferenceLocation().upper()
|
||||
if refloc == 'START':
|
||||
refloc, twiss0 = self.parent.reference.getReference()
|
||||
|
||||
if refloc.upper() == 'START':
|
||||
refloc = start.upper()
|
||||
twiss0['energy'] = self.startEnergy*1e-3 # convert to GeV for madx
|
||||
|
||||
start, end = self.checkRange(start, end, refloc[0:7])
|
||||
if start is None:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user