Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Boost.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 FNAL MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for Boost
12 //
13 // Created by: Mark Fischler Mon Nov 1 2005
14 //
15 // Last update: $Id$
16 //
17 #ifndef ROOT_Math_GenVector_Boost
18 #define ROOT_Math_GenVector_Boost 1
19 
24 
25 #include "Math/GenVector/BoostX.h"
26 #include "Math/GenVector/BoostY.h"
27 #include "Math/GenVector/BoostZ.h"
28 
29 namespace ROOT {
30 
31  namespace Math {
32 
33 //__________________________________________________________________________________________
34  /**
35  Lorentz boost class with the (4D) transformation represented internally
36  by a 4x4 orthosymplectic matrix.
37  See also BoostX, BoostY and BoostZ for classes representing
38  specialized Lorentz boosts.
39  Also, the 3-D rotation classes can be considered to be special Lorentz
40  transformations which do not mix space and time components.
41 
42  @ingroup GenVector
43 
44  */
45 
46 class Boost {
47 
48 public:
49 
50  typedef double Scalar;
51 
52  enum ELorentzRotationMatrixIndex {
53  kLXX = 0, kLXY = 1, kLXZ = 2, kLXT = 3
54  , kLYX = 4, kLYY = 5, kLYZ = 6, kLYT = 7
55  , kLZX = 8, kLZY = 9, kLZZ = 10, kLZT = 11
56  , kLTX = 12, kLTY = 13, kLTZ = 14, kLTT = 15
57  };
58 
59  enum EBoostMatrixIndex {
60  kXX = 0, kXY = 1, kXZ = 2, kXT = 3
61  , kYY = 4, kYZ = 5, kYT = 6
62  , kZZ = 7, kZT = 8
63  , kTT = 9
64  };
65 
66  // ========== Constructors and Assignment =====================
67 
68  /**
69  Default constructor (identity transformation)
70  */
71  Boost() { SetIdentity(); }
72 
73  /**
74  Construct given a three Scalars beta_x, beta_y, and beta_z
75  */
76  Boost(Scalar beta_x, Scalar beta_y, Scalar beta_z)
77  { SetComponents(beta_x, beta_y, beta_z); }
78 
79  /**
80  Construct given a beta vector (which must have methods x(), y(), z())
81  */
82  template <class Avector>
83  explicit
84  Boost(const Avector & beta) { SetComponents(beta); }
85 
86  /**
87  Construct given a pair of pointers or iterators defining the
88  beginning and end of an array of three Scalars to use as beta_x, _y, and _z
89  */
90  template<class IT>
91  Boost(IT begin, IT end) { SetComponents(begin,end); }
92 
93  /**
94  copy constructor
95  */
96  Boost(Boost const & b) {
97  *this = b;
98  }
99 
100  /**
101  Construct from an axial boost
102  */
103 
104  explicit Boost( BoostX const & bx ) {SetComponents(bx.BetaVector());}
105  explicit Boost( BoostY const & by ) {SetComponents(by.BetaVector());}
106  explicit Boost( BoostZ const & bz ) {SetComponents(bz.BetaVector());}
107 
108  // The compiler-generated copy ctor, copy assignment, and dtor are OK.
109 
110  /**
111  Assignment operator
112  */
113  Boost &
114  operator=(Boost const & rhs ) {
115  for (unsigned int i=0; i < 10; ++i) {
116  fM[i] = rhs.fM[i];
117  }
118  return *this;
119  }
120 
121  /**
122  Assign from an axial pure boost
123  */
124  Boost &
125  operator=( BoostX const & bx ) { return operator=(Boost(bx)); }
126  Boost &
127  operator=( BoostY const & by ) { return operator=(Boost(by)); }
128  Boost &
129  operator=( BoostZ const & bz ) { return operator=(Boost(bz)); }
130 
131  /**
132  Re-adjust components to eliminate small deviations from a perfect
133  orthosyplectic matrix.
134  */
135  void Rectify();
136 
137  // ======== Components ==============
138 
139  /**
140  Set components from beta_x, beta_y, and beta_z
141  */
142  void
143  SetComponents (Scalar beta_x, Scalar beta_y, Scalar beta_z);
144 
145  /**
146  Get components into beta_x, beta_y, and beta_z
147  */
148  void
149  GetComponents (Scalar& beta_x, Scalar& beta_y, Scalar& beta_z) const;
150 
151  /**
152  Set components from a beta vector
153  */
154  template <class Avector>
155  void
156  SetComponents (const Avector & beta)
157  { SetComponents(beta.x(), beta.y(), beta.z()); }
158 
159  /**
160  Set given a pair of pointers or iterators defining the beginning and end of
161  an array of three Scalars to use as beta_x,beta _y, and beta_z
162  */
163  template<class IT>
164 #ifndef NDEBUG
165  void SetComponents(IT begin, IT end) {
166 #else
167  void SetComponents(IT begin, IT ) {
168 #endif
169  IT a = begin; IT b = ++begin; IT c = ++begin;
170  assert (++begin==end);
171  SetComponents (*a, *b, *c);
172  }
173 
174  /**
175  Get given a pair of pointers or iterators defining the beginning and end of
176  an array of three Scalars into which to place beta_x, beta_y, and beta_z
177  */
178  template<class IT>
179 #ifndef NDEBUG
180  void GetComponents(IT begin, IT end) const {
181 #else
182  void GetComponents(IT begin, IT ) const {
183 #endif
184  IT a = begin; IT b = ++begin; IT c = ++begin;
185  assert (++begin==end);
186  GetComponents (*a, *b, *c);
187  }
188 
189  /**
190  Get given a pointer or an iterator defining the beginning of
191  an array into which to place beta_x, beta_y, and beta_z
192  */
193  template<class IT>
194  void GetComponents(IT begin ) const {
195  double bx,by,bz = 0;
196  GetComponents (bx,by,bz);
197  *begin++ = bx;
198  *begin++ = by;
199  *begin = bz;
200  }
201 
202  /**
203  The beta vector for this boost
204  */
205  typedef DisplacementVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > XYZVector;
206  XYZVector BetaVector() const;
207 
208  /**
209  Get elements of internal 4x4 symmetric representation, into a data
210  array suitable for direct use as the components of a LorentzRotation
211  Note -- 16 Scalars will be written into the array; if the array is not
212  that large, then this will lead to undefined behavior.
213  */
214  void
215  GetLorentzRotation (Scalar r[]) const;
216 
217  // =========== operations ==============
218 
219  /**
220  Lorentz transformation operation on a Minkowski ('Cartesian')
221  LorentzVector
222  */
223  LorentzVector< ROOT::Math::PxPyPzE4D<double> >
224  operator() (const LorentzVector< ROOT::Math::PxPyPzE4D<double> > & v) const;
225 
226  /**
227  Lorentz transformation operation on a LorentzVector in any
228  coordinate system
229  */
230  template <class CoordSystem>
231  LorentzVector<CoordSystem>
232  operator() (const LorentzVector<CoordSystem> & v) const {
233  LorentzVector< PxPyPzE4D<double> > xyzt(v);
234  LorentzVector< PxPyPzE4D<double> > r_xyzt = operator()(xyzt);
235  return LorentzVector<CoordSystem> ( r_xyzt );
236  }
237 
238  /**
239  Lorentz transformation operation on an arbitrary 4-vector v.
240  Preconditions: v must implement methods x(), y(), z(), and t()
241  and the arbitrary vector type must have a constructor taking (x,y,z,t)
242  */
243  template <class Foreign4Vector>
244  Foreign4Vector
245  operator() (const Foreign4Vector & v) const {
246  LorentzVector< PxPyPzE4D<double> > xyzt(v);
247  LorentzVector< PxPyPzE4D<double> > r_xyzt = operator()(xyzt);
248  return Foreign4Vector ( r_xyzt.X(), r_xyzt.Y(), r_xyzt.Z(), r_xyzt.T() );
249  }
250 
251  /**
252  Overload operator * for boost on a vector
253  */
254  template <class A4Vector>
255  inline
256  A4Vector operator* (const A4Vector & v) const
257  {
258  return operator()(v);
259  }
260 
261  /**
262  Invert a Boost in place
263  */
264  void Invert();
265 
266  /**
267  Return inverse of a boost
268  */
269  Boost Inverse() const;
270 
271  /**
272  Equality/inequality operators
273  */
274  bool operator == (const Boost & rhs) const {
275  for (unsigned int i=0; i < 10; ++i) {
276  if( fM[i] != rhs.fM[i] ) return false;
277  }
278  return true;
279  }
280  bool operator != (const Boost & rhs) const {
281  return ! operator==(rhs);
282  }
283 
284 protected:
285 
286  void SetIdentity();
287 
288 private:
289 
290  Scalar fM[10];
291 
292 }; // Boost
293 
294 // ============ Class Boost ends here ============
295 
296 /**
297  Stream Output and Input
298  */
299  // TODO - I/O should be put in the manipulator form
300 
301 std::ostream & operator<< (std::ostream & os, const Boost & b);
302 
303 
304 } //namespace Math
305 } //namespace ROOT
306 
307 
308 
309 
310 
311 
312 
313 #endif /* ROOT_Math_GenVector_Boost */