0001 function [kn,ks,ind]=EquivalentGradientsFromAlignments6D(r,inCOD)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 indsext=find(atgetcells(r,'Class','Sextupole'))';
0026
0027 b3=atgetfieldvalues(r,indsext,'PolynomB',{1,3});
0028
0029 oin=findorbit6(r,indsext,inCOD);
0030 oout=findorbit6(r,indsext+1,inCOD);
0031
0032 xmisal=cellfun(@(a)getT1(a,1),r(indsext));
0033 ymisal=cellfun(@(a)getT1(a,3),r(indsext));
0034
0035 Dx=(oout(1,:)+oin(1,:))/2;
0036 Dy=(oout(3,:)+oin(3,:))/2;
0037
0038
0039 kn_sext_err=cellfun(@(a)a.PolynomB(2),r(indsext));
0040 ks_sext_err=cellfun(@(a)a.PolynomA(2),r(indsext));
0041
0042 kn_sext=-2.*b3.*(-Dx+xmisal')'+kn_sext_err;
0043 ks_sext=-2.*b3.*(-Dy+ymisal')'+ks_sext_err;
0044
0045
0046 indquad=find(atgetcells(r,'Class','Quadrupole'))';
0047
0048 kn2=atgetfieldvalues(r,indquad,'PolynomB',{1,2});
0049 ks2=atgetfieldvalues(r,indquad,'PolynomA',{1,2});
0050 srot=cellfun(@(a)getR1(a),r(indquad));
0051
0052 kn_quad=(1-srot).*kn2;
0053 ks_quad=-srot.*kn2+ks2;
0054
0055
0056 indPolB=find(atgetcells(r,'PolynomB') & ...
0057 ~atgetcells(r,'Class','Quadrupole') & ...
0058 ~atgetcells(r,'Class','Sextupole' ))';
0059
0060 NpolB=cellfun(@(a)length(a.PolynomB),r(indPolB));
0061 NpolA=cellfun(@(a)length(a.PolynomA),r(indPolB));
0062
0063 indPolB=indPolB(NpolB>=2 & NpolA>=2 & ~ismember(indPolB,[indquad indsext])');
0064
0065 kn_all=cellfun(@(a)a.PolynomB(2),r(indPolB));
0066 ks_all=cellfun(@(a)a.PolynomA(2),r(indPolB));
0067
0068 [ind,ord]=sort([indsext,indquad,indPolB]);
0069
0070 kn=[kn_sext;kn_quad;kn_all];
0071 ks=[ks_sext;ks_quad;ks_all];
0072
0073
0074
0075
0076 kn=kn(ord);
0077 ks=ks(ord);
0078
0079
0080 return
0081
0082
0083 function t1=getT1(a,ind)
0084 t1=0;
0085 if isfield(a,'T1')
0086 t1=-a.T1(ind);
0087 end
0088 return
0089
0090
0091 function r1=getR1(a)
0092 r1=0;
0093 if isfield(a,'R1')
0094 r1=asin(a.R1(1,3));
0095 end
0096 return