Commit 1cbf1a5f authored by Simone Liuzzo's avatar Simone Liuzzo
Browse files

also large tune change ok (with some betabeating), fixed quadrupole fringe merge of magnet

parent 3305c783
......@@ -156,6 +156,12 @@ r=[r(1:cellstartindex-1);...
end
function r=funUnbQF4(r,v,pb0,indqf4)
r=atsetfieldvalues(r,indqf4([1,2]),'PolynomB',{1,2},pb0([1 2])+v(1));
r=atsetfieldvalues(r,indqf4([3,4]),'PolynomB',{1,2},pb0([3,4])-v(1));
end
function [rok,d]=matchSurveyml(r,r0,r0sb,BndToChange,BndToChange2,BndToChange3,ploton,verbose)
% function matchSurvey()
......
......@@ -196,7 +196,7 @@ Constr(excludeconstr)=[];
%% execute least square fit
arcm=arc;
arcm=atmatch(arcm,Variab,Constr,10^-9,300,verb,@lsqnonlin,twiin);%,'fminsearch');%
arcm=atmatch(arcm,Variab,Constr,10^-9,500,verb,@lsqnonlin,twiin);%,'fminsearch');%
%arcm=atmatch(arcm,Variab,Constr,10^-10,1000,verb,@fminsearch,twiin);%,'fminsearch');%
%arcm=atmatch(arcm,Variab,Constr,10^-15,100,verb,@lsqnonlin,twiin);%,'fminsearch');%
......
......@@ -136,6 +136,12 @@ splitdq=[false false false];
L=atgetfieldvalues(arc,indsf(1:2:end),'Length');
arc=atsetfieldvalues(arc,indsf(1:2:end),'Length',L*2);
exfield=exitfields();
for ii=1:2:length(indsf)
[exitf,~]=mvfield(struct(),arc{indsf(ii+1)},exfield); % extract exit fields
arc{indsf(ii)}=mvfield(arc{indsf(ii)},exitf); % Set back exit fields
end
bendind=atgetcells(arc(indsf),'BendingAngle');
if ~isempty(find(bendind,1))
indsf=indsf(bendind);
......@@ -420,7 +426,7 @@ rb0=rb;
id2pw=[1,5,7,14,25,29,31]; id2pwstandard=[1,5,7,25,31];
idsb=[2,8,16,20,26,28,30,32]; idsbstandard=[2,8,20,26,28,32];
idcant = sort([id2pw,idsb]);
idcant = sort([id2pw,idsb]);
tpwarc=[];
sbarc=[];
......@@ -436,7 +442,7 @@ if match2PW || matchSB
for id=1:length(idcant)
if verbose, disp(['Match cell ' num2str(idcant(id)) '']); end
idnum=idcant(id);
% assign relevant dipole fields to rb
[cellstartindexs,cellendindexs]=ebs.getcellstartend(rb,idnum);
seldip=(dipBM<cellendindexs & dipBM>cellstartindexs);
......@@ -458,8 +464,8 @@ if match2PW || matchSB
twimid=twi(centind);
twisf=twi(sfaeind);
% get arc to match and relevant locations from
% get arc to match and relevant locations from
%arc=ra(cellstartindexa(id):cellendindexa(id));
arc=rb(cellstartindex(id):cellendindex(id));
sfaeind=find(atgetcells(arc,'FamName','DR_10','DR_35'),2,'last')+1;
......@@ -487,62 +493,90 @@ if match2PW || matchSB
arc=copyquadK(sbarc,arc,famnamesi); % ra ring with arcA quad K in all cells
end
% match as transfer line
arc=ebs.matching.arcopen(...
arc,...
twiin,twiend,...
twisf,...
twimid,...
sfaeind,...
centind,...
excludequad,...
excludeconstr,...
true);
%save 2pw arc ,matched
if ~isempty(tpwarc) & ismember(idcan(id),id2pwstandard)
tpwarc=arc;
end
%save sb arc ,matched
if ~isempty(sbarc) & ismember(idcan(id),idsbstandard)
sbarc=arc;
end
if verbose
figure('name',['cell ' num2str(idcant(id))]); atplot(arc,'inputtwiss',twiin);
end
% rbm=rb;
% if ismember(idcant(id),id2pwstandard) % if 2PW
%
% [rb,arc]=ebs.matching.TwoPoleWigglerOptics(rb,r0,idcant(id));
% %save 2pw arc ,matched
% if ~isempty(tpwarc) & ismember(idcan(id),id2pwstandard)
% tpwarc=arc;
% end
%
% elseif ismember(idcant(id),idsbstandard) % if SB
%
% [rb,arc]=ebs.matching.ShortBendOptics(rb,r0,idcant(id));
%
% %save sb arc ,matched
% if ~isempty(sbarc) & ismember(idcan(id),idsbstandard)
% sbarc=arc;
% end
%
% else % canted + BM
%
% match as transfer line
arc=ebs.matching.arcopen(...
arc,...
twiin,twiend,...
twisf,...
twimid,...
sfaeind,...
centind,...
excludequad,...
excludeconstr,...
true);
% save 2pw arc ,matched
if ~isempty(tpwarc) & ismember(idcan(id),id2pwstandard)
tpwarc=arc;
end
% save sb arc ,matched
if ~isempty(sbarc) & ismember(idcan(id),idsbstandard)
sbarc=arc;
end
% reconstruct lattice with new cell
if verbose, disp(['include cell ' num2str(idcant(id)) ' in final lattice']); end
rb=[rb(1:cellstartindex(id)-1);...
arc;... % arcwith 2PW
rb(cellendindex(id)+1:end)];
% end
if verbose
figure('name',['cell ' num2str(idcant(id))]); atplot(arc,'inputtwiss',twiin);
figure('name',['cell B0 ' num2str(idcant(id))]); atplot(arc,'inputtwiss',twiin,@plotB0curlyh);
figure('name',['ring ' num2str(idcant(id))]); atplot(rb);
end
end
end
rb2pw=rb;
%% reconstruct lattice
% get matched quadrupole gradients
qpib=atgetcells(rb,'Class','Quadrupole');
qpk=atgetfieldvalues(rb,qpib,'PolynomB',{1,2});
% get matched dipole-quadrupole gradients
dqpib=atgetcells(rb,'FamName','DQ\w*');
dqpk=atgetfieldvalues(rb,dqpib,'PolynomB',{1,2});
% set rm gradients in r, to garantee correct ring size and elements.
qpi=atgetcells(r,'Class','Quadrupole');
rM=atsetfieldvalues(r,qpi,'PolynomB',{1,2},qpk);
dqpi=atgetcells(rM,'FamName','DQ\w*');
rM=atsetfieldvalues(rM,dqpi,'PolynomB',{1,2},dqpk);
% qpib=atgetcells(rb,'Class','Quadrupole') ;
% qpk=atgetfieldvalues(rb,qpib,'PolynomB',{1,2});
%
% % get matched quadrupole gradients
% q6ib=atgetcells(rb,'FamName','QF6D\w*') ;
% q6k=atgetfieldvalues(rb,q6ib,'PolynomB',{1,2});
%
% % get matched dipole-quadrupole gradients
% dqpib=atgetcells(rb,'FamName','DQ\w*');
% dqpk=atgetfieldvalues(rb,dqpib,'PolynomB',{1,2});
%
% % set rm gradients in r, to garantee correct ring size and elements.
% qpi=atgetcells(r,'Class','Quadrupole');
% rM=atsetfieldvalues(r,qpi,'PolynomB',{1,2},qpk);
% q6pi=atgetcells(rM,'FamName','QF6D\w*');
% rM=atsetfieldvalues(rM,q6pi,'PolynomB',{1,2},q6k);
% dqpi=atgetcells(rM,'FamName','DQ\w*');
% rM=atsetfieldvalues(rM,dqpi,'PolynomB',{1,2},dqpk);
% add back pinholes markers
rbmod = ebs.model(rM);
rbmod = ebs.model(rb);
rM = rbmod.ring;
......
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