1 | function 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 | |
---|
17 | if nargin < 1 |
---|
18 | CMFamily = gethcmfamily; |
---|
19 | end |
---|
20 | if nargin < 2 |
---|
21 | mm = []; |
---|
22 | end |
---|
23 | if 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]; |
---|
28 | end |
---|
29 | if nargin < 3 |
---|
30 | CMDeviceList = []; |
---|
31 | end |
---|
32 | if isempty(CMDeviceList) |
---|
33 | CMDeviceList = family2dev(CMFamily); |
---|
34 | end |
---|
35 | if nargin < 4 |
---|
36 | XAxisFlag = 'meters'; |
---|
37 | end |
---|
38 | CMDeviceList = CMDeviceList(1,:); |
---|
39 | |
---|
40 | Fig = gcf; |
---|
41 | |
---|
42 | % X-axis |
---|
43 | if 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'; |
---|
48 | else |
---|
49 | BPMxspos = getspos(gethbpmfamily); |
---|
50 | BPMyspos = getspos(getvbpmfamily); |
---|
51 | XLabel = 'BPM Position [meters]'; |
---|
52 | end |
---|
53 | |
---|
54 | % BPM plane |
---|
55 | if ~isempty(findstr(upper(CMFamily),'H')) || ~isempty(findstr(upper(CMFamily),'X')) |
---|
56 | BPMFamily = gethbpmfamily; |
---|
57 | BPMspos = BPMxspos; |
---|
58 | elseif ~isempty(findstr(upper(CMFamily),'V')) || ~isempty(findstr(upper(CMFamily),'Y')) || ... |
---|
59 | ~isempty(findstr(upper(CMFamily),'Z')) |
---|
60 | BPMFamily = getvbpmfamily; |
---|
61 | BPMspos = BPMyspos; |
---|
62 | else |
---|
63 | error('Not sure if corrector family is horizontal or vertical.'); |
---|
64 | end |
---|
65 | BPMDeviceList = family2dev(BPMFamily); |
---|
66 | |
---|
67 | |
---|
68 | mm = mm(:)'; |
---|
69 | Amps = mm2amp(CMFamily, mm, CMDeviceList); |
---|
70 | |
---|
71 | |
---|
72 | % Get data |
---|
73 | x0 = getam(BPMFamily, 'struct'); |
---|
74 | SP0 = 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 | |
---|
86 | for 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); |
---|
90 | end |
---|
91 | setsp(CMFamily, SP0.Data, CMDeviceList, -2); |
---|
92 | |
---|
93 | |
---|
94 | C = getfamilydata('Circumference'); |
---|
95 | |
---|
96 | save bpmresplinearitydata |
---|
97 | |
---|
98 | figure(Fig); |
---|
99 | clf reset |
---|
100 | h1 = subplot(3,1,1); |
---|
101 | plot(BPMspos, x, '.-'); |
---|
102 | ylabel(sprintf('%s [%s]', BPMFamily, x0.UnitsString)); |
---|
103 | title(sprintf('BPM linearity using storage Ring Orbit Response for %s(%d,%d)', CMFamily, CMDeviceList(1,1), CMDeviceList(1,2))); |
---|
104 | if ~isempty(C) |
---|
105 | xaxis([0 C]); |
---|
106 | end |
---|
107 | |
---|
108 | for i = 1:size(x,2) |
---|
109 | x(:,i) = x(:,i)/Amps(i); |
---|
110 | end |
---|
111 | |
---|
112 | h2 = subplot(3,1,2); |
---|
113 | plot(BPMspos, x, '.-'); |
---|
114 | ylabel(sprintf('%s [%s/%s]', BPMFamily, x0.UnitsString, SP0.UnitsString)); |
---|
115 | |
---|
116 | x00 = x(:,1); |
---|
117 | for i = 1:size(x,2) |
---|
118 | x(:,i) = x(:,i) - x00; |
---|
119 | end |
---|
120 | |
---|
121 | h3 = subplot(3,1,3); |
---|
122 | plot(BPMspos, x, '.-'); |
---|
123 | xlabel(XLabel); |
---|
124 | ylabel(sprintf('Response Matrix Differences')); |
---|
125 | |
---|
126 | linkaxes([h1 h2 h3],'x') |
---|
127 | set([h1 h2 h3],'XGrid','On','YGrid','On'); |
---|
128 | |
---|
129 | addlabel(1, 0, datestr(clock,0)); |
---|