Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LorentzRotation.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class LorentzRotation, a 4x4 matrix representation of
12// a general Lorentz transformation
13//
14// Created by: Mark Fischler Mon Aug 8 2005
15//
16
18
23
24#include <cmath>
25#include <algorithm>
26
31
33
35
36namespace ROOT {
37
38namespace ROOT_MATH_ARCH {
39
41{
42 // constructor of an identity LR
43 fM[kXX] = 1.0;
44 fM[kXY] = 0.0;
45 fM[kXZ] = 0.0;
46 fM[kXT] = 0.0;
47 fM[kYX] = 0.0;
48 fM[kYY] = 1.0;
49 fM[kYZ] = 0.0;
50 fM[kYT] = 0.0;
51 fM[kZX] = 0.0;
52 fM[kZY] = 0.0;
53 fM[kZZ] = 1.0;
54 fM[kZT] = 0.0;
55 fM[kTX] = 0.0;
56 fM[kTY] = 0.0;
57 fM[kTZ] = 0.0;
58 fM[kTT] = 1.0;
59}
60
62{
63 // construct from Rotation3D
64 r.GetComponents(fM[kXX], fM[kXY], fM[kXZ], fM[kYX], fM[kYY], fM[kYZ], fM[kZX], fM[kZY], fM[kZZ]);
65 fM[kXT] = 0.0;
66 fM[kYT] = 0.0;
67 fM[kZT] = 0.0;
68 fM[kTX] = 0.0;
69 fM[kTY] = 0.0;
70 fM[kTZ] = 0.0;
71 fM[kTT] = 1.0;
72}
73
75{
76 // construct from AxisAngle
77 const Rotation3D r(a);
78 r.GetComponents(fM[kXX], fM[kXY], fM[kXZ], fM[kYX], fM[kYY], fM[kYZ], fM[kZX], fM[kZY], fM[kZZ]);
79 fM[kXT] = 0.0;
80 fM[kYT] = 0.0;
81 fM[kZT] = 0.0;
82 fM[kTX] = 0.0;
83 fM[kTY] = 0.0;
84 fM[kTZ] = 0.0;
85 fM[kTT] = 1.0;
86}
87
89{
90 // construct from EulerAngles
91 const Rotation3D r(e);
92 r.GetComponents(fM[kXX], fM[kXY], fM[kXZ], fM[kYX], fM[kYY], fM[kYZ], fM[kZX], fM[kZY], fM[kZZ]);
93 fM[kXT] = 0.0;
94 fM[kYT] = 0.0;
95 fM[kZT] = 0.0;
96 fM[kTX] = 0.0;
97 fM[kTY] = 0.0;
98 fM[kTZ] = 0.0;
99 fM[kTT] = 1.0;
100}
101
103{
104 // construct from Quaternion
105 const Rotation3D r(q);
106 r.GetComponents(fM[kXX], fM[kXY], fM[kXZ], fM[kYX], fM[kYY], fM[kYZ], fM[kZX], fM[kZY], fM[kZZ]);
107 fM[kXT] = 0.0;
108 fM[kYT] = 0.0;
109 fM[kZT] = 0.0;
110 fM[kTX] = 0.0;
111 fM[kTY] = 0.0;
112 fM[kTZ] = 0.0;
113 fM[kTT] = 1.0;
114}
115
117{
118 // construct from RotationX
119 Scalar s = r.SinAngle();
120 Scalar c = r.CosAngle();
121 fM[kXX] = 1.0;
122 fM[kXY] = 0.0;
123 fM[kXZ] = 0.0;
124 fM[kXT] = 0.0;
125 fM[kYX] = 0.0;
126 fM[kYY] = c;
127 fM[kYZ] = -s;
128 fM[kYT] = 0.0;
129 fM[kZX] = 0.0;
130 fM[kZY] = s;
131 fM[kZZ] = c;
132 fM[kZT] = 0.0;
133 fM[kTX] = 0.0;
134 fM[kTY] = 0.0;
135 fM[kTZ] = 0.0;
136 fM[kTT] = 1.0;
137}
138
140{
141 // construct from RotationY
142 Scalar s = r.SinAngle();
143 Scalar c = r.CosAngle();
144 fM[kXX] = c;
145 fM[kXY] = 0.0;
146 fM[kXZ] = s;
147 fM[kXT] = 0.0;
148 fM[kYX] = 0.0;
149 fM[kYY] = 1.0;
150 fM[kYZ] = 0.0;
151 fM[kYT] = 0.0;
152 fM[kZX] = -s;
153 fM[kZY] = 0.0;
154 fM[kZZ] = c;
155 fM[kZT] = 0.0;
156 fM[kTX] = 0.0;
157 fM[kTY] = 0.0;
158 fM[kTZ] = 0.0;
159 fM[kTT] = 1.0;
160}
161
163{
164 // construct from RotationX
165 Scalar s = r.SinAngle();
166 Scalar c = r.CosAngle();
167 fM[kXX] = c;
168 fM[kXY] = -s;
169 fM[kXZ] = 0.0;
170 fM[kXT] = 0.0;
171 fM[kYX] = s;
172 fM[kYY] = c;
173 fM[kYZ] = 0.0;
174 fM[kYT] = 0.0;
175 fM[kZX] = 0.0;
176 fM[kZY] = 0.0;
177 fM[kZZ] = 1.0;
178 fM[kZT] = 0.0;
179 fM[kTX] = 0.0;
180 fM[kTY] = 0.0;
181 fM[kTZ] = 0.0;
182 fM[kTT] = 1.0;
183}
184
186{
187 // Assuming the representation of this is close to a true Lorentz Rotation,
188 // but may have drifted due to round-off error from many operations,
189 // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation
190 // again.
191
193 if (fM[kTT] <= 0) {
194#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
195 GenVector_Throw("LorentzRotation:Rectify(): Non-positive TT component - cannot rectify");
196#endif
197 return;
198 }
199 FourVector t(fM[kTX], fM[kTY], fM[kTZ], fM[kTT]);
200 Scalar m2 = t.M2();
201 if (m2 <= 0) {
202#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
203 GenVector_Throw("LorentzRotation:Rectify(): Non-timelike time row - cannot rectify");
204#endif
205 return;
206 }
207 t /= math_sqrt(m2);
208 FourVector z(fM[kZX], fM[kZY], fM[kZZ], fM[kZT]);
209 z = z - z.Dot(t) * t;
210 m2 = z.M2();
211 if (m2 >= 0) {
212#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
213 GenVector_Throw("LorentzRotation:Rectify(): Non-spacelike Z row projection - "
214 "cannot rectify");
215#endif
216 return;
217 }
218 z /= math_sqrt(-m2);
219 FourVector y(fM[kYX], fM[kYY], fM[kYZ], fM[kYT]);
220 y = y - y.Dot(t) * t - y.Dot(z) * z;
221 m2 = y.M2();
222 if (m2 >= 0) {
223#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
224 GenVector_Throw("LorentzRotation:Rectify(): Non-spacelike Y row projection - "
225 "cannot rectify");
226#endif
227 return;
228 }
229 y /= math_sqrt(-m2);
230 FourVector x(fM[kXX], fM[kXY], fM[kXZ], fM[kXT]);
231 x = x - x.Dot(t) * t - x.Dot(z) * z - x.Dot(y) * y;
232 m2 = x.M2();
233 if (m2 >= 0) {
234#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
235 GenVector_Throw("LorentzRotation:Rectify(): Non-spacelike X row projection - "
236 "cannot rectify");
237#endif
238 return;
239 }
240 x /= math_sqrt(-m2);
241}
242
244{
245 // invert modifying current content
246 Scalar temp;
247 temp = fM[kXY];
248 fM[kXY] = fM[kYX];
249 fM[kYX] = temp;
250 temp = fM[kXZ];
251 fM[kXZ] = fM[kZX];
252 fM[kZX] = temp;
253 temp = fM[kYZ];
254 fM[kYZ] = fM[kZY];
255 fM[kZY] = temp;
256 temp = fM[kXT];
257 fM[kXT] = -fM[kTX];
258 fM[kTX] = -temp;
259 temp = fM[kYT];
260 fM[kYT] = -fM[kTY];
261 fM[kTY] = -temp;
262 temp = fM[kZT];
263 fM[kZT] = -fM[kTZ];
264 fM[kTZ] = -temp;
265}
266
268{
269 // return an inverse LR
270 return LorentzRotation(fM[kXX], fM[kYX], fM[kZX], -fM[kTX], fM[kXY], fM[kYY], fM[kZY], -fM[kTY], fM[kXZ], fM[kYZ],
271 fM[kZZ], -fM[kTZ], -fM[kXT], -fM[kYT], -fM[kZT], fM[kTT]);
272}
273
275{
276 // combination with another LR
277 return LorentzRotation(fM[kXX] * r.fM[kXX] + fM[kXY] * r.fM[kYX] + fM[kXZ] * r.fM[kZX] + fM[kXT] * r.fM[kTX],
278 fM[kXX] * r.fM[kXY] + fM[kXY] * r.fM[kYY] + fM[kXZ] * r.fM[kZY] + fM[kXT] * r.fM[kTY],
279 fM[kXX] * r.fM[kXZ] + fM[kXY] * r.fM[kYZ] + fM[kXZ] * r.fM[kZZ] + fM[kXT] * r.fM[kTZ],
280 fM[kXX] * r.fM[kXT] + fM[kXY] * r.fM[kYT] + fM[kXZ] * r.fM[kZT] + fM[kXT] * r.fM[kTT],
281 fM[kYX] * r.fM[kXX] + fM[kYY] * r.fM[kYX] + fM[kYZ] * r.fM[kZX] + fM[kYT] * r.fM[kTX],
282 fM[kYX] * r.fM[kXY] + fM[kYY] * r.fM[kYY] + fM[kYZ] * r.fM[kZY] + fM[kYT] * r.fM[kTY],
283 fM[kYX] * r.fM[kXZ] + fM[kYY] * r.fM[kYZ] + fM[kYZ] * r.fM[kZZ] + fM[kYT] * r.fM[kTZ],
284 fM[kYX] * r.fM[kXT] + fM[kYY] * r.fM[kYT] + fM[kYZ] * r.fM[kZT] + fM[kYT] * r.fM[kTT],
285 fM[kZX] * r.fM[kXX] + fM[kZY] * r.fM[kYX] + fM[kZZ] * r.fM[kZX] + fM[kZT] * r.fM[kTX],
286 fM[kZX] * r.fM[kXY] + fM[kZY] * r.fM[kYY] + fM[kZZ] * r.fM[kZY] + fM[kZT] * r.fM[kTY],
287 fM[kZX] * r.fM[kXZ] + fM[kZY] * r.fM[kYZ] + fM[kZZ] * r.fM[kZZ] + fM[kZT] * r.fM[kTZ],
288 fM[kZX] * r.fM[kXT] + fM[kZY] * r.fM[kYT] + fM[kZZ] * r.fM[kZT] + fM[kZT] * r.fM[kTT],
289 fM[kTX] * r.fM[kXX] + fM[kTY] * r.fM[kYX] + fM[kTZ] * r.fM[kZX] + fM[kTT] * r.fM[kTX],
290 fM[kTX] * r.fM[kXY] + fM[kTY] * r.fM[kYY] + fM[kTZ] * r.fM[kZY] + fM[kTT] * r.fM[kTY],
291 fM[kTX] * r.fM[kXZ] + fM[kTY] * r.fM[kYZ] + fM[kTZ] * r.fM[kZZ] + fM[kTT] * r.fM[kTZ],
292 fM[kTX] * r.fM[kXT] + fM[kTY] * r.fM[kYT] + fM[kTZ] * r.fM[kZT] + fM[kTT] * r.fM[kTT]);
293}
294
295#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
296
297std::ostream &operator<<(std::ostream &os, const LorentzRotation &r)
298{
299 // TODO - this will need changing for machine-readable issues
300 // and even the human readable form needs formatting improvements
301 double m[16];
302 r.GetComponents(m, m + 16);
303 os << "\n" << m[0] << " " << m[1] << " " << m[2] << " " << m[3];
304 os << "\n" << m[4] << " " << m[5] << " " << m[6] << " " << m[7];
305 os << "\n" << m[8] << " " << m[9] << " " << m[10] << " " << m[11];
306 os << "\n" << m[12] << " " << m[13] << " " << m[14] << " " << m[15] << "\n";
307 return os;
308}
309#endif
310
311} // namespace ROOT_MATH_ARCH
312} // namespace ROOT
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:46
EulerAngles class describing rotation as three angles (Euler Angles).
Definition EulerAngles.h:50
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
LorentzRotation Inverse() const
Return inverse of a rotation.
LorentzRotation()
Default constructor (identity transformation)
void Rectify()
Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix.
void Invert()
Invert a Lorentz rotation in place.
A4Vector operator*(const A4Vector &v) const
Overload operator * for rotation on a vector.
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition Quaternion.h:52
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:71
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:45
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition RotationY.h:45
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:45
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
void GenVector_Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
Scalar math_sqrt(Scalar x)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:98
TMarker m
Definition textangle.C:8