1 | // -*- C++ -*-
|
---|
2 | // ---------------------------------------------------------------------------
|
---|
3 | //
|
---|
4 | // This file is a part of the CLHEP - a Class Library for High Energy Physics.
|
---|
5 | //
|
---|
6 | // This is the implementation of that part of the HepLorentzRotation class
|
---|
7 | // which is concerned with setting or constructing the transformation based
|
---|
8 | // on 4 supplied columns or rows.
|
---|
9 |
|
---|
10 | #ifdef GNUPRAGMA
|
---|
11 | #pragma implementation
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | #include "CLHEP/Vector/defs.h"
|
---|
15 | #include "CLHEP/Vector/LorentzRotation.h"
|
---|
16 | #include "CLHEP/Vector/LorentzVector.h"
|
---|
17 | #include "CLHEP/Vector/ZMxpv.h"
|
---|
18 |
|
---|
19 | #include <cmath>
|
---|
20 |
|
---|
21 | namespace CLHEP {
|
---|
22 |
|
---|
23 | // ---------- Constructors and Assignment:
|
---|
24 |
|
---|
25 | HepLorentzRotation & HepLorentzRotation::set (const HepLorentzVector & col1,
|
---|
26 | const HepLorentzVector & col2,
|
---|
27 | const HepLorentzVector & col3,
|
---|
28 | const HepLorentzVector & col4) {
|
---|
29 | // First, test that the four cols do represent something close to a
|
---|
30 | // true LT:
|
---|
31 |
|
---|
32 | ZMpvMetric_t savedMetric = HepLorentzVector::setMetric (TimePositive);
|
---|
33 |
|
---|
34 | if ( col4.getT() < 0 ) {
|
---|
35 | ZMthrowC (ZMxpvImproperTransformation(
|
---|
36 | "column 4 supplied to define transformation has negative T component"));
|
---|
37 | *this = HepLorentzRotation();
|
---|
38 | return *this;
|
---|
39 | }
|
---|
40 |
|
---|
41 | double u1u1 = col1.dot(col1);
|
---|
42 | double f11 = fabs(u1u1 + 1.0);
|
---|
43 | if ( f11 > Hep4RotationInterface::tolerance ) {
|
---|
44 | ZMthrowC (ZMxpvNotSymplectic(
|
---|
45 | "column 1 supplied for HepLorentzRotation has w*w != -1"));
|
---|
46 | }
|
---|
47 | double u2u2 = col2.dot(col2);
|
---|
48 | double f22 = fabs(u2u2 + 1.0);
|
---|
49 | if ( f22 > Hep4RotationInterface::tolerance ) {
|
---|
50 | ZMthrowC (ZMxpvNotSymplectic(
|
---|
51 | "column 2 supplied for HepLorentzRotation has w*w != -1"));
|
---|
52 | }
|
---|
53 | double u3u3 = col3.dot(col3);
|
---|
54 | double f33 = fabs(u3u3 + 1.0);
|
---|
55 | if ( f33 > Hep4RotationInterface::tolerance ) {
|
---|
56 | ZMthrowC (ZMxpvNotSymplectic(
|
---|
57 | "column 3 supplied for HepLorentzRotation has w*w != -1"));
|
---|
58 | }
|
---|
59 | double u4u4 = col4.dot(col4);
|
---|
60 | double f44 = fabs(u4u4 - 1.0);
|
---|
61 | if ( f44 > Hep4RotationInterface::tolerance ) {
|
---|
62 | ZMthrowC (ZMxpvNotSymplectic(
|
---|
63 | "column 4 supplied for HepLorentzRotation has w*w != +1"));
|
---|
64 | }
|
---|
65 |
|
---|
66 | double u1u2 = col1.dot(col2);
|
---|
67 | double f12 = fabs(u1u2);
|
---|
68 | if ( f12 > Hep4RotationInterface::tolerance ) {
|
---|
69 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
70 | "columns 1 and 2 supplied for HepLorentzRotation have non-zero dot"));
|
---|
71 | }
|
---|
72 | double u1u3 = col1.dot(col3);
|
---|
73 | double f13 = fabs(u1u3);
|
---|
74 |
|
---|
75 | if ( f13 > Hep4RotationInterface::tolerance ) {
|
---|
76 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
77 | "columns 1 and 3 supplied for HepLorentzRotation have non-zero dot"));
|
---|
78 | }
|
---|
79 | double u1u4 = col1.dot(col4);
|
---|
80 | double f14 = fabs(u1u4);
|
---|
81 | if ( f14 > Hep4RotationInterface::tolerance ) {
|
---|
82 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
83 | "columns 1 and 4 supplied for HepLorentzRotation have non-zero dot"));
|
---|
84 | }
|
---|
85 | double u2u3 = col2.dot(col3);
|
---|
86 | double f23 = fabs(u2u3);
|
---|
87 | if ( f23 > Hep4RotationInterface::tolerance ) {
|
---|
88 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
89 | "columns 2 and 3 supplied for HepLorentzRotation have non-zero dot"));
|
---|
90 | }
|
---|
91 | double u2u4 = col2.dot(col4);
|
---|
92 | double f24 = fabs(u2u4);
|
---|
93 | if ( f24 > Hep4RotationInterface::tolerance ) {
|
---|
94 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
95 | "columns 2 and 4 supplied for HepLorentzRotation have non-zero dot"));
|
---|
96 | }
|
---|
97 | double u3u4 = col3.dot(col4);
|
---|
98 | double f34 = fabs(u3u4);
|
---|
99 | if ( f34 > Hep4RotationInterface::tolerance ) {
|
---|
100 | ZMthrowC (ZMxpvNotOrthogonal(
|
---|
101 | "columns 3 and 4 supplied for HepLorentzRotation have non-zero dot"));
|
---|
102 | }
|
---|
103 |
|
---|
104 | // Our strategy will be to order the cols, then do gram-schmidt on them
|
---|
105 | // (that is, remove the components of col d that make it non-orthogonal to
|
---|
106 | // col c, normalize that, then remove the components of b that make it
|
---|
107 | // non-orthogonal to d and to c, normalize that, etc.
|
---|
108 |
|
---|
109 | // Because col4, the time col, is most likely to be computed directly, we
|
---|
110 | // will start from there and work left-ward.
|
---|
111 |
|
---|
112 | HepLorentzVector a, b, c, d;
|
---|
113 | bool isLorentzTransformation = true;
|
---|
114 | double norm;
|
---|
115 |
|
---|
116 | d = col4;
|
---|
117 | norm = d.dot(d);
|
---|
118 | if (norm <= 0.0) {
|
---|
119 | isLorentzTransformation = false;
|
---|
120 | if (norm == 0.0) {
|
---|
121 | d = T_HAT4; // Moot, but let's keep going...
|
---|
122 |
|
---|
123 | norm = 1.0;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | d /= norm;
|
---|
127 |
|
---|
128 | c = col3 - col3.dot(d) * d;
|
---|
129 | norm = -c.dot(c);
|
---|
130 | if (norm <= 0.0) {
|
---|
131 | isLorentzTransformation = false;
|
---|
132 | if (norm == 0.0) {
|
---|
133 | c = Z_HAT4; // Moot
|
---|
134 | norm = 1.0;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | c /= norm;
|
---|
138 |
|
---|
139 | b = col2 + col2.dot(c) * c - col2.dot(d) * d;
|
---|
140 | norm = -b.dot(b);
|
---|
141 | if (norm <= 0.0) {
|
---|
142 | isLorentzTransformation = false;
|
---|
143 | if (norm == 0.0) {
|
---|
144 | b = Y_HAT4; // Moot
|
---|
145 | norm = 1.0;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | b /= norm;
|
---|
149 |
|
---|
150 | a = col1 + col1.dot(b) * b + col1.dot(c) * c - col1.dot(d) * d;
|
---|
151 | norm = -a.dot(a);
|
---|
152 | if (norm <= 0.0) {
|
---|
153 | isLorentzTransformation = false;
|
---|
154 | if (norm == 0.0) {
|
---|
155 | a = X_HAT4; // Moot
|
---|
156 | norm = 1.0;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | a /= norm;
|
---|
160 |
|
---|
161 | if ( !isLorentzTransformation ) {
|
---|
162 | ZMthrowC (ZMxpvImproperTransformation(
|
---|
163 | "cols 1-4 supplied to define transformation form either \n"
|
---|
164 | " a boosted reflection or a tachyonic transformation -- \n"
|
---|
165 | " transformation will be set to Identity "));
|
---|
166 |
|
---|
167 |
|
---|
168 | *this = HepLorentzRotation();
|
---|
169 | }
|
---|
170 |
|
---|
171 | if ( isLorentzTransformation ) {
|
---|
172 | mxx = a.x(); myx = a.y(); mzx = a.z(); mtx = a.t();
|
---|
173 | mxy = b.x(); myy = b.y(); mzy = b.z(); mty = b.t();
|
---|
174 | mxz = c.x(); myz = c.y(); mzz = c.z(); mtz = c.t();
|
---|
175 | mxt = d.x(); myt = d.y(); mzt = d.z(); mtt = d.t();
|
---|
176 | }
|
---|
177 |
|
---|
178 | HepLorentzVector::setMetric (savedMetric);
|
---|
179 | return *this;
|
---|
180 |
|
---|
181 | } // set ( col1, col2, col3, col4 )
|
---|
182 |
|
---|
183 | HepLorentzRotation & HepLorentzRotation::setRows
|
---|
184 | (const HepLorentzVector & row1,
|
---|
185 | const HepLorentzVector & row2,
|
---|
186 | const HepLorentzVector & row3,
|
---|
187 | const HepLorentzVector & row4) {
|
---|
188 | // Set based on using those rows as columns:
|
---|
189 | set (row1, row2, row3, row4);
|
---|
190 | // Now transpose in place:
|
---|
191 | register double q1, q2, q3;
|
---|
192 | q1 = mxy; q2 = mxz; q3 = mxt;
|
---|
193 | mxy = myx; mxz = mzx; mxt = mtx;
|
---|
194 | myx = q1; mzx = q2; mtx = q3;
|
---|
195 | q1 = myz; q2 = myt; q3 = mzt;
|
---|
196 | myz = mzy; myt = mty; mzt = mtz;
|
---|
197 | mzy = q1; mty = q2; mtz = q3;
|
---|
198 | return *this;
|
---|
199 | } // LorentzTransformation::setRows(row1 ... row4)
|
---|
200 |
|
---|
201 | HepLorentzRotation::HepLorentzRotation ( const HepLorentzVector & col1,
|
---|
202 | const HepLorentzVector & col2,
|
---|
203 | const HepLorentzVector & col3,
|
---|
204 | const HepLorentzVector & col4 )
|
---|
205 | {
|
---|
206 | set ( col1, col2, col3, col4 );
|
---|
207 | }
|
---|
208 |
|
---|
209 | } // namespace CLHEP
|
---|
210 |
|
---|