source: MML/trunk/machine/SOLEIL/StorageRing/bpm/analbpmresp.m @ 17

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

To have a stable version on the server.

  • Property svn:executable set to *
File size: 8.4 KB
Line 
1function 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
13BPMxGain = getgain('BPMx');
14BPMzGain = getgain('BPMz');
15
16SectorLength = 16.40;
17Circumference = 12*SectorLength;
18idbpms = IDBPMs;
19idbpms(1) = idbpms(1)-Circumference;
20
21if 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
43elseif nargin == 1
44   FileName = Sx;
45   if isstr(FileName)
46      load(FileName);
47   else
48      error('FileName must be a string.');
49   end
50end
51
52
53if size(Sx) == [96 96]
54   % input OK
55elseif size(Sx) == [96 94]
56   S = zeros(96,96);
57   S(:,HCMelem) = Sx;
58   Sx = S;
59else
60   error('Sx is the wrong size.');
61end
62
63
64if size(Sy) == [96 96]
65   % input OK
66elseif size(Sy) == [96 70]
67   S = zeros(96,96);
68   S(:,VCMelem) = Sy;
69   Sy = S;
70else
71   error('Sy is the wrong size.');
72end
73
74
75% Horizontal
76
77% New S-matrix
78Sxnew=zeros(size(Sxmat));
79for 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));
87end
88
89
90for 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
149end
150
151figure(1);
152subplot(4,1,1);
153xlabel('BPM Position [meters]');
154ylabel('Mag #1');
155title('Horizontal Corrector Magnets (S-matrix Data: mm/amp)');
156
157subplot(4,1,2);
158xlabel('BPM Position [meters]');
159ylabel('Mag #2');
160
161subplot(4,1,3);
162xlabel('BPM Position [meters]');
163ylabel('Mag #3');
164
165subplot(4,1,4);
166xlabel('BPM Position [meters]');
167ylabel('Mag #4');
168
169figure(2);
170subplot(4,1,1);
171xlabel('BPM Position [meters]');
172ylabel('Mag #5');
173title('Horizontal Corrector Magnets (S-matrix Data: mm/amp)');
174
175subplot(4,1,2);
176xlabel('BPM Position [meters]');
177ylabel('Mag #6');
178
179subplot(4,1,3);
180xlabel('BPM Position [meters]');
181ylabel('Mag #7');
182
183subplot(4,1,4);
184xlabel('BPM Position [meters]');
185ylabel('Mag #8');
186
187
188figure(5);
189subplot(4,1,1);
190xlabel('BPM Position [meters]');
191ylabel('Mag #1');
192title('Horizontal Corrector Magnets (Calibrated S-matrix Data: mm/mrad)');
193
194subplot(4,1,2);
195xlabel('BPM Position [meters]');
196ylabel('Mag #2');
197
198subplot(4,1,3);
199xlabel('BPM Position [meters]');
200ylabel('Mag #3');
201
202subplot(4,1,4);
203xlabel('BPM Position [meters]');
204ylabel('Mag #4');
205
206figure(6);
207subplot(4,1,1);
208xlabel('BPM Position [meters]');
209ylabel('Mag #5');
210title('Horizontal Corrector Magnets (Calibrated S-matrix Data: mm/mrad)');
211
212subplot(4,1,2);
213xlabel('BPM Position [meters]');
214ylabel('Mag #6');
215
216subplot(4,1,3);
217xlabel('BPM Position [meters]');
218ylabel('Mag #7');
219
220subplot(4,1,4);
221xlabel('BPM Position [meters]');
222ylabel('Mag #8');
223
224
225figure(9);
226subplot(4,1,1);
227xlabel('IDBPM Position [meters]');
228ylabel('Mag #1');
229title('Horizontal Corrector Magnets');
230
231subplot(4,1,2);
232xlabel('IDBPM Position [meters]');
233ylabel('Mag #2');
234
235subplot(4,1,3);
236xlabel('IDBPM Position [meters]');
237ylabel('Mag #3');
238
239subplot(4,1,4);
240xlabel('IDBPM Position [meters]');
241ylabel('Mag #4');
242
243figure(10);
244subplot(4,1,1);
245xlabel('IDBPM Position [meters]');
246ylabel('Mag #5');
247title('Horizontal Corrector Magnets');
248
249subplot(4,1,2);
250xlabel('IDBPM Position [meters]');
251ylabel('Mag #6');
252
253subplot(4,1,3);
254xlabel('IDBPM Position [meters]');
255ylabel('Mag #7');
256
257subplot(4,1,4);
258xlabel('IDBPM Position [meters]');
259ylabel('Mag #8');
260
261
262
263% Vertical
264
265% New S-matrix
266Synew=zeros(size(Symat));
267for 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));
273end
274
275for 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
337end
338
339
340figure(3);
341subplot(4,1,1);
342xlabel('BPM Position [meters]');
343ylabel('Mag #1');
344title('Vertical Corrector Magnets (S-matrix Data: mm/amp)');
345
346subplot(4,1,2);
347xlabel('BPM Position [meters]');
348ylabel('Mag #2');
349
350subplot(4,1,3);
351xlabel('BPM Position [meters]');
352ylabel('Mag #3');
353
354subplot(4,1,4);
355xlabel('BPM Position [meters]');
356ylabel('Mag #4');
357
358figure(4);
359subplot(4,1,1);
360xlabel('BPM Position [meters]');
361ylabel('Mag #5');
362title('Vertical Corrector Magnets (S-matrix Data: mm/amp)');
363
364subplot(4,1,2);
365xlabel('BPM Position [meters]');
366ylabel('Mag #6');
367
368subplot(4,1,3);
369xlabel('BPM Position [meters]');
370ylabel('Mag #7');
371
372subplot(4,1,4);
373xlabel('BPM Position [meters]');
374ylabel('Mag #8');
375
376
377
378figure(7);
379subplot(4,1,1);
380xlabel('BPM Position [meters]');
381ylabel('Mag #1');
382title('Vertical Corrector Magnets (Calibrated S-matrix Data: mm/mrad)');
383
384subplot(4,1,2);
385xlabel('BPM Position [meters]');
386ylabel('Mag #2');
387
388subplot(4,1,3);
389xlabel('BPM Position [meters]');
390ylabel('Mag #3');
391
392subplot(4,1,4);
393xlabel('BPM Position [meters]');
394ylabel('Mag #4');
395
396figure(8);
397subplot(4,1,1);
398xlabel('BPM Position [meters]');
399ylabel('Mag #5');
400title('Vertical Corrector Magnets (Calibrated S-matrix Data: mm/mrad)');
401
402subplot(4,1,2);
403xlabel('BPM Position [meters]');
404ylabel('Mag #6');
405
406subplot(4,1,3);
407xlabel('BPM Position [meters]');
408ylabel('Mag #7');
409
410subplot(4,1,4);
411xlabel('BPM Position [meters]');
412ylabel('Mag #8');
413
414figure(11);
415subplot(4,1,1);
416xlabel('IDBPM Position [meters]');
417ylabel('Mag #1');
418title('Vertical Corrector Magnets');
419
420subplot(4,1,2);
421xlabel('IDBPM Position [meters]');
422ylabel('Mag #2');
423
424subplot(4,1,3);
425xlabel('IDBPM Position [meters]');
426ylabel('Mag #3');
427
428subplot(4,1,4);
429xlabel('IDBPM Position [meters]');
430ylabel('Mag #4');
431
432figure(12);
433subplot(4,1,1);
434xlabel('IDBPM Position [meters]');
435ylabel('Mag #5');
436title('Vertical Corrector Magnets');
437
438subplot(4,1,2);
439xlabel('IDBPM Position [meters]');
440ylabel('Mag #6');
441
442subplot(4,1,3);
443xlabel('IDBPM Position [meters]');
444ylabel('Mag #7');
445
446subplot(4,1,4);
447xlabel('IDBPM Position [meters]');
448ylabel('Mag #8');
449
450
451
452figure(1); orient tall
453figure(2); orient tall
454figure(3); orient tall
455figure(4); orient tall
456figure(5); orient tall
457figure(6); orient tall
458figure(7); orient tall
459figure(8); orient tall
460figure(9); orient tall
461figure(10); orient tall
462
Note: See TracBrowser for help on using the repository browser.