1 | function [s2 bx2 bz2 etax2 etaz2 ax2 az2] = tracy_readsigma(file,cell) |
---|
2 | %function tracy_readtwiss(file,cell) - Plot Twiss functions from TRacy output file |
---|
3 | % |
---|
4 | % OUPUTS |
---|
5 | % 1. s2 - s-position alon the ring |
---|
6 | % 2. bx2 - Horizontal beta function |
---|
7 | % 3. bz2 - Vertical beta function |
---|
8 | % 4. etax2 - Horizontal dispersion |
---|
9 | % 5. etaz2 - Vertical dispersion |
---|
10 | % 6. ax2 - Horizontal alpha function |
---|
11 | % 7. az2 - Vertical alpha function |
---|
12 | % |
---|
13 | % cell = 1 show all the ring |
---|
14 | % cell = 4 show one out of 4 periods |
---|
15 | |
---|
16 | % |
---|
17 | %% Written by Laurent S. Nadolski, 27/09/08, SOLEIL |
---|
18 | |
---|
19 | DisplayFlag = 1; |
---|
20 | |
---|
21 | if nargin == 0 |
---|
22 | file = 'sigma.out'; |
---|
23 | end |
---|
24 | |
---|
25 | if (nargin ==2 && ~isempty(cell)) |
---|
26 | cell = 4; |
---|
27 | else |
---|
28 | cell = 1; |
---|
29 | end |
---|
30 | |
---|
31 | [dummy s bx mux by muy sqrtSx sqrtSxp sqrtSy sqrtSyp sxy twist delta sqrtSxoSy sqrtexbx sqrteyby sqrtsI sqrtsII sIII sqrtsIosII] = ... |
---|
32 | textread(file,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f','headerlines',4); |
---|
33 | [s idx] = unique(s); |
---|
34 | bx = bx(idx); by = by(idx); |
---|
35 | mux = mux(idx); muy = muy(idx); |
---|
36 | sqrtSx = sqrtSx(idx); |
---|
37 | sqrtSxp = sqrtSxp(idx); |
---|
38 | sqrtSy = sqrtSy(idx); |
---|
39 | sqrtSyp = sqrtSyp(idx); |
---|
40 | sxy = sxy(idx); |
---|
41 | delta = delta(idx); |
---|
42 | sqrtSxoSy = sqrtSxoSy(idx); |
---|
43 | sqrtexbx = sqrtexbx(idx); |
---|
44 | sqrteyby = sqrteyby(idx); |
---|
45 | sqrtsI = sqrtsI(idx); |
---|
46 | sqrtsII = sqrtsII(idx); |
---|
47 | sIII = sIII(idx); |
---|
48 | twist = twist(idx); |
---|
49 | sqrtsIosII = sqrtsIosII(idx); |
---|
50 | |
---|
51 | %invariant |
---|
52 | epsX = sqrtexbx.*sqrtexbx./bx; |
---|
53 | epsY = sqrteyby.*sqrteyby./by; |
---|
54 | |
---|
55 | if 0 |
---|
56 | [s2 bx2 by2 etax2 etay2 ax2 ay2] = tracy_readtwiss; |
---|
57 | |
---|
58 | % projected emittance ?? look like invariant |
---|
59 | epsXp = (sqrtSx.*sqrtSx-etax2.*etax2*1.016e-3*1.016e-3)./bx2; |
---|
60 | epsYp = (sqrtSy.*sqrtSy-etay2.*etay2*1.016e-3*1.016e-3)./by2; |
---|
61 | % epsXp = (sqrtsI.*sqrtsI-etax2.*etax2*1.016e-3*1.016e-3)./bx2; |
---|
62 | % epsYp = (sqrtsII.*sqrtsII-etay2.*etay2*1.016e-3*1.016e-3)./by2; |
---|
63 | fprintf('Mean projected emittance epsX = %e (nm.rad) epsY = %e (nm.rad)\n', mean(epsX), mean(epsY)); |
---|
64 | fprintf('Entrance projected emittance epsX = %e (nm.rad) epsY = %e (nm.rad)\n', epsX(1), epsY(1)); |
---|
65 | fprintf('Mean projected emittance ratio = %e\n', mean(epsY./epsX)); |
---|
66 | figure |
---|
67 | subplot(2,1,1) |
---|
68 | plot(s,epsXp); hold on |
---|
69 | plot(s,epsYp); axis tight; |
---|
70 | subplot(2,1,2) |
---|
71 | plot(s,epsYp./epsXp*100); axis tight; |
---|
72 | end |
---|
73 | |
---|
74 | %% |
---|
75 | if DisplayFlag |
---|
76 | h = figure(21) |
---|
77 | cla |
---|
78 | plot(s,bx,'r.',s,by,'b.'); |
---|
79 | %drawlattice(0,2,gca) |
---|
80 | %plotlattice(0,2) |
---|
81 | legend('\beta_x','\beta_z') |
---|
82 | xaxis([0 s(end)/cell]) |
---|
83 | title('Optical functions') |
---|
84 | xlabel('s (m)') |
---|
85 | datalabel on |
---|
86 | %% |
---|
87 | %% interpolation |
---|
88 | si = (s(1):0.2:s(end))'; |
---|
89 | bxi = interp1(s,bx,si,'pchip'); |
---|
90 | byi = interp1(s,by,si,'pchip'); |
---|
91 | |
---|
92 | hold on; |
---|
93 | plot(si,bxi,'r-',si,byi,'b-'); |
---|
94 | drawlattice(0,2,gca) |
---|
95 | xaxis([0 s(end)/cell]) |
---|
96 | title('Optical functions') |
---|
97 | xlabel('s (m)') |
---|
98 | |
---|
99 | figure |
---|
100 | plot(s,epsY./epsX*100) |
---|
101 | ylabel('Coupling value (%)') |
---|
102 | axis tight |
---|
103 | |
---|
104 | figure |
---|
105 | subplot(2,1,1) |
---|
106 | plot(s,sqrtsI,s,sqrtsII) |
---|
107 | ylabel('Beam sizes (%)') |
---|
108 | axis tight |
---|
109 | subplot(2,1,2) |
---|
110 | plot(s,sqrtsIosII) |
---|
111 | ylabel('Beam size ratio (%)') |
---|
112 | axis tight |
---|
113 | |
---|
114 | figure |
---|
115 | subplot(2,2,2) |
---|
116 | plot(s,epsX*1e9) |
---|
117 | ylabel('H-emittance (nm.rad)') |
---|
118 | axis tight |
---|
119 | subplot(2,2,4) |
---|
120 | plot(s,epsY*1e9) |
---|
121 | ylabel('V-emittance (nm.rad)') |
---|
122 | axis tight |
---|
123 | subplot(2,2,1) |
---|
124 | plot(s,twist*180/pi) |
---|
125 | ylabel('twist (degree)') |
---|
126 | axis tight |
---|
127 | subplot(2,2,3) |
---|
128 | plot(s,sqrtSx*1e6,'b', s, sqrtSy*1e6,'g') |
---|
129 | ylabel('Beam sizes (µm)') |
---|
130 | axis tight |
---|
131 | end |
---|