Commit 53fb4874 authored by Simone Liuzzo's avatar Simone Liuzzo

debug bestcor option in CTRM MDTNov27

parent b7a0dcd6
......@@ -5,6 +5,7 @@ classdef OrbitCorrection < RingControl
properties
ModelRM % response matrix structure for trajectory correction
end
......@@ -31,11 +32,13 @@ classdef OrbitCorrection < RingControl
switch obj.machine
case 'ebs-simu'
b = load('/machfs/liuzzo/EBS/Simulator/commissioningtools/matlab/@OrbitCorrection/EBSOrbitRM.mat');
b = load('/machfs/liuzzo/EBS/Simulator/commissioningtools/@OrbitCorrection/EBSOrbitRM.mat');
obj.ModelRM = b.ModelRM;
case 'esrf-sr'
b = load('/machfs/MDT/2018/Nov27/matlaboperation_MASTER_BESTCOR/@OrbitCorrection/ESRFSimuOrbitRM.mat');
obj.ModelRM = b.ModelRM;
case 'esrf-sy'
......
......@@ -111,7 +111,6 @@ inCOD = zeros(6,1);
indBPM = p.Results.indBPM;
indHCor = p.Results.indHCor;
indVCor = p.Results.indVCor;
lim = p.Results.max_BPM_good_reading;
cor_s_range = p.Results.cor_s_range;
bpm_s_range = p.Results.bpm_s_range;
......@@ -297,14 +296,11 @@ while ~stopped
%% COMPUTE HORIZONTAL CORRECTION
% septa, h steerers, frequency
if printouttext
disp('H PLANE');
end
% get initial corrector values
% get initial corrector values
corh0=obj.sh.get;
tothcor=corh0;
% restrict RM to usable correctors
if corropt.corH
......@@ -315,6 +311,14 @@ while ~stopped
steermeanlist=[];
end
if corropt.corH
if printouttext
disp('H PLANE');
end
% dpp correction, add after of correctors
if corropt.corRF
RespHd=RMHd(usebpm);
......@@ -386,17 +390,12 @@ while ~stopped
end
% SVD/bestcor Correction
if ~corropt.absolute
dch=obj.computecorrection(corropt.svdmode,FRH,vec,corropt.svdparam);
% apply only a fraction of the computed correction
dch = dch*corropt.fraction;
else
dch1=obj.computecorrection(corropt.svdmode,FRH,vec1,corropt.svdparam);
end
dch=obj.computecorrection(corropt.svdmode,FRH,vec,corropt.svdparam);
dch1=obj.computecorrection(corropt.svdmode,FRH,vec1,corropt.svdparam);
% apply only a fraction of the computed correction
dch = dch*corropt.fraction;
% if dpp correction separate dpp from correctors
if corropt.corRF
deltacor0=deltacor;
......@@ -410,8 +409,6 @@ while ~stopped
end
end
tothcor=corh0;
% limit steerers strengths
if corropt.corH
cc = corh0*0;
......@@ -435,17 +432,21 @@ while ~stopped
end
end
%% COMPUTE VERTICAL CORRECTION
% get current correctors values
corv0=obj.sv.get;
totvcor=corv0;
RespV=RMV(usebpm,usecorV);
if corropt.corV
if printouttext
disp('V PLANE');
end
% get current correctors values
corv0=obj.sv.get;
% restrict RM
RespV=RMV(usebpm,usecorV);
steermeanlist = ones(size(corv0(usecorV)));
if corropt.corRF % dpp correction
......@@ -464,7 +465,11 @@ while ~stopped
if corropt.meanzero % no dpp mean0
FRV=[RespV;steermeanlist];
elseif ~corropt.meanzero % no dpp no mean0
FRV=RespV;
FRV=RespV;disp('Correction regressing ');
disp(['rms orbit not decreased: ' num2str(nbpmu)]);
disp(['Before Correction: ' num2str(std2(t0is'))]);
disp(['After Correction: ' num2str(std2(t'))]);
end
......@@ -510,15 +515,13 @@ while ~stopped
end
% SVD/bestcor Correction
if ~corropt.absolute
dcv=obj.computecorrection(corropt.svdmode,FRV,vec,corropt.svdparam);
% apply only a fraction of the computed correction
dcv = dcv*corropt.fraction;
else
dcv1=obj.computecorrection(corropt.svdmode,FRV,vec1,corropt.svdparam);
end
disp('relative')
dcv=obj.computecorrection(corropt.svdmode,FRV,vec,corropt.svdparam);
disp('absolute')
dcv1=obj.computecorrection(corropt.svdmode,FRV,vec1,corropt.svdparam);
totvcor=corv0;
% apply only a fraction of the computed correction
dcv = dcv*corropt.fraction;
% limit steerers strengths
if corropt.corV
......@@ -541,9 +544,10 @@ while ~stopped
totvcor(totvcor>corropt.steererlimit(2))=corropt.steererlimit(2);
totvcor(totvcor<-corropt.steererlimit(2))=-corropt.steererlimit(2);
end
end
end
%% APPLY CORRECTION
%% APPLY CORRECTIONS19/C24 0.02
% display proposed correction
t0is = t_iter_start;
......@@ -555,7 +559,7 @@ while ~stopped
plot(sbpm,t0is(1,:),'r+-'); hold on;
%plot(sbpm(~usebpm),t0is(1,~usebpm),'mx','MarkerSize',15,'LineWidth',2);hold on;
if corropt.corH
plot(sbpm,t0is(1,:)-(RespH*(corh0(usecorH)-tothcor(usecorH))')','co-');
% plot(sbpm,t0is(1,:)+(RespH*(corh0(usecorH)-tothcor(usecorH))')','co-');
end
legend('objective','measured','proposed');
ylabel('hor [m]');
......@@ -574,14 +578,14 @@ while ~stopped
ax2=subplot(2,2,2);
bar(scorh,[repmat(obj.sh.get,1,1); tothcor]','BarWidth',10);
bar(scorh,[repmat(obj.sh.get,1,1); tothcor]','BarWidth',2);
ylabel('hor [rad]');
%xlabel('s [m]');
ax2.XTick=scorh;%1:length(scorh);
if strcmp(obj.machine,'ebs-simu')
ax2.XTickLabel=cellfun(@(a)a(1:end),ebs.hsteername(1:length(indHCor)),'un',0);
elseif strcmp(obj.machine,'esrf-sr')
ax2.XTickLabel=repmat(cellfun(@(a)a(1:end),sr.hsteername(1:length(indHCor)),'un',0),1,obj.nturns);
ax2.XTickLabel=repmat(cellfun(@(a)a(1:end),sr.steername(1:length(indHCor)),'un',0),1,obj.nturns);
end
ax2.XTickLabelRotation=90;
ax2.FontSize=8;
......@@ -591,14 +595,12 @@ while ~stopped
plot(sbpm,t0is(2,:),'r+-'); hold on;
% plot(sbpm(~usebpm),t0is(2,~usebpm),'mx','MarkerSize',15,'LineWidth',2); hold on;
if corropt.corV
plot(sbpm,t0is(2,:)-(RespV*(corv0(usecorV)-totvcor(usecorV))')','co-');
% plot(sbpm,t0is(2,:)+(RespV*(corv0(usecorV)-totvcor(usecorV))')','co-');
end
legend('objective','measured','proposed');
ylabel('ver [m]'); grid on;
ylim([-corropt.limits(2) corropt.limits(2)]);
xlabel('s [m]');
ax4=subplot(2,2,4);
bar(scorv,[repmat(obj.sv.get,1,1); totvcor]');
ylabel('ver [rad]');
......@@ -609,10 +611,14 @@ while ~stopped
if printouttext
% display results
disp('Forseen change: ')
if corropt.corH
disp(['hor. : ' num2str(std2(ox(usebpm))*1e6,'%3.3f') ' -> '...
num2str(std2(t0is(1,:)'-RespH*(corh0(usecorH)-tothcor(usecorH))')*1e6,'%3.3f') ' um'])
num2str(std2(RespH*(corh0(usecorH)-tothcor(usecorH))')*1e6,'%3.3f') ' um'])
end
if corropt.corV
disp(['ver. : ' num2str(std2(oy(usebpm))*1e6,'%3.3f') ' -> '...
num2str(std2(t0is(2,:)'-RespV*(corv0(usecorV)-totvcor(usecorV))')*1e6,'%3.3f') ' um'])
num2str(std2(RespV*(corv0(usecorV)-totvcor(usecorV))')*1e6,'%3.3f') ' um'])
end
disp(['H cor mean: ' num2str(std2(corh0*1e6),'%3.3f') ' -> ' num2str(std2(tothcor*1e6),'%3.3f') ' murad']);
disp(['V cor mean: ' num2str(std2(corv0*1e6),'%3.3f') ' -> ' num2str(std2(totvcor*1e6),'%3.3f') ' murad']);
......@@ -624,9 +630,7 @@ while ~stopped
if isempty(response), response = 'a'; end
end
if response == 'y' % REVERT
if response == 'y' % APPLY
if corropt.corH
......@@ -708,7 +712,7 @@ while ~stopped
if strcmp(obj.machine,'ebs-simu')
ax2.XTickLabel=cellfun(@(a)a(1:end),ebs.hsteername(1:length(indHCor)),'un',0);
elseif strcmp(obj.machine,'esrf-sr')
ax2.XTickLabel=repmat(cellfun(@(a)a(1:end),sr.hsteername(1:length(indHCor)),'un',0),1,obj.nturns);
ax2.XTickLabel=repmat(cellfun(@(a)a(1:end),sr.steername(1:length(indHCor)),'un',0),1,obj.nturns);
end
ax2.XTickLabelRotation=90;
ax2.FontSize=8;
......@@ -748,7 +752,7 @@ while ~stopped
nbpmu = length(find(usebpm));
lastsig = find(~isnan(ox),1,'last');
if any(std2(t0is')<std2(t'))
if any(std2(t0is([1,2],:)')<std2(t([1,2],:)'))
disp('Correction regressing ');
disp(['rms orbit not decreased: ' num2str(nbpmu)]);
......@@ -904,9 +908,9 @@ switch corropt.svdmode
corropt.svdmode = 'e';
corropt.svdparam = inputcor('max num of eigenvectors ',corropt.svdparam);
end
corropt.corH = inputcor('apply horizontal correction',corropt.corH);
corropt.corV = inputcor('apply vertical correction',corropt.corV);
corropt.corRF = inputcor('apply RF correction',corropt.corRF);
corropt.corH = inputcor('compute horizontal correction',corropt.corH);
corropt.corV = inputcor('compute vertical correction',corropt.corV);
corropt.corRF = inputcor('compute RF correction',corropt.corRF);
corropt.absolute = inputcor('Absolute (true) or Relative (false) correction',corropt.absolute);
if corropt.absolute
disp('absolute correction, no partial setting of correctors, plese use a large number of eigenvalues (100/300) or Tikhonov parameter (5-10).')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment