#ifndef ROOT_Math_GenVector_Cylindrical3D
#define ROOT_Math_GenVector_Cylindrical3D 1
#ifndef ROOT_Math_Math
#include "Math/Math.h"
#endif
#ifndef ROOT_Math_GenVector_etaMax
#include "Math/GenVector/etaMax.h"
#endif
#include <limits>
namespace ROOT {
namespace Math {
template <class T>
class Cylindrical3D {
public :
typedef T Scalar;
Cylindrical3D() : fRho(0), fZ(0), fPhi(0) { }
Cylindrical3D(Scalar rho, Scalar zz, Scalar phi) :
fRho(rho), fZ(zz), fPhi(phi) { Restrict(); }
template <class CoordSystem >
explicit Cylindrical3D( const CoordSystem & v ) :
fRho( v.Rho() ), fZ( v.Z() ), fPhi( v.Phi() ) { Restrict(); }
Cylindrical3D(const Cylindrical3D & v) :
fRho(v.Rho() ), fZ(v.Z() ), fPhi(v.Phi() ) { }
Cylindrical3D & operator= (const Cylindrical3D & v) {
fRho = v.Rho();
fZ = v.Z();
fPhi = v.Phi();
return *this;
}
void SetCoordinates( const Scalar src[] )
{ fRho=src[0]; fZ=src[1]; fPhi=src[2]; Restrict(); }
void GetCoordinates( Scalar dest[] ) const
{ dest[0] = fRho; dest[1] = fZ; dest[2] = fPhi; }
void SetCoordinates(Scalar rho, Scalar zz, Scalar phi)
{ fRho=rho; fZ=zz; fPhi=phi; Restrict(); }
void GetCoordinates(Scalar& rho, Scalar& zz, Scalar& phi) const
{rho=fRho; zz=fZ; phi=fPhi;}
private:
inline static Scalar pi() { return M_PI; }
inline void Restrict() {
if ( fPhi <= -pi() || fPhi > pi() )
fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi();
return;
}
public:
Scalar Rho() const { return fRho; }
Scalar Z() const { return fZ; }
Scalar Phi() const { return fPhi; }
Scalar X() const { return fRho*std::cos(fPhi); }
Scalar Y() const { return fRho*std::sin(fPhi); }
Scalar Mag2() const { return fRho*fRho + fZ*fZ; }
Scalar R() const { return std::sqrt( Mag2()); }
Scalar Perp2() const { return fRho*fRho; }
Scalar Theta() const { return (fRho==0 && fZ==0 ) ? 0 : atan2(fRho,fZ); }
Scalar Eta() const {
return Impl::Eta_FromRhoZ( fRho, fZ);
}
void SetRho(T rho) {
fRho = rho;
}
void SetZ(T zz) {
fZ = zz;
}
void SetPhi(T phi) {
fPhi = phi;
Restrict();
}
void SetXYZ(Scalar x, Scalar y, Scalar z);
void Scale (T a) {
if (a < 0) {
Negate();
a = -a;
}
fRho *= a;
fZ *= a;
}
void Negate ( ) {
fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
fZ = -fZ;
}
template <class CoordSystem >
Cylindrical3D & operator= ( const CoordSystem & c ) {
fRho = c.Rho();
fZ = c.Z();
fPhi = c.Phi();
return *this;
}
bool operator==(const Cylindrical3D & rhs) const {
return fRho == rhs.fRho && fZ == rhs.fZ && fPhi == rhs.fPhi;
}
bool operator!= (const Cylindrical3D & rhs) const
{return !(operator==(rhs));}
T x() const { return X();}
T y() const { return Y();}
T z() const { return Z(); }
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
void SetX(Scalar x);
void SetY(Scalar y);
void SetEta(Scalar eta);
void SetR(Scalar r);
void SetTheta(Scalar theta);
#endif
private:
T fRho;
T fZ;
T fPhi;
};
}
}
#ifndef ROOT_Math_Cartesian3D
#include "Math/GenVector/Cartesian3D.h"
#endif
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
#include "Math/GenVector/GenVector_exception.h"
#include "Math/GenVector/Polar3D.h"
#include "Math/GenVector/CylindricalEta3D.h"
#endif
namespace ROOT {
namespace Math {
template <class T>
void Cylindrical3D<T>::SetXYZ(Scalar xx, Scalar yy, Scalar zz) {
*this = Cartesian3D<Scalar>(xx, yy, zz);
}
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
template <class T>
void Cylindrical3D<T>::SetX(Scalar xx) {
GenVector_exception e("Cylindrical3D::SetX() is not supposed to be called");
throw e;
Cartesian3D<Scalar> v(*this); v.SetX(xx); *this = Cylindrical3D<Scalar>(v);
}
template <class T>
void Cylindrical3D<T>::SetY(Scalar yy) {
GenVector_exception e("Cylindrical3D::SetY() is not supposed to be called");
throw e;
Cartesian3D<Scalar> v(*this); v.SetY(yy); *this = Cylindrical3D<Scalar>(v);
}
template <class T>
void Cylindrical3D<T>::SetR(Scalar r) {
GenVector_exception e("Cylindrical3D::SetR() is not supposed to be called");
throw e;
Polar3D<Scalar> v(*this); v.SetR(r);
*this = Cylindrical3D<Scalar>(v);
}
template <class T>
void Cylindrical3D<T>::SetTheta(Scalar theta) {
GenVector_exception e("Cylindrical3D::SetTheta() is not supposed to be called");
throw e;
Polar3D<Scalar> v(*this); v.SetTheta(theta);
*this = Cylindrical3D<Scalar>(v);
}
template <class T>
void Cylindrical3D<T>::SetEta(Scalar eta) {
GenVector_exception e("Cylindrical3D::SetEta() is not supposed to be called");
throw e;
CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
*this = Cylindrical3D<Scalar>(v);
}
#endif
}
}
#endif /* ROOT_Math_GenVector_Cylindrical3D */