Commit a3357171 authored by beamdyn's avatar beamdyn
Browse files

FitLocalErrors: additional input n eigvectors, error for bad positions,...

FitLocalErrors: additional input n eigvectors, error for bad positions, display of results, additional output of sorted positions
parent f9b2cd6f
function [knl, ksl] = FitLocalErrors(.... function [knl, ksl, serr] = FitLocalErrors(....
ReferenceRM,... ReferenceRM,...
PerturbedRM,... PerturbedRM,...
errorlocation) errorlocation,...
neig)
%FITLOCALERRORS fit the best error to reproduced the difference between %FITLOCALERRORS fit the best error to reproduced the difference between
% Reference and Perturebed RM at errorlocation s positions % Reference and Perturebed RM at errorlocation s positions
% %
% INPUT: % INPUT:
% ReferenceRM: folder where the RM data is loaded or RM itself % ReferenceRM : folder where the RM data is loaded or RM itself
% PerturbedRM: folder where the RM data is loaded or RM itself % PerturbedRM : folder where the RM data is loaded or RM itself
% errorlocation : list of s positions of error sources % errorlocation : list of s positions of error sources (
% neig : # of eigenvectors for svd (default: length(errorlocation))
% %
% OUTPUT: % OUTPUT:
% integrated normal (knl) and skew (ksl) quadrupole gradients (1/m) % integrated normal (knl) and skew (ksl) quadrupole gradients (1/m) and
% serr ordered locations of errors
% %
% EXAMPLE: % EXAMPLE:
% %
% >> [knl, ksl] = FitLocalErrors('/machfs/MDT/2018/Sep17/respAC1','/machfs/MDT/2018/Mar25/resp1',[345.5,824.2]) % >> [knl, ksl] = FitLocalErrors('/machfs/MDT/2018/Sep26/respAC14','/machfs/MDT/2018/Sep26/respAC22',[286.34 584.438]);
% %
% WARNING:
% errorlocation should not be inside dipoles! an
%
%see also: qemextract atsbreak %see also: qemextract atsbreak
if nargin<4
neig=length(errorlocation);
end
% load reference (normal and skew) % load reference (normal and skew)
[qemb, qemres, semres] = qemextract(ReferenceRM); [qemb, qemres, semres] = qemextract(ReferenceRM);
...@@ -29,6 +38,12 @@ function [knl, ksl] = FitLocalErrors(.... ...@@ -29,6 +38,12 @@ function [knl, ksl] = FitLocalErrors(....
% s location % s location
r = qemb(2).at; r = qemb(2).at;
C = findspos(r,length(r)+1);
if any(errorlocation>C) | any(errorlocation<0)
error(['Some locations are below 0 or above length of lattice (' num2str(C) ')']);
end
[rerr,errpos]=atsbreak(r,errorlocation); [rerr,errpos]=atsbreak(r,errorlocation);
Lthin = 1e-6; Lthin = 1e-6;
...@@ -131,7 +146,7 @@ if ~isfield(mode,'vnorm') ...@@ -131,7 +146,7 @@ if ~isfield(mode,'vnorm')
end end
mode.nsets=4; mode.nsets=4;
mode.neigs=length(errorlocation); mode.neigs=neig;
mode.tuneweight=0; mode.tuneweight=0;
mode.dispweight=0; mode.dispweight=0;
...@@ -145,17 +160,25 @@ resps0(isnan(resps0))=0; ...@@ -145,17 +160,25 @@ resps0(isnan(resps0))=0;
ks = semerrfit(length(semres.hlist),length(semres.vlist),resps-resps0,... ks = semerrfit(length(semres.hlist),length(semres.vlist),resps-resps0,...
drespskew,mode); drespskew,mode);
knl = kn ; knl = kn *Lthin;
ksl = ks ; ksl = ks *Lthin;
% display fit residual % display fit residual
rm_in=(resp-resp0); rm_in(end-length(qemres.bpmidx)-2:end)=[]; rm_in=(resp-resp0); rm_in(end-length(qemres.bpmidx)-2:end)=[];
dresp(end-length(qemres.bpmidx)-2:end)=[]; dresp(end-length(qemres.bpmidx)-2:end,:)=[];
disp(['residual on- diagonal blocks: ' num2str(std2(rm_in)) '->'... disp(['residual on- diagonal blocks: ' num2str(std2(rm_in)) '->'...
num2str(std2(rm_in - dresp*kn))]) num2str(std2(rm_in - dresp*kn))])
disp(['residual off-diagonal blocks: ' num2str(std2(resps-resps0)) '->'... disp(['residual off-diagonal blocks: ' num2str(std2(resps-resps0)) '->'...
num2str(std2(resps-resps0 - drespskew*ks))]) num2str(std2(resps-resps0 - drespskew*ks))])
% display results
serr = findspos(rerr,sort(errpos)); % fitted gradient are sorted in lattice order
for il=1:length(serr)
disp(['@ ' num2str(serr(il),'%6.2f') ' m : knl= '...
num2str(knl(il),'%9.2e') ' 1/m, ksl= '...
num2str(ksl(il),'%9.2e') ' 1/m']);
end
end end
......
Supports Markdown
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