0001 function rerr=atsetwaveerrors(rerr,magindex,indBPM,W,A,type)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
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
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
0052 [X0,Y0,S0,T0,R0,P0,bpmerr]=GetExistingErrors(rerr,magindex);
0053
0054 if (std(X0)==0 && std(Y0)==0)
0055
0056 errfun=@(r,po,er)setANYshift(r,po,1:6,er);
0057 rerr=seterrorwave(rerr,magindex,errfun,1,0);
0058 end
0059
0060
0061 switch type
0062 case 'x'
0063
0064 disp('X error');
0065
0066 errfun=@(r,po,er)setANYshift(r,po,1,er);
0067 rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0068
0069 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
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);
0076 rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0077
0078 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
0079 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0080
0081 case 's'
0082
0083 disp('S error');
0084
0085 errfun=@(r,po,er)setDSerr(r,po,er);
0086 rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0087
0088 case 'phi'
0089
0090 disp('phi error');
0091
0092 errfun=@(r,po,er)setTiltAbout(r,po,'x',er);
0093 rerr=seterrorwave(rerr,magindex,errfun,W,A,R0);
0094
0095 case 'theta'
0096
0097 disp('theta error');
0098
0099 errfun=@(r,po,er)setTiltAbout(r,po,'y',er);
0100 rerr=seterrorwave(rerr,magindex,errfun,W,A,P0);
0101
0102 case 'psi'
0103
0104 disp('s-asix rotation error');
0105
0106 errfun=@(r,po,er)setTiltAbout(r,po,'s',er);
0107 rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0108
0109
0110
0111
0112 case 'bpm'
0113
0114
0115
0116
0117 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
0118 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0119 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
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
0126 errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er);
0127 rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0128
0129
0130 errfun=@(r,po,er)setANYshift(r,po,1,er);
0131 rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0132
0133 errfun=@(r,po,er)setANYshift(r,po,3,er);
0134 rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0135
0136 errfun=@(r,po,er)setDSerr(r,po,er);
0137 rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0138
0139
0140 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
0141 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0142 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
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
0149 errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er);
0150 rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0151
0152
0153 errfun=@(r,po,er)setANYshift(r,po,1,er);
0154 rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0155
0156 errfun=@(r,po,er)setANYshift(r,po,3,er);
0157 rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0158
0159
0160 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
0161 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0162 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
0163 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsety);
0164
0165 case 'x.y'
0166 disp('x,y misal, bpm ');
0167
0168
0169 errfun=@(r,po,er)setANYshift(r,po,1,er);
0170 rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0171
0172 errfun=@(r,po,er)setANYshift(r,po,3,er);
0173 rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0174
0175
0176 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
0177 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0178 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
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
0185 errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er);
0186 rerr=seterrorwave(rerr,magindex,errfun,W,A,T0);
0187
0188 errfun=@(r,po,er)setTiltAbout(r,po,'y',er);
0189 rerr=seterrorwave(rerr,magindex,errfun,W,A,P0);
0190
0191 errfun=@(r,po,er)setTiltAbout(r,po,'x',er);
0192 rerr=seterrorwave(rerr,magindex,errfun,W,A,R0);
0193
0194
0195 errfun=@(r,po,er)setANYshift(r,po,1,er);
0196 rerr=seterrorwave(rerr,magindex,errfun,W,A,X0);
0197
0198 errfun=@(r,po,er)setANYshift(r,po,3,er);
0199 rerr=seterrorwave(rerr,magindex,errfun,W,A,Y0);
0200
0201 errfun=@(r,po,er)setDSerr(r,po,er);
0202 rerr=seterrorwave(rerr,magindex,errfun,W,A,S0);
0203
0204
0205
0206
0207 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,1);
0208 rerr=seterrorwave(rerr,indBPM,errfun,W,-A,bpmerr.offsetx);
0209 errfun=@(r,po,er)setcellstruct(r,'Offset',po,er,1,2);
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
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;
0262 disp(['Random errors max amplitude: ' num2str(Ar*1e6) ' um'])
0263 Ar=Ar/nsig;
0264
0265 errfun=@(r,po,er)settilt_THERING_Dipole(r,po,er);
0266 rerr=seterrorrand(rerr,magindex,errfun,seed,Ar,nsig,T);
0267
0268
0269 errfun=@(r,po,er)setANYshift(r,po,1,er);
0270 rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,X);
0271
0272 errfun=@(r,po,er)setANYshift(r,po,3,er);
0273 rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,Y);
0274
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
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;
0293 disp(['Random errors max amplitude: ' num2str(Ar*1e6) ' um'])
0294 Ar=Ar/nsig;
0295
0296
0297 errfun=@(r,po,er)setANYshift(r,po,1,er);
0298 rerr=seterrorrand(rerr,magindex,errfun,seed,Ar,nsig,X);
0299
0300 errfun=@(r,po,er)setANYshift(r,po,3,er);
0301 rerr=seterrorrand(rerr,magindex,errfun,seed*0,Ar,nsig,Y);
0302
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