1 | function [c, FileName] = plotchro(varargin) |
---|
2 | %PLOTCHRO - Plot the chromaticity function |
---|
3 | % c = plotchro(c); |
---|
4 | % c = plotchro(c, 'Hardware'); plots in hardware units [Tune/MHz] |
---|
5 | % c = plotchro(c, 'Physics'); plots in physics units [Tune/(dp/p)] |
---|
6 | % c = plotchro(FileName); |
---|
7 | % [c, FileName] = plotchro(''); prompts for a file |
---|
8 | % |
---|
9 | % INPUTS |
---|
10 | % 1. c is the chromacity structure returned by measchro |
---|
11 | % 2. PhysicsString is the units 'Hardware' or 'Physics' |
---|
12 | % |
---|
13 | % OUTPUTS |
---|
14 | % 1. c is the chromacity structure returned by measchro |
---|
15 | % |
---|
16 | % NOTES |
---|
17 | % 1.'Zeta' can be used instead of 'Physics' |
---|
18 | % 2. The default units comes from the structure c.Units |
---|
19 | % |
---|
20 | % See Also measchro, getchro |
---|
21 | |
---|
22 | % |
---|
23 | % Written by Greg Portmann and Jeff Corbett |
---|
24 | % Modified by Laurent S. Nadolski |
---|
25 | |
---|
26 | c = []; |
---|
27 | PhysicsString = ''; |
---|
28 | FileName = ''; |
---|
29 | |
---|
30 | |
---|
31 | % Input parsing |
---|
32 | UnitsFlag = {}; |
---|
33 | for i = length(varargin):-1:1 |
---|
34 | if isstruct(varargin{i}) |
---|
35 | % Ignor structures |
---|
36 | elseif iscell(varargin{i}) |
---|
37 | % Ignor cells |
---|
38 | elseif strcmpi(varargin{i},'Zeta') || strcmpi(varargin{i},'Physics') |
---|
39 | UnitsFlag = [UnitsFlag varargin(i)]; |
---|
40 | %if length(varargin) >= i+1 % Not using these inputs at the moment |
---|
41 | % if isnumeric(varargin{i+1}) |
---|
42 | % MCF = varargin{i+1}; |
---|
43 | % if length(varargin) >= i+2 |
---|
44 | % if isnumeric(varargin{i+2}) |
---|
45 | % RF0 = varargin{i+2}; |
---|
46 | % varargin(i+2) = []; |
---|
47 | % end |
---|
48 | % end |
---|
49 | % varargin(i+1) = []; |
---|
50 | % end |
---|
51 | %end |
---|
52 | varargin(i) = []; |
---|
53 | elseif strcmpi(varargin{i},'Hardware') |
---|
54 | UnitsFlag = [UnitsFlag varargin(i)]; |
---|
55 | varargin(i) = []; |
---|
56 | end |
---|
57 | end |
---|
58 | |
---|
59 | |
---|
60 | if length(varargin) >= 1 |
---|
61 | if isstruct(varargin{1}) |
---|
62 | c = varargin{1}; |
---|
63 | elseif ischar(varargin{1}) |
---|
64 | FileName = varargin{1}; |
---|
65 | end |
---|
66 | end |
---|
67 | if isempty(c) |
---|
68 | [c, FileName] = getchro(FileName, 'Struct', UnitsFlag{:}); |
---|
69 | end |
---|
70 | if ~isstruct(c) |
---|
71 | error('Input must be a structure as returned by measchro'); |
---|
72 | end |
---|
73 | |
---|
74 | if strcmpi(c.Mode,'Model') |
---|
75 | warning('Measured taken as Model and not as Simulator. Not implemented') |
---|
76 | end |
---|
77 | |
---|
78 | Chromaticity = c.Data; |
---|
79 | Tune = c.Tune; |
---|
80 | Units = c.Units; |
---|
81 | UnitsString = c.UnitsString; |
---|
82 | DeltaRF = c.ActuatorDelta; |
---|
83 | |
---|
84 | % Override the Units field |
---|
85 | if isempty(UnitsFlag) |
---|
86 | PhysicsString = Units; |
---|
87 | else |
---|
88 | PhysicsString = UnitsFlag{1}; |
---|
89 | end |
---|
90 | |
---|
91 | |
---|
92 | if strcmpi(Units, 'Hardware') |
---|
93 | if strcmpi(PhysicsString,'Physics') |
---|
94 | % Change units to physics |
---|
95 | % MCF = c.MCF; |
---|
96 | % RF0 = c.Actuator.Data; |
---|
97 | % p = polyfit(c.dp, Tune(1,:), 2); |
---|
98 | % c.PolyFit(1,:) = p; |
---|
99 | % c.Data(1,1) = p(2); |
---|
100 | % p = polyfit(c.dp, Tune(2,:), 2); |
---|
101 | % c.PolyFit(2,:) = p; |
---|
102 | % c.Data(2,1) = p(2); |
---|
103 | % c.Units = 'Physics'; |
---|
104 | % c.UnitsString = '1/(dp/p)'; |
---|
105 | c = hw2physics(c); |
---|
106 | plotchro(c); |
---|
107 | return |
---|
108 | end |
---|
109 | |
---|
110 | %================================================ |
---|
111 | % Tune shift vs. rf frequency |
---|
112 | %================================================ |
---|
113 | x2 = linspace(min(DeltaRF), max(DeltaRF), 1000); |
---|
114 | |
---|
115 | clf reset |
---|
116 | set(gcf,'NumberTitle','on','Name','Tune Shift vs. RF Frequency'); |
---|
117 | subplot(2,1,1); |
---|
118 | if strcmpi(c.Actuator.UnitsString,'MHz') |
---|
119 | % Hz is easier to view |
---|
120 | plot(1e6*DeltaRF, Tune(1,:), 'ob','markersize',2); % plot raw tune data |
---|
121 | else |
---|
122 | plot(DeltaRF, Tune(1,:), 'ob','markersize',2); % plot raw tune data |
---|
123 | end |
---|
124 | hold on; |
---|
125 | p = c.PolyFit(1,:); |
---|
126 | y = polyval(p, x2); % evaluate polynomial on equispaced points x2 |
---|
127 | if strcmpi(c.Actuator.UnitsString,'MHz') |
---|
128 | plot(1e6*x2, y, '-b'); % plot polynomial fit |
---|
129 | xlabel('RF Frequency Change [Hz]'); |
---|
130 | else |
---|
131 | plot(x2, y, '-b'); % plot polynomial fit |
---|
132 | xlabel(sprintf('RF Frequency Change [%s]', c.Actuator.UnitsString)); |
---|
133 | end |
---|
134 | hold off; |
---|
135 | title([num2str(p(1)),' x (drf/rf)^2 + ',num2str(p(2)),' x drf/rf + ',num2str(p(3))]); |
---|
136 | ylabel('Horizontal Tune'); |
---|
137 | |
---|
138 | subplot(2,1,2); |
---|
139 | if strcmpi(c.Actuator.UnitsString,'MHz') |
---|
140 | plot(1e6*DeltaRF, Tune(2,:), 'ob','markersize',2); % plot raw tune data |
---|
141 | else |
---|
142 | plot(DeltaRF, Tune(2,:), 'ob','markersize',2); % plot raw tune data |
---|
143 | end |
---|
144 | hold on; |
---|
145 | p = c.PolyFit(2,:); |
---|
146 | y = polyval(p, x2); |
---|
147 | if strcmpi(c.Actuator.UnitsString,'MHz') |
---|
148 | plot(1e6*x2, y, '-b'); % plot polynomial fit |
---|
149 | xlabel('RF Frequency Change [Hz]'); |
---|
150 | else |
---|
151 | plot(x2, y, '-b'); % plot polynomial fit |
---|
152 | xlabel(sprintf('RF Frequency Change [%s]', c.Actuator.UnitsString)); |
---|
153 | end |
---|
154 | hold off; |
---|
155 | title([num2str(p(1)),' x (drf/rf)^2 + ',num2str(p(2)),' x drf/rf + ',num2str(p(3))]); |
---|
156 | ylabel('Vertical Tune'); |
---|
157 | if any(strcmpi(c.Monitor.Mode, {'Model','Simulator'})) |
---|
158 | addlabel(1,0,sprintf('%s (Model)', datestr(c.TimeStamp,0))); |
---|
159 | else |
---|
160 | addlabel(1,0,sprintf('%s', datestr(c.TimeStamp,0))); |
---|
161 | end |
---|
162 | orient tall |
---|
163 | |
---|
164 | elseif strcmpi(Units, 'Physics') |
---|
165 | if strcmpi(PhysicsString,'Hardware') |
---|
166 | % Change units to hardware |
---|
167 | %MCF = c.MCF; |
---|
168 | %RF0 = c.Actuator.Data; |
---|
169 | %p = polyfit(DeltaRF, Tune(1,:), 2); |
---|
170 | %c.PolyFit(1,:) = p; |
---|
171 | %c.Data(1,1) = p(2); |
---|
172 | %p = polyfit(DeltaRF, Tune(2,:), 2); |
---|
173 | %c.PolyFit(2,:) = p; |
---|
174 | %c.Data(2,1) = p(2); |
---|
175 | %c.Units = 'Hardware'; |
---|
176 | %c.UnitsString = c.Actuator.UnitsString; |
---|
177 | c = physics2hw(c); |
---|
178 | |
---|
179 | plotchro(c); |
---|
180 | return |
---|
181 | end |
---|
182 | |
---|
183 | %================================================ |
---|
184 | % Tune shift vs. momentum |
---|
185 | %================================================ |
---|
186 | x2 = linspace(min(c.dp), max(c.dp), 1000); %create momentum value interval |
---|
187 | |
---|
188 | clf reset |
---|
189 | set(gcf,'NumberTitle','on','Name','Tune Shift vs. Momentum '); |
---|
190 | subplot(2,1,1); |
---|
191 | plot(100*c.dp,Tune(1,:), 'ob','markersize',2); %raw data |
---|
192 | hold on; |
---|
193 | p = c.PolyFit(1,:); |
---|
194 | y = polyval(p, x2); %evaluate polynomial on equispaced points x2 |
---|
195 | plot(100*x2, y, '-b'); %plot polynomial fit |
---|
196 | hold off; |
---|
197 | xlabel('Momentum Shift, dp/p [%]') |
---|
198 | title([num2str(p(1)),' (dp/p)^2 + ',num2str(p(2)),' dp/p + ',num2str(p(3))]); |
---|
199 | ylabel('Horizontal Tune'); |
---|
200 | |
---|
201 | subplot(2,1,2); |
---|
202 | plot(100*c.dp,Tune(2,:),'ob','markersize',2); |
---|
203 | hold on; |
---|
204 | p = c.PolyFit(2,:); |
---|
205 | y = polyval(p, x2); |
---|
206 | plot(100*x2, y, '-b'); |
---|
207 | hold off; |
---|
208 | |
---|
209 | xlabel('Momentum Shift, dp/p [%]') |
---|
210 | title([num2str(p(1)),' (dp/p)^2 + ',num2str(p(2)),' dp/p + ',num2str(p(3))]); |
---|
211 | ylabel('Vertical Tune'); |
---|
212 | if any(strcmpi(c.Monitor.Mode, {'Model','Simulator'})) |
---|
213 | addlabel(1,0,sprintf('%s (Model)', datestr(c.TimeStamp,0))); |
---|
214 | else |
---|
215 | addlabel(1,0,sprintf('%s', datestr(c.TimeStamp,0))); |
---|
216 | end |
---|
217 | %addlabel(1,0,sprintf('%s', datestr(c.TimeStamp,0))); |
---|
218 | orient tall |
---|
219 | |
---|
220 | else |
---|
221 | error('UnitsString unknown type'); |
---|
222 | end |
---|