1 | function bendalign(sx,sy); |
---|
2 | %locate bend magnets in AO and return alignment to zero |
---|
3 | %function bendalign(sx,sy); sx and sy are sigma values for randn; |
---|
4 | %units are meters |
---|
5 | if nargin<2 |
---|
6 | disp('Error in bendalign - must supply alignment spreads'); |
---|
7 | return |
---|
8 | end |
---|
9 | |
---|
10 | global THERING |
---|
11 | AO = getao; |
---|
12 | |
---|
13 | ATindx=[]; %indices of bend magnets |
---|
14 | mx=[]; |
---|
15 | my=[]; |
---|
16 | len=findspos(THERING,length(THERING)+1); |
---|
17 | |
---|
18 | for ii=1:length(AO) |
---|
19 | if strcmp(lower(AO{ii}.FamilyType),'bend') |
---|
20 | indx=AO{ii}.AT.ATIndex; |
---|
21 | |
---|
22 | %assign random alignment error to first magnet |
---|
23 | mx=[mx; sx*randn]; |
---|
24 | my=[my; sy*randn]; |
---|
25 | |
---|
26 | % assign random error to rest of family |
---|
27 | tol=1e-6; %tolerance for spacing between magnets |
---|
28 | for jj=2:length(indx) |
---|
29 | |
---|
30 | %check for split magnets |
---|
31 | if AO{ii}.Position(jj)-THERING{indx(jj)}.Length - AO{ii}.Position(jj-1)<tol %magnet split |
---|
32 | disp([' Split magnet ' AO{ii}.FamilyName ' found in function bendalign with index ', num2str(indx(jj))]); |
---|
33 | mx=[mx; -mx(end)]; |
---|
34 | my=[my; -my(end)]; |
---|
35 | else %magnet not split |
---|
36 | mx=[mx; sx*randn]; |
---|
37 | my=[my; sy*randn]; |
---|
38 | end |
---|
39 | |
---|
40 | end |
---|
41 | |
---|
42 | %check if first/last element split in THERING |
---|
43 | if abs(AO{ii}.Position(1)) < tol & ... %first element near zero |
---|
44 | abs((len - AO{ii}.Position(end) - THERING{indx(end)}.Length < tol)) %last element near end |
---|
45 | disp([' Split magnet ' AO{ii}.FamilyName ' found in function bendalign with index ',... |
---|
46 | num2str(indx(1)), ' ',num2str(indx(end))]); |
---|
47 | mx(end)=-mx(end-length(indx)+1); %error on last quad same as error on first quad in family |
---|
48 | my(end)=-my(end-length(indx)+1); |
---|
49 | end |
---|
50 | |
---|
51 | ATindx=[ATindx; indx]; |
---|
52 | end %end quad condition |
---|
53 | end %end loop over families |
---|
54 | |
---|
55 | %set polynomials to mimic dipole misalignment errors |
---|
56 | for ii=1:length(ATindx) |
---|
57 | |
---|
58 | rho=THERING{ATindx(ii)}.Length/THERING{ATindx(ii)}.BendingAngle; |
---|
59 | dB=THERING{ATindx(ii)}.PolynomB(2)*mx(ii)*rho; %dB = (gradB/B*rho)*dx*rho |
---|
60 | THERING{ATindx(ii)}.PolynomB(1)=THERING{ATindx(ii)}.PolynomB(1)+dB; %horizontal |
---|
61 | |
---|
62 | THERING{ATindx(ii)}.PolynomA(1)=THERING{ATindx(ii)}.PolynomA(1)+dB; %vertical |
---|
63 | end |
---|