0001 function ringerr=SetESRFAlgeAlignmentError(ring,algeexcelfile,filenameout,nseeds,fracerr,plotdataALGE)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if nargin<5
0014 fracerr=1;
0015 end
0016
0017 if nargin<6
0018 plotdataALGE=0;
0019 end
0020
0021 globalpos = xlsread(algeexcelfile,'Coords');
0022 x=globalpos(:,1);
0023 y=globalpos(:,2);
0024 z=globalpos(:,3);
0025
0026 ringlength=findspos(ring,length(ring)+1);
0027
0028
0029 s=[cumsum(sqrt(diff(x).^2+diff(y).^2+diff(z).^2)); ringlength];
0030
0031 dR = xlsread(algeexcelfile,'dR')*1e-3;
0032 dL = xlsread(algeexcelfile,'dL')*1e-3;
0033 dZ = xlsread(algeexcelfile,'dZ')*1e-3;
0034
0035
0036 s=[0;s];
0037 dR=[dR(end,:);dR];
0038 dL=[dL(end,:);dL];
0039 dZ=[dZ(end,:);dZ];
0040
0041
0042 slat=findspos(ring,1:length(ring));
0043
0044
0045 celllength=ringlength/32;
0046
0047 slatshift=slat-celllength*4;
0048
0049 [~,indslatsort]=sort(slatshift);
0050
0051 dxlat=interp1(s,dR,slat(indslatsort));
0052 dzlat=interp1(s,dZ,slat(indslatsort));
0053 dslat=interp1(s,dL,slat(indslatsort));
0054
0055
0056 dslat(dslat<0)=0;
0057 dslat(isnan(dslat))=0;
0058 dslat(isinf(dslat))=0;
0059 dxlat(isnan(dxlat))=0;
0060 dxlat(isinf(dxlat))=0;
0061 dzlat(isnan(dzlat))=0;
0062 dzlat(isinf(dzlat))=0;
0063
0064 dslat(end-2:end,1)=dslat(2);
0065 dzlat(end-2:end,1)=dzlat(2);
0066 dxlat(end-2:end,1)=dxlat(2);
0067
0068 if nargin<4
0069 nseeds=1;
0070 end
0071
0072 if find(nseeds>size(dR,2))
0073 nseeds=size(dR,2);
0074 end
0075
0076 indbpm=unique([find(atgetcells(ring,'Class','Monitor'))' find(atgetcells(ring,'BetaCode','PU'))']);
0077
0078
0079 ierr=nseeds;
0080
0081 ringerr=ring;
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 ringerr=atsetshift(ringerr,1:length(ring),dxlat(:,ierr)*fracerr,dzlat(:,ierr)*fracerr);
0102
0103 if ~isempty(filenameout)
0104 save(['ALGEErrorsLattice_' num2str(ierr) '_' filenameout],'ringerr');
0105 end
0106
0107
0108
0109
0110
0111 if plotdataALGE
0112
0113 figure;plot3(x,y,z);
0114 zlabel('z [m]');xlabel('x [m]');ylabel('y [m]');
0115 saveas(gca,['globalpos3d' filenameout '.fig']);
0116 saveas(gca,['globalpos3d' filenameout '.jpg']);
0117
0118 figure;plot(s,dR,'-');xlabel('s [m]');ylabel('dR [m]')
0119 saveas(gca,['dRdeviation' filenameout '.fig']);
0120 saveas(gca,['dRdeviation' filenameout '.jpg']);
0121 figure;plot(s,dZ,'-');xlabel('s [m]');ylabel('dZ [m]')
0122 saveas(gca,['dZdeviation' filenameout '.fig']);
0123 saveas(gca,['dZdeviation' filenameout '.jpg']);
0124 figure;plot(s,dL,'-');xlabel('s [m]');ylabel('dL [m]')
0125 saveas(gca,['dLdeviation' filenameout '.fig']);
0126 saveas(gca,['dLdeviation' filenameout '.jpg']);
0127
0128 [~,r,z]=cart2pol(x,y,z);
0129 dR_=dR(2:end,:);
0130 dL_=dL(2:end,:);
0131 dZ_=dZ(2:end,:);
0132
0133 [dX,dY]=pol2cart(dR_,dL_.*repmat(r,1,50));
0134
0135
0136 figure;
0137 plot3(repmat(x,1,50)+dX,repmat(y,1,50)+dY,repmat(0*z,1,50)+dZ_,'-');
0138 hold on;
0139 plot3(x,y,z,'r-','LineWidth',3);
0140 zlabel('z [m]');xlabel('x [m]');ylabel('y [m]');
0141 saveas(gca,['globalpos3dAndErrors' filenameout '.fig']);
0142 saveas(gca,['globalpos3dAndErrors' filenameout '.jpg']);
0143
0144
0145 figure;
0146 plot3(dR',dL',dZ','.');
0147 xlabel('dR');ylabel('dL');zlabel('dZ')
0148 saveas(gca,['errorclouds3D' filenameout '.fig']);
0149 saveas(gca,['errorclouds3D' filenameout '.jpg']);
0150
0151 end
0152
0153
0154 return