source: MML/trunk/mml/at/linepass1turn.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.3 KB
Line 
1function [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
32global THERING
33if isempty(THERING)
34    error('THERING is not defined.');
35end
36
37
38% AT units meters & radians
39if nargin < 1
40    x0 = [];
41end
42if isempty(x0)
43    % 1 mm starting offset
44    x0 = [.001 0, 0.001, 0, 0, 0]';
45end
46
47x0 = x0(:);
48if size(x0,1) == 4
49    x0 = [x0; 0; 0];
50elseif size(x0,1) ~= 6
51    error('x0 must be a 4x1 or 6x1 vector.');
52end
53
54if nargin < 2
55    Family0 = [];
56end
57if isempty(Family0)
58    Family0 = 'BPMx';
59end
60if nargin < 3
61    DeviceList0 = [];
62end
63
64if nargin < 4
65    Family = [];
66end
67if isempty(Family)
68    Family = 'BPMx';
69end
70if nargin < 5
71    DeviceList  = [];
72end
73
74
75% Get AT index
76if 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
92else
93    % AT index was input directly
94    ATindex0 = Family0;
95    ATindex = DeviceList0;
96end
97
98if any(size(ATindex0) ~= [1 1])
99    error('DeviceList0 must be one location.');
100end
101
102
103ATindex = ATindex(:)';
104if isempty(ATindex)
105    error('AT index empty.');
106end
107
108
109% Propagrate single turn data around the ring
110% xAllBPMs (6 x BPM Number)
111
112% Find forward and backward BPMs
113iForward  = find(ATindex >= ATindex0);
114iBackward = find(ATindex < ATindex0);
115
116x = [];
117if ~isempty(iForward)
118    Index = ATindex(iForward) - ATindex0 + 1;
119    x = linepass(THERING([ATindex0:ATindex(iForward(end))]), x0, Index);
120end
121
122if ~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];
143end
144
Note: See TracBrowser for help on using the repository browser.