Added support to import LongTrack settings file and to match with user defined twiss values

This commit is contained in:
2026-03-05 11:00:17 +01:00
parent bc81dcce00
commit 9bef0adc13
6 changed files with 340 additions and 20 deletions
+86
View File
@@ -1,6 +1,10 @@
from dataclasses import field
from PyQt5 import QtCore, QtGui, QtWidgets
import numpy as np
import re
import scipy
import json
CGrey = QtGui.QColor(230,230,230)
CBeige = QtGui.QColor(250, 240, 200)
@@ -20,6 +24,7 @@ class Sandbox:
self.parent.Mach2ModUnd.clicked.connect(self.updateModelEvent)
self.parent.SB2ModUnd.clicked.connect(self.updateModelEvent)
self.parent.SB2MachineMag.clicked.connect(self.updateMachine)
self.parent.SBLongTrack.clicked.connect(self.updateFromLongTrack)
def updateMachine(self):
vals = self.getSBbyCol(self.parent.MagSB,1)
@@ -244,3 +249,84 @@ class Sandbox:
colors.append(sbcol)
self.updateSandboxCommon(sb, values, colors, labels)
def updateFromLongTrack(self):
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName,_ = QtWidgets.QFileDialog.getOpenFileName(self.parent, "Open LongTrack Settings",".","Json Files (*.json)", options=options)
if not fileName:
return
with open(fileName,'r') as f:
data = json.load(f)
for sec in ['SINSB','SINXB','Linac1-1','Linac1-2','Linac2','Linac3']:
self.updateLTRF(data,sec)
for sec in ['BC1','BC2','Laser Heater']:
self.updateLTBC(data,sec)
self.updateSandbox()
self.parent.model.forceLatticeUpdate()
self.parent.status('Sandbox mode')
def updateLTBC(self,data,section):
if not section in data.keys():
return
self.rootR56=data[section]['R56']
self.rootLb = data[section]['Dipole Length']
self.rootLd = data[section]['L1']
x=data[section]['Angle']
if self.rootR56 > 0:
res = scipy.optimize.root_scalar(self.calc56,method='bisect',bracket=[1e-5,0.2])
angle = -res.root*180/np.pi
else:
angle = 0.
if 'BC1' in section:
self.parent.model.updateElement('SINBC02.MBND', [angle])
elif 'BC2' in section:
self.parent.model.updateElement('S10BC02.MBND', [angle])
elif 'Laser Heater' in section:
self.parent.model.updateElement('SINLH02.MBND', [angle])
def calc56(self, x):
return 2* (4* x / np.sin(x) * self.rootLb + 2 * self.rootLd / np.cos(x)-4*self.rootLb-2*self.rootLd)-self.rootR56
def updateLTRF(self,data,section):
if not section in data.keys():
return
phase=data[section]['Phase']
gain=data[section]['Voltage']
if 'Linac3' in section:
gain/=13.
for i in range(1,14):
field='S30CB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)
elif 'Linac2' in section:
gain/=4
for i in range(1,5):
field='S20CB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)
elif 'Linac1-2' in section:
gain/=7
for i in range(3,10):
field='S10CB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)
elif 'Linac1-1' in section:
gain/=2
for i in range(1,3):
field='S10CB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)
elif 'SINSB' in section:
gain/=2
for i in range(3,5):
field='SINSB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)
elif 'SINXB' in section:
for i in range(1,2):
field='SINXB%2.2d-RSYS' % i
val = [gain, phase]
self.parent.model.updateElement(field.replace('-', '.'), val)