#ifndef ROOT_Math_GenVector_DisplacementVector3D
#define ROOT_Math_GenVector_DisplacementVector3D 1
#ifndef ROOT_Math_GenVector_Cartesian3D
#include "Math/GenVector/Cartesian3D.h"
#endif
#ifndef ROOT_Math_GenVector_PositionVector3Dfwd
#include "Math/GenVector/PositionVector3Dfwd.h"
#endif
#ifndef ROOT_Math_GenVector_GenVectorIO
#include "Math/GenVector/GenVectorIO.h"
#endif
#ifndef ROOT_Math_GenVector_BitReproducible
#include "Math/GenVector/BitReproducible.h"
#endif
#ifndef ROOT_Math_GenVector_CoordinateSystemTags
#include "Math/GenVector/CoordinateSystemTags.h"
#endif
#include <cassert>
namespace ROOT {
namespace Math {
template <class CoordSystem, class Tag = DefaultCoordinateSystemTag >
class DisplacementVector3D {
public:
typedef typename CoordSystem::Scalar Scalar;
typedef CoordSystem CoordinateType;
typedef Tag CoordinateSystemTag;
DisplacementVector3D ( ) : fCoordinates() { }
DisplacementVector3D(Scalar a, Scalar b, Scalar c) :
fCoordinates ( a , b, c ) { }
template <class OtherCoords>
explicit DisplacementVector3D( const DisplacementVector3D<OtherCoords, Tag> & v) :
fCoordinates ( v.Coordinates() ) { }
template <class OtherCoords>
explicit DisplacementVector3D( const PositionVector3D<OtherCoords,Tag> & p) :
fCoordinates ( p.Coordinates() ) { }
template <class ForeignVector>
explicit DisplacementVector3D( const ForeignVector & v) :
fCoordinates ( Cartesian3D<Scalar>( v.x(), v.y(), v.z() ) ) { }
#ifdef LATER
template <class LAVector>
DisplacementVector3D(const LAVector & v, size_t index0 ) {
fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
}
#endif
template <class OtherCoords>
DisplacementVector3D & operator=
( const DisplacementVector3D<OtherCoords, Tag> & v) {
fCoordinates = v.Coordinates();
return *this;
}
template <class OtherCoords>
DisplacementVector3D & operator=
( const PositionVector3D<OtherCoords,Tag> & rhs) {
SetXYZ(rhs.x(), rhs.y(), rhs.z());
return *this;
}
template <class ForeignVector>
DisplacementVector3D & operator= ( const ForeignVector & v) {
SetXYZ( v.x(), v.y(), v.z() );
return *this;
}
#ifdef LATER
template <class LAVector>
DisplacementVector3D & assignFrom(const LAVector & v, size_t index0 = 0) {
fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
return *this;
}
#endif
CoordSystem Coordinates() const {
return fCoordinates;
}
DisplacementVector3D<CoordSystem, Tag>& SetCoordinates( const Scalar src[] )
{ fCoordinates.SetCoordinates(src); return *this; }
DisplacementVector3D<CoordSystem, Tag>& SetCoordinates( Scalar a, Scalar b, Scalar c )
{ fCoordinates.SetCoordinates(a, b, c); return *this; }
template <class IT>
DisplacementVector3D<CoordSystem, Tag>& SetCoordinates( IT begin, IT end )
{ IT a = begin; IT b = ++begin; IT c = ++begin;
assert (++begin==end);
SetCoordinates (*a,*b,*c);
return *this;
}
void GetCoordinates( Scalar& a, Scalar& b, Scalar& c ) const
{ fCoordinates.GetCoordinates(a, b, c); }
void GetCoordinates( Scalar dest[] ) const
{ fCoordinates.GetCoordinates(dest); }
template <class IT>
void GetCoordinates( IT begin, IT end ) const
{ IT a = begin; IT b = ++begin; IT c = ++begin;
assert (++begin==end);
GetCoordinates (*a,*b,*c);
}
template <class IT>
void GetCoordinates( IT begin) const {
Scalar a,b,c = 0;
GetCoordinates (a,b,c);
*begin++ = a;
*begin++ = b;
*begin = c;
}
DisplacementVector3D<CoordSystem, Tag>& SetXYZ (Scalar a, Scalar b, Scalar c) {
fCoordinates.SetXYZ(a,b,c);
return *this;
}
bool operator==(const DisplacementVector3D & rhs) const {
return fCoordinates==rhs.fCoordinates;
}
bool operator!= (const DisplacementVector3D & rhs) const {
return !(operator==(rhs));
}
Scalar X() const { return fCoordinates.X(); }
Scalar Y() const { return fCoordinates.Y(); }
Scalar Z() const { return fCoordinates.Z(); }
Scalar R() const { return fCoordinates.R(); }
Scalar Theta() const { return fCoordinates.Theta(); }
Scalar Phi() const { return fCoordinates.Phi(); }
Scalar Eta() const { return fCoordinates.Eta(); }
Scalar Rho() const { return fCoordinates.Rho(); }
Scalar Mag2() const { return fCoordinates.Mag2();}
Scalar Perp2() const { return fCoordinates.Perp2();}
DisplacementVector3D Unit() const {
Scalar tot = R();
return tot == 0 ? *this : DisplacementVector3D(*this) / tot;
}
DisplacementVector3D<CoordSystem, Tag>& SetX (Scalar xx) { fCoordinates.SetX(xx); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetY (Scalar yy) { fCoordinates.SetY(yy); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetZ (Scalar zz) { fCoordinates.SetZ(zz); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetR (Scalar rr) { fCoordinates.SetR(rr); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetTheta (Scalar ang) { fCoordinates.SetTheta(ang); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetPhi (Scalar ang) { fCoordinates.SetPhi(ang); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetRho (Scalar rr) { fCoordinates.SetRho(rr); return *this;}
DisplacementVector3D<CoordSystem, Tag>& SetEta (Scalar etaval) { fCoordinates.SetEta(etaval); return *this;}
template< class OtherCoords >
Scalar Dot( const DisplacementVector3D<OtherCoords,Tag> & v) const {
return X()*v.X() + Y()*v.Y() + Z()*v.Z();
}
template< class OtherVector >
Scalar Dot( const OtherVector & v) const {
return X()*v.x() + Y()*v.y() + Z()*v.z();
}
template <class OtherCoords>
DisplacementVector3D Cross( const DisplacementVector3D<OtherCoords,Tag> & v) const {
DisplacementVector3D result;
result.SetXYZ ( Y()*v.Z() - v.Y()*Z(),
Z()*v.X() - v.Z()*X(),
X()*v.Y() - v.X()*Y() );
return result;
}
template <class OtherVector>
DisplacementVector3D Cross( const OtherVector & v) const {
DisplacementVector3D result;
result.SetXYZ ( Y()*v.z() - v.y()*Z(),
Z()*v.x() - v.z()*X(),
X()*v.y() - v.x()*Y() );
return result;
}
template <class OtherCoords>
DisplacementVector3D & operator+=
(const DisplacementVector3D<OtherCoords,Tag> & v) {
SetXYZ( X() + v.X(), Y() + v.Y(), Z() + v.Z() );
return *this;
}
template <class OtherCoords>
DisplacementVector3D & operator-=
(const DisplacementVector3D<OtherCoords,Tag> & v) {
SetXYZ( x() - v.x(), y() - v.y(), z() - v.z() );
return *this;
}
DisplacementVector3D & operator*= (Scalar a) {
fCoordinates.Scale(a);
return *this;
}
DisplacementVector3D & operator/= (Scalar a) {
fCoordinates.Scale(1/a);
return *this;
}
DisplacementVector3D operator * ( Scalar a ) const {
DisplacementVector3D tmp(*this);
tmp *= a;
return tmp;
}
DisplacementVector3D operator - ( ) const {
return operator*( Scalar(-1) );
}
DisplacementVector3D operator + ( ) const {return *this;}
DisplacementVector3D operator/ (Scalar a) const {
DisplacementVector3D tmp(*this);
tmp /= a;
return tmp;
}
Scalar x() const { return fCoordinates.X(); }
Scalar y() const { return fCoordinates.Y(); }
Scalar z() const { return fCoordinates.Z(); }
Scalar r() const { return fCoordinates.R(); }
Scalar theta() const { return fCoordinates.Theta(); }
Scalar phi() const { return fCoordinates.Phi(); }
Scalar eta() const { return fCoordinates.Eta(); }
Scalar rho() const { return fCoordinates.Rho(); }
Scalar mag2() const { return fCoordinates.Mag2(); }
Scalar perp2() const { return fCoordinates.Perp2(); }
DisplacementVector3D unit() const {return Unit();}
private:
CoordSystem fCoordinates;
#ifdef NOT_SURE_THIS_SHOULD_BE_FORBIDDEN
template <class T2>
DisplacementVector3D Cross( const PositionVector3D<T2> & ) const;
#endif
template <class OtherCoords, class OtherTag>
explicit DisplacementVector3D( const DisplacementVector3D<OtherCoords, OtherTag> & ) {}
template <class OtherCoords, class OtherTag>
explicit DisplacementVector3D( const PositionVector3D<OtherCoords, OtherTag> & ) {}
template <class OtherCoords, class OtherTag>
DisplacementVector3D & operator=( const DisplacementVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
DisplacementVector3D & operator=( const PositionVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
DisplacementVector3D & operator+=(const DisplacementVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
DisplacementVector3D & operator-=(const DisplacementVector3D<OtherCoords, OtherTag> & );
template<class OtherCoords, class OtherTag >
Scalar Dot( const DisplacementVector3D<OtherCoords, OtherTag> & ) const;
template<class OtherCoords, class OtherTag >
DisplacementVector3D Cross( const DisplacementVector3D<OtherCoords, OtherTag> & ) const;
};
template <class CoordSystem1, class CoordSystem2, class U>
inline
DisplacementVector3D<CoordSystem1,U>
operator+( DisplacementVector3D<CoordSystem1,U> v1,
const DisplacementVector3D<CoordSystem2,U> & v2) {
return v1 += v2;
}
template <class CoordSystem1, class CoordSystem2, class U>
inline
DisplacementVector3D<CoordSystem1,U>
operator-( DisplacementVector3D<CoordSystem1,U> v1,
DisplacementVector3D<CoordSystem2,U> const & v2) {
return v1 -= v2;
}
template <class CoordSystem, class U>
inline
DisplacementVector3D<CoordSystem,U>
operator * ( typename DisplacementVector3D<CoordSystem,U>::Scalar a,
DisplacementVector3D<CoordSystem,U> v) {
return v *= a;
}
template< class char_t, class traits_t, class T, class U >
inline
std::basic_ostream<char_t,traits_t> &
operator << ( std::basic_ostream<char_t,traits_t> & os
, DisplacementVector3D<T,U> const & v
)
{
if( !os ) return os;
typename T::Scalar a, b, c;
v.GetCoordinates(a, b, c);
if( detail::get_manip( os, detail::bitforbit ) ) {
detail::set_manip( os, detail::bitforbit, '\00' );
typedef GenVector_detail::BitReproducible BR;
BR::Output(os, a);
BR::Output(os, b);
BR::Output(os, c);
}
else {
os << detail::get_manip( os, detail::open ) << a
<< detail::get_manip( os, detail::sep ) << b
<< detail::get_manip( os, detail::sep ) << c
<< detail::get_manip( os, detail::close );
}
return os;
}
template< class char_t, class traits_t, class T, class U >
inline
std::basic_istream<char_t,traits_t> &
operator >> ( std::basic_istream<char_t,traits_t> & is
, DisplacementVector3D<T,U> & v
)
{
if( !is ) return is;
typename T::Scalar a, b, c;
if( detail::get_manip( is, detail::bitforbit ) ) {
detail::set_manip( is, detail::bitforbit, '\00' );
typedef GenVector_detail::BitReproducible BR;
BR::Input(is, a);
BR::Input(is, b);
BR::Input(is, c);
}
else {
detail::require_delim( is, detail::open ); is >> a;
detail::require_delim( is, detail::sep ); is >> b;
detail::require_delim( is, detail::sep ); is >> c;
detail::require_delim( is, detail::close );
}
if( is )
v.SetCoordinates(a, b, c);
return is;
}
}
}
#endif /* ROOT_Math_GenVector_DisplacementVector3D */
Last change: Wed Jun 25 08:29:29 2008
Last generated: 2008-06-25 08:29
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.