1 | function [ChromaticityMatrix, FileName] = getchroresp(varargin) |
---|
2 | %GETCHRORESP - Loads the chromaticity response vector (or matrix) for multiple sextupole families |
---|
3 | % [ChromaticityMatrix, FileName] = getchroresp(FamilyName1, DeviceList1, FamilyName2, DeviceList2, ... , FileName, GeV) |
---|
4 | % [ChromaticityMatrix, FileName] = getchroresp(DataStructure1, DataStructure2, ... , FileName, GeV) |
---|
5 | % |
---|
6 | % INPUTS |
---|
7 | % 1. FamilyName - Sextupole family name |
---|
8 | % 2. DeviceList - DeviceList for a sextupole family. If [] or no input, then ChromaticityMatrix |
---|
9 | % will be a column vector which is the cumulative sum of all magnets in the family. |
---|
10 | % 3. FileName - File name to look for the response matrix (or cell array of file names) |
---|
11 | % '' prompts the user to choose a response matrix file |
---|
12 | % 4. GeV will linearly scale the response matrix from the measured energy {Default: getenergy}. |
---|
13 | % Note: FamilyName and DeviceList can be cell arrays instead of multiple input pairs |
---|
14 | % |
---|
15 | % OUTPUTS |
---|
16 | % 1. ChromaticityMatrix - Response matrix {Default is physics units} |
---|
17 | % |
---|
18 | % It is assumed that most common use of this function is with the chromaticity |
---|
19 | % corrector families on a ganged power supply. Hence, the default |
---|
20 | % behavior is to return the cumulative sum of all the magnets in the chain. |
---|
21 | % If there is more than one FamilyName, then ChromaticityMatrix will be a matrix |
---|
22 | % where each column is the sum of the contribution of all magnets in that family. |
---|
23 | % |
---|
24 | % To get the response matrix for individual magnets in the family use getrespmat: |
---|
25 | % getrespmat('Chromaticity', [1 1;1 2], MagnetFamilyName, MagnetDeviceList) |
---|
26 | % For instance, getrespmat('Chromaticity', [1 1;1 2], 'SF', []) |
---|
27 | % |
---|
28 | % EXAMPLES |
---|
29 | % 1. M = getchroresp |
---|
30 | % M = getchroresp( 'SF','SD') |
---|
31 | % M = getchroresp({'SF','SD'}) |
---|
32 | % M = getchroresp({'SF','SD'},{[],[]}) |
---|
33 | % All returns the same 2x2 matrix of SF and SD to horizontal and vertical chromaticity |
---|
34 | % |
---|
35 | % 2. M = getchroresp('SF') |
---|
36 | % M = getchroresp('SF', []) |
---|
37 | % M = getchroresp('SF',getlist('SF')) |
---|
38 | % Returns a 2x1 matrix representing the cumulative sum of all the magnets in the chain |
---|
39 | % |
---|
40 | % 3. SF_DataStruct = getsp('SF','Struct'); |
---|
41 | % M = getchroresp(SF_DataStruct); |
---|
42 | % Returns a 2x1 matrix representing the cumulative sum of all the magnets in the chain |
---|
43 | % |
---|
44 | % 4. Change the chromaticity by [.1; -.1] using the entire 'SF' and 'SD' families (see stepchro) |
---|
45 | % DeltaChromaticity = [.1; -.1]; |
---|
46 | % DeltaAmps = inv(getchroresp) * DeltaChromaticity; |
---|
47 | % setsp({'SF', 'SD'}, {getsp('SF')+DeltaAmps(1), getsp('SD')+DeltaAmps(2)}); |
---|
48 | % |
---|
49 | % Written by Greg Portmann |
---|
50 | |
---|
51 | % |
---|
52 | % Written by Gregory J. Portmann |
---|
53 | % Modified By Laurent S. Nadolski |
---|
54 | |
---|
55 | FileName = ''; |
---|
56 | NumericFlag = 1; |
---|
57 | InputFlags = {}; |
---|
58 | for i = length(varargin):-1:1 |
---|
59 | if isstruct(varargin{i}) |
---|
60 | % Ignore structures |
---|
61 | elseif iscell(varargin{i}) |
---|
62 | % Ignore cells |
---|
63 | elseif strcmpi(varargin{i},'Struct') |
---|
64 | NumericFlag = 0; |
---|
65 | varargin(i) = []; |
---|
66 | elseif strcmpi(varargin{i},'Numeric') |
---|
67 | NumericFlag = 1; |
---|
68 | varargin(i) = []; |
---|
69 | elseif strcmpi(varargin{i},'Online') |
---|
70 | % Remove |
---|
71 | fprintf(' GETCHRORESP WARNING: ''Online'' input ignored. Used measchroresp to get the chromaticity response matrix.\n'); |
---|
72 | varargin(i) = []; |
---|
73 | elseif strcmpi(varargin{i},'Simulator') |
---|
74 | % Remove |
---|
75 | fprintf(' GETCHRORESP WARNING: ''Simulator'' input ignored.\n Used measchroresp(''Simulator'') to get the simulated chromaticity response matrix.\n'); |
---|
76 | varargin(i) = []; |
---|
77 | elseif strcmpi(varargin{i},'Model') |
---|
78 | % Remove |
---|
79 | fprintf(' GETCHRORESP WARNING: ''Model'' input ignored.\n Use measchroresp(''Model'') to get the model chromaticity response matrix.\n'); |
---|
80 | varargin(i) = []; |
---|
81 | elseif strcmpi(varargin{i},'Physics') |
---|
82 | InputFlags = [InputFlags varargin(i)]; |
---|
83 | varargin(i) = []; |
---|
84 | elseif strcmpi(varargin{i},'Hardware') |
---|
85 | InputFlags = [InputFlags varargin(i)]; |
---|
86 | varargin(i) = []; |
---|
87 | elseif strcmpi(varargin{i},'FileName') |
---|
88 | if length(varargin) >= i+1 && ischar(varargin{i+1}) |
---|
89 | FileName = varargin{i+1}; |
---|
90 | varargin(i:i+1) = []; |
---|
91 | else |
---|
92 | varargin(i) = []; |
---|
93 | end |
---|
94 | if isempty(FileName) |
---|
95 | DirectoryName = getfamilydata('Directory', 'ChroResponse'); |
---|
96 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a chromaticity response matrix file', DirectoryName); |
---|
97 | InputFlags = [InputFlags {[DirectoryName FileName]}]; |
---|
98 | end |
---|
99 | end |
---|
100 | end |
---|
101 | |
---|
102 | |
---|
103 | % Default units |
---|
104 | if ~any(strcmpi(InputFlags,'Physics')) && ~any(strcmpi(InputFlags,'Hardware')) |
---|
105 | InputFlags{length(InputFlags)+1} = 'Physics'; |
---|
106 | end |
---|
107 | |
---|
108 | |
---|
109 | ActuatorFamilyDefault = findmemberof('Chromaticity Corrector')'; |
---|
110 | if isempty(ActuatorFamilyDefault) |
---|
111 | ActuatorFamilyDefault = {'S9','S10'}; |
---|
112 | end |
---|
113 | |
---|
114 | if isempty(varargin) |
---|
115 | FamilyNameCell = ActuatorFamilyDefault; |
---|
116 | DeviceListCell = cell(size(ActuatorFamilyDefault)); |
---|
117 | NumFamilies = length(ActuatorFamilyDefault); |
---|
118 | |
---|
119 | elseif length(varargin) == 1 && isempty(varargin{1}) |
---|
120 | FamilyNameCell = ActuatorFamilyDefault; |
---|
121 | DeviceListCell = cell(size(ActuatorFamilyDefault)); |
---|
122 | NumFamilies = length(ActuatorFamilyDefault); |
---|
123 | |
---|
124 | elseif iscell(varargin{1}) |
---|
125 | FamilyNameCell = varargin{1}; |
---|
126 | varargin(1) = []; |
---|
127 | if length(varargin) >= 1 |
---|
128 | DeviceListCell = varargin{1}; |
---|
129 | varargin(1) = []; |
---|
130 | else |
---|
131 | for i = 1:length(FamilyNameCell) |
---|
132 | DeviceListCell{i} = []; |
---|
133 | end |
---|
134 | end |
---|
135 | NumFamilies = length(FamilyNameCell); |
---|
136 | if ~iscell(DeviceListCell) |
---|
137 | error('If FamilyName is a cell array then DeviceList must be a cell array') |
---|
138 | end |
---|
139 | |
---|
140 | elseif isstruct(varargin{1}) |
---|
141 | NumFamilies = 0; |
---|
142 | while ~isempty(varargin) |
---|
143 | % Look for Family and DeviceList |
---|
144 | if length(varargin) >= 1 |
---|
145 | if ~isstruct(varargin{1}) |
---|
146 | break |
---|
147 | end |
---|
148 | if ~isfamily(varargin{1}.FamilyName) |
---|
149 | error('Unknown family name in data structure'); |
---|
150 | end |
---|
151 | NumFamilies = NumFamilies + 1; |
---|
152 | FamilyNameCell{NumFamilies} = varargin{1}.FamilyName; |
---|
153 | DeviceListCell{NumFamilies} = varargin{1}.DeviceList; |
---|
154 | varargin(1) = []; |
---|
155 | end |
---|
156 | end |
---|
157 | |
---|
158 | else |
---|
159 | NumFamilies = 0; |
---|
160 | while ~isempty(varargin) |
---|
161 | % Look for Family and DeviceList |
---|
162 | if length(varargin) >= 1 |
---|
163 | if ~isfamily(varargin{1}) |
---|
164 | break |
---|
165 | end |
---|
166 | NumFamilies = NumFamilies + 1; |
---|
167 | FamilyNameCell{NumFamilies} = varargin{1}; |
---|
168 | varargin(1) = []; |
---|
169 | end |
---|
170 | if length(varargin) >= 1 |
---|
171 | if isnumeric(varargin{1}) || isempty(varargin{1}) |
---|
172 | DeviceListCell{NumFamilies} = varargin{1}; |
---|
173 | varargin(1) = []; |
---|
174 | else |
---|
175 | DeviceListCell{NumFamilies} = []; |
---|
176 | end |
---|
177 | else |
---|
178 | DeviceListCell{NumFamilies} = []; |
---|
179 | end |
---|
180 | end |
---|
181 | end |
---|
182 | |
---|
183 | |
---|
184 | % FileName should be the next input (if a string, or [] for dialog box) |
---|
185 | if length(varargin) >= 1 |
---|
186 | if ischar(varargin{1}) || isempty(varargin{1}) |
---|
187 | FileName = varargin{1}; |
---|
188 | varargin(1) = []; |
---|
189 | |
---|
190 | if isempty(FileName) |
---|
191 | % Note: This only works if all families are in the same file |
---|
192 | DirectoryName = getfamilydata('Directory', 'ChroResponse'); |
---|
193 | [FileName, DirectoryName, FilterIndex] = uigetfile('*.mat','Select Sextupole-to-Chromaticity Response Matrix File', DirectoryName); |
---|
194 | if FilterIndex == 0 |
---|
195 | ChromaticityMatrix = []; |
---|
196 | FileName = []; |
---|
197 | return |
---|
198 | end |
---|
199 | |
---|
200 | FileName = [DirectoryName FileName]; |
---|
201 | InputFlags = [{FileName} InputFlags]; |
---|
202 | end |
---|
203 | end |
---|
204 | end |
---|
205 | |
---|
206 | |
---|
207 | % The only thing left on the input line can be energy which can be left in varargin |
---|
208 | |
---|
209 | |
---|
210 | % Get the response matrix |
---|
211 | if NumericFlag == 1 |
---|
212 | ChromaticityMatrix = []; |
---|
213 | end |
---|
214 | for i = 1:NumFamilies |
---|
215 | if NumericFlag == 1 |
---|
216 | try |
---|
217 | [M, FileName] = getrespmat('Chromaticity', [1 1;1 2], FamilyNameCell{i}, DeviceListCell{i}, 'Numeric', InputFlags{:}, varargin{:}); |
---|
218 | catch |
---|
219 | fprintf(' Could not find a chromaticity response matrix file, so using the model (%s).\n', FamilyNameCell{i}); |
---|
220 | M = measchroresp(FamilyNameCell{i}, DeviceListCell{i}, 'Model', 'Numeric', InputFlags{:}, varargin{:}); |
---|
221 | %M = measrespmat('Chromaticity', [1 1;1 2], FamilyNameCell{i}, DeviceListCell{i}, 'Model', 'Numeric', InputFlags{:}, varargin{:}); |
---|
222 | FileName = ''; |
---|
223 | end |
---|
224 | ChromaticityMatrix = [ChromaticityMatrix sum(M,2)]; |
---|
225 | else |
---|
226 | try |
---|
227 | [ChromaticityMatrix(1,i), FileName] = getrespmat('Chromaticity', [1 1;1 2], FamilyNameCell{i}, DeviceListCell{i}, 'Struct', InputFlags{:}, varargin{:}); |
---|
228 | %ChromaticityMatrix(1,i).Data = sum(ChromaticityMatrix(1,i).Data,2); |
---|
229 | %ChromaticityMatrix(1,i).ActuatorDelta = mean(ChromaticityMatrix(1,i).ActuatorDelta,1); |
---|
230 | %ChromaticityMatrix(1,i).Actuator.Data = mean(ChromaticityMatrix(1,i).Actuator.Data,1); |
---|
231 | catch |
---|
232 | fprintf(' Could not find a chromaticity response matrix file, so using the model (%s).\n', FamilyNameCell{i}); |
---|
233 | ChromaticityMatrix(1,i) = measchroresp(FamilyNameCell{i}, DeviceListCell{i}, 'Model', 'Struct', InputFlags{:}, varargin{:}); |
---|
234 | FileName = ''; |
---|
235 | end |
---|
236 | end |
---|
237 | end |
---|
238 | |
---|