1 //--------------------------------------------------------------------------
4 // This software is part of the EvtGen package developed jointly
5 // for the BaBar and CLEO collaborations. If you use all or part
6 // of it, please give an appropriate acknowledgement.
8 // Copyright Information: See EvtGen/COPYRIGHT
9 // Copyright (C) 1998 Caltech, UCSB
11 // Module: EvtVector4R.cc
13 // Description: Real implementation of 4-vectors
15 // Modification history:
17 // DJL/RYD September 25, 1996 Module created
19 //------------------------------------------------------------------------
21 #include "EvtGenBase/EvtPatches.hh"
25 #include "EvtGenBase/EvtVector4R.hh"
26 #include "EvtGenBase/EvtVector3R.hh"
27 #include "EvtGenBase/EvtVector4C.hh"
28 #include "EvtGenBase/EvtTensor4C.hh"
34 EvtVector4R::EvtVector4R(double e,double p1,double p2, double p3){
36 v[0]=e; v[1]=p1; v[2]=p2; v[3]=p3;
39 double EvtVector4R::mass() const{
41 double m2=v[0]*v[0]-v[1]*v[1]-v[2]*v[2]-v[3]*v[3];
52 EvtVector4R rotateEuler(const EvtVector4R& rs,
53 double alpha,double beta,double gamma){
56 tmp.applyRotateEuler(alpha,beta,gamma);
61 EvtVector4R boostTo(const EvtVector4R& rs,
62 const EvtVector4R& p4){
70 EvtVector4R boostTo(const EvtVector4R& rs,
71 const EvtVector3R& boost){
74 tmp.applyBoostTo(boost);
81 void EvtVector4R::applyRotateEuler(double phi,double theta,double ksi){
90 double x=( ck*ct*cp-sk*sp)*v[1]+( -sk*ct*cp-ck*sp)*v[2]+st*cp*v[3];
91 double y=( ck*ct*sp+sk*cp)*v[1]+(-sk*ct*sp+ck*cp)*v[2]+st*sp*v[3];
92 double z=-ck*st*v[1]+sk*st*v[2]+ct*v[3];
100 ostream& operator<<(ostream& s, const EvtVector4R& v){
102 s<<"("<<v.v[0]<<","<<v.v[1]<<","<<v.v[2]<<","<<v.v[3]<<")";
108 void EvtVector4R::applyBoostTo(const EvtVector4R& p4){
112 EvtVector3R boost(p4.get(1)/e,p4.get(2)/e,p4.get(3)/e);
120 void EvtVector4R::applyBoostTo(const EvtVector3R& boost){
122 double bx,by,bz,gamma,b2;
141 gamma=1.0/sqrt(1-b2);
144 double gb2=(gamma-1.0)/b2;
146 double gb2xy=gb2*bx*by;
147 double gb2xz=gb2*bx*bz;
148 double gb2yz=gb2*by*bz;
159 v[0]=gamma*e2+gbx*px2+gby*py2+gbz*pz2;
161 v[1]=gbx*e2+gb2*bxx*px2+px2+gb2xy*py2+gb2xz*pz2;
163 v[2]=gby*e2+gb2*byy*py2+py2+gb2xy*px2+gb2yz*pz2;
165 v[3]=gbz*e2+gb2*bzz*pz2+pz2+gb2yz*py2+gb2xz*px2;
171 EvtVector4R EvtVector4R::cross( const EvtVector4R& p2 ){
173 //Calcs the cross product. Added by djl on July 27, 1995.
174 //Modified for real vectros by ryd Aug 28-96
179 temp.v[1] = v[2]*p2.v[3] - v[3]*p2.v[2];
180 temp.v[2] = v[3]*p2.v[1] - v[1]*p2.v[3];
181 temp.v[3] = v[1]*p2.v[2] - v[2]*p2.v[1];
186 double EvtVector4R::d3mag() const
188 // returns the 3 momentum mag.
192 temp = v[1]*v[1]+v[2]*v[2]+v[3]*v[3];
199 double EvtVector4R::dot ( const EvtVector4R& p2 )const{
201 //Returns the dot product of the 3 momentum. Added by
202 //djl on July 27, 1995. for real!!!
207 temp += v[2]*p2.v[2];
208 temp += v[3]*p2.v[3];
214 // Functions below added by AJB
216 // Calculate ( \vec{p1} cross \vec{p2} ) \cdot \vec{p3} in rest frame of object
217 double EvtVector4R::scalartripler3( const EvtVector4R& p1,
218 const EvtVector4R& p2, const EvtVector4R& p3 ) const
220 EvtVector4C lc=dual(directProd(*this, p1)).cont2(p2);
221 EvtVector4R l(real(lc.get(0)), real(lc.get(1)), real(lc.get(2)),
224 return -1.0/mass() * (l * p3);
227 // Calculate the 3-d dot product of 4-vectors p1 and p2 in the rest frame of
229 double EvtVector4R::dotr3( const EvtVector4R& p1, const EvtVector4R& p2 ) const
231 return 1/mass2() * ((*this) * p1) * ((*this) * p2) - p1 * p2;
234 // Calculate the 3-d magnitude squared of 4-vector p1 in the rest frame of
236 double EvtVector4R::mag2r3( const EvtVector4R& p1 ) const
238 return Square((*this) * p1)/mass2() - p1.mass2();
241 // Calculate the 3-d magnitude 4-vector p1 in the rest frame of 4-vector p0.
242 double EvtVector4R::magr3( const EvtVector4R& p1 ) const
244 return sqrt(mag2r3(p1));