Commit 370444d2 authored by Simone Liuzzo's avatar Simone Liuzzo

WIP:initial modification for SEMPANEL

parent 2357acb5
......@@ -18,7 +18,7 @@ orbitrange=nbpm*(nhst+nvst);
if nargin<7, okbpm=true(nbpm,1); end
if nargin<6, okfit=true(nq,1); end
if nargin<5 || isempty(mode), mode=struct; end
if ~isfield(mode,'nsets'), mode.nsets=4; end
if ~isfield(mode,'nsets'), mode.nsets=16; end
if ~isfield(mode,'neigs'), mode.neigs=100; end
if ~isfield(mode,'dispweight'), mode.dispweight=0; end
if ~isfield(mode,'vnorm')
......
......@@ -12,7 +12,8 @@ if isempty(okfit), okfit=true(1,length(qemres.dipidx)); end
dfrv=semres.bvscale*frv-frv0;
[~,dipresponse]=qemdispderiv(mach,qemres.ct,@tiltelem,1.e-4,qemres.dipidx,qemres.bpmidx);
bok=isfinite(dfrv)&okbpm;
diprot=dipresponse(bok,okfit)\dfrv(bok);
%diprot=dipresponse(bok,okfit)\dfrv(bok);
diprot = qemsvd(dipresponse(bok,okfit),dfrv(bok),5);%floor(length(find(okfit))/2));
function elt=tiltelem(elt,dval)
vini=atan2(elt.R1(1,3),elt.R1(1,1));
......
......@@ -12,7 +12,9 @@ if isempty(okfit), okfit=true(1,length(qemres.dipidx)); end
dfrv=semres.bvscale*frv-frv0;
[~,dipresponse]=qemdispderivAnalytic(mach,qemres.dipidx,qemres.bpmidx);
bok=isfinite(dfrv)&okbpm;
diprot=dipresponse(bok,okfit)\dfrv(bok);
% diprot=dipresponse(bok,okfit)\dfrv(bok);
diprot = qemsvd(dipresponse(bok,okfit),dfrv(bok),5);%floor(length(find(okfit))/6));
function elt=tiltelem(elt,dval)
vini=atan2(elt.R1(1,3),elt.R1(1,1));
......
......@@ -89,9 +89,10 @@ semres.iaxemz=semloadiax(qemres.datadir);
handles.semdata=sempanelset(qemres.datadir,handles);
A=textscan(fopen(fullfile(qemres.datadir,'skewcor.dat'),'r'),'%s %f','HeaderLines',7); %read from setting manager saved file
qemb(2).skewcor=A{2};
qemb(2).skewcor=A{2}*0; warning('zero initial skew quadrupoles')
set(handles.pushbutton3,'Enable','On');
set(handles.pushbutton9,'Enable','On');
qemb(2)=sempaneldisp(qemres,semres,qemb(2),qemb(1),handles);
set(handles.edit1,'String',qemres.datadir);
guidata(hObject,handles);
......@@ -129,7 +130,7 @@ global qemb qemres semres
set(handles.statustext,'String','fitting quadrupoles');
semres.wdisp=str2double(get(handles.edit3,'String'));
if get(handles.AnalyticFitCheck,'Value') == 1
hw=waitbar(0,'Fitting quadrupole rotations...');
hw=waitbar(0,'Fitting quadrupole rotations (Analytic)...');
else
hw=waitbar(0,'Fitting quadrupole rotations...');
end
......@@ -168,12 +169,14 @@ function pushbutton10_Callback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global qemb qemres semres
set(handles.statustext,'String','Setting errors to 0');
qemb(2).ks=qemb(1).ks;
qemb(2).diptilt=qemb(1).diptilt;
qemb(2).dzs=qemb(1).dzs;
qemb(2)=sempaneldisp(qemres,semres,qemb(2),qemb(1),handles);
set(handles.semdata.errdef,'Enable','On');
set(hObject,'Enable','Off');
set(handles.statustext,'String','Errors at 0');
% --- Executes on button press in pushbutton11: Errors->Save
function pushbutton11_Callback(hObject, eventdata, handles)
......@@ -260,8 +263,11 @@ function pushbutton13_Callback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global qemb qemres semres
qemb(2).skewcor(:,2)=load_correction(fullfile(qemres.datadir,'skewcor.dat'),...
qemres.skcode,qemres.opticsdir);
%qemb(2).skewcor(:,2)=load_correction(fullfile(qemres.datadir,'skewcor.dat'),...
% qemres.skcode,qemres.opticsdir);
A=textscan(fopen(fullfile(qemres.datadir,'skewcor.dat'),'r'),'%s %f','HeaderLines',7); %read from setting manager saved file
qemb(2).skewcor(:,2)=A{2};
set(handles.semdata.cordef,'Enable','On');
set(hObject,'Enable','Off');
qemb(2)=sempaneldisp(qemres,semres,qemb(2),qemb(1),handles);
......@@ -308,8 +314,11 @@ global qemb qemres semres
corfile=fullfile(qemres.datadir, 'skewcor.dat');
[fname,fpath]=uigetfile('*.dat','Load correction:',corfile);
if ischar(fname)
qemb(2).skewcor(:,2)=load_correction(fullfile(fpath,fname),...
qemres.skcode,qemres.opticsdir);
% qemb(2).skewcor(:,2)=load_correction(fullfile(fpath,fname),...
% qemres.skcode,qemres.opticsdir);
A=textscan(fopen(fullfile(qemres.datadir,'skewcor.dat'),'r'),'%s %f','HeaderLines',7); %read from setting manager saved file
qemb(2).skewcor(:,2)=A{2};
set(handles.semdata.cordef,'Enable','On');
qemb(2)=sempaneldisp(qemres,semres,qemb(2),qemb(1),handles);
end
......@@ -369,6 +378,7 @@ function edit3_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
% DISPERSION WEIGTH FOR quadrupole FIT
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
......
......@@ -50,8 +50,10 @@ end
if isfield(handles,'axes2') % displays vertical dispersion
if isfield(semres,'frespz')
plot(handles.axes2,sbpm,-qemb.pm.alpha*[semres.bvscale*semres.frespz qemb.frespz]);
leg = {'measured','fit'};
else
plot(handles.axes2,sbpm,-qemb.pm.alpha*qemb.frespz);
leg = {'measured'};
end
title(handles.axes2,'Vertical dispersion');
ax=axis(handles.axes2);
......@@ -59,6 +61,7 @@ if isfield(handles,'axes2') % displays vertical dispersion
axis(handles.axes2,[0 844.39 -ym ym]);
ylabel(handles.axes2,'\eta_z [m]');
grid(handles.axes2,'on');
legend(handles.axes2,leg);
end
if isfield(handles,'axes3') % displays horizontal dispersion
......@@ -75,8 +78,96 @@ if isfield(handles,'axes3') % displays horizontal dispersion
grid(handles.axes3,'on');
end
% %% compare to simulator
a=load('/operation/appdata/ebs/optics/settings/theory/errcormodel.mat','errcormodel'); warning('replace by ring simulator lattice or remove');
rs=a.errcormodel;
inds=1:length(rs);
indbs=find(atgetcells(rs,'Class','Monitor'))';
modulh=bmodul(qemb.beta(:,1),qemb0.beta(:,1));
modulv=bmodul(qemb.beta(:,2),qemb0.beta(:,2));
[ls,ts,cs]=atlinopt(rs,0,inds);
ss=arrayfun(@(a)a.SPos(1),ls);
bxs=arrayfun(@(a)a.beta(1),ls);
bys=arrayfun(@(a)a.beta(2),ls);
dxs=arrayfun(@(a)a.Dispersion(1),ls);
dzs=arrayfun(@(a)a.Dispersion(3),ls);
modulhS=bmodul(bxs(indbs)',qemb0.beta(:,1));
modulvS=bmodul(bys(indbs)',qemb0.beta(:,2));
%%
figure;
subplot(2,2,1)
qemmodulplot(gca, sbpm, modulh, '');hold on;
qemmodulplot(gca, ss(indbs),modulhS, '');hold off;
legend('\beta_x FIT','\beta_x SIMULATOR','Location','NorthWest')
subplot(2,2,2)
qemmodulplot(gca, sbpm, modulv, '');hold on;
qemmodulplot(gca, ss(indbs),modulvS, '');hold off;
legend('\beta_z FIT','\beta_z SIMULATOR','Location','NorthWest')
subplot(2,2,3)
if isfield(qemres,'frespx')
plot(gca,sbpm,-qemb.pm.alpha*[qemb.frespx-qemb0.frespx...
qemres.bhscale*qemres.frespx-qemb0.frespx...
(qemb.frespx-qemb0.frespx)-(qemres.bhscale*qemres.frespx-qemb0.frespx)]);
else
plot(gca,sbpm,-qemb.pm.alpha*(qemb.frespx-qemb0.frespx));
end
hold on;
plot(gca,sbpm,(dxs(indbs)'-(-qemb.pm.alpha*qemb0.frespx)));
ax=axis(gca);
ym=max(abs(ax([3 4])));
axis(gca,[0 844.39 -ym ym]);
ylabel(gca,'\eta_x [m]');
grid(gca,'on');
legend(gca,'\Delta\eta_x measured','\Delta\eta_x fit','\Delta\eta_x difference','\Delta\eta_x simulator','Location','NorthWest')
subplot(2,2,4)
if isfield(qemres,'frespz')
plot(gca,sbpm,-qemb.pm.alpha*[qemb.frespz-qemb0.frespz...
qemres.bzscale*qemres.frespz-qemb0.frespz...
(qemb.frespz-qemb0.frespz)-(qemres.bhscale*qemres.frespz-qemb0.frespz)]);
else
plot(gca,sbpm,-qemb.pm.alpha*(qemb.frespz-qemb0.frespz));
end
hold on;
plot(gca,sbpm,(dzs(indbs)'-(-qemb.pm.alpha*qemb0.frespz)));
ax=axis(gca);
ym=max(abs(ax([3 4])));
axis(gca,[0 844.39 -ym ym]);
ylabel(gca,'\eta_z [m]');
grid(gca,'on');
legend(gca,'\Delta\eta_z measured',....
'\Delta\eta_z fit','\Delta\eta_z difference',...
'\Delta\eta_z simulator','Location','NorthWest')
disp('simulator (will be removed)');toc;
if isfield(handles,'selplot') % additional plot
sempanelplot(5,handles.selplot,qemb0,qemb,qemres);
elseif isfield(handles,'popupmenu3')
sempanelplot(5,get(handles.popupmenu3,'Value'),qemb0,qemb,qemres);
end
function bave=baverage(b)
bb=mean(sr.fold(b),2);
bave=repmat([bb;bb(end:-1:1)],16,1);
end
function mdl=bmodul(beta,beta0)
mdl=(beta-beta0)./beta0;
end
end
......@@ -37,7 +37,10 @@ orbit0=findsyncorbit(qemb.at,qemres.ct,qemres.bpmidx);
resp0=[rh2v0(:);rv2h0(:);frv0];
resp=[rh2v(:);rv2h(:);semres.bvscale*frv];
mode=struct('vnorm',sqrt([0.77;2;0.9;1.15;1.15;0.9;2;1]));
% mode=struct('vnorm',sqrt([0.77;2;0.9;1.15;1.15;0.9;2;1]));
mode=struct();
mode=struct('dispweight',semres.wdisp); % struct();%
% newks=qemb.ks+semerrfit(length(semres.hlist),length(semres.vlist),resp-resp0,...
% quadresponse,mode,varargin{:});
newks=qemb.ks+semerrfit(length(semres.hlist),length(semres.vlist),resp-resp0,...
......
......@@ -19,11 +19,11 @@ function [newks,quadresponse]=sempanelfitqAnalytic(qemb,qemres,semres,varargin)
% narg=narg-1;
% end
if isfield(semres,'quadresponse')
quadresponse=semres.quadresponse;
else
% if isfield(semres,'quadresponse')
% quadresponse=semres.quadresponse;
% else
quadresponse=semquadrespAnalytic(qemb,qemres,semres,varargin{:});
end
% end
orbit0=findsyncorbit(qemb.at,qemres.ct,qemres.bpmidx);
[rh,rh2v,rv2h,rv,frh,frv]=qemdecode(qemb.at,qemres.ct,qemres,...
......@@ -37,9 +37,9 @@ orbit0=findsyncorbit(qemb.at,qemres.ct,qemres.bpmidx);
resp0=[rh2v0(:);rv2h0(:);frv0];
resp=[rh2v(:);rv2h(:);semres.bvscale*frv];
mode=struct();
mode=struct('dispweight',semres.wdisp); % struct();%
% newks=qemb.ks+semerrfit(length(semres.hlist),length(semres.vlist),resp-resp0,...
% quadresponse,mode,varargin{:});
newks=qemb.ks+semerrfit(length(semres.hlist),length(semres.vlist),resp-resp0,...
newks=qemb.ks + semerrfit(length(semres.hlist),length(semres.vlist),resp-resp0,...
quadresponse,mode);
end
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