1 | function [x, ATindex, LostBeam] = linepass1turn(x0, Family0, DeviceList0, Family, DeviceList) |
---|
2 | %LINEPASS1TURN - Track particle forward or backwards in one turn of the ring |
---|
3 | % [x, ATIndex] = linepass1turn(x0, Family, DeviceList) |
---|
4 | % [x, ATIndex] = linepass1turn(x0, ATIndex) |
---|
5 | % |
---|
6 | % INPUTS |
---|
7 | % 1. x0 - 6-component column vector {Default: [.001 0 .001 0 0]'} |
---|
8 | % Initial particle launch condition at the start of the ring (see ringpass) |
---|
9 | % AT units are meters & radians. |
---|
10 | % 2. Location to measure turns: Family / DeviceList {Default: 'BPMx'} |
---|
11 | % or |
---|
12 | % ATIndex |
---|
13 | % |
---|
14 | % NOTE: Family can be a MiddlyLayer family or AT family. |
---|
15 | % If using at AT family, then DeviceList is an index array (see family2atindex). |
---|
16 | % |
---|
17 | % OUTPUTS |
---|
18 | % 1. x - Single turn data (6 x BPM Number) |
---|
19 | % 2. ATIndex - AT index vector |
---|
20 | % |
---|
21 | % EXAMPLES |
---|
22 | % 1. Get the starting coordinates for a kick at HCM[7 1] |
---|
23 | % x = linepass1turn([.001 0 .001 0 0 0]', HCM, [7 1], 1); |
---|
24 | % |
---|
25 | % See also getturns |
---|
26 | % |
---|
27 | % Note: this function is still under development!!! |
---|
28 | % |
---|
29 | % Written by Greg Portmann |
---|
30 | |
---|
31 | |
---|
32 | global THERING |
---|
33 | if isempty(THERING) |
---|
34 | error('THERING is not defined.'); |
---|
35 | end |
---|
36 | |
---|
37 | |
---|
38 | % AT units meters & radians |
---|
39 | if nargin < 1 |
---|
40 | x0 = []; |
---|
41 | end |
---|
42 | if isempty(x0) |
---|
43 | % 1 mm starting offset |
---|
44 | x0 = [.001 0, 0.001, 0, 0, 0]'; |
---|
45 | end |
---|
46 | |
---|
47 | x0 = x0(:); |
---|
48 | if size(x0,1) == 4 |
---|
49 | x0 = [x0; 0; 0]; |
---|
50 | elseif size(x0,1) ~= 6 |
---|
51 | error('x0 must be a 4x1 or 6x1 vector.'); |
---|
52 | end |
---|
53 | |
---|
54 | if nargin < 2 |
---|
55 | Family0 = []; |
---|
56 | end |
---|
57 | if isempty(Family0) |
---|
58 | Family0 = 'BPMx'; |
---|
59 | end |
---|
60 | if nargin < 3 |
---|
61 | DeviceList0 = []; |
---|
62 | end |
---|
63 | |
---|
64 | if nargin < 4 |
---|
65 | Family = []; |
---|
66 | end |
---|
67 | if isempty(Family) |
---|
68 | Family = 'BPMx'; |
---|
69 | end |
---|
70 | if nargin < 5 |
---|
71 | DeviceList = []; |
---|
72 | end |
---|
73 | |
---|
74 | |
---|
75 | % Get AT index |
---|
76 | if ischar(Family0) |
---|
77 | ATindex0 = family2atindex(Family0, DeviceList0); |
---|
78 | % Watch for split magnets |
---|
79 | if size(ATindex0,2) > 1 |
---|
80 | ATindex0 = ATindex0(:,1); |
---|
81 | end |
---|
82 | if ischar(Family) |
---|
83 | ATindex = family2atindex(Family, DeviceList); |
---|
84 | % Watch for split magnets |
---|
85 | if size(ATindex,2) > 1 |
---|
86 | ATindex = ATindex(:,1); |
---|
87 | end |
---|
88 | else |
---|
89 | % AT index was input directly |
---|
90 | ATindex = Family; |
---|
91 | end |
---|
92 | else |
---|
93 | % AT index was input directly |
---|
94 | ATindex0 = Family0; |
---|
95 | ATindex = DeviceList0; |
---|
96 | end |
---|
97 | |
---|
98 | if any(size(ATindex0) ~= [1 1]) |
---|
99 | error('DeviceList0 must be one location.'); |
---|
100 | end |
---|
101 | |
---|
102 | |
---|
103 | ATindex = ATindex(:)'; |
---|
104 | if isempty(ATindex) |
---|
105 | error('AT index empty.'); |
---|
106 | end |
---|
107 | |
---|
108 | |
---|
109 | % Propagrate single turn data around the ring |
---|
110 | % xAllBPMs (6 x BPM Number) |
---|
111 | |
---|
112 | % Find forward and backward BPMs |
---|
113 | iForward = find(ATindex >= ATindex0); |
---|
114 | iBackward = find(ATindex < ATindex0); |
---|
115 | |
---|
116 | x = []; |
---|
117 | if ~isempty(iForward) |
---|
118 | Index = ATindex(iForward) - ATindex0 + 1; |
---|
119 | x = linepass(THERING([ATindex0:ATindex(iForward(end))]), x0, Index); |
---|
120 | end |
---|
121 | |
---|
122 | if ~isempty(iBackward) |
---|
123 | if x0(5)~=0 | x0(6)~=0 |
---|
124 | fprintf(' WARNING: x0(5) & x0(6) must be zero for propagating backwards in the ring to work correctly.\n'); |
---|
125 | end |
---|
126 | |
---|
127 | x0neg = x0; |
---|
128 | x0neg([2 4]) = -x0neg([2 4]); |
---|
129 | |
---|
130 | IndexBack = [ATindex(iBackward):ATindex0]-1; |
---|
131 | IndexBack(1) = []; |
---|
132 | |
---|
133 | %Index = ATindex0-IndexBack; |
---|
134 | ATIndexBack = ATindex(iBackward); |
---|
135 | Index = ATindex0 - ATIndexBack + 1; |
---|
136 | Index = Index(end:-1:1); |
---|
137 | |
---|
138 | xb = linepass(THERING(IndexBack(end:-1:1)), x0neg, Index); |
---|
139 | xb([2 4],:) = -xb([2 4],:); |
---|
140 | |
---|
141 | |
---|
142 | x = [xb(:,end:-1:1) x]; |
---|
143 | end |
---|
144 | |
---|