CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
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 / 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 & m ) const { 00101 if (mtt<m.mtt) return -1; else if (mtt>m.mtt) return 1; 00102 else if (mtz<m.mtz) return -1; else if (mtz>m.mtz) return 1; 00103 else if (mty<m.mty) return -1; else if (mty>m.mty) return 1; 00104 else if (mtx<m.mtx) return -1; else if (mtx>m.mtx) return 1; 00105 00106 else if (mzt<m.mzt) return -1; else if (mzt>m.mzt) return 1; 00107 else if (mzz<m.mzz) return -1; else if (mzz>m.mzz) return 1; 00108 else if (mzy<m.mzy) return -1; else if (mzy>m.mzy) return 1; 00109 else if (mzx<m.mzx) return -1; else if (mzx>m.mzx) return 1; 00110 00111 else if (myt<m.myt) return -1; else if (myt>m.myt) return 1; 00112 else if (myz<m.myz) return -1; else if (myz>m.myz) return 1; 00113 else if (myy<m.myy) return -1; else if (myy>m.myy) return 1; 00114 else if (myx<m.myx) return -1; else if (myx>m.myx) return 1; 00115 00116 else if (mxt<m.mxt) return -1; else if (mxt>m.mxt) return 1; 00117 else if (mxz<m.mxz) return -1; else if (mxz>m.mxz) return 1; 00118 else if (mxy<m.mxy) return -1; else if (mxy>m.mxy) return 1; 00119 else if (mxx<m.mxx) return -1; else if (mxx>m.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 & m) const { 00129 return HepLorentzRotation( 00130 mxx*m.xx_ + mxy*m.yx_ + mxz*m.zx_ + mxt*m.tx_, 00131 mxx*m.xy_ + mxy*m.yy_ + mxz*m.zy_ + mxt*m.ty_, 00132 mxx*m.xz_ + mxy*m.yz_ + mxz*m.zz_ + mxt*m.tz_, 00133 mxx*m.xt_ + mxy*m.yt_ + mxz*m.zt_ + mxt*m.tt_, 00134 00135 myx*m.xx_ + myy*m.yx_ + myz*m.zx_ + myt*m.tx_, 00136 myx*m.xy_ + myy*m.yy_ + myz*m.zy_ + myt*m.ty_, 00137 myx*m.xz_ + myy*m.yz_ + myz*m.zz_ + myt*m.tz_, 00138 myx*m.xt_ + myy*m.yt_ + myz*m.zt_ + myt*m.tt_, 00139 00140 mzx*m.xx_ + mzy*m.yx_ + mzz*m.zx_ + mzt*m.tx_, 00141 mzx*m.xy_ + mzy*m.yy_ + mzz*m.zy_ + mzt*m.ty_, 00142 mzx*m.xz_ + mzy*m.yz_ + mzz*m.zz_ + mzt*m.tz_, 00143 mzx*m.xt_ + mzy*m.yt_ + mzz*m.zt_ + mzt*m.tt_, 00144 00145 mtx*m.xx_ + mty*m.yx_ + mtz*m.zx_ + mtt*m.tx_, 00146 mtx*m.xy_ + mty*m.yy_ + mtz*m.zy_ + mtt*m.ty_, 00147 mtx*m.xz_ + mty*m.yz_ + mtz*m.zz_ + mtt*m.tz_, 00148 mtx*m.xt_ + mty*m.yt_ + mtz*m.zt_ + mtt*m.tt_ ); 00149 } 00150 00151 HepLorentzRotation & HepLorentzRotation::rotateX(double delta) { 00152 double c = cos (delta); 00153 double s = sin (delta); 00154 HepLorentzVector rowy = row2(); 00155 HepLorentzVector rowz = row3(); 00156 HepLorentzVector r2 = c * rowy - s * rowz; 00157 HepLorentzVector r3 = s * rowy + c * 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 c = cos (delta); 00165 double s = sin (delta); 00166 HepLorentzVector rowx = row1(); 00167 HepLorentzVector rowz = row3(); 00168 HepLorentzVector r1 = c * rowx + s * rowz; 00169 HepLorentzVector r3 = -s * rowx + c * 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 c = cos (delta); 00177 double s = sin (delta); 00178 HepLorentzVector rowx = row1(); 00179 HepLorentzVector rowy = row2(); 00180 HepLorentzVector r1 = c * rowx - s * rowy; 00181 HepLorentzVector r2 = s * rowx + c * 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 g = 1.0/sqrt(1.0-b2); 00194 double bg = beta*g; 00195 HepLorentzVector rowx = row1(); 00196 HepLorentzVector rowt = row4(); 00197 HepLorentzVector r1 = g * rowx + bg * rowt; 00198 HepLorentzVector r4 = bg * rowx + g * 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 g = 1.0/sqrt(1.0-b2); 00211 double bg = beta*g; 00212 HepLorentzVector rowy = row2(); 00213 HepLorentzVector rowt = row4(); 00214 HepLorentzVector r2 = g * rowy + bg * rowt; 00215 HepLorentzVector r4 = bg * rowy + g * 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 g = 1.0/sqrt(1.0-b2); 00228 double bg = beta*g; 00229 HepLorentzVector rowz = row3(); 00230 HepLorentzVector rowt = row4(); 00231 HepLorentzVector r3 = g * rowz + bg * rowt; 00232 HepLorentzVector r4 = bg * rowz + g * 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 // using std::setw; 00240 // using std::setprecision; 00241 os << "\n [ ( " << 00242 std::setw(11) << std::setprecision(6) << xx() << " " << 00243 std::setw(11) << std::setprecision(6) << xy() << " " << 00244 std::setw(11) << std::setprecision(6) << xz() << " " << 00245 std::setw(11) << std::setprecision(6) << xt() << ")\n" 00246 << " ( " << 00247 std::setw(11) << std::setprecision(6) << yx() << " " << 00248 std::setw(11) << std::setprecision(6) << yy() << " " << 00249 std::setw(11) << std::setprecision(6) << yz() << " " << 00250 std::setw(11) << std::setprecision(6) << yt() << ")\n" 00251 << " ( " << 00252 std::setw(11) << std::setprecision(6) << zx() << " " << 00253 std::setw(11) << std::setprecision(6) << zy() << " " << 00254 std::setw(11) << std::setprecision(6) << zz() << " " << 00255 std::setw(11) << std::setprecision(6) << zt() << ")\n" 00256 << " ( " << 00257 std::setw(11) << std::setprecision(6) << tx() << " " << 00258 std::setw(11) << std::setprecision(6) << ty() << " " << 00259 std::setw(11) << std::setprecision(6) << tz() << " " << 00260 std::setw(11) << std::setprecision(6) << tt() << ") ]\n"; 00261 return os; 00262 } 00263 00264 HepLorentzRotation operator* ( const HepRotation & r, 00265 const HepLorentzRotation & lt) { 00266 r.rep4x4(); 00267 lt.rep4x4(); 00268 return HepLorentzRotation( HepRep4x4( 00269 r.xx()*lt.xx() + r.xy()*lt.yx() + r.xz()*lt.zx() + r.xt()*lt.tx(), 00270 r.xx()*lt.xy() + r.xy()*lt.yy() + r.xz()*lt.zy() + r.xt()*lt.ty(), 00271 r.xx()*lt.xz() + r.xy()*lt.yz() + r.xz()*lt.zz() + r.xt()*lt.tz(), 00272 r.xx()*lt.xt() + r.xy()*lt.yt() + r.xz()*lt.zt() + r.xt()*lt.tt(), 00273 00274 r.yx()*lt.xx() + r.yy()*lt.yx() + r.yz()*lt.zx() + r.yt()*lt.tx(), 00275 r.yx()*lt.xy() + r.yy()*lt.yy() + r.yz()*lt.zy() + r.yt()*lt.ty(), 00276 r.yx()*lt.xz() + r.yy()*lt.yz() + r.yz()*lt.zz() + r.yt()*lt.tz(), 00277 r.yx()*lt.xt() + r.yy()*lt.yt() + r.yz()*lt.zt() + r.yt()*lt.tt(), 00278 00279 r.zx()*lt.xx() + r.zy()*lt.yx() + r.zz()*lt.zx() + r.zt()*lt.tx(), 00280 r.zx()*lt.xy() + r.zy()*lt.yy() + r.zz()*lt.zy() + r.zt()*lt.ty(), 00281 r.zx()*lt.xz() + r.zy()*lt.yz() + r.zz()*lt.zz() + r.zt()*lt.tz(), 00282 r.zx()*lt.xt() + r.zy()*lt.yt() + r.zz()*lt.zt() + r.zt()*lt.tt(), 00283 00284 r.tx()*lt.xx() + r.ty()*lt.yx() + r.tz()*lt.zx() + r.tt()*lt.tx(), 00285 r.tx()*lt.xy() + r.ty()*lt.yy() + r.tz()*lt.zy() + r.tt()*lt.ty(), 00286 r.tx()*lt.xz() + r.ty()*lt.yz() + r.tz()*lt.zz() + r.tt()*lt.tz(), 00287 r.tx()*lt.xt() + r.ty()*lt.yt() + r.tz()*lt.zt() + r.tt()*lt.tt() ) ); 00288 } 00289 00290 00291 const HepLorentzRotation HepLorentzRotation::IDENTITY; 00292 00293 } // namespace CLHEP