source: MML/trunk/machine/SOLEIL/StorageRing/feedforward/ffanal.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: 9.9 KB
Line 
1function FigureHandles = ffanal(Sector, GeVnum, DirStr)
2%FFANAL - Analyses an existing feedforward table
3% function FigureHandles = ffanal(Sector, GeV, Directory)
4%            or
5% function FigureHandles = ffanal
6%
7%    This function plots various information about the feed forward tables.
8%
9%    Sector    = the storage ring sector number for that insertion device
10%    GeV       = the storage ring energy (1.0, 1.3, 1.5, 1.9)
11%    Directory = the directory location where the files are located.  To directory "tree"
12%                from the root or w:\public\matlab\gaptrack.
13%
14%    For example, ffanal(7,1.5) analyzes the most recently generated table for sector 7
15%    at 1.5 GeV.
16%   
17%    If no input auguments are used, a dialog box will allow one
18%    to choose any feed forward table.  Table are grouped in directories
19%    according and energy and the date the file was generated.  The most
20%    recent table is located in w:\public\matlab\gaptrack.
21%
22
23%
24% Written By ALS people
25
26% TODO
27% Adpation for SOLEIL
28
29global BPMs IDBPMs IDXgolden IDYgolden
30
31BLeffHCM = 410;  % gauss cm / amp;
32BLeffVCM = 171;  % gauss cm / amp;
33Leff = 55;       % cm
34
35%disp(' ');
36
37if nargin == 0
38   % Load the data tables
39   CurrentDir = pwd;
40   
41   gotodata
42   cd gaptrack
43   [filename, pathname] = uigetfile('id*.mat', 'Choose the desired feed forward file.');
44   if filename==0
45      eval(['cd ',CurrentDir]);
46      disp('  Function canceled.'); disp(' ');
47      return
48   end
49   
50   eval(['cd ', pathname]);
51   Datafn = filename;
52   
53   Sector = str2num(filename(3:4));
54   GeVnum = str2num(filename(6)) + .1*str2num(filename(7));
55elseif nargin == 2 | nargin == 3
56   GeVstr = num2str(GeVnum);
57   
58   CurrentDir = pwd;
59   gotodata
60   cd gaptrack
61   
62   if nargin == 3
63      eval(['cd ', DirStr]);
64   end
65   
66   Datafn = sprintf('id%02de%c%c.mat', Sector, GeVstr(1), GeVstr(3));
67else
68   error('ffanal requires 0, 2, or 3 input arguments.');
69end
70
71
72Datafn = lower(Datafn);
73if exist(Datafn)==2
74   % OK
75else
76   Datafn = upper(Datafn);
77   if exist(Datafn)==2
78      % OK
79   else
80      disp('  File not found.'); disp(' ');
81      return
82   end
83end
84
85eval(['load ', Datafn]);
86eval(['cd ', CurrentDir]);
87
88% IDBPM starting point
89% Find the IDBPMs in the sector where the ID is located.
90ii = dev2elem('IDBPMx',getlist('IDBPMx',Sector));
91IDBPMgoalx = IDXgolden(ii);
92IDBPMgoaly = IDYgolden(ii);
93
94ii=find(idbpmlist(:,1)==Sector);
95IDBPM210ax = IDx210a(ii);
96IDBPM210ay = IDy210a(ii);
97IDBPM210bx = IDx210b(ii);
98IDBPM210by = IDy210b(ii);
99
100if exist('BPMFlag')==1
101   if BPMFlag == 1
102      disp('  Arc sector BPMs were used to generation the feed forward tables.');
103   elseif BPMFlag == 2
104      disp('  IDBPMs were used to generation the feed forward tables.');;
105   end
106end
107
108fprintf('                Golden    Starting   Error     Ending    Error\n');
109fprintf('  IDBPMx(%2d,1): %6.3f     %6.3f   %6.3f     %6.3f   %6.3f  [mm]\n',   Sector, IDBPMgoalx(1), IDBPM210ax(1), IDBPM210ax(1)-IDBPMgoalx(1), IDBPM210bx(1), IDBPM210bx(1)-IDBPMgoalx(1));
110fprintf('  IDBPMx(%2d,2): %6.3f     %6.3f   %6.3f     %6.3f   %6.3f  [mm]\n',   Sector, IDBPMgoalx(2), IDBPM210ax(2), IDBPM210ax(2)-IDBPMgoalx(2), IDBPM210bx(2), IDBPM210bx(2)-IDBPMgoalx(2));
111fprintf('  IDBPMz(%2d,1): %6.3f     %6.3f   %6.3f     %6.3f   %6.3f  [mm]\n',   Sector, IDBPMgoaly(1), IDBPM210ay(1), IDBPM210ay(1)-IDBPMgoaly(1), IDBPM210by(1), IDBPM210by(1)-IDBPMgoaly(1));
112fprintf('  IDBPMz(%2d,2): %6.3f     %6.3f   %6.3f     %6.3f   %6.3f  [mm]\n\n', Sector, IDBPMgoaly(2), IDBPM210ay(2), IDBPM210ay(2)-IDBPMgoaly(2), IDBPM210by(2), IDBPM210by(2)-IDBPMgoaly(2));
113pause(0);
114
115% Plot tables
116Buffer = .01;
117HeightBuffer = .05;
118
119h1=figure;
120subplot(2,1,1);
121plot(tableX(:,1),tableX(:,2),'-', tableX(:,1),tableX(:,3),'--');
122%xlabel('Gap Position [mm]');
123ylabel('Corrector Strength [amps]');
124title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector)]);     
125legend(['HCM4, Sector ',num2str(Sector-1),'  '], ...
126       ['HCM1, Sector ',num2str(Sector),  '  '],0);
127%[hl,hl1] = legend(['HCM4, Sector ',num2str(Sector-1),'  '], ...
128%                  ['HCM1, Sector ',num2str(Sector),  '  ']);
129%set(hl1(1,2),'FontUnits','points','FontSize',10);
130%set(hl1(2,2),'FontUnits','points','FontSize',10);
131axis tight;
132
133subplot(2,1,2);
134plot(tableY(:,1),tableY(:,2),'-', tableY(:,1),tableY(:,3),'--');
135xlabel('Gap Position [mm]');
136ylabel('Corrector Strength [amps]');
137axis tight;
138legend(['VCM4, Sector ',num2str(Sector-1),'  '], ...
139       ['VCM1, Sector ',num2str(Sector),  '  '],0);
140set(h1,'units','normal','position',[.0+Buffer .5+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]);
141addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]);
142orient tall
143
144
145h2=figure;
146if exist('IDXrms') == 1     
147   subplot(2,1,1);
148end
149plot(tableX(:,1),1000*Xrms,'-', tableX(:,1),1000*Yrms,'--');
150title(['RMS Orbit Change During Table Generation for Sector ', num2str(Sector)]);
151ylabel('BPM Error [microns]');
152axis tight;
153legend(['Horizontal  '],['Vertical    '],0);
154
155if exist('IDXrms') == 1     
156   subplot(2,1,2);
157   plot(tableX(:,1),1000*IDXrms,'-', tableX(:,1),1000*IDYrms,'--');
158   ylabel('IDBPM Error [microns]');
159   legend(['Horizontal  '],['Vertical    '],0);
160end
161xlabel('GAP Position [mm]');
162axis tight;
163set(h2,'units','normal','position',[.5+Buffer .5+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]);
164addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]);
165orient tall
166
167
168h3=figure;
169if exist('IDx210a') == 1     
170   subplot(2,1,1);
171end
172plot(BPMs,1000*(x210a-x210b),'-', BPMs,1000*(y210a-y210b),'--');
173title(['Drift in the Orbit During Table Generation for Sector ', num2str(Sector)]);
174xlabel('BPM Position [meters]');
175ylabel('BPM Drift [microns]');
176axis tight;
177xaxis([0 200]);
178legend(['Horizontal  '],['Vertical    '],0);
179
180if exist('IDx210a') == 1     
181   subplot(2,1,2);
182   idbpmelem = dev2elem('IDBPMx',idbpmlist);
183   plot(IDBPMs(idbpmelem),1000*(IDx210a-IDx210b),'-', IDBPMs(idbpmelem),1000*(IDy210a-IDy210b),'--');
184   xlabel('IDBPM Position [meters]');
185   ylabel('IDBPM Drift [microns]');
186   legend(['Horizontal  '],['Vertical    '],0);
187   axis tight;
188   xaxis([0 200]);
189end
190
191set(h3,'units','normal','position',[.5+Buffer .1+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]);
192addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]);
193orient tall
194
195
196% Rate of change
197ExtraPlots = 1;
198if ExtraPlots == 1
199   % Rate of change
200   N = size(tableX,1);
201   h4=figure;
202   subplot(2,1,1);
203   plot(tableX(2:N,1),diff(tableX(:,2))./diff(tableX(:,1)),'-', tableX(2:N,1),diff(tableX(:,3))./diff(tableX(:,1)),'--');
204   %xlabel('Gap Position [mm]');
205   ylabel('Horizontal [amps/mm]');
206   title(['Corrector Magnet Rates for Sector ', num2str(Sector)]);
207   axis tight;
208   legend(['HCM4, Sector ',num2str(Sector-1),'  '], ['HCM1, Sector ',num2str(Sector),'  '],0);
209     
210   subplot(2,1,2); hold off
211   plot(tableY(2:N,1),diff(tableY(:,2))./diff(tableY(:,1)),'-', tableY(2:N,1),diff(tableY(:,3))./diff(tableY(:,1)),'--');
212   xlabel('Gap Position [mm]');
213   ylabel('Vertical [amps/mm]');
214   axis tight;
215   legend(['VCM4, Sector ',num2str(Sector-1),'  '], ['VCM1, Sector ',num2str(Sector),'  '],0);
216   set(h4,'units','normal','position',[.0+Buffer .1+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]);
217   addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]);
218   orient tall
219     
220   FigureHandles = [h1;h2;h3;h4];
221else
222   FigureHandles = [h1;h2;h3];       
223end
224
225
226if 0
227   figure
228   subplot(2,1,1);
229   plot(tableX(:,1),tableX(:,2)*407,'-', tableX(:,1),tableX(:,3)*407,'--');
230   %xlabel('Gap Position [mm]');
231   ylabel('Corrector Strength [Gauss CM]');
232   title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector)]);     
233   axis tight;
234   legend(['HCM4, Sector ',num2str(Sector-1),'  '], ...
235          ['HCM1, Sector ',num2str(Sector),  '  '],0);
236   
237   subplot(2,1,2);
238   plot(tableY(:,1),tableY(:,2)*171,'-', tableY(:,1),tableY(:,3)*171,'--');
239   xlabel('Gap Position [mm]');
240   ylabel('Corrector Strength [Gauss CM]');
241   legend(['VCM4, Sector ',num2str(Sector-1),'  '], ...
242          ['VCM1, Sector ',num2str(Sector),  '  '],0);
243   axis tight;
244   set(h1,'units','normal','position',[.0+Buffer .5+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]);
245   addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]);
246   orient tall
247end
248
249
250%  figure(2); clf;
251%  subplot(2,1,1); hold off
252%  plot(h1(:,1),h1(:,2)*BLeffHCM,'-r', h1(:,1),h1(:,3)*BLeffHCM,'--r');
253%  xlabel('Gap Position [mm]');
254%  ylabel('Horizontal Corrector Strength [G cm]');
255%
256%  if GeVnum == 1.9
257%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.9 GeV']);
258%  elseif GeVnum == 1.5
259%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.5 GeV']);
260%  elseif GeVnum == 1.0
261%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.0 GeV']);
262%  end
263%
264%  legend('-r',  ['HCM4, Sector ',num2str(Sector-1),'  '], ...
265%         '--r', ['HCM1, Sector ',num2str(Sector),'  ']);
266%
267%  subplot(2,1,2); hold off
268%  plot(v1(:,1),v1(:,2)*BLeffVCM,'-r', v1(:,1),v1(:,3)*BLeffVCM,'--r');
269%  xlabel('Gap Position [mm]');
270%  ylabel('Vertical Corrector Strength [G cm]');
271%
272%  legend('-r',  ['VCM4, Sector ',num2str(Sector-1),'  '], ...
273%         '--r', ['VCM1, Sector ',num2str(Sector),'  ']);
274
275
276%%  Plot integrated kick stuff
277%  figure(7); clf;
278%  subplot(2,1,1);
279%  plot(h1(:,1),h1(:,2)*BLeffHCM+h1(:,3)*BLeffHCM,'-r'); hold on;
280%  plot(v1(:,1),v1(:,2)*BLeffVCM+v1(:,3)*BLeffVCM,'--g'); hold off;
281%  xlabel('Gap Position [mm]');
282%  ylabel('Integrated B dl [G cm]');
283%
284%  if GeVnum == 1.9
285%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.9 GeV']);
286%  elseif GeVnum == 1.5
287%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.5 GeV']);
288%  elseif GeVnum == 1.0
289%    title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector),' at 1.0 GeV']);
290%  end
291%
292%  legend('Horizontal','Vertical');
293%
294%  subplot(2,1,2);
295%  plot(h1(:,1),Leff*(h1(:,2)*BLeffHCM/Leff).^2+Leff*(h1(:,3)*BLeffHCM/Leff).^2,'-r'); hold on;
296%  plot(v1(:,1),Leff*(v1(:,2)*BLeffVCM/Leff).^2+Leff*(v1(:,3)*BLeffVCM/Leff).^2,'--g'); hold off;
297%  xlabel('Gap Position [mm]');
298%  ylabel('Integrated (B^2 dl) [G^2 cm]');
299%
300%  legend('Horizontal','Vertical');
301
302
Note: See TracBrowser for help on using the repository browser.