1 | function m = gcr2loco(gx, gy, c, r) |
---|
2 | %LOCO2GCR - Converts the LOCO BPM output to gain, crunch, and roll parameterization |
---|
3 | % M = gcr2loco(Gx, Gy, C, R) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. Gx - Horizontal gain |
---|
7 | % 2. Gy - Vertical gain |
---|
8 | % 3. C - Crunch |
---|
9 | % 4. R - Roll [radians] |
---|
10 | % |
---|
11 | % OUTPUTS |
---|
12 | % 1. M - LOCO output matrix (gain/coupling) |
---|
13 | % Note: for vector inputs the output will have rows [Gx Gy C R] |
---|
14 | % |
---|
15 | % ALGORITHM |
---|
16 | % The LOCO matrix for a BPM converts the model BPM data to the |
---|
17 | % coordinate system of the actual BPM measurement. The new BPM is |
---|
18 | % is defined as the calibrated BPM data. The middle layer applies |
---|
19 | % the coordinate conversion from the measured data to the model gcr2loco splits this matrix up |
---|
20 | % into a Gain, Crunch, and Roll term. |
---|
21 | % |
---|
22 | % [Measured Coordinate System] = LOCO Matrix * [Model] (LOCO coordinate transform) |
---|
23 | % [Calibrated to Model Coordinate System] = inv(LOCO Matrix) * [Measured Data] (Middle layer coordinate transform) |
---|
24 | % |
---|
25 | % The middle layer stores the coordinate transform in terms of gain, crunch, and roll. |
---|
26 | % The gain terms are use in real2raw/raw2real (hence hw2physics/physics2hw) and the |
---|
27 | % crunch and roll are used in programs like getpvmodel/setpvmodel. That is, hw2physics/physics2hw |
---|
28 | % does not make a coordinate rotation, it just corrects the gain. |
---|
29 | % |
---|
30 | % inv(LOCO Matrix) = Rotation Matrix * Crunch Matrix * Gain Matrix |
---|
31 | % | cos(R) sin(R) | | 1 C | | Gx 0 | |
---|
32 | % |-sin(R) cos(R) | | C 1 | / sqrt(1-C^2) | 0 Gy | |
---|
33 | % |
---|
34 | % See also loco2gcr, getgain, getroll, getcrunch |
---|
35 | % |
---|
36 | % Written by Greg Portmann |
---|
37 | |
---|
38 | |
---|
39 | if nargin == 0 |
---|
40 | error('At least one input required.'); |
---|
41 | end |
---|
42 | |
---|
43 | |
---|
44 | if length(gx) > 1 |
---|
45 | for i = 1:size(gx,1) |
---|
46 | if nargin < 2 |
---|
47 | mm = gcr2loco(gx(i)); |
---|
48 | elseif nargin < 3 |
---|
49 | mm = gcr2loco(gx(i), gy(i)); |
---|
50 | elseif nargin < 4 |
---|
51 | mm = gcr2loco(gx(i), gy(i), c(i)); |
---|
52 | else |
---|
53 | mm = gcr2loco(gx(i), gy(i), c(i), r(i)); |
---|
54 | end |
---|
55 | m(i,:) = [mm(1) mm(2) mm(3) mm(4)]; |
---|
56 | end |
---|
57 | return |
---|
58 | end |
---|
59 | |
---|
60 | |
---|
61 | % Roll term |
---|
62 | if nargin == 1 |
---|
63 | m = [1/gx 0; 0 0]; |
---|
64 | return |
---|
65 | else |
---|
66 | m = [1/gx 0; 0 1/gy]; |
---|
67 | end |
---|
68 | |
---|
69 | |
---|
70 | % Crunch term |
---|
71 | if nargin >= 3 |
---|
72 | m = m * [1 -c; -c 1] / sqrt(1-c^2); |
---|
73 | end |
---|
74 | |
---|
75 | |
---|
76 | % Roll term |
---|
77 | if nargin >= 4 |
---|
78 | m = m * [cos(r) sin(r); -sin(r) cos(r)]; |
---|
79 | end |
---|
80 | |
---|