1 | function [KLeff, K, Leff] = getkleff(Family, varargin); |
---|
2 | %GETKLEFF - Returns K * Leff in the AT deck |
---|
3 | % KLeff = getkleff(Family, DeviceList) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. Family = Family Name |
---|
7 | % Accelerator Object |
---|
8 | % Cell Array of Accelerator Objects or Family Names |
---|
9 | % AT FamName |
---|
10 | % 2. DeviceList = [Sector Device #] or [element #] list {Default or empty list: entire family} |
---|
11 | % |
---|
12 | % NOTES |
---|
13 | % 1. If Family is a cell array, then DeviceList must also be a cell array |
---|
14 | % 2. If using AT FamName, then DeviceList is index vector, ie, |
---|
15 | % Length = THERING{ATIndexList}.Length(DeviceList) |
---|
16 | % |
---|
17 | % Written by Greg Portmann |
---|
18 | |
---|
19 | global THERING |
---|
20 | |
---|
21 | if nargin == 0, |
---|
22 | error('Must have at least one input (Family or Channel Name).'); |
---|
23 | end |
---|
24 | |
---|
25 | ATIndexList = getfamilydata(Family, 'AT', 'ATIndex', varargin{:}); |
---|
26 | |
---|
27 | if isempty(ATIndexList) |
---|
28 | % Try an AT family |
---|
29 | % For split families, this will return all the magnets |
---|
30 | ATIndexList = findcells(THERING, 'FamName', Family); |
---|
31 | ATIndexList = ATIndexList(:); |
---|
32 | if nargin >= 2 |
---|
33 | ATIndexList = ATIndexList(varargin{2}); |
---|
34 | end |
---|
35 | end |
---|
36 | |
---|
37 | |
---|
38 | Leff = getleff(Family, varargin{:}); |
---|
39 | |
---|
40 | |
---|
41 | % For split magnets this assumes that all K-values are the same |
---|
42 | for i=1:size(ATIndexList,1) |
---|
43 | if isfield(THERING{ATIndexList(i,1)},'K') |
---|
44 | % Could be QUAD or a BEND depend on the machine |
---|
45 | K(i,:) = THERING{ATIndexList(i,1)}.K; |
---|
46 | KLeff(i,:) = Leff(i) * K(i,:); |
---|
47 | elseif isfield(THERING{ATIndexList(i,1)},'KickAngle') & ismemberof(Family, 'HCM') |
---|
48 | % For correctors, KickAngle = B * Leff / Brho ??? (mradians) |
---|
49 | KLeff(i,:) = THERING{ATIndexList(i,1)}.KickAngle(1); |
---|
50 | if nargout >= 2 |
---|
51 | K(i,:) = KLeff(i,:) ./ Leff; |
---|
52 | end |
---|
53 | elseif isfield(THERING{ATIndexList(i,1)},'KickAngle') & ismemberof(Family, 'VCM') |
---|
54 | % For correctors, KickAngle = B * Leff / Brho ??? (mradians) |
---|
55 | % Hence, even if Leff = 0 (thin lense corrector) K*Leff will be right |
---|
56 | KLeff(i,:) = THERING{ATIndexList(i,1)}.KickAngle(2); |
---|
57 | if nargout >= 2 |
---|
58 | K(i,:) = KLeff(i,:) ./ Leff; |
---|
59 | end |
---|
60 | elseif isfield(THERING{ATIndexList(i,1)},'PolynomB') & ismemberof(Family, 'SEXT') |
---|
61 | K(i,:) = THERING{ATIndexList(i,1)}.PolynomB(3); |
---|
62 | KLeff(i,:) = Leff(i) * K(i,:); |
---|
63 | elseif isfield(THERING{ATIndexList(i,1)},'PolynomA') & ismemberof(Family, 'SKEWQUAD') |
---|
64 | K(i,:) = THERING{ATIndexList(i,1)}.PolynomA(2); |
---|
65 | KLeff(i,:) = Leff(i) * K(i,:); |
---|
66 | else |
---|
67 | error('Which field in THERING to use is not clear.'); |
---|
68 | end |
---|
69 | end |
---|
70 | |
---|