Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LorentzRotation.h
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 ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for LorentzRotation
12//
13// Created by: Mark Fischler Mon Aug 8 2005
14//
15// Last update: $Id$
16//
17#ifndef ROOT_MathX_GenVectorX_LorentzRotation
18#define ROOT_MathX_GenVectorX_LorentzRotation 1
19
21
24
36
38
39namespace ROOT {
40
41namespace ROOT_MATH_ARCH {
42
43//__________________________________________________________________________________________
44/**
45 Lorentz transformation class with the (4D) transformation represented by
46 a 4x4 orthosymplectic matrix.
47 See also Boost, BoostX, BoostY and BoostZ for classes representing
48 specialized Lorentz transformations.
49 Also, the 3-D rotation classes can be considered to be special Lorentz
50 transformations which do not mix space and time components.
51
52 @ingroup GenVectorX
53
54 @see GenVectorX
55*/
56
58
59public:
60 typedef double Scalar;
61
63 kXX = 0,
64 kXY = 1,
65 kXZ = 2,
66 kXT = 3,
67 kYX = 4,
68 kYY = 5,
69 kYZ = 6,
70 kYT = 7,
71 kZX = 8,
72 kZY = 9,
73 kZZ = 10,
74 kZT = 11,
75 kTX = 12,
76 kTY = 13,
77 kTZ = 14,
78 kTT = 15
79 };
80
81 // ========== Constructors and Assignment =====================
82
83 /**
84 Default constructor (identity transformation)
85 */
87
88 /**
89 Construct given a pair of pointers or iterators defining the
90 beginning and end of an array of sixteen Scalars
91 */
92 template <class IT>
93 LorentzRotation(IT begin, IT end)
94 {
95 SetComponents(begin, end);
96 }
97
98 // The compiler-generated and dtor are OK but we have implementwd the copy-ctor and
99 // assignment operators since we have a template assignment
100
101 /**
102 Copy constructor
103 */
104 LorentzRotation(LorentzRotation const &r) { *this = r; }
105
106 /**
107 Construct from a pure boost
108 */
109 explicit LorentzRotation(Boost const &b) { b.GetLorentzRotation(fM + 0); }
110 explicit LorentzRotation(BoostX const &bx) { bx.GetLorentzRotation(fM + 0); }
111 explicit LorentzRotation(BoostY const &by) { by.GetLorentzRotation(fM + 0); }
112 explicit LorentzRotation(BoostZ const &bz) { bz.GetLorentzRotation(fM + 0); }
113
114 /**
115 Construct from a 3-D rotation (no space-time mixing)
116 */
117 explicit LorentzRotation(Rotation3D const &r);
118 explicit LorentzRotation(AxisAngle const &a);
119 explicit LorentzRotation(EulerAngles const &e);
120 explicit LorentzRotation(Quaternion const &q);
121 explicit LorentzRotation(RotationX const &r);
122 explicit LorentzRotation(RotationY const &r);
123 explicit LorentzRotation(RotationZ const &r);
124
125 /**
126 Construct from a linear algebra matrix of size at least 4x4,
127 which must support operator()(i,j) to obtain elements (0,3) thru (3,3).
128 Precondition: The matrix is assumed to be orthosymplectic. NO checking
129 or re-adjusting is performed.
130 Note: (0,0) refers to the XX component; (3,3) refers to the TT component.
131 */
132 template <class ForeignMatrix>
134 {
136 }
137
138 /**
139 Construct from four orthosymplectic vectors (which must have methods
140 x(), y(), z() and t()) which will be used as the columns of the Lorentz
141 rotation matrix. The orthosymplectic conditions will be checked, and
142 values adjusted so that the result will always be a good Lorentz rotation
143 matrix.
144 */
145 template <class Foreign4Vector>
147 const Foreign4Vector &v4)
148 {
149 SetComponents(v1, v2, v3, v4);
150 }
151
152 /**
153 Raw constructor from sixteen Scalar components (without any checking)
154 */
160
161 /**
162 Assign from another LorentzRotation
163 */
165 {
166 SetComponents(rhs.fM[0], rhs.fM[1], rhs.fM[2], rhs.fM[3], rhs.fM[4], rhs.fM[5], rhs.fM[6], rhs.fM[7], rhs.fM[8],
167 rhs.fM[9], rhs.fM[10], rhs.fM[11], rhs.fM[12], rhs.fM[13], rhs.fM[14], rhs.fM[15]);
168 return *this;
169 }
170
171 /**
172 Assign from a pure boost
173 */
178
179 /**
180 Assign from a 3-D rotation
181 */
189
190 /**
191 Assign from a linear algebra matrix of size at least 4x4,
192 which must support operator()(i,j) to obtain elements (0,3) thru (3,3).
193 Precondition: The matrix is assumed to be orthosymplectic. NO checking
194 or re-adjusting is performed.
195 */
196 template <class ForeignMatrix>
198 {
199 SetComponents(m(0, 0), m(0, 1), m(0, 2), m(0, 3), m(1, 0), m(1, 1), m(1, 2), m(1, 3), m(2, 0), m(2, 1), m(2, 2),
200 m(2, 3), m(3, 0), m(3, 1), m(3, 2), m(3, 3));
201 return *this;
202 }
203
204 /**
205 Re-adjust components to eliminate small deviations from a perfect
206 orthosyplectic matrix.
207 */
208 void Rectify();
209
210 // ======== Components ==============
211
212 /**
213 Set components from four orthosymplectic vectors (which must have methods
214 x(), y(), z(), and t()) which will be used as the columns of the
215 Lorentz rotation matrix. The values will be adjusted
216 so that the result will always be a good Lorentz rotation matrix.
217 */
218 template <class Foreign4Vector>
219 void
221 {
222 fM[kXX] = v1.x();
223 fM[kXY] = v2.x();
224 fM[kXZ] = v3.x();
225 fM[kXT] = v4.x();
226 fM[kYX] = v1.y();
227 fM[kYY] = v2.y();
228 fM[kYZ] = v3.y();
229 fM[kYT] = v4.y();
230 fM[kZX] = v1.z();
231 fM[kZY] = v2.z();
232 fM[kZZ] = v3.z();
233 fM[kZT] = v4.z();
234 fM[kTX] = v1.t();
235 fM[kTY] = v2.t();
236 fM[kTZ] = v3.t();
237 fM[kTT] = v4.t();
238 Rectify();
239 }
240
241 /**
242 Get components into four 4-vectors which will be the (orthosymplectic)
243 columns of the rotation matrix. (The 4-vector class must have a
244 constructor from 4 Scalars used as x, y, z, t)
245 */
246 template <class Foreign4Vector>
254
255 /**
256 Set the 16 matrix components given an iterator to the start of
257 the desired data, and another to the end (16 past start).
258 */
259 template <class IT>
260 void SetComponents(IT begin, IT end)
261 {
262 for (int i = 0; i < 16; ++i) {
263 fM[i] = *begin;
264 ++begin;
265 }
266 (void)end;
267 assert(end == begin);
268 }
269
270 /**
271 Get the 16 matrix components into data specified by an iterator begin
272 and another to the end of the desired data (16 past start).
273 */
274 template <class IT>
275 void GetComponents(IT begin, IT end) const
276 {
277 for (int i = 0; i < 16; ++i) {
278 *begin = fM[i];
279 ++begin;
280 }
281 (void)end;
282 assert(end == begin);
283 }
284
285 /**
286 Get the 16 matrix components into data specified by an iterator begin
287 */
288 template <class IT>
289 void GetComponents(IT begin) const
290 {
291 std::copy(fM + 0, fM + 16, begin);
292 }
293
294 /**
295 Set components from a linear algebra matrix of size at least 4x4,
296 which must support operator()(i,j) to obtain elements (0,0) thru (3,3).
297 Precondition: The matrix is assumed to be orthosymplectic. NO checking
298 or re-adjusting is performed.
299 */
300 template <class ForeignMatrix>
302 {
303 fM[kXX] = m(0, 0);
304 fM[kXY] = m(0, 1);
305 fM[kXZ] = m(0, 2);
306 fM[kXT] = m(0, 3);
307 fM[kYX] = m(1, 0);
308 fM[kYY] = m(1, 1);
309 fM[kYZ] = m(1, 2);
310 fM[kYT] = m(1, 3);
311 fM[kZX] = m(2, 0);
312 fM[kZY] = m(2, 1);
313 fM[kZZ] = m(2, 2);
314 fM[kZT] = m(2, 3);
315 fM[kTX] = m(3, 0);
316 fM[kTY] = m(3, 1);
317 fM[kTZ] = m(3, 2);
318 fM[kTT] = m(3, 3);
319 }
320
321 /**
322 Get components into a linear algebra matrix of size at least 4x4,
323 which must support operator()(i,j) for write access to elements
324 (0,0) thru (3,3).
325 */
326 template <class ForeignMatrix>
328 {
329 m(0, 0) = fM[kXX];
330 m(0, 1) = fM[kXY];
331 m(0, 2) = fM[kXZ];
332 m(0, 3) = fM[kXT];
333 m(1, 0) = fM[kYX];
334 m(1, 1) = fM[kYY];
335 m(1, 2) = fM[kYZ];
336 m(1, 3) = fM[kYT];
337 m(2, 0) = fM[kZX];
338 m(2, 1) = fM[kZY];
339 m(2, 2) = fM[kZZ];
340 m(2, 3) = fM[kZT];
341 m(3, 0) = fM[kTX];
342 m(3, 1) = fM[kTY];
343 m(3, 2) = fM[kTZ];
344 m(3, 3) = fM[kTT];
345 }
346
347 /**
348 Set the components from sixteen scalars -- UNCHECKED for orthosymplectic
349 */
352 {
353 fM[kXX] = xx;
354 fM[kXY] = xy;
355 fM[kXZ] = xz;
356 fM[kXT] = xt;
357 fM[kYX] = yx;
358 fM[kYY] = yy;
359 fM[kYZ] = yz;
360 fM[kYT] = yt;
361 fM[kZX] = zx;
362 fM[kZY] = zy;
363 fM[kZZ] = zz;
364 fM[kZT] = zt;
365 fM[kTX] = tx;
366 fM[kTY] = ty;
367 fM[kTZ] = tz;
368 fM[kTT] = tt;
369 }
370
371 /**
372 Get the sixteen components into sixteen scalars
373 */
376 Scalar &tt) const
377 {
378 xx = fM[kXX];
379 xy = fM[kXY];
380 xz = fM[kXZ];
381 xt = fM[kXT];
382 yx = fM[kYX];
383 yy = fM[kYY];
384 yz = fM[kYZ];
385 yt = fM[kYT];
386 zx = fM[kZX];
387 zy = fM[kZY];
388 zz = fM[kZZ];
389 zt = fM[kZT];
390 tx = fM[kTX];
391 ty = fM[kTY];
392 tz = fM[kTZ];
393 tt = fM[kTT];
394 }
395
396 // =========== operations ==============
397
398 /**
399 Lorentz transformation operation on a Minkowski ('Cartesian')
400 LorentzVector
401 */
403 {
404 Scalar x = v.Px();
405 Scalar y = v.Py();
406 Scalar z = v.Pz();
407 Scalar t = v.E();
409 fM[kXX] * x + fM[kXY] * y + fM[kXZ] * z + fM[kXT] * t, fM[kYX] * x + fM[kYY] * y + fM[kYZ] * z + fM[kYT] * t,
410 fM[kZX] * x + fM[kZY] * y + fM[kZZ] * z + fM[kZT] * t, fM[kTX] * x + fM[kTY] * y + fM[kTZ] * z + fM[kTT] * t);
411 }
412
413 /**
414 Lorentz transformation operation on a LorentzVector in any
415 coordinate system
416 */
417 template <class CoordSystem>
424
425 /**
426 Lorentz transformation operation on an arbitrary 4-vector v.
427 Preconditions: v must implement methods x(), y(), z(), and t()
428 and the arbitrary vector type must have a constructor taking (x,y,z,t)
429 */
430 template <class Foreign4Vector>
437
438 /**
439 Overload operator * for rotation on a vector
440 */
441 template <class A4Vector>
442 inline A4Vector operator*(const A4Vector &v) const
443 {
444 return operator()(v);
445 }
446
447 /**
448 Invert a Lorentz rotation in place
449 */
450 void Invert();
451
452 /**
453 Return inverse of a rotation
454 */
455 LorentzRotation Inverse() const;
456
457 // ========= Multi-Rotation Operations ===============
458
459 /**
460 Multiply (combine) this Lorentz rotation by another LorentzRotation
461 */
463
464 // #ifdef TODO_LATER
465 /**
466 Multiply (combine) this Lorentz rotation by a pure Lorentz boost
467 */
468 // TODO: implement directly in a more efficient way. Now are implemented
469 // going through another LorentzRotation
471 {
472 LorentzRotation tmp(b);
473 return (*this) * tmp;
474 }
476 {
477 LorentzRotation tmp(b);
478 return (*this) * tmp;
479 }
481 {
482 LorentzRotation tmp(b);
483 return (*this) * tmp;
484 }
486 {
487 LorentzRotation tmp(b);
488 return (*this) * tmp;
489 }
490
491 /**
492 Multiply (combine) this Lorentz rotation by a 3-D Rotation
493 */
495 {
496 LorentzRotation tmp(r);
497 return (*this) * tmp;
498 }
500 {
501 LorentzRotation tmp(a);
502 return (*this) * tmp;
503 }
505 {
506 LorentzRotation tmp(e);
507 return (*this) * tmp;
508 }
510 {
511 LorentzRotation tmp(q);
512 return (*this) * tmp;
513 }
515 {
516 LorentzRotation tmp(rx);
517 return (*this) * tmp;
518 }
520 {
521 LorentzRotation tmp(ry);
522 return (*this) * tmp;
523 }
525 {
526 LorentzRotation tmp(rz);
527 return (*this) * tmp;
528 }
529 // #endif
530
531 /**
532 Post-Multiply (on right) by another LorentzRotation, Boost, or
533 rotation : T = T*R
534 */
535 template <class R>
537 {
538 return *this = (*this) * r;
539 }
540
541 /**
542 Equality/inequality operators
543 */
544 bool operator==(const LorentzRotation &rhs) const
545 {
546 for (unsigned int i = 0; i < 16; ++i) {
547 if (fM[i] != rhs.fM[i])
548 return false;
549 }
550 return true;
551 }
552 bool operator!=(const LorentzRotation &rhs) const { return !operator==(rhs); }
553
554private:
556
557}; // LorentzRotation
558
559// ============ Class LorentzRotation ends here ============
560
561#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
562/**
563 Stream Output and Input
564 */
565// TODO - I/O should be put in the manipulator form
566std::ostream &operator<<(std::ostream &os, const LorentzRotation &r);
567
568// ============================================ vetted to here ============
569
570#ifdef NOTYET
571/**
572 Distance between two Lorentz rotations
573 */
574template <class R>
575inline typename Rotation3D::Scalar Distance(const Rotation3D &r1, const R &r2)
576{
577 return gv_detail::dist(r1, r2);
578}
579#endif
580
581#endif
582
583} // namespace ROOT_MATH_ARCH
584} // namespace ROOT
585
586#endif /* ROOT_MathX_GenVectorX_LorentzRotation */
#define b(i)
Definition RSha256.hxx:100
#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
Option_t Option_t TPoint xy
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:46
Class representing a Lorentz Boost along the X axis, by beta.
Definition BoostX.h:43
Class representing a Lorentz Boost along the Y axis, by beta.
Definition BoostY.h:43
Class representing a Lorentz Boost along the Z axis, by beta.
Definition BoostZ.h:43
Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matr...
Definition Boost.h:51
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 & operator=(LorentzRotation const &rhs)
Assign from another LorentzRotation.
LorentzRotation & operator=(Rotation3D const &r)
Assign from a 3-D rotation.
LorentzRotation & operator=(AxisAngle const &a)
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &v) const
Lorentz transformation operation on a LorentzVector in any coordinate system.
LorentzRotation & operator=(RotationY const &r)
LorentzRotation operator*(const BoostY &b) const
LorentzRotation Inverse() const
Return inverse of a rotation.
LorentzRotation(const Foreign4Vector &v1, const Foreign4Vector &v2, const Foreign4Vector &v3, const Foreign4Vector &v4)
Construct from four orthosymplectic vectors (which must have methods x(), y(), z() and t()) which wil...
LorentzRotation & operator=(Boost const &b)
Assign from a pure boost.
LorentzRotation & operator=(BoostX const &b)
LorentzRotation & operator=(RotationZ const &r)
void GetComponents(Scalar &xx, Scalar &xy, Scalar &xz, Scalar &xt, Scalar &yx, Scalar &yy, Scalar &yz, Scalar &yt, Scalar &zx, Scalar &zy, Scalar &zz, Scalar &zt, Scalar &tx, Scalar &ty, Scalar &tz, Scalar &tt) const
Get the sixteen components into sixteen scalars.
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 4x4, which must support operator()(i,...
LorentzRotation operator*(const Boost &b) const
Multiply (combine) this Lorentz rotation by a pure Lorentz boost.
LorentzVector< PxPyPzE4D< double > > operator()(const LorentzVector< PxPyPzE4D< double > > &v) const
Lorentz transformation operation on a Minkowski ('Cartesian') LorentzVector.
Foreign4Vector operator()(const Foreign4Vector &v) const
Lorentz transformation operation on an arbitrary 4-vector v.
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 4x4, which must support operator()(i,...
LorentzRotation()
Default constructor (identity transformation)
LorentzRotation & operator*=(const R &r)
Post-Multiply (on right) by another LorentzRotation, Boost, or rotation : T = T*R.
void GetComponents(IT begin) const
Get the 16 matrix components into data specified by an iterator begin.
void SetComponents(Scalar xx, Scalar xy, Scalar xz, Scalar xt, Scalar yx, Scalar yy, Scalar yz, Scalar yt, Scalar zx, Scalar zy, Scalar zz, Scalar zt, Scalar tx, Scalar ty, Scalar tz, Scalar tt)
Set the components from sixteen scalars – UNCHECKED for orthosymplectic.
LorentzRotation & operator=(RotationX const &r)
LorentzRotation & operator=(EulerAngles const &e)
LorentzRotation operator*(const BoostZ &b) const
LorentzRotation(Boost const &b)
Construct from a pure boost.
void SetComponents(const Foreign4Vector &v1, const Foreign4Vector &v2, const Foreign4Vector &v3, const Foreign4Vector &v4)
Set components from four orthosymplectic vectors (which must have methods x(), y(),...
LorentzRotation & operator=(const ForeignMatrix &m)
Assign from a linear algebra matrix of size at least 4x4, which must support operator()(i,...
LorentzRotation operator*(const Rotation3D &r) const
Multiply (combine) this Lorentz rotation by a 3-D Rotation.
LorentzRotation(LorentzRotation const &r)
Copy constructor.
LorentzRotation operator*(const RotationY &ry) const
void Rectify()
Re-adjust components to eliminate small deviations from a perfect orthosyplectic matrix.
LorentzRotation operator*(const RotationZ &rz) const
void SetComponents(IT begin, IT end)
Set the 16 matrix components given an iterator to the start of the desired data, and another to the e...
LorentzRotation operator*(const Quaternion &q) const
LorentzRotation(Scalar xx, Scalar xy, Scalar xz, Scalar xt, Scalar yx, Scalar yy, Scalar yz, Scalar yt, Scalar zx, Scalar zy, Scalar zz, Scalar zt, Scalar tx, Scalar ty, Scalar tz, Scalar tt)
Raw constructor from sixteen Scalar components (without any checking)
LorentzRotation operator*(const EulerAngles &e) const
LorentzRotation operator*(const BoostX &b) const
void Invert()
Invert a Lorentz rotation in place.
LorentzRotation operator*(const AxisAngle &a) const
void GetComponents(Foreign4Vector &v1, Foreign4Vector &v2, Foreign4Vector &v3, Foreign4Vector &v4) const
Get components into four 4-vectors which will be the (orthosymplectic) columns of the rotation matrix...
void GetComponents(IT begin, IT end) const
Get the 16 matrix components into data specified by an iterator begin and another to the end of the d...
LorentzRotation(IT begin, IT end)
Construct given a pair of pointers or iterators defining the beginning and end of an array of sixteen...
bool operator!=(const LorentzRotation &rhs) const
LorentzRotation(const ForeignMatrix &m)
Construct from a linear algebra matrix of size at least 4x4, which must support operator()(i,...
LorentzRotation operator*(const RotationX &rx) const
LorentzRotation & operator=(BoostZ const &b)
LorentzRotation & operator=(Quaternion const &q)
A4Vector operator*(const A4Vector &v) const
Overload operator * for rotation on a vector.
LorentzRotation & operator=(BoostY const &b)
bool operator==(const LorentzRotation &rhs) const
Equality/inequality operators.
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
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
double dist(Rotation3D const &r1, Rotation3D const &r2)
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:346
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:98
TMarker m
Definition textangle.C:8
auto * tt
Definition textangle.C:16