0001 function rp = ringpara(THERING,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if nargin==0
0020 global THERING;
0021 end
0022 Cq = 3.8319E-13;
0023 a = findcells(THERING,'Energy');
0024 if isempty(a)
0025 gamma = 3000/PhysConstant.electron_mass_energy_equivalent_in_MeV.value;
0026 else
0027 gamma = THERING{a(1)}.Energy/(PhysConstant.electron_mass_energy_equivalent_in_MeV.value*1e6);
0028 end
0029
0030 dpindex = findcells(THERING,'BendingAngle');
0031 [tw,tune,chrom] = twissring(THERING,0,dpindex,'chrom',0.00001);
0032 beta = cat(1, tw.beta);
0033 alpha = cat(1, tw.alpha);
0034 mu = cat(1, tw.mu);
0035 disper = cat(1, tw.Dispersion);
0036 Dx = disper(1:4:end);
0037 Dxp = disper(2:4:end);
0038 Dy = disper(3:4:end);
0039 Dyp = disper(4:4:end);
0040
0041 [tmptw,tune,chrom] = twissring(THERING,0,1:length(THERING),'chrom',0.00001);
0042
0043 lendp = getcellstruct(THERING,'Length',dpindex);
0044 lendp(lendp==0)=1;
0045 theta = getcellstruct(THERING,'BendingAngle',dpindex);
0046 rho = lendp./theta;
0047
0048 I1 = 0;
0049 I2 = 0;
0050 I3 = 0;
0051 I4 = 0;
0052 I5 = 0;
0053 len = length(dpindex);
0054 curHavg1 = 1:len;
0055 for ii=1:len
0056 if theta(ii) ~= 0.0
0057 K = 0;
0058 Kk = 0;
0059 Kp = 0;
0060 if isfield(THERING{dpindex(ii)},'K')
0061 Kk = THERING{dpindex(ii)}.K;
0062 end
0063 if isfield(THERING{dpindex(ii)},'PolynomB')
0064 Kp = THERING{dpindex(ii)}.PolynomB(2);
0065 end
0066 if Kk~=Kp && (Kk~=0 && Kp~=0)
0067 warning('Values in K and PolynomB(2) are different. Using larger absolute value');
0068 end
0069 Ks=[Kk,Kp];
0070 [~,i]=max(abs(Ks));
0071 K=Ks(i);
0072
0073 th1 = THERING{dpindex(ii)}.EntranceAngle;
0074 th2 = THERING{dpindex(ii)}.ExitAngle;
0075 [dI1,dI2,dI3,dI4,dI5,curHavg1(ii)] = calcRadInt(rho(ii),theta(ii), ...
0076 alpha(ii,1),beta(ii,1),Dx(ii),Dxp(ii),K,th1,th2);
0077 I1 = I1 + dI1;
0078 I2 = I2 + dI2;
0079 I3 = I3 + dI3;
0080 I4 = I4 + dI4;
0081 I5 = I5 + dI5;
0082 end
0083 end
0084
0085
0086
0087 R = findspos(THERING, length(THERING)+1)/2/pi;
0088 alphac = I1/2/pi/R;
0089 U0 = 14.085*(gamma*PhysConstant.electron_mass_energy_equivalent_in_MeV.value/1000)^4*I2*1000.;
0090 if nargin>=2
0091 fprintf('dipole radiation loss: %4.5f keV\n', U0/1000.);
0092 U0 = varargin{1}*1e6;
0093 end
0094 sigma_E = gamma*sqrt(Cq*I3/(2*I2+I4));
0095 Jx = 1-I4/I2;
0096 Jy = 1.00;
0097 Je = 2+I4/I2;
0098 emittx = Cq*gamma^2*I5/(I2-I4);
0099
0100
0101 spos=findspos(THERING,1:length(THERING)+1);
0102 [tmptw,tune,chrom] = twissring(THERING,0,1:length(THERING),'chrom');
0103 betaall = cat(1, tmptw.beta);
0104 meanbetayovers=sum(betaall(:,2)'.*diff(spos))/spos(end);
0105 meaninvr2=mean((1./rho.^2));
0106 meaninvr3=mean((1./abs(rho.^3)));
0107 emitty_lim = Cq*meanbetayovers/2/Jy*meaninvr3/meaninvr2;
0108
0109
0110 cspeed = PhysConstant.speed_of_light_in_vacuum.value;
0111 T0 = 2*pi*R/cspeed;
0112 alpha0 = U0/1.0e6/2/T0/(gamma*PhysConstant.electron_mass_energy_equivalent_in_MeV.value);
0113 alphax = Jx*alpha0;
0114 alphay = Jy*alpha0;
0115 alphaE = Je*alpha0;
0116
0117 rp.E0 = gamma*PhysConstant.electron_mass_energy_equivalent_in_MeV.value*1E6;
0118 rp.R = R;
0119 rp.alphac = alphac;
0120 rp.U0 = U0;
0121 rp.sigma_E = sigma_E;
0122 rp.emittx = emittx;
0123 rp.emitty_lim= emitty_lim;
0124 rp.T0 = T0;
0125 rp.integrals = [I1,I2,I3,I4,I5];
0126 rp.dampingalpha = [alphax, alphay, alphaE];
0127 rp.dampingtime = 1./[alphax, alphay, alphaE];
0128
0129
0130
0131
0132 try
0133 [nu,chi]=atTunesAndDampingRatesFromMat(findm66((THERING)));
0134 catch exc
0135 warning('failed coupled damping times computation');
0136 nu=[NaN,NaN,NaN];
0137 chi=[NaN,NaN,NaN];
0138 end
0139
0140 rp.coupleddampingtime=T0./chi;
0141
0142 rp.dampingJ = [Jx,Jy,Je];
0143
0144
0145
0146 rp.tunes = tune;
0147 rp.chroms = chrom;
0148 rp.etac = 1/gamma^2-alphac;
0149
0150 cavind = findcells(THERING,'HarmNumber');
0151 if ~isempty(cavind)
0152 freq_rf = THERING{cavind(1)}.Frequency;
0153 harm = THERING{cavind(1)}.HarmNumber;
0154 Vrf = 0;
0155 for ii=1:length(cavind)
0156 Vrf = Vrf+THERING{cavind(ii)}.Voltage;
0157 end
0158 else
0159
0160 fprintf('warning: SPEAR3 rf parameters are assume\n');
0161 freq_rf = 476.314e6;
0162 harm = 372;
0163 Vrf = 3.2e6;
0164 end
0165
0166 phi_s = pi-asin(rp.U0/Vrf);
0167 nus = sqrt(harm*Vrf*abs(rp.etac*cos(phi_s))/2/pi/rp.E0);
0168 rp.nus = nus;
0169 rp.phi_s = phi_s;
0170 rp.harm = harm;
0171 rp.bunchlength = rp.sigma_E*rp.harm*abs(rp.etac)/rp.nus/2/pi/freq_rf*cspeed;
0172 delta_max = sqrt(2*U0/pi/alphac/harm/rp.E0)*sqrt( sqrt((Vrf/U0).^2-1) - acos(U0./Vrf));
0173 rp.delta_max = delta_max;
0174
0175
0176
0177 curVavg1 = 1./beta(:,2).*(Dy.^2 + (beta(:,2).*Dyp + alpha(:,2).*Dy).^2);
0178 curVavg = sum(curVavg1.*lendp./abs(rho))/sum(lendp);
0179 emitty_d = Cq*gamma^2*curVavg/Jy;
0180
0181
0182
0183
0184
0185
0186
0187 rp.emitty_d = emitty_d;
0188
0189
0190 if nargout == 0
0191 fprintf('\n');
0192 fprintf(' ******** AT Ring Parmater Summary ********\n');
0193 fprintf(' Energy: \t\t\t%4.5f [GeV]\n', rp.E0/1E9);
0194 fprintf(' Circumference: \t\t%4.5f [m]\n', rp.R*2*pi);
0195 fprintf(' Revolution time: \t\t%4.5f [ns] (%4.5f [MHz]) \n', rp.T0*1e9,1./rp.T0*1e-6);
0196 fprintf(' Betatron tune H: \t\t%4.5f (%4.5f [kHz])\n', rp.tunes(1),(rp.tunes(1)-floor(rp.tunes(1)))/rp.T0*1e-3);
0197 fprintf(' V: \t\t%4.5f (%4.5f [kHz])\n', rp.tunes(2),(rp.tunes(2)-floor(rp.tunes(2)))/rp.T0*1e-3);
0198 fprintf(' Momentum Compaction Factor: \t%4.5f\n', rp.alphac);
0199 fprintf(' Chromaticity H: \t\t%+4.5f\n', rp.chroms(1));
0200 fprintf(' V: \t\t%+4.5f\n', rp.chroms(2));
0201 fprintf(' Synchrotron Integral 1: \t%4.5f [m]\n', rp.integrals(1));
0202 fprintf(' 2: \t%4.5f [m^-1]\n', rp.integrals(2));
0203 fprintf(' 3: \t%4.5f [m^-2]\n', rp.integrals(3));
0204 fprintf(' 4: \t%4.5f [m^-1]\n', rp.integrals(4));
0205 fprintf(' 5: \t%4.5f [m^-1]\n', rp.integrals(5));
0206 fprintf(' Damping Partition H: \t%4.5f\n', rp.dampingJ(1));
0207 fprintf(' V: \t%4.5f\n', rp.dampingJ(2));
0208 fprintf(' E: \t%4.5f\n', rp.dampingJ(3));
0209 fprintf(' Radiation Loss: \t\t%4.5f [keV]\n', rp.U0/1000.);
0210 fprintf(' Natural Energy Spread: \t%4.5e\n', rp.sigma_E);
0211 fprintf(' Natural Emittance: \t\t%4.5e [nm]\n', rp.emittx*1e9);
0212 fprintf(' Radiation Damping H: \t%4.5f [ms]\n', rp.dampingtime(1)*1e3);
0213 fprintf(' V: \t%4.5f [ms]\n', rp.dampingtime(2)*1e3);
0214 fprintf(' E: \t%4.5f [ms]\n', rp.dampingtime(3)*1e3);
0215 fprintf(' Slip factor : \t%4.5f\n', rp.etac);
0216 fprintf('\n');
0217 fprintf(' Assuming cavities Voltage: %4.5f [kV]\n', Vrf/1e3);
0218 fprintf(' Frequency: %4.5f [MHz]\n', freq_rf/1e6);
0219 fprintf(' Harmonic Number: %5d\n', rp.harm);
0220 fprintf(' Synchronous Phase: %4.5f [rad] (%4.5f [deg])\n', rp.phi_s, rp.phi_s*180/pi);
0221 fprintf(' Linear Energy Acceptance: %4.5f %%\n', rp.delta_max*100);
0222 fprintf(' Synchrotron Tune: %4.5f (%4.5f kHz or %4.2f turns) \n', rp.nus, rp.nus/rp.T0*1e-3, 1/rp.nus);
0223 fprintf(' Bunch Length: %4.5f [mm], %4.5f [ps]\n', rp.bunchlength*1e3, rp.bunchlength/cspeed*1e12);
0224 fprintf('\n');
0225
0226
0227 fprintf(' Emitty from Dy: %4.5f [nm]\n', rp.emitty_d*1e9);
0228 fprintf(' Emitty 1/gamma cone limit: %4.5f [pm]\n', rp.emitty_lim*1e12);
0229 end
0230
0231
0232 function [dI1,dI2,dI3,dI4,dI5,curHavg] = calcRadInt(rho,theta, a0,b0,D0,D0p,K1,th1,th2)
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244 if nargin==6
0245 K1=0;
0246 end
0247 if nargin<9
0248 th1 = 0;
0249 th2 = 0;
0250 end
0251
0252 M21 = tan(th1)/rho;
0253 D0p = M21*D0+D0p;
0254 a0 = -M21*b0+a0;
0255
0256 N = 100;
0257 th = (0:N)/N*theta;
0258 len = length(th);
0259 Dx = zeros(len,1); Dxp = zeros(len,1); curHavg1 = zeros(len,1);
0260 for ii=1:len
0261 [Dx(ii), Dxp(ii)] = calcdisp(rho, th(ii), D0, D0p, K1);
0262 [ax, bx] = calctwiss(rho, th(ii), a0, b0, K1);
0263 curHavg1(ii) = (Dx(ii)^2+(ax*Dx(ii)+bx*Dxp(ii))^2)/bx;
0264 end
0265 curHavg = ((curHavg1(1)+curHavg1(end))/2.0 + sum(curHavg1(2:end-1)))/(length(th)-1);
0266
0267 dI1 = ((Dx(1) + Dx(end))/2.0 + sum(Dx(2:end-1)))*theta/N;
0268 dI2 = abs(theta/rho);
0269 dI3 = abs(theta/rho^2);
0270 dI4 = (1/rho^2 + 2*K1)*dI1 - (Dx(1)/rho^2*tan(th1) + Dx(end)/rho^2*tan(th2));
0271 dI5 = curHavg*abs(theta/rho^2);
0272
0273 function [Dx, Dxp] = calcdisp(rho, theta, D0, D0p, K1)
0274
0275 s = rho*theta;
0276 if K1>-1/rho^2
0277 sqK = sqrt(1/rho^2+K1);
0278 Dx = D0*cos(sqK*s) + D0p/sqK*sin(sqK*s)+(1-cos(sqK*s))/rho/sqK^2;
0279 Dxp = -D0*sqK*sin(sqK*s)+D0p*cos(sqK*s)+sin(sqK*s)/rho/sqK;
0280 else
0281 sqK = sqrt(-(1/rho^2+K1));
0282 Dx = D0*cosh(sqK*s) + D0p/sqK*sinh(sqK*s)+(-1+cosh(sqK*s))/rho/sqK^2;
0283 Dxp = D0*sqK*sinh(sqK*s)+D0p*cosh(sqK*s)+sinh(sqK*s)/rho/sqK;
0284
0285 end
0286
0287 function [ax, bx] = calctwiss(rho, theta, a0, b0, K1)
0288
0289 Mx = calcMx(rho, K1,theta);
0290 g0 = (1+a0^2)/b0;
0291 twx2 = [Mx(1,1)^2, -2*Mx(1,1)*Mx(1,2), Mx(1,2)^2;
0292 -Mx(1,1)*Mx(2,1), Mx(1,1)*Mx(2,2)+Mx(1,2)*Mx(2,1),-Mx(1,2)*Mx(2,2);
0293 Mx(2,1)^2, -2*Mx(2,1)*Mx(2,2),Mx(2,2)^2] * [b0, a0, g0]';
0294 ax = twx2(2);
0295 bx = twx2(1);
0296
0297 function Mx = calcMx(rho,K1,theta)
0298 s = rho*theta;
0299 if K1>-1/rho^2
0300 sqK = sqrt(1/rho^2+K1);
0301 Mx = [cos(sqK*s), sin(sqK*s)/sqK; -sqK*sin(sqK*s), cos(sqK*s)];
0302 else
0303 sqK = sqrt(-(1/rho^2+K1));
0304 Mx = [cosh(sqK*s), sinh(sqK*s)/sqK; sqK*sinh(sqK*s), cosh(sqK*s)];
0305 end
0306