CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

LorentzRotation.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: LorentzRotation.cc,v 1.2 2003/08/13 20:00:14 garren Exp $
00003 // ---------------------------------------------------------------------------
00004 //
00005 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00006 //
00007 // This is the implementation basic parts of the HepLorentzRotation class.
00008 //
00009 // Some ZOOM methods involving construction from columns and decomposition 
00010 // into boost*rotation are split off into LorentzRotationC and LorentzRotationD
00011 
00012 #ifdef GNUPRAGMA
00013 #pragma implementation
00014 #endif
00015 
00016 #include "CLHEP/Vector/defs.h"
00017 #include "CLHEP/Vector/LorentzRotation.h"
00018 #include "CLHEP/Vector/ZMxpv.h"
00019 
00020 #include <iostream>
00021 #include <iomanip>
00022 
00023 namespace CLHEP  {
00024 
00025 // ----------  Constructors and Assignment:
00026 
00027 
00028 HepLorentzRotation & HepLorentzRotation::set
00029                                 (double bx, double by, double bz) {
00030   double bp2 = bx*bx + by*by + bz*bz;
00031   if (bp2 >= 1) {
00032     ZMthrowA (ZMxpvTachyonic(
00033     "Boost Vector supplied to set HepLorentzRotation represents speed >= c."));
00034   }    
00035   double gamma = 1.0 / std::sqrt(1.0 - bp2);
00036   double bgamma = gamma * gamma / (1.0 + gamma);
00037   mxx = 1.0 + bgamma * bx * bx;
00038   myy = 1.0 + bgamma * by * by;
00039   mzz = 1.0 + bgamma * bz * bz;
00040   mxy = myx = bgamma * bx * by;
00041   mxz = mzx = bgamma * bx * bz;
00042   myz = mzy = bgamma * by * bz;
00043   mxt = mtx = gamma * bx;
00044   myt = mty = gamma * by;
00045   mzt = mtz = gamma * bz;
00046   mtt = gamma;
00047   return *this;
00048 }
00049 
00050 HepLorentzRotation & HepLorentzRotation::set 
00051                 (const HepBoost & B, const HepRotation & R) {
00052   set (B.rep4x4());
00053   *this = matrixMultiplication ( R.rep4x4() );
00054   return *this;
00055 }
00056 
00057 HepLorentzRotation & HepLorentzRotation::set 
00058                 (const HepRotation & R, const HepBoost & B) {
00059   set (R.rep4x4());
00060   *this = matrixMultiplication ( B.rep4x4() );
00061   return *this;
00062 }
00063 
00064 // ----------  Accessors:
00065 
00066 // ------------  Subscripting:
00067 
00068 double HepLorentzRotation::operator () (int i, int j) const {
00069   if (i == 0) {
00070     if (j == 0) { return xx(); }
00071     if (j == 1) { return xy(); }
00072     if (j == 2) { return xz(); } 
00073     if (j == 3) { return xt(); } 
00074   } else if (i == 1) {
00075     if (j == 0) { return yx(); }
00076     if (j == 1) { return yy(); }
00077     if (j == 2) { return yz(); } 
00078     if (j == 3) { return yt(); } 
00079   } else if (i == 2) {
00080     if (j == 0) { return zx(); }
00081     if (j == 1) { return zy(); }
00082     if (j == 2) { return zz(); } 
00083     if (j == 3) { return zt(); } 
00084   } else if (i == 3) {
00085     if (j == 0) { return tx(); }
00086     if (j == 1) { return ty(); }
00087     if (j == 2) { return tz(); } 
00088     if (j == 3) { return tt(); } 
00089   } 
00090   std::cerr << "HepLorentzRotation subscripting: bad indeces "
00091             << "(" << i << "," << j << ")\n";
00092   return 0.0;
00093 } 
00094 
00095 // ---------- Application:
00096 
00097 
00098 // ---------- Comparison:
00099 
00100 int HepLorentzRotation::compare( const HepLorentzRotation & m1  ) const {
00101        if (mtt<m1.mtt) return -1; else if (mtt>m1.mtt) return 1;
00102   else if (mtz<m1.mtz) return -1; else if (mtz>m1.mtz) return 1;
00103   else if (mty<m1.mty) return -1; else if (mty>m1.mty) return 1;
00104   else if (mtx<m1.mtx) return -1; else if (mtx>m1.mtx) return 1;
00105 
00106   else if (mzt<m1.mzt) return -1; else if (mzt>m1.mzt) return 1;
00107   else if (mzz<m1.mzz) return -1; else if (mzz>m1.mzz) return 1;
00108   else if (mzy<m1.mzy) return -1; else if (mzy>m1.mzy) return 1;
00109   else if (mzx<m1.mzx) return -1; else if (mzx>m1.mzx) return 1;
00110 
00111   else if (myt<m1.myt) return -1; else if (myt>m1.myt) return 1;
00112   else if (myz<m1.myz) return -1; else if (myz>m1.myz) return 1;
00113   else if (myy<m1.myy) return -1; else if (myy>m1.myy) return 1;
00114   else if (myx<m1.myx) return -1; else if (myx>m1.myx) return 1;
00115 
00116   else if (mxt<m1.mxt) return -1; else if (mxt>m1.mxt) return 1;
00117   else if (mxz<m1.mxz) return -1; else if (mxz>m1.mxz) return 1;
00118   else if (mxy<m1.mxy) return -1; else if (mxy>m1.mxy) return 1;
00119   else if (mxx<m1.mxx) return -1; else if (mxx>m1.mxx) return 1;
00120 
00121   else return 0;
00122 }
00123 
00124 
00125 // ---------- Operations in the group of 4-Rotations
00126 
00127 HepLorentzRotation
00128 HepLorentzRotation::matrixMultiplication(const HepRep4x4 & m1) const {
00129   return HepLorentzRotation(
00130     mxx*m1.xx_ + mxy*m1.yx_ + mxz*m1.zx_ + mxt*m1.tx_,
00131     mxx*m1.xy_ + mxy*m1.yy_ + mxz*m1.zy_ + mxt*m1.ty_,
00132     mxx*m1.xz_ + mxy*m1.yz_ + mxz*m1.zz_ + mxt*m1.tz_,
00133     mxx*m1.xt_ + mxy*m1.yt_ + mxz*m1.zt_ + mxt*m1.tt_,
00134 
00135     myx*m1.xx_ + myy*m1.yx_ + myz*m1.zx_ + myt*m1.tx_,
00136     myx*m1.xy_ + myy*m1.yy_ + myz*m1.zy_ + myt*m1.ty_,
00137     myx*m1.xz_ + myy*m1.yz_ + myz*m1.zz_ + myt*m1.tz_,
00138     myx*m1.xt_ + myy*m1.yt_ + myz*m1.zt_ + myt*m1.tt_,
00139 
00140     mzx*m1.xx_ + mzy*m1.yx_ + mzz*m1.zx_ + mzt*m1.tx_,
00141     mzx*m1.xy_ + mzy*m1.yy_ + mzz*m1.zy_ + mzt*m1.ty_,
00142     mzx*m1.xz_ + mzy*m1.yz_ + mzz*m1.zz_ + mzt*m1.tz_,
00143     mzx*m1.xt_ + mzy*m1.yt_ + mzz*m1.zt_ + mzt*m1.tt_,
00144 
00145     mtx*m1.xx_ + mty*m1.yx_ + mtz*m1.zx_ + mtt*m1.tx_,
00146     mtx*m1.xy_ + mty*m1.yy_ + mtz*m1.zy_ + mtt*m1.ty_,
00147     mtx*m1.xz_ + mty*m1.yz_ + mtz*m1.zz_ + mtt*m1.tz_,
00148     mtx*m1.xt_ + mty*m1.yt_ + mtz*m1.zt_ + mtt*m1.tt_ );
00149 }
00150 
00151 HepLorentzRotation & HepLorentzRotation::rotateX(double delta) {
00152   double c1 = std::cos (delta);
00153   double s1 = std::sin (delta);
00154   HepLorentzVector rowy = row2();
00155   HepLorentzVector rowz = row3();
00156   HepLorentzVector r2 = c1 * rowy - s1 * rowz;
00157   HepLorentzVector r3 = s1 * rowy + c1 * rowz;
00158   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t(); 
00159   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
00160   return *this;
00161 }
00162 
00163 HepLorentzRotation & HepLorentzRotation::rotateY(double delta) {
00164   double c1 = std::cos (delta);
00165   double s1 = std::sin (delta);
00166   HepLorentzVector rowx = row1();
00167   HepLorentzVector rowz = row3();
00168   HepLorentzVector r1 =  c1 * rowx + s1 * rowz;
00169   HepLorentzVector r3 = -s1 * rowx + c1 * rowz;
00170   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t(); 
00171   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
00172   return *this;
00173 }
00174 
00175 HepLorentzRotation & HepLorentzRotation::rotateZ(double delta) {
00176   double c1 = std::cos (delta);
00177   double s1 = std::sin (delta);
00178   HepLorentzVector rowx = row1();
00179   HepLorentzVector rowy = row2();
00180   HepLorentzVector r1 = c1 * rowx - s1 * rowy;
00181   HepLorentzVector r2 = s1 * rowx + c1 * rowy;
00182   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t();
00183   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t();
00184   return *this;
00185 }
00186 
00187 HepLorentzRotation & HepLorentzRotation::boostX(double beta) {
00188   double b2 = beta*beta;
00189   if (b2 >= 1) {
00190     ZMthrowA (ZMxpvTachyonic(
00191     "Beta supplied to HepLorentzRotation::boostX represents speed >= c."));
00192   }    
00193   double g1  = 1.0/std::sqrt(1.0-b2);
00194   double bg = beta*g1;
00195   HepLorentzVector rowx = row1();
00196   HepLorentzVector rowt = row4();
00197   HepLorentzVector r1 = g1 * rowx + bg * rowt;
00198   HepLorentzVector r4 = bg * rowx + g1 * rowt;
00199   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t(); 
00200   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
00201   return *this;
00202 }
00203 
00204 HepLorentzRotation & HepLorentzRotation::boostY(double beta) {
00205   double b2 = beta*beta;
00206   if (b2 >= 1) {
00207     ZMthrowA (ZMxpvTachyonic(
00208     "Beta supplied to HepLorentzRotation::boostY represents speed >= c."));
00209   }    
00210   double g1  = 1.0/std::sqrt(1.0-b2);
00211   double bg = beta*g1;
00212   HepLorentzVector rowy = row2();
00213   HepLorentzVector rowt = row4();
00214   HepLorentzVector r2 = g1 * rowy + bg * rowt;
00215   HepLorentzVector r4 = bg * rowy + g1 * rowt;
00216   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t(); 
00217   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
00218   return *this;
00219 }
00220 
00221 HepLorentzRotation & HepLorentzRotation::boostZ(double beta) {
00222   double b2 = beta*beta;
00223   if (b2 >= 1) {
00224     ZMthrowA (ZMxpvTachyonic(
00225     "Beta supplied to HepLorentzRotation::boostZ represents speed >= c."));
00226   }    
00227   double g1  = 1.0/std::sqrt(1.0-b2);
00228   double bg = beta*g1;
00229   HepLorentzVector rowz = row3();
00230   HepLorentzVector rowt = row4();
00231   HepLorentzVector r3 = g1 * rowz + bg * rowt;
00232   HepLorentzVector r4 = bg * rowz + g1 * rowt;
00233   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
00234   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
00235   return *this;
00236 }
00237 
00238 std::ostream & HepLorentzRotation::print( std::ostream & os ) const {
00239   os << "\n   [ ( " <<
00240         std::setw(11) << std::setprecision(6) << xx() << "   " <<
00241         std::setw(11) << std::setprecision(6) << xy() << "   " <<
00242         std::setw(11) << std::setprecision(6) << xz() << "   " <<
00243         std::setw(11) << std::setprecision(6) << xt() << ")\n"
00244      << "     ( " <<
00245         std::setw(11) << std::setprecision(6) << yx() << "   " <<
00246         std::setw(11) << std::setprecision(6) << yy() << "   " <<
00247         std::setw(11) << std::setprecision(6) << yz() << "   " <<
00248         std::setw(11) << std::setprecision(6) << yt() << ")\n"
00249      << "     ( " <<
00250         std::setw(11) << std::setprecision(6) << zx() << "   " <<
00251         std::setw(11) << std::setprecision(6) << zy() << "   " <<
00252         std::setw(11) << std::setprecision(6) << zz() << "   " <<
00253         std::setw(11) << std::setprecision(6) << zt() << ")\n"
00254      << "     ( " <<
00255         std::setw(11) << std::setprecision(6) << tx() << "   " <<
00256         std::setw(11) << std::setprecision(6) << ty() << "   " <<
00257         std::setw(11) << std::setprecision(6) << tz() << "   " <<
00258         std::setw(11) << std::setprecision(6) << tt() << ") ]\n";
00259   return os;
00260 }
00261 
00262 HepLorentzRotation operator* ( const HepRotation & r,
00263                                const HepLorentzRotation & lt) {
00264   r.rep4x4();
00265   lt.rep4x4();
00266   return HepLorentzRotation( HepRep4x4(
00267          r.xx()*lt.xx() + r.xy()*lt.yx() + r.xz()*lt.zx() + r.xt()*lt.tx(),
00268          r.xx()*lt.xy() + r.xy()*lt.yy() + r.xz()*lt.zy() + r.xt()*lt.ty(),
00269          r.xx()*lt.xz() + r.xy()*lt.yz() + r.xz()*lt.zz() + r.xt()*lt.tz(),
00270          r.xx()*lt.xt() + r.xy()*lt.yt() + r.xz()*lt.zt() + r.xt()*lt.tt(),
00271 
00272          r.yx()*lt.xx() + r.yy()*lt.yx() + r.yz()*lt.zx() + r.yt()*lt.tx(),
00273          r.yx()*lt.xy() + r.yy()*lt.yy() + r.yz()*lt.zy() + r.yt()*lt.ty(),
00274          r.yx()*lt.xz() + r.yy()*lt.yz() + r.yz()*lt.zz() + r.yt()*lt.tz(),
00275          r.yx()*lt.xt() + r.yy()*lt.yt() + r.yz()*lt.zt() + r.yt()*lt.tt(),
00276 
00277          r.zx()*lt.xx() + r.zy()*lt.yx() + r.zz()*lt.zx() + r.zt()*lt.tx(),
00278          r.zx()*lt.xy() + r.zy()*lt.yy() + r.zz()*lt.zy() + r.zt()*lt.ty(),
00279          r.zx()*lt.xz() + r.zy()*lt.yz() + r.zz()*lt.zz() + r.zt()*lt.tz(),
00280          r.zx()*lt.xt() + r.zy()*lt.yt() + r.zz()*lt.zt() + r.zt()*lt.tt(),
00281 
00282          r.tx()*lt.xx() + r.ty()*lt.yx() + r.tz()*lt.zx() + r.tt()*lt.tx(),
00283          r.tx()*lt.xy() + r.ty()*lt.yy() + r.tz()*lt.zy() + r.tt()*lt.ty(),
00284          r.tx()*lt.xz() + r.ty()*lt.yz() + r.tz()*lt.zz() + r.tt()*lt.tz(),
00285          r.tx()*lt.xt() + r.ty()*lt.yt() + r.tz()*lt.zt() + r.tt()*lt.tt() ) );
00286 }
00287 
00288 
00289 const HepLorentzRotation HepLorentzRotation::IDENTITY;
00290 
00291 }  // namespace CLHEP

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7