93 #ifndef ST_THREE_VECTOR_HH
94 #define ST_THREE_VECTOR_HH
104 #if defined (__SUNPRO_CC) && __SUNPRO_CC < 0x500
105 # include <stdcomp.h>
107 #ifndef ST_NO_EXCEPTIONS
108 # include <stdexcept>
109 # if !defined(ST_NO_NAMESPACES)
110 using std::out_of_range;
120 #if ROOT_VERSION_CODE >= 328449
125 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
145 void set(T X,T Y, T Z) {mX1=X;mX2=Y;mX3=Z;}
150 void setMagnitude(T);
155 const T* xyz()
const;
165 T pseudoRapidity()
const;
166 T operator() (
size_t)
const;
167 T operator[] (
size_t)
const;
169 T& operator() (
size_t);
170 T& operator[] (
size_t);
172 T massHypothesis(T mass)
const;
187 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
219 int valid(
double world = 1.e+5)
const;
220 int bad(
double world = 1.e+5)
const;
233 : mX1(0), mX2(0), mX3(0) {}
237 : mX1(X), mX2(Y), mX3(Z) {}
253 double r = magnitude();
256 mX1 = r*sin(th)*cos(Angle);
257 mX2 = r*sin(th)*sin(Angle);
263 double r = magnitude();
266 mX1 = r*sin(Angle)*cos(ph);
267 mX2 = r*sin(Angle)*sin(ph);
277 mX1 = r*sin(th)*cos(ph);
278 mX2 = r*sin(th)*sin(ph);
306 return acos(cosTheta());
312 return mX3/(mag()+1e-20);
318 return atan2(mX2,mX1);
328 double tmp = tan(theta()/2.);
if (tmp <=0.)
return 1e20;
335 double tmp = mag();
if (tmp<=0.) tmp = 1e-20;
342 return ::sqrt((*
this)*(*
this) + mass*mass);
350 double X = (mX1 < 0.0) ? -mX1 : mX1;
351 double Y = (mX2 < 0.0) ? -mX2 : mX2;
352 double Z = (mX3 < 0.0) ? -mX3 : mX3;
357 return mX2 < mX3 ? StThreeVector<T>(-mX3,0,mX1) :
StThreeVector<T>(mX2,-mX1,0);
364 double yPrime = cos(Angle)*mX2 - sin(Angle)*mX3;
365 double zPrime = sin(Angle)*mX2 + cos(Angle)*mX3;
375 double zPrime = cos(Angle)*mX3 - sin(Angle)*mX1;
376 double xPrime = sin(Angle)*mX3 + cos(Angle)*mX1;
386 double xPrime = cos(Angle)*mX1 - sin(Angle)*mX2;
387 double yPrime = sin(Angle)*mX1 + cos(Angle)*mX2;
396 return ::sqrt(mX1*mX1+mX2*mX2);
402 return mX1*mX1+mX2*mX2;
414 return ::sqrt(mX1*mX1+mX2*mX2+mX3*mX3);
420 return mX1*mX1+mX2*mX2+mX3*mX3;
426 if (i <= 2)
return (&mX1)[i];
427 #ifndef ST_NO_EXCEPTIONS
428 throw out_of_range(
"StThreeVector<T>::operator(): bad index");
430 cerr <<
"StThreeVector<T>::operator(): bad index" << endl;
438 if (i <= 2)
return (&mX1)[i];
439 #ifndef ST_NO_EXCEPTIONS
440 throw out_of_range(
"StThreeVector<T>::operator(): bad index");
442 cerr <<
"StThreeVector<T>::operator(): bad index" << endl;
450 if (i <= 2)
return (&mX1)[i];
451 #ifndef ST_NO_EXCEPTIONS
452 throw out_of_range(
"StThreeVector<T>::operator[]: bad index");
454 cerr <<
"StThreeVector<T>::operator[]: bad index" << endl;
462 if (i <= 2)
return (&mX1)[i];
463 #ifndef ST_NO_EXCEPTIONS
464 throw out_of_range(
"StThreeVector<T>::operator[]: bad index");
466 cerr <<
"StThreeVector<T>::operator[]: bad index" << endl;
474 mX1 *= c; mX2 *= c; mX3 *= c;
484 mX1 /= c; mX2 /= c; mX3 /= c;
507 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
512 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {}
528 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
536 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
543 return !(*
this == v);
551 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
560 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
568 return mX1*v.x() + mX2*v.y() + mX3*v.z();
577 mX3*v.x() - mX1*v.z(),
578 mX1*v.y() - mX2*v.x());
585 double norm = this->mag2()*vec.mag2();
587 return norm > 0 ? acos(this->dot(vec)/(::sqrt(norm))) : 0;
595 return this->pseudoProduct(v.x(),v.y(),v.z());
602 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {}
606 : mX1(v.x()), mX2(v.y()), mX3(v.z()) {}
628 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
636 mX1 = v.x(); mX2 = v.y(); mX3 = v.z();
644 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
651 return mX1 == v.x() && mX2 == v.y() && mX3 == v.z();
658 return !(*
this == v);
665 return !(*
this == v);
672 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
680 mX1 += v.x(); mX2 += v.y(); mX3 += v.z();
688 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
696 mX1 -= v.x(); mX2 -= v.y(); mX3 -= v.z();
703 return mX1*v.x() + mX2*v.y() + mX3*v.z();
709 return mX1*v.x() + mX2*v.y() + mX3*v.z();
717 mX3*v.x() - mX1*v.z(),
718 mX1*v.y() - mX2*v.x());
726 mX3*v.x() - mX1*v.z(),
727 mX1*v.y() - mX2*v.x());
733 double tmp = mag()*v.mag();
if (tmp <=0) tmp = 1e-20;
734 return acos(this->dot(v)/tmp);
740 double tmp = mag()*v.mag();
if (tmp <=0) tmp = 1e-20;
741 return acos(this->dot(v)/tmp);
748 return this->pseudoProduct(v.x(),v.y(),v.z());
755 return this->pseudoProduct(v.x(),v.y(),v.z());
757 #endif // ST_NO_MEMBER_TEMPLATES
766 for (
int i=0;i<3;i++) {
767 if (!::finite((&mX1)[i]) )
return 10+i;
768 if ( ::fabs ((&mX1)[i])>world)
return 20+i;
775 #if !defined(ST_NO_MEMBER_TEMPLATES) && !defined(__CINT__)
778 template<
class T,
class X>
784 template<
class T,
class X>
791 template<
class T,
class X>
798 template<
class T,
class X>
891 ostream& operator<<(ostream& os, const StThreeVector<T>& v)
893 return os << v.x() <<
'\t' << v.y() <<
'\t' << v.z();
896 template<> ostream& operator<<(ostream& os, const StThreeVector<double>& v);
897 template<> ostream& operator<<(ostream& os, const StThreeVector<float>& v);