1 | function 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 | |
---|
29 | global BPMs IDBPMs IDXgolden IDYgolden |
---|
30 | |
---|
31 | BLeffHCM = 410; % gauss cm / amp; |
---|
32 | BLeffVCM = 171; % gauss cm / amp; |
---|
33 | Leff = 55; % cm |
---|
34 | |
---|
35 | %disp(' '); |
---|
36 | |
---|
37 | if 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)); |
---|
55 | elseif 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)); |
---|
67 | else |
---|
68 | error('ffanal requires 0, 2, or 3 input arguments.'); |
---|
69 | end |
---|
70 | |
---|
71 | |
---|
72 | Datafn = lower(Datafn); |
---|
73 | if exist(Datafn)==2 |
---|
74 | % OK |
---|
75 | else |
---|
76 | Datafn = upper(Datafn); |
---|
77 | if exist(Datafn)==2 |
---|
78 | % OK |
---|
79 | else |
---|
80 | disp(' File not found.'); disp(' '); |
---|
81 | return |
---|
82 | end |
---|
83 | end |
---|
84 | |
---|
85 | eval(['load ', Datafn]); |
---|
86 | eval(['cd ', CurrentDir]); |
---|
87 | |
---|
88 | % IDBPM starting point |
---|
89 | % Find the IDBPMs in the sector where the ID is located. |
---|
90 | ii = dev2elem('IDBPMx',getlist('IDBPMx',Sector)); |
---|
91 | IDBPMgoalx = IDXgolden(ii); |
---|
92 | IDBPMgoaly = IDYgolden(ii); |
---|
93 | |
---|
94 | ii=find(idbpmlist(:,1)==Sector); |
---|
95 | IDBPM210ax = IDx210a(ii); |
---|
96 | IDBPM210ay = IDy210a(ii); |
---|
97 | IDBPM210bx = IDx210b(ii); |
---|
98 | IDBPM210by = IDy210b(ii); |
---|
99 | |
---|
100 | if 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 |
---|
106 | end |
---|
107 | |
---|
108 | fprintf(' Golden Starting Error Ending Error\n'); |
---|
109 | fprintf(' 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)); |
---|
110 | fprintf(' 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)); |
---|
111 | fprintf(' 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)); |
---|
112 | fprintf(' 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)); |
---|
113 | pause(0); |
---|
114 | |
---|
115 | % Plot tables |
---|
116 | Buffer = .01; |
---|
117 | HeightBuffer = .05; |
---|
118 | |
---|
119 | h1=figure; |
---|
120 | subplot(2,1,1); |
---|
121 | plot(tableX(:,1),tableX(:,2),'-', tableX(:,1),tableX(:,3),'--'); |
---|
122 | %xlabel('Gap Position [mm]'); |
---|
123 | ylabel('Corrector Strength [amps]'); |
---|
124 | title(['Insertion Device Feedfoward Table for Sector ', num2str(Sector)]); |
---|
125 | legend(['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); |
---|
131 | axis tight; |
---|
132 | |
---|
133 | subplot(2,1,2); |
---|
134 | plot(tableY(:,1),tableY(:,2),'-', tableY(:,1),tableY(:,3),'--'); |
---|
135 | xlabel('Gap Position [mm]'); |
---|
136 | ylabel('Corrector Strength [amps]'); |
---|
137 | axis tight; |
---|
138 | legend(['VCM4, Sector ',num2str(Sector-1),' '], ... |
---|
139 | ['VCM1, Sector ',num2str(Sector), ' '],0); |
---|
140 | set(h1,'units','normal','position',[.0+Buffer .5+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]); |
---|
141 | addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]); |
---|
142 | orient tall |
---|
143 | |
---|
144 | |
---|
145 | h2=figure; |
---|
146 | if exist('IDXrms') == 1 |
---|
147 | subplot(2,1,1); |
---|
148 | end |
---|
149 | plot(tableX(:,1),1000*Xrms,'-', tableX(:,1),1000*Yrms,'--'); |
---|
150 | title(['RMS Orbit Change During Table Generation for Sector ', num2str(Sector)]); |
---|
151 | ylabel('BPM Error [microns]'); |
---|
152 | axis tight; |
---|
153 | legend(['Horizontal '],['Vertical '],0); |
---|
154 | |
---|
155 | if 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); |
---|
160 | end |
---|
161 | xlabel('GAP Position [mm]'); |
---|
162 | axis tight; |
---|
163 | set(h2,'units','normal','position',[.5+Buffer .5+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]); |
---|
164 | addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]); |
---|
165 | orient tall |
---|
166 | |
---|
167 | |
---|
168 | h3=figure; |
---|
169 | if exist('IDx210a') == 1 |
---|
170 | subplot(2,1,1); |
---|
171 | end |
---|
172 | plot(BPMs,1000*(x210a-x210b),'-', BPMs,1000*(y210a-y210b),'--'); |
---|
173 | title(['Drift in the Orbit During Table Generation for Sector ', num2str(Sector)]); |
---|
174 | xlabel('BPM Position [meters]'); |
---|
175 | ylabel('BPM Drift [microns]'); |
---|
176 | axis tight; |
---|
177 | xaxis([0 200]); |
---|
178 | legend(['Horizontal '],['Vertical '],0); |
---|
179 | |
---|
180 | if 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]); |
---|
189 | end |
---|
190 | |
---|
191 | set(h3,'units','normal','position',[.5+Buffer .1+Buffer .5-2*Buffer .5-2*Buffer-HeightBuffer]); |
---|
192 | addlabel(1,0,[num2str(GeVnum),' GeV, ', FFDate]); |
---|
193 | orient tall |
---|
194 | |
---|
195 | |
---|
196 | % Rate of change |
---|
197 | ExtraPlots = 1; |
---|
198 | if 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]; |
---|
221 | else |
---|
222 | FigureHandles = [h1;h2;h3]; |
---|
223 | end |
---|
224 | |
---|
225 | |
---|
226 | if 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 |
---|
247 | end |
---|
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 | |
---|