


ATX computes and displays global information
BEAMDATA=ATX(RING,DPP,REFPTS)
RING: AT structure
DPP: relative energy deviation (default: 0)
REFPTS: Index of elements (default: 1:length(ring))
BEAMDATA is a MATLAB structure array with fields
From atlinopt:
ElemIndex - ordinal position in the RING
SPos - longitudinal position [m]
ClosedOrbit - closed orbit column vector with
components x, px, y, py (momentums, NOT angles)
Dispersion - dispersion orbit position vector with
components eta_x, eta_prime_x, eta_y, eta_prime_y
calculated with respect to the closed orbit with
momentum deviation DP
M44 - 4x4 transfer matrix M from the beginning of RING
to the entrance of the element for specified DP [2]
A - 2x2 matrix A in [3]
B - 2x2 matrix B in [3]
C - 2x2 matrix C in [3]
gamma - gamma parameter of the transformation to eigenmodes
mu - [ mux, muy] horizontal and vertical betatron phase
beta - [betax, betay] vector
alpha - [alphax, alphay] vector
From ohmienvelope:
beam66 - 6x6 equilibrium beam matrix
emit66 - 6x6 emittance projections on x and y + energy spread
beam44 - intersection of beam66 for dpp=0
emit44 - emittances of the projections of beam44 on x and y
modemit - emittance of eigenmodes
[BEAMDATA,PARAMS]=ATX(...) Returns also a structure PM with fields
ll - Circumference
alpha - momentum compaction factor
fractunes
fulltunes
nuh - Tunes
nuv
chromaticity
dampingtime
espread - Energy spread
blength - Bunch length
energy
fs - synchrotron frequency
eloss - energy loss/turn
synchrophase- synchronous phase
modemittance- Eigen emittances
momcompact - momentum compaction factor
BEAMDATA=ATX(RING,DPP,REFPTS,RADRING,RADINDEX,CAVINDEX)
Radiation must be turned on for emittance computation. This is done by
default using the ATRADON function with default arguments. If this is not
desired, this syntax allows to explicitly enter the radiative lattice
with the indices of radiating elements and cavities
BEAMDATA=ATX(RING,DPP,REFPTS,RADFUNCTION)
RADFUNCTION is substituted to ATRADON to provide the radiative lattice
and indices, in the form:
[RADRING,RADINDEX,CAVINDEX]=RADFUNCTION(RING)
See also: ATLINOPT ATRADON OHMIENVELOPE


0001 function varargout=atx(ring,varargin) 0002 %ATX computes and displays global information 0003 % 0004 %BEAMDATA=ATX(RING,DPP,REFPTS) 0005 % 0006 %RING: AT structure 0007 %DPP: relative energy deviation (default: 0) 0008 %REFPTS: Index of elements (default: 1:length(ring)) 0009 % 0010 %BEAMDATA is a MATLAB structure array with fields 0011 % 0012 % From atlinopt: 0013 % 0014 % ElemIndex - ordinal position in the RING 0015 % SPos - longitudinal position [m] 0016 % ClosedOrbit - closed orbit column vector with 0017 % components x, px, y, py (momentums, NOT angles) 0018 % Dispersion - dispersion orbit position vector with 0019 % components eta_x, eta_prime_x, eta_y, eta_prime_y 0020 % calculated with respect to the closed orbit with 0021 % momentum deviation DP 0022 % M44 - 4x4 transfer matrix M from the beginning of RING 0023 % to the entrance of the element for specified DP [2] 0024 % A - 2x2 matrix A in [3] 0025 % B - 2x2 matrix B in [3] 0026 % C - 2x2 matrix C in [3] 0027 % gamma - gamma parameter of the transformation to eigenmodes 0028 % mu - [ mux, muy] horizontal and vertical betatron phase 0029 % beta - [betax, betay] vector 0030 % alpha - [alphax, alphay] vector 0031 % 0032 % From ohmienvelope: 0033 % 0034 % beam66 - 6x6 equilibrium beam matrix 0035 % emit66 - 6x6 emittance projections on x and y + energy spread 0036 % beam44 - intersection of beam66 for dpp=0 0037 % emit44 - emittances of the projections of beam44 on x and y 0038 % modemit - emittance of eigenmodes 0039 % 0040 %[BEAMDATA,PARAMS]=ATX(...) Returns also a structure PM with fields 0041 % ll - Circumference 0042 % alpha - momentum compaction factor 0043 % fractunes 0044 % fulltunes 0045 % nuh - Tunes 0046 % nuv 0047 % chromaticity 0048 % dampingtime 0049 % espread - Energy spread 0050 % blength - Bunch length 0051 % energy 0052 % fs - synchrotron frequency 0053 % eloss - energy loss/turn 0054 % synchrophase- synchronous phase 0055 % modemittance- Eigen emittances 0056 % momcompact - momentum compaction factor 0057 % 0058 %BEAMDATA=ATX(RING,DPP,REFPTS,RADRING,RADINDEX,CAVINDEX) 0059 % Radiation must be turned on for emittance computation. This is done by 0060 % default using the ATRADON function with default arguments. If this is not 0061 % desired, this syntax allows to explicitly enter the radiative lattice 0062 % with the indices of radiating elements and cavities 0063 % 0064 % 0065 %BEAMDATA=ATX(RING,DPP,REFPTS,RADFUNCTION) 0066 % RADFUNCTION is substituted to ATRADON to provide the radiative lattice 0067 % and indices, in the form: 0068 % [RADRING,RADINDEX,CAVINDEX]=RADFUNCTION(RING) 0069 % 0070 % See also: ATLINOPT ATRADON OHMIENVELOPE 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; %#ok<*NOPRT> 0092 0093 ts=periods*tunes; % fractional tunes 0094 fractunes=ts-fix(ts); 0095 0096 circumference=periods*lindata(end).SPos;% circumference 0097 revperiod=lindata(end).SPos/c; 0098 0099 transfer=lindata(end).M44; % transfer matrix 0100 0101 [beamA,beamB]=beam44(lindata(1)); % beam matrices 0102 0103 closedorbit=lindata(1).ClosedOrbit'; % closed orbit 0104 0105 dispersion=lindata(1).Dispersion'; % dispersion 0106 0107 tuneper=lindata(end).mu/2/pi; % tunes 0108 tunes=periods*tuneper; % tunes 0109 0110 momcompact=mcf(ring); % momentum compaction 0111 0112 chromaticity=[periods*xsi;xsi./tuneper]; % chromaticity 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 % bm44 in the intersection of beam66 0208 siginv=inv(bm66); % with dp/p==0 ( 4x4 betatron emittance) 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 % [beamA,beamB]=beam44(lindata(i)); % betatron 4x4 coupled matrices 0215 % beamA - 2x2 beam matrix for mode A 0216 % beamB - 2x2 beam matrix for mode B 0217 % Eigen emittances: Solve bm44 = modemit(1)*beamA + modemit(2)*beamB; 0218 % lindata(i).modemit=([beamA(:) beamB(:)]\bm44(:))'; 0219 % aa=amat(T(:,:,i)*m*inv(T(:,:,i))); %#ok<MINV> 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 % Projected betatron emittances 0226 lind.emit44=sqrt([det(bm44(1:2,1:2)) det(bm44(3:4,3:4))]); 0227 % Projected full emittances (energy spread included) 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 %find tunes and damping rates from one map matrix with radiation 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