1 | function [gx, gy, c, r] = loco2gcr(m) |
---|
2 | %LOCO2GCR - Converts the LOCO BPM output to gain, crunch, and roll parameterization |
---|
3 | % [Gx, Gy, C, R] = loco2gcr(M) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. M - LOCO output matrix (gain/coupling) |
---|
7 | % |
---|
8 | % OUTPUTS |
---|
9 | % 1. Gx - Horizontal gain |
---|
10 | % 2. Gy - Vertical gain |
---|
11 | % 3. C - Crunch |
---|
12 | % 4. R - Roll [radians] |
---|
13 | % |
---|
14 | % ALGORITHM |
---|
15 | % The LOCO matrix for a BPM converts the model BPM data to the |
---|
16 | % coordinate system of the actual BPM measurement. The new BPM is |
---|
17 | % is defined as the calibrated BPM data. The middle layer applies |
---|
18 | % the coordinate conversion from the measured data to the model gcr2loco splits this matrix up |
---|
19 | % into a Gain, Crunch, and Roll term. |
---|
20 | % |
---|
21 | % [Measured Coordinate System] = LOCO Matrix * [Model] (LOCO coordinate transform) |
---|
22 | % [Calibrated to Model Coordinate System] = inv(LOCO Matrix) * [Measured Data] (Middle layer coordinate transform) |
---|
23 | % |
---|
24 | % The middle layer stores the coordinate transform in terms of gain, crunch, and roll. |
---|
25 | % The gain terms are use in real2raw/raw2real (hence hw2physics/physics2hw) and the |
---|
26 | % crunch and roll are used in programs like getpvmodel/setpvmodel. That is, hw2physics/physics2hw |
---|
27 | % does not make a coordinate rotation, it just corrects the gain. |
---|
28 | % |
---|
29 | % LOCO Matrix for the ith BPM = [BPMData.HBPMGain(i) BPMData.HBPMCoupling(i) |
---|
30 | % BPMData.VBPMCoupling(i) BPMData.VBPMGain(i) ]; |
---|
31 | % |
---|
32 | % inv(LOCO Matrix) = Rotation Matrix * Crunch Matrix * Gain Matrix |
---|
33 | % | cos(R) sin(R) | | 1 C | | Gx 0 | |
---|
34 | % |-sin(R) cos(R) | | C 1 | / sqrt(1-C^2) | 0 Gy | |
---|
35 | % |
---|
36 | % See also gcr2loco, getgain, getroll, getcrunch |
---|
37 | % |
---|
38 | % Written by Greg Portmann |
---|
39 | |
---|
40 | |
---|
41 | m = inv(m); |
---|
42 | |
---|
43 | % Roll |
---|
44 | r = .5 * atan( (m(2,2)*m(2,1)-m(1,1)*m(1,2)) / (m(1,1)*m(2,2)+m(1,2)*m(2,1)) ); |
---|
45 | |
---|
46 | |
---|
47 | a = m(1,1)*cos(r) + m(2,1)*sin(r); |
---|
48 | b = m(2,2)*cos(r) - m(1,2)*sin(r); |
---|
49 | |
---|
50 | |
---|
51 | % Crunch |
---|
52 | c = (-m(1,1)*sin(r)+m(2,1)*cos(r)) / a; |
---|
53 | %c_also = (m(2,2)*sin(r)+m(1,2)*cos(r)) / b |
---|
54 | |
---|
55 | |
---|
56 | % Gain |
---|
57 | s = sqrt(1-c^2); |
---|
58 | gx = s * a; |
---|
59 | gy = s * b; |
---|
60 | |
---|
61 | |
---|