1 | function [S, FileName] = getbpmresp(varargin) |
---|
2 | %GETBPMRESP - Returns the BPM response matrix in the horizontal and vertical planes |
---|
3 | % |
---|
4 | % For family name, device list inputs: |
---|
5 | % [Rmat, FileName] = getbpmresp(BPMxFamily, BPMxList, BPMyFamily, BPMyList, HCMFamily, HCMList, VCMFamily, VCMList, FileName) |
---|
6 | % |
---|
7 | % For data structure inputs: |
---|
8 | % [Rmat, FileName] = getbpmresp(BPMxStruct, BPMyStruct, HCMStruct, VCMStruct, FileName) |
---|
9 | % |
---|
10 | % INPUTS |
---|
11 | % 1. BPMxFamily - BPMx family name {Default: gethbpmfamily} |
---|
12 | % BPMxDeviceList - BPMx device list {Default: all devices with good status} |
---|
13 | % or |
---|
14 | % BPMxStruct can replace BPMxFamily and BPMxList |
---|
15 | % |
---|
16 | % 2. BPMyFamily - BPMy family name {Default: getvbpmfamily} |
---|
17 | % BPMyDeviceList - BPMy device list {Default: all devices with good status} |
---|
18 | % or |
---|
19 | % BPMyStruct can replace BPMyFamily and BPMyList |
---|
20 | % |
---|
21 | % 3. HCMFamily - HCM family name {Default: gethcmfamily} |
---|
22 | % HCMDeviceList - HCM device list {Default: all devices with good status} |
---|
23 | % or |
---|
24 | % HCMStruct can replace HCMFamily and HCMList |
---|
25 | % |
---|
26 | % 4. VCMFamily - VCM family name {Default: getvcmfamily} |
---|
27 | % VCMDeviceList - VCM device list {Default: all devices with good status} |
---|
28 | % or |
---|
29 | % VCMStruct can replace VCMFamily and VCMList |
---|
30 | % |
---|
31 | % 5. FileName - File name for response matrix (or cell array of file names) {Default: use getfamilydata('OpsData','RespFiles')} |
---|
32 | % [] or '' - prompt the user to choose a response matrix file |
---|
33 | % To put the filename anywhere in the function call use the keyword, 'Filename' followed by the actual |
---|
34 | % filename or [] to get a dialog box. For example, m = getbpmresp('FileName','RmatABC') to search in RmatABC.mat. |
---|
35 | % |
---|
36 | % 6. GeV is the energy that the response matrix will be used at {Default or []: getenergy}. |
---|
37 | % It's not always desirable to scale by the energy, so the following keywords can be used. |
---|
38 | % 'EnergyScaling' - Scale the response matrix by energy (getenergy / measured energy) {Default} |
---|
39 | % 'NoEnergyScaling' - Don't scale with energy |
---|
40 | % 7. 'Struct' will return the response matrix structure {Default if BPMxFamily is a structure input} |
---|
41 | % 'Numeric' will return a numeric matrix {Default for non-data structure inputs} |
---|
42 | % |
---|
43 | % OUTPUTS |
---|
44 | % 1. Rmat = Orbit response matrix (delta(orbit)/delta(Kick)) |
---|
45 | % |
---|
46 | % Numeric Output: |
---|
47 | % Rmat = [x/x x/y |
---|
48 | % y/x y/y] |
---|
49 | % |
---|
50 | % Ie, columns are correctors arranged horizontal to vertical |
---|
51 | % rows are BPMs arranged horizontal to vertical |
---|
52 | % |
---|
53 | % Stucture Output: |
---|
54 | % Rmat(BPM Plane, Corrector Plane) - 2x2 struct array |
---|
55 | % Rmat(1,1).Data = x/x; % Kick x, look x |
---|
56 | % Rmat(2,1).Data = y/x; % Kick x, look y |
---|
57 | % Rmat(1,2).Data = x/y; % Kick y, look x |
---|
58 | % Rmat(2,2).Data = y/y; % Kick y, look y |
---|
59 | % |
---|
60 | % Rmat(Monitor, Actuator).Data - Response matrix |
---|
61 | % .Monitor - BPM data structure (starting orbit) |
---|
62 | % .Monitor1 - BPM matrix (first data point) |
---|
63 | % .Monitor2 - BPM matrix (second data point) |
---|
64 | % .Actuator - Corrector data structure |
---|
65 | % .ActuatorDelta - Corrector kick vector |
---|
66 | % .GeV - Electron beam energy |
---|
67 | % .ModulationMethod - 'unipolar' or 'bipolar' |
---|
68 | % .WaitFlag - Wait flag used when acquiring data |
---|
69 | % .TimeStamp |
---|
70 | % .CreatedBy |
---|
71 | % .DCCT |
---|
72 | % |
---|
73 | % 2. FileName = File name where the data was found |
---|
74 | % |
---|
75 | % |
---|
76 | % NOTES |
---|
77 | % 1. If the DeviceList is empty, [], or not present, all the device in that response matrix will be returned. |
---|
78 | % 2. GeV will linearly scale the response matrix from the measured energy. |
---|
79 | % |
---|
80 | % |
---|
81 | % EXAMPLES |
---|
82 | % 1. Get the default corrector to BPM response matrix and plot |
---|
83 | % S = getbpmresp; |
---|
84 | % or |
---|
85 | % S = getbpmresp('BPMx', 'BPMy', 'HCM', 'VCM'); |
---|
86 | % surf(S); |
---|
87 | % |
---|
88 | % 2. Get a HCM to BPM response matrix but return as a structure |
---|
89 | % S = getbpmresp('BPMx', 'BPMy', 'HCM', 'VCM', 'Struct'); |
---|
90 | % |
---|
91 | % 4. Structure inputs: |
---|
92 | % Xmon = getx([1 1;1 2; 1 3],'struct'); |
---|
93 | % Ymon = gety([1 1;1 2; 1 3],'struct'); |
---|
94 | % Xact = getsp('HCM', [1 1;2 1;2 2;4 1],'struct'); |
---|
95 | % Yact = getsp('VCM', [1 1;2 1;2 2;4 1],'struct'); |
---|
96 | % S = getbpmresp(Xmon, Ymon, Xact, Yact); |
---|
97 | % Returns the same matrix as in Example 1. |
---|
98 | % |
---|
99 | % See also getrespmat, measbpmresp, measrespmat |
---|
100 | % |
---|
101 | % Written by Greg Portmann |
---|
102 | |
---|
103 | |
---|
104 | % Initialize defaults |
---|
105 | BPMxFamily = gethbpmfamily; |
---|
106 | if isempty(BPMxFamily) |
---|
107 | error('"BPMx" needs to be a MemberOf some family.'); |
---|
108 | end |
---|
109 | BPMxList = []; |
---|
110 | |
---|
111 | BPMyFamily = getvbpmfamily; |
---|
112 | if isempty(BPMyFamily) |
---|
113 | error('"BPMy" needs to be a MemberOf some family.'); |
---|
114 | end |
---|
115 | BPMyList = []; |
---|
116 | |
---|
117 | HCMFamily = gethcmfamily; |
---|
118 | if isempty(HCMFamily) |
---|
119 | error('"HCM" needs to be a MemberOf some family.'); |
---|
120 | end |
---|
121 | HCMList = []; |
---|
122 | HCMKicks = []; |
---|
123 | |
---|
124 | VCMFamily = getvcmfamily; |
---|
125 | if isempty(VCMFamily) |
---|
126 | error('"VCM" needs to be a MemberOf some family.'); |
---|
127 | end |
---|
128 | VCMList = []; |
---|
129 | VCMKicks = []; |
---|
130 | |
---|
131 | FileName = ''; |
---|
132 | InputFlags = {}; |
---|
133 | for i = length(varargin):-1:1 |
---|
134 | if isstruct(varargin{i}) |
---|
135 | % Ignor structures |
---|
136 | elseif iscell(varargin{i}) |
---|
137 | % Ignor cells |
---|
138 | elseif strcmpi(varargin{i},'Struct') |
---|
139 | InputFlags = [InputFlags varargin(i)]; |
---|
140 | varargin(i) = []; |
---|
141 | elseif strcmpi(varargin{i},'Numeric') |
---|
142 | InputFlags = [InputFlags varargin(i)]; |
---|
143 | varargin(i) = []; |
---|
144 | elseif strcmpi(varargin{i},'Model') || strcmpi(varargin{i},'Simulator') |
---|
145 | fprintf('WARNING: Model input ignored. Used measbpmresp to get the model response matrix.\n'); |
---|
146 | varargin(i) = []; |
---|
147 | elseif strcmpi(varargin{i},'EnergyScaling') |
---|
148 | InputFlags = [InputFlags varargin(i)]; |
---|
149 | varargin(i) = []; |
---|
150 | elseif strcmpi(varargin{i},'NoEnergyScaling') |
---|
151 | InputFlags = [InputFlags varargin(i)]; |
---|
152 | varargin(i) = []; |
---|
153 | elseif strcmpi(varargin{i},'Physics') |
---|
154 | InputFlags = [InputFlags varargin(i)]; |
---|
155 | varargin(i) = []; |
---|
156 | elseif strcmpi(varargin{i},'Hardware') |
---|
157 | InputFlags = [InputFlags varargin(i)]; |
---|
158 | varargin(i) = []; |
---|
159 | elseif strcmpi(varargin{i},'FileName') |
---|
160 | if length(varargin) >= i+1 && ischar(varargin{i+1}) |
---|
161 | FileName = varargin{i+1}; |
---|
162 | varargin(i:i+1) = []; |
---|
163 | else |
---|
164 | varargin(i) = []; |
---|
165 | end |
---|
166 | if isempty(FileName) |
---|
167 | DirectoryName = getfamilydata('Directory', 'BPMResponse'); |
---|
168 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a BPM response matrix file', DirectoryName); |
---|
169 | if FileName == 0 |
---|
170 | S = []; |
---|
171 | FileName = []; |
---|
172 | return; |
---|
173 | end |
---|
174 | FileName = [DirectoryName FileName]; |
---|
175 | end |
---|
176 | end |
---|
177 | end |
---|
178 | |
---|
179 | |
---|
180 | %%%%%%%%%%%%%%%% |
---|
181 | % Parse Inputs % |
---|
182 | %%%%%%%%%%%%%%%% |
---|
183 | |
---|
184 | % Special case: empty in input 1, ask for a file |
---|
185 | if length(varargin) == 1 && (isempty(varargin{1}) || strcmp(varargin{1},'.')) |
---|
186 | FileName = varargin{1}; |
---|
187 | varargin(1) = []; |
---|
188 | |
---|
189 | if isempty(FileName) |
---|
190 | DirectoryName = getfamilydata('Directory', 'BPMResponse'); |
---|
191 | elseif strcmp(FileName, '.') |
---|
192 | DirectoryName = ''; |
---|
193 | end |
---|
194 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a BPM response matrix file', DirectoryName); |
---|
195 | if FileName == 0 |
---|
196 | S = []; |
---|
197 | FileName = []; |
---|
198 | return; |
---|
199 | end |
---|
200 | FileName = [DirectoryName FileName]; |
---|
201 | end |
---|
202 | |
---|
203 | % Look for BPMx family info |
---|
204 | if length(varargin) >= 1 |
---|
205 | if isstruct(varargin{1}) |
---|
206 | BPMxFamily = varargin{1}.FamilyName; |
---|
207 | BPMxList = varargin{1}.DeviceList; |
---|
208 | varargin(1) = []; |
---|
209 | if ~any(strcmpi(InputFlags,'Numeric')) |
---|
210 | % Only change to structure output if 'Numeric' is not on the input line |
---|
211 | InputFlags = [{'Struct'} InputFlags]; |
---|
212 | end |
---|
213 | elseif ischar(varargin{1}) |
---|
214 | BPMxFamily = varargin{1}; |
---|
215 | varargin(1) = []; |
---|
216 | if length(varargin) >= 1 |
---|
217 | if isnumeric(varargin{1}) |
---|
218 | BPMxList = varargin{1}; |
---|
219 | varargin(1) = []; |
---|
220 | end |
---|
221 | end |
---|
222 | elseif isnumeric(varargin{1}) |
---|
223 | BPMxList = varargin{1}; |
---|
224 | varargin(1) = []; |
---|
225 | end |
---|
226 | end |
---|
227 | if isempty(BPMxList) && ~isempty(BPMxFamily) |
---|
228 | BPMxList = family2dev(BPMxFamily, 1); |
---|
229 | end |
---|
230 | |
---|
231 | % Look for BPMy family info |
---|
232 | if length(varargin) >= 1 |
---|
233 | if isstruct(varargin{1}) |
---|
234 | BPMyFamily = varargin{1}.FamilyName; |
---|
235 | BPMyList = varargin{1}.DeviceList; |
---|
236 | varargin(1) = []; |
---|
237 | elseif ischar(varargin{1}) |
---|
238 | BPMyFamily = varargin{1}; |
---|
239 | varargin(1) = []; |
---|
240 | if length(varargin) >= 1 |
---|
241 | if isnumeric(varargin{1}) |
---|
242 | BPMyList = varargin{1}; |
---|
243 | varargin(1) = []; |
---|
244 | end |
---|
245 | end |
---|
246 | elseif isnumeric(varargin{1}) |
---|
247 | BPMyList = varargin{1}; |
---|
248 | varargin(1) = []; |
---|
249 | end |
---|
250 | end |
---|
251 | if isempty(BPMyList) && ~isempty(BPMyFamily) |
---|
252 | BPMyList = family2dev(BPMyFamily, 1); |
---|
253 | end |
---|
254 | |
---|
255 | % Look for HCM family info |
---|
256 | if length(varargin) >= 1 |
---|
257 | if isstruct(varargin{1}) |
---|
258 | HCMFamily = varargin{1}.FamilyName; |
---|
259 | HCMList = varargin{1}.DeviceList; |
---|
260 | varargin(1) = []; |
---|
261 | elseif ischar(varargin{1}) |
---|
262 | HCMFamily = varargin{1}; |
---|
263 | varargin(1) = []; |
---|
264 | if length(varargin) >= 1 |
---|
265 | if isnumeric(varargin{1}) |
---|
266 | HCMList = varargin{1}; |
---|
267 | varargin(1) = []; |
---|
268 | end |
---|
269 | end |
---|
270 | elseif isnumeric(varargin{1}) |
---|
271 | HCMList = varargin{1}; |
---|
272 | varargin(1) = []; |
---|
273 | end |
---|
274 | end |
---|
275 | if isempty(HCMList) && ~isempty(HCMFamily) |
---|
276 | HCMList = family2dev(HCMFamily, 1); |
---|
277 | end |
---|
278 | |
---|
279 | % Look for VCM family info |
---|
280 | if length(varargin) >= 1 |
---|
281 | if isstruct(varargin{1}) |
---|
282 | VCMFamily = varargin{1}.FamilyName; |
---|
283 | VCMList = varargin{1}.DeviceList; |
---|
284 | varargin(1) = []; |
---|
285 | elseif ischar(varargin{1}) |
---|
286 | VCMFamily = varargin{1}; |
---|
287 | varargin(1) = []; |
---|
288 | if length(varargin) >= 1 |
---|
289 | if isnumeric(varargin{1}) |
---|
290 | VCMList = varargin{1}; |
---|
291 | varargin(1) = []; |
---|
292 | end |
---|
293 | end |
---|
294 | elseif isnumeric(varargin{1}) |
---|
295 | VCMList = varargin{1}; |
---|
296 | varargin(1) = []; |
---|
297 | end |
---|
298 | end |
---|
299 | if isempty(VCMList) && ~isempty(VCMFamily) |
---|
300 | VCMList = family2dev(VCMFamily, 1); |
---|
301 | end |
---|
302 | |
---|
303 | |
---|
304 | if length(varargin) >= 1 |
---|
305 | if ischar(varargin{1}) |
---|
306 | FileName = varargin{1}; |
---|
307 | varargin(1) = []; |
---|
308 | if isempty(FileName) |
---|
309 | DirectoryName = getfamilydata('Directory', 'BPMResponse'); |
---|
310 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a BPM response matrix file', DirectoryName); |
---|
311 | if FileName == 0 |
---|
312 | S = []; |
---|
313 | FileName = []; |
---|
314 | return; |
---|
315 | end |
---|
316 | FileName = [DirectoryName FileName]; |
---|
317 | end |
---|
318 | end |
---|
319 | end |
---|
320 | |
---|
321 | |
---|
322 | try |
---|
323 | |
---|
324 | if ~isempty(FileName) |
---|
325 | [S, FileName] = getrespmat({BPMxFamily, BPMyFamily}, {BPMxList, BPMyList}, {HCMFamily, VCMFamily}, {HCMList, VCMList}, FileName, InputFlags{:}); |
---|
326 | else |
---|
327 | [S, FileName] = getrespmat({BPMxFamily, BPMyFamily}, {BPMxList, BPMyList}, {HCMFamily, VCMFamily}, {HCMList, VCMList}, InputFlags{:}); |
---|
328 | end |
---|
329 | |
---|
330 | catch |
---|
331 | fprintf(' Could not find a BPM response matrix file, so using the model (%s & %s).\n', HCMFamily, VCMFamily); |
---|
332 | S = measbpmresp('Model',{BPMxFamily, BPMyFamily}, {BPMxList, BPMyList}, {HCMFamily, VCMFamily}, {HCMList, VCMList}, InputFlags{:}, varargin{:}); |
---|
333 | FileName = ''; |
---|
334 | end |
---|
335 | |
---|
336 | |
---|
337 | |
---|