sempanelfitq.m 1.87 KB
Newer Older
Simone Liuzzo's avatar
Simone Liuzzo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
function [newks,quadresponse]=sempanelfitq(qemb,qemres,semres,varargin)
%SEMPANELFITQ Vary quadrupole strengths to fit the measured response matrix
%NEWK=SEMPANELFITS(MACH,QEMRES,SEMRES,OKVAR,OKBPM)
%
%QEMB:
%QEMRES:    global parameters (bpmidx,steerhidx,steervidx,hlist,vlist,
%           khrot,khgain,kvrot,kvgain,brot,bhgain,bvgain,resph,respv,frespx)
%SEMRES:    global parameters (hlist,vlist,bvscale,quadresponse,resph,respv,frespz)
%OKVAR:     Select a subset of variable parameters (default: all)
%OKBPM:     Select a subset of valid BPMS (default:all)
%
%NEWKS:       New skew quadrupole strengths

% narg=length(varargin);
% if narg<3
%     disparg={};
% else
%     disparg={@(i,itot) nselect(4,varargin{3},i,itot)};
%     narg=narg-1;
% end

22 23 24
% if isfield(semres,'quadresponse')
%     quadresponse=semres.quadresponse;
% else
Simone Liuzzo's avatar
Simone Liuzzo committed
25
    quadresponse=semquadresp(qemb,qemres,semres,varargin{:});
26
%end
Simone Liuzzo's avatar
Simone Liuzzo committed
27 28 29 30 31 32 33 34 35 36 37 38 39
orbit0=findsyncorbit(qemb.at,qemres.ct,qemres.bpmidx);

[rh,rh2v,rv2h,rv,frh,frv]=qemdecode(qemb.at,qemres.ct,qemres,...
    qemres.resph,semres.respv,semres.resph,qemres.respv,...
    qemres.frespx,semres.frespz,...
    qemres.khrot,qemres.khgain,qemres.kvrot,qemres.kvgain,...
    qemres.brot,qemres.bhgain,qemres.bvgain); %#ok<ASGLU>
[rh0,rh2v0,rv2h0,rv0,frh0,frv0]=qemcode(qemb.at,qemres.ct,...
    qemres.steerhidx(qemres.hlist),qemres.steervidx(qemres.vlist),...
    qemres.bpmidx,[],[],[],[],[],[],[],orbit0); %#ok<ASGLU>

resp0=[rh2v0(:);rv2h0(:);frv0];
resp=[rh2v(:);rv2h(:);semres.bvscale*frv];
40 41 42
% 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();%
43
mode.neigs=semres.neigQuadFit; % struct();%
44

Simone Liuzzo's avatar
Simone Liuzzo committed
45 46 47 48 49
% 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,...
    quadresponse,mode);
end