Home > pubtools > LatticeTuningFunctions > errors > random > atsetrandomerrors.m

atsetrandomerrors

PURPOSE ^

function rerr=atsetrandomerrors(...

SYNOPSIS ^

function rerr=atsetrandomerrors(rerr,magindex,indBPM,seed,sigma,nsig,type)

DESCRIPTION ^

function rerr=atsetrandomerrors(...
 rerr, %lattice
 magindex, %indexes of magnts to set errors
 indBPM,  %index of bpm to mode reference using offsets
  seed    % error seed
  sigma   % number of sigma for truncation
 type)    % type of error (see list)

 Set random errors for a given seed.
 Considers also magnets grouped by MagNum field and
 girders specified by GS and GE markers.
 BPMs are moved with girders.

 If magindx is a cellarray of index vectors, 
 then also sigma and type must be and they will be applyed summing. 
 
 type may be: x, y, s, psi (roll), theta (yaw), phi (pitch), (individual magnets)
               bpm (bpm.offset)    
               bpm.scale, bpm.read   
              x.y, x.y.psi, x.y.s.psi,
              x.y.s.psi.theta.phi
              gx, gy, gpsi, gtheta, gphi,  gx.gy,             (girder)
              gx.gy.gpsi, gx.gy.gpsi.x.y.psi
              dpb1, dpb2, dpb3, dpb4           (PolynomB random error)


see also: atsetshift atset_s_shift setTiltAbout seterrorrand
UniformMagGroupsErrors UniformGirderErrors ApplyErrorWave

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rerr=atsetrandomerrors(...
0002     rerr,...
0003     magindex,...
0004     indBPM,...
0005     seed,...
0006     sigma,...
0007     nsig,...
0008     type)
0009 %function rerr=atsetrandomerrors(...
0010 % rerr, %lattice
0011 % magindex, %indexes of magnts to set errors
0012 % indBPM,  %index of bpm to mode reference using offsets
0013 %  seed    % error seed
0014 %  sigma   % number of sigma for truncation
0015 % type)    % type of error (see list)
0016 %
0017 % Set random errors for a given seed.
0018 % Considers also magnets grouped by MagNum field and
0019 % girders specified by GS and GE markers.
0020 % BPMs are moved with girders.
0021 %
0022 % If magindx is a cellarray of index vectors,
0023 % then also sigma and type must be and they will be applyed summing.
0024 %
0025 % type may be: x, y, s, psi (roll), theta (yaw), phi (pitch), (individual magnets)
0026 %               bpm (bpm.offset)
0027 %               bpm.scale, bpm.read
0028 %              x.y, x.y.psi, x.y.s.psi,
0029 %              x.y.s.psi.theta.phi
0030 %              gx, gy, gpsi, gtheta, gphi,  gx.gy,             (girder)
0031 %              gx.gy.gpsi, gx.gy.gpsi.x.y.psi
0032 %              dpb1, dpb2, dpb3, dpb4           (PolynomB random error)
0033 %
0034 %
0035 %see also: atsetshift atset_s_shift setTiltAbout seterrorrand
0036 %UniformMagGroupsErrors UniformGirderErrors ApplyErrorWave
0037 
0038 r0=rerr; % store nominal lattice at this stage
0039 
0040 if iscell(magindex)% if list of errors is given
0041     if length(magindex)~=length(sigma) || length(magindex)~=length(type)
0042         error('magindex, sigma, type, must be cell array of the same length, or numeric.')
0043     end
0044     
0045     % loop magindex to apply errors
0046     for im=1:length(magindex)
0047         
0048         if im>0, seed=0; end; % do not change or reset seed anymore (seterrorrand)
0049         
0050         disp([...
0051             'magindex ' num2str(im)...
0052             ', type:' type{im}...
0053             ', sig:' num2str(sigma{im})...
0054             ', seed: ' num2str(seed)]...
0055             );
0056         
0057         rerr=atsetrandomerrors(...
0058             rerr,...
0059             magindex{im},...
0060             indBPM,...
0061             seed,...
0062             sigma{im},...
0063             nsig,...
0064             type{im});
0065         
0066     end
0067     
0068 else
0069     
0070     % set error wave to zero if no error existing
0071     [X0,Y0,S0,T0,R0,P0,bpm0]=GetExistingErrors(rerr,magindex);
0072     
0073     if isnan(Y0)
0074     disp('NAN Y0!')
0075     end
0076     
0077     % initialize errors if not inizialized
0078     %if (std(X0)==0 && std(Y0)==0)
0079     if any(X0==0 & Y0==0) 
0080         % sets all field of T1 to 0
0081         errfun=@(r,po,er)setANYshift(r,po,1:6,er);
0082         rerr=seterrorrand(rerr,magindex(X0==0 & Y0==0),errfun,0,0,nsig);
0083     end
0084     
0085     % set error to required amplitude and wavelength
0086     switch type
0087         case 'zero'
0088             disp('setting all errors to 0');
0089             
0090             % sets all field of T1 to 0
0091             errfun=@(r,po,er)setANYshift(r,po,1:6,er);
0092             rerr=seterrorrand(rerr,magindex,errfun,1,0,nsig);
0093             errfun=@(r,po,er)atset_s_shift(r,po,er); % sets DS errors to zero
0094             rerr=seterrorrand(rerr,magindex,errfun,0,0,nsig);
0095             
0096             % rotation
0097             errfun=@(r,po,er)atsettiltdipole(r,po,er); % sets rotation about s
0098             rerr=seterrorrand(rerr,magindex,errfun,0,0,nsig);
0099             errfun=@(r,po,er)setTiltAbout(r,po,'y',er); % sets rotation about Y
0100             rerr=seterrorrand(rerr,magindex,errfun,0,0,nsig);
0101             errfun=@(r,po,er)setTiltAbout(r,po,'x',er); % sets rotation about X
0102             rerr=seterrorrand(rerr,magindex,errfun,0,0,nsig);
0103             
0104             % bpm
0105             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm Offset errors
0106             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0107             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0108             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0109             errfun=@(r,po,er)setcellstruct(r,'Scale',po,er,1,1); % sets x bpm Scale errors
0110             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0111             errfun=@(r,po,er)setcellstruct(r,'Scale',po,er,1,2); % sets Y bpm errors
0112             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0113             errfun=@(r,po,er)setcellstruct(r,'Reading',po,er,1,1); % sets x bpm Reading errors
0114             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0115             errfun=@(r,po,er)setcellstruct(r,'Reading',po,er,1,2); % sets Y bpm errors
0116             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0117             errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1,1); % sets x bpm Rotation errors
0118             rerr=seterrorrand(rerr,indBPM,errfun,0,0,nsig);
0119             
0120         case 'dpb1'
0121             
0122             disp('PolynomB(1) error');
0123             rerr=setFieldIntegralError(r0,rerr,magindex,1,nsig,sigma);
0124             
0125         case 'dpb2'
0126             disp('PolynomB(2) error');
0127             
0128             rerr=setFieldIntegralError(r0,rerr,magindex,2,nsig,sigma);
0129             
0130         case 'dpb3'
0131             disp('PolynomB(3) error');
0132             
0133             rerr=setFieldIntegralError(r0,rerr,magindex,3,nsig,sigma);
0134             
0135         case 'dpb4'
0136             disp('PolynomB(4) error');
0137             
0138             rerr=setFieldIntegralError(r0,rerr,magindex,4,nsig,sigma);
0139             
0140         case 'x'
0141             
0142             disp('X error');
0143            
0144             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets X errors
0145             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,X0);
0146             
0147             %uniform errors in sliced magnets
0148             rerr=UniformMagGroupsErrors(rerr);
0149             
0150         case 'y'
0151             
0152             disp('Y error');
0153             
0154             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0155             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,Y0);
0156             %uniform errors in sliced magnets
0157             rerr=UniformMagGroupsErrors(rerr);
0158             
0159         case 's' % longitudinal displacement
0160             
0161             disp('S error');
0162             
0163             errfun=@(r,po,er)atset_s_shift(r,po,er); % sets Y errors
0164             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,S0);
0165             %uniform errors in sliced magnets
0166             rerr=UniformMagGroupsErrors(rerr);
0167             
0168         case 'phi' % about x
0169             
0170             disp('phi error');
0171             
0172             errfun=@(r,po,er)setTiltAbout(r,po,'x',er); % sets Y errors
0173             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,R0);
0174             %uniform errors in sliced magnets
0175             rerr=UniformMagGroupsErrors(rerr);
0176             
0177         case 'theta' % about y
0178             
0179             disp('theta error');
0180             
0181             errfun=@(r,po,er)setTiltAbout(r,po,'y',er); % sets Y errors
0182             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,P0);
0183             %uniform errors in sliced magnets
0184             rerr=UniformMagGroupsErrors(rerr);
0185             
0186         case 'psi' % about s
0187             
0188             disp('s-asix rotation error');
0189             
0190             errfun=@(r,po,er)setTiltAbout(r,po,'s',er); % sets Y errors
0191             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,T0);
0192             %uniform errors in sliced magnets
0193             rerr=UniformMagGroupsErrors(rerr);
0194             
0195         case 'bpm'
0196             
0197             disp('bpm offset error');
0198             % bpm
0199             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0200             % rerr=seterrorrand(rerr,indBPM,errfun,W,-A);
0201           
0202             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0203             rerr=seterrorrand(rerr,indBPM,errfun,seed,-sigma,nsig,bpm0.offsetx);
0204             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0205             rerr=seterrorrand(rerr,indBPM,errfun,seed*0,-sigma,nsig,bpm0.offsety);
0206             
0207          case 'bpm.offset'
0208             
0209             disp('bpm offset error');
0210             % bpm
0211             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0212             % rerr=seterrorrand(rerr,indBPM,errfun,W,-A);
0213           
0214             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1); % sets x bpm errors
0215             rerr=seterrorrand(rerr,indBPM,errfun,seed,-sigma,nsig,bpm0.offsetx);
0216             errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2); % sets Y bpm errors
0217             rerr=seterrorrand(rerr,indBPM,errfun,seed*0,-sigma,nsig,bpm0.offsety);
0218             
0219         case 'bpm.scale'
0220             
0221             disp('bpm scale error (1+...)');
0222             % bpm
0223             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0224             % rerr=seterrorrand(rerr,indBPM,errfun,W,-A);
0225           
0226             errfun=@(r,po,er)setcellstruct(r,'Scale',po,1+er,1,1); % sets x bpm errors
0227             rerr=seterrorrand(rerr,indBPM,errfun,seed,-sigma,nsig,zeros(size(bpm0.offsetx)));
0228             errfun=@(r,po,er)setcellstruct(r,'Scale',po,1+er,1,2); % sets Y bpm errors
0229             rerr=seterrorrand(rerr,indBPM,errfun,seed*0,-sigma,nsig,zeros(size(bpm0.offsety)));
0230             
0231         case 'bpm.read'
0232             
0233             disp('bpm reading error');
0234             % bpm
0235             % errfun=@(r,po,er)setcellstruct(r,'Rotation',po,er,1); % sets psi bpm errors
0236             % rerr=seterrorrand(rerr,indBPM,errfun,W,-A);
0237           
0238             errfun=@(r,po,er)setcellstruct(r,'Reading',po,er,1,1); % sets x bpm errors
0239             rerr=seterrorrand(rerr,indBPM,errfun,seed,-sigma,nsig,zeros(size(bpm0.offsetx)));
0240              
0241         case 'x.y.s.psi'
0242             disp('x,y,s misal, bpm and s-asix rotation error (psi only, no phi and theta)');
0243             
0244             % rotation
0245             errfun=@(r,po,er)atsettiltdipole(r,po,er); % sets rotation about s
0246             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,T0);
0247             
0248             % alignment
0249             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0250             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,X0);
0251             
0252             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0253             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,Y0);
0254             
0255             %uniform errors in sliced magnets
0256             rerr=UniformMagGroupsErrors(rerr);
0257             
0258             errfun=@(r,po,er)atset_s_shift(r,po,er); % sets S errors
0259             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,S0);
0260             
0261             
0262         case 'x.y.psi'
0263             disp('x,y misal, bpm and s-asix rotation error (psi only, no phi and theta)');
0264             
0265             % rotation
0266             errfun=@(r,po,er)atsettiltdipole(r,po,er); % sets rotation about s
0267             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,T0);
0268             
0269             % alignment
0270             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0271             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,X0);
0272             
0273             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0274             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,Y0);
0275             %uniform errors in sliced magnets
0276             rerr=UniformMagGroupsErrors(rerr);
0277             
0278             
0279         case 'x.y'
0280             disp('x,y misal');
0281             
0282             % alignment
0283             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0284             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,X0);
0285             
0286             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0287             rerr=seterrorrand(rerr,magindex,errfun,0,sigma,nsig,Y0);
0288             %uniform errors in sliced magnets
0289             rerr=UniformMagGroupsErrors(rerr);
0290             
0291             
0292         case 'x.y.s.psi.theta.phi'
0293             disp('x,y,s misal, bpm and rotation errors (psi, phi and theta)');
0294             
0295             % rotation
0296             errfun=@(r,po,er)atsettiltdipole(r,po,er); % sets rotation about s
0297             rerr=seterrorrand(rerr,magindex,errfun,seed,sigma,nsig,T0);
0298             
0299             errfun=@(r,po,er)setTiltAbout(r,po,'y',er); % sets rotation about Y
0300             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,R0);
0301             
0302             errfun=@(r,po,er)setTiltAbout(r,po,'x',er); % sets rotation about X
0303             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,P0);
0304             
0305             % alignment
0306             errfun=@(r,po,er)setANYshift(r,po,1,er); % sets x errors
0307             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,X0);
0308             
0309             errfun=@(r,po,er)setANYshift(r,po,3,er); % sets Y errors
0310             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,Y0);
0311             
0312             %uniform errors in sliced magnets before placing s errors
0313             rerr=UniformMagGroupsErrors(rerr);
0314             
0315             errfun=@(r,po,er)atset_s_shift(r,po,er); % sets S errors
0316             rerr=seterrorrand(rerr,magindex,errfun,seed*0,sigma,nsig,S0);
0317             
0318         case 'gx'
0319             
0320             disp('girder X error');
0321             
0322             % set all errors to 0
0323             rZ=atsetrandomerrors(r0,magindex,indBPM,0,0,nsig,'zero'); 
0324 
0325             % assign girder errors on zero err lattice
0326             rgerr=atsetrandomerrors(rZ,magindex,indBPM,seed,sigma,nsig,'x');
0327             [rgerr,mag_gr]=UniformGirderErrors(rgerr); % unifroms all errors!
0328             
0329             % sum errors
0330             magindex=[mag_gr{:}];
0331             rerr=SumErrors(rerr,rgerr,magindex,indBPM);
0332             
0333         case 'gy'
0334            
0335             disp('girder Y error');
0336             
0337             % set all errors to 0
0338             rZ=atsetrandomerrors(r0,magindex,indBPM,0,0,nsig,'zero'); 
0339 
0340             % assign girder errors on zero err lattice
0341             rgerr=atsetrandomerrors(rZ,magindex,indBPM,seed,sigma,nsig,'y');
0342             [rgerr,mag_gr]=UniformGirderErrors(rgerr); % unifroms all errors!
0343             
0344             % sum errors
0345             magindex=[mag_gr{:}];
0346             rerr=SumErrors(rerr,rgerr,magindex,indBPM);
0347             
0348         case 'gpsi'
0349             
0350             disp('girder PSI error');
0351             
0352             % set all errors to 0
0353             rZ=atsetrandomerrors(r0,magindex,indBPM,0,0,nsig,'zero'); 
0354 
0355             % assign girder errors on zero err lattice
0356             rgerr=atsetrandomerrors(rZ,magindex,indBPM,seed,sigma,nsig,'psi');
0357             [rgerr,mag_gr]=UniformGirderErrors(rgerr); % unifroms all errors!
0358             
0359             % get errors on all gider magnets
0360             magindex=[mag_gr{:}];
0361             rerr=SumErrors(rerr,rgerr,magindex,indBPM);
0362         
0363         case 'gtheta'
0364             
0365             disp('girder THETA error');
0366             
0367             % set all errors to 0
0368             rZ=atsetrandomerrors(r0,magindex,indBPM,0,0,nsig,'zero'); 
0369 
0370             % assign girder errors on zero err lattice
0371             rgerr=atsetrandomerrors(rZ,magindex,indBPM,seed,sigma,nsig,'theta');
0372             [rgerr,mag_gr]=UniformGirderErrors(rgerr); % unifroms all errors!
0373             
0374             rgerr=ThetaPhiGirder(rgerr,mag_gr);
0375             
0376             % get errors on all gider magnets
0377             magindex=[mag_gr{:}];
0378             rerr=SumErrors(rerr,rgerr,magindex,indBPM);
0379               
0380         case 'gphi'
0381             disp('girder phi error');
0382             
0383             % set all errors to 0
0384             rZ=atsetrandomerrors(r0,magindex,indBPM,0,0,nsig,'zero'); 
0385 
0386             % assign girder errors on zero err lattice
0387             rgerr=atsetrandomerrors(rZ,magindex,indBPM,seed,sigma,nsig,'phi');
0388             [rgerr,mag_gr]=UniformGirderErrors(rgerr); % unifroms all errors!
0389             
0390             rgerr=ThetaPhiGirder(rgerr,mag_gr);
0391             
0392             % sum errors
0393             magindex=[mag_gr{:}];
0394             rerr=SumErrors(rerr,rgerr,magindex,indBPM);
0395               
0396             
0397         case 'gx.gy'
0398             
0399             disp('girder X Y error');
0400             
0401             rerr=atsetrandomerrors(rerr,magindex,indBPM,seed,sigma,nsig,'gy');
0402             rerr=atsetrandomerrors(rerr,magindex,indBPM,seed+1000,sigma,nsig,'gx');
0403 
0404         case 'gx.gy.gpsi'
0405             disp('girder X Y PSI error');
0406             rerr=atsetrandomerrors(rerr,magindex,indBPM,seed,sigma,nsig,'gx.gy');
0407             rerr=atsetrandomerrors(rerr,magindex,indBPM,seed+2000,sigma,nsig,'gpsi');
0408 
0409         otherwise
0410             disp('type may be: x, y, s, psi, theta, phi, bpm');
0411             disp('             x.y, x.y.psi, x.y.s.psi, x.y.s.psi.theta.phi');
0412             disp('             gx, gy, gpsi, gtheta,gphi, gx.gy, gx.gy.gpsi,');
0413             disp('             dpb1, dpb2, dpb3, dpb4');
0414     end
0415     
0416 %     [Xe,Ye,Se,Te,Re,Pe]=GetExistingErrors(rerr,magindex);
0417 %     disp(['X: ' num2str(std(X0),'%2.2e') ' -> ' num2str(std(Xe),'%2.2e')]);
0418 %     disp(['Y: ' num2str(std(Y0),'%2.2e') ' -> ' num2str(std(Ye),'%2.2e')]);
0419 %     disp(['S: ' num2str(std(S0),'%2.2e') ' -> ' num2str(std(Se),'%2.2e')]);
0420 %     disp(['T: ' num2str(std(T0),'%2.2e') ' -> ' num2str(std(Te),'%2.2e')]);
0421 %     disp(['R: ' num2str(std(R0),'%2.2e') ' -> ' num2str(std(Re),'%2.2e')]);
0422 %     disp(['P: ' num2str(std(P0),'%2.2e') ' -> ' num2str(std(Pe),'%2.2e')]);
0423 
0424 end% if cell
0425 
0426 %rerr=setBpmOffsetOnDipoleRef(rerr);
0427 
0428 return
0429 
0430

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