28 #ifndef __VECTOR_LIB__
29 #define __VECTOR_LIB__
69 double amag = fabs(
mag); cX = amag * sin(
theta) * cos(
phi);
76 {
return cX == 0.0 && cY == 0.0 && cZ == 0.0 ? 0.0 : atan2(
perp(),cZ);}
80 {
return cX == 0.0 && cY == 0.0 ? 0.0 : atan2(cY,cX);}
84 {
return sqrt(cX*cX + cY*cY);}
88 {
return (cX*cX + cY*cY);}
92 {
return (cX*cX + cY*cY + cZ*cZ);}
96 {
return sqrt(
mag2());}
99 double x()
const {
return cX;};
101 double y()
const {
return cY;};
103 double z()
const {
return cZ;};
120 double arg =
dot(q)/sqrt(ptot2);
121 if(arg > 1.0) arg = 1.0;
122 if(arg < -1.0) arg = -1.0;
130 double s = sin(
angle);
double c = cos(
angle);
double yy = cY;
131 cY = c*yy - s*cZ; cZ = s*yy + c*cZ;
137 double s = sin(
angle);
double c = cos(
angle);
double zz = cZ;
138 cZ = c*zz - s*cX; cX = s*zz + c*cX;
144 double s = sin(
angle);
double c = cos(
angle);
double xx = cX;
145 cX = c*xx - s*cY; cY = s*xx + c*cY;
155 return vector3(cY*vec.
z()-vec.
y()*cZ, cZ*vec.
x()-vec.
z()*cX,
156 cX*vec.
y()-vec.
x()*cY);
161 {
return (cX*vec.
x() + cY*vec.
y() + cZ*vec.
z());}
166 void print(
const char *_line =
"V3 ")
167 {printf(
"%s : %9.5f %9.5f %9.5f (Mag = %9.5f )\n",
168 _line,
x(),
y(),
z(),
mag());};
185 {
return vector3(a.
x() + b.
x(),a.
y() + b.
y(),a.
z() + b.
z());}
189 {
return vector3(a.
x() - b.
x(), a.
y() - b.
y(), a.
z() - b.
z());}
201 { cX += p.cX; cY += p.cY; cZ += p.cZ;
return *
this; }
204 { cX -= p.cX; cY -= p.cY; cZ -= p.cZ;
return *
this; }
224 lorentz4 (
double _px,
double _py,
double _pz,
double _e)
225 { fVect.
setXYZ(_px,_py,_pz);fE = _e;}
231 double px()
const {
return fVect.
x();};
233 double py()
const {
return fVect.
y();};
235 double pz()
const {
return fVect.
z();};
237 double x()
const {
return fVect.
x();};
239 double y()
const {
return fVect.
y();};
241 double z()
const {
return fVect.
z();};
245 double phi()
const {
return fVect.
phi();};
248 double m2()
const {
return (fE*fE-fVect.
mag2());};
252 double e()
const {
return fE;};
254 double t()
const {
return fE;};
266 void setT(
double _eg){fE=_eg;};
269 void setXYZM(
double _x,
double _y,
double _z,
double _m)
271 setXYZE(_x,_y,_z,sqrt(_x*_x+_y*_y+_z*_z+_m*_m));
273 setXYZE(_x,_y,_z,sqrt(_x*_x+_y*_y+_z*_z));
277 void setXYZE(
double _x,
double _y,
double _z,
double _e)
306 return mm < 0.0 ? -sqrt(-mm) : sqrt(mm);
326 void boost(
double bx,
double by,
double bz)
328 double b2 = bx*bx + by*by + bz*bz;
330 double gamma = 1.0 / sqrt(1.0 - b2);
332 double bp = bx*
x() + by*
y() + bz*
z();
334 double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
336 setX(
x() + gamma2*bp*bx + gamma*bx*
t());
337 setY(
y() + gamma2*bp*by + gamma*by*
t());
338 setZ(
z() + gamma2*bp*bz + gamma*bz*
t());
339 setT(gamma*(
t() + bp));
344 void print(
const char *_line =
"LV ")
345 {printf(
"%s : %9.5f %9.5f %9.5f (Mag = %9.5f , M = %9.5f)\n",
375 fVect -= q.
vect(); fE -= q.
t();
return *
this;
Four-component Lorentz vector for relativistic kinematics.
lorentz4(double _px, double _py, double _pz, double _e)
Construct from px, py, pz, and energy.
void boost(double bx, double by, double bz)
Apply a Lorentz boost using beta components.
void setY(double _p)
Set the Y momentum component.
void rotateY(double angle)
Rotate the 3-momentum around the Y axis.
lorentz4()
Default constructor (uninitialized).
void setZ(double _p)
Set the Z momentum component.
lorentz4 & operator+=(const lorentz4 &)
Add another Lorentz vector to this one in place.
lorentz4(vector3 v, double energy)
Construct from a 3-vector and energy.
void rotateX(double angle)
Rotate the 3-momentum around the X axis.
void setX(double _p)
Set the X momentum component.
void setXYZE(double _x, double _y, double _z, double _e)
Set components from momentum and energy directly.
void rotateZ(double angle)
Rotate the 3-momentum around the Z axis.
void setXYZM(double _x, double _y, double _z, double _m)
Set components from momentum and mass; energy is computed.
void boost(vector3 vb)
Apply a Lorentz boost using a boost vector.
void setT(double _eg)
Set the energy/time component.
void setVectM(vector3 &_v, double _mass)
Set from a 3-vector and mass; energy is computed.
lorentz4 & operator=(const lorentz4 &)
Copy-assignment operator.
lorentz4 & operator-=(const lorentz4 &)
Subtract another Lorentz vector from this one in place.
void print(const char *_line="LV ")
Print the Lorentz vector components, magnitude, and mass to stdout.
lorentz4 operator-(const lorentz4 &) const
Lorentz vector subtraction.
lorentz4 operator+(const lorentz4 &) const
Lorentz vector addition.
Three-dimensional Cartesian vector.
vector3 & operator+=(const vector3 &)
Add another vector to this one in place.
void rotateZ(double angle)
Rotate the vector around the Z axis.
void setXYZ(double x, double y, double z)
Set the Cartesian components.
vector3 & operator-=(const vector3 &)
Subtract another vector from this one in place.
void setZ(double _z)
Set the Z component.
void print(const char *_line="V3 ")
Print the vector components and magnitude to stdout.
vector3 cross(const vector3 &vec) const
Compute the cross product with another vector.
void setX(double _x)
Set the X component.
void setMagThetaPhi(double mag, double theta, double phi)
Set the vector from spherical coordinates.
vector3(double x, double y, double z)
Construct from Cartesian components.
double dot(const vector3 &vec) const
Compute the dot product with another vector.
double angle(const vector3 &q)
Compute the angle between this vector and another.
const vector3 & operator=(const vector3 &vec)
Copy-assignment operator.
void rotateY(double angle)
Rotate the vector around the Y axis.
void setY(double _y)
Set the Y component.
vector3()
Default constructor (uninitialized components).
void rotateX(double angle)
Rotate the vector around the X axis.
vector3 operator*(double a, const vector3 &b)
Scalar-vector multiplication (scalar on the left).
vector3 operator+(const vector3 &a, const vector3 &b)
Vector addition.
vector3 operator-(const vector3 &a, const vector3 &b)
Vector subtraction.