1 | function [Rmcf1 Rmcf2]=modelmcfsensitivity(varargin) |
---|
2 | %modelmcfsensitivity - Computes 1st and 2nd mcf variation with quadrupole |
---|
3 | % and/or sextupole family magnets |
---|
4 | % INPUTS |
---|
5 | % 'Quad'/'NoQuad'- Compute or not mcf variation versus quadrupoles |
---|
6 | % 'Sextu'/'NoSextu'- Compute or not mcf variation versus quadrupoles |
---|
7 | % |
---|
8 | % OUTPUTS |
---|
9 | % 1. Rmcf1 - first order mcf response matrix |
---|
10 | % 2. Rmcf2 - second order mcf response matrix |
---|
11 | % |
---|
12 | % NOTES |
---|
13 | % 1. S11 and S1 are seen as a unique family |
---|
14 | % 2. Value depends on the optics for the moment see below the sextu steps |
---|
15 | % |
---|
16 | % See Also modeltunesensitivity, modechrosensitivity |
---|
17 | % |
---|
18 | % Written by Laurent S. Nadolski |
---|
19 | |
---|
20 | FirstOrderFlag = 0; |
---|
21 | QuadFlag = 0; |
---|
22 | SextuFlag = 0; |
---|
23 | |
---|
24 | % Flag factory parser |
---|
25 | for i = length(varargin):-1:1 |
---|
26 | if strcmpi(varargin{i},'Quad') |
---|
27 | QuadFlag = 1; |
---|
28 | varargin(i) = []; |
---|
29 | elseif strcmpi(varargin{i},'NoQuad') |
---|
30 | QuadFlag = 0; |
---|
31 | varargin(i) = []; |
---|
32 | elseif strcmpi(varargin{i},'Sextu') |
---|
33 | SextuFlag = 1; |
---|
34 | varargin(i) = []; |
---|
35 | elseif strcmpi(varargin{i},'NoSextu') |
---|
36 | SextuFlag = 0; |
---|
37 | varargin(i) = []; |
---|
38 | end |
---|
39 | end |
---|
40 | |
---|
41 | fprintf(' ******** Summary for ''%s'' ********\n', getlatticename); |
---|
42 | |
---|
43 | quadFamList = findmemberof('QUAD'); |
---|
44 | |
---|
45 | if QuadFlag |
---|
46 | % remove nanoscopium |
---|
47 | quadFamList(12) = []; |
---|
48 | quadFamList(11) = []; |
---|
49 | % intitialization |
---|
50 | FamilyNumber= length(quadFamList); |
---|
51 | Rmcf1 = zeros(1,FamilyNumber); |
---|
52 | Rmcf2 = zeros(1,FamilyNumber); |
---|
53 | |
---|
54 | % Quadrupole variation in Ampere |
---|
55 | StepValue = ones(1,FamilyNumber)*0.1; % A |
---|
56 | |
---|
57 | fprintf('Quadrupole change for quadFamList change of %f A \n', StepValue(1)); |
---|
58 | for k = 1:FamilyNumber, |
---|
59 | |
---|
60 | Family = quadFamList{k}; |
---|
61 | |
---|
62 | stepsp(Family, 0.5*StepValue(k), 'Model'); % plus delta |
---|
63 | |
---|
64 | % Compute momentum compaction factor |
---|
65 | if FirstOrderFlag |
---|
66 | mcf1plus = getmcf('Model'); %linear value |
---|
67 | |
---|
68 | stepsp(Family, -StepValue(k), 'Model'); % minus delta |
---|
69 | |
---|
70 | mcf1minus = getmcf('Model'); |
---|
71 | else |
---|
72 | [mcf1plus mcf2plus] = physics_mcf('Nodisplay'); %by fitting |
---|
73 | |
---|
74 | stepsp(Family, -StepValue(k), 'Model'); % minus delta |
---|
75 | |
---|
76 | [mcf1minus mcf2minus] = physics_mcf('Nodisplay'); |
---|
77 | end |
---|
78 | |
---|
79 | stepsp(Family, 0.5*StepValue(k), 'Model'); % go back to nominal value |
---|
80 | |
---|
81 | % first mcf response matrix per Ampere |
---|
82 | Rmcf1(k) = (mcf1plus - mcf1minus) / StepValue(k); |
---|
83 | if ~FirstOrderFlag |
---|
84 | % second order mcf response matrix per Ampere |
---|
85 | Rmcf2(k) = (mcf2plus - mcf2minus) / StepValue(k); |
---|
86 | fprintf('%4s (1A): Delta MCF1 = %+1.2e Delta MCF2 = %+1.2e\n', ... |
---|
87 | Family, Rmcf1(k), Rmcf2(k)); |
---|
88 | else |
---|
89 | fprintf('%4s (1A): Delta MCF1 = %1.2e\n', Family, Rmcf1(k)); |
---|
90 | end |
---|
91 | |
---|
92 | end |
---|
93 | end |
---|
94 | |
---|
95 | if SextuFlag |
---|
96 | |
---|
97 | sextuFamList = findmemberof('Sext'); |
---|
98 | sextuFamList(12) = []; % nanoscopium |
---|
99 | sextuFamList(11) = []; % S11 is linked to S1 |
---|
100 | |
---|
101 | FamilyNumber= length(sextuFamList); |
---|
102 | Rmcf1 = zeros(1,FamilyNumber); |
---|
103 | Rmcf2 = zeros(1,FamilyNumber); |
---|
104 | |
---|
105 | % Sextupole variation in Ampere |
---|
106 | StepValue = ones(1,FamilyNumber)*0.1; % A |
---|
107 | |
---|
108 | fprintf('Sextupole change for sextuFamList change of %f A \n', StepValue(1)); |
---|
109 | for k = 1:FamilyNumber, |
---|
110 | |
---|
111 | Family = sextuFamList{k}; |
---|
112 | |
---|
113 | % step sextupole strength by plus delta |
---|
114 | if strcmp(Family, 'S1') % S1 and S11 are linked |
---|
115 | stepsp('S11', 0.5*StepValue(k), 'Model'); % minus delta |
---|
116 | end |
---|
117 | stepsp(Family, 0.5*StepValue(k), 'Model'); |
---|
118 | |
---|
119 | |
---|
120 | if FirstOrderFlag |
---|
121 | mcf1plus = getmcf('Model'); |
---|
122 | |
---|
123 | stepsp(Family, -StepValue(k), 'Model'); % minus delta |
---|
124 | |
---|
125 | mcf1minus = getmcf('Model'); |
---|
126 | else |
---|
127 | [mcf1plus mcf2plus] = physics_mcf('Nodisplay'); |
---|
128 | |
---|
129 | % step sextupole strength to minus delta |
---|
130 | if strcmp(Family, 'S1') % S1 and S11 are linked |
---|
131 | stepsp('S11', -StepValue(k), 'Model'); % minus delta |
---|
132 | end |
---|
133 | stepsp(Family, -StepValue(k), 'Model'); % minus delta |
---|
134 | |
---|
135 | [mcf1minus mcf2minus] = physics_mcf('Nodisplay'); |
---|
136 | end |
---|
137 | |
---|
138 | % First order mcf Response matrix per Ampere |
---|
139 | Rmcf1(k) = (mcf1plus - mcf1minus) / StepValue(k); |
---|
140 | |
---|
141 | % restore sextupole strength to nominal values |
---|
142 | if strcmp(Family, 'S1') % S1 and S11 are linked |
---|
143 | stepsp('S11', 0.5*StepValue(k), 'Model'); |
---|
144 | end |
---|
145 | stepsp(Family, 0.5*StepValue(k), 'Model'); % come back to nominal value |
---|
146 | |
---|
147 | if FirstOrderFlag |
---|
148 | fprintf('%4s (1A): Delta MCF1 = %1.2e\n', ... |
---|
149 | Family, Rmcf1(k)); |
---|
150 | else |
---|
151 | % Second order Response matrix per Ampere |
---|
152 | Rmcf2(k) = (mcf2plus - mcf2minus) / StepValue(k); |
---|
153 | fprintf('%4s (1A) : Delta MCF1 = %+1.2e Delta MCF2 = %+1.2e\n', ... |
---|
154 | Family, Rmcf1(k), Rmcf2(k)); |
---|
155 | end |
---|
156 | end |
---|
157 | end |
---|