source: MML/trunk/machine/SOLEIL/common/naff/naffutils/touscheklifetime/Calc_Tous.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 5.2 KB
Line 
1function [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
31FullMachineFlag = 0;
32DisplayFlag = 1;
33
34
35% Get input flags
36for 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
43end
44
45% Help part if not enough input arguments
46if length(varargin) <1
47    help(eval('mfilename'))
48    return;
49else
50    file   = varargin{1}; % Energy acceptance
51    linlat = varargin{2}; % Twiss parameters
52end
53
54% Reading Twiss function
55% name     s    alphax  betax   nux   etax   etapx  alphay  betay   nuy   etay   etapy
56%         [m]            [m]           [m]                   [m]           [m]
57try
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);
60catch
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
67end
68
69% Emittance
70if length(varargin) <3
71    ex = 3.7E-9;  %Default emittance value
72    fprintf('Default coupling value is: ex = %f nm.rad\n',ex)
73else
74   ex = varargin{3};
75end
76
77% coupling value
78if length(varargin) <5
79    kapa = 1.0E-2;  %Default coupling value
80    fprintf('Default coupling value is: kapa = %f\n',kapa)
81else
82    kapa = varargin{5};
83end
84
85ez = ex*kapa;  %Emittance V
86se = 1.016E-3; %Dispersion en energie
87gx = (1+ax.^2)./bx; %Gammax
88
89sx = sqrt(bx*ex+(se*etax).^2);  %Taille  H
90sxp= sqrt(gx*ex+(se*etaxp).^2); %Divergence H
91sz = sqrt(bz*ez+(se*etaz).^2);  %Taille V
92
93[dummy sd acen lost nom] = textread(file,'%d %f %f %f %s','headerlines',3);
94Nb_pts=length(sd)/2;
95s=sd(1:Nb_pts);
96acen_p=acen(1:Nb_pts); acen_n=acen(Nb_pts+1:end);
97
98% bunch length value
99if length(varargin) <4
100    ss = 6.0E-4;  %sigma_s en mm
101    fprintf('Default bunch length : sigma_s= %f m\n',ss)
102else
103    ss =varargin{4};
104end
105
106% bunch length value
107if length(varargin) <6
108    E     = 2.739;           % Energy
109    fprintf('Default beam energy: E= %f GeV \n',E)
110else
111    E =varargin{6};
112end
113
114V     = 8*pi*sqrt(pi).*sx.*sz.*ss; %Volume du paquet
115Gamma = 5382.57324;      % Facteur de Lorentz
116c     = 2.99792458E8;    % Vitesse de la lumiere
117re    = 2.81794092E-15;  % Rayon classique de l'electron
118I0    = 1.0E-3;          % Courant par paquet
119Qe    = 1.6022E-19;      % Charge de l'electron
120L     = 354.097;         % Circonference de l'anneau
121N     = 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;
128FF = sqrt(pi)*re*re*c*N*3600;
129Tinvp = zeros(1,Nb_pts);
130Tinvn = zeros(1,Nb_pts);
131
132h = waitbar(0,sprintf('Computing: %2d %%',0), 'Name', 'Touschek lifetime');
133for 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)));
139end
140close(h);
141   
142% Local average lifetime
143Tinv = (Tinvp+Tinvn)/2;
144
145Tp=1./Tinvp;
146Tn=1./Tinvn;
147T =1./Tinv;
148
149% Integration: Simpson method
150s1=[0 ; s]; s2=[s ; 0]; ds=s2-s1;
151Tousp=1/sum(1./Tp.*ds(1:end-1)')*s(end);
152Tousn=1/sum(1./Tn.*ds(1:end-1)')*s(end);
153
154Tous=2/(1/Tousp+1/Tousn);
155
156%% plotsection
157
158if 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 (%)')
199end
Note: See TracBrowser for help on using the repository browser.