#ifndef ROOT_Math_GenVector_Polar2D
#define ROOT_Math_GenVector_Polar2D 1
#ifndef ROOT_Math_Math
#include "Math/Math.h"
#endif
#ifndef ROOT_Math_GenVector_etaMax
#include "Math/GenVector/etaMax.h"
#endif
namespace ROOT {
namespace Math {
template <class T>
class Polar2D {
public :
typedef T Scalar;
Polar2D() : fR(1.), fPhi(0) { }
Polar2D(T r,T phi) : fR(r), fPhi(phi) { Restrict(); }
template <class CoordSystem >
explicit Polar2D( const CoordSystem & v ) :
fR(v.R() ), fPhi(v.Phi() ) { Restrict(); }
Polar2D(const Polar2D & v) :
fR(v.R() ), fPhi(v.Phi() ) { }
Polar2D & operator= (const Polar2D & v) {
fR = v.R();
fPhi = v.Phi();
return *this;
}
void SetCoordinates(Scalar r, Scalar phi)
{ fR=r; fPhi=phi; Restrict(); }
void GetCoordinates(Scalar& r, Scalar& phi) const {r=fR; phi=fPhi;}
Scalar R() const { return fR;}
Scalar Phi() const { return fPhi; }
Scalar X() const { return fR*std::cos(fPhi);}
Scalar Y() const { return fR*std::sin(fPhi);}
Scalar Mag2() const { return fR*fR;}
void SetR(const T & r) {
fR = r;
}
void SetPhi(const T & phi) {
fPhi = phi;
Restrict();
}
void SetXY(Scalar a, Scalar b);
private:
inline static double pi() { return M_PI; }
inline void Restrict() {
if ( fPhi <= -pi() || fPhi > pi() )
fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi();
return;
}
public:
void Scale (T a) {
if (a < 0) {
Negate();
a = -a;
}
fR *= a;
}
void Negate ( ) {
fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
}
void Rotate(T angle) {
fPhi += angle;
Restrict();
}
template <class CoordSystem >
Polar2D & operator= ( const CoordSystem & c ) {
fR = c.R();
fPhi = c.Phi();
return *this;
}
bool operator==(const Polar2D & rhs) const {
return fR == rhs.fR && fPhi == rhs.fPhi;
}
bool operator!= (const Polar2D & rhs) const {return !(operator==(rhs));}
T x() const { return X();}
T y() const { return Y();}
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
void SetX(Scalar a);
void SetY(Scalar a);
#endif
private:
T fR;
T fPhi;
};
}
}
#ifndef ROOT_Math_GenVector_Cartesian2D
#include "Math/GenVector/Cartesian2D.h"
#endif
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
#ifndef ROOT_Math_GenVector_GenVector_exception
#include "Math/GenVector/GenVector_exception.h"
#endif
#endif
namespace ROOT {
namespace Math {
template <class T>
void Polar2D<T>::SetXY(Scalar a, Scalar b) {
*this = Cartesian2D<Scalar>(a, b);
}
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
template <class T>
void Polar2D<T>::SetX(Scalar a) {
GenVector_exception e("Polar2D::SetX() is not supposed to be called");
throw e;
Cartesian2D<Scalar> v(*this); v.SetX(a); *this = Polar2D<Scalar>(v);
}
template <class T>
void Polar2D<T>::SetY(Scalar a) {
GenVector_exception e("Polar2D::SetY() is not supposed to be called");
throw e;
Cartesian2D<Scalar> v(*this); v.SetY(a); *this = Polar2D<Scalar>(v);
}
#endif
}
}
#endif /* ROOT_Math_GenVector_Polar2D */