source: MML/trunk/mml/plotbpmresp.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: 15.1 KB
Line 
1function plotbpmresp(varargin)
2%PLOTBPMRESP - Plots the orbit response matrix in various ways
3%  plotbpmresp
4%
5%  INPUTS
6%  1. 'Absolute' {Default} or 'Error' (subtract the model)
7%  2. PlotType: '3D', 'Rows', 'Columns', 'CMSpace', 'BPMSpace'  {Default: '3D'}
8%  3. Plane:   'All', 'xx', 'x{y,z}', '{y,z}x', '{yy,zz}'  {Default: 'All' for '3D', else 'xx'}
9%  4. Filename (or '' for a dialog box)
10%
11%  NOTE
12%  1. PlotType = 'Rows' or 'Columns' can take a long time to generate
13%  2. 'ColumnSpace' and 'BPMSpace' are the same
14%     'RowSpace' and 'CMSpace' are the same
15%  3. Plane = 'All' can only be used on PlotType = '3D'
16%  4. Use popplot to expand a subplot to full size.
17
18%
19%  Written by Gregory J. Portmann
20%  Adapted by Laurent S. Nadolski
21
22
23R = '';
24PlotType = '3D';
25Plane = 'All';
26ErrorFlag = 0;
27
28
29% Input parsing
30for i = length(varargin):-1:1
31    if isstruct(varargin{i})
32        % Response matrix
33        R = varargin(i);
34        varargin(i) = [];
35    elseif iscell(varargin{i})
36        % Just remove
37        varargin(i) = [];
38    elseif any(strcmpi(varargin(i),{'Absolute','Abs'}))
39        ErrorFlag = 0;
40        varargin(i) = [];
41    elseif strcmpi(varargin(i),'Error')
42        ErrorFlag = 1;
43        varargin(i) = [];
44    elseif any(strcmpi(varargin(i),{'3D'}))
45        PlotType = '3D';
46        varargin(i) = [];
47    elseif any(strcmpi(varargin(i),{'Row','Rows'}))
48        PlotType = 'Rows';
49        varargin(i) = [];
50    elseif any(strcmpi(varargin(i),{'Col','Cols','Column','Columns'}))
51        PlotType = 'Columns';
52        varargin(i) = [];
53    elseif any(strcmpi(varargin(i),{'RowSpace','CMSpace'}))
54        PlotType = 'CMSpace';
55        varargin(i) = [];
56    elseif any(strcmpi(varargin(i),{'ColumnSpace','BPMSpace'}))
57        PlotType = 'BPMSpace';
58        varargin(i) = [];
59    elseif any(strcmpi(varargin(i),{'x','xx','horizontal'}))
60        Plane = 'xx';
61        varargin(i) = [];
62    elseif any(strcmpi(varargin(i),{'y','yy','z','zz','vertical'}))
63        Plane = 'yy';
64        varargin(i) = [];
65    elseif any(strcmpi(varargin(i),{'xy','xz'}))
66        Plane = 'xy';
67        varargin(i) = [];
68    elseif any(strcmpi(varargin(i),{'yx','zx'}))
69        Plane = 'yx';
70        varargin(i) = [];
71    elseif any(strcmpi(varargin(i),{'All'}))
72        Plane = 'All';
73        varargin(i) = [];
74    elseif ischar(varargin{i})
75        % Filename
76        R = getbpmresp('FileName', varargin{i}, 'Struct', 'NoEnergyScaling');
77        varargin(i) = [];
78    end
79end
80
81
82if isempty(R)
83    R = getbpmresp('Struct', 'NoEnergyScaling');
84end
85if isempty(R)
86    fprintf('   Response matrix not found.\n');
87    return;
88end
89
90
91if ErrorFlag
92    % Plot the difference between the measured and model
93    m = measbpmresp('Model','Struct');
94    R(1,1).Data = R(1,1).Data - m(1,1).Data;
95    R(1,2).Data = R(1,2).Data - m(1,2).Data;
96    R(2,1).Data = R(2,1).Data - m(2,1).Data;
97    R(2,2).Data = R(2,2).Data - m(2,2).Data;
98end
99
100
101hfig = gcf;
102clf reset
103
104if strcmpi(PlotType, '3D')
105
106    % 3-D response matrix plot
107    if strcmpi(Plane, 'All')
108        surf([R(1,1).Data R(1,2).Data; R(2,1).Data R(2,2).Data]);
109        xlabel('CM Number');
110        ylabel('BPM Number');
111        if isfield(R(1,1),'UnitsString')
112            zlabel(R(1,1).UnitsString);
113        end
114    elseif strcmpi(Plane, 'xx')
115        surf([R(1,1).Data]);
116        xlabel('HCM Number');
117        ylabel('BPMx Number');
118        if isfield(R(1,1),'UnitsString')
119            zlabel(R(1,1).UnitsString);
120        end
121    elseif strcmpi(Plane, 'xy')
122        surf([R(1,2).Data]);
123        xlabel('VCM Number');
124        ylabel('BPMx Number');
125        if isfield(R(1,2),'UnitsString')
126            zlabel(R(1,2).UnitsString);
127        end
128    elseif strcmpi(Plane, 'yx')
129        surf([R(2,1).Data]);
130        xlabel('HCM Number');
131        ylabel('BPMy Number');
132        if isfield(R(2,1),'UnitsString')
133            zlabel(R(2,1).UnitsString);
134        end
135    elseif strcmpi(Plane, 'yy')
136        surf([R(2,2).Data]);
137        xlabel('VCM Number');
138        ylabel('BPMy Number');
139        if isfield(R(2,2),'UnitsString')
140            zlabel(R(2,2).UnitsString);
141        end
142    end
143    view(-70, 65);
144    addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp)));
145
146    if ErrorFlag
147        % Measured - Model
148        title('Orbit Response Matrix Error (Measured-Model)');
149    else
150        % Absolute response matrix plot
151        title('Orbit Response Matrix');
152    end
153
154elseif strcmpi(PlotType,'Columns')
155    set(gcf, 'Units', get(0, 'Units'));
156    Pfig = get(gcf, 'Position');
157    set(gcf, 'Position', get(0, 'ScreenSize'));
158
159    NSectors = R(1,1).Monitor.DeviceList(end,1);
160    NBPMxperSector = max(R(1,1).Monitor.DeviceList(:,2));
161    NBPMyperSector = max(R(2,2).Monitor.DeviceList(:,2));
162
163    NBPMx = size(R(1,1).Data,1);
164    NBPMy = size(R(2,2).Data,1);
165
166    NHCMperSector = max(R(1,1).Actuator.DeviceList(:,2));
167    NVCMperSector = max(R(2,2).Actuator.DeviceList(:,2));
168
169    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
170        s = getspos(R(1,1).Monitor.FamilyName, R(1,1).Monitor.DeviceList);
171        for i = 1:NSectors
172            for j = 1:NHCMperSector
173                Index = findrowindex([i j], R(1,1).Actuator.DeviceList);
174                if ~isempty(Index)
175                    figure(hfig);
176                    subplot(NSectors, NHCMperSector, (i-1)*NHCMperSector + j);
177                    plot(s, R(1,1).Data(:,Index));
178                    %axis tight
179                    set(gca,'XTickLabel','');
180                    set(gca,'YTickLabel','');
181                end
182            end
183        end
184        addlabel(.5, 1, 'Horizontal Orbit Response Matrix Columns',12);
185        addlabel(.5, 0, 'Horizontal Magnet Device Number', 10);
186
187    elseif strcmpi(Plane, 'xy')
188        s = getspos(R(1,2).Monitor.FamilyName, R(1,2).Monitor.DeviceList);
189        for i = 1:NSectors
190            for j = 1:NVCMperSector
191                Index = findrowindex([i j], R(1,2).Actuator.DeviceList);
192                if ~isempty(Index)
193                    figure(hfig);
194                    subplot(NSectors, NVCMperSector, (i-1)*NVCMperSector + j);
195                    plot(s, R(1,2).Data(:,Index));
196                    %axis tight
197                    set(gca,'XTickLabel','');
198                    set(gca,'YTickLabel','');
199                end
200            end
201        end
202        addlabel(.5, 1, 'Response Matrix Columns:  Horizontal Orbit / Vertical Kick',12);
203        addlabel(.5, 0, 'Vertical Magnet Device Number', 10);
204
205    elseif strcmpi(Plane, 'yx')
206        s = getspos(R(2,1).Monitor.FamilyName, R(2,1).Monitor.DeviceList);
207        for i = 1:NSectors
208            for j = 1:NHCMperSector
209                Index = findrowindex([i j], R(2,1).Actuator.DeviceList);
210                if ~isempty(Index)
211                    figure(hfig);
212                    subplot(NSectors, NHCMperSector, (i-1)*NHCMperSector + j);
213                    plot(s, R(2,1).Data(:,Index));
214                    %axis tight
215                    set(gca,'XTickLabel','');
216                    set(gca,'YTickLabel','');
217                end
218            end
219        end
220        addlabel(.5, 1, 'Response Matrix Columns:  Vertical Orbit / Horizontal Kick',12);
221        addlabel(.5, 0, 'Horizontal Magnet Device Number', 10);
222
223    elseif strcmpi(Plane, 'yy')
224        s = getspos(R(2,2).Monitor.FamilyName, R(2,2).Monitor.DeviceList);
225        for i = 1:NSectors
226            for j = 1:NVCMperSector
227                Index = findrowindex([i j], R(2,2).Actuator.DeviceList);
228                if ~isempty(Index)
229                    figure(hfig);
230                    subplot(NSectors, NVCMperSector, (i-1)*NVCMperSector + j);
231                    plot(s, R(2,2).Data(:,Index));
232                    %axis tight
233                    set(gca,'XTickLabel','');
234                    set(gca,'YTickLabel','');
235                end
236            end
237        end
238        addlabel(.5, 1, 'Vertical Orbit Response Matrix Columns',12);
239        addlabel(.5, 0, 'Vertical Magnet Device Number', 10);
240    end
241
242    h = addlabel(.02,.5,'Sector Number',10);
243    set(h,'Rotation',90);
244    set(h,'HorizontalAlignment','center');
245    set(h,'VerticalAlignment','top');
246    addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp)));
247    set(gcf,'Position', Pfig);
248
249elseif strcmpi(PlotType,'Rows')
250    set(gcf, 'Units', get(0, 'Units'));
251    Pfig = get(gcf, 'Position');
252    set(gcf, 'Position', get(0, 'ScreenSize'));
253
254    NSectors = R(1,1).Monitor.DeviceList(end,1);
255    NBPMxperSector = max(R(1,1).Monitor.DeviceList(:,2));
256    NBPMyperSector = max(R(2,2).Monitor.DeviceList(:,2));
257
258    NBPMx = size(R(1,1).Data,1);
259    NBPMy = size(R(2,2).Data,1);
260
261    NHCMperSector = max(R(1,1).Actuator.DeviceList(:,2));
262    NVCMperSector = max(R(2,2).Actuator.DeviceList(:,2));
263
264
265    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
266        s = getspos(R(1,1).Actuator.FamilyName, R(1,1).Actuator.DeviceList);
267        for i = 1:NSectors
268            for j = 1:NBPMxperSector
269                Index = findrowindex([i j], R(1,1).Monitor.DeviceList);
270                if ~isempty(Index)
271                    figure(hfig);
272                    subplot(NSectors, NBPMxperSector, (i-1)*NBPMxperSector + j);
273                    plot(s, R(1,1).Data(Index,:));
274                    %axis tight
275                    set(gca,'XTickLabel','');
276                    set(gca,'YTickLabel','');
277                end
278            end
279        end
280        addlabel(.5,1, 'Horizontal Orbit Response Matrix Rows',12);
281        addlabel(.5,0, 'Horizontal BPM Device Number', 10);
282
283    elseif strcmpi(Plane, 'xy')
284        s = getspos(R(1,2).Actuator.FamilyName, R(1,2).Actuator.DeviceList);
285        for i = 1:NSectors
286            for j = 1:NBPMxperSector
287                Index = findrowindex([i j], R(1,2).Monitor.DeviceList);
288                if ~isempty(Index)
289                    figure(hfig);
290                    subplot(NSectors, NBPMxperSector, (i-1)*NBPMxperSector + j);
291                    plot(s, R(1,2).Data(Index,:));
292                    %axis tight
293                    set(gca,'XTickLabel','');
294                    set(gca,'YTickLabel','');
295                end
296            end
297        end
298        addlabel(.5,1, 'Response Matrix Rows:  Horizontal Orbit / Vertical Kick',12);
299        addlabel(.5,0, 'Horizontal BPM Device Number', 10);
300
301    elseif strcmpi(Plane, 'yx')
302        s = getspos(R(2,1).Actuator.FamilyName, R(2,1).Actuator.DeviceList);
303        for i = 1:NSectors
304            for j = 1:NBPMyperSector
305                Index = findrowindex([i j], R(2,1).Monitor.DeviceList);
306                if ~isempty(Index)
307                    figure(hfig);
308                    subplot(NSectors, NBPMyperSector, (i-1)*NBPMyperSector + j);
309                    plot(s, R(2,1).Data(Index,:));
310                    %axis tight
311                    set(gca,'XTickLabel','');
312                    set(gca,'YTickLabel','');
313                end
314            end
315        end
316        addlabel(.5,1, 'Response Matrix Rows:  Vertical Orbit / Horizontal Kick',12);
317        addlabel(.5,0, 'Vertical BPM Device Number', 10);
318
319    elseif strcmpi(Plane, 'yy')
320        s = getspos(R(2,2).Actuator.FamilyName, R(2,2).Actuator.DeviceList);
321        for i = 1:NSectors
322            for j = 1:NBPMyperSector
323                Index = findrowindex([i j], R(2,2).Monitor.DeviceList);
324                if ~isempty(Index)
325                    figure(hfig);
326                    subplot(NSectors, NBPMyperSector, (i-1)*NBPMyperSector + j);
327                    plot(s, R(2,2).Data(Index,:));
328                    %axis tight
329                    set(gca,'XTickLabel','');
330                    set(gca,'YTickLabel','');
331                end
332            end
333        end
334        addlabel(.5,1, 'Vertical Orbit Response Matrix Rows',12);
335        addlabel(.5,0, 'Vertical BPM Device Number', 10);
336    end
337
338    xaxesposition(1.20);
339    yaxesposition(1.20);
340    h = addlabel(.02,.5,'Sector Number',10);
341    set(h,'Rotation',90);
342    set(h,'HorizontalAlignment','center');
343    set(h,'VerticalAlignment','top');
344    addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp)));
345    set(gcf,'Position', Pfig);
346   
347elseif strcmpi(PlotType,'BPMSpace')
348    set(gcf, 'Units', get(0, 'Units'));
349    Pfig = get(gcf, 'Position');
350    set(gcf, 'Position', get(0, 'ScreenSize'));
351
352    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
353        [U,S,V] = svd(R(1,1).Data, 0);
354    elseif strcmpi(Plane, 'xy')
355        [U,S,V] = svd(R(1,2).Data, 0);
356    elseif strcmpi(Plane, 'yx')
357        [U,S,V] = svd(R(2,1).Data, 0);
358    elseif strcmpi(Plane, 'yy')
359        [U,S,V] = svd(R(2,2).Data, 0);
360    end
361   
362    n = 0;
363    M = ceil(sqrt(size(U,2)));
364    N = ceil(sqrt(size(U,2)));
365    for i = 1:M
366        for j = 1:N
367            n = n + 1;
368            figure(hfig);
369            subplot(M, N, n);
370            plot(U(:,n));
371            axis tight
372            set(gca,'XTickLabel','');
373            set(gca,'YTickLabel','');
374            if n == size(U,2)
375                break
376            end
377        end
378        if n == size(U,2)
379            break
380        end
381    end
382
383    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
384        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Horizontal BPM Space (U(%dx%d))',size(U,1),size(U,2)),12);
385    elseif strcmpi(Plane, 'xy')
386        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Horizontal BPM Cross Space (U(%dx%d))',size(U,1),size(U,2)),12);
387    elseif strcmpi(Plane, 'yx')
388        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Vertical BPM Cross Space (U(%dx%d))',size(U,1),size(U,2)),12);
389    elseif strcmpi(Plane, 'yy')
390        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Vertical BPM Space (U(%dx%d))',size(U,1),size(U,2)),12);
391    end
392
393    addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp)));
394    set(gcf,'Position', Pfig);
395
396elseif strcmpi(PlotType,'CMSpace')
397    set(gcf, 'Units', get(0, 'Units'));
398    Pfig = get(gcf, 'Position');
399    set(gcf, 'Position', get(0, 'ScreenSize'));
400
401    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
402        [U,S,V] = svd(R(1,1).Data, 0);
403    elseif strcmpi(Plane, 'xy')
404        [U,S,V] = svd(R(1,2).Data, 0);
405    elseif strcmpi(Plane, 'yx')
406        [U,S,V] = svd(R(2,1).Data, 0);
407    elseif strcmpi(Plane, 'yy')
408        [U,S,V] = svd(R(2,2).Data, 0);
409    end
410   
411    n = 0;
412    M = ceil(sqrt(size(V,2)));
413    N = ceil(sqrt(size(V,2)));
414    for i = 1:M
415        for j = 1:N
416            n = n + 1;
417            figure(hfig);
418            subplot(M, N, n);
419            plot(V(:,n));
420            axis tight
421            set(gca,'XTickLabel','');
422            set(gca,'YTickLabel','');
423            if n == size(V,2)
424                break
425            end
426        end
427        if n == size(U,2)
428            break
429        end
430    end
431
432    if strcmpi(Plane, 'xx') | strcmpi(Plane, 'All')
433        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Horizontal Corrector Space (V(%dx%d))', size(V,1), size(V,2)), 12);
434    elseif strcmpi(Plane, 'xy')
435        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Vertical Corrector Cross Space (V(%dx%d))', size(V,1), size(V,2)), 12);
436    elseif strcmpi(Plane, 'yx')
437        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Horizontal Corrector Cross Space (V(%dx%d))', size(V,1), size(V,2)), 12);
438    elseif strcmpi(Plane, 'yy')
439        addlabel(.5, 1, sprintf('Singular Vectors Spanning the Vertical Corrector Space (V(%dx%d))', size(V,1), size(V,2)), 12);
440    end
441
442    addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp)));
443    set(gcf,'Position', Pfig);
444
445end
446
447
Note: See TracBrowser for help on using the repository browser.