Home > pubtools > LatticeTuningFunctions > errors > wave > atsetwaveerrors.m

atsetwaveerrors

PURPOSE ^

function rerr=atsetwaveerrors(...

SYNOPSIS ^

function rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,type)

DESCRIPTION ^

function rerr=atsetwaveerrors(...
 rerr, lattice
 magindex, indexes of magnts to set errors
 indBPM,  index of bpm to mode reference using offsets
 W, wave length
 A, amplitude
 type)

 Set Error wave

 is magindex is a cellarray, then also type, W and A must be. This will be
 applied summing.

 if W and A are vectors the resulting sinusoids are summed. 
 
 type may be: x, y, s, psi, theta, phi, bpm'
              x.y, x.y.psi, x.y.s.psi,
              x.y.s.psi.theta.phi'

see also: setANYshift setDSerr setTiltAbout seterrorwave

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,type)
0002 %function rerr=atsetwaveerrors(...
0003 % rerr, lattice
0004 % magindex, indexes of magnts to set errors
0005 % indBPM,  index of bpm to mode reference using offsets
0006 % W, wave length
0007 % A, amplitude
0008 % type)
0009 %
0010 % Set Error wave
0011 %
0012 % is magindex is a cellarray, then also type, W and A must be. This will be
0013 % applied summing.
0014 %
0015 % if W and A are vectors the resulting sinusoids are summed.
0016 %
0017 % type may be: x, y, s, psi, theta, phi, bpm'
0018 %              x.y, x.y.psi, x.y.s.psi,
0019 %              x.y.s.psi.theta.phi'
0020 %
0021 %see also: setANYshift setDSerr setTiltAbout seterrorwave
0022 
0023 if iscell(magindex)
0024     
0025     if length(magindex)~=length(W) || length(magindex)~=length(A) || length(magindex)~=length(type)
0026         error('magindex, A, W, type ,must be cell array of the same length, or numeric.')
0027     end
0028     
0029     % loop magindex to apply errors
0030     for im=1:length(magindex)
0031         
0032        disp([...
0033             'magindex ' num2str(im)...
0034             ', type:' type{im}...
0035             ', A:' num2str(A{im}(1)) ' ... ' num2str(A{im}(end))...
0036             ', W: ' num2str(W{im}(1)) ' ... ' num2str(W{im}(end))]...
0037             );
0038         
0039         rerr=atsetwaveerrors(...
0040             rerr,...
0041             magindex{im},...
0042             indBPM,...
0043             W{im},...
0044             A{im},...
0045             type{im});
0046     end
0047     
0048     
0049 else
0050     
0051     % set error wave to zero if no error existing
0052     [X0,Y0,S0,T0,R0,P0,bpmerr]=GetExistingErrors(rerr,magindex);
0053     
0054     if (std(X0)==0 && std(Y0)==0)
0055         % sets all field of T1 to 0
0056         errfun=@(r,po,er)setANYshift(r,po,1:6,er);
0057         rerr=seterrorwave(rerr,magindex,errfun,1,0);
0058     end
0059     
0060     % set error torequired amplitude and wavelength
0061     switch type
0062         case 'x'
0063             
0064             disp('X error');
0065             
0066             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets X errors
0067             rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0068             
0069             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets X bpm errors
0070             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0071         case 'y'
0072             
0073             disp('Y error');
0074             
0075             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0076             rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0077             
0078             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0079             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0080             
0081         case 's' % longitudinal displacement
0082             
0083             disp('S error');
0084             
0085             errfun=@(r,po,er)setDSerr(r,po,er); % sets Y errors
0086             rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0087             
0088         case 'phi' % about x
0089             
0090             disp('phi error');
0091             
0092             errfun=@(r,po,er)setTiltAbout(r,po,'x',er); % sets Y errors
0093             rerr=seterrorwave(rerr,magindex,errfun,W,A,R0);
0094             
0095         case 'theta' % about y
0096             
0097             disp('theta error');
0098             
0099             errfun=@(r,po,er)setTiltAbout(r,po,'y',er); % sets Y errors
0100             rerr=seterrorwave(rerr,magindex,errfun,W,A,P0);
0101             
0102         case 'psi' % about s
0103             
0104             disp('s-asix rotation error');
0105             
0106             errfun=@(r,po,er)setTiltAbout(r,po,'s',er); % sets Y errors
0107             rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0108             
0109             %  errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets Y bpm errors
0110             %  rerr=seterrorwave(rerr,indBPM,errfun,W,-A);
0111             
0112         case 'bpm'
0113             
0114             % bpm
0115             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0116             % rerr=seterrorwave(rerr,indBPM,errfun,W,-A);
0117             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0118             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0119             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0120             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0121             
0122         case 'x.y.s.psi'
0123             disp('x,y,s misal, bpm and s-asix rotation error (psi only, no phi and theta)');
0124             
0125             % rotation
0126             errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er); % sets rotation about s
0127             rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0128             
0129             % alignment
0130             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0131             rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0132             
0133             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0134             rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0135             
0136             errfun=@(r,po,er)setDSerr(r,po,er); % sets S errors
0137             rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0138             
0139             % bpm
0140             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0141             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0142             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0143             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0144             
0145         case 'x.y.psi'
0146             disp('x,y misal, bpm and s-asix rotation error (psi only, no phi and theta)');
0147             
0148             % rotation
0149             errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er); % sets rotation about s
0150             rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0151             
0152             % alignment
0153             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0154             rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0155             
0156             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0157             rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0158             
0159             % bpm
0160             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0161             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0162             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0163             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0164             
0165         case 'x.y'
0166             disp('x,y misal, bpm ');
0167             
0168             % alignment
0169             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0170             rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0171             
0172             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0173             rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0174             
0175             % bpm
0176             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0177             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0178             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0179             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0180             
0181         case 'x.y.s.psi.theta.phi'
0182             disp('x,y,s misal, bpm and rotation errors (psi, phi and theta)');
0183             
0184             % rotation
0185             errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er); % sets rotation about s
0186             rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0187             
0188             errfun=@(r,po,er)setTiltAbout(r,po,'y',er); % sets rotation about Y
0189             rerr=seterrorwave(rerr,magindex,errfun,W,A,P0);
0190             
0191             errfun=@(r,po,er)setTiltAbout(r,po,'x',er); % sets rotation about X
0192             rerr=seterrorwave(rerr,magindex,errfun,W,A,R0);
0193             
0194             % alignment
0195             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0196             rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0197             
0198             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0199             rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0200             
0201             errfun=@(r,po,er)setDSerr(r,po,er); % sets S errors
0202             rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0203             
0204             % bpm
0205             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0206             % rerr=seterrorwave(rerr,indBPM,errfun,W,-A);
0207             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0208             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0209             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0210             rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0211             
0212         case 'gx'
0213             
0214             disp('girder X error');
0215             
0216             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'x');
0217             rerr=UniformGirderErrors(rerr);
0218             
0219         case 'gy'
0220             
0221             disp('girder Y error');
0222             
0223             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'y');
0224             rerr=UniformGirderErrors(rerr);
0225             
0226         case 'gpsi'
0227             
0228             disp('girder PSI error');
0229             
0230             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'psi');
0231             rerr=UniformGirderErrors(rerr);
0232             
0233         case 'gx.gy'
0234             
0235             disp('girder X Y error');
0236             
0237             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'x.y');
0238             rerr=UniformGirderErrors(rerr);
0239             
0240         case 'gx.gy.gpsi'
0241             disp('girder X Y PSI error');
0242             
0243             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'x.y.psi');
0244             rerr=UniformGirderErrors(rerr);
0245             
0246         case 'gx.gy.gpsi.x.y.psi'
0247             
0248             disp('girder wave and individual rand mag. X Y PSI error');
0249             
0250             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'x.y.psi');
0251             rerr=UniformGirderErrors(rerr);
0252             
0253             % get errors
0254             [X,Y,T]=GetMisalignments(rerr,magindex);
0255             
0256             seed=1;
0257             nsig=2;
0258             disp(['Girder wave amplitude: ' num2str(A*1e6) ' um'])
0259             betweengird=max(abs(diff(X)));
0260             disp(['Max distance between two adjacent girders: ' num2str(betweengird*1e6) ' um'])
0261             Ar=betweengird/sqrt(2)/2;% get distance between 2 girders
0262             disp(['Random errors max amplitude: ' num2str(Ar*1e6) ' um'])
0263             Ar=Ar/nsig; 
0264             % rotation
0265             errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er); % sets rotation about s
0266             rerr=seterrorrand(rerr,magindex,errfun,seed,Ar,nsig,T);
0267             
0268             % alignment
0269             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0270             rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,X);
0271             
0272             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0273             rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,Y);
0274             %uniform errors in sliced magnets
0275             rerr=UniformMagGroupsErrors(rerr);
0276             
0277         case 'gx.gy.x.y'
0278             
0279             disp('girder wave and individual rand mag. X Y error');
0280             
0281             rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,'x.y');
0282             rerr=UniformGirderErrors(rerr);
0283             
0284             % get errors
0285             [X,Y,T]=GetMisalignments(rerr,magindex);
0286             
0287             seed=1;
0288             nsig=2;
0289             disp(['Girder wave amplitude: ' num2str(A*1e6) ' um'])
0290             betweengird=max(abs(diff(X)));
0291             disp(['Max distance between two adjacent girders: ' num2str(betweengird*1e6) ' um'])
0292             Ar=betweengird/sqrt(2)/2;% get distance between 2 girders
0293             disp(['Random errors max amplitude: ' num2str(Ar*1e6) ' um'])
0294             Ar=Ar/nsig; 
0295            
0296             % alignment
0297             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0298             rerr=seterrorrand(rerr,magindex,errfun,seed,Ar,nsig,X);
0299             
0300             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0301             rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,Y);
0302             %uniform errors in sliced magnets
0303             rerr=UniformMagGroupsErrors(rerr);
0304               
0305         otherwise
0306             disp('type may be: x, y, s, psi, theta, phi, bpm');
0307             disp('             x.y, x.y.psi, x.y.s.psi, x.y.s.psi.theta.phi');
0308             disp('             gx, gy, gx.gy, gx.gy.gpsi,gx.gy.x.y, gx.gy.gpsi.x.y.psi');
0309     end
0310     
0311 end
0312 
0313 return

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005