0001 function [...
0002 rcor,...
0003 inCOD,...
0004 fc...
0005 ]=atRFcorrection(...
0006 rerr,...
0007 indBPM,...
0008 inCOD,...
0009 neigSteerer,...
0010 scalefactor,...
0011 ModelRM,...
0012 reforbit,...
0013 printouttext)
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 kval=1e-5;
0048 delta=1e-3;
0049
0050 alpha=mcf(rerr);
0051 indrfc=find(atgetcells(rerr,'Frequency'));
0052
0053
0054 if nargin<8
0055 printouttext=true;
0056 end
0057
0058 if nargin<2
0059 if printouttext
0060 disp('get BPM and Correctors indexes'); end;
0061 indBPM=finc(atgetcells(rerr,'Class','Monitor'));
0062 end
0063
0064 if nargin<3
0065 inCOD=[0 0 0 0 0 0]';
0066 end
0067
0068 if nargin<4
0069 neigSteerer=1;
0070 end
0071
0072
0073 if nargin<5
0074 if printouttext
0075 disp(' --- scale set to 1.0'); end;
0076 scalefactor=1.0;
0077 end
0078
0079 if nargin<6
0080 if printouttext, disp(' --- computing orbit Response matrix'); end;
0081 ModelRM=[];
0082 end
0083
0084 if nargin<7
0085 if printouttext, disp(' --- reference orbit = 0'); end;
0086 reforbit=zeros(2,length(indBPM));
0087 end
0088
0089 if scalefactor<0 || scalefactor>1
0090 if printouttext
0091 disp(' --- scale factor out of range. Set to 1.0'); end;
0092 scalefactor=1.0;
0093 end
0094
0095
0096 if isempty(ModelRM)
0097
0098 if printouttext
0099 disp('get orbit RM'); end;
0100
0101 ModelRM=getresponsematrices(...
0102 rerr,...
0103 indBPM,...
0104 [],...
0105 [],...
0106 [],...
0107 [],...
0108 [],...
0109 inCOD,...
0110 [3]...
0111 );
0112
0113 end
0114
0115
0116 dppH=ModelRM.OrbHDPP;
0117 dppV=ModelRM.OrbVDPP;
0118
0119
0120
0121 f0=rerr{indrfc(1)}.Frequency;
0122 tlag0=atgetfieldvalues(rerr,indrfc,'TimeLag');
0123
0124
0125 o=findorbit6Err(rerr,indBPM,inCOD);
0126 ox0=o(1,:);
0127 oy0=o(3,:);
0128
0129
0130
0131
0132 Niter=size(neigSteerer,1);
0133 for iter=1:Niter
0134
0135 if printouttext
0136 disp(['RF correction iter ' num2str(iter,'%d, ') 'n-eig: ' num2str(neigSteerer(iter,:),'%d, ')]);
0137 end
0138
0139
0140 f=rerr{indrfc(1)}.Frequency;
0141 tlag=atgetfieldvalues(rerr,indrfc,'TimeLag');
0142
0143
0144 o=findorbit6Err(rerr,indBPM,inCOD);
0145 ox=o(1,:);
0146
0147
0148 ox=ox-reforbit(1,:);
0149
0150
0151
0152 RMH=dppH';
0153
0154
0155 dd=qemsvd_mod(RMH,ox',neigSteerer(iter,1));
0156
0157
0158
0159 rcor=atsetfieldvalues(rerr,indrfc,'Frequency',f-alpha*(-dd)*f);
0160
0161
0162 orb = findorbit6(rcor,indrfc,inCOD);
0163 rcor=atsetfieldvalues(rcor,indrfc,'TimeLag',tlag-orb(6,:)');
0164
0165 if printouttext
0166 disp(['Delta RF : ' num2str(-alpha*(dd)*f) ' Hz']);
0167 disp(['Delta TimeLag : ' num2str(-orb(6,:)*1e6) ' um']);
0168 end
0169
0170
0171 rerr=rcor;
0172 end
0173
0174
0175 o=findorbit6Err(rcor,indBPM,inCOD);
0176 oxc=o(1,:);
0177
0178
0179 fc=rcor{indrfc(1)}.Frequency;
0180 tlagc=atgetfieldvalues(rcor,indrfc,'TimeLag');
0181
0182 inCOD=findorbit6Err(rcor,1,inCOD);
0183
0184 if printouttext
0185
0186 disp([' before' ' ' '-->' ' ' 'after'])
0187 disp(['oX: ' num2str(std(ox0-reforbit(1,:))*1e6,'%3.3f') ' -> ' num2str(std(oxc-reforbit(1,:))*1e6,'%3.3f') 'um']);
0188 disp(['freq: ' num2str(f0,'%3.3f') ' -> ' num2str(fc,'%3.3f') ' Hz ' ' ' num2str(fc-f0,'%3.3f') ' Hz ']);
0189 disp(['tlag: ' num2str(tlag0','%3.3f, ') ' -> ' num2str(tlagc','%3.3f, ') ' m' ' ' num2str(tlagc'-tlag0','%3.3f') ]);
0190 disp(['dpp: ' num2str(inCOD(5))])
0191 end