1 | function plotbpmrespsym(R) |
---|
2 | %PLOTBPMRESPSYM - Looks for symmetry of the orbit response matrix |
---|
3 | % plotbpmrespsym(R) |
---|
4 | % plotbpmrespsym(FileName) |
---|
5 | % |
---|
6 | % NOTES |
---|
7 | % 1. This function is only informative if the lattice is |
---|
8 | % symmetric by sector. |
---|
9 | % 2. This function only works if the corrector and BPM |
---|
10 | % placement is symmetric in each sector. |
---|
11 | % |
---|
12 | % Written by Greg Portmann |
---|
13 | |
---|
14 | |
---|
15 | if nargin == 0 |
---|
16 | R = getbpmresp('Struct'); |
---|
17 | end |
---|
18 | if isempty(R) |
---|
19 | R = getbpmresp('','Struct'); |
---|
20 | end |
---|
21 | if isempty(R) |
---|
22 | return; |
---|
23 | end |
---|
24 | |
---|
25 | |
---|
26 | % Use physics units for scaling |
---|
27 | R = hw2physics(R); |
---|
28 | |
---|
29 | |
---|
30 | FontSize = 10; |
---|
31 | Buffer = .01; |
---|
32 | HeightBuffer = .08; |
---|
33 | |
---|
34 | |
---|
35 | Sx = R(1,1).Data; |
---|
36 | Sy = R(2,2).Data; |
---|
37 | |
---|
38 | NSectors = R(1,1).Monitor.DeviceList(end,1); |
---|
39 | NBPMxperSector = max(R(1,1).Monitor.DeviceList(:,2)); |
---|
40 | NBPMyperSector = max(R(2,2).Monitor.DeviceList(:,2)); |
---|
41 | |
---|
42 | NBPMx = size(Sx,1); |
---|
43 | NBPMy = size(Sy,1); |
---|
44 | |
---|
45 | NHCMperSector = max(R(1,1).Actuator.DeviceList(:,2)); |
---|
46 | NVCMperSector = max(R(2,2).Actuator.DeviceList(:,2)); |
---|
47 | |
---|
48 | %NHCMperSector = size(Sx,2) / NSectors; |
---|
49 | %NVCMperSector = size(Sy,2) / NSectors; |
---|
50 | |
---|
51 | Circumference = getfamilydata('Circumference'); |
---|
52 | |
---|
53 | BPMxs = getspos(R(1,1).Monitor.FamilyName, R(1,1).Monitor.DeviceList); |
---|
54 | BPMxs = BPMxs(:); |
---|
55 | BPMys = getspos(R(2,2).Monitor.FamilyName, R(2,2).Monitor.DeviceList); |
---|
56 | BPMys = BPMys(:); |
---|
57 | |
---|
58 | BPMxDev = R(1,1).Monitor.DeviceList; |
---|
59 | BPMyDev = R(2,2).Monitor.DeviceList; |
---|
60 | % BPMxelem = dev2elem(R(1,1).Monitor.FamilyName, R(1,1).Monitor.DeviceList); |
---|
61 | % BPMyelem = dev2elem(R(2,2).Monitor.FamilyName, R(2,2).Monitor.DeviceList); |
---|
62 | |
---|
63 | % BPMxGain = getgain(R(1,1).Monitor.FamilyName, R(1,1).Monitor.DeviceList); |
---|
64 | % BPMyGain = getgain(R(2,2).Monitor.FamilyName, R(2,2).Monitor.DeviceList); |
---|
65 | |
---|
66 | HCMDev = R(1,1).Actuator.DeviceList; |
---|
67 | VCMDev = R(2,2).Actuator.DeviceList; |
---|
68 | % HCMelem = dev2elem('HCM', R(1,1).Actuator.DeviceList); |
---|
69 | % VCMelem = dev2elem('VCM', R(2,2).Actuator.DeviceList); |
---|
70 | |
---|
71 | % % Hardware units to mradian |
---|
72 | % %HCMGain = getgain('HCM', R(1,1).Actuator.DeviceList); |
---|
73 | % HCMGain = 1 ./ (hw2physics('HCM', 'Setpoint', R(1,1).ActuatorDelta, HCMDev) ./ R(1,1).ActuatorDelta) / 1000; |
---|
74 | % |
---|
75 | % %VCMGain = getgain('VCM', R(2,2).Actuator.DeviceList); |
---|
76 | % VCMGain = 1 ./ (hw2physics('VCM', 'Setpoint', R(2,2).ActuatorDelta, VCMDev) ./ R(2,2).ActuatorDelta) / 1000; |
---|
77 | |
---|
78 | XUnitsString = R(1,1).UnitsString; |
---|
79 | XUnitsString(findstr(XUnitsString,'(')) = []; |
---|
80 | XUnitsString(findstr(XUnitsString,')')) = []; |
---|
81 | YUnitsString = R(2,2).UnitsString; |
---|
82 | YUnitsString(findstr(YUnitsString,'(')) = []; |
---|
83 | YUnitsString(findstr(YUnitsString,')')) = []; |
---|
84 | |
---|
85 | |
---|
86 | L = getfamilydata('Circumference'); |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | %%%%%%%%%%%%%% |
---|
91 | % Horizontal % |
---|
92 | %%%%%%%%%%%%%% |
---|
93 | |
---|
94 | % % Scale response matrix by the BPM gains |
---|
95 | % for i = 1:size(Sx,2) |
---|
96 | % Sx(:,i) = Sx(:,i) .* BPMxGain(:); |
---|
97 | % end |
---|
98 | % |
---|
99 | % % Scale response matrix by the HCM gains |
---|
100 | % for i = 1:size(Sx,1) |
---|
101 | % Sx(i,:) = Sx(i,:) .* HCMGain(:)'; |
---|
102 | % %Sx(i,:) = Sx(i,:) ./ hw2physics('HCM', 'Setpoint', 1, HCMDev)'/1000; |
---|
103 | % %Sx(i,:) = Sx(i,:) / (1000*amps2rad('HCM',1,i)); |
---|
104 | % end |
---|
105 | |
---|
106 | |
---|
107 | figure; |
---|
108 | clf reset |
---|
109 | set(gcf,'units','normal','position',[.0+Buffer .27+Buffer .5-2*Buffer .72-2*Buffer-HeightBuffer]); |
---|
110 | for Mag = 1:NHCMperSector |
---|
111 | S = []; |
---|
112 | P = []; |
---|
113 | for i = 1:NSectors |
---|
114 | j = findrowindex([i Mag], HCMDev); |
---|
115 | if ~isempty(j) |
---|
116 | k = min(find(BPMxDev(:,1)==i)); |
---|
117 | S = [S [Sx(k:end, j); Sx(1:k-1, j)]]; |
---|
118 | P = [P [BPMxs(k:end); BPMxs(1:k-1)+L]-BPMxs(k)+BPMxs(1)]; |
---|
119 | end |
---|
120 | end |
---|
121 | |
---|
122 | subplot(NHCMperSector, 1, Mag); |
---|
123 | if isempty(S) |
---|
124 | plot(BPMxs, NaN*ones(size(BPMxs))); |
---|
125 | else |
---|
126 | plot(P, S); |
---|
127 | end |
---|
128 | ylabel(sprintf('Mag #%d', Mag), 'FontSize', FontSize); |
---|
129 | end |
---|
130 | |
---|
131 | subplot(NHCMperSector,1,1); |
---|
132 | title(sprintf('Horizontal Corrector Magnet Response (%s)', XUnitsString), 'FontSize', FontSize); |
---|
133 | |
---|
134 | subplot(NHCMperSector,1,NHCMperSector); |
---|
135 | xlabel('BPM Position [meters]', 'FontSize', FontSize); |
---|
136 | if isfield(R(1,1), 'TimeStamp') |
---|
137 | addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp))); |
---|
138 | end |
---|
139 | orient tall |
---|
140 | |
---|
141 | |
---|
142 | %%%%%%%%%%%% |
---|
143 | % Vertical % |
---|
144 | %%%%%%%%%%%% |
---|
145 | |
---|
146 | % % Scale response matrix by the BPM gains |
---|
147 | % for i = 1:size(Sy,2) |
---|
148 | % Sy(:,i) = Sy(:,i) .* BPMyGain(:); |
---|
149 | % end |
---|
150 | % |
---|
151 | % % Scale response matrix by the VCM gains |
---|
152 | % for i = 1:size(Sy,1) |
---|
153 | % Sy(i,:) = Sy(i,:) .* VCMGain(:)'; |
---|
154 | % %Sy(i,:) = Sy(i,:) / (1000*amps2rad('VCM',1,i)); |
---|
155 | % end |
---|
156 | |
---|
157 | figure(gcf+1); |
---|
158 | clf reset |
---|
159 | set(gcf,'units','normal','position',[.5+Buffer .27+Buffer .5-2*Buffer .72-2*Buffer-HeightBuffer]); |
---|
160 | |
---|
161 | for Mag = 1:NVCMperSector |
---|
162 | S = []; |
---|
163 | P = []; |
---|
164 | for i = 1:NSectors |
---|
165 | j = findrowindex([i Mag], VCMDev); |
---|
166 | if ~isempty(j) |
---|
167 | k = min(find(BPMyDev(:,1)==i)); |
---|
168 | S = [S [Sy(k:end, j); Sy(1:k-1, j)]]; |
---|
169 | P = [P [BPMys(k:end); BPMys(1:k-1)+L]-BPMys(k)+BPMys(1)]; |
---|
170 | end |
---|
171 | end |
---|
172 | |
---|
173 | subplot(NVCMperSector, 1, Mag); |
---|
174 | if isempty(S) |
---|
175 | plot(BPMys, NaN*ones(size(BPMys))); |
---|
176 | else |
---|
177 | plot(P, S); |
---|
178 | end |
---|
179 | ylabel(sprintf('Mag #%d', Mag), 'FontSize', FontSize); |
---|
180 | end |
---|
181 | |
---|
182 | subplot(NVCMperSector,1,1); |
---|
183 | title(sprintf('Vertical Corrector Magnet Response (%s)', XUnitsString), 'FontSize', FontSize); |
---|
184 | |
---|
185 | subplot(NVCMperSector,1,NVCMperSector); |
---|
186 | xlabel('BPM Position [meters]', 'FontSize', FontSize); |
---|
187 | if isfield(R(1,1), 'TimeStamp') |
---|
188 | addlabel(1,0,sprintf('%s', datestr(R(1,1).TimeStamp))); |
---|
189 | end |
---|
190 | orient tall |
---|
191 | |
---|
192 | |
---|