Home > pubtools > LatticeTuningFunctions > errors > Survey > SetESRFAlgeAlignmentError.m

SetESRFAlgeAlignmentError

PURPOSE ^

function SetESRFAlgeAlignmentError(...

SYNOPSIS ^

function ringerr=SetESRFAlgeAlignmentError(ring,algeexcelfile,filenameout,nseeds,fracerr,plotdataALGE)

DESCRIPTION ^

function SetESRFAlgeAlignmentError(...
     ring,...          lattice AT
     algeexcelfile,... excel file with sheets: Coords, dR, dL, dZ
     filenameout,...   output filename = ['ALGEErrorsLattice_' num2str(ierr) '_' filenameout]
     nseeds,...        vector of seeds to use
     plotdataALGE)     % flag to plot 3D alignment data

 sets alignment errors defined in excel file algeexcelfile. BPM move with
 the lattice

see also: setDSerr setshift_THERING

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ringerr=SetESRFAlgeAlignmentError(ring,algeexcelfile,filenameout,nseeds,fracerr,plotdataALGE)
0002 %function SetESRFAlgeAlignmentError(...
0003 %     ring,...          lattice AT
0004 %     algeexcelfile,... excel file with sheets: Coords, dR, dL, dZ
0005 %     filenameout,...   output filename = ['ALGEErrorsLattice_' num2str(ierr) '_' filenameout]
0006 %     nseeds,...        vector of seeds to use
0007 %     plotdataALGE)     % flag to plot 3D alignment data
0008 %
0009 % sets alignment errors defined in excel file algeexcelfile. BPM move with
0010 % the lattice
0011 %
0012 %see also: setDSerr setshift_THERING
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 % get s along lattice for later interpolation and plot
0029 s=[cumsum(sqrt(diff(x).^2+diff(y).^2+diff(z).^2)); ringlength];
0030 
0031 dR = xlsread(algeexcelfile,'dR')*1e-3; % [m]
0032 dL = xlsread(algeexcelfile,'dL')*1e-3;
0033 dZ = xlsread(algeexcelfile,'dZ')*1e-3;
0034 
0035 % close loop
0036 s=[0;s];
0037 dR=[dR(end,:);dR];
0038 dL=[dL(end,:);dL];
0039 dZ=[dZ(end,:);dZ];
0040 
0041 % lattice positions
0042 slat=findspos(ring,1:length(ring));
0043 % shift by 4 cells to go to injection cell
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 % remove non significant values
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;%:size(dR,2);
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 %for
0079 ierr=nseeds;
0080     
0081     ringerr=ring;
0082     
0083 %     % bpm offsets  %%% removed this part and modified ApplyBPMErr.m to
0084 %     consider also misalignment errors T1, R1, as offset and rotation.
0085 %     This implements somehow the concept of positioning error of the BPM
0086 %     as different form the offset error.
0087 %
0088 %     ofx0=atgetfieldvalues(ringerr,indbpm,'Offset',{1,1});
0089 %     if isnan(ofx0), ofx0=zeros(size(indbpm)); end;
0090 %
0091 %     ofy0=atgetfieldvalues(ringerr,indbpm,'Offset',{1,2});
0092 %     if isnan(ofy0), ofy0=zeros(size(indbpm)); end;
0093 %
0094 %     ringerr=setcellstruct(ringerr,'Offset',indbpm,ofx0(:)-dxlat(indbpm,ierr),1,1);
0095 %     ringerr=setcellstruct(ringerr,'Offset',indbpm,ofy0(:)-dzlat(indbpm,ierr),1,2);
0096 %
0097     % % longitudinal erros
0098     % ringerr=setDSerr(ringerr,1:length(ring),dslat(:,ierr)'); % since after this comand there is an atsetshift, the T2 will be ignored!
0099     
0100     % transverse errors
0101     ringerr=atsetshift(ringerr,1:length(ring),dxlat(:,ierr)*fracerr,dzlat(:,ierr)*fracerr); %#ok<NASGU>
0102     
0103     if ~isempty(filenameout)
0104         save(['ALGEErrorsLattice_' num2str(ierr) '_' filenameout],'ringerr');
0105     end
0106 %end
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

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