0001 function [rcor,inCOD,qs,ss]=atRDTdispersionmeasuredcorrection(...
0002 rerr,...
0003 rfit,...
0004 r0,...
0005 indBPM,...
0006 indQCor,...
0007 indSCor,...
0008 inCOD,...
0009 neigSteerer,...
0010 correctflags,...
0011 scalefactor,...
0012 wdisp,...
0013 ModelRM,...
0014 steererlimit,...
0015 printouttext)
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 delta=1e-3;
0068
0069
0070 if nargin<14
0071 printouttext=true;
0072 end
0073 if nargin<13
0074 steererlimit=[];
0075 end
0076
0077 if nargin<6
0078 if printouttext
0079 disp('get BPM and Correctors indexes'); end;
0080 indBPM=finc(atgetcells(rfit,'Class','Monitor'));
0081 indQCor=finc(atgetcells(rfit,'Class','Quadrupole'));
0082 indSCor=finc(atgetcells(rfit,'Class','Sextupole'));
0083 end
0084
0085 if nargin<7
0086 inCOD=[0 0 0 0 0 0]';
0087 end
0088
0089 if nargin<8
0090 neigSteerer=[length(indQCor) length(indSCor)]/2;
0091 end
0092
0093 if nargin<9
0094 correctflags=true;
0095 end
0096
0097 if nargin<10
0098 if printouttext
0099 disp(' --- scale set to 1.0'); end;
0100 scalefactor=1.0;
0101 end
0102
0103 if nargin<11
0104 if printouttext, disp(' --- wdisph=0.7 wtune=0.1 wdispv=0.7'); end;
0105 wdisp=[.7 .1 .7];
0106 end
0107
0108 if nargin<12
0109 if printouttext, disp(' --- computing orbit Response matrix'); end;
0110 ModelRM=[];
0111 end
0112
0113
0114 if scalefactor<0 || scalefactor>1
0115 if printouttext
0116 disp(' --- scale factor out of range. Set to 1.0'); end;
0117 scalefactor=1.0;
0118 end
0119
0120
0121
0122 if isempty(ModelRM)
0123
0124 if printouttext
0125 disp('get RM'); end;
0126
0127
0128 ModelRM=getresponsematrices(...
0129 rfit,...
0130 indBPM,...
0131 [],...
0132 [],...
0133 indSCor,...
0134 indQCor,...
0135 [],...
0136 inCOD,...
0137 [10 11 12]...
0138 );
0139
0140
0141 end
0142
0143
0144
0145 drmQ=ModelRM.DispQCor;
0146 drmS=ModelRM.DispSCor;
0147
0148
0149 tuneQ=[ModelRM.TuneQCor{1};ModelRM.TuneQCor{2}];
0150
0151
0152 [~,~,ind]=EquivalentGradientsFromAlignments6D(rfit,inCOD);
0153 indAllQuad=ind;
0154 indAllSkew=ind;
0155
0156
0157
0158
0159 [respqx,respqz]=qemrdtresp_mod(rfit,indBPM,indAllQuad);
0160 QL=atgetfieldvalues(rfit,indAllQuad,'Length');
0161 QL(QL==0)=1;
0162
0163
0164
0165
0166 lengthsmat=repmat(QL',length(indBPM),1);
0167 respqx=respqx.*lengthsmat;
0168 respqz=respqz.*lengthsmat;
0169
0170 [~,qkcor]=ismember(indQCor,indAllQuad);
0171 rdtQ=[...
0172 real(respqx(:,qkcor));...
0173 imag(respqx(:,qkcor));...
0174 real(respqz(:,qkcor));...
0175 imag(respqz(:,qkcor))];
0176
0177
0178
0179 [respsx,respsz]=semrdtresp_mod(rfit,indBPM,indAllSkew);
0180 SL=atgetfieldvalues(rfit,indAllSkew,'Length');
0181 SL(SL==0)=1;
0182 lengthsmat=repmat(SL',length(indBPM),1);
0183 respsx=respsx.*lengthsmat;
0184 respsz=respsz.*lengthsmat;
0185
0186 [~,skcor]=ismember(indSCor,indAllSkew);
0187 rdtS=[...
0188 real(respsx(:,skcor));...
0189 imag(respsx(:,skcor));...
0190 real(respsz(:,skcor));...
0191 imag(respsz(:,skcor))];
0192
0193
0194 inCOD=[0 0 0 0 0 0]';
0195 [l,t,~]=atlinopt(r0,0,indBPM);
0196 refdispersion=zeros(2,length(indBPM));
0197 refdispersion(1,:)=arrayfun(@(a)a.Dispersion(1),l);
0198 refdispersion(2,:)=arrayfun(@(a)a.Dispersion(3),l);
0199 reftune=t;
0200
0201 [KQnoer,KSnoer,~]=EquivalentGradientsFromAlignments6D(r0,inCOD);
0202
0203
0204
0205 fx=respqx*KQnoer;
0206 fz=respqz*KQnoer;
0207 rdtvecq=[...
0208 real(fx);...
0209 imag(fx);...
0210 real(fz);...
0211 imag(fz)]';
0212
0213 fx=respsx*KSnoer;
0214 fz=respsz*KSnoer;
0215 rdtvecs=[...
0216 real(fx);...
0217 imag(fx);...
0218 real(fz);...
0219 imag(fz)]';
0220
0221 refrdt(1,:)=rdtvecq;
0222 refrdt(2,:)=rdtvecs;
0223
0224
0225
0226
0227 [KQi,KSi,~]=EquivalentGradientsFromAlignments6D(rfit,inCOD);
0228
0229
0230
0231 fx=respqx*KQi;
0232 fz=respqz*KQi;
0233 rq0=[...
0234 real(fx);...
0235 imag(fx);...
0236 real(fz);...
0237 imag(fz)]';
0238
0239 fx=respsx*KSi;
0240 fz=respsz*KSi;
0241 rs0=[...
0242 real(fx);...
0243 imag(fx);...
0244 real(fz);...
0245 imag(fz)]';
0246
0247
0248 alpha=mcf(rfit);
0249 indrfc=find(atgetcells(rfit,'Frequency'));
0250
0251
0252
0253 d=finddispersion6Err(rerr,indBPM,indrfc,alpha,delta,inCOD);
0254 dx0=d(1,:);
0255 dy0=d(3,:);
0256
0257
0258 [~,t0,~]=atlinopt(rerr,0,1);
0259
0260
0261 qs0=atgetfieldvalues(rfit,indQCor,'PolynomB',{1,2});
0262 ss0=atgetfieldvalues(rfit,indSCor,'PolynomA',{1,2});
0263 qse0=atgetfieldvalues(rerr,indQCor,'PolynomB',{1,2});
0264 sse0=atgetfieldvalues(rerr,indSCor,'PolynomA',{1,2});
0265
0266
0267 Niter=size(neigSteerer,1);
0268 for iter=1:Niter
0269
0270 if printouttext
0271 disp(['RDT Disp. Tune Steering iter ' num2str(iter,'%d, ') ...
0272 ' n-eig: ' num2str(neigSteerer(iter,:),'%d, ') ...
0273 ' alpha: ' num2str(wdisp,'%2.2f ')]);
0274 end
0275
0276
0277 corq0=atgetfieldvalues(rfit,indQCor,'PolynomB',{1,2});
0278 cors0=atgetfieldvalues(rfit,indSCor,'PolynomA',{1,2});
0279 corqe0=atgetfieldvalues(rerr,indQCor,'PolynomB',{1,2});
0280 corse0=atgetfieldvalues(rerr,indSCor,'PolynomA',{1,2});
0281
0282
0283
0284 [KQe,KSe,~]=EquivalentGradientsFromAlignments6D(rfit,inCOD);
0285
0286
0287
0288 fx=respqx*KQe;
0289 fz=respqz*KQe;
0290 rq=[...
0291 real(fx);...
0292 imag(fx);...
0293 real(fz);...
0294 imag(fz)]';
0295
0296 fx=respsx*KSe;
0297 fz=respsz*KSe;
0298 rs=[...
0299 real(fx);...
0300 imag(fx);...
0301 real(fz);...
0302 imag(fz)]';
0303
0304
0305 d=finddispersion6Err(rerr,indBPM,indrfc,alpha,delta,inCOD);
0306 dx=d(1,:);
0307 dy=d(3,:);
0308
0309 [~,t,~]=atlinopt(rerr,0,1);
0310
0311
0312
0313 rq=rq-refrdt(1,:);
0314 rs=rs-refrdt(2,:);
0315
0316 dx=dx-refdispersion(1,:);
0317 dy=dy-refdispersion(2,:);
0318
0319 t=t-reftune;
0320
0321
0322 rq=rq*(1-wdisp(1)-wdisp(2));
0323 rs=rs*(1-wdisp(3));
0324 dx=dx*(wdisp(1));
0325 dy=dy*(wdisp(3));
0326 t=t*(wdisp(2));
0327
0328
0329 if correctflags(1)
0330 RMQ=[rdtQ*(1-wdisp(1)-wdisp(2));drmQ{1}*(wdisp(1));tuneQ*(wdisp(2));ones(size(indQCor))];
0331
0332 RMS=[rdtS*(1-wdisp(3));drmS{3}*(wdisp(3));ones(size(indSCor))];
0333 elseif ~correctflags(1)
0334 RMQ=[rdtQ*(1-wdisp(1)-wdisp(2));drmQ{1}*(wdisp(1));tuneQ*(wdisp(2))];
0335
0336 RMS=[rdtS*(1-wdisp(3));drmS{3}*(wdisp(3))];
0337 end
0338
0339
0340 if correctflags(1)
0341 vecq=[rq dx t 0]';
0342
0343 vecs=[rs dy 0]';
0344 else
0345 vecq=[rq dx t]';
0346
0347 vecs=[rs dy]';
0348 end
0349
0350 dcq=qemsvd_mod(RMQ,vecq,neigSteerer(iter,1));
0351 dcs=qemsvd_mod(RMS,vecs,neigSteerer(iter,2));
0352
0353
0354
0355 qs=corq0-dcq*scalefactor;
0356 ss=cors0-dcs*scalefactor;
0357 qse=corqe0-dcq*scalefactor;
0358 sse=corse0-dcs*scalefactor;
0359
0360
0361 if ~isempty(steererlimit)
0362 qs(abs(qs)>steererlimit(1))=steererlimit(1);
0363 ss(abs(ss)>steererlimit(2))=steererlimit(2);
0364 qse(abs(qse)>steererlimit(1))=steererlimit(1);
0365 sse(abs(sse)>steererlimit(2))=steererlimit(2);
0366 end
0367
0368
0369 rfit=atsetfieldvalues(rfit,indQCor,'PolynomB',{1,2},qs);
0370 rfit=atsetfieldvalues(rfit,indSCor,'PolynomA',{1,2},ss);
0371
0372 rerr=atsetfieldvalues(rerr,indQCor,'PolynomB',{1,2},qse);
0373 rerr=atsetfieldvalues(rerr,indSCor,'PolynomA',{1,2},sse);
0374
0375
0376 rcor=rfit;
0377 end
0378
0379
0380
0381 [KQ,KS,~]=EquivalentGradientsFromAlignments6D(rcor,inCOD);
0382
0383
0384
0385 fx=respqx*KQ;
0386 fz=respqz*KQ;
0387 rqc=[...
0388 real(fx);...
0389 imag(fx);...
0390 real(fz);...
0391 imag(fz)]';
0392
0393 fx=respsx*KS;
0394 fz=respsz*KS;
0395 rsc=[...
0396 real(fx);...
0397 imag(fx);...
0398 real(fz);...
0399 imag(fz)]';
0400
0401
0402 d=finddispersion6Err(rcor,indBPM,indrfc,alpha,delta,inCOD);
0403 dxc=d(1,:);
0404 dyc=d(3,:);
0405
0406 [~,tc,~]=atlinopt(rcor,0,1);
0407
0408
0409 if printouttext
0410
0411 disp([' before' ' ' '-->' ' ' 'after'])
0412 disp(['rq: ' num2str(std(rq0-refrdt(1,:))*1e3,'%3.3f') ' -> ' num2str(std(rqc-refrdt(1,:))*1e3,'%3.3f') '']);
0413 disp(['rs: ' num2str(std(rs0-refrdt(2,:))*1e3,'%3.3f') ' -> ' num2str(std(rsc-refrdt(2,:))*1e3,'%3.3f') '']);
0414 disp(['dX: ' num2str(std(dx0-refdispersion(1,:))*1e3,'%3.3f') ' -> ' num2str(std(dxc-refdispersion(1,:))*1e3,'%3.3f') 'mm'])
0415 disp(['dY: ' num2str(std(dy0-refdispersion(2,:))*1e3,'%3.3f') ' -> ' num2str(std(dyc-refdispersion(2,:))*1e3,'%3.3f') 'mm'])
0416 disp(['tX: ' num2str((t0(1)-reftune(1)),'%3.3f') ' -> ' num2str((tc(1)-reftune(1)),'%3.3f') ''])
0417 disp(['tY: ' num2str((t0(2)-reftune(2)),'%3.3f') ' -> ' num2str((tc(2)-reftune(2)),'%3.3f') ''])
0418 disp([' ' 'min' ' ' 'mean' ' ' 'max'])
0419 disp(['qs:' num2str([min(qs-qs0) mean(qs-qs0) max(qs-qs0)]*1e0,' %2.2f ') ' 1/m2'])
0420 disp(['ss:' num2str([min(ss-ss0) mean(ss-ss0) max(ss-ss0)]*1e0,' %2.2f ') ' 1/m2'])
0421 disp(['dpp: ' num2str(inCOD(5))])
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442 end
0443
0444
0445 end