semfitdipoleAnalytic.m 1001 Bytes
Newer Older
Simone Liuzzo's avatar
Simone Liuzzo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
function [diprot,dipresponse]=semfitdipoleAnalytic(mach,qemres,semres,okfit,okbpm)
%SEMFITDIPOLE Fits dipole beanding angle to match the measured dispersion
%[DIPROT,DIPRESPONSE]=SEMFITDIPOLE(QEMB,QEMRES,SEMRES,OKVAR,OKBPM)

if nargin<5, okbpm=[]; end
if nargin<4, okfit=[]; end
if isempty(okbpm), okbpm=true(length(qemres.bpmidx),1); end
if isempty(okfit), okfit=true(1,length(qemres.dipidx)); end
[frh,frv]=qembpmdecode(qemres.frespx,semres.frespz,...
    qemres.brot,qemres.bhgain,qemres.bvgain);  %#ok<ASGLU>
[frh0,frv0]=qemfresp(mach,qemres.ct,qemres.bpmidx,[],[],[]);  %#ok<ASGLU>
dfrv=semres.bvscale*frv-frv0;
[~,dipresponse]=qemdispderivAnalytic(mach,qemres.dipidx,qemres.bpmidx);
bok=isfinite(dfrv)&okbpm;
15 16
% diprot=dipresponse(bok,okfit)\dfrv(bok);

17
diprot = qemsvd(dipresponse(bok,okfit),dfrv(bok),semres.neigDipFit);%floor(length(find(okfit))/6));
Simone Liuzzo's avatar
Simone Liuzzo committed
18 19 20 21 22 23 24

    function elt=tiltelem(elt,dval)
        vini=atan2(elt.R1(1,3),elt.R1(1,1));
        elt=attiltelem(elt,vini+dval);
    end
        
end