def TrackSigmaMatrix(infile,nameprevel,initdc,nparticles): transfermatrixopt = io.tfsDict(infile) prevelinex = transfermatrixopt[0]["name"].index(nameprevel)-1 gamma = transfermatrixopt[1]['gamma'] ex = transfermatrixopt[1]['ex'] ey = transfermatrixopt[1]['ey'] sige = transfermatrixopt[1]['sige'] sigt = transfermatrixopt[1]['sigt'] print transfermatrixopt[0]['name'][prevelinex-1] print transfermatrixopt[0]['name'][prevelinex] print transfermatrixopt[0]['name'][prevelinex+1] matrix = np.array([ [transfermatrixopt[0]["re11"][prevelinex],transfermatrixopt[0]["re12"][prevelinex], transfermatrixopt[0]["re13"][prevelinex],transfermatrixopt[0]["re14"][prevelinex], transfermatrixopt[0]["re15"][prevelinex],transfermatrixopt[0]["re16"][prevelinex]], [transfermatrixopt[0]["re21"][prevelinex],transfermatrixopt[0]["re22"][prevelinex], transfermatrixopt[0]["re23"][prevelinex],transfermatrixopt[0]["re24"][prevelinex], transfermatrixopt[0]["re25"][prevelinex],transfermatrixopt[0]["re26"][prevelinex]], [transfermatrixopt[0]["re31"][prevelinex],transfermatrixopt[0]["re32"][prevelinex], transfermatrixopt[0]["re33"][prevelinex],transfermatrixopt[0]["re34"][prevelinex], transfermatrixopt[0]["re35"][prevelinex],transfermatrixopt[0]["re36"][prevelinex]], [transfermatrixopt[0]["re41"][prevelinex],transfermatrixopt[0]["re42"][prevelinex], transfermatrixopt[0]["re43"][prevelinex],transfermatrixopt[0]["re44"][prevelinex], transfermatrixopt[0]["re45"][prevelinex],transfermatrixopt[0]["re46"][prevelinex]], [transfermatrixopt[0]["re51"][prevelinex],transfermatrixopt[0]["re52"][prevelinex], transfermatrixopt[0]["re53"][prevelinex],transfermatrixopt[0]["re54"][prevelinex], transfermatrixopt[0]["re55"][prevelinex],transfermatrixopt[0]["re56"][prevelinex]], [transfermatrixopt[0]["re61"][prevelinex],transfermatrixopt[0]["re62"][prevelinex], transfermatrixopt[0]["re63"][prevelinex],transfermatrixopt[0]["re64"][prevelinex], transfermatrixopt[0]["re65"][prevelinex],transfermatrixopt[0]["re66"][prevelinex]] ]) sigma0matrix = np.array([ ex / 2. * np.array([initdc['BETX'],-initdc['ALFX'],0.,0.,0.,0.]), ex / 2. * np.array([-initdc['ALFX'],(2+initdc['ALFX']**2)/initdc['BETX'],0.,0.,0.,0.]), ey / 2. * np.array([0.,0.,initdc['BETY'],-initdc['ALFY'],0.,0.]), ey / 2. * np.array([0.,0.,-initdc['ALFY'],(2+initdc['ALFY']**2)/initdc['BETY'],0,0]), np.array([0.,0.,0.,0.,0.,0.]), np.array([0.,0.,0.,0.,0.,sige**2]), ]) orbit = np.array([transfermatrixopt[0]["x"][prevelinex], transfermatrixopt[0]["px"][prevelinex], transfermatrixopt[0]["y"][prevelinex], transfermatrixopt[0]["py"][prevelinex], transfermatrixopt[0]["t"][prevelinex], transfermatrixopt[0]["pt"][prevelinex]]) sigma1matrix = np.dot(matrix,np.dot(sigma0matrix,np.transpose(matrix))) # print sigma0matrix,initdc['DELTAP'],np.sqrt(sigma1matrix[5,5]) coordinates = np.transpose( np.array([ np.random.normal(orbit[0],np.sqrt(sigma1matrix[0,0]),nparticles), np.random.normal(orbit[1],np.sqrt(sigma1matrix[1,1]),nparticles), np.random.normal(orbit[2],np.sqrt(sigma1matrix[2,2]),nparticles), np.random.normal(orbit[3],np.sqrt(sigma1matrix[3,3]),nparticles), np.random.normal(0,sigt,nparticles), np.random.normal(initdc['DELTAP'],np.sqrt(sigma1matrix[5,5]),nparticles)#initdc['DELTAP'] ]) ) return coordinates
def get_p(tfsfile): opt = io.tfsDict(tfsfile) return opt[1]['pc']
import cern_pymad_domain_tfs as dom import cern_pymad_io_tfs as io import numpy as nm import matplotlib.pyplot as plt import math data = io.tfsDict("LHCB1-Optics.tfs") keys = [] for key, val in data[0].items(): keys.append(key) print keys print data[1] #plt.plot(data[0]['s'], data[0]['x'], 'b-') plt.axis([-500, 500, -0.01, 0.01]) #plt.show() a = nm.array(data[0]['betx']) b= data[1]['ex'] print b * a aa=nm.array(data[0]['x'])+nm.sqrt(b* a + nm.array(data[0]['dx'])**2 * data[1]['sige']**2) aaa=nm.array(data[0]['x'])-nm.sqrt(b* a + nm.array(data[0]['dx'])**2 * data[1]['sige']**2) plt.plot(data[0]['s'], data[0]['x'], 'b-',data[0]['s'], aa, 'r-',data[0]['s'], aaa, 'r-') plt.show()
if isinstance(table.get(k)[i],str): addvals = '"' + str(table.get(k)[i]).upper() + '"' elif isinstance(table.get(k)[i],float): addvals = float_to_mathematica(table.get(k)[i]) else: addvals = str(table.get(k)[i]).upper() mfs += addvals + ',' mfs = mfs[:-1] mfs += '},' mfs = mfs[:-1] mfs += '}]' return mfs # Reading in the tfs file to python library datab1 = io.tfsDict("LHCB1-Optics.tfs") datab2 = io.tfsDict("LHCB2-Optics.tfs") rb1 = datab1[0] rb2 = datab2[0] cols1 = ['name','keyword','y','px','py','betx','bety','alfx','alfy','mux','muy','dx','dy','dpx','dpy','s','x'] cols2 = ['y','betx','bety','dx','dy','s','x'] gamma1 = datab1[1]['gamma'] ex1 = datab1[1]['ex'] ey1 = datab1[1]['ey'] sige1 = datab1[1]['sige'] n1 = datab1[1]['npart'] q1 = datab1[1]['charge'] m1 = datab1[1]['mass'] s1 = nm.array(rb1.get('s')) xc1 = nm.array(rb1.get('x')) yc1 = nm.array(rb1.get('y'))
def TrackSigmaMatrix(infile, nameprevel, initdc, nparticles): transfermatrixopt = io.tfsDict(infile) prevelinex = transfermatrixopt[0]["name"].index(nameprevel) - 1 gamma = transfermatrixopt[1]['gamma'] ex = transfermatrixopt[1]['ex'] ey = transfermatrixopt[1]['ey'] sige = transfermatrixopt[1]['sige'] sigt = transfermatrixopt[1]['sigt'] print transfermatrixopt[0]['name'][prevelinex - 1] print transfermatrixopt[0]['name'][prevelinex] print transfermatrixopt[0]['name'][prevelinex + 1] matrix = np.array([[ transfermatrixopt[0]["re11"][prevelinex], transfermatrixopt[0]["re12"][prevelinex], transfermatrixopt[0]["re13"][prevelinex], transfermatrixopt[0]["re14"][prevelinex], transfermatrixopt[0]["re15"][prevelinex], transfermatrixopt[0]["re16"][prevelinex] ], [ transfermatrixopt[0]["re21"][prevelinex], transfermatrixopt[0]["re22"][prevelinex], transfermatrixopt[0]["re23"][prevelinex], transfermatrixopt[0]["re24"][prevelinex], transfermatrixopt[0]["re25"][prevelinex], transfermatrixopt[0]["re26"][prevelinex] ], [ transfermatrixopt[0]["re31"][prevelinex], transfermatrixopt[0]["re32"][prevelinex], transfermatrixopt[0]["re33"][prevelinex], transfermatrixopt[0]["re34"][prevelinex], transfermatrixopt[0]["re35"][prevelinex], transfermatrixopt[0]["re36"][prevelinex] ], [ transfermatrixopt[0]["re41"][prevelinex], transfermatrixopt[0]["re42"][prevelinex], transfermatrixopt[0]["re43"][prevelinex], transfermatrixopt[0]["re44"][prevelinex], transfermatrixopt[0]["re45"][prevelinex], transfermatrixopt[0]["re46"][prevelinex] ], [ transfermatrixopt[0]["re51"][prevelinex], transfermatrixopt[0]["re52"][prevelinex], transfermatrixopt[0]["re53"][prevelinex], transfermatrixopt[0]["re54"][prevelinex], transfermatrixopt[0]["re55"][prevelinex], transfermatrixopt[0]["re56"][prevelinex] ], [ transfermatrixopt[0]["re61"][prevelinex], transfermatrixopt[0]["re62"][prevelinex], transfermatrixopt[0]["re63"][prevelinex], transfermatrixopt[0]["re64"][prevelinex], transfermatrixopt[0]["re65"][prevelinex], transfermatrixopt[0]["re66"][prevelinex] ]]) sigma0matrix = np.array([ ex / 2. * np.array([initdc['BETX'], -initdc['ALFX'], 0., 0., 0., 0.]), ex / 2. * np.array([ -initdc['ALFX'], (2 + initdc['ALFX']**2) / initdc['BETX'], 0., 0., 0., 0. ]), ey / 2. * np.array([0., 0., initdc['BETY'], -initdc['ALFY'], 0., 0.]), ey / 2. * np.array([ 0., 0., -initdc['ALFY'], (2 + initdc['ALFY']**2) / initdc['BETY'], 0, 0 ]), np.array([0., 0., 0., 0., 0., 0.]), np.array([0., 0., 0., 0., 0., sige**2]), ]) orbit = np.array([ transfermatrixopt[0]["x"][prevelinex], transfermatrixopt[0]["px"][prevelinex], transfermatrixopt[0]["y"][prevelinex], transfermatrixopt[0]["py"][prevelinex], transfermatrixopt[0]["t"][prevelinex], transfermatrixopt[0]["pt"][prevelinex] ]) sigma1matrix = np.dot(matrix, np.dot(sigma0matrix, np.transpose(matrix))) # print sigma0matrix,initdc['DELTAP'],np.sqrt(sigma1matrix[5,5]) coordinates = np.transpose( np.array([ np.random.normal(orbit[0], np.sqrt(sigma1matrix[0, 0]), nparticles), np.random.normal(orbit[1], np.sqrt(sigma1matrix[1, 1]), nparticles), np.random.normal(orbit[2], np.sqrt(sigma1matrix[2, 2]), nparticles), np.random.normal(orbit[3], np.sqrt(sigma1matrix[3, 3]), nparticles), np.random.normal(0, sigt, nparticles), np.random.normal(initdc['DELTAP'], np.sqrt(sigma1matrix[5, 5]), nparticles) #initdc['DELTAP'] ])) return coordinates