Home > pubtools > LatticeTuningFunctions > correction > RFcavity > atRFcorrection.m

atRFcorrection

PURPOSE ^

function [...

SYNOPSIS ^

function [rcor,inCOD,fc.]=atRFcorrection(rerr,indBPM,inCOD,neigSteerer,scalefactor,ModelRM,reforbit,printouttext)

DESCRIPTION ^

 function [...
    rcor,...           1) corrected lattice
    inCOD,...          2) initial COD 
    fc...              3) required frequency change
    ]=atRFcorrection(...
     rerr,...          1) AT lattice to correct
     indBPM,...        2) Nbx1 bpm indexes
     inCOD,...         3) 6x1 initial COD guess
     neigSteerer,...   4) 1xNiter eigenvectors for correction dpp (default: [1])
     scalefactor,...   5) scale factor to correction (default: 1.0)
     ModelRM,...       6) ModelRM.Orb(H/V)DPP = 6x1 array of orbit
                          response to dpp
                          if [] compute RM (default: [])
     reforbit,...      7) 2xNbpm reference orbit to correct to (default 0*2xNb)
     printouttext      8) if 1 or true, display rms orbit
     )

 corrects RF frequency and TimeLag to have 0 timeLag at cavities and
 minimize the dispersive contribution to orbit ( final <dpp>_ring =0 )

 features impelemented:
 ddp correction
 6D orbit with BPM errors
 initial coordinate
 correction to reference orbit refx refy
 use atsetfieldvalues, atgetcells


see also: qemsvd_mod findorbit6Err getresponsematrices

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % function [...
0015 %    rcor,...           1) corrected lattice
0016 %    inCOD,...          2) initial COD
0017 %    fc...              3) required frequency change
0018 %    ]=atRFcorrection(...
0019 %     rerr,...          1) AT lattice to correct
0020 %     indBPM,...        2) Nbx1 bpm indexes
0021 %     inCOD,...         3) 6x1 initial COD guess
0022 %     neigSteerer,...   4) 1xNiter eigenvectors for correction dpp (default: [1])
0023 %     scalefactor,...   5) scale factor to correction (default: 1.0)
0024 %     ModelRM,...       6) ModelRM.Orb(H/V)DPP = 6x1 array of orbit
0025 %                          response to dpp
0026 %                          if [] compute RM (default: [])
0027 %     reforbit,...      7) 2xNbpm reference orbit to correct to (default 0*2xNb)
0028 %     printouttext      8) if 1 or true, display rms orbit
0029 %     )
0030 %
0031 % corrects RF frequency and TimeLag to have 0 timeLag at cavities and
0032 % minimize the dispersive contribution to orbit ( final <dpp>_ring =0 )
0033 %
0034 % features impelemented:
0035 % ddp correction
0036 % 6D orbit with BPM errors
0037 % initial coordinate
0038 % correction to reference orbit refx refy
0039 % use atsetfieldvalues, atgetcells
0040 %
0041 %
0042 %see also: qemsvd_mod findorbit6Err getresponsematrices
0043 
0044 
0045 
0046 % response matrix kicks
0047 kval=1e-5;
0048 delta=1e-3;
0049 
0050 alpha=mcf(rerr);
0051 indrfc=find(atgetcells(rerr,'Frequency'));
0052 
0053 % default arguments
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 % load or compute response matrix
0096 if isempty(ModelRM)
0097     % get orbit RM
0098     if printouttext
0099         disp('get orbit RM'); end;
0100     
0101         ModelRM=getresponsematrices(...
0102             rerr,...          %1 AT lattice
0103             indBPM,...      %2 bpm indexes in at lattice
0104             [],...     %3 h cor indexes
0105             [],...     %4 v cor indexes
0106             [],...     %5 skew cor indexes
0107             [],...     %6 quad cor indexes
0108             [],...
0109             inCOD,...       %7 initial coordinates
0110             [3]...      %8 specifiy rm to be computed
0111             );
0112    
0113 end
0114 
0115 % kval=ModelRM.kval;
0116 dppH=ModelRM.OrbHDPP;
0117 dppV=ModelRM.OrbVDPP;
0118 % delta=ModelRM.delta;
0119 
0120 % get intiial RF
0121 f0=rerr{indrfc(1)}.Frequency;
0122 tlag0=atgetfieldvalues(rerr,indrfc,'TimeLag');
0123     
0124 % get initial orbit
0125 o=findorbit6Err(rerr,indBPM,inCOD);
0126 ox0=o(1,:);
0127 oy0=o(3,:);
0128 
0129 %rerr0=rerr;
0130 
0131 % iterate correction
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     % intial RF frequency
0140     f=rerr{indrfc(1)}.Frequency;
0141     tlag=atgetfieldvalues(rerr,indrfc,'TimeLag');
0142         
0143     % get current orbit
0144     o=findorbit6Err(rerr,indBPM,inCOD);
0145     ox=o(1,:);
0146     
0147     % subtract reference orbit
0148     ox=ox-reforbit(1,:);
0149     
0150     % build RMs
0151     
0152     RMH=dppH';
0153     
0154     % compute correction
0155     dd=qemsvd_mod(RMH,ox',neigSteerer(iter,1));
0156     
0157    
0158     % set RF correction
0159     rcor=atsetfieldvalues(rerr,indrfc,'Frequency',f-alpha*(-dd)*f);
0160     
0161     % reset TimeLag
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     % lattice start point for next iteration
0171     rerr=rcor;
0172 end
0173 
0174 % get current orbit
0175 o=findorbit6Err(rcor,indBPM,inCOD);
0176 oxc=o(1,:);
0177 
0178 % intial RF frequency
0179 fc=rcor{indrfc(1)}.Frequency;
0180 tlagc=atgetfieldvalues(rcor,indrfc,'TimeLag');
0181     
0182 inCOD=findorbit6Err(rcor,1,inCOD);
0183 
0184 if printouttext
0185     % display results
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

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005