LorentzRotation.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: LorentzRotation.cxx 24923 2008-07-23 15:43:05Z moneta $
00002 // Authors: W. Brown, M. Fischler, L. Moneta    2005  
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team                    *
00007   *                                                                    *
00008   *                                                                    *
00009   **********************************************************************/
00010 
00011 // Header file for class LorentzRotation, a 4x4 matrix representation of
00012 // a general Lorentz transformation
00013 //
00014 // Created by: Mark Fischler Mon Aug 8  2005
00015 //
00016 
00017 #include "Math/GenVector/GenVectorIO.h"
00018 
00019 #include "Math/GenVector/LorentzRotation.h"
00020 #include "Math/GenVector/LorentzVector.h"
00021 #include "Math/GenVector/PxPyPzE4D.h"
00022 #include "Math/GenVector/GenVector_exception.h"
00023 
00024 #include <cmath>
00025 #include <algorithm>
00026 
00027 #include "Math/GenVector/Rotation3D.h"
00028 #include "Math/GenVector/RotationX.h"
00029 #include "Math/GenVector/RotationY.h"
00030 #include "Math/GenVector/RotationZ.h"
00031 
00032 namespace ROOT {
00033 
00034 namespace Math {
00035 
00036 LorentzRotation::LorentzRotation() {
00037    // constructor of an identity LR
00038    fM[kXX] = 1.0;  fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kXT] = 0.0;
00039    fM[kYX] = 0.0;  fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kYT] = 0.0;
00040    fM[kZX] = 0.0;  fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kZT] = 0.0;
00041    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00042 }
00043 
00044 LorentzRotation::LorentzRotation(Rotation3D  const & r) {  
00045    // construct from  Rotation3D
00046    r.GetComponents ( fM[kXX], fM[kXY], fM[kXZ],
00047                      fM[kYX], fM[kYY], fM[kYZ],
00048                      fM[kZX], fM[kZY], fM[kZZ] );
00049    fM[kXT] = 0.0;
00050    fM[kYT] = 0.0;
00051    fM[kZT] = 0.0;
00052    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00053 }
00054 
00055 LorentzRotation::LorentzRotation(AxisAngle  const & a) {  
00056    // construct from  AxisAngle
00057    const Rotation3D r(a);
00058    r.GetComponents ( fM[kXX], fM[kXY], fM[kXZ],
00059                      fM[kYX], fM[kYY], fM[kYZ],
00060                      fM[kZX], fM[kZY], fM[kZZ] );
00061    fM[kXT] = 0.0;
00062    fM[kYT] = 0.0;
00063    fM[kZT] = 0.0;
00064    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00065 }
00066 
00067 LorentzRotation::LorentzRotation(EulerAngles  const & e) {  
00068    // construct from  EulerAngles
00069    const Rotation3D r(e);
00070    r.GetComponents ( fM[kXX], fM[kXY], fM[kXZ],
00071                      fM[kYX], fM[kYY], fM[kYZ],
00072                      fM[kZX], fM[kZY], fM[kZZ] );
00073    fM[kXT] = 0.0;
00074    fM[kYT] = 0.0;
00075    fM[kZT] = 0.0;
00076    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00077 }
00078 
00079 LorentzRotation::LorentzRotation(Quaternion  const & q) {  
00080    // construct from Quaternion
00081    const Rotation3D r(q);
00082    r.GetComponents ( fM[kXX], fM[kXY], fM[kXZ],
00083                      fM[kYX], fM[kYY], fM[kYZ],
00084                      fM[kZX], fM[kZY], fM[kZZ] );
00085    fM[kXT] = 0.0;
00086    fM[kYT] = 0.0;
00087    fM[kZT] = 0.0;
00088    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00089 }
00090 
00091 LorentzRotation::LorentzRotation(RotationX  const & r) {  
00092    // construct from  RotationX
00093    Scalar s = r.SinAngle();
00094    Scalar c = r.CosAngle();
00095    fM[kXX] = 1.0;  fM[kXY] = 0.0; fM[kXZ] = 0.0; fM[kXT] = 0.0;
00096    fM[kYX] = 0.0;  fM[kYY] =  c ; fM[kYZ] = -s ; fM[kYT] = 0.0;
00097    fM[kZX] = 0.0;  fM[kZY] =  s ; fM[kZZ] =  c ; fM[kZT] = 0.0;
00098    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00099 }
00100 
00101 LorentzRotation::LorentzRotation(RotationY  const & r) {  
00102    // construct from  RotationY
00103    Scalar s = r.SinAngle();
00104    Scalar c = r.CosAngle();
00105    fM[kXX] =  c ;  fM[kXY] = 0.0; fM[kXZ] =  s ; fM[kXT] = 0.0;
00106    fM[kYX] = 0.0;  fM[kYY] = 1.0; fM[kYZ] = 0.0; fM[kYT] = 0.0;
00107    fM[kZX] = -s ;  fM[kZY] = 0.0; fM[kZZ] =  c ; fM[kZT] = 0.0;
00108    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00109 }
00110 
00111 LorentzRotation::LorentzRotation(RotationZ  const & r) {  
00112    // construct from  RotationX
00113    Scalar s = r.SinAngle();
00114    Scalar c = r.CosAngle();
00115    fM[kXX] =  c ;  fM[kXY] = -s ; fM[kXZ] = 0.0; fM[kXT] = 0.0;
00116    fM[kYX] =  s ;  fM[kYY] =  c ; fM[kYZ] = 0.0; fM[kYT] = 0.0;
00117    fM[kZX] = 0.0;  fM[kZY] = 0.0; fM[kZZ] = 1.0; fM[kZT] = 0.0;
00118    fM[kTX] = 0.0;  fM[kTY] = 0.0; fM[kTZ] = 0.0; fM[kTT] = 1.0;
00119 }
00120 
00121 void 
00122 LorentzRotation::Rectify() {
00123    // Assuming the representation of this is close to a true Lorentz Rotation,
00124    // but may have drifted due to round-off error from many operations,
00125    // this forms an "exact" orthosymplectic matrix for the Lorentz Rotation
00126    // again.
00127    
00128    typedef LorentzVector< PxPyPzE4D<Scalar> > FourVector;
00129    if (fM[kTT] <= 0) {
00130       GenVector::Throw ( 
00131                               "LorentzRotation:Rectify(): Non-positive TT component - cannot rectify");
00132       return;
00133    }  
00134    FourVector t ( fM[kTX], fM[kTY], fM[kTZ], fM[kTT] );
00135    Scalar m2 = t.M2();
00136    if ( m2 <= 0 ) {
00137       GenVector::Throw ( 
00138                               "LorentzRotation:Rectify(): Non-timelike time row - cannot rectify");
00139       return;
00140    }
00141    t /= std::sqrt(m2);
00142    FourVector z ( fM[kZX], fM[kZY], fM[kZZ], fM[kZT] );
00143    z = z - z.Dot(t)*t;
00144    m2 = z.M2();
00145    if ( m2 >= 0 ) {
00146       GenVector::Throw ( 
00147                               "LorentzRotation:Rectify(): Non-spacelike Z row projection - "
00148                               "cannot rectify");
00149       return;
00150    }
00151    z /= std::sqrt(-m2);
00152    FourVector y ( fM[kYX], fM[kYY], fM[kYZ], fM[kYT] );
00153    y = y - y.Dot(t)*t - y.Dot(z)*z;
00154    m2 = y.M2();
00155    if ( m2 >= 0 ) {
00156       GenVector::Throw ( 
00157                               "LorentzRotation:Rectify(): Non-spacelike Y row projection - "
00158                               "cannot rectify");
00159       return;
00160    }
00161    y /= std::sqrt(-m2);
00162    FourVector x ( fM[kXX], fM[kXY], fM[kXZ], fM[kXT] );
00163    x = x - x.Dot(t)*t - x.Dot(z)*z - x.Dot(y)*y;
00164    m2 = x.M2();
00165    if ( m2 >= 0 ) {
00166       GenVector::Throw ( 
00167                               "LorentzRotation:Rectify(): Non-spacelike X row projection - "
00168                               "cannot rectify");
00169       return;
00170    }
00171    x /= std::sqrt(-m2);
00172 }
00173 
00174 
00175 void LorentzRotation::Invert() {
00176    // invert modifying current content
00177    Scalar temp;
00178    temp = fM[kXY]; fM[kXY] =  fM[kYX]; fM[kYX] =  temp;  
00179    temp = fM[kXZ]; fM[kXZ] =  fM[kZX]; fM[kZX] =  temp;  
00180    temp = fM[kYZ]; fM[kYZ] =  fM[kZY]; fM[kZY] =  temp;  
00181    temp = fM[kXT]; fM[kXT] = -fM[kTX]; fM[kTX] = -temp;  
00182    temp = fM[kYT]; fM[kYT] = -fM[kTY]; fM[kTY] = -temp;  
00183    temp = fM[kZT]; fM[kZT] = -fM[kTZ]; fM[kTZ] = -temp;  
00184 }
00185 
00186 LorentzRotation LorentzRotation::Inverse() const {
00187    // return an inverse LR
00188    return LorentzRotation 
00189    (  fM[kXX],  fM[kYX],  fM[kZX], -fM[kTX]
00190       ,  fM[kXY],  fM[kYY],  fM[kZY], -fM[kTY]
00191       ,  fM[kXZ],  fM[kYZ],  fM[kZZ], -fM[kTZ]
00192       , -fM[kXT], -fM[kYT], -fM[kZT],  fM[kTT]
00193       );
00194 }
00195 
00196 LorentzRotation LorentzRotation::operator * (const LorentzRotation & r) const {
00197    // combination with another LR
00198    return LorentzRotation 
00199    ( fM[kXX]*r.fM[kXX] + fM[kXY]*r.fM[kYX] + fM[kXZ]*r.fM[kZX] + fM[kXT]*r.fM[kTX]
00200      , fM[kXX]*r.fM[kXY] + fM[kXY]*r.fM[kYY] + fM[kXZ]*r.fM[kZY] + fM[kXT]*r.fM[kTY]
00201      , fM[kXX]*r.fM[kXZ] + fM[kXY]*r.fM[kYZ] + fM[kXZ]*r.fM[kZZ] + fM[kXT]*r.fM[kTZ]
00202      , fM[kXX]*r.fM[kXT] + fM[kXY]*r.fM[kYT] + fM[kXZ]*r.fM[kZT] + fM[kXT]*r.fM[kTT]
00203      , fM[kYX]*r.fM[kXX] + fM[kYY]*r.fM[kYX] + fM[kYZ]*r.fM[kZX] + fM[kYT]*r.fM[kTX]
00204      , fM[kYX]*r.fM[kXY] + fM[kYY]*r.fM[kYY] + fM[kYZ]*r.fM[kZY] + fM[kYT]*r.fM[kTY]
00205      , fM[kYX]*r.fM[kXZ] + fM[kYY]*r.fM[kYZ] + fM[kYZ]*r.fM[kZZ] + fM[kYT]*r.fM[kTZ]
00206      , fM[kYX]*r.fM[kXT] + fM[kYY]*r.fM[kYT] + fM[kYZ]*r.fM[kZT] + fM[kYT]*r.fM[kTT]
00207      , fM[kZX]*r.fM[kXX] + fM[kZY]*r.fM[kYX] + fM[kZZ]*r.fM[kZX] + fM[kZT]*r.fM[kTX]
00208      , fM[kZX]*r.fM[kXY] + fM[kZY]*r.fM[kYY] + fM[kZZ]*r.fM[kZY] + fM[kZT]*r.fM[kTY]
00209      , fM[kZX]*r.fM[kXZ] + fM[kZY]*r.fM[kYZ] + fM[kZZ]*r.fM[kZZ] + fM[kZT]*r.fM[kTZ]
00210      , fM[kZX]*r.fM[kXT] + fM[kZY]*r.fM[kYT] + fM[kZZ]*r.fM[kZT] + fM[kZT]*r.fM[kTT]
00211      , fM[kTX]*r.fM[kXX] + fM[kTY]*r.fM[kYX] + fM[kTZ]*r.fM[kZX] + fM[kTT]*r.fM[kTX]
00212      , fM[kTX]*r.fM[kXY] + fM[kTY]*r.fM[kYY] + fM[kTZ]*r.fM[kZY] + fM[kTT]*r.fM[kTY]
00213      , fM[kTX]*r.fM[kXZ] + fM[kTY]*r.fM[kYZ] + fM[kTZ]*r.fM[kZZ] + fM[kTT]*r.fM[kTZ]
00214      , fM[kTX]*r.fM[kXT] + fM[kTY]*r.fM[kYT] + fM[kTZ]*r.fM[kZT] + fM[kTT]*r.fM[kTT]
00215      );    
00216 }
00217 
00218 
00219 std::ostream & operator<< (std::ostream & os, const LorentzRotation & r) {
00220    // TODO - this will need changing for machine-readable issues
00221    //        and even the human readable form needs formatiing improvements
00222    double m[16];
00223    r.GetComponents(m, m+16);
00224    os << "\n" << m[0]  << "  " << m[1]  << "  " << m[2]  << "  " << m[3]; 
00225    os << "\n" << m[4]  << "  " << m[5]  << "  " << m[6]  << "  " << m[7]; 
00226    os << "\n" << m[8]  << "  " << m[9]  << "  " << m[10] << "  " << m[11]; 
00227    os << "\n" << m[12] << "  " << m[13] << "  " << m[14] << "  " << m[15] << "\n";
00228    return os;
00229 }
00230 
00231 
00232 } //namespace Math
00233 } //namespace ROOT

Generated on Tue Jul 5 14:33:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1