1 | %function [xix xiz] = measchronat |
---|
2 | % MEASCHRONAT - Measure natural chromaticities by varying dipole fied |
---|
3 | % |
---|
4 | % INPUTS |
---|
5 | % |
---|
6 | % OUTPUTS |
---|
7 | % 1. xix - horizontal natural chromaticity |
---|
8 | % 2. xiz - vertical natural chromaticity |
---|
9 | |
---|
10 | % |
---|
11 | % Written by Laurent S. Nadolski |
---|
12 | |
---|
13 | % TODO List |
---|
14 | % Tuning of the time constantes, RMN probe takes around 15 to 20 s to refresh its data |
---|
15 | |
---|
16 | nb = 4; |
---|
17 | tune= []; |
---|
18 | Idip = []; |
---|
19 | Rmn = []; |
---|
20 | itot = 1; % total step for dipole in A |
---|
21 | istep = -itot/nb; % stepsize in A |
---|
22 | |
---|
23 | tune_start = gettune; |
---|
24 | stepsp('BEND',itot); |
---|
25 | fprintf('Dipole current (%f A) is changed by %f\n',getsp('BEND'), itot); |
---|
26 | fprintf('Wait ...'); |
---|
27 | pause |
---|
28 | Idip(1) = getsp('BEND'); |
---|
29 | % for ik1 = 1:100, |
---|
30 | % temp(ik1) = getam('BEND'); pause(0.1) |
---|
31 | % end |
---|
32 | %Idip(1) = mean(temp); |
---|
33 | Rmn(1) = getrmn; |
---|
34 | tune(1,:) = gettune |
---|
35 | |
---|
36 | k1 = 2; |
---|
37 | for k = nb:-1:-nb+1, |
---|
38 | stepsp('BEND',istep); |
---|
39 | pause(10); |
---|
40 | %fprintf('Wait ...\n'); |
---|
41 | %pause |
---|
42 | Idip(k1) = getsp('BEND'); |
---|
43 | % for ik1 = 1:100, |
---|
44 | % temp(ik1) = getam('BEND'); pause(0.1) |
---|
45 | % end |
---|
46 | % Idip(k1) = mean(temp); |
---|
47 | fprintf('Dipole current (%f A) is changed by %f A\n',Idip(k1), istep); |
---|
48 | tune(k1,:) = gettune |
---|
49 | Rmn(k1) = getrmn; |
---|
50 | k1 = k1 + 1; |
---|
51 | end |
---|
52 | |
---|
53 | stepsp('BEND',itot); |
---|
54 | fprintf('Dipole current (%f A) is changed back to nominal value by %f A\n',getsp('BEND'), itot); |
---|
55 | pause(10); |
---|
56 | |
---|
57 | tune_finish = gettune; |
---|
58 | |
---|
59 | fprintf('Tune variation \n') |
---|
60 | fprintf('begin %f %f\n',tune_start) |
---|
61 | fprintf('end %f %f\n',tune_finish) |
---|
62 | |
---|
63 | % BUG should accept a array |
---|
64 | E = []; |
---|
65 | |
---|
66 | for k = 1:length(Idip), |
---|
67 | E(k) = bend2gev(Idip(k)); |
---|
68 | end |
---|
69 | |
---|
70 | E0 = 2.73913739373611; |
---|
71 | % E = (E-E0)./E0; |
---|
72 | % E = E'; |
---|
73 | E = (Rmn-Rmn(nb+1))./Rmn(nb+1); |
---|
74 | E = E'; |
---|
75 | |
---|
76 | %% |
---|
77 | p1 = polyfit(E,tune(:,1),1) |
---|
78 | p2 = polyfit(E,tune(:,2),1) |
---|
79 | |
---|
80 | fprintf('natural chromaticity xix = %4.1f xiz = %4.1f\n',p1(1),p2(1)); |
---|
81 | |
---|
82 | %% |
---|
83 | figure; |
---|
84 | subplot(2,1,1) |
---|
85 | suptitle(sprintf('Natural chromaticities xix = %4.1f xiz = %4.1f\n',p1(1),p2(1))); |
---|
86 | plot(E*100,tune(:,1),'.-') |
---|
87 | hold on |
---|
88 | plot(E*100,polyval(p1,E), 'k') |
---|
89 | |
---|
90 | ylabel('nux') |
---|
91 | grid on |
---|
92 | subplot(2,1,2) |
---|
93 | plot(E*100,tune(:,2),'.-') |
---|
94 | hold on |
---|
95 | plot(E*100,polyval(p2,E), 'k') |
---|
96 | ylabel('nuz') |
---|
97 | xlabel('Energy deviation [%]'); |
---|
98 | grid on |
---|
99 | |
---|
100 | xix = p1(1); xiz = p2(1); |
---|