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

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

Initial import--MML version from SOLEIL@2013

File size: 3.2 KB
Line 
1function measbpmresplinearity(CMFamily, mm, CMDeviceList, XAxisFlag)
2% MEASBPMRESPLINEARITY - Compute BPMlinearity
3%
4%  INPUTS
5%  1. CMFamily - Corrector Magnet Family {Default: 'HCOR'}
6%  2. mm - Vector of given amplitude {Default: mm = [.5 1 1.5 2 2.5 3 3.5 4];
7%  3. CMDeviceList - BPM DeviceListe {Default: [1 1]}
8%  4. XaxisFlag - 'meters' or 'Phase' {Defaults: 'meters'}
9%
10%  NOTES
11%  1. Data saved in bpmresplinearitydata
12
13%
14%  Written By Gregory J. Portmann
15%  MOdified by Laurent S. Nadolski
16
17if nargin < 1
18    CMFamily = gethcmfamily;
19end
20if nargin < 2
21    mm = [];
22end
23if isempty(mm)
24    mm = [.05 .25 .5 .75 1 1.25 1.5 1.75 2];
25    %mm = [.25 .5 .75 1 1.25 1.5 1.75 2];
26    %mm = [.1 .2 .3 .4 .5 .6 .7 .8 .9 1];
27    mm = [.5 1 1.5 2 2.5 3 3.5 4];
28end
29if nargin < 3
30    CMDeviceList = [];
31end
32if isempty(CMDeviceList)
33    CMDeviceList = family2dev(CMFamily);
34end
35if nargin < 4
36    XAxisFlag = 'meters';
37end
38CMDeviceList = CMDeviceList(1,:);
39
40Fig = gcf;
41
42% X-axis
43if strcmpi(XAxisFlag, 'Phase')
44    [BPMxspos, BPMyspos, Sx, Sy, Tune] = modeltwiss('Phase', gethbpmfamily, [], getvbpmfamily, []);
45    BPMxspos = BPMxspos/2/pi;
46    BPMyspos = BPMyspos/2/pi;
47    XLabel = 'BPM Phase';
48else
49    BPMxspos = getspos(gethbpmfamily);
50    BPMyspos = getspos(getvbpmfamily);
51    XLabel = 'BPM Position [meters]';
52end
53
54% BPM plane
55if ~isempty(findstr(upper(CMFamily),'H')) || ~isempty(findstr(upper(CMFamily),'X'))
56    BPMFamily = gethbpmfamily;
57    BPMspos = BPMxspos;
58elseif ~isempty(findstr(upper(CMFamily),'V')) || ~isempty(findstr(upper(CMFamily),'Y')) || ...
59        ~isempty(findstr(upper(CMFamily),'Z'))
60    BPMFamily = getvbpmfamily;
61    BPMspos = BPMyspos;
62else
63    error('Not sure if corrector family is horizontal or vertical.');
64end
65BPMDeviceList = family2dev(BPMFamily);
66
67
68mm = mm(:)';
69Amps = mm2amp(CMFamily, mm, CMDeviceList);
70
71
72% Get data
73x0 = getam(BPMFamily, 'struct');
74SP0 = getsp(CMFamily, CMDeviceList, 'struct');
75
76% if strcmpi(getmode('HCM'), 'Online')
77%     Amps0 = mm2amps(CMFamily, .250, CMDeviceList);
78%
79% else
80%     Amps0 = mm2amps(CMFamily, .025, CMDeviceList);
81% end
82%
83% setsp(CMFamily, SP0 + Amps0, CMDeviceList, -2);
84% BPMResp0 = (getam(BPMFamily, BPMDeviceList) - x0.Data) / Amp0;
85   
86for i = 1:length(Amps)
87    setsp(CMFamily, SP0.Data + Amps(i), CMDeviceList, -2);
88    %x(:,i) = (getam(BPMFamily, BPMDeviceList) - x0.Data) / Amps(i);
89    x(:,i) = (getam(BPMFamily, BPMDeviceList) - x0.Data);
90end
91setsp(CMFamily, SP0.Data, CMDeviceList, -2);
92
93
94C = getfamilydata('Circumference');
95
96save bpmresplinearitydata
97
98figure(Fig);
99clf reset
100h1 = subplot(3,1,1);
101plot(BPMspos, x, '.-');
102ylabel(sprintf('%s [%s]', BPMFamily, x0.UnitsString));
103title(sprintf('BPM linearity using storage Ring Orbit Response for %s(%d,%d)', CMFamily, CMDeviceList(1,1), CMDeviceList(1,2)));
104if ~isempty(C)
105    xaxis([0 C]);
106end
107
108for i = 1:size(x,2)
109    x(:,i) = x(:,i)/Amps(i);
110end
111
112h2 = subplot(3,1,2);
113plot(BPMspos, x, '.-');
114ylabel(sprintf('%s [%s/%s]', BPMFamily, x0.UnitsString, SP0.UnitsString));
115
116x00 = x(:,1);
117for i = 1:size(x,2)
118    x(:,i) = x(:,i) - x00;
119end
120
121h3 = subplot(3,1,3);
122plot(BPMspos, x, '.-');
123xlabel(XLabel);
124ylabel(sprintf('Response Matrix Differences'));
125
126linkaxes([h1 h2 h3],'x')
127set([h1 h2 h3],'XGrid','On','YGrid','On');
128
129addlabel(1, 0, datestr(clock,0));
Note: See TracBrowser for help on using the repository browser.