takes the last two correctors to match the orbit and angle trajectory at the first BPM.
0001 function rmatch=MatchLast2CorForFirstBPM(ring,inCOD,indBPM,indHCor,indVCor) 0002 %takes the last two correctors to match the orbit and angle trajectory at 0003 %the first BPM. 0004 0005 % get trajectory 0006 [t0]=findtrajectory6Err(ring,indBPM,inCOD); 0007 0008 % trn4=linepass([ring; ring; ring; ring],[inCOD(1:4),0,0]',[indBPM length(ring)+indBPM length(ring)*2+indBPM length(ring)*3+indBPM]); 0009 % figure('name','initial matched 4 turn'); plot(trn4');ylim([-3e-3 3e-3]); 0010 % export_fig('InitialTrajectory4turnRF.jpg') 0011 0012 %figure('name','initial'); plot(t0');ylim([-3e-3 3e-3]); 0013 0014 % match angle and position at BPM 1 of the un rotated lattice ( BPM n of the rotated 0015 % lattice) to be identical to those of the initial trajectory 0016 h1=atVariableBuilder(ring,indHCor(end-1),{'PolynomB',{1,1}}); 0017 h2=atVariableBuilder(ring,indHCor(end),{'PolynomB',{1,1}}); 0018 v1=atVariableBuilder(ring,indVCor(end-1),{'PolynomA',{1,1}}); 0019 v2=atVariableBuilder(ring,indVCor(end),{'PolynomA',{1,1}}); 0020 Variab=[h1 h2 v1 v2]; 0021 0022 bpmmatchind=1; 0023 0024 Constr=struct(... 0025 'Fun',@(r,~,~)transpose(findtrajectory6Err([r;r],length(r)+indBPM(bpmmatchind),inCOD)),... % bpmmatchind BPM of second turn 0026 'Weight',ones(6,1)',... 0027 'RefPoints',[1],... 0028 'Min',t0(:,bpmmatchind)',... 0029 'Max',t0(:,bpmmatchind)'); 0030 0031 % input optics and COD 0032 [intwi,~,~]=atlinopt(ring,0,1); 0033 intwi.ClosedOrbit=inCOD(1:4); 0034 0035 [rmatch]=atmatch(... 0036 ring,Variab,Constr,1e-12,100,0,@lsqnonlin,intwi); 0037 0038 [tm]=findtrajectory6Err(rmatch,indBPM,inCOD); 0039 %figure('name','rotated matched'); plot(tm');ylim([-3e-3 3e-3]); 0040 0041 0042 % % check multi turns. 0043 % ring=rmatch; 0044 % trn4=linepass([ring; ring; ring; ring],[inCOD(1:4),0,0]',[indBPM length(ring)+indBPM length(ring)*2+indBPM length(ring)*3+indBPM]); 0045 % figure('name','initial matched 4 turn'); plot(trn4');ylim([-3e-3 3e-3]); 0046 % export_fig('MatchedTrajectory4turnRF.jpg') 0047 0048 % % check that now a COD exists. 0049 % ring=rmatch; 0050 %findorbit4Err(ring,0,indBPM,[inCOD 0 0]'); 0051 0052 % % 6D ok if cavity is correctly set before setting errors in the lattice 0053 %findorbit6Err(atsetRFCavity(ring,6.5e6,0,992,0.0),indBPM,[inCOD 0 0]'); 0054 0055 return