1 | function [TwissX, TwissY, Sx, Sy, Tune] = modeltwissdp(varargin) |
---|
2 | %MODELTWISS - Returns a twiss function of the model for offmomentum energy |
---|
3 | % [TwissX, TwissY, Sx, Sy, Tune] = modeltwissdp(TwissData {opt.}, TwissString, Family1, DeviceList1, Family2, DeviceList2) |
---|
4 | % [TwissX, TwissY, Sx, Sy, Tune] = modeltwissdp(TwissData {opt.}, TwissString, Family1, Family2) |
---|
5 | % [TwissX, TwissY, Sx, Sy, Tune] = modeltwissdp(TwissData {opt.}, TwissString, Family1, DeviceList1) |
---|
6 | % [TwissX, TwissY, Sx, Sy, Tune] = modeltwissdp(TwissData {opt.}, TwissString) |
---|
7 | % |
---|
8 | % INPUTS |
---|
9 | % 1. TwissData - Structure with the twiss parameters {Default: get from THERING{1}.TwissData} |
---|
10 | % 2. TwissString - 'beta' for beta function [meters] |
---|
11 | % 'mu' or 'Phase' for betatron phase advance (NOT 2*PI normalized) |
---|
12 | % 'alpha' Derivative of the beta function |
---|
13 | % 'ClosedOrbit' or 'x' ('y' reverses output [ y, x, Sy, Sx, Tune] = modeltwissdp('y')) |
---|
14 | % 'ClosedOrbitPrime' or 'Px' ('Py' reverses output [Py, Px, Sy, Sx, Tune] = modeltwissdp('Py')) (momentum, NOT angle) |
---|
15 | % 'Eta' for dispersion |
---|
16 | % 'EtaPrime' for the derivative of dispersion |
---|
17 | % 3. Family1 and Family2 are the family names for where to measure the horizontal/vertical twiss parameter. |
---|
18 | % A family name can be a middlelayer family or an AT family (FamName). |
---|
19 | % 'All' returns the value at every element in the model plus the end of the ring. |
---|
20 | % {Default or []: 'All'} |
---|
21 | % 4. DeviceList1 and DeviceList2 are the device list corresponding to Family1 and Family2. |
---|
22 | % {Default or []: the entire list} |
---|
23 | % |
---|
24 | % OUTPUTS |
---|
25 | % 1. TwissX and TwissY - Horizontal and vertical twiss parameter |
---|
26 | % 2. Sx and Sy are longitudinal locations in the ring [meters] |
---|
27 | % 3. Tune - Fractional tune |
---|
28 | % |
---|
29 | % NOTES |
---|
30 | % 1. This function use twissline which uses the linear model. See twissline |
---|
31 | % for all the assumption that it uses. |
---|
32 | % 2. This function uses the model coordinate system in physics units. |
---|
33 | % Ie., no BPM or CM gain or rolls errors are applied. |
---|
34 | % 3. Family1 and DeviceList1 can be any family. For instance, if Family1='VCM' |
---|
35 | % and DeviceList1=[], then TwissX is the horizontal beta function at the |
---|
36 | % vertical corrector magnets (similarly for Family2 and DeviceList2). |
---|
37 | % 4. If no output exists, the function will be plotted to the screen. |
---|
38 | % 5. Phase is in radians. |
---|
39 | % |
---|
40 | % See also modelbeta modeltune modeldisp getpvmodel setpvmodel |
---|
41 | % |
---|
42 | % Written by Greg Portmann |
---|
43 | |
---|
44 | |
---|
45 | global THERING |
---|
46 | if isempty(THERING) |
---|
47 | error('Simulator variable is not setup properly.'); |
---|
48 | end |
---|
49 | |
---|
50 | % Default parameters if not overwritten |
---|
51 | TwissString = 'beta'; |
---|
52 | Family1 = 'ALL'; |
---|
53 | Family2 = 'ALL'; |
---|
54 | %Family1 = 'BPMx'; |
---|
55 | %Family2 = 'BPMy'; |
---|
56 | DeviceList1 = []; |
---|
57 | DeviceList2 = []; |
---|
58 | DrawLatticeFlag = 0; |
---|
59 | |
---|
60 | |
---|
61 | % Look for flags |
---|
62 | for i = length(varargin):-1:1 |
---|
63 | if ischar(varargin{i}) |
---|
64 | if strcmpi(varargin{i}, 'DrawLattice') |
---|
65 | DrawLatticeFlag = 1; |
---|
66 | varargin(i) = []; |
---|
67 | end |
---|
68 | end |
---|
69 | end |
---|
70 | |
---|
71 | |
---|
72 | % Look for TwissString |
---|
73 | if length(varargin) >= 1 |
---|
74 | if ischar(varargin{1}) |
---|
75 | TwissString = varargin{1}; |
---|
76 | varargin(1) = []; |
---|
77 | end |
---|
78 | end |
---|
79 | |
---|
80 | % Look for BPMx family info |
---|
81 | if length(varargin) >= 1 |
---|
82 | if ischar(varargin{1}) |
---|
83 | Family1 = varargin{1}; |
---|
84 | varargin(1) = []; |
---|
85 | if length(varargin) >= 1 |
---|
86 | if isnumeric(varargin{1}) |
---|
87 | DeviceList1 = varargin{1}; |
---|
88 | varargin(1) = []; |
---|
89 | end |
---|
90 | end |
---|
91 | else |
---|
92 | if isnumeric(varargin{1}) |
---|
93 | DeviceList1 = varargin{1}; |
---|
94 | varargin(1) = []; |
---|
95 | end |
---|
96 | end |
---|
97 | end |
---|
98 | |
---|
99 | % Look for BPMy family info |
---|
100 | if length(varargin) >= 1 |
---|
101 | if ischar(varargin{1}) |
---|
102 | Family2 = varargin{1}; |
---|
103 | varargin(1) = []; |
---|
104 | if length(varargin) >= 1 |
---|
105 | if isnumeric(varargin{1}) |
---|
106 | DeviceList2 = varargin{1}; |
---|
107 | varargin(1) = []; |
---|
108 | end |
---|
109 | end |
---|
110 | else |
---|
111 | if isnumeric(varargin{1}) |
---|
112 | DeviceList2 = varargin{1}; |
---|
113 | varargin(1) = []; |
---|
114 | end |
---|
115 | end |
---|
116 | else |
---|
117 | Family2 = Family1; |
---|
118 | DeviceList2 = DeviceList1; |
---|
119 | end |
---|
120 | |
---|
121 | |
---|
122 | % Horizontal plane |
---|
123 | if strcmpi(Family1,'All') |
---|
124 | Index1 = 1:length(THERING)+1; |
---|
125 | elseif isfamily(Family1) |
---|
126 | Index1 = family2atindex(Family1, DeviceList1); |
---|
127 | else |
---|
128 | Index1 = findcells(THERING, 'FamName', Family1); |
---|
129 | end |
---|
130 | if isempty(Index1) |
---|
131 | error('Family1 could not be found in the AO or AT deck'); |
---|
132 | else |
---|
133 | Index1 = Index1(:)'; % Row vector |
---|
134 | end |
---|
135 | |
---|
136 | % Vertical plane |
---|
137 | if strcmpi(Family2,'All') |
---|
138 | Index2 = 1:length(THERING)+1; |
---|
139 | elseif isfamily(Family2) |
---|
140 | Index2 = family2atindex(Family2, DeviceList2); |
---|
141 | else |
---|
142 | Index2 = findcells(THERING, 'FamName', Family2); |
---|
143 | end |
---|
144 | if isempty(Index2) |
---|
145 | error('Family2 could not be found in the AO or AT deck'); |
---|
146 | else |
---|
147 | Index2 = Index2(:)'; % Row vector |
---|
148 | end |
---|
149 | |
---|
150 | MachineType = getfamilydata('MachineType'); |
---|
151 | if any(strcmpi(MachineType, {'Transport','Transportline','Linac'})) |
---|
152 | % Transport line |
---|
153 | |
---|
154 | % Look for TWISSDATAIN |
---|
155 | TWISSDATAIN = []; |
---|
156 | if length(varargin) >= 1 |
---|
157 | if isstruct(varargin{1}) |
---|
158 | TWISSDATAIN = varargin{1}; |
---|
159 | varargin(1) = []; |
---|
160 | end |
---|
161 | end |
---|
162 | if isempty(TWISSDATAIN) |
---|
163 | if isfield(THERING{1}, 'TwissData') |
---|
164 | TWISSDATAIN = THERING{1}.TwissData; |
---|
165 | else |
---|
166 | TWISSDATAIN = getfamilydata('TwissData'); |
---|
167 | if isempty(TWISSDATAIN) |
---|
168 | error('TWISSDATAIN must be an input, located in THERING{1}.TwissData, or accessible to getfamilydata.'); |
---|
169 | end |
---|
170 | end |
---|
171 | end |
---|
172 | |
---|
173 | if strcmpi(TwissString, 'Eta') || strcmpi(TwissString, 'Dispersion') || strcmpi(TwissString, 'Disp') |
---|
174 | TD = twissline(THERING, 0, TWISSDATAIN, 1:(length(THERING)+1), 'Chrom'); |
---|
175 | elseif strcmpi(TwissString, 'etaprime') |
---|
176 | TD = twissline(THERING, 0, TWISSDATAIN, 1:(length(THERING)+1), 'Chrom'); |
---|
177 | else |
---|
178 | TD = twissline(THERING, 0, TWISSDATAIN, 1:(length(THERING)+1)); |
---|
179 | end |
---|
180 | |
---|
181 | % Tune |
---|
182 | Tune = TD(end).mu/2/pi; |
---|
183 | Tune = Tune(:); |
---|
184 | |
---|
185 | else |
---|
186 | % Storage ring |
---|
187 | if strcmpi(TwissString, 'Eta') || strcmpi(TwissString, 'Dispersion') |
---|
188 | % if nargout == 0 |
---|
189 | % % To get the default plot |
---|
190 | % modeldisp(Family1, DeviceList1, Family2, DeviceList2, 'Physics'); |
---|
191 | % else |
---|
192 | % [TwissX, TwissY, Sx, Sy] = modeldisp(Family1, DeviceList1, Family2, DeviceList2, 'Physics'); |
---|
193 | % end |
---|
194 | % if nargout >= 5 |
---|
195 | % Tune = modeltune; |
---|
196 | % end |
---|
197 | % return; |
---|
198 | [TD, Tune] = twissring(THERING, 0, 1:(length(THERING)+1), 'Chrom'); |
---|
199 | elseif strcmpi(TwissString, 'etaprime') |
---|
200 | [TD, Tune] = twissring(THERING, 0, 1:(length(THERING)+1), 'Chrom'); |
---|
201 | else |
---|
202 | [TD, Tune] = twissring(THERING, 0, 1:(length(THERING)+1)); |
---|
203 | end |
---|
204 | Tune = Tune(:); |
---|
205 | end |
---|
206 | |
---|
207 | |
---|
208 | if strcmpi(TwissString, 'Phase') |
---|
209 | TwissString = 'mu'; |
---|
210 | end |
---|
211 | |
---|
212 | |
---|
213 | if strcmpi(TwissString, 'beta') |
---|
214 | Twiss = cat(1,TD.beta); |
---|
215 | TwissXAll = Twiss(:,1); |
---|
216 | TwissYAll = Twiss(:,2); |
---|
217 | TwissX = Twiss(Index1,1); |
---|
218 | TwissY = Twiss(Index2,2); |
---|
219 | |
---|
220 | % Average of beginning and end of magnet |
---|
221 | %TwissXAll = [(Twiss(1:end-1,1)+Twiss(2:end,1))/2; Twiss(end,1)]; |
---|
222 | %TwissYAll = [(Twiss(1:end-1,2)+Twiss(2:end,2))/2; Twiss(end,2)]; |
---|
223 | %TwissX = (Twiss(Index1,1)+Twiss(Index1+1,1))/2; |
---|
224 | %TwissY = (Twiss(Index2,2)+Twiss(Index2+1,2))/2; |
---|
225 | |
---|
226 | YLabel1 = sprintf('\\beta_x [meters]'); |
---|
227 | YLabel2 = sprintf('\\beta_y [meters]'); |
---|
228 | Title1 = sprintf('\\beta-function (Tune = %.3f / %.3f)', Tune); |
---|
229 | elseif strcmpi(TwissString, 'mu') |
---|
230 | Twiss = cat(1,TD.mu); |
---|
231 | TwissXAll = Twiss(:,1); |
---|
232 | TwissYAll = Twiss(:,2); |
---|
233 | TwissX = Twiss(Index1,1); |
---|
234 | TwissY = Twiss(Index2,2); |
---|
235 | |
---|
236 | %TwissXAll = [(Twiss(1:end-1,1)+Twiss(2:end,1))/2; Twiss(end,1)]; |
---|
237 | %TwissYAll = [(Twiss(1:end-1,2)+Twiss(2:end,2))/2; Twiss(end,2)]; |
---|
238 | %TwissX = (Twiss(Index1,1)+Twiss(Index1+1,1))/2; |
---|
239 | %TwissY = (Twiss(Index2,2)+Twiss(Index2+1,2))/2; |
---|
240 | |
---|
241 | YLabel1 = sprintf('\\%s_x [radians]', 'phi'); |
---|
242 | YLabel2 = sprintf('\\%s_y [radians]', 'phi'); |
---|
243 | Title1 = sprintf('Phase Advance (Tune = %.3f / %.3f)', Tune); |
---|
244 | elseif strcmpi(TwissString, 'dispersion') || strcmpi(TwissString, 'disp') || strcmpi(TwissString, 'eta') |
---|
245 | %error('Use modeldisp'); |
---|
246 | Twiss = cat(2,TD.Dispersion)'; |
---|
247 | TwissXAll = Twiss(:,1); |
---|
248 | TwissYAll = Twiss(:,3); |
---|
249 | TwissX = Twiss(Index1,1); |
---|
250 | TwissY = Twiss(Index2,3); |
---|
251 | YLabel1 = sprintf('\\eta_x [m/(dp/p)]'); |
---|
252 | YLabel2 = sprintf('\\eta_y [m/(dp/p)]'); |
---|
253 | Title1 = sprintf('Dispersion'); |
---|
254 | elseif strcmpi(TwissString, 'etaprime') |
---|
255 | Twiss = cat(2,TD.Dispersion)'; |
---|
256 | TwissXAll = Twiss(:,2); |
---|
257 | TwissYAll = Twiss(:,4); |
---|
258 | TwissX = Twiss(Index1,2); |
---|
259 | TwissY = Twiss(Index2,4); |
---|
260 | YLabel1 = '\partial\eta_x / \partial \its'; |
---|
261 | YLabel2 = '\partial\eta_y / \partial \its'; |
---|
262 | Title1 = sprintf('Derivative of the Dispersion'); |
---|
263 | elseif strcmpi(TwissString, 'ClosedOrbit') || strcmpi(TwissString, 'x') |
---|
264 | iCavity = findcells(THERING,'Frequency'); |
---|
265 | |
---|
266 | if isempty(iCavity) %no cavity in AT model |
---|
267 | Twiss = cat(2,TD.ClosedOrbit)'; |
---|
268 | %Twiss = findsyncorbit(THERING, 0, ATIndexList); |
---|
269 | else |
---|
270 | % Cavity in AT model |
---|
271 | PassMethod = THERING{iCavity(1)}.PassMethod; |
---|
272 | for kk = 1:length(iCavity) |
---|
273 | THERING{iCavity(kk)}.PassMethod = 'IdentityPass'; % Off |
---|
274 | end |
---|
275 | |
---|
276 | C = 2.99792458e8; |
---|
277 | CavityFrequency = THERING{iCavity(1)}.Frequency; |
---|
278 | CavityHarmNumber = THERING{iCavity(1)}.HarmNumber; |
---|
279 | L = findspos(THERING,length(THERING)+1); |
---|
280 | f0 = C * CavityHarmNumber / L; |
---|
281 | DeltaRF = CavityFrequency - f0; % Hz |
---|
282 | Twiss = findsyncorbit(THERING, -C*DeltaRF*CavityHarmNumber/CavityFrequency^2, 1:length(THERING)+1); |
---|
283 | |
---|
284 | % Reset PassMethod |
---|
285 | for kk = 1:length(iCavity) |
---|
286 | %THERING{iCavity(kk)}.PassMethod = 'ThinCavityPass'; % On |
---|
287 | THERING{iCavity(kk)}.PassMethod = PassMethod; |
---|
288 | end |
---|
289 | |
---|
290 | Twiss = Twiss'; |
---|
291 | end |
---|
292 | TwissXAll = Twiss(:,1); |
---|
293 | TwissYAll = Twiss(:,3); |
---|
294 | TwissX = Twiss(Index1, 1); |
---|
295 | TwissY = Twiss(Index2, 3); |
---|
296 | YLabel1 = sprintf('x [meter]'); |
---|
297 | YLabel2 = sprintf('y [meter]'); |
---|
298 | Title1 = sprintf('Closed Orbit'); |
---|
299 | elseif strcmpi(TwissString, 'y') |
---|
300 | iCavity = findcells(THERING,'Frequency'); |
---|
301 | if isempty(iCavity) %no cavity in AT model |
---|
302 | Twiss = cat(2,TD.ClosedOrbit)'; |
---|
303 | %Twiss = findsyncorbit(THERING, 0, ATIndexList); |
---|
304 | else |
---|
305 | % Cavity in AT model |
---|
306 | PassMethod = THERING{iCavity}.PassMethod; |
---|
307 | THERING{iCavity}.PassMethod = 'IdentityPass'; % Off |
---|
308 | |
---|
309 | C = 2.99792458e8; |
---|
310 | CavityFrequency = THERING{iCavity}.Frequency; |
---|
311 | CavityHarmNumber = THERING{iCavity}.HarmNumber; |
---|
312 | L = findspos(THERING,length(THERING)+1); |
---|
313 | f0 = C * CavityHarmNumber / L; |
---|
314 | DeltaRF = CavityFrequency - f0; % Hz |
---|
315 | Twiss = findsyncorbit(THERING, -C*DeltaRF*CavityHarmNumber/CavityFrequency^2, 1:length(THERING)+1); |
---|
316 | |
---|
317 | % Reset PassMethod |
---|
318 | %THERING{iCavity}.PassMethod = 'ThinCavityPass'; % On |
---|
319 | THERING{iCavity}.PassMethod = PassMethod; |
---|
320 | |
---|
321 | Twiss = Twiss'; |
---|
322 | end |
---|
323 | TwissXAll = Twiss(:,3); |
---|
324 | TwissYAll = Twiss(:,1); |
---|
325 | TwissX = Twiss(Index1, 3); |
---|
326 | TwissY = Twiss(Index2, 1); |
---|
327 | YLabel1 = sprintf('y [meter]'); |
---|
328 | YLabel2 = sprintf('x [meter]'); |
---|
329 | Title1 = sprintf('Closed Orbit'); |
---|
330 | elseif strcmpi(TwissString, 'ClosedOrbitPrime') || strcmpi(TwissString, 'Px') |
---|
331 | Twiss = cat(2,TD.ClosedOrbit)'; |
---|
332 | TwissXAll = Twiss(:,2); |
---|
333 | TwissYAll = Twiss(:,4); |
---|
334 | TwissX = Twiss(Index1, 2); |
---|
335 | TwissY = Twiss(Index2, 4); |
---|
336 | YLabel1 = 'P_x'; |
---|
337 | YLabel2 = 'P_y'; |
---|
338 | Title1 = 'Derivative of the Closed Orbit'; |
---|
339 | elseif strcmpi(TwissString, 'Py') |
---|
340 | Twiss = cat(2,TD.ClosedOrbit)'; |
---|
341 | TwissXAll = Twiss(:,4); |
---|
342 | TwissYAll = Twiss(:,2); |
---|
343 | TwissX = Twiss(Index1, 4); |
---|
344 | TwissY = Twiss(Index2, 2); |
---|
345 | YLabel1 = 'P_y'; |
---|
346 | YLabel2 = 'P_x'; |
---|
347 | Title1 = 'Derivative of the Closed Orbit'; |
---|
348 | else |
---|
349 | Twiss = cat(1,TD.(TwissString)); |
---|
350 | TwissXAll = Twiss(:,1); |
---|
351 | TwissYAll = Twiss(:,2); |
---|
352 | TwissX = Twiss(Index1, 1); |
---|
353 | TwissY = Twiss(Index2, 2); |
---|
354 | YLabel1 = sprintf('\\%s_x', TwissString); |
---|
355 | YLabel2 = sprintf('\\%s_y', TwissString); |
---|
356 | Title1 = sprintf('\\%s-functions', TwissString); |
---|
357 | end |
---|
358 | |
---|
359 | |
---|
360 | % Longitudinal position |
---|
361 | SAll = cat(1,TD.SPos); |
---|
362 | Sx = SAll(Index1); |
---|
363 | Sy = SAll(Index2); |
---|
364 | |
---|
365 | Sx = Sx(:); |
---|
366 | Sy = Sy(:); |
---|
367 | SAll = SAll(:); |
---|
368 | |
---|
369 | % Twiss = Twiss; |
---|
370 | % TwissX = TwissX; |
---|
371 | % TwissY = TwissY; |
---|
372 | % TwissXAll = TwissXAll; |
---|
373 | % TwissYAll = TwissYAll; |
---|
374 | |
---|
375 | |
---|
376 | % Output |
---|
377 | if nargout == 0 |
---|
378 | % Plot |
---|
379 | if strcmpi(TwissString, 'mu') |
---|
380 | % Keep phase plot between -pi and pi |
---|
381 | xall = []; |
---|
382 | sxall= []; |
---|
383 | for i = 1:length(TwissXAll) |
---|
384 | if TwissXAll(i) > 2*pi |
---|
385 | TwissXAll(i:end) = TwissXAll(i:end) - 2*pi; |
---|
386 | xall = [xall; 2*pi; 0]; |
---|
387 | sxall = [sxall; mean(SAll(i-1:i)); mean(SAll(i-1:i))]; |
---|
388 | xall = [xall; TwissXAll(i)]; |
---|
389 | sxall = [sxall; SAll(i)]; |
---|
390 | else |
---|
391 | xall = [xall; TwissXAll(i)]; |
---|
392 | sxall = [sxall; SAll(i)]; |
---|
393 | end |
---|
394 | end |
---|
395 | TwissX = rem(TwissX,2*pi); |
---|
396 | |
---|
397 | yall = []; |
---|
398 | syall= []; |
---|
399 | for i = 1:length(TwissYAll) |
---|
400 | if TwissYAll(i) > 2*pi |
---|
401 | TwissYAll(i:end) = TwissYAll(i:end) - 2*pi; |
---|
402 | yall = [yall; 2*pi; 0]; |
---|
403 | syall = [syall; mean(SAll(i-1:i)); mean(SAll(i-1:i))]; |
---|
404 | yall = [yall; TwissYAll(i)]; |
---|
405 | syall = [syall; SAll(i)]; |
---|
406 | else |
---|
407 | yall = [yall; TwissYAll(i)]; |
---|
408 | syall = [syall; SAll(i)]; |
---|
409 | end |
---|
410 | end |
---|
411 | TwissY = rem(TwissY,2*pi); |
---|
412 | |
---|
413 | clf reset |
---|
414 | h1 = subplot(5,1,[1 2]); |
---|
415 | % plot Twiss paramaters |
---|
416 | plot(sxall, xall, '-b'); |
---|
417 | if strcmpi(Family1,'All') |
---|
418 | xlabel('Position [meters]'); |
---|
419 | else |
---|
420 | hold on; |
---|
421 | plot(Sx, TwissX, '.b'); |
---|
422 | hold off; |
---|
423 | xlabel(sprintf('%s Position [meters]', Family1)); |
---|
424 | end |
---|
425 | ylabel(YLabel1); |
---|
426 | title(Title1, 'Fontsize', 12); |
---|
427 | yaxis([0 2*pi]); |
---|
428 | xaxis([SAll(1) SAll(end)]); |
---|
429 | |
---|
430 | % plot lattice |
---|
431 | h2 = subplot(5,1,3); |
---|
432 | drawlattice; |
---|
433 | |
---|
434 | h3 = subplot(5,1,[4 5]); |
---|
435 | % plot Twiss paramaters |
---|
436 | plot(syall, yall, '-b'); |
---|
437 | if strcmpi(Family2,'All') |
---|
438 | xlabel('Position [meters]'); |
---|
439 | else |
---|
440 | hold on; |
---|
441 | plot(Sy, TwissY, '.b'); |
---|
442 | hold off; |
---|
443 | xlabel(sprintf('%s Position [meters]', Family2)); |
---|
444 | end |
---|
445 | ylabel(YLabel2); |
---|
446 | yaxis([0 2*pi]); |
---|
447 | xaxis([SAll(1) SAll(end)]); |
---|
448 | |
---|
449 | linkaxes([h1 h2 h3],'x') |
---|
450 | set([h1 h2 h3],'XGrid','On','YGrid','On'); |
---|
451 | else |
---|
452 | clf reset |
---|
453 | h1 = subplot(5,1,[1 2]); |
---|
454 | % plot Twiss paramaters |
---|
455 | plot(SAll, TwissXAll, '-b'); |
---|
456 | if strcmpi(Family1,'All') |
---|
457 | xlabel('Position [meters]'); |
---|
458 | else |
---|
459 | hold on; |
---|
460 | plot(Sx, TwissX, '.b'); |
---|
461 | hold off; |
---|
462 | xlabel(sprintf('%s Position [meters]', Family1)); |
---|
463 | end |
---|
464 | ylabel(YLabel1); |
---|
465 | title(Title1, 'Fontsize', 12); |
---|
466 | xaxis([SAll(1) SAll(end)]); |
---|
467 | |
---|
468 | % plot lattice |
---|
469 | h2 = subplot(5,1,3); |
---|
470 | drawlattice; |
---|
471 | |
---|
472 | h3 = subplot(5,1,[4 5]); |
---|
473 | % plot Twiss parmaters |
---|
474 | plot(SAll, TwissYAll, '-b'); |
---|
475 | if strcmpi(Family2,'All') |
---|
476 | xlabel('Position [meters]'); |
---|
477 | else |
---|
478 | hold on; |
---|
479 | plot(Sy, TwissY, '.b'); |
---|
480 | hold off; |
---|
481 | xlabel(sprintf('%s Position [meters]', Family2)); |
---|
482 | end |
---|
483 | ylabel(YLabel2); |
---|
484 | xaxis([SAll(1) SAll(end)]); |
---|
485 | |
---|
486 | linkaxes([h1 h2 h3],'x') |
---|
487 | set([h1 h2 h3],'XGrid','On','YGrid','On'); |
---|
488 | |
---|
489 | grid on; |
---|
490 | end |
---|
491 | |
---|
492 | if DrawLatticeFlag |
---|
493 | subplot(2,1,1); |
---|
494 | hold on |
---|
495 | a = axis; |
---|
496 | drawlattice(a(4)-.08*(a(4)-a(3)),.05*(a(4)-a(3))); |
---|
497 | %drawlattice(a(4)-.5*(a(4)-a(3)),.05*(a(4)-a(3))); |
---|
498 | hold off; |
---|
499 | %subplot(2,1,2); |
---|
500 | %hold on |
---|
501 | %a = axis; |
---|
502 | %drawlattice(a(4)-.08*(a(4)-a(3)),.05*(a(4)-a(3))); |
---|
503 | %hold off; |
---|
504 | |
---|
505 | % subplot(2,1,1); |
---|
506 | % xlabel(''); |
---|
507 | % |
---|
508 | % h = subplot(17,1,9); |
---|
509 | % drawlattice(0, 1, h); |
---|
510 | % %set(h,'Visible','Off'); |
---|
511 | % set(h,'Color','None'); |
---|
512 | % set(h,'XMinorTick','Off'); |
---|
513 | % set(h,'XMinorGrid','Off'); |
---|
514 | % set(h,'YMinorTick','Off'); |
---|
515 | % set(h,'YMinorGrid','Off'); |
---|
516 | % set(h,'XTickLabel',[]); |
---|
517 | % set(h,'YTickLabel',[]); |
---|
518 | % set(h,'XLim', [0 Cir]); |
---|
519 | % set(h,'YLim', [-1.5 1.5]); |
---|
520 | end |
---|
521 | end |
---|