0001
0002 close all
0003 clear all
0004 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions');
0005
0006 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions/correction/');
0007 addpath('/mntdirect/_machfs/liuzzo/CODE/LatticeTuningFunctions/errors/');
0008
0009
0010 load ESRFLattice.mat
0011
0012
0013 speclab='DispersionESRF';
0014
0015 modelrmfile=fullfile(pwd,['RMmodel' speclab '.mat']);
0016
0017 if ~exist([modelrmfile],'file')
0018
0019 ModelRM...
0020 =getresponsematrices(...
0021 ring,...
0022 indBPM,...
0023 indHCor,...
0024 indVCor,...
0025 indSCor,...
0026 indQCor,...
0027 [],...
0028 [0 0 0 0 0 0]',...
0029 [9 10 11]);
0030
0031 save([modelrmfile],'ModelRM');
0032 else
0033 load([modelrmfile],'ModelRM');
0034 end
0035
0036
0037 ind=find(atgetcells(ring,'Class','Quadrupole','Sextupole'));
0038 dx=5e-6*randn(size(ind));
0039 dy=5e-6*randn(size(ind));
0040 dr=5e-6*randn(size(ind));
0041
0042 rerr=atsetshift(ring,ind,dx,dy);
0043 rerr=atsettilt(rerr,ind,dr);
0044
0045
0046 inCOD=[0 0 0 0 0 0]';
0047 [l,~,~]=atlinopt(ring,0,indBPM);
0048 refdispersion=zeros(2,length(indBPM));
0049 refdispersion(1,:)=arrayfun(@(a)a.Dispersion(1),l);
0050 refdispersion(2,:)=arrayfun(@(a)a.Dispersion(3),l);
0051
0052
0053 [rcor,inCOD,hs,vs]=atcorrectdispersion(...
0054 rerr,...
0055 indBPM,...
0056 indQCor,...
0057 indSCor,...
0058 inCOD,...
0059 [floor(linspace(20,250,7));...
0060 floor(linspace(20,250,7))]',...
0061 [false true],...
0062 1.0,...
0063 ModelRM,...
0064 refdispersion,...
0065 [],...
0066 true);
0067
0068 alpha=mcf(rerr);
0069 indrfc=find(atgetcells(rerr,'Frequency'));
0070 delta=1e-4;
0071
0072 o=finddispersion6Err(rerr,indBPM,indrfc,alpha,delta,inCOD);
0073 oxe=o(1,:);
0074 oye=o(3,:);
0075
0076 o=finddispersion6Err(rcor,indBPM,indrfc,alpha,delta,inCOD);
0077 oxc=o(1,:);
0078 oyc=o(3,:);
0079
0080 sBPM=findspos(rcor,indBPM);
0081 figure;subplot(2,1,1);
0082 plot(sBPM,oxe-refdispersion(1,:),'.-');hold on; plot(sBPM,oxc-refdispersion(1,:),'.-');
0083 legend('before','after');
0084 xlabel('s [m]');
0085 ylabel('hor. disp - model');
0086 subplot(2,1,2);
0087 plot(sBPM,oye-refdispersion(2,:),'.-');hold on; plot(sBPM,oyc-refdispersion(2,:),'.-');
0088 legend('before','after');
0089 xlabel('s [m]');
0090 ylabel('ver. disp');
0091 saveas(gca,'DispCor.fig');
0092 export_fig('DispCor.jpg','-r300');
0093
0094 return