sempaneldisp.m 4.14 KB
Newer Older
Simone Liuzzo's avatar
Simone Liuzzo committed
1 2 3 4 5 6 7 8 9
function qemb=sempaneldisp(qemres,semres,qemb,qemb0,handles)

if nargin < 5, handles=struct(); end

qemb.at=qemat(qemres,qemb,true);
qemb=qemoptics(qemres,qemb,qemb0);
sbpm=cat(1,qemb.lindata.SPos);

if isfield(handles,'axes1')
10
    sqcheck(qemb.ks,qemb.kn,qemb.diptilt,handles.axes1,get(handles.largefigure,'Value'));
Simone Liuzzo's avatar
Simone Liuzzo committed
11
else
12
    sqcheck(qemb.ks,qemb.kn,qemb.diptilt,[],get(handles.largefigure,'Value'));
Simone Liuzzo's avatar
Simone Liuzzo committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
end

mess={};
if (isfield(handles,'compare') && handles.compare) || ...
        (isfield(handles,'pushbutton13') && strcmpi(get(handles.pushbutton13,'Enable'),'Off'))
    if all(isfield(semres,{'resph','respv','frespz'}))
        diffv2h=qemb.atrespv2h-semres.resph;    % Response V -> H in m/rad
        diffh2v=qemb.atresph2v-semres.respv;    % Response H -> V in m/rad
        diff2=[diffv2h diffh2v];
        residual=std2(diff2(:));
        vdispresidual=qemb.pm.alpha*std2(semres.bvscale*semres.frespz-qemb.frespz);
        fprintf('residual V2H = %g m/rad\n', std2(diffv2h(:)));
        fprintf('residual H2V = %g m/rad\n', std2(diffh2v(:)));
        mess={['orbit residual = '  num2str(residual)];...
            ['V disp. residual = ' num2str(vdispresidual)]};
        qemplotresp(4,diffv2h,diffh2v,'deviation');
    end
end

32 33 34

% PLOT EMITTANCE compared to measurement (see qemoptics.m and
% ebs.pinholenames(1:5)
Simone Liuzzo's avatar
Simone Liuzzo committed
35 36 37 38 39 40
mess0=semdisp(qemb,qemres,semres);      % figures 1 and 2
mess=[mess;...
    sprintf('tunes H/V: %.4f/%.4f',qemb.pm.fractunes);...
    mess0];

if isfield(handles,'text3')             % displays values
Simone Liuzzo's avatar
Simone Liuzzo committed
41
    set(handles.text3,'String',mess,'FontSize',10);
Simone Liuzzo's avatar
Simone Liuzzo committed
42 43 44 45 46
else
    fprintf('%s\n',mess{:});
end

if isfield(handles,'axes4')             % displays corr. strengths
47 48
    
    if  get(handles.largefigure,'Value')
49 50 51
        figure(21);
        extfigax = gca;
        plot(extfigax,qemb.skewcor);
52 53 54 55
        legend(extfigax,'initial','corrected');
        title(extfigax,'Corrector strengths');
        grid(extfigax,'on');
    end
56 57 58 59 60
    % colormp default;
    Nc = length(qemb.skewcor);
    extracor = mod(Nc,32); % remove extra correctors from injection cells
    cor_per_cell_std = squeeze(std(reshape(...
        qemb.skewcor((1+extracor/2):(Nc-extracor/2),:),...
61
        [],32,size(qemb.skewcor,2)),1,1));
62 63
    % cor_per_cell_mean = squeeze(mean(reshape(qemb.cor((1+extracor/2):(Nc-extracor/2),:),32,[],2),2));
    bar(handles.axes4,cor_per_cell_std,'EdgeColor','none');
64 65 66 67
    handles.axes4.XTick=[1:32];
    handles.axes4.XTickLabel=arrayfun(@(a)num2str(a),[4:32,1:3],'un',0);
    handles.axes4.XTickLabelRotation=90;
    
68 69 70
    title(handles.axes4,'std Corrector strengths (per cell)');
    legend(handles.axes4,'initial','corrected');
    grid(handles.axes4,'on');
71
    
Simone Liuzzo's avatar
Simone Liuzzo committed
72 73 74 75 76
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]);
77
        leg = {'measured','fit'};
Simone Liuzzo's avatar
Simone Liuzzo committed
78 79
    else
        plot(handles.axes2,sbpm,-qemb.pm.alpha*qemb.frespz);
80
        leg = {'measured'};
Simone Liuzzo's avatar
Simone Liuzzo committed
81 82 83 84 85 86 87
    end
    title(handles.axes2,'Vertical dispersion');
    ax=axis(handles.axes2);
    ym=max(abs(ax([3 4])));
    axis(handles.axes2,[0 844.39 -ym ym]);
    ylabel(handles.axes2,'\eta_z [m]');
    grid(handles.axes2,'on');
88
    legend(handles.axes2,leg);
Simone Liuzzo's avatar
Simone Liuzzo committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
end

if isfield(handles,'axes3')             % displays horizontal dispersion
    if isfield(qemres,'frespx')
        plot(handles.axes3,sbpm,-qemb.pm.alpha*[qemres.bhscale*qemres.frespx-qemb0.frespx qemb.frespx-qemb0.frespx]);
    else
        plot(handles.axes3,sbpm,-qemb.pm.alpha*(qemb.frespx-qemb0.frespx));
    end
    title(handles.axes3,'Horizontal dispersion');
    ax=axis(handles.axes3);
    ym=max(abs(ax([3 4])));
    axis(handles.axes3,[0 844.39 -ym ym]);
    ylabel(handles.axes3,'\eta_x [m]');
    grid(handles.axes3,'on');
end

105 106 107



Simone Liuzzo's avatar
Simone Liuzzo committed
108 109 110 111 112
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
113 114 115 116 117 118 119 120 121 122 123


    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