0001 function varargout=atx(ring,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 [energy,periods,voltage,~,eloss]=atenergy(ring);
0073 [varargout{1:nargout}]=atx2(ring(:,1),energy,periods,voltage,eloss,varargin{:});
0074 if nargout >= 1 && size(ring,2) > 1
0075 varargout{1}=repmat(varargout{1}(:),1,size(ring,2));
0076 end
0077
0078 function [linusr,pm]=atx2(ring,energy,periods,voltage,eloss,varargin)
0079
0080 c=2.9987924e8;
0081 [dpp,refusr]=parseargs({0,1:length(ring)},varargin);
0082 if islogical(refusr)
0083 refusr(end+1,length(ring)+1)=false;
0084 else
0085 refusr=setelems(false(1,length(ring)+1),refusr);
0086 end
0087 refpts=setelems(refusr,[1 length(ring)+1]);
0088 keep=refusr(refpts);
0089
0090 [lindata,tunes,xsi]=atlinopt(ring,dpp,refpts);
0091 coupled=max(abs(1-cat(1,lindata.gamma))) > 1.e-3;
0092
0093 ts=periods*tunes;
0094 fractunes=ts-fix(ts);
0095
0096 circumference=periods*lindata(end).SPos;
0097 revperiod=lindata(end).SPos/c;
0098
0099 transfer=lindata(end).M44;
0100
0101 [beamA,beamB]=beam44(lindata(1));
0102
0103 closedorbit=lindata(1).ClosedOrbit';
0104
0105 dispersion=lindata(1).Dispersion';
0106
0107 tuneper=lindata(end).mu/2/pi;
0108 tunes=periods*tuneper;
0109
0110 momcompact=mcf(ring);
0111
0112 chromaticity=[periods*xsi;xsi./tuneper];
0113
0114 synchrophase=asin(eloss/voltage);
0115
0116 if nargout == 0
0117 display(coupled);
0118 display(fractunes);
0119 display(circumference);
0120 display(transfer);
0121 display(beamA);
0122 display(beamB);
0123 display(closedorbit);
0124 display(dispersion);
0125 display(tuneper);
0126 display(tunes);
0127 display(momcompact);
0128 display(chromaticity);
0129 display(eloss);
0130 display(synchrophase);
0131 end
0132
0133 if length(varargin)<3
0134 [ring2,radindex,cavindex]=atradon(ring);
0135 elseif isa(varargin{3},'function_handle')
0136 [ring2,radindex,cavindex]=varargin{3}(ring);
0137 else
0138 [ring2,radindex,cavindex]=deal(varargin{3:5});
0139 end
0140
0141 if any(cavindex)
0142 try
0143 [envelope,espread,blength,m,T]=ohmienvelope(ring2,radindex,refpts);
0144 [chi,tns]=atdampingrates(m);
0145 fs=abs(tns(3))/revperiod;
0146 dampingtime=revperiod./chi;
0147 if any(radindex)
0148 jmt=jmat(3);
0149 lindata=cellfun(@process,{envelope.R},reshape(num2cell(T,[1 2]),1,[]),num2cell(lindata));
0150 else
0151 lindata=arrayfun(@deflt,lindata);
0152 end
0153 catch err
0154 warning('atx:unstable','Emittance computation failed:\n%s\n',...
0155 err.message);
0156 blength=NaN;
0157 espread=NaN;
0158 fs=NaN;
0159 dampingtime=NaN(1,3);
0160 lindata=arrayfun(@deflt,lindata);
0161 end
0162 else
0163 blength=NaN;
0164 espread=NaN;
0165 fs=NaN;
0166 dampingtime=NaN(1,3);
0167 lindata=arrayfun(@deflt,lindata);
0168 end
0169 modemit=cat(1,lindata.modemit);
0170 modemittance=mean(modemit);
0171 modcoupling=mean(modemit(:,2)./modemit(:,1));
0172 projemit=cat(1,lindata.emit44);
0173 projemittance=projemit(1,:);
0174 projcoupling=mean(projemit(:,2)./projemit(:,1));
0175 if nargout==0
0176 display(energy);
0177 display(modemittance);
0178 display(modcoupling);
0179 display(projemittance);
0180 display(projcoupling);
0181 display(dampingtime);
0182 display(fs);
0183 display(espread);
0184 display(blength);
0185 end
0186 if nargout>=1
0187 linusr=lindata(keep);
0188 end
0189 if nargout>=2
0190 pm=struct('ll',circumference,'alpha',momcompact,...
0191 'fractunes',fractunes,...
0192 'fulltunes',tunes,...
0193 'nuh',tunes(1),'nuv',tunes(2),...
0194 'chromaticity',chromaticity(1,:),...
0195 'dampingtime',dampingtime,...
0196 'espread',espread,...
0197 'blength',blength,...
0198 'modemittance',modemittance,...
0199 'energy',energy,...
0200 'fs',fs,...
0201 'eloss',eloss,...
0202 'synchrophase',synchrophase,...
0203 'momcompact',momcompact);
0204 end
0205
0206 function lind=process(bm66,T,lind)
0207 if coupled
0208 siginv=inv(bm66);
0209 bm44=inv(siginv(1:4,1:4));
0210 else
0211 siginv=inv(bm66([1 2 5 6],[1 2 5 6]));
0212 bm44=[inv(siginv(1:2,1:2)) zeros(2,2);zeros(2,4)];
0213 end
0214
0215
0216
0217
0218
0219
0220 aa=amat(T*m*jmt'*T'*jmt);
0221 nn=-aa'*jmt*bm66*jmt*aa;
0222 lind.modemit=0.5*[nn(1,1)+nn(2,2) nn(3,3)+nn(4,4) nn(5,5)+nn(6,6)];
0223 lind.beam66=bm66;
0224 lind.beam44=bm44;
0225
0226 lind.emit44=sqrt([det(bm44(1:2,1:2)) det(bm44(3:4,3:4))]);
0227
0228 lind.emit66=sqrt([det(bm66(1:2,1:2)) det(bm66(3:4,3:4)) det(bm66(5:6,5:6))]);
0229 end
0230
0231 function lind=deflt(lind)
0232 lind.modemit=NaN(1,3);
0233 lind.emit44=NaN(1,2);
0234 end
0235
0236 function [chi,nu]=atdampingrates(m66)
0237
0238 aa=amat(m66);
0239
0240 Rmat=aa\m66*aa;
0241
0242 [chi,nu]=cellfun(@decode,num2cell(reshape(1:size(m66,1),2,[]),1));
0243
0244 function [chi,nu]=decode(range)
0245 matr=Rmat(range,range);
0246 nu=atan2(matr(1,2)-matr(2,1),matr(1,1)+matr(2,2))/2/pi;
0247 chi=-log(sqrt(det(matr)));
0248 end
0249 end
0250
0251 function mask=setelems(mask,idx)
0252 mask(idx)=true;
0253 end
0254 end
0255 end
0256
0257