def __init__(self,base,nsigma=12,nangles=7,wp=(0.28, 0.31),mcx=False): self.base=base self.label=base.replace('_',' ')+' comp' self.tw=optics.open(os.path.join(base,'optics0_inser.mad')) self.et=optics.open(os.path.join(base,'tripD1D2.errors')) if mcx: self.mcx=os.path.join(base,'MCX_setting.mad') else: self.mcx=False self.nsigma=nsigma self.nangles=nangles self.x,self.y=self.mk_grid() self.tunx=self.x*0+wp[0] self.tuny=self.y*0+wp[1] self.ex=self.tw.param['ex'] self.ey=self.tw.param['ex'] self.mk_detuning()
def __init__(self, base, nsigma=12, nangles=7, wp=(0.28, 0.31), mcx=False): self.base = base self.label = base.replace('_', ' ') + ' comp' self.tw = optics.open(os.path.join(base, 'optics0_inser.mad')) self.et = optics.open(os.path.join(base, 'tripD1D2.errors')) if mcx: self.mcx = os.path.join(base, 'MCX_setting.mad') else: self.mcx = False self.nsigma = nsigma self.nangles = nangles self.x, self.y = self.mk_grid() self.tunx = self.x * 0 + wp[0] self.tuny = self.y * 0 + wp[1] self.ex = self.tw.param['ex'] self.ey = self.tw.param['ex'] self.mk_detuning()
def check_el(p): madt = optics.open('sps/madx/track.obs0002.p0001') out1 = [madt[l][0] for l in 'x px y py y t pt'.split()] out2 = [getattr(p, l) for l in 'x px y py y tau pt'.split()] diff = 0 for a, b in zip(out1, out2): diff += (a - b)**2 print "%24.17e %24.17e %24.17e" % (a, b, a - b) print np.sqrt(diff)
def check_el(p): madt=optics.open('sps/madx/track.obs0002.p0001') out1=[madt[l][0] for l in 'x px y py y t pt'.split()] out2=[getattr(p,l) for l in 'x px y py y tau pt'.split()] diff=0 for a,b in zip(out1,out2): diff+=(a-b)**2 print("%24.17e %24.17e %24.17e"%(a,b,a-b)) print(np.sqrt(diff))
from pyoptics import madlang,optics #see sps/madx/a001_track_thin.madx mad=madlang.open('madx/SPS_Q20_thin.seq') mad.acta_31637.volt=4.5 mad.acta_31637.lag=0.5 import pysixtrack elems,rest,iconv=mad.sps.expand_struct(pysixtrack.element_types) pbench=optics.open('madx/track.obs0001.p0001') sps=pysixtrack.Line(elements= [e[2] for e in elems]) def get_part(pbench,ii): pstart=[pbench[n][ii] for n in 'x px y py t pt'.split()] pstart=dict(zip('x px y py tau ptau'.split(),pstart)) prun=pysixtrack.Particles(energy0=pbench.e[ii]*1e9,**pstart) return prun def compare(prun,pbench): out=[] for att in 'x px y py tau ptau'.split(): vrun=getattr(prun,att) vbench=getattr(pbench,att) diff=vrun-vbench out.append(abs(diff)) print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g}") print(f"max {max(out):21.12e}") return max(out) prun=get_part(pbench,0)
from pyoptics import madlang, optics import pysixtrack # see sps/madx/a001_track_thin.madx mad = madlang.open("madx/SPS_Q20_thin.seq") mad.acta_31637.volt = 4.5 mad.acta_31637.lag = 0.5 elems, rest, iconv = mad.sps.expand_struct(pysixtrack.element_types) pbench = optics.open("madx/track.obs0001.p0001") sps = pysixtrack.Line(elements=[e[2] for e in elems]) def get_part(pbench, ii): pstart = [pbench[n][ii] for n in "x px y py t pt".split()] pstart = dict(zip("x px y py tau ptau".split(), pstart)) prun = pysixtrack.Particles(energy0=pbench.e[ii] * 1e9, **pstart) return prun def compare(prun, pbench): out = [] for att in "x px y py tau ptau".split(): vrun = getattr(prun, att) vbench = getattr(pbench, att) diff = vrun - vbench out.append(abs(diff)) print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g}") print(f"max {max(out):21.12e}") return max(out)
from pyoptics import madlang, optics #see sps/madx/a001_track_thin.madx mad = madlang.open('madx/SPS_Q20_thin.seq') mad.acta_31637.volt = 4.5 mad.acta_31637.lag = 0.5 import pysixtrack elems, rest, iconv = mad.sps.expand_struct(pysixtrack.element_types) pbench = optics.open('madx/track.obs0001.p0001') sps = pysixtrack.Line(elements=[e[2] for e in elems]) def get_part(pbench, ii): pstart = [pbench[n][ii] for n in 'x px y py t pt'.split()] pstart = dict(zip('x px y py tau ptau'.split(), pstart)) prun = pysixtrack.Particles(energy0=pbench.e[ii] * 1e9, **pstart) return prun def compare(prun, pbench): out = [] for att in 'x px y py tau ptau'.split(): vrun = getattr(prun, att) vbench = getattr(pbench, att) diff = vrun - vbench out.append(abs(diff)) print(f"{att:<5} {vrun:22.13e} {vbench:22.13e} {diff:22.13g}") print(f"max {max(out):21.12e}")