source: MML/trunk/machine/SOLEIL/StorageRing/bpm/plotmonbpm.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: 6.9 KB
Line 
1function BPM = plotmonbpm(varargin)
2%PLOTMONBPM - plot BPM noise data archived
3%
4%  INPUTS
5%  1. FileName
6%
7%  See Also monbpm
8
9%
10% Written by Laurent S. Nadolski
11
12SummaryFlag = 1;
13for i = length(varargin):-1:1
14    if strcmpi(varargin{i},'Summary')
15        SummaryFlag = 1;
16        varargin(i) = [];
17    elseif strcmpi(varargin{i},'NoSummary')
18        SummaryFlag = 0;
19        varargin(i) = [];
20    end
21end
22
23if length(varargin) <1
24    FileName = '';
25else
26    FileName = varargin{1};
27end
28
29
30if isempty(FileName)
31    DirectoryName = getfamilydata('Directory','BPMData');
32    if isempty(DirectoryName)
33        DirectoryName = [getfamilydata('Directory','DataRoot'), filesep, 'BPM', filesep];
34    else
35        % Make sure default directory exists
36        DirStart = pwd;
37        [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName);
38        cd(DirStart);
39    end
40    [FileName, DirectoryName] = uigetfile('*.mat', 'Select a BPM Monitor File', [DirectoryName FileName]);
41    FileName = fullfile(DirectoryName, FileName);
42elseif FileName == -1
43    FileName = appendtimestamp('BPMData');
44    DirectoryName = getfamilydata('Directory','BPMData');
45    if isempty(DirectoryName)
46        DirectoryName = [getfamilydata('Directory','DataRoot'), filesep, 'BPM', filesep];
47    end
48    FileName = [DirectoryName, FileName];
49end
50
51if exist(FileName, 'file') ~=2
52    error('File does not exist');
53end
54
55A = load(FileName);
56if ~isfield(A, 'BPMxData') || ~isfield(A, 'BPMxData')
57    error('Wrong file, no BPM data')
58end
59
60BPM(1) = A.BPMxData;
61BPM(2) = A.BPMyData;
62
63% Compute the standard deviation
64
65% Low frequency drifting increases the STD.  For many purposes, like LOCO,
66% this is not desireable.  Using difference orbits mitigates the drift problem.
67
68
69
70% plot part
71figure
72subplot(2,2,1);
73
74tout = BPM(1).tout;
75Mx = BPM(1).Data;
76% Orbit compared to first set
77for i = 1:size(Mx,2)
78    Mx(:,i) = Mx(:,i) - BPM(1).Data(:,1);
79end
80
81plot(tout, Mx);
82grid on;
83%title(sprintf('BPM Data (%s)', datestr(BPM(1).TimeStamp)))
84xlabel('Time [Seconds]');
85ylabel('Horizontal Relative Position [mm]');
86
87
88tout = BPM(2).tout;
89% Orbit compared to first set
90My = BPM(2).Data;
91for i = 1:size(My,2)
92    My(:,i) = My(:,i) -  BPM(2).Data(:,1);
93end
94
95subplot(2,2,3);
96plot(tout, My);
97grid on;
98xlabel('Time [Seconds]');
99ylabel(sprintf('Vertical Position [%s]', BPM(2).UnitsString));
100
101subplot(2,2,2);
102List = BPM(1).DeviceList;
103Nsectors = max(List(:,1));
104Ndevices = max(List(:,2));
105Sector = List(:,1) + List(:,2)/Ndevices + 1/Ndevices/2;
106[Sector Idx] = sort(Sector);
107plot(Sector, BPM(1).Sigma(Idx));
108grid on;
109xaxis([1 Nsectors+1])
110set(gca,'XTick',1:Nsectors);
111xlabel('Sector Number');
112ylabel(sprintf('Horizontal STD [%s]', BPM(1).UnitsString));
113
114subplot(2,2,4);
115List = BPM(2).DeviceList;
116Nsectors = max(List(:,1));
117Ndevices = max(List(:,2));
118Sector = List(:,1) + List(:,2)/Ndevices + 1/Ndevices/2;
119[Sector Idx] = sort(Sector);
120plot(Sector, BPM(2).Sigma(Idx));
121grid on;
122xaxis([1 Nsectors+1])
123set(gca,'XTick',1:Nsectors);
124xlabel('Sector Number');
125ylabel(sprintf('Vertical STD [%s]', BPM(2).UnitsString));
126
127addlabel(.5,1,sprintf('BPM Data (%s)', datestr(BPM(1).TimeStamp)), 10);
128orient landscape
129
130%plot fit of the dispersion in the H-plane
131figure
132spos = getspos('BPMx',BPM(1).DeviceList);
133etax = modeldisp('BPMx',BPM(1).DeviceList);
134% y = disp*delta + y0
135x = lsqr([etax ones(size(BPM(1).Sigma))], BPM(1).Sigma*1e-3); % m
136plot(spos, BPM(1).Sigma); hold on
137plot(spos,(etax*x(1)+x(2))*1e3,'r'); hold on
138legend('Data', 'fit')
139title(sprintf('Noise in H-plane: Delta = %.2f %% (x0=%.2e mm)', x(1)*100, x(2)*1e3));
140xlabel('s-position (m)')
141ylabel('RMS x (mm)')
142
143if SummaryFlag
144    % Low frequency drifting increases the STD.  For many purposes, like LOCO,
145    % this is not desireable.  Using difference orbits mitigates the drift problem.
146    Mx = BPM(1).Data;
147    for i = 1:size(Mx,2)-1
148        Mx(:,i) = Mx(:,i+1) - Mx(:,i);
149    end
150    Mx(:,end) = [];
151
152    My = BPM(2).Data;
153    for i = 1:size(My,2)-1
154        My(:,i) = My(:,i+1) - My(:,i);
155    end
156    My(:,end) = [];
157
158    BPM(1).Sigma = std(Mx,0,2) / sqrt(2);   % sqrt(2) comes from substracting 2 random variables
159    BPM(2).Sigma = std(My,0,2) / sqrt(2);
160
161
162    [SortedData1 DataIdx1] = sort(BPM(1).Sigma,'descend');
163    SortedDeviceList1 = BPM(1).DeviceList(DataIdx1,:);
164    [SortedData2 DataIdx2] = sort(BPM(2).Sigma,'descend');
165    SortedDeviceList2 = BPM(2).DeviceList(DataIdx2,:);
166
167    % sort by drift
168    maxBPM1 =  max(abs(Mx),[],2);
169    [SortedData3 DataIdx3] = sort(maxBPM1,'descend');
170    SortedDeviceList3 = BPM(1).DeviceList(DataIdx3,:);
171    maxBPM2 =  max(abs(My),[],2);
172    [SortedData4 DataIdx4] = sort(maxBPM2,'descend');
173    SortedDeviceList4 = BPM(2).DeviceList(DataIdx4,:);
174
175    fprintf('\n\n BPMxname DevList     Max drift           BPMzname DevList       Max drift\n');
176    for k=1:size(BPM(1).DeviceList,1),
177        fprintf('%s    [%2d %2d]      %6.2e [%s]        %s    [%2d %2d]      %6.2e [%s] \n', ...
178            'BPMx', SortedDeviceList3(k,1), SortedDeviceList3(k,2), SortedData3(k), BPM(1).UnitsString, ...
179            'BPMz', SortedDeviceList4(k,1), SortedDeviceList4(k,2), SortedData4(k), BPM(2).UnitsString);
180    end
181
182    fprintf('\n\n BPMxname DevList     STD value           BPMzname DevList       STD value\n');
183
184    for k=1:size(BPM(1).DeviceList,1),
185        fprintf('%s    [%2d %2d]      %6.2e [%s]        %s    [%2d %2d]      %6.2e [%s] \n', ...
186            'BPMx', SortedDeviceList1(k,1), SortedDeviceList1(k,2), SortedData1(k), BPM(1).UnitsString, ...
187            'BPMz', SortedDeviceList2(k,1), SortedDeviceList2(k,2), SortedData2(k), BPM(2).UnitsString);
188    end
189    [SortedData1 DataIdx1] = sort(BPM(1).Sigma,'descend');
190    SortedDeviceList1 = BPM(1).DeviceList(DataIdx1,:);
191    [SortedData2 DataIdx2] = sort(BPM(2).Sigma,'descend');
192    SortedDeviceList2 = BPM(2).DeviceList(DataIdx2,:);
193
194    % sort by drift
195    maxBPM1 =  max(abs(Mx),[],2);
196    [SortedData3 DataIdx3] = sort(maxBPM1,'descend');
197    SortedDeviceList3 = BPM(1).DeviceList(DataIdx3,:);
198    maxBPM2 =  max(abs(My),[],2);
199    [SortedData4 DataIdx4] = sort(maxBPM2,'descend');
200    SortedDeviceList4 = BPM(2).DeviceList(DataIdx4,:);
201
202    fprintf('\n\n BPMxname DevList     Max drift           BPMzname DevList       Max drift\n');
203    for k=1:size(BPM(1).DeviceList,1),
204        fprintf('%s    [%2d %2d]      %6.2e [%s]        %s    [%2d %2d]      %6.2e [%s] \n', ...
205            'BPMx', SortedDeviceList3(k,1), SortedDeviceList3(k,2), SortedData3(k), BPM(1).UnitsString, ...
206            'BPMz', SortedDeviceList4(k,1), SortedDeviceList4(k,2), SortedData4(k), BPM(2).UnitsString);
207    end
208
209    fprintf('\n\n BPMxname DevList     STD value           BPMzname DevList       STD value\n');
210    for k=1:size(BPM(1).DeviceList,1),
211        fprintf('%s    [%2d %2d]      %6.2e [%s]        %s    [%2d %2d]      %6.2e [%s] \n', ...
212            'BPMx', SortedDeviceList1(k,1), SortedDeviceList1(k,2), SortedData1(k), BPM(1).UnitsString, ...
213            'BPMz', SortedDeviceList2(k,1), SortedDeviceList2(k,2), SortedData2(k), BPM(2).UnitsString);
214    end
215
216end
Note: See TracBrowser for help on using the repository browser.