C3Momentum.h
//-----------------------------------------------------------------------------
// $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/C3Momentum.h,v 2.2 1996/10/04 08:43:39 voigt Exp $
//
// COOL Program Library
// Copyright (C) CERES collaboration, 1996
//
// Declaration of class C3Momentum.
//
//-----------------------------------------------------------------------------
#ifndef C3MOMENTUM_H
#define C3MOMENTUM_H
#include <math.h>
#include <iostream.h>
#include "cool.h"
#include "CAngle.h"
class C3Momentum {
public:
C3Momentum();
C3Momentum(double, double, double);
C3Momentum(const C3Momentum&);
~C3Momentum();
public:
double getX() const { return x; }
double getY() const { return y; }
double getZ() const { return z; }
const C3Momentum& getP() const { return *this; }
double getAbs() const;
void setX(double newX) { x = newX; }
void setY(double newY) { y = newY; }
void setZ(double newZ) { z = newZ; }
public:
friend C3Momentum operator + (const C3Momentum&, const C3Momentum&);
friend C3Momentum operator - (const C3Momentum&, const C3Momentum&);
friend C3Momentum operator - (const C3Momentum&);
friend C3Momentum operator * (const double, const C3Momentum&);
friend C3Momentum operator * (const C3Momentum&, const double);
friend C3Momentum operator / (const C3Momentum&, const double);
friend double operator * (const C3Momentum&, const C3Momentum&);
C3Momentum& operator = (const C3Momentum&);
C3Momentum& operator -= (const C3Momentum&);
C3Momentum& operator += (const C3Momentum&);
C3Momentum& operator *= (const double);
C3Momentum& operator /= (const double);
friend CBoolean operator == (const C3Momentum&, const C3Momentum&);
friend CBoolean operator != (const C3Momentum&, const C3Momentum&);
double getPerp() const ;
double getLong() const ;
double getTheta() const ;
double getPhi() const ;
double getEta() const ;
private:
double x, y, z;
};
ostream& operator << (ostream&, const C3Momentum&);
inline double C3Momentum::getAbs() const
{
return sqrt(x*x + y*y + z*z);
}
inline C3Momentum operator + (const C3Momentum& a, const C3Momentum& b)
{
C3Momentum q(a.x + b.x, a.y + b.y, a.z + b.z);
return q;
}
inline C3Momentum operator - (const C3Momentum& a, const C3Momentum& b)
{
C3Momentum q(a.x - b.x, a.y - b.y, a.z - b.z);
return q;
}
inline C3Momentum operator - (const C3Momentum& a)
{
C3Momentum q(-a.x, -a.y, -a.z);
return q;
}
inline double operator * (const C3Momentum& a, const C3Momentum& b)
{
return a.x*b.x + a.y*b.y + a.z*b.z;
}
inline double abs(const C3Momentum& a)
{
return a.getAbs();
}
inline C3Momentum operator * (const double c, const C3Momentum& a)
{
C3Momentum q(a.x*c, a.y*c, a.z*c);
return q;
}
inline C3Momentum operator * (const C3Momentum& a, const double c)
{
C3Momentum q(a.x*c, a.y*c, a.z*c);
return q;
}
inline C3Momentum operator / (const C3Momentum& a, const double c)
{
C3Momentum q(a.x/c, a.y/c, a.z/c);
return q;
}
inline C3Momentum& C3Momentum::operator = (const C3Momentum& a)
{
x = a.getX();
y = a.getY();
z = a.getZ();
return *this;
}
inline C3Momentum& C3Momentum::operator -= (const C3Momentum& a)
{
*this = *this - a;
return *this;
}
inline C3Momentum& C3Momentum::operator += (const C3Momentum& a)
{
*this = *this + a;
return *this;
}
inline C3Momentum& C3Momentum::operator *= (const double c)
{
*this = *this * c;
return *this;
}
inline C3Momentum& C3Momentum::operator /= (const double c)
{
*this = *this / c;
return *this;
}
inline CBoolean operator == (const C3Momentum& a, const C3Momentum& b)
{
return (a.x == b.x && a.y == b.y && a.z == b.z);
}
inline CBoolean operator != (const C3Momentum& a, const C3Momentum& b)
{
return (a.x != b.x || a.y != b.y || a.z != b.z);
}
inline double C3Momentum::getPerp() const
{
return sqrt(x*x + y*y);
}
inline double C3Momentum::getLong() const
{
return z;
}
inline double C3Momentum::getTheta() const
{
double absOfThis = getAbs();
double theta = (absOfThis>0 ? acos(z/absOfThis) : 0);
return theta;
}
inline double C3Momentum::getPhi() const
{
CAngle phi = atan2(y,x);
return double(phi);
}
inline double C3Momentum::getEta() const
{
double theta = getTheta();
double eta = (theta>0 ? -log(tan(theta/2)) : 0);
return eta;
}
#endif /* C3MOMENTUM_H */