1 | function quadalign(sx,sz) |
---|
2 | %QUADALIGN - Locates quadrupoles in AO and apply random alignment |
---|
3 | %quadalign(sx,sz); sx and sz are sigma values for randn; |
---|
4 | % units are meters |
---|
5 | % |
---|
6 | % INPUTS |
---|
7 | % 1. sx sigma for vertical plane |
---|
8 | % 2. sz sigma for horizontal plane |
---|
9 | % |
---|
10 | |
---|
11 | % |
---|
12 | % Written by SPEAR people |
---|
13 | % Modified by Laurent S. Nadolski |
---|
14 | |
---|
15 | cutoff = 3; % sigma |
---|
16 | |
---|
17 | if nargin<2 |
---|
18 | error('Error in quadalign - must supply alignment sigma values for both planes'); |
---|
19 | end |
---|
20 | |
---|
21 | global THERING |
---|
22 | AO = getao; |
---|
23 | |
---|
24 | ATindx=[]; %indices of quadrupoles |
---|
25 | mx=[]; |
---|
26 | my=[]; |
---|
27 | len = findspos(THERING,length(THERING)+1); |
---|
28 | |
---|
29 | |
---|
30 | QuadList = findmemberof('Quad'); |
---|
31 | |
---|
32 | for ii = 1:length(QuadList)-2, |
---|
33 | |
---|
34 | Family = QuadList{ii}; |
---|
35 | indx=AO.(Family).AT.ATIndex; |
---|
36 | |
---|
37 | %assign random alignment error to first magnet |
---|
38 | mx=[mx; sx*randncut('CutOff',cutoff)]; |
---|
39 | my=[my; sz*randncut('CutOff',cutoff)]; |
---|
40 | |
---|
41 | % assign random error to rest of family |
---|
42 | tol=1e-6; %tolerance for spacing between magnets |
---|
43 | for jj=2:length(indx) |
---|
44 | %check for split magnets |
---|
45 | if AO.(Family).Position(jj)-THERING{indx(jj)}.Length - AO.(Family).Position(jj-1)<tol %magnet split |
---|
46 | disp([' Split magnet ' AO{ii}.FamilyName ' found in function quadalign with index ', num2str(indx(jj))]); |
---|
47 | mx=[mx; -mx(end)]; |
---|
48 | my=[my; -my(end)]; |
---|
49 | else %magnet not split |
---|
50 | mx=[mx; sx*randn]; |
---|
51 | my=[my; sz*randn]; |
---|
52 | end |
---|
53 | |
---|
54 | end |
---|
55 | |
---|
56 | %check if first/last element split in THERING |
---|
57 | if abs(AO.(Family).Position(1)) < tol && ... %first element near zero |
---|
58 | abs((len - AO.(Family).Position(end) - THERING{indx(end)}.Length < tol)) %last element near end |
---|
59 | disp([' Split magnet ' AO.(Family).FamilyName ' found in function quadalign with index ',... |
---|
60 | num2str(indx(1)), ' ',num2str(indx(end))]); |
---|
61 | mx(end)=-mx(end-length(indx)+1); %error on last quad same as error on first quad in family |
---|
62 | my(end)=-my(end-length(indx)+1); |
---|
63 | end |
---|
64 | |
---|
65 | ATindx=[ATindx; indx]; |
---|
66 | end %end loop over families |
---|
67 | |
---|
68 | % my=sz*randn(1,length(ATindx)); |
---|
69 | % mx=sx*randn(1,length(ATindx)); |
---|
70 | setshift(ATindx,mx,my); |
---|
71 | |
---|