source: MML/trunk/mml/plotcm.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 7.7 KB
Line 
1function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = plotcm(varargin)
2%PLOTCM - Plots the horizontal and vertical corrector magnet families and
3%         computes the energy change due to the horizontal correctors.
4%
5%  [DeltaRF, DeltaEnergy, DeltaL] = plotcm(DeviceList, ...)
6%
7%  INPUTS (optional)
8%  1.  DeviceList
9%  2. 'Position' {Default} or 'Phase' for the x-axis units
10%  3. 'Display' - Plot orbit information {Default}
11%     'NoDisplay' - No plot
12%  4. 'Online', 'Model', 'Manual', 'Hardware', 'Physics', etc. (the usual Units and Mode flags)
13
14%
15%  OUTPUTS
16%  1. DeltaRF - RF change that equates to the energy change
17%  2. DeltaEnergy - Total energy change due to the horizontal correctors
18%  3. DeltaL - Path length change that equates to changing the RF by DeltaRF
19%
20%  See also findrf findrf1 rmdisp
21%
22%  Written by Greg Portmann
23
24
25DisplayFlag = 1;
26XAxisFlag = 'Position';
27
28
29% Input parsing
30InputFlags = {};
31for i = length(varargin):-1:1
32    if isstruct(varargin{i})
33        % Ignor structures
34    elseif iscell(varargin{i})
35        % Ignor cells
36    elseif strcmpi(varargin{i},'struct')
37        % Just remove
38        varargin(i) = [];
39    elseif strcmpi(varargin{i},'numeric')
40        % Just remove
41        varargin(i) = [];
42    elseif strcmpi(varargin{i},'Position')
43        XAxisFlag = 'Position';
44        varargin(i) = [];
45    elseif strcmpi(varargin{i},'Phase')
46        XAxisFlag = 'Phase';
47        varargin(i) = [];
48    elseif strcmpi(varargin{i},'Display')
49        DisplayFlag = 1;
50        varargin(i) = [];
51    elseif strcmpi(varargin{i},'NoDisplay')
52        DisplayFlag = 0;
53        varargin(i) = [];
54    end
55end
56
57
58% Get the default corrector families
59
60Family = gethcmfamily;
61if isempty(Family)
62    Family1 = 'HCM';
63else
64    Family1 = Family;
65end
66Family = getvcmfamily;
67if isempty(Family)
68    Family2 = 'VCM';
69else
70    Family2 = Family;
71end
72
73
74
75% SP or AM ???
76x = getam(Family1, 'Struct', varargin{:});
77y = getam(Family2, 'Struct', varargin{:});
78
79
80% Compute the energy change due to the correctors
81L = getfamilydata('Circumference');
82HCM = hw2physics(x);
83HCM = HCM.Data;
84
85
86if strcmpi(getfamilydata('Machine'),'ALS')
87    % For the ALS, either the HCMChicane magnets need to be included or
88    % the chicane "part" of the HCMs needs to be removed
89    Energy = getfamilydata('Energy');
90   
91    % Sector 6
92    %                   Off    1.9 GeV   1.5 GeV
93    % HCMCHICANEM(6,1)  80.0    18.0       ?
94    % HCMCHICANEM(6,1)  80.0    20.0       ?
95    % HCM(6,1)           0.0    18.8       ?
96    ihcm = findrowindex([6 1], x.DeviceList);
97    if length(ihcm) == 1
98        try
99            if getsp('HCMCHICANEM',[6 1]) < 70
100                % Assume sector 6 chicane is on
101                if Energy == 1.9
102                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, -18.8, [6 1]);
103                    x.Data(ihcm) = x.Data(ihcm) - 18.8;
104                else
105                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, -18.8*1.5/1.9, [6 1]);
106                    x.Data(ihcm) = x.Data(ihcm) - 18.8*1.5/1.9;
107                end
108            end
109        catch
110            fprintf('%s\n', lasterr);
111            fprintf('Problem reading HCMCHICANEM(6,1).  The chicane "offset" on HCM(6,1) will not be removed.\n\n');
112        end
113    end
114
115    % Sector 11
116    %                    Off    1.9 GeV   1.5 GeV
117    % HCMCHICANEM(11,1)  80.0    40.5      52.0
118    % HCMCHICANEM(11,1)  80.0    40.5      52.0
119    % HCM(10,8)           0.0   -17.0     -14.0
120    % HCM(11,1)           0.0   -17.0     -14.0
121    ihcm = findrowindex([10 8], x.DeviceList);
122    if length(ihcm) == 1
123        try
124            if getsp('HCMCHICANEM',[11 1]) < 60
125                % Assume sector 11 chicane is on
126                if Energy == 1.9
127                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, 17, [10 8]);
128                    x.Data(ihcm) = x.Data(ihcm) + 17;
129                else
130                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, 14, [10 8]);
131                    x.Data(ihcm) = x.Data(ihcm) + 14;
132                end
133            end
134        catch
135            fprintf('%s\n', lasterr);
136            fprintf('Due to an error, the chicane "offset" on HCM(10,8) will not be removed.n\n');
137        end
138    end
139    ihcm = findrowindex([11 1], x.DeviceList);
140    if length(ihcm) == 1
141        try
142            if getsp('HCMCHICANEM',[11 1]) < 60
143                % Assume sector 11 chicane is on
144                if Energy == 1.9
145                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, 17, [11 1]);
146                    x.Data(ihcm) = x.Data(ihcm) + 17;
147                else
148                    HCM(ihcm) = HCM(ihcm) + hw2physics(x.FamilyName, x.Field, 14, [11 1]);
149                    x.Data(ihcm) = x.Data(ihcm) + 14;
150                end
151            end
152        catch
153            fprintf('%s\n', lasterr);
154            fprintf('Due to an error, the chicane "offset" on HCM(11,1) will not be removed.n\n');
155        end
156    end
157end
158
159
160[DxHCM, DyHCM] = modeldisp([], x.FamilyName, x.DeviceList, 'Numeric', 'Physics');
161HCMEnergyChange = -1 * HCM .* DxHCM / getmcf / L;
162HCMEnergyChangeTotal = sum(HCMEnergyChange);
163
164% Delta RF to move the energy change due to the corrector to the RF frequency
165DeltaRF = -1 * getrf * getmcf * HCMEnergyChangeTotal;                     % Default units of getrf/setrf
166DeltaRFPhysics = -1 * getrf('Physics') * getmcf * HCMEnergyChangeTotal;   % Must be Hz
167
168DeltaL = L * getmcf * HCMEnergyChangeTotal;
169
170
171if DisplayFlag
172    LeftGraphColor = 'b';
173    RightGraphColor = 'r';
174
175    [RFUnits, RFUnitsString] = getunits('RF');
176
177    if strcmpi(XAxisFlag, 'Phase')
178        [BPMxspos, BPMyspos, Sx, Sy, Tune] = modeltwiss('Phase', x.FamilyName, x.DeviceList, y.FamilyName, y.DeviceList);
179        BPMxspos = BPMxspos/2/pi;
180        BPMyspos = BPMyspos/2/pi;
181        XLabel = 'Phase';
182    else
183        BPMxspos = getspos(x.FamilyName, x.DeviceList);
184        BPMyspos = getspos(y.FamilyName, y.DeviceList);
185        XLabel = 'Position [meters]';
186    end
187
188
189    hfig = gcf;
190    clf reset
191    %p = get(hfig, 'Position');
192    %set(hfig, 'Position', [p(1) p(2)-.8*p(4) p(3) p(4)+.8*p(4)]);
193   
194   
195    subplot(2,1,1);
196    [ax, h1, h2] = plotyy(BPMxspos, x.Data, BPMxspos, -HCMEnergyChange);
197    FontSize = get(ax(1), 'Fontsize');
198    title(sprintf('%s (%g rms [%s]):  Energy Change  \\Delta p / p  = \\Sigma \\delta_{hcm} \\eta_{hcm} / (-\\alpha L) = %.3e', Family1, std(x.Data), x.UnitsString, HCMEnergyChangeTotal), 'Fontsize',FontSize);
199    set(get(ax(1),'Ylabel'), 'String', sprintf('%s [%s]', Family1, x.UnitsString), 'Fontsize',FontSize);
200    set(get(ax(2),'Ylabel'), 'String', '-\Delta p/p', 'Color', RightGraphColor, 'Fontsize',FontSize);
201    set(h1, 'Marker','.');
202    set(h2, 'Marker','.');
203    %'\fontsize{14}\sigma_y \fontsize{10}BL 3.1 [\mum]'
204    set(ax(2), 'YColor', RightGraphColor);
205    set(h2, 'Color', RightGraphColor);
206    grid on
207
208    if ~strcmpi(XAxisFlag, 'Phase')
209        axes(ax(1));
210        aa = axis;
211        aa(1) = 0;
212        aa(2) = L;
213        axis(aa);
214        axes(ax(2));
215        aa = axis;
216        aa(1) = 0;
217        aa(2) = L;
218        axis(aa);
219    end
220
221
222    subplot(2,1,2);
223    plot(BPMyspos, y.Data, '.-');
224    title(sprintf('%s (%g rms [%s])', Family2, std(y.Data), y.UnitsString), 'Fontsize',FontSize);
225    xlabel(XLabel, 'Fontsize',FontSize);
226    ylabel(sprintf('%s [%s]',Family2, x.UnitsString), 'Color', LeftGraphColor, 'Fontsize',FontSize);
227    set(gca,'YColor', LeftGraphColor);
228    if ~strcmpi(XAxisFlag, 'Phase')
229        xaxis([0 L]);
230    end
231
232    addlabel(1, 0, datestr(clock,0), 7);
233    addlabel(0, 0, sprintf('Equivalent energy change using the RF is  \\DeltaRF = %g [%s]  \\DeltaL = %g [m]', DeltaRF, RFUnitsString, DeltaL), 7);
234
235    if strcmpi(getfamilydata('Machine'),'ALS')
236        addlabel(1, .5, 'Nominal chicane setting may have been removed from the HCM family', 7);
237    end
238end
239
240
Note: See TracBrowser for help on using the repository browser.