1 | function analbpmresp(Sx, Sy) |
---|
2 | %ANALBPMRESP - Analyses bpm response matrix |
---|
3 | % analbpmresp(Sx, Sy) |
---|
4 | % or |
---|
5 | % analbpmresp(FileName) |
---|
6 | % |
---|
7 | % Written at SPEAR3 |
---|
8 | % Modified Laurent S. Nadolski |
---|
9 | % |
---|
10 | % TODO |
---|
11 | % Need adaptation for SOLEIL |
---|
12 | |
---|
13 | BPMxGain = getgain('BPMx'); |
---|
14 | BPMzGain = getgain('BPMz'); |
---|
15 | |
---|
16 | SectorLength = 16.40; |
---|
17 | Circumference = 12*SectorLength; |
---|
18 | idbpms = IDBPMs; |
---|
19 | idbpms(1) = idbpms(1)-Circumference; |
---|
20 | |
---|
21 | if nargin == 0 |
---|
22 | Flag = menu('Which S-matrix?','From a file.',sprintf('%.1f GeV Default',GLOBAL_SR_GEV),' Exit '); |
---|
23 | if Flag == 1 |
---|
24 | CurrentDir = pwd; |
---|
25 | gotodata |
---|
26 | cd smatrix |
---|
27 | [FileName, PathName] = uigetfile('*.*', 'Choose the desired S-matrix file.'); |
---|
28 | eval(['cd ',CurrentDir]); |
---|
29 | if FileName == 0 |
---|
30 | disp(' Function canceled.'); |
---|
31 | disp(' '); |
---|
32 | return |
---|
33 | else |
---|
34 | load([PathName, FileName]); |
---|
35 | end |
---|
36 | elseif Flag == 2 |
---|
37 | Sx = Sxmat; |
---|
38 | Sy = Symat; |
---|
39 | else |
---|
40 | disp(' Function canceled.'); disp(' '); |
---|
41 | return |
---|
42 | end |
---|
43 | elseif nargin == 1 |
---|
44 | FileName = Sx; |
---|
45 | if isstr(FileName) |
---|
46 | load(FileName); |
---|
47 | else |
---|
48 | error('FileName must be a string.'); |
---|
49 | end |
---|
50 | end |
---|
51 | |
---|
52 | |
---|
53 | if size(Sx) == [96 96] |
---|
54 | % input OK |
---|
55 | elseif size(Sx) == [96 94] |
---|
56 | S = zeros(96,96); |
---|
57 | S(:,HCMelem) = Sx; |
---|
58 | Sx = S; |
---|
59 | else |
---|
60 | error('Sx is the wrong size.'); |
---|
61 | end |
---|
62 | |
---|
63 | |
---|
64 | if size(Sy) == [96 96] |
---|
65 | % input OK |
---|
66 | elseif size(Sy) == [96 70] |
---|
67 | S = zeros(96,96); |
---|
68 | S(:,VCMelem) = Sy; |
---|
69 | Sy = S; |
---|
70 | else |
---|
71 | error('Sy is the wrong size.'); |
---|
72 | end |
---|
73 | |
---|
74 | |
---|
75 | % Horizontal |
---|
76 | |
---|
77 | % New S-matrix |
---|
78 | Sxnew=zeros(size(Sxmat)); |
---|
79 | for i = HCMelem' |
---|
80 | %size(BPMxGain) |
---|
81 | %size(Sx(:,i)) |
---|
82 | % Remove BPM eain effect |
---|
83 | Sxnew(:,i) = Sx(:,i) .* BPMxGain; |
---|
84 | |
---|
85 | % Remove corrector magnet gain effect (convert to mm/mrad) |
---|
86 | Sxnew(:,i) = Sxnew(:,i) / (1000*amps2rad('HCM',1,i)); |
---|
87 | end |
---|
88 | |
---|
89 | |
---|
90 | for Mag = 1:8 |
---|
91 | S=[]; |
---|
92 | Snew=[]; |
---|
93 | |
---|
94 | if Mag == 1 |
---|
95 | m = 2; |
---|
96 | else |
---|
97 | m = 1; |
---|
98 | end |
---|
99 | |
---|
100 | if Mag == 8 |
---|
101 | n = 11; |
---|
102 | else |
---|
103 | n = 12; |
---|
104 | end |
---|
105 | |
---|
106 | for i = m:n |
---|
107 | S(:,i-m+1) = Sx(rem((BPMelem-1)+8*(i-1),96)+1, Mag+8*(i-1)); |
---|
108 | Snew(:,i-m+1) = Sxnew(rem((BPMelem-1)+8*(i-1),96)+1, Mag+8*(i-1)); |
---|
109 | |
---|
110 | ii = rem(((1:24)'-1)+2*(i-1),24)+1; |
---|
111 | SID(:,i-m+1) = SIDxmat(ii, Mag+8*(i-1)); |
---|
112 | |
---|
113 | % Set missing IDBPMs to NaN |
---|
114 | iNaN=find(SID(:,i-m+1)==0); |
---|
115 | SID(iNaN,i-m+1) = NaN; |
---|
116 | end |
---|
117 | |
---|
118 | if Mag == 9 |
---|
119 | break |
---|
120 | end |
---|
121 | |
---|
122 | if Mag <= 4 |
---|
123 | figure(1); |
---|
124 | subplot(4,1, Mag); |
---|
125 | plot(BPMs, S); |
---|
126 | |
---|
127 | figure(5); |
---|
128 | subplot(4,1, Mag); |
---|
129 | plot(BPMs, Snew); |
---|
130 | |
---|
131 | figure(9); |
---|
132 | subplot(4,1, Mag); |
---|
133 | plot(idbpms, SID); |
---|
134 | axis tight |
---|
135 | else |
---|
136 | figure(2); |
---|
137 | subplot(4,1, Mag-4); |
---|
138 | plot(BPMs, S); |
---|
139 | |
---|
140 | figure(6); |
---|
141 | subplot(4,1, Mag-4); |
---|
142 | plot(BPMs, Snew); |
---|
143 | |
---|
144 | figure(10); |
---|
145 | subplot(4,1, Mag-4); |
---|
146 | plot(idbpms, SID); |
---|
147 | axis tight |
---|
148 | end |
---|
149 | end |
---|
150 | |
---|
151 | figure(1); |
---|
152 | subplot(4,1,1); |
---|
153 | xlabel('BPM Position [meters]'); |
---|
154 | ylabel('Mag #1'); |
---|
155 | title('Horizontal Corrector Magnets (S-matrix Data: mm/amp)'); |
---|
156 | |
---|
157 | subplot(4,1,2); |
---|
158 | xlabel('BPM Position [meters]'); |
---|
159 | ylabel('Mag #2'); |
---|
160 | |
---|
161 | subplot(4,1,3); |
---|
162 | xlabel('BPM Position [meters]'); |
---|
163 | ylabel('Mag #3'); |
---|
164 | |
---|
165 | subplot(4,1,4); |
---|
166 | xlabel('BPM Position [meters]'); |
---|
167 | ylabel('Mag #4'); |
---|
168 | |
---|
169 | figure(2); |
---|
170 | subplot(4,1,1); |
---|
171 | xlabel('BPM Position [meters]'); |
---|
172 | ylabel('Mag #5'); |
---|
173 | title('Horizontal Corrector Magnets (S-matrix Data: mm/amp)'); |
---|
174 | |
---|
175 | subplot(4,1,2); |
---|
176 | xlabel('BPM Position [meters]'); |
---|
177 | ylabel('Mag #6'); |
---|
178 | |
---|
179 | subplot(4,1,3); |
---|
180 | xlabel('BPM Position [meters]'); |
---|
181 | ylabel('Mag #7'); |
---|
182 | |
---|
183 | subplot(4,1,4); |
---|
184 | xlabel('BPM Position [meters]'); |
---|
185 | ylabel('Mag #8'); |
---|
186 | |
---|
187 | |
---|
188 | figure(5); |
---|
189 | subplot(4,1,1); |
---|
190 | xlabel('BPM Position [meters]'); |
---|
191 | ylabel('Mag #1'); |
---|
192 | title('Horizontal Corrector Magnets (Calibrated S-matrix Data: mm/mrad)'); |
---|
193 | |
---|
194 | subplot(4,1,2); |
---|
195 | xlabel('BPM Position [meters]'); |
---|
196 | ylabel('Mag #2'); |
---|
197 | |
---|
198 | subplot(4,1,3); |
---|
199 | xlabel('BPM Position [meters]'); |
---|
200 | ylabel('Mag #3'); |
---|
201 | |
---|
202 | subplot(4,1,4); |
---|
203 | xlabel('BPM Position [meters]'); |
---|
204 | ylabel('Mag #4'); |
---|
205 | |
---|
206 | figure(6); |
---|
207 | subplot(4,1,1); |
---|
208 | xlabel('BPM Position [meters]'); |
---|
209 | ylabel('Mag #5'); |
---|
210 | title('Horizontal Corrector Magnets (Calibrated S-matrix Data: mm/mrad)'); |
---|
211 | |
---|
212 | subplot(4,1,2); |
---|
213 | xlabel('BPM Position [meters]'); |
---|
214 | ylabel('Mag #6'); |
---|
215 | |
---|
216 | subplot(4,1,3); |
---|
217 | xlabel('BPM Position [meters]'); |
---|
218 | ylabel('Mag #7'); |
---|
219 | |
---|
220 | subplot(4,1,4); |
---|
221 | xlabel('BPM Position [meters]'); |
---|
222 | ylabel('Mag #8'); |
---|
223 | |
---|
224 | |
---|
225 | figure(9); |
---|
226 | subplot(4,1,1); |
---|
227 | xlabel('IDBPM Position [meters]'); |
---|
228 | ylabel('Mag #1'); |
---|
229 | title('Horizontal Corrector Magnets'); |
---|
230 | |
---|
231 | subplot(4,1,2); |
---|
232 | xlabel('IDBPM Position [meters]'); |
---|
233 | ylabel('Mag #2'); |
---|
234 | |
---|
235 | subplot(4,1,3); |
---|
236 | xlabel('IDBPM Position [meters]'); |
---|
237 | ylabel('Mag #3'); |
---|
238 | |
---|
239 | subplot(4,1,4); |
---|
240 | xlabel('IDBPM Position [meters]'); |
---|
241 | ylabel('Mag #4'); |
---|
242 | |
---|
243 | figure(10); |
---|
244 | subplot(4,1,1); |
---|
245 | xlabel('IDBPM Position [meters]'); |
---|
246 | ylabel('Mag #5'); |
---|
247 | title('Horizontal Corrector Magnets'); |
---|
248 | |
---|
249 | subplot(4,1,2); |
---|
250 | xlabel('IDBPM Position [meters]'); |
---|
251 | ylabel('Mag #6'); |
---|
252 | |
---|
253 | subplot(4,1,3); |
---|
254 | xlabel('IDBPM Position [meters]'); |
---|
255 | ylabel('Mag #7'); |
---|
256 | |
---|
257 | subplot(4,1,4); |
---|
258 | xlabel('IDBPM Position [meters]'); |
---|
259 | ylabel('Mag #8'); |
---|
260 | |
---|
261 | |
---|
262 | |
---|
263 | % Vertical |
---|
264 | |
---|
265 | % New S-matrix |
---|
266 | Synew=zeros(size(Symat)); |
---|
267 | for i = VCMelem' |
---|
268 | % Remove BPM eain effect |
---|
269 | Synew(:,i) = Sy(:,i) .* BPMzGain; |
---|
270 | |
---|
271 | % Remove corrector magnet gain effect (convert to mm/mrad) |
---|
272 | Synew(:,i) = Synew(:,i) / (1000*amps2rad('VCM',1,i)); |
---|
273 | end |
---|
274 | |
---|
275 | for Mag = [1 2 4 5 7 8] |
---|
276 | S=[]; |
---|
277 | Snew=[]; |
---|
278 | |
---|
279 | SID=[]; |
---|
280 | SIDnew=[]; |
---|
281 | |
---|
282 | if Mag == 1 |
---|
283 | m = 2; |
---|
284 | else |
---|
285 | m = 1; |
---|
286 | end |
---|
287 | |
---|
288 | if Mag == 8 |
---|
289 | n = 11; |
---|
290 | else |
---|
291 | n = 12; |
---|
292 | end |
---|
293 | |
---|
294 | for i = m:n |
---|
295 | S(:,i-m+1) = Sy(rem((BPMelem-1)+8*(i-1),96)+1, Mag+8*(i-1)); |
---|
296 | Snew(:,i-m+1) = Synew(rem((BPMelem-1)+8*(i-1),96)+1, Mag+8*(i-1)); |
---|
297 | |
---|
298 | ii = rem(((1:24)'-1)+2*(i-1),24)+1; |
---|
299 | SID(:,i-m+1) = SIDymat(ii, Mag+8*(i-1)); |
---|
300 | |
---|
301 | % Set missing IDBPMs to NaN |
---|
302 | iNaN=find(SID(:,i-m+1)==0); |
---|
303 | SID(iNaN,i-m+1) = NaN; |
---|
304 | end |
---|
305 | |
---|
306 | if Mag == 9 |
---|
307 | break |
---|
308 | end |
---|
309 | |
---|
310 | if Mag <= 4 |
---|
311 | figure(3); |
---|
312 | subplot(4,1, Mag); |
---|
313 | plot(BPMs, S); |
---|
314 | |
---|
315 | figure(7); |
---|
316 | subplot(4,1, Mag); |
---|
317 | plot(BPMs, Snew); |
---|
318 | |
---|
319 | figure(11); |
---|
320 | subplot(4,1, Mag); |
---|
321 | plot(idbpms, SID); |
---|
322 | axis tight |
---|
323 | else |
---|
324 | figure(4); |
---|
325 | subplot(4,1, Mag-4); |
---|
326 | plot(BPMs, S); |
---|
327 | |
---|
328 | figure(8); |
---|
329 | subplot(4,1, Mag-4); |
---|
330 | plot(BPMs, Snew); |
---|
331 | |
---|
332 | figure(12); |
---|
333 | subplot(4,1, Mag-4); |
---|
334 | plot(idbpms, SID); |
---|
335 | axis tight |
---|
336 | end |
---|
337 | end |
---|
338 | |
---|
339 | |
---|
340 | figure(3); |
---|
341 | subplot(4,1,1); |
---|
342 | xlabel('BPM Position [meters]'); |
---|
343 | ylabel('Mag #1'); |
---|
344 | title('Vertical Corrector Magnets (S-matrix Data: mm/amp)'); |
---|
345 | |
---|
346 | subplot(4,1,2); |
---|
347 | xlabel('BPM Position [meters]'); |
---|
348 | ylabel('Mag #2'); |
---|
349 | |
---|
350 | subplot(4,1,3); |
---|
351 | xlabel('BPM Position [meters]'); |
---|
352 | ylabel('Mag #3'); |
---|
353 | |
---|
354 | subplot(4,1,4); |
---|
355 | xlabel('BPM Position [meters]'); |
---|
356 | ylabel('Mag #4'); |
---|
357 | |
---|
358 | figure(4); |
---|
359 | subplot(4,1,1); |
---|
360 | xlabel('BPM Position [meters]'); |
---|
361 | ylabel('Mag #5'); |
---|
362 | title('Vertical Corrector Magnets (S-matrix Data: mm/amp)'); |
---|
363 | |
---|
364 | subplot(4,1,2); |
---|
365 | xlabel('BPM Position [meters]'); |
---|
366 | ylabel('Mag #6'); |
---|
367 | |
---|
368 | subplot(4,1,3); |
---|
369 | xlabel('BPM Position [meters]'); |
---|
370 | ylabel('Mag #7'); |
---|
371 | |
---|
372 | subplot(4,1,4); |
---|
373 | xlabel('BPM Position [meters]'); |
---|
374 | ylabel('Mag #8'); |
---|
375 | |
---|
376 | |
---|
377 | |
---|
378 | figure(7); |
---|
379 | subplot(4,1,1); |
---|
380 | xlabel('BPM Position [meters]'); |
---|
381 | ylabel('Mag #1'); |
---|
382 | title('Vertical Corrector Magnets (Calibrated S-matrix Data: mm/mrad)'); |
---|
383 | |
---|
384 | subplot(4,1,2); |
---|
385 | xlabel('BPM Position [meters]'); |
---|
386 | ylabel('Mag #2'); |
---|
387 | |
---|
388 | subplot(4,1,3); |
---|
389 | xlabel('BPM Position [meters]'); |
---|
390 | ylabel('Mag #3'); |
---|
391 | |
---|
392 | subplot(4,1,4); |
---|
393 | xlabel('BPM Position [meters]'); |
---|
394 | ylabel('Mag #4'); |
---|
395 | |
---|
396 | figure(8); |
---|
397 | subplot(4,1,1); |
---|
398 | xlabel('BPM Position [meters]'); |
---|
399 | ylabel('Mag #5'); |
---|
400 | title('Vertical Corrector Magnets (Calibrated S-matrix Data: mm/mrad)'); |
---|
401 | |
---|
402 | subplot(4,1,2); |
---|
403 | xlabel('BPM Position [meters]'); |
---|
404 | ylabel('Mag #6'); |
---|
405 | |
---|
406 | subplot(4,1,3); |
---|
407 | xlabel('BPM Position [meters]'); |
---|
408 | ylabel('Mag #7'); |
---|
409 | |
---|
410 | subplot(4,1,4); |
---|
411 | xlabel('BPM Position [meters]'); |
---|
412 | ylabel('Mag #8'); |
---|
413 | |
---|
414 | figure(11); |
---|
415 | subplot(4,1,1); |
---|
416 | xlabel('IDBPM Position [meters]'); |
---|
417 | ylabel('Mag #1'); |
---|
418 | title('Vertical Corrector Magnets'); |
---|
419 | |
---|
420 | subplot(4,1,2); |
---|
421 | xlabel('IDBPM Position [meters]'); |
---|
422 | ylabel('Mag #2'); |
---|
423 | |
---|
424 | subplot(4,1,3); |
---|
425 | xlabel('IDBPM Position [meters]'); |
---|
426 | ylabel('Mag #3'); |
---|
427 | |
---|
428 | subplot(4,1,4); |
---|
429 | xlabel('IDBPM Position [meters]'); |
---|
430 | ylabel('Mag #4'); |
---|
431 | |
---|
432 | figure(12); |
---|
433 | subplot(4,1,1); |
---|
434 | xlabel('IDBPM Position [meters]'); |
---|
435 | ylabel('Mag #5'); |
---|
436 | title('Vertical Corrector Magnets'); |
---|
437 | |
---|
438 | subplot(4,1,2); |
---|
439 | xlabel('IDBPM Position [meters]'); |
---|
440 | ylabel('Mag #6'); |
---|
441 | |
---|
442 | subplot(4,1,3); |
---|
443 | xlabel('IDBPM Position [meters]'); |
---|
444 | ylabel('Mag #7'); |
---|
445 | |
---|
446 | subplot(4,1,4); |
---|
447 | xlabel('IDBPM Position [meters]'); |
---|
448 | ylabel('Mag #8'); |
---|
449 | |
---|
450 | |
---|
451 | |
---|
452 | figure(1); orient tall |
---|
453 | figure(2); orient tall |
---|
454 | figure(3); orient tall |
---|
455 | figure(4); orient tall |
---|
456 | figure(5); orient tall |
---|
457 | figure(6); orient tall |
---|
458 | figure(7); orient tall |
---|
459 | figure(8); orient tall |
---|
460 | figure(9); orient tall |
---|
461 | figure(10); orient tall |
---|
462 | |
---|