00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifdef GNUPRAGMA
00013 #pragma implementation
00014 #endif
00015
00016 #include "CLHEP/Vector/LorentzRotation.h"
00017
00018 #include <iostream>
00019 #include <iomanip>
00020
00021 namespace CLHEP {
00022
00023
00024
00025
00026 HepLorentzRotation & HepLorentzRotation::set
00027 (double bx, double by, double bz) {
00028 double bp2 = bx*bx + by*by + bz*bz;
00029
00030
00031
00032
00033
00034 double gamma = 1.0 / std::sqrt(1.0 - bp2);
00035 double bgamma = gamma * gamma / (1.0 + gamma);
00036 mxx = 1.0 + bgamma * bx * bx;
00037 myy = 1.0 + bgamma * by * by;
00038 mzz = 1.0 + bgamma * bz * bz;
00039 mxy = myx = bgamma * bx * by;
00040 mxz = mzx = bgamma * bx * bz;
00041 myz = mzy = bgamma * by * bz;
00042 mxt = mtx = gamma * bx;
00043 myt = mty = gamma * by;
00044 mzt = mtz = gamma * bz;
00045 mtt = gamma;
00046 return *this;
00047 }
00048
00049 HepLorentzRotation & HepLorentzRotation::set
00050 (const HepBoost & B, const HepRotation & R) {
00051 set (B.rep4x4());
00052 *this = matrixMultiplication ( R.rep4x4() );
00053 return *this;
00054 }
00055
00056 HepLorentzRotation & HepLorentzRotation::set
00057 (const HepRotation & R, const HepBoost & B) {
00058 set (R.rep4x4());
00059 *this = matrixMultiplication ( B.rep4x4() );
00060 return *this;
00061 }
00062
00063
00064
00065
00066
00067 double HepLorentzRotation::operator () (int i, int j) const {
00068 if (i == 0) {
00069 if (j == 0) { return xx(); }
00070 if (j == 1) { return xy(); }
00071 if (j == 2) { return xz(); }
00072 if (j == 3) { return xt(); }
00073 } else if (i == 1) {
00074 if (j == 0) { return yx(); }
00075 if (j == 1) { return yy(); }
00076 if (j == 2) { return yz(); }
00077 if (j == 3) { return yt(); }
00078 } else if (i == 2) {
00079 if (j == 0) { return zx(); }
00080 if (j == 1) { return zy(); }
00081 if (j == 2) { return zz(); }
00082 if (j == 3) { return zt(); }
00083 } else if (i == 3) {
00084 if (j == 0) { return tx(); }
00085 if (j == 1) { return ty(); }
00086 if (j == 2) { return tz(); }
00087 if (j == 3) { return tt(); }
00088 }
00089 std::cerr << "HepLorentzRotation subscripting: bad indeces "
00090 << "(" << i << "," << j << ")\n";
00091 return 0.0;
00092 }
00093
00094
00095
00096
00097
00098
00099 int HepLorentzRotation::compare( const HepLorentzRotation & m1 ) const {
00100 if (mtt<m1.mtt) return -1; else if (mtt>m1.mtt) return 1;
00101 else if (mtz<m1.mtz) return -1; else if (mtz>m1.mtz) return 1;
00102 else if (mty<m1.mty) return -1; else if (mty>m1.mty) return 1;
00103 else if (mtx<m1.mtx) return -1; else if (mtx>m1.mtx) return 1;
00104
00105 else if (mzt<m1.mzt) return -1; else if (mzt>m1.mzt) return 1;
00106 else if (mzz<m1.mzz) return -1; else if (mzz>m1.mzz) return 1;
00107 else if (mzy<m1.mzy) return -1; else if (mzy>m1.mzy) return 1;
00108 else if (mzx<m1.mzx) return -1; else if (mzx>m1.mzx) return 1;
00109
00110 else if (myt<m1.myt) return -1; else if (myt>m1.myt) return 1;
00111 else if (myz<m1.myz) return -1; else if (myz>m1.myz) return 1;
00112 else if (myy<m1.myy) return -1; else if (myy>m1.myy) return 1;
00113 else if (myx<m1.myx) return -1; else if (myx>m1.myx) return 1;
00114
00115 else if (mxt<m1.mxt) return -1; else if (mxt>m1.mxt) return 1;
00116 else if (mxz<m1.mxz) return -1; else if (mxz>m1.mxz) return 1;
00117 else if (mxy<m1.mxy) return -1; else if (mxy>m1.mxy) return 1;
00118 else if (mxx<m1.mxx) return -1; else if (mxx>m1.mxx) return 1;
00119
00120 else return 0;
00121 }
00122
00123
00124
00125
00126 HepLorentzRotation
00127 HepLorentzRotation::matrixMultiplication(const HepRep4x4 & m1) const {
00128 return HepLorentzRotation(
00129 mxx*m1.xx_ + mxy*m1.yx_ + mxz*m1.zx_ + mxt*m1.tx_,
00130 mxx*m1.xy_ + mxy*m1.yy_ + mxz*m1.zy_ + mxt*m1.ty_,
00131 mxx*m1.xz_ + mxy*m1.yz_ + mxz*m1.zz_ + mxt*m1.tz_,
00132 mxx*m1.xt_ + mxy*m1.yt_ + mxz*m1.zt_ + mxt*m1.tt_,
00133
00134 myx*m1.xx_ + myy*m1.yx_ + myz*m1.zx_ + myt*m1.tx_,
00135 myx*m1.xy_ + myy*m1.yy_ + myz*m1.zy_ + myt*m1.ty_,
00136 myx*m1.xz_ + myy*m1.yz_ + myz*m1.zz_ + myt*m1.tz_,
00137 myx*m1.xt_ + myy*m1.yt_ + myz*m1.zt_ + myt*m1.tt_,
00138
00139 mzx*m1.xx_ + mzy*m1.yx_ + mzz*m1.zx_ + mzt*m1.tx_,
00140 mzx*m1.xy_ + mzy*m1.yy_ + mzz*m1.zy_ + mzt*m1.ty_,
00141 mzx*m1.xz_ + mzy*m1.yz_ + mzz*m1.zz_ + mzt*m1.tz_,
00142 mzx*m1.xt_ + mzy*m1.yt_ + mzz*m1.zt_ + mzt*m1.tt_,
00143
00144 mtx*m1.xx_ + mty*m1.yx_ + mtz*m1.zx_ + mtt*m1.tx_,
00145 mtx*m1.xy_ + mty*m1.yy_ + mtz*m1.zy_ + mtt*m1.ty_,
00146 mtx*m1.xz_ + mty*m1.yz_ + mtz*m1.zz_ + mtt*m1.tz_,
00147 mtx*m1.xt_ + mty*m1.yt_ + mtz*m1.zt_ + mtt*m1.tt_ );
00148 }
00149
00150 HepLorentzRotation & HepLorentzRotation::rotateX(double delta) {
00151 double c1 = std::cos (delta);
00152 double s1 = std::sin (delta);
00153 HepLorentzVector rowy = row2();
00154 HepLorentzVector rowz = row3();
00155 HepLorentzVector r2 = c1 * rowy - s1 * rowz;
00156 HepLorentzVector r3 = s1 * rowy + c1 * rowz;
00157 myx = r2.x(); myy = r2.y(); myz = r2.z(); myt = r2.t();
00158 mzx = r3.x(); mzy = r3.y(); mzz = r3.z(); mzt = r3.t();
00159 return *this;
00160 }
00161
00162 HepLorentzRotation & HepLorentzRotation::rotateY(double delta) {
00163 double c1 = std::cos (delta);
00164 double s1 = std::sin (delta);
00165 HepLorentzVector rowx = row1();
00166 HepLorentzVector rowz = row3();
00167 HepLorentzVector r1 = c1 * rowx + s1 * rowz;
00168 HepLorentzVector r3 = -s1 * rowx + c1 * rowz;
00169 mxx = r1.x(); mxy = r1.y(); mxz = r1.z(); mxt = r1.t();
00170 mzx = r3.x(); mzy = r3.y(); mzz = r3.z(); mzt = r3.t();
00171 return *this;
00172 }
00173
00174 HepLorentzRotation & HepLorentzRotation::rotateZ(double delta) {
00175 double c1 = std::cos (delta);
00176 double s1 = std::sin (delta);
00177 HepLorentzVector rowx = row1();
00178 HepLorentzVector rowy = row2();
00179 HepLorentzVector r1 = c1 * rowx - s1 * rowy;
00180 HepLorentzVector r2 = s1 * rowx + c1 * rowy;
00181 mxx = r1.x(); mxy = r1.y(); mxz = r1.z(); mxt = r1.t();
00182 myx = r2.x(); myy = r2.y(); myz = r2.z(); myt = r2.t();
00183 return *this;
00184 }
00185
00186 HepLorentzRotation & HepLorentzRotation::boostX(double beta) {
00187 double b2 = beta*beta;
00188
00189
00190
00191
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
00207
00208
00209
00210
00211 double g1 = 1.0/std::sqrt(1.0-b2);
00212 double bg = beta*g1;
00213 HepLorentzVector rowy = row2();
00214 HepLorentzVector rowt = row4();
00215 HepLorentzVector r2 = g1 * rowy + bg * rowt;
00216 HepLorentzVector r4 = bg * rowy + g1 * rowt;
00217 myx = r2.x(); myy = r2.y(); myz = r2.z(); myt = r2.t();
00218 mtx = r4.x(); mty = r4.y(); mtz = r4.z(); mtt = r4.t();
00219 return *this;
00220 }
00221
00222 HepLorentzRotation & HepLorentzRotation::boostZ(double beta) {
00223 double b2 = beta*beta;
00224
00225
00226
00227
00228
00229 double g1 = 1.0/std::sqrt(1.0-b2);
00230 double bg = beta*g1;
00231 HepLorentzVector rowz = row3();
00232 HepLorentzVector rowt = row4();
00233 HepLorentzVector r3 = g1 * rowz + bg * rowt;
00234 HepLorentzVector r4 = bg * rowz + g1 * rowt;
00235 mtx = r4.x(); mty = r4.y(); mtz = r4.z(); mtt = r4.t();
00236 mzx = r3.x(); mzy = r3.y(); mzz = r3.z(); mzt = r3.t();
00237 return *this;
00238 }
00239
00240 std::ostream & HepLorentzRotation::print( std::ostream & os ) const {
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 }