Skip to content

Commit

Permalink
Fix atplot for single-element lattices (#854)
Browse files Browse the repository at this point in the history
* fix atplot for single element lattices
* ring splitting when length(ring)==1
  • Loading branch information
lfarv authored Nov 13, 2024
1 parent a929804 commit 268994f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 47 deletions.
81 changes: 36 additions & 45 deletions atmat/atplot/atplotsyn.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,54 @@
indx=indx(sok);
[dipoles,qpoles,spoles,mpoles,bpms]=cellfun(@eltype,rok);

ampl=0.05*tlim; % Dipoles
[xplot,yplot]=setxpl(sl(dipoles),ll(dipoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
%[xplot,yplot]=setxpl(sl(dipoles),ll(dipoles),[0;0;1;1;0],ampl*[-1;1;1;-1;-1]);
if (~isempty(xplot) && ~isempty(yplot))
p1=patch(xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
%p1=patch(ax,xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
sld=sl(dipoles);
if isempty(sld)
p1={};
else
p1={};
ampl=0.05*tlim; % Dipoles
[xplot,yplot]=setxpl(sld,ll(dipoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
p1=patch(xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
end

ampl=0.05*tlim; % Quadrupoles
foc=reshape(0.4*ampl*sign(atgetfieldvalues(rok(qpoles),'PolynomB',{2})),1,[]);
[xplot,yplot]=setxpl(sl(qpoles),ll(qpoles),[0;0;0.5;1;1;0],ampl*[0;1;1;1;0;0]);
yplot(3,:)=yplot(3,:)+foc;
%[xplot,yplot]=setxpl(sl(qpoles),ll(qpoles),[0;0;0.5;1;1;0.5;0],ampl*[-1;1;1;1;-1;-1;-1]);
%yplot(6,:)=yplot(6,:)-foc;
if (~isempty(xplot) && ~isempty(yplot))
p2=patch(xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
%p2=patch(ax,xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
slq=sl(qpoles);
if isempty(slq)
p2={};
else
p2={};
ampl=0.05*tlim; % Quadrupoles
foc=reshape(0.4*ampl*sign(atgetfieldvalues(rok(qpoles),'PolynomB',{2})),1,[]);
[xplot,yplot]=setxpl(slq,ll(qpoles),[0;0;0.5;1;1;0],ampl*[0;1;1;1;0;0]);
yplot(3,:)=yplot(3,:)+foc;
p2=patch(xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
end

ampl=0.04*tlim; % Sextupoles
foc=reshape(0.25*ampl*sign(atgetfieldvalues(rok(spoles),'PolynomB',{3})),1,[]);
[xplot,yplot]=setxpl(sl(spoles),ll(spoles),[0;0;0.33;0.66;1;1;0],ampl*[0;1;1;1;1;0;0]);
yplot(3:4,:)=yplot(3:4,:)+foc([1;1],:);
%[xplot,yplot]=setxpl(sl(spoles),ll(spoles),[0;0;0.33;0.66;1;1;0.66;0.33;0],ampl*[-1;1;1;1;1;-1;-1;-1;-1]);
%yplot(7:8,:)=yplot(7:8,:)-foc([1;1],:);
if (~isempty(xplot) && ~isempty(yplot))
p3=patch(xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
%p3=patch(ax,xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
sls=sl(spoles);
if isempty(sls)
p3={};
else
p3={};
ampl=0.04*tlim; % Sextupoles
foc=reshape(0.25*ampl*sign(atgetfieldvalues(rok(spoles),'PolynomB',{3})),1,[]);
[xplot,yplot]=setxpl(sls,ll(spoles),[0;0;0.33;0.66;1;1;0],ampl*[0;1;1;1;1;0;0]);
yplot(3:4,:)=yplot(3:4,:)+foc([1;1],:);
p3=patch(xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
end

ampl=0.03*tlim; % Other multipoles
[xplot,yplot]=setxpl(sl(mpoles),ll(mpoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
%[xplot,yplot]=setxpl(sl(mpoles),ll(mpoles),[0;0;1;1;0],ampl*[-1;1;1;-1;-1]);
if (~isempty(xplot) && ~isempty(yplot))
p4=patch(xplot,yplot,[0 0.5 0]);
%p4=patch(ax,xplot,yplot,[0 0.5 0]);
slm=sl(mpoles);
if isempty(slm)
p4={};
else
p4={};
ampl=0.03*tlim; % Other multipoles
[xplot,yplot]=setxpl(slm,ll(mpoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
p4=patch(xplot,yplot,[0 0.5 0]);
end

ampl=0.015*tlim; % BPMs
amplx=0.005*slim;
[xplot,yplot]=setxpl(sl(bpms),ones(1,sum(bpms)),[-amplx;0;amplx;0;-amplx],[0;-ampl;0;ampl;0]);
if (~isempty(xplot) && ~isempty(yplot))
p5=patch(xplot,yplot,[0 0.5 0],'DisplayName','BPM');
%p5=patch(ax,xplot,yplot,[0 0 0],'clipping','off');
slb=sl(bpms);
if isempty(slb)
p5={};
else
p5={};
ampl=0.015*tlim; % BPMs
amplx=0.005*slim;
[xplot,yplot]=setxpl(slb,ones(1,sum(bpms)),[-amplx;0;amplx;0;-amplx],[0;-ampl;0;ampl;0]);
p5=patch(xplot,yplot,[0 0.5 0],'DisplayName','BPM');
end

if any(labs)
Expand All @@ -98,10 +92,7 @@
args={'Label',text(slabs,-0.03*tlim*ones(size(slabs)),vlabs,'Rotation',90,...
'Interpreter','none','FontUnits','normalized','FontSize',0.025,...
'HorizontalAlignment','right')};
else
args={};
end
if any(indx)
elseif any(indx)
sindex=sl(indx)+0.5*ll(indx);
iiok=1:length(rok);
vlabs=cellfun(@(el) el,num2cell(iiok(indx)),'UniformOutput',false);
Expand Down
4 changes: 2 additions & 2 deletions atmat/atplot/xplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
% Split the ring
elmlength=findspos(ring(el1:el2-1),el2-el1+1)/npts;
r2=cellfun(@splitelem,ring(el1:el2-1),'UniformOutput',false);
splitring=cat(1,ring(1:el1-1),r2{:},ring(el2:elt0));
splitring=cat(1,ring(1:el1-1,1),r2{:},ring(el2:elt0,1));
plrange=el1:el2+length(splitring)-elt0;

[s,outp]=plotfun(splitring,curve.dpp,plotargs{:},dpargs{:});
Expand All @@ -53,7 +53,7 @@
ylabel(ax2(1),outp(1).axislabel);
ylabel(ax2(2),outp(2).axislabel);
linkaxes([ax2(1) ax2(2)],'x');% allows zoom on both right and left plots
elseif numel(outp) == 1
elseif isscalar(outp)
curve.left=plot(ax,s(plrange),outp(1).values(plrange,:));
curve.right=[];
ylabel(ax,outp(1).axislabel);
Expand Down

0 comments on commit 268994f

Please sign in to comment.