LorentzRotationC.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 //
00006 // This is the implementation of that part of the HepLorentzRotation class
00007 // which is concerned with setting or constructing the transformation based 
00008 // on 4 supplied columns or rows.
00009 
00010 #ifdef GNUPRAGMA
00011 #pragma implementation
00012 #endif
00013 
00014 #include "CLHEP/Vector/LorentzRotation.h"
00015 #include "CLHEP/Vector/LorentzVector.h"
00016 
00017 #include <cmath>
00018 
00019 namespace CLHEP  {
00020 
00021 // ----------  Constructors and Assignment:
00022 
00023 HepLorentzRotation & HepLorentzRotation::set (const HepLorentzVector & ccol1,
00024                                               const HepLorentzVector & ccol2,
00025                                               const HepLorentzVector & ccol3,
00026                                               const HepLorentzVector & ccol4) {
00027   // First, test that the four cols do represent something close to a
00028   // true LT:
00029 
00030   ZMpvMetric_t savedMetric = HepLorentzVector::setMetric (TimePositive);
00031 
00032   if ( ccol4.getT() < 0 ) {
00033     std::cerr << "HepLorentzRotation::set() - "
00034       << "column 4 supplied to define transformation has negative T component"
00035       << std::endl;
00036     *this = HepLorentzRotation();
00037     return *this;
00038   }
00039 /*
00040   double u1u1 = ccol1.dot(ccol1);
00041   double f11  = std::fabs(u1u1 + 1.0);
00042   if ( f11 > Hep4RotationInterface::tolerance ) {
00043     std::cerr << "HepLorentzRotation::set() - "
00044       << "column 1 supplied for HepLorentzRotation has w*w != -1" << std::endl;
00045   }
00046   double u2u2 = ccol2.dot(ccol2);
00047   double f22  = std::fabs(u2u2 + 1.0);
00048   if ( f22 > Hep4RotationInterface::tolerance ) {
00049     std::cerr << "HepLorentzRotation::set() - "
00050       << "column 2 supplied for HepLorentzRotation has w*w != -1" << std::endl;
00051   }
00052   double u3u3 = ccol3.dot(ccol3);
00053   double f33  = std::fabs(u3u3 + 1.0);
00054   if ( f33 > Hep4RotationInterface::tolerance ) {
00055     std::cerr << "HepLorentzRotation::set() - "
00056       << "column 3 supplied for HepLorentzRotation has w*w != -1" << std::endl;
00057   }
00058   double u4u4 = ccol4.dot(ccol4);
00059   double f44  = std::fabs(u4u4 - 1.0);
00060   if ( f44 > Hep4RotationInterface::tolerance ) {
00061     std::cerr << "HepLorentzRotation::set() - "
00062       << "column 4 supplied for HepLorentzRotation has w*w != +1" << std::endl;
00063   }
00064 
00065   double u1u2 = ccol1.dot(ccol2);
00066   double f12  = std::fabs(u1u2);
00067   if ( f12 > Hep4RotationInterface::tolerance ) {
00068     std::cerr << "HepLorentzRotation::set() - "
00069       << "columns 1 and 2 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00070   }
00071   double u1u3 = ccol1.dot(ccol3);
00072   double f13  = std::fabs(u1u3);
00073 
00074   if ( f13 > Hep4RotationInterface::tolerance ) {
00075     std::cerr << "HepLorentzRotation::set() - "
00076       << "columns 1 and 3 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00077   }
00078   double u1u4 = ccol1.dot(ccol4);
00079   double f14  = std::fabs(u1u4);
00080   if ( f14 > Hep4RotationInterface::tolerance ) {
00081     std::cerr << "HepLorentzRotation::set() - "
00082       << "columns 1 and 4 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00083   }
00084   double u2u3 = ccol2.dot(ccol3);
00085   double f23  = std::fabs(u2u3);
00086   if ( f23 > Hep4RotationInterface::tolerance ) {
00087     std::cerr << "HepLorentzRotation::set() - "
00088       << "columns 2 and 3 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00089   }
00090   double u2u4 = ccol2.dot(ccol4);
00091   double f24  = std::fabs(u2u4);
00092   if ( f24 > Hep4RotationInterface::tolerance ) {
00093     std::cerr << "HepLorentzRotation::set() - "
00094       << "columns 2 and 4 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00095   }
00096   double u3u4 = ccol3.dot(ccol4);
00097   double f34  = std::fabs(u3u4);
00098   if ( f34 > Hep4RotationInterface::tolerance ) {
00099     std::cerr << "HepLorentzRotation::set() - "
00100       << "columns 3 and 4 supplied for HepLorentzRotation have non-zero dot" << std::endl;
00101   }
00102 */
00103   // Our strategy will be to order the cols, then do gram-schmidt on them
00104   // (that is, remove the components of col d that make it non-orthogonal to
00105   // col c, normalize that, then remove the components of b that make it
00106   // non-orthogonal to d and to c, normalize that, etc.
00107 
00108   // Because col4, the time col, is most likely to be computed directly, we
00109   // will start from there and work left-ward.
00110 
00111   HepLorentzVector a, b, c, d;
00112   bool isLorentzTransformation = true;
00113   double norm;
00114 
00115   d = ccol4;
00116   norm = d.dot(d);
00117   if (norm <= 0.0) {
00118     isLorentzTransformation = false;
00119     if (norm == 0.0) {
00120       d = T_HAT4;       // Moot, but let's keep going...
00121       norm = 1.0;
00122     }
00123   }
00124   d /= norm;
00125 
00126   c = ccol3 - ccol3.dot(d) * d;
00127   norm = -c.dot(c);
00128   if (norm <= 0.0) {
00129     isLorentzTransformation = false;
00130     if (norm == 0.0) {
00131       c = Z_HAT4;       // Moot
00132       norm = 1.0;
00133     }
00134   }
00135   c /= norm;
00136 
00137   b = ccol2 + ccol2.dot(c) * c - ccol2.dot(d) * d;
00138   norm = -b.dot(b);
00139   if (norm <= 0.0) {
00140     isLorentzTransformation = false;
00141     if (norm == 0.0) {
00142       b = Y_HAT4;       // Moot
00143       norm = 1.0;
00144     }
00145   }
00146   b /= norm;
00147 
00148   a = ccol1 + ccol1.dot(b) * b + ccol1.dot(c) * c - ccol1.dot(d) * d;
00149   norm = -a.dot(a);
00150   if (norm <= 0.0) {
00151     isLorentzTransformation = false;
00152     if (norm == 0.0) {
00153       a = X_HAT4;       // Moot
00154       norm = 1.0;
00155     }
00156   }
00157   a /= norm;
00158 
00159   if ( !isLorentzTransformation ) {
00160       std::cerr << "HepLorentzRotation::set() - "
00161         << "cols 1-4 supplied to define transformation form either \n"
00162         << "       a boosted reflection or a tachyonic transformation -- \n"
00163         << "       transformation will be set to Identity " << std::endl;
00164 
00165     *this = HepLorentzRotation();
00166   }
00167 
00168   if ( isLorentzTransformation ) {
00169     mxx = a.x(); myx = a.y(); mzx = a.z(); mtx = a.t();
00170     mxy = b.x(); myy = b.y(); mzy = b.z(); mty = b.t();
00171     mxz = c.x(); myz = c.y(); mzz = c.z(); mtz = c.t();
00172     mxt = d.x(); myt = d.y(); mzt = d.z(); mtt = d.t();
00173   }
00174 
00175   HepLorentzVector::setMetric (savedMetric);
00176   return *this;
00177 
00178 } // set ( col1, col2, col3, col4 )
00179 
00180 HepLorentzRotation & HepLorentzRotation::setRows
00181          (const HepLorentzVector & rrow1,
00182           const HepLorentzVector & rrow2,
00183           const HepLorentzVector & rrow3,
00184           const HepLorentzVector & rrow4) {
00185   // Set based on using those rows as columns:
00186   set (rrow1, rrow2, rrow3, rrow4);
00187   // Now transpose in place:
00188   register double q1, q2, q3;
00189   q1  = mxy;  q2  = mxz;  q3  = mxt;
00190   mxy = myx;  mxz = mzx;  mxt = mtx;
00191   myx = q1;   mzx = q2;   mtx = q3;
00192   q1  = myz;  q2  = myt;  q3  = mzt;
00193   myz = mzy;  myt = mty;  mzt = mtz;
00194   mzy = q1;   mty = q2;   mtz = q3;
00195   return *this;
00196 } // LorentzTransformation::setRows(row1 ... row4)
00197 
00198 HepLorentzRotation::HepLorentzRotation ( const HepLorentzVector & ccol1,
00199                                          const HepLorentzVector & ccol2,
00200                                          const HepLorentzVector & ccol3,
00201                                          const HepLorentzVector & ccol4 ) 
00202 {
00203   set ( ccol1, ccol2, ccol3, ccol4 );
00204 }
00205 
00206 }  // namespace CLHEP
00207 

Generated on Mon May 27 17:50:31 2013 for Geant4 by  doxygen 1.4.7