00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #ifndef ST_LORENTZ_VECTOR_HH
00068 #define ST_LORENTZ_VECTOR_HH
00069
00070 #include "StThreeVector.hh"
00071 template<class T> class StLorentzVector {
00072 public:
00073 StLorentzVector(T, T, T, T);
00074 StLorentzVector();
00075 virtual ~StLorentzVector();
00076
00077 template<class X> StLorentzVector(const StThreeVector<X>&, T);
00078 template<class X, class Y> StLorentzVector(const StThreeVector<X>&, Y);
00079 template<class X, class Y> StLorentzVector(Y, const StThreeVector<X>&);
00080 template<class X> StLorentzVector(T, const StThreeVector<X>&);
00081
00082 template<class X> StLorentzVector(const StLorentzVector<X>&);
00083 template<class X> StLorentzVector<T>& operator=(const StLorentzVector<X>&);
00084
00085
00086 T x() const;
00087 T y() const;
00088 T z() const;
00089 T t() const;
00090 T px() const;
00091 T py() const;
00092 T pz() const;
00093 T e() const;
00094 T operator() (size_t) const;
00095 T operator[] (size_t) const;
00096
00097 T& operator() (size_t);
00098 T& operator[] (size_t);
00099
00100 const StThreeVector<T>& vect() const;
00101
00102 void setX(T);
00103 void setY(T);
00104 void setZ(T);
00105 void setPx(T);
00106 void setPy(T);
00107 void setPz(T);
00108 void setE(T);
00109 void setT(T);
00110
00111 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
00112 template <class X> void setVect(const StThreeVector<X>&);
00113 #else
00114 void setVect(const StThreeVector<float>&);
00115 void setVect(const StThreeVector<double>&);
00116 #endif
00117
00118 T perp() const;
00119 T perp2() const;
00120 T pseudoRapidity() const;
00121 T phi() const;
00122 T theta() const;
00123 T cosTheta() const;
00124
00125 T plus() const;
00126 T minus() const;
00127
00128 T m() const;
00129 T m2() const;
00130 T mt() const;
00131 T mt2() const;
00132 T rapidity() const;
00133
00134 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
00135 template<class X> StLorentzVector<T> boost(const StLorentzVector<X>&) const;
00136 #else
00137 StLorentzVector<T> boost(const StLorentzVector<float>&) const;
00138 StLorentzVector<T> boost(const StLorentzVector<double>&) const;
00139 #endif
00140
00141 StLorentzVector<T> operator- ();
00142 StLorentzVector<T> operator+ ();
00143 StLorentzVector<T>& operator*= (double);
00144 StLorentzVector<T>& operator/= (double);
00145
00146 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
00147 template<class X> bool operator == (const StLorentzVector<X>&) const;
00148 template<class X> bool operator != (const StLorentzVector<X>&) const;
00149 template<class X> StLorentzVector<T>& operator+= (const StLorentzVector<X>&);
00150 template<class X> StLorentzVector<T>& operator-= (const StLorentzVector<X>&);
00151 #else
00152 bool operator == (const StLorentzVector<float>&) const;
00153 bool operator != (const StLorentzVector<float>&) const;
00154 bool operator == (const StLorentzVector<double>&) const;
00155 bool operator != (const StLorentzVector<double>&) const;
00156
00157 StLorentzVector<T>& operator+= (const StLorentzVector<float>&);
00158 StLorentzVector<T>& operator-= (const StLorentzVector<float>&);
00159 StLorentzVector<T>& operator+= (const StLorentzVector<double>&);
00160 StLorentzVector<T>& operator-= (const StLorentzVector<double>&);
00161 #endif
00162
00163 protected:
00164 StThreeVector<T> mThreeVector;
00165 T mX4;
00166 #ifdef __ROOT__
00167 ClassDef(StLorentzVector,3)
00168 #endif
00169 };
00170 #ifndef __CINT__
00171
00172
00173
00174 template<class T>
00175 StLorentzVector<T>::StLorentzVector()
00176 : mThreeVector(0, 0, 0), mX4(0) { }
00177
00178 template<class T>
00179 StLorentzVector<T>::StLorentzVector(T x, T y, T z, T t)
00180 : mThreeVector(x, y, z), mX4(t) { }
00181
00182 template<class T>
00183 StLorentzVector<T>::~StLorentzVector() { }
00184
00185 template<class T>
00186 const StThreeVector<T>& StLorentzVector<T>::vect() const
00187 {
00188 return mThreeVector;
00189 }
00190
00191 template<class T>
00192 T StLorentzVector<T>::m2() const
00193 {
00194 return (mX4*mX4 - mThreeVector*mThreeVector);
00195 }
00196
00197 template<class T>
00198 T StLorentzVector<T>::plus() const { return (e() + pz()); }
00199
00200 template<class T>
00201 T StLorentzVector<T>::minus() const { return (e() - pz()); }
00202
00203 template<class T>
00204 T StLorentzVector<T>::m() const
00205 {
00206 T mass2 = m2();
00207 if (mass2 < 0)
00208 return -::sqrt(-mass2);
00209 else
00210 return ::sqrt(mass2);
00211 }
00212
00213 template<class T>
00214 T StLorentzVector<T>::mt2() const
00215 {
00216 return this->perp2() + m2();
00217 }
00218
00219 template<class T>
00220 T StLorentzVector<T>::mt() const
00221 {
00222
00223
00224
00225 T massPerp2 = mt2();
00226 if (massPerp2 < 0)
00227 return -::sqrt(-massPerp2);
00228 else
00229 return ::sqrt(massPerp2);
00230 }
00231
00232 template<class T>
00233 void StLorentzVector<T>::setPx(T x) {mThreeVector.setX(x);}
00234
00235 template<class T>
00236 void StLorentzVector<T>::setPy(T y) {mThreeVector.setY(y);}
00237
00238 template<class T>
00239 void StLorentzVector<T>::setPz(T z) {mThreeVector.setZ(z);}
00240
00241 template<class T>
00242 void StLorentzVector<T>::setX(T x) {mThreeVector.setX(x);}
00243
00244 template<class T>
00245 void StLorentzVector<T>::setY(T y) {mThreeVector.setY(y);}
00246
00247 template<class T>
00248 void StLorentzVector<T>::setZ(T z) {mThreeVector.setZ(z);}
00249
00250 template<class T>
00251 void StLorentzVector<T>::setT(T t) {mX4 = t;}
00252
00253 template<class T>
00254 void StLorentzVector<T>::setE(T e) {mX4 = e;}
00255
00256 template<class T>
00257 T StLorentzVector<T>::x() const {return mThreeVector.x();}
00258
00259 template<class T>
00260 T StLorentzVector<T>::y() const {return mThreeVector.y();}
00261
00262 template<class T>
00263 T StLorentzVector<T>::z() const {return mThreeVector.z();}
00264
00265 template<class T>
00266 T StLorentzVector<T>::px() const {return mThreeVector.x();}
00267
00268 template<class T>
00269 T StLorentzVector<T>::py() const {return mThreeVector.y();}
00270
00271 template<class T>
00272 T StLorentzVector<T>::pz() const {return mThreeVector.z();}
00273
00274 template<class T>
00275 T StLorentzVector<T>::e() const {return mX4;}
00276
00277 template<class T>
00278 T StLorentzVector<T>::t() const {return mX4;}
00279
00280 template<class T>
00281 T StLorentzVector<T>::perp() const {return mThreeVector.perp();}
00282
00283 template<class T>
00284 T StLorentzVector<T>::perp2() const {return mThreeVector.perp2();}
00285
00286 template<class T>
00287 T StLorentzVector<T>::pseudoRapidity() const {return mThreeVector.pseudoRapidity();}
00288
00289 template<class T>
00290 T StLorentzVector<T>::phi() const {return mThreeVector.phi();}
00291
00292 template<class T>
00293 T StLorentzVector<T>::theta() const {return mThreeVector.theta();}
00294
00295 template<class T>
00296 T StLorentzVector<T>::cosTheta() const {return mThreeVector.cosTheta();}
00297
00298 template<class T>
00299 T StLorentzVector<T>::operator() (size_t i) const
00300 {
00301 if (i < 3)
00302 return mThreeVector(i);
00303 else if (i == 3)
00304 return mX4;
00305 else {
00306 #ifndef ST_NO_EXCEPTIONS
00307 throw out_of_range("StLorentzVector<T>::operator(): bad index");
00308 #else
00309 cerr << "StLorentzVector<T>::operator(): bad index." << endl;
00310 #endif
00311 return 0;
00312 }
00313 }
00314
00315 template<class T>
00316 T& StLorentzVector<T>::operator() (size_t i)
00317 {
00318 if (i < 3)
00319 return mThreeVector(i);
00320 else if (i == 3)
00321 return mX4;
00322 else {
00323 #ifndef ST_NO_EXCEPTIONS
00324 throw out_of_range("StLorentzVector<T>::operator(): bad index");
00325 #else
00326 cerr << "StLorentzVector<T>::operator(): bad index." << endl;
00327 #endif
00328 return mX4;
00329 }
00330 }
00331
00332 template<class T>
00333 T StLorentzVector<T>::operator[] (size_t i) const
00334 {
00335 if (i < 3)
00336 return mThreeVector[i];
00337 else if (i == 3)
00338 return mX4;
00339 else {
00340 #ifndef ST_NO_EXCEPTIONS
00341 throw out_of_range("StLorentzVector<T>::operator[]: bad index");
00342 #else
00343 cerr << "StLorentzVector<T>::operator[]: bad index." << endl;
00344 #endif
00345 return 0;
00346 }
00347 }
00348
00349 template<class T>
00350 T& StLorentzVector<T>::operator[] (size_t i)
00351 {
00352 if (i < 3)
00353 return mThreeVector[i];
00354 else if (i == 3)
00355 return mX4;
00356 else {
00357 #ifndef ST_NO_EXCEPTIONS
00358 throw out_of_range("StLorentzVector<T>::operator[]: bad index");
00359 #else
00360 cerr << "StLorentzVector<T>::operator[]: bad index." << endl;
00361 #endif
00362 return mX4;
00363 }
00364 }
00365
00366 template<class T>
00367 T StLorentzVector<T>::rapidity() const
00368 {
00369 return 0.5*::log((mX4+mThreeVector.z())/(mX4-mThreeVector.z())+1e-20);
00370 }
00371
00372 template<class T>
00373 StLorentzVector<T> StLorentzVector<T>::operator- ()
00374 {
00375 return StLorentzVector<T>(-mX4,-mThreeVector);
00376 }
00377
00378 template<class T>
00379 StLorentzVector<T> StLorentzVector<T>::operator+ ()
00380 {
00381 return *this;
00382 }
00383
00384 template<class T>
00385 StLorentzVector<T>& StLorentzVector<T>::operator*= (double c)
00386 {
00387 mThreeVector *= c;
00388 mX4 *= c;
00389 return *this;
00390 }
00391
00392 template<class T>
00393 StLorentzVector<T>& StLorentzVector<T>::operator/= (double c)
00394 {
00395 mThreeVector /= c;
00396 mX4 /= c;
00397 return *this;
00398 }
00399
00400 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
00401
00402 template<class T>
00403 template<class X>
00404 StLorentzVector<T>::StLorentzVector(const StThreeVector<X> &vec, T t)
00405 : mThreeVector(vec), mX4(t) { }
00406
00407 template<class T>
00408 template<class X>
00409 StLorentzVector<T>::StLorentzVector(T t, const StThreeVector<X> &vec)
00410 : mThreeVector(vec), mX4(t) { }
00411
00412 template<class T>
00413 template<class X>
00414 StLorentzVector<T>::StLorentzVector(const StLorentzVector<X> &vec)
00415 : mThreeVector(vec.vect()), mX4(vec.t()) { }
00416
00417 template<class T>
00418 template<class X>
00419 StLorentzVector<T>
00420 StLorentzVector<T>::boost(const StLorentzVector<X>& pframe) const
00421 {
00422 T mass = abs(pframe);
00423 StThreeVector<T> eta = (-1./mass)*pframe.vect();
00424 T gamma = fabs(pframe.e())/mass;
00425 StThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta;
00426 return StLorentzVector<T>(gamma*this->e() - this->vect()*eta,
00427 this->vect() + (gamma-1.)*pl - this->e()*eta);
00428 }
00429
00430 template<class T>
00431 template<class X>
00432 void StLorentzVector<T>::setVect(const StThreeVector<X>& v)
00433 {
00434 mThreeVector = v;
00435 }
00436
00437 template<class T>
00438 template<class X>
00439 StLorentzVector<T>&
00440 StLorentzVector<T>::operator=(const StLorentzVector<X>& vec)
00441 {
00442 mThreeVector = vec.vect();
00443 mX4 = vec.t();
00444 return *this;
00445 }
00446
00447 template<class T>
00448 template<class X>
00449 bool
00450 StLorentzVector<T>::operator== (const StLorentzVector<X>& v) const
00451 {
00452 return (mThreeVector == v.vect()) && (mX4 == v.t());
00453 }
00454
00455 template<class T>
00456 template<class X>
00457 bool
00458 StLorentzVector<T>::operator!= (const StLorentzVector<X>& v) const
00459 {
00460 return !(*this == v);
00461 }
00462
00463 template<class T>
00464 template<class X>
00465 StLorentzVector<T>&
00466 StLorentzVector<T>::operator+= (const StLorentzVector<X>& v)
00467 {
00468 mThreeVector += v.vect();
00469 mX4 += v.t();
00470 return *this;
00471 }
00472
00473 template<class T>
00474 template<class X>
00475 StLorentzVector<T>&
00476 StLorentzVector<T>::operator-= (const StLorentzVector<X>& v)
00477 {
00478 mThreeVector -= v.vect();
00479 mX4 -= v.t();
00480 return *this;
00481 }
00482
00483 #else
00484
00485 template<class T>
00486 StLorentzVector<T>::StLorentzVector(const StThreeVector<float> &vec, T t)
00487 : mThreeVector(vec), mX4(t) { }
00488
00489 template<class T>
00490 StLorentzVector<T>::StLorentzVector(const StThreeVector<double> &vec, T t)
00491 : mThreeVector(vec), mX4(t) { }
00492
00493 template<class T>
00494 StLorentzVector<T>::StLorentzVector(T t, const StThreeVector<float> &vec)
00495 : mThreeVector(vec), mX4(t) { }
00496
00497 template<class T>
00498 StLorentzVector<T>::StLorentzVector(T t, const StThreeVector<double> &vec)
00499 : mThreeVector(vec), mX4(t) { }
00500
00501 template<class T>
00502 StLorentzVector<T>::StLorentzVector(const StLorentzVector<float> &vec)
00503 : mThreeVector(vec.vect()), mX4(vec.t()) { }
00504
00505 template<class T>
00506 StLorentzVector<T>::StLorentzVector(const StLorentzVector<double> &vec)
00507 : mThreeVector(vec.vect()), mX4(vec.t()) { }
00508
00509 template<class T>
00510 StLorentzVector<T>
00511 StLorentzVector<T>::boost(const StLorentzVector<float>& pframe) const
00512 {
00513 T mass = abs(pframe);
00514 StThreeVector<T> eta = (-1./mass)*pframe.vect();
00515 T gamma = fabs(pframe.e())/mass;
00516 StThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta;
00517 return StLorentzVector<T>(gamma*this->e() - this->vect()*eta,
00518 this->vect() + (gamma-1.)*pl - this->e()*eta);
00519 }
00520
00521 template<class T>
00522 StLorentzVector<T>
00523 StLorentzVector<T>::boost(const StLorentzVector<double>& pframe) const
00524 {
00525 T mass = abs(pframe);
00526 StThreeVector<T> eta = (-1./mass)*pframe.vect();
00527 T gamma = fabs(pframe.e())/mass;
00528 StThreeVector<T> pl = ((this->vect()*eta)/(eta*eta))*eta;
00529 return StLorentzVector<T>(gamma*this->e() - this->vect()*eta,
00530 this->vect() + (gamma-1.)*pl - this->e()*eta);
00531 }
00532
00533 template<class T>
00534 void StLorentzVector<T>::setVect(const StThreeVector<float>& v)
00535 {
00536 mThreeVector = v;
00537 }
00538
00539 template<class T>
00540 void StLorentzVector<T>::setVect(const StThreeVector<double>& v)
00541 {
00542 mThreeVector = v;
00543 }
00544
00545 template<class T>
00546 StLorentzVector<T>&
00547 StLorentzVector<T>::operator=(const StLorentzVector<float>& vec)
00548 {
00549 mThreeVector = vec.vect();
00550 mX4 = vec.t();
00551 return *this;
00552 }
00553
00554 template<class T>
00555 StLorentzVector<T>&
00556 StLorentzVector<T>::operator=(const StLorentzVector<double>& vec)
00557 {
00558 mThreeVector = vec.vect();
00559 mX4 = vec.t();
00560 return *this;
00561 }
00562
00563 template<class T>
00564 bool
00565 StLorentzVector<T>::operator== (const StLorentzVector<float>& v) const
00566 {
00567 return (this->vect() == v.vect()) && (mX4 == v.t());
00568 }
00569
00570 template<class T>
00571 bool
00572 StLorentzVector<T>::operator== (const StLorentzVector<double>& v) const
00573 {
00574 return (mThreeVector == v.vect()) && (mX4 == v.t());
00575 }
00576
00577 template<class T>
00578 bool
00579 StLorentzVector<T>::operator!= (const StLorentzVector<float>& v) const
00580 {
00581 return !(*this == v);
00582 }
00583
00584 template<class T>
00585 bool
00586 StLorentzVector<T>::operator!= (const StLorentzVector<double>& v) const
00587 {
00588 return !(*this == v);
00589 }
00590
00591 template<class T>
00592 StLorentzVector<T>&
00593 StLorentzVector<T>::operator+= (const StLorentzVector<float>& v)
00594 {
00595 mThreeVector += v.vect();
00596 mX4 += v.t();
00597 return *this;
00598 }
00599
00600 template<class T>
00601 StLorentzVector<T>&
00602 StLorentzVector<T>::operator+= (const StLorentzVector<double>& v)
00603 {
00604 mThreeVector += v.vect();
00605 mX4 += v.t();
00606 return *this;
00607 }
00608
00609 template<class T>
00610 StLorentzVector<T>&
00611 StLorentzVector<T>::operator-= (const StLorentzVector<float>& v)
00612 {
00613 mThreeVector -= v.vect();
00614 mX4 -= v.t();
00615 return *this;
00616 }
00617
00618 template<class T>
00619 StLorentzVector<T>&
00620 StLorentzVector<T>::operator-= (const StLorentzVector<double>& v)
00621 {
00622 mThreeVector -= v.vect();
00623 mX4 -= v.t();
00624 return *this;
00625 }
00626
00627 #endif // ST_NO_MEMBER_TEMPLATES
00628 #endif
00629
00630
00631
00632
00633 template<class T, class X>
00634 StLorentzVector<T>
00635 operator+ (const StLorentzVector<T>& v1, const StLorentzVector<X>& v2)
00636 {
00637 return StLorentzVector<T>(v1) += v2;
00638 }
00639
00640 template<class T, class X>
00641 StLorentzVector<T>
00642 operator- (const StLorentzVector<T>& v1, const StLorentzVector<X>& v2)
00643 {
00644 return StLorentzVector<T>(v1) -= v2;
00645 }
00646
00647 template<class T, class X>
00648 T operator* (const StLorentzVector<T>& v1, const StLorentzVector<X>& v2)
00649 {
00650 return v1.t()*v2.t() - v1.vect()*v2.vect();
00651 }
00652
00653 template<class T>
00654 StLorentzVector<T>
00655 operator* (const StLorentzVector<T>& v, double c)
00656 {
00657 return StLorentzVector<T>(v) *= c;
00658 }
00659
00660 template<class T>
00661 StLorentzVector<T> operator* (double c, const StLorentzVector<T>& v)
00662 {
00663 return StLorentzVector<T>(v) *= c;
00664 }
00665
00666 template<class T, class X>
00667 StLorentzVector<T> operator/ (const StLorentzVector<T>& v, X c)
00668 {
00669 return StLorentzVector<T>(v) /= c;
00670 }
00671
00672 template<class T>
00673 ostream& operator<< (ostream& os, const StLorentzVector<T>& v)
00674 {
00675 return os << v.vect() << "\t\t" << v.t();
00676 }
00677
00678 template<class T>
00679 istream& operator>>(istream& is, StLorentzVector<T>& v)
00680 {
00681 T x, y, z, t;
00682 is >> x >> y >> z >> t;
00683 v.setX(x);
00684 v.setY(y);
00685 v.setZ(z);
00686 v.setT(t);
00687 return is;
00688 }
00689
00690
00691
00692
00693 template<class T>
00694 T abs(const StLorentzVector<T>& v) {return v.m();}
00695 #endif