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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // -*- C++ -*-
  2 // ---------------------------------------------------------------------------
  3 //
  4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
  5 //
  6 // This is the implementation basic parts of the HepLorentzRotation class.
  7 //
  8 // Some ZOOM methods involving construction from columns and decomposition 
  9 // into boost*rotation are split off into LorentzRotationC and LorentzRotationD
 10 
 11 #include "CLHEP/Vector/LorentzRotation.h"
 12 
 13 #include <cmath>
 14 #include <iomanip>
 15 #include <iostream>
 16 
 17 namespace CLHEP  {
 18 
 19 // ----------  Constructors and Assignment:
 20 
 21 
 22 HepLorentzRotation & HepLorentzRotation::set
 23         (double bx, double by, double bz) {
 24   double bp2 = bx*bx + by*by + bz*bz;
 25 //  if (bp2 >= 1) {
 26 //    std::cerr << "HepLorentzRotation::set() - "
 27 //      << "Boost Vector supplied to set HepLorentzRotation represents speed >= c."
 28 //      << std::endl;
 29 //  }    
 30   double gamma = 1.0 / std::sqrt(1.0 - bp2);
 31   double bgamma = gamma * gamma / (1.0 + gamma);
 32   mxx = 1.0 + bgamma * bx * bx;
 33   myy = 1.0 + bgamma * by * by;
 34   mzz = 1.0 + bgamma * bz * bz;
 35   mxy = myx = bgamma * bx * by;
 36   mxz = mzx = bgamma * bx * bz;
 37   myz = mzy = bgamma * by * bz;
 38   mxt = mtx = gamma * bx;
 39   myt = mty = gamma * by;
 40   mzt = mtz = gamma * bz;
 41   mtt = gamma;
 42   return *this;
 43 }
 44 
 45 HepLorentzRotation & HepLorentzRotation::set 
 46     (const HepBoost & B, const HepRotation & R) {
 47   set (B.rep4x4());
 48   *this = matrixMultiplication ( R.rep4x4() );
 49   return *this;
 50 }
 51 
 52 HepLorentzRotation & HepLorentzRotation::set 
 53     (const HepRotation & R, const HepBoost & B) {
 54   set (R.rep4x4());
 55   *this = matrixMultiplication ( B.rep4x4() );
 56   return *this;
 57 }
 58 
 59 // ----------  Accessors:
 60 
 61 // ------------  Subscripting:
 62 
 63 double HepLorentzRotation::operator () (int i, int j) const {
 64   if (i == 0) {
 65     if (j == 0) { return xx(); }
 66     if (j == 1) { return xy(); }
 67     if (j == 2) { return xz(); } 
 68     if (j == 3) { return xt(); } 
 69   } else if (i == 1) {
 70     if (j == 0) { return yx(); }
 71     if (j == 1) { return yy(); }
 72     if (j == 2) { return yz(); } 
 73     if (j == 3) { return yt(); } 
 74   } else if (i == 2) {
 75     if (j == 0) { return zx(); }
 76     if (j == 1) { return zy(); }
 77     if (j == 2) { return zz(); } 
 78     if (j == 3) { return zt(); } 
 79   } else if (i == 3) {
 80     if (j == 0) { return tx(); }
 81     if (j == 1) { return ty(); }
 82     if (j == 2) { return tz(); } 
 83     if (j == 3) { return tt(); } 
 84   } 
 85   std::cerr << "HepLorentzRotation subscripting: bad indices "
 86       << "(" << i << "," << j << ")\n";
 87   return 0.0;
 88 } 
 89 
 90 // ---------- Application:
 91 
 92 
 93 // ---------- Comparison:
 94 
 95 int HepLorentzRotation::compare( const HepLorentzRotation & m1  ) const {
 96        if (mtt<m1.mtt) return -1; else if (mtt>m1.mtt) return 1;
 97   else if (mtz<m1.mtz) return -1; else if (mtz>m1.mtz) return 1;
 98   else if (mty<m1.mty) return -1; else if (mty>m1.mty) return 1;
 99   else if (mtx<m1.mtx) return -1; else if (mtx>m1.mtx) return 1;
100 
101   else if (mzt<m1.mzt) return -1; else if (mzt>m1.mzt) return 1;
102   else if (mzz<m1.mzz) return -1; else if (mzz>m1.mzz) return 1;
103   else if (mzy<m1.mzy) return -1; else if (mzy>m1.mzy) return 1;
104   else if (mzx<m1.mzx) return -1; else if (mzx>m1.mzx) return 1;
105 
106   else if (myt<m1.myt) return -1; else if (myt>m1.myt) return 1;
107   else if (myz<m1.myz) return -1; else if (myz>m1.myz) return 1;
108   else if (myy<m1.myy) return -1; else if (myy>m1.myy) return 1;
109   else if (myx<m1.myx) return -1; else if (myx>m1.myx) return 1;
110 
111   else if (mxt<m1.mxt) return -1; else if (mxt>m1.mxt) return 1;
112   else if (mxz<m1.mxz) return -1; else if (mxz>m1.mxz) return 1;
113   else if (mxy<m1.mxy) return -1; else if (mxy>m1.mxy) return 1;
114   else if (mxx<m1.mxx) return -1; else if (mxx>m1.mxx) return 1;
115 
116   else return 0;
117 }
118 
119 
120 // ---------- Operations in the group of 4-Rotations
121 
122 HepLorentzRotation
123 HepLorentzRotation::matrixMultiplication(const HepRep4x4 & m1) const {
124   return HepLorentzRotation(
125     mxx*m1.xx_ + mxy*m1.yx_ + mxz*m1.zx_ + mxt*m1.tx_,
126     mxx*m1.xy_ + mxy*m1.yy_ + mxz*m1.zy_ + mxt*m1.ty_,
127     mxx*m1.xz_ + mxy*m1.yz_ + mxz*m1.zz_ + mxt*m1.tz_,
128     mxx*m1.xt_ + mxy*m1.yt_ + mxz*m1.zt_ + mxt*m1.tt_,
129 
130     myx*m1.xx_ + myy*m1.yx_ + myz*m1.zx_ + myt*m1.tx_,
131     myx*m1.xy_ + myy*m1.yy_ + myz*m1.zy_ + myt*m1.ty_,
132     myx*m1.xz_ + myy*m1.yz_ + myz*m1.zz_ + myt*m1.tz_,
133     myx*m1.xt_ + myy*m1.yt_ + myz*m1.zt_ + myt*m1.tt_,
134 
135     mzx*m1.xx_ + mzy*m1.yx_ + mzz*m1.zx_ + mzt*m1.tx_,
136     mzx*m1.xy_ + mzy*m1.yy_ + mzz*m1.zy_ + mzt*m1.ty_,
137     mzx*m1.xz_ + mzy*m1.yz_ + mzz*m1.zz_ + mzt*m1.tz_,
138     mzx*m1.xt_ + mzy*m1.yt_ + mzz*m1.zt_ + mzt*m1.tt_,
139 
140     mtx*m1.xx_ + mty*m1.yx_ + mtz*m1.zx_ + mtt*m1.tx_,
141     mtx*m1.xy_ + mty*m1.yy_ + mtz*m1.zy_ + mtt*m1.ty_,
142     mtx*m1.xz_ + mty*m1.yz_ + mtz*m1.zz_ + mtt*m1.tz_,
143     mtx*m1.xt_ + mty*m1.yt_ + mtz*m1.zt_ + mtt*m1.tt_ );
144 }
145 
146 HepLorentzRotation & HepLorentzRotation::rotateX(double delta) {
147   double c1 = std::cos (delta);
148   double s1 = std::sin (delta);
149   HepLorentzVector rowy = row2();
150   HepLorentzVector rowz = row3();
151   HepLorentzVector r2 = c1 * rowy - s1 * rowz;
152   HepLorentzVector r3 = s1 * rowy + c1 * rowz;
153   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t(); 
154   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
155   return *this;
156 }
157 
158 HepLorentzRotation & HepLorentzRotation::rotateY(double delta) {
159   double c1 = std::cos (delta);
160   double s1 = std::sin (delta);
161   HepLorentzVector rowx = row1();
162   HepLorentzVector rowz = row3();
163   HepLorentzVector r1 =  c1 * rowx + s1 * rowz;
164   HepLorentzVector r3 = -s1 * rowx + c1 * rowz;
165   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t(); 
166   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
167   return *this;
168 }
169 
170 HepLorentzRotation & HepLorentzRotation::rotateZ(double delta) {
171   double c1 = std::cos (delta);
172   double s1 = std::sin (delta);
173   HepLorentzVector rowx = row1();
174   HepLorentzVector rowy = row2();
175   HepLorentzVector r1 = c1 * rowx - s1 * rowy;
176   HepLorentzVector r2 = s1 * rowx + c1 * rowy;
177   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t();
178   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t();
179   return *this;
180 }
181 
182 HepLorentzRotation & HepLorentzRotation::boostX(double beta) {
183   double b2 = beta*beta;
184 //  if (b2 >= 1) {
185 //    std::cerr << "HepLorentzRotation::boostX() - "
186 //      << "Beta supplied to HepLorentzRotation::boostX represents speed >= c."
187 //      << std::endl;
188 //  }    
189   double g1  = 1.0/std::sqrt(1.0-b2);
190   double bg = beta*g1;
191   HepLorentzVector rowx = row1();
192   HepLorentzVector rowt = row4();
193   HepLorentzVector r1 =  g1 * rowx + bg * rowt;
194   HepLorentzVector r4 = bg * rowx +  g1 * rowt;
195   mxx = r1.x();   mxy = r1.y();   mxz = r1.z();   mxt = r1.t(); 
196   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
197   return *this;
198 }
199 
200 HepLorentzRotation & HepLorentzRotation::boostY(double beta) {
201   double b2 = beta*beta;
202 //  if (b2 >= 1) {
203 //    std::cerr << "HepLorentzRotation::boostY() - "
204 //      << "Beta supplied to HepLorentzRotation::boostY represents speed >= c."
205 //      << std::endl;
206 //  }    
207   double g1  = 1.0/std::sqrt(1.0-b2);
208   double bg = beta*g1;
209   HepLorentzVector rowy = row2();
210   HepLorentzVector rowt = row4();
211   HepLorentzVector r2 =  g1 * rowy + bg * rowt;
212   HepLorentzVector r4 = bg * rowy +  g1 * rowt;
213   myx = r2.x();   myy = r2.y();   myz = r2.z();   myt = r2.t(); 
214   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
215   return *this;
216 }
217 
218 HepLorentzRotation & HepLorentzRotation::boostZ(double beta) {
219   double b2 = beta*beta;
220 //  if (b2 >= 1) {
221 //    std::cerr << "HepLorentzRotation::boostZ() - "
222 //      << "Beta supplied to HepLorentzRotation::boostZ represents speed >= c."
223 //      << std::endl;
224 //  }    
225   double g1  = 1.0/std::sqrt(1.0-b2);
226   double bg = beta*g1;
227   HepLorentzVector rowz = row3();
228   HepLorentzVector rowt = row4();
229   HepLorentzVector r3 =  g1 * rowz + bg * rowt;
230   HepLorentzVector r4 = bg * rowz +  g1 * rowt;
231   mtx = r4.x();   mty = r4.y();   mtz = r4.z();   mtt = r4.t(); 
232   mzx = r3.x();   mzy = r3.y();   mzz = r3.z();   mzt = r3.t(); 
233   return *this;
234 }
235 
236 std::ostream & HepLorentzRotation::print( std::ostream & os ) const {
237   os << "\n   [ ( " <<
238         std::setw(11) << std::setprecision(6) << xx() << "   " <<
239         std::setw(11) << std::setprecision(6) << xy() << "   " <<
240         std::setw(11) << std::setprecision(6) << xz() << "   " <<
241         std::setw(11) << std::setprecision(6) << xt() << ")\n"
242      << "     ( " <<
243         std::setw(11) << std::setprecision(6) << yx() << "   " <<
244         std::setw(11) << std::setprecision(6) << yy() << "   " <<
245         std::setw(11) << std::setprecision(6) << yz() << "   " <<
246         std::setw(11) << std::setprecision(6) << yt() << ")\n"
247      << "     ( " <<
248         std::setw(11) << std::setprecision(6) << zx() << "   " <<
249         std::setw(11) << std::setprecision(6) << zy() << "   " <<
250         std::setw(11) << std::setprecision(6) << zz() << "   " <<
251         std::setw(11) << std::setprecision(6) << zt() << ")\n"
252      << "     ( " <<
253         std::setw(11) << std::setprecision(6) << tx() << "   " <<
254         std::setw(11) << std::setprecision(6) << ty() << "   " <<
255         std::setw(11) << std::setprecision(6) << tz() << "   " <<
256         std::setw(11) << std::setprecision(6) << tt() << ") ]\n";
257   return os;
258 }
259 
260 HepLorentzRotation operator* ( const HepRotation & r,
261                                const HepLorentzRotation & lt) {
262   r.rep4x4();
263   lt.rep4x4();
264   return HepLorentzRotation( HepRep4x4(
265          r.xx()*lt.xx() + r.xy()*lt.yx() + r.xz()*lt.zx() + r.xt()*lt.tx(),
266    r.xx()*lt.xy() + r.xy()*lt.yy() + r.xz()*lt.zy() + r.xt()*lt.ty(),
267    r.xx()*lt.xz() + r.xy()*lt.yz() + r.xz()*lt.zz() + r.xt()*lt.tz(),
268    r.xx()*lt.xt() + r.xy()*lt.yt() + r.xz()*lt.zt() + r.xt()*lt.tt(),
269 
270          r.yx()*lt.xx() + r.yy()*lt.yx() + r.yz()*lt.zx() + r.yt()*lt.tx(),
271          r.yx()*lt.xy() + r.yy()*lt.yy() + r.yz()*lt.zy() + r.yt()*lt.ty(),
272          r.yx()*lt.xz() + r.yy()*lt.yz() + r.yz()*lt.zz() + r.yt()*lt.tz(),
273          r.yx()*lt.xt() + r.yy()*lt.yt() + r.yz()*lt.zt() + r.yt()*lt.tt(),
274 
275          r.zx()*lt.xx() + r.zy()*lt.yx() + r.zz()*lt.zx() + r.zt()*lt.tx(),
276          r.zx()*lt.xy() + r.zy()*lt.yy() + r.zz()*lt.zy() + r.zt()*lt.ty(),
277          r.zx()*lt.xz() + r.zy()*lt.yz() + r.zz()*lt.zz() + r.zt()*lt.tz(),
278          r.zx()*lt.xt() + r.zy()*lt.yt() + r.zz()*lt.zt() + r.zt()*lt.tt(),
279 
280          r.tx()*lt.xx() + r.ty()*lt.yx() + r.tz()*lt.zx() + r.tt()*lt.tx(),
281          r.tx()*lt.xy() + r.ty()*lt.yy() + r.tz()*lt.zy() + r.tt()*lt.ty(),
282          r.tx()*lt.xz() + r.ty()*lt.yz() + r.tz()*lt.zz() + r.tt()*lt.tz(),
283          r.tx()*lt.xt() + r.ty()*lt.yt() + r.tz()*lt.zt() + r.tt()*lt.tt() ) );
284 }
285 
286 
287 const HepLorentzRotation HepLorentzRotation::IDENTITY;
288 
289 }  // namespace CLHEP
290