1 | function [Tous,Tousp,Tousn]=Calc_Tous(varargin) |
---|
2 | %function [Tous,Tousp,Tousn]=Calc_Tous(file,linlat,sigmas,couplage) |
---|
3 | %Calc_Tous - Compute Touschek liftetime based on the energy acceptance |
---|
4 | %computed by Tracy code |
---|
5 | % |
---|
6 | % Integration method: Simpson (as in BETA code) |
---|
7 | % |
---|
8 | % External function used: C(xi) standard function |
---|
9 | % |
---|
10 | % INPUTS |
---|
11 | % 1. file - output format from tracy (soleil.out) |
---|
12 | % 2. linlat - optics file (linlat.out) |
---|
13 | % 3. hemittance - Horizontal emittance |
---|
14 | % 4. sigmas - bunch length (m) |
---|
15 | % 5. couplage - coupling value |
---|
16 | % 6. energy - Energy value |
---|
17 | % Extra 'Full' - Full machine instead of a quarter |
---|
18 | % |
---|
19 | % OUTPUTS |
---|
20 | % 1. T(h) - Total Touschek lifetime |
---|
21 | % 2. Tp(h) - Touschek lifetime delta >0 |
---|
22 | % 3. Tn(h) - Touschek lifetime delta <0 |
---|
23 | % |
---|
24 | % Example |
---|
25 | % 1. Computation for 1% coupling and 6 mm bunch length |
---|
26 | % [T, Tp, Tn] = Calc_Tous('soleil.out','linlat.out', 6e-3, 1e-2) |
---|
27 | |
---|
28 | % |
---|
29 | %% Written by Laurent S. Nadolski, SOLEIL 2003 |
---|
30 | |
---|
31 | FullMachineFlag = 0; |
---|
32 | DisplayFlag = 1; |
---|
33 | |
---|
34 | |
---|
35 | % Get input flags |
---|
36 | for i = length(varargin):-1:1 |
---|
37 | if isstr(varargin{i}) |
---|
38 | if strcmpi(varargin{i},'FullMachine') |
---|
39 | FullMachineFlag = 1; |
---|
40 | varargin(i) = []; |
---|
41 | end |
---|
42 | end |
---|
43 | end |
---|
44 | |
---|
45 | % Help part if not enough input arguments |
---|
46 | if length(varargin) <1 |
---|
47 | help(eval('mfilename')) |
---|
48 | return; |
---|
49 | else |
---|
50 | file = varargin{1}; % Energy acceptance |
---|
51 | linlat = varargin{2}; % Twiss parameters |
---|
52 | end |
---|
53 | |
---|
54 | % Reading Twiss function |
---|
55 | % name s alphax betax nux etax etapx alphay betay nuy etay etapy |
---|
56 | % [m] [m] [m] [m] [m] |
---|
57 | try |
---|
58 | [dummy s ax bx mux etax etaxp az bz muz etaz etazp] = ... |
---|
59 | textread(linlat,'%s %f %f %f %f %f %f %f %f %f %f %f','headerlines',4); |
---|
60 | catch |
---|
61 | errmsg = lasterr; |
---|
62 | if strfind(errmsg, 'File not found.'); |
---|
63 | error('Input file %s not found \n Abort \n',linlat); |
---|
64 | else |
---|
65 | error('Unknown error %s \n', errmsg) |
---|
66 | end |
---|
67 | end |
---|
68 | |
---|
69 | % Emittance |
---|
70 | if length(varargin) <3 |
---|
71 | ex = 3.7E-9; %Default emittance value |
---|
72 | fprintf('Default coupling value is: ex = %f nm.rad\n',ex) |
---|
73 | else |
---|
74 | ex = varargin{3}; |
---|
75 | end |
---|
76 | |
---|
77 | % coupling value |
---|
78 | if length(varargin) <5 |
---|
79 | kapa = 1.0E-2; %Default coupling value |
---|
80 | fprintf('Default coupling value is: kapa = %f\n',kapa) |
---|
81 | else |
---|
82 | kapa = varargin{5}; |
---|
83 | end |
---|
84 | |
---|
85 | ez = ex*kapa; %Emittance V |
---|
86 | se = 1.016E-3; %Dispersion en energie |
---|
87 | gx = (1+ax.^2)./bx; %Gammax |
---|
88 | |
---|
89 | sx = sqrt(bx*ex+(se*etax).^2); %Taille H |
---|
90 | sxp= sqrt(gx*ex+(se*etaxp).^2); %Divergence H |
---|
91 | sz = sqrt(bz*ez+(se*etaz).^2); %Taille V |
---|
92 | |
---|
93 | [dummy sd acen lost nom] = textread(file,'%d %f %f %f %s','headerlines',3); |
---|
94 | Nb_pts=length(sd)/2; |
---|
95 | s=sd(1:Nb_pts); |
---|
96 | acen_p=acen(1:Nb_pts); acen_n=acen(Nb_pts+1:end); |
---|
97 | |
---|
98 | % bunch length value |
---|
99 | if length(varargin) <4 |
---|
100 | ss = 6.0E-4; %sigma_s en mm |
---|
101 | fprintf('Default bunch length : sigma_s= %f m\n',ss) |
---|
102 | else |
---|
103 | ss =varargin{4}; |
---|
104 | end |
---|
105 | |
---|
106 | % bunch length value |
---|
107 | if length(varargin) <6 |
---|
108 | E = 2.739; % Energy |
---|
109 | fprintf('Default beam energy: E= %f GeV \n',E) |
---|
110 | else |
---|
111 | E =varargin{6}; |
---|
112 | end |
---|
113 | |
---|
114 | V = 8*pi*sqrt(pi).*sx.*sz.*ss; %Volume du paquet |
---|
115 | Gamma = 5382.57324; % Facteur de Lorentz |
---|
116 | c = 2.99792458E8; % Vitesse de la lumiere |
---|
117 | re = 2.81794092E-15; % Rayon classique de l'electron |
---|
118 | I0 = 1.0E-3; % Courant par paquet |
---|
119 | Qe = 1.6022E-19; % Charge de l'electron |
---|
120 | L = 354.097; % Circonference de l'anneau |
---|
121 | N = I0/c*L/Qe; % Nombre d'electrons par paquet |
---|
122 | |
---|
123 | % Inverse Touschek lifetime |
---|
124 | |
---|
125 | %Duree de vie locale positive et negative en heures |
---|
126 | %xi_p=(acen_p./Gamma./sxp)^2; |
---|
127 | %xi_n=(acen_n./Gamma./sxp)^2; |
---|
128 | FF = sqrt(pi)*re*re*c*N*3600; |
---|
129 | Tinvp = zeros(1,Nb_pts); |
---|
130 | Tinvn = zeros(1,Nb_pts); |
---|
131 | |
---|
132 | h = waitbar(0,sprintf('Computing: %2d %%',0), 'Name', 'Touschek lifetime'); |
---|
133 | for i=1:Nb_pts, % loop because of Cxi function |
---|
134 | Tinvp(i) = (FF*Cxi((acen_p(i)/Gamma/sxp(i))^2)/sxp(i) ... |
---|
135 | /Gamma^3/acen_p(i)^2/V(i)); |
---|
136 | Tinvn(i) = (FF*Cxi((acen_n(i)/Gamma/sxp(i))^2)/sxp(i) ... |
---|
137 | /Gamma^3/acen_n(i)^2/V(i)); |
---|
138 | waitbar(i/Nb_pts, h, sprintf('Computing progression: %3d %%', floor(i/Nb_pts*100))); |
---|
139 | end |
---|
140 | close(h); |
---|
141 | |
---|
142 | % Local average lifetime |
---|
143 | Tinv = (Tinvp+Tinvn)/2; |
---|
144 | |
---|
145 | Tp=1./Tinvp; |
---|
146 | Tn=1./Tinvn; |
---|
147 | T =1./Tinv; |
---|
148 | |
---|
149 | % Integration: Simpson method |
---|
150 | s1=[0 ; s]; s2=[s ; 0]; ds=s2-s1; |
---|
151 | Tousp=1/sum(1./Tp.*ds(1:end-1)')*s(end); |
---|
152 | Tousn=1/sum(1./Tn.*ds(1:end-1)')*s(end); |
---|
153 | |
---|
154 | Tous=2/(1/Tousp+1/Tousn); |
---|
155 | |
---|
156 | %% plotsection |
---|
157 | |
---|
158 | if DisplayFlag |
---|
159 | figure |
---|
160 | subplot(2,1,1) |
---|
161 | plot(s,Tp,'.-'); |
---|
162 | grid on |
---|
163 | xlabel('s (m)') |
---|
164 | ylabel('Tp (h)') |
---|
165 | |
---|
166 | subplot(2,1,2) |
---|
167 | plot(s,Tn,'.-'); |
---|
168 | grid on |
---|
169 | xlabel('s (m)') |
---|
170 | ylabel('Tn (h)') |
---|
171 | |
---|
172 | % Structure file |
---|
173 | if FullMachineFlag |
---|
174 | files = fullfile(fileparts(which('naffgui')),'structure_nanoscopium'); |
---|
175 | else |
---|
176 | files = fullfile(fileparts(which('naffgui')),'structure'); |
---|
177 | end |
---|
178 | struc=dlmread(files); |
---|
179 | |
---|
180 | % artificial symmetry |
---|
181 | acen=acen*100; |
---|
182 | |
---|
183 | figure |
---|
184 | clf |
---|
185 | plot([sd(1:Nb_pts); 2*sd(Nb_pts)-sd(Nb_pts:-1:1)],[acen(1:Nb_pts) ; acen(Nb_pts:-1:1)],'b.-'); |
---|
186 | hold on |
---|
187 | plot([sd(Nb_pts+1:end); 2*sd(end)-sd(end:-1:1+Nb_pts)],[acen(Nb_pts+1:end) ; acen(end:-1:Nb_pts+1)],'b.-'); |
---|
188 | plot(struc(:,1),struc(:,2)/2,'k-') |
---|
189 | |
---|
190 | if FullMachineFlag |
---|
191 | axis([0 getcircumference -9 5]) |
---|
192 | else |
---|
193 | axis([0 getcircumference/4 -9 5]) |
---|
194 | end |
---|
195 | grid on |
---|
196 | title('SOLEIL') |
---|
197 | xlabel('s (m)') |
---|
198 | ylabel('Energy Acceptance \epsilon (%)') |
---|
199 | end |
---|