1 | function [DelSext, ActuatorFamily] = stepchro(varargin) |
---|
2 | %STEPCHRO - Incremental change in the chromaticity (Delta Tune / Delta RF) |
---|
3 | % [DelSext, SextFamily] = stepchro(DeltaChromaticity, ChroResponseMatrix) |
---|
4 | % |
---|
5 | % Step change in storage ring chromaticity using the default chromaticty correctors (findmemberof('Chromaticity Corrector')) |
---|
6 | % |
---|
7 | % INPUTS |
---|
8 | % 1. | Change in Horizontal Chromaticity | |
---|
9 | % DeltaChromaticity = | | |
---|
10 | % | Change in Vertical Chromaticity | |
---|
11 | % 2. ChroResponseMatrix - Chromaticity response matrix {Default: getchroresp} |
---|
12 | % 3. ActuatorFamily - Sextupoles to vary, ex {'S9', 'S10'} {Default: findmemberof('Chromaticity Corrector')'} |
---|
13 | % 4. Optional override of the units: |
---|
14 | % 'Physics' - Use physics units |
---|
15 | % 'Hardware' - Use hardware units |
---|
16 | % 5. Optional override of the mode: |
---|
17 | % 'Online' - Set/Get data online |
---|
18 | % 'Model' - Set/Get data on the simulated accelerator using AT |
---|
19 | % 'Simulator' - Set/Get data on the simulated accelerator using AT |
---|
20 | % 'Manual' - Set/Get data manually |
---|
21 | % |
---|
22 | % |
---|
23 | % OUTPUTS |
---|
24 | % 1. DelSext |
---|
25 | % 2. SextFamily - Families used (cell array) |
---|
26 | % |
---|
27 | % ALGORITHM |
---|
28 | % SVD method |
---|
29 | % DelSext = inv(CHROMATICITY_RESP_MATRIX) * DeltaChromaticity |
---|
30 | % |
---|
31 | % NOTES |
---|
32 | % 1. Beware of what units you are working in. The default units for chromaticity |
---|
33 | % are physics units. This is an exception to the normal middle layer convention. |
---|
34 | % Hardware units for "chromaticity" is in tune change per change in RF frequency. |
---|
35 | % Since this is an unusual unit to work with, the default units for chromaticity |
---|
36 | % is physics units. Note that goal chromaticity is also stored in physics units. |
---|
37 | % 2. The actuator family comes from findmemberof('Chromaticity Corrector') or 'SF','SD' if empty |
---|
38 | % |
---|
39 | % EXAMPLES |
---|
40 | % 1. use default families |
---|
41 | % stepchro([1 0.5]) |
---|
42 | % 2. use 10 families |
---|
43 | % Sfam = {'S1','S2','S3','S4','S5','S6','S7','S8','S9','S10'}; |
---|
44 | % B = measchroresp('Model','Display',Sfam); |
---|
45 | % stepchro([1 0.5],'Model',B,Sfam) |
---|
46 | % 3. To know by how much chromaticity change |
---|
47 | % getchroresp('Hardware')*[-31; 8]*getmcf*getrf |
---|
48 | % |
---|
49 | % See Also setchro |
---|
50 | |
---|
51 | % |
---|
52 | % Written by Gregory J. Portmann |
---|
53 | % Modifed by Laurent S. Nadolski |
---|
54 | % add ActuatorFamily as optional input |
---|
55 | |
---|
56 | ModeFlag = {}; |
---|
57 | UnitsFlag = {'Physics'}; |
---|
58 | |
---|
59 | for i = length(varargin):-1:1 |
---|
60 | if strcmpi(varargin{i},'Physics') |
---|
61 | UnitsFlag = varargin(i); |
---|
62 | varargin(i) = []; |
---|
63 | elseif strcmpi(varargin{i},'Hardware') |
---|
64 | UnitsFlag = varargin(i); |
---|
65 | varargin(i) = []; |
---|
66 | elseif strcmpi(varargin{i},'Simulator') | strcmpi(varargin{i},'Model') |
---|
67 | ModeFlag = varargin(i); |
---|
68 | varargin(i) = []; |
---|
69 | elseif strcmpi(varargin{i},'Online') |
---|
70 | ModeFlag = varargin(i); |
---|
71 | varargin(i) = []; |
---|
72 | elseif strcmpi(varargin{i},'Manual') |
---|
73 | ModeFlag = varargin(i); |
---|
74 | varargin(i) = []; |
---|
75 | end |
---|
76 | end |
---|
77 | |
---|
78 | |
---|
79 | if length(varargin) >= 1 |
---|
80 | DeltaChrom = varargin{1}; |
---|
81 | else |
---|
82 | DeltaChrom = []; |
---|
83 | end |
---|
84 | if isempty(DeltaChrom) |
---|
85 | answer = inputdlg({'Change the horizontal chromaticity by', 'Change the vertical chromaticity by'},'STEPCHRO',1,{'0','0'}); |
---|
86 | if isempty(answer) |
---|
87 | return |
---|
88 | end |
---|
89 | DeltaChrom(1,1) = str2num(answer{1}); |
---|
90 | DeltaChrom(2,1) = str2num(answer{2}); |
---|
91 | end |
---|
92 | DeltaChrom = DeltaChrom(:); |
---|
93 | if size(DeltaChrom,1) ~= 2 |
---|
94 | error('Input must be a 2x1 column vector.'); |
---|
95 | end |
---|
96 | if DeltaChrom(1)==0 && DeltaChrom(2)==0 |
---|
97 | return |
---|
98 | end |
---|
99 | |
---|
100 | if length(varargin) >= 2 |
---|
101 | ChroResponseMatrix = varargin{2}; |
---|
102 | else |
---|
103 | ChroResponseMatrix = []; |
---|
104 | end |
---|
105 | if isempty(ChroResponseMatrix) |
---|
106 | ChroResponseMatrix = getchroresp(UnitsFlag{:}); |
---|
107 | end |
---|
108 | if isempty(ChroResponseMatrix) |
---|
109 | error('The chromaticity response matrix must be an input or available in one of the default response matrix files.'); |
---|
110 | end |
---|
111 | |
---|
112 | if length(varargin) >= 3 |
---|
113 | ActuatorFamily = varargin{3}; |
---|
114 | else |
---|
115 | ActuatorFamily = findmemberof('Chromaticity Corrector')'; |
---|
116 | if isempty(ActuatorFamily) |
---|
117 | ActuatorFamily = {'S9','S10'}; |
---|
118 | end |
---|
119 | end |
---|
120 | |
---|
121 | % 1. SVD Tune Correction |
---|
122 | % Decompose the chromaticity response matrix: |
---|
123 | [U, S, V] = svd(ChroResponseMatrix, 'econ'); |
---|
124 | % ChroResponseMatrix = U*S*V' |
---|
125 | % |
---|
126 | % The V matrix columns are the singular vectors in the sextupole magnet space |
---|
127 | % The U matrix columns are the singular vectors in the chromaticity space |
---|
128 | % U'*U=I and V*V'=I |
---|
129 | % |
---|
130 | % CHROCoef is the projection onto the columns of ChroResponseMatrix*V(:,Ivec) (same space as spanned by U) |
---|
131 | % Sometimes it's interesting to look at the size of these coefficients with singular value number. |
---|
132 | CHROCoef = diag(diag(S).^(-1)) * U' * DeltaChrom; |
---|
133 | % |
---|
134 | % Convert the vector CHROCoef back to coefficents of ChroResponseMatrix |
---|
135 | DelSext = V * CHROCoef; |
---|
136 | |
---|
137 | |
---|
138 | % 2. Square matrix solution |
---|
139 | %DelSext = inv(ChroResponseMatrix) * DeltaChrom; |
---|
140 | |
---|
141 | |
---|
142 | SP = getsp(ActuatorFamily, UnitsFlag{:}, ModeFlag{:}); |
---|
143 | |
---|
144 | if iscell(SP) |
---|
145 | for i = 1:length(SP) |
---|
146 | SP{i} = SP{i} + DelSext(i); |
---|
147 | end |
---|
148 | else |
---|
149 | SP = SP + DelSext; |
---|
150 | end |
---|
151 | |
---|
152 | |
---|
153 | setsp(ActuatorFamily, SP, UnitsFlag{:}, ModeFlag{:}); |
---|
154 | |
---|