1 | function [Xnew, Ynew, BPMxFamily, QUADxFamily, BPMyFamily, QUADyFamily, DateMatX, DateMatY] = quadplotall(DirName, PlotFlag) |
---|
2 | %QUADPLOTALL - Collect the date from a quadrupole center run. |
---|
3 | % When all the quadrupole center data files are stored in a directory this function |
---|
4 | % will go through all the files and pull out and plot some of the important information. |
---|
5 | % Note: if more than one quadrupole center file for the same quadrupole is in the directory |
---|
6 | % then only the latter file will be returned. Use quadgetdata to get all the data. |
---|
7 | % |
---|
8 | % [X, Y, BPMxFamily, QUADxFamily, BPMyFamily, QUADyFamily, XfileDate, YfilesDate] = quadplotall(DirName, PlotFlag) |
---|
9 | % |
---|
10 | % INPUTS |
---|
11 | % 1. DirName - Directory name to look for quadrupole center files |
---|
12 | % [] to browse {Default} |
---|
13 | % 2. PlotFlag - 0 to just get data without plotting results, else, plot results |
---|
14 | % |
---|
15 | % OUTPUTS |
---|
16 | % 1. X - Horizontal output matrix (format below) |
---|
17 | % 2. Y - Vertical output matrix (format below) |
---|
18 | % |
---|
19 | % 1&2 3 4 5 6 7 8 9 10 11 12 13 |
---|
20 | % Output = [BPMDev Center CenterSTD BPMpos DCCT BPMATIndex Quadpos QuadATIndex BPMBeta BPMPhi QuadBeta QuadPhi] |
---|
21 | % |
---|
22 | % 3-6. BPMxFamily, QUADxFamily, BPMyFamily, QUADyFamily - Family name for each center measurement |
---|
23 | % 7-8. XfileDate, YfilesDate - Date string for the file name |
---|
24 | |
---|
25 | % |
---|
26 | % Written by Greg Portmann |
---|
27 | % Modified by Laurent S. Nadolski |
---|
28 | |
---|
29 | |
---|
30 | if nargin == 0 |
---|
31 | DirName = ''; |
---|
32 | end |
---|
33 | |
---|
34 | if nargin < 2 |
---|
35 | PlotFlag = 1; |
---|
36 | end |
---|
37 | |
---|
38 | |
---|
39 | [X, Y, BPMxFamily, QUADxFamily, BPMyFamily, QUADyFamily, DateMatX, DateMatY] = quadgetdata(DirName, PlotFlag); |
---|
40 | |
---|
41 | |
---|
42 | if ~isempty(X) |
---|
43 | dx = family2dev('BPMx',0); |
---|
44 | Xnew = NaN * ones(size(dx,1),size(X,2)); |
---|
45 | Xnew(:,1:2) = dx; |
---|
46 | i = findrowindex(X(:,1:2), dx); |
---|
47 | Xnew(i,:) = X; |
---|
48 | end |
---|
49 | |
---|
50 | if ~isempty(Y) |
---|
51 | dy = family2dev('BPMz',0); |
---|
52 | Ynew = NaN * ones(size(dy,1),size(Y,2)); |
---|
53 | Ynew(:,1:2) = dy; |
---|
54 | j = findrowindex(Y(:,1:2), dy); |
---|
55 | Ynew(j,:) = Y; |
---|
56 | end |
---|
57 | |
---|
58 | % Add to quadgetdata output |
---|
59 | |
---|
60 | |
---|
61 | % Get the average Beta and Phi at all AT indicies |
---|
62 | [BetaX, BetaY] = modeltwiss('Beta'); |
---|
63 | BetaX = [(BetaX(1:end-1)+BetaX(2:end))/2; BetaX(end)]; |
---|
64 | BetaY = [(BetaY(1:end-1)+BetaY(2:end))/2; BetaY(end)]; |
---|
65 | |
---|
66 | [PhiX, PhiY] = modeltwiss('Phase'); |
---|
67 | PhiX = [(PhiX(1:end-1)+PhiX(2:end))/2; PhiX(end)]; |
---|
68 | PhiY = [(PhiY(1:end-1)+PhiY(2:end))/2; PhiY(end)]; |
---|
69 | |
---|
70 | if ~isempty(X) |
---|
71 | i = findrowindex(X(:,1:2), dx); |
---|
72 | Xnew = [Xnew NaN*ones(size(Xnew,1),4)]; |
---|
73 | Xnew(i,end-3:end) = [BetaX(Xnew(i,7)) PhiX(Xnew(i,7)) BetaX(Xnew(i,9)) PhiX(Xnew(i,9))]; |
---|
74 | end |
---|
75 | |
---|
76 | if ~isempty(Y) |
---|
77 | j = findrowindex(Y(:,1:2), dy); |
---|
78 | Ynew = [Ynew NaN*ones(size(Ynew,1),4)]; |
---|
79 | Ynew(j,end-3:end) = [BetaY(Ynew(j,7)) PhiY(Ynew(j,7)) BetaY(Ynew(j,9)) PhiY(Ynew(j,9))]; |
---|
80 | end |
---|
81 | |
---|
82 | |
---|
83 | if PlotFlag |
---|
84 | L = getfamilydata('Circumference'); |
---|
85 | |
---|
86 | if ~isempty(X) |
---|
87 | XOffset = getoffset('BPMx', Xnew(:,1:2)); |
---|
88 | end |
---|
89 | |
---|
90 | if ~isempty(Y) |
---|
91 | YOffset = getoffset('BPMy', Ynew(:,1:2)); |
---|
92 | end |
---|
93 | |
---|
94 | figure; |
---|
95 | subplot(2,1,1); |
---|
96 | if ~isempty(X) |
---|
97 | plot(Xnew(:,5), Xnew(:,3)-XOffset, '.b'); |
---|
98 | end |
---|
99 | ylabel('Horizontal [mm]'); |
---|
100 | xaxis([0 L]); |
---|
101 | title('New BPM Offsets Relative to the Present Offset Orbit'); |
---|
102 | |
---|
103 | subplot(2,1,2); |
---|
104 | if ~isempty(Y) |
---|
105 | plot(Ynew(:,5), Ynew(:,3)-YOffset, '.b'); |
---|
106 | end |
---|
107 | xlabel('BPM Position [meters]'); |
---|
108 | ylabel('Vertical [mm]'); |
---|
109 | xaxis([0 L]); |
---|
110 | |
---|
111 | |
---|
112 | figure; |
---|
113 | subplot(2,1,1); |
---|
114 | if ~isempty(X) |
---|
115 | plot(Xnew(:,5),360*(Xnew(:,11)-Xnew(:,13))/2/pi,'.r'); |
---|
116 | end |
---|
117 | xaxis([0 L]); |
---|
118 | ylabel('Horizontal [degrees]'); |
---|
119 | title('Phase Advance Between the BPM and Quadrupole'); |
---|
120 | |
---|
121 | subplot(2,1,2); |
---|
122 | if ~isempty(Y) |
---|
123 | plot(Ynew(:,5),360*(Ynew(:,11)-Ynew(:,13))/2/pi,'.r'); |
---|
124 | end |
---|
125 | xaxis([0 L]); |
---|
126 | xlabel('BPM Position [meters]'); |
---|
127 | ylabel('Vertical [degrees]'); |
---|
128 | |
---|
129 | |
---|
130 | figure; |
---|
131 | subplot(2,1,1); |
---|
132 | if ~isempty(X) |
---|
133 | plot(Xnew(:,5),Xnew(:,10),'.b', Xnew(:,8),Xnew(:,12),'.r'); |
---|
134 | end |
---|
135 | xaxis([0 L]); |
---|
136 | ylabel('Horizontal [meters]'); |
---|
137 | legend('BPM', 'Quadrupole'); |
---|
138 | title('Beta Function at the BPM and Quadrupole'); |
---|
139 | |
---|
140 | subplot(2,1,2); |
---|
141 | if ~isempty(Y) |
---|
142 | plot(Ynew(:,5),Ynew(:,10),'.b', Ynew(:,8),Ynew(:,12),'.r'); |
---|
143 | end |
---|
144 | xaxis([0 L]); |
---|
145 | xlabel('Position [meters]'); |
---|
146 | ylabel('Vertical [meters]'); |
---|
147 | legend('BPM', 'Quadrupole'); |
---|
148 | |
---|
149 | |
---|
150 | figure; |
---|
151 | subplot(2,1,1); |
---|
152 | if ~isempty(X) |
---|
153 | plot(Xnew(:,5),Xnew(:,6),'.'); |
---|
154 | end |
---|
155 | xaxis([0 L]); |
---|
156 | xlabel('Position [meters]'); |
---|
157 | ylabel('DCCT [mamps]'); |
---|
158 | title('Beam Current During the Horizontal Measurement'); |
---|
159 | |
---|
160 | subplot(2,1,2); |
---|
161 | if ~isempty(Y) |
---|
162 | plot(Ynew(:,5),Ynew(:,6),'.'); |
---|
163 | end |
---|
164 | xaxis([0 L]); |
---|
165 | xlabel('Position [meters]'); |
---|
166 | ylabel('DCCT [mamps]'); |
---|
167 | title('Beam Current During the Vertical Measurement'); |
---|
168 | |
---|
169 | |
---|
170 | % Only return the measure centers |
---|
171 | if ~isempty(X) |
---|
172 | i = find(~isnan(Xnew(:,3))); |
---|
173 | Xnew = Xnew(i,:); |
---|
174 | end |
---|
175 | |
---|
176 | if ~isempty(Y) |
---|
177 | i = find(~isnan(Ynew(:,3))); |
---|
178 | Ynew = Ynew(i,:); |
---|
179 | end |
---|
180 | end |
---|