Changeset View
Changeset View
Standalone View
Standalone View
EvtGenBase/EvtComplex.hh
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class EvtComplex { | ||||
inline friend double abs2( const EvtComplex& c ); | inline friend double abs2( const EvtComplex& c ); | ||||
inline friend double arg( const EvtComplex& c ); | inline friend double arg( const EvtComplex& c ); | ||||
inline friend double real( const EvtComplex& c ); | inline friend double real( const EvtComplex& c ); | ||||
inline friend double imag( const EvtComplex& c ); | inline friend double imag( const EvtComplex& c ); | ||||
inline friend EvtComplex exp( const EvtComplex& c ); | inline friend EvtComplex exp( const EvtComplex& c ); | ||||
friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c ); | friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c ); | ||||
public: | public: | ||||
EvtComplex() : _rpart( 0.0 ), _ipart( 0.0 ) {} | EvtComplex() : m_rpart( 0.0 ), m_ipart( 0.0 ) {} | ||||
EvtComplex( double rpart, double ipart = 0.0 ) : | EvtComplex( double rpart, double ipart = 0.0 ) : | ||||
_rpart( rpart ), _ipart( ipart ) | m_rpart( rpart ), m_ipart( ipart ) | ||||
{ | { | ||||
} | } | ||||
EvtComplex( const EvtComplex& c ) : _rpart( c._rpart ), _ipart( c._ipart ) | EvtComplex( const EvtComplex& c ) : | ||||
m_rpart( c.m_rpart ), m_ipart( c.m_ipart ) | |||||
{ | { | ||||
} | } | ||||
inline EvtComplex& operator*=( double d ); | inline EvtComplex& operator*=( double d ); | ||||
inline EvtComplex& operator/=( double d ); | inline EvtComplex& operator/=( double d ); | ||||
EvtComplex& operator*=( EvtComplex c ); | EvtComplex& operator*=( EvtComplex c ); | ||||
EvtComplex& operator/=( EvtComplex c ); | EvtComplex& operator/=( EvtComplex c ); | ||||
inline EvtComplex& operator=( const EvtComplex& c ); | inline EvtComplex& operator=( const EvtComplex& c ); | ||||
inline EvtComplex& operator+=( const EvtComplex& c ); | inline EvtComplex& operator+=( const EvtComplex& c ); | ||||
inline EvtComplex& operator-=( const EvtComplex& c ); | inline EvtComplex& operator-=( const EvtComplex& c ); | ||||
inline EvtComplex& operator+=( double d ); | inline EvtComplex& operator+=( double d ); | ||||
inline EvtComplex& operator-=( double d ); | inline EvtComplex& operator-=( double d ); | ||||
inline int operator==( const EvtComplex c ); | inline int operator==( const EvtComplex c ); | ||||
inline int operator!=( const EvtComplex c ); | inline int operator!=( const EvtComplex c ); | ||||
private: | private: | ||||
double _rpart, _ipart; | double m_rpart, m_ipart; | ||||
}; | }; | ||||
typedef EvtComplex* EvtComplexPtr; | typedef EvtComplex* EvtComplexPtr; | ||||
typedef EvtComplexPtr* EvtComplexPtrPtr; | typedef EvtComplexPtr* EvtComplexPtrPtr; | ||||
typedef EvtComplexPtrPtr* EvtComplexPtrPtrPtr; | typedef EvtComplexPtrPtr* EvtComplexPtrPtrPtr; | ||||
EvtComplex& EvtComplex::operator=( const EvtComplex& c ) | EvtComplex& EvtComplex::operator=( const EvtComplex& c ) | ||||
{ | { | ||||
_rpart = c._rpart; | m_rpart = c.m_rpart; | ||||
_ipart = c._ipart; | m_ipart = c.m_ipart; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex& EvtComplex::operator+=( const EvtComplex& c ) | EvtComplex& EvtComplex::operator+=( const EvtComplex& c ) | ||||
{ | { | ||||
_rpart += c._rpart; | m_rpart += c.m_rpart; | ||||
_ipart += c._ipart; | m_ipart += c.m_ipart; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex& EvtComplex::operator-=( const EvtComplex& c ) | EvtComplex& EvtComplex::operator-=( const EvtComplex& c ) | ||||
{ | { | ||||
_rpart -= c._rpart; | m_rpart -= c.m_rpart; | ||||
_ipart -= c._ipart; | m_ipart -= c.m_ipart; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex& EvtComplex::operator+=( double d ) | EvtComplex& EvtComplex::operator+=( double d ) | ||||
{ | { | ||||
_rpart += d; | m_rpart += d; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex& EvtComplex::operator-=( double d ) | EvtComplex& EvtComplex::operator-=( double d ) | ||||
{ | { | ||||
_rpart -= d; | m_rpart -= d; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex operator*( double d, const EvtComplex& c ) | EvtComplex operator*( double d, const EvtComplex& c ) | ||||
{ | { | ||||
return EvtComplex( c._rpart * d, c._ipart * d ); | return EvtComplex( c.m_rpart * d, c.m_ipart * d ); | ||||
} | } | ||||
EvtComplex operator*( const EvtComplex& c, double d ) | EvtComplex operator*( const EvtComplex& c, double d ) | ||||
{ | { | ||||
return EvtComplex( c._rpart * d, c._ipart * d ); | return EvtComplex( c.m_rpart * d, c.m_ipart * d ); | ||||
} | } | ||||
EvtComplex operator/( const EvtComplex& c, double d ) | EvtComplex operator/( const EvtComplex& c, double d ) | ||||
{ | { | ||||
return EvtComplex( c._rpart / d, c._ipart / d ); | return EvtComplex( c.m_rpart / d, c.m_ipart / d ); | ||||
} | } | ||||
EvtComplex& EvtComplex::operator*=( double d ) | EvtComplex& EvtComplex::operator*=( double d ) | ||||
{ | { | ||||
_rpart *= d; | m_rpart *= d; | ||||
_ipart *= d; | m_ipart *= d; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex& EvtComplex::operator/=( double d ) | EvtComplex& EvtComplex::operator/=( double d ) | ||||
{ | { | ||||
_rpart /= d; | m_rpart /= d; | ||||
_ipart /= d; | m_ipart /= d; | ||||
return *this; | return *this; | ||||
} | } | ||||
EvtComplex operator/( double d, const EvtComplex& c ) | EvtComplex operator/( double d, const EvtComplex& c ) | ||||
{ | { | ||||
double Num = d / ( c._rpart * c._rpart + c._ipart * c._ipart ); | double Num = d / ( c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart ); | ||||
return EvtComplex( Num * c._rpart, -Num * c._ipart ); | return EvtComplex( Num * c.m_rpart, -Num * c.m_ipart ); | ||||
} | } | ||||
EvtComplex operator/( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator/( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
double inv = 1.0 / ( c2._rpart * c2._rpart + c2._ipart * c2._ipart ); | double inv = 1.0 / ( c2.m_rpart * c2.m_rpart + c2.m_ipart * c2.m_ipart ); | ||||
return EvtComplex( inv * ( c1._rpart * c2._rpart + c1._ipart * c2._ipart ), | return EvtComplex( | ||||
inv * ( c1._ipart * c2._rpart - c1._rpart * c2._ipart ) ); | inv * ( c1.m_rpart * c2.m_rpart + c1.m_ipart * c2.m_ipart ), | ||||
inv * ( c1.m_ipart * c2.m_rpart - c1.m_rpart * c2.m_ipart ) ); | |||||
} | } | ||||
EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart * c2._rpart - c1._ipart * c2._ipart, | return EvtComplex( c1.m_rpart * c2.m_rpart - c1.m_ipart * c2.m_ipart, | ||||
c1._rpart * c2._ipart + c1._ipart * c2._rpart ); | c1.m_rpart * c2.m_ipart + c1.m_ipart * c2.m_rpart ); | ||||
} | } | ||||
EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart - c2._rpart, c1._ipart - c2._ipart ); | return EvtComplex( c1.m_rpart - c2.m_rpart, c1.m_ipart - c2.m_ipart ); | ||||
} | } | ||||
EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 ) | EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 ) | ||||
{ | { | ||||
return EvtComplex( c1._rpart + c2._rpart, c1._ipart + c2._ipart ); | return EvtComplex( c1.m_rpart + c2.m_rpart, c1.m_ipart + c2.m_ipart ); | ||||
} | } | ||||
int EvtComplex::operator==( const EvtComplex c ) | int EvtComplex::operator==( const EvtComplex c ) | ||||
{ | { | ||||
return _rpart == c._rpart && _ipart == c._ipart; | return m_rpart == c.m_rpart && m_ipart == c.m_ipart; | ||||
} | } | ||||
int EvtComplex::operator!=( const EvtComplex c ) | int EvtComplex::operator!=( const EvtComplex c ) | ||||
{ | { | ||||
return _rpart != c._rpart || _ipart != c._ipart; | return m_rpart != c.m_rpart || m_ipart != c.m_ipart; | ||||
} | } | ||||
EvtComplex operator-( const EvtComplex& c ) | EvtComplex operator-( const EvtComplex& c ) | ||||
{ | { | ||||
return EvtComplex( -c._rpart, -c._ipart ); | return EvtComplex( -c.m_rpart, -c.m_ipart ); | ||||
} | } | ||||
EvtComplex conj( const EvtComplex& c ) | EvtComplex conj( const EvtComplex& c ) | ||||
{ | { | ||||
return EvtComplex( c._rpart, -c._ipart ); | return EvtComplex( c.m_rpart, -c.m_ipart ); | ||||
} | } | ||||
double abs( const EvtComplex& c ) | double abs( const EvtComplex& c ) | ||||
{ | { | ||||
double c2 = c._rpart * c._rpart + c._ipart * c._ipart; | double c2 = c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart; | ||||
if ( c2 <= 0.0 ) | if ( c2 <= 0.0 ) | ||||
return 0.0; | return 0.0; | ||||
return sqrt( c2 ); | return sqrt( c2 ); | ||||
} | } | ||||
double abs2( const EvtComplex& c ) | double abs2( const EvtComplex& c ) | ||||
{ | { | ||||
return c._rpart * c._rpart + c._ipart * c._ipart; | return c.m_rpart * c.m_rpart + c.m_ipart * c.m_ipart; | ||||
} | } | ||||
double arg( const EvtComplex& c ) | double arg( const EvtComplex& c ) | ||||
{ | { | ||||
if ( ( c._rpart == 0 ) && ( c._ipart == 0 ) ) { | if ( ( c.m_rpart == 0 ) && ( c.m_ipart == 0 ) ) { | ||||
return 0.0; | return 0.0; | ||||
} | } | ||||
if ( c._rpart == 0 ) { | if ( c.m_rpart == 0 ) { | ||||
if ( c._ipart > 0 ) { | if ( c.m_ipart > 0 ) { | ||||
return EvtConst::pi / 2; | return EvtConst::pi / 2; | ||||
} else { | } else { | ||||
return -EvtConst::pi / 2; | return -EvtConst::pi / 2; | ||||
} | } | ||||
} else { | } else { | ||||
return atan2( c._ipart, c._rpart ); | return atan2( c.m_ipart, c.m_rpart ); | ||||
} | } | ||||
} | } | ||||
double real( const EvtComplex& c ) | double real( const EvtComplex& c ) | ||||
{ | { | ||||
return c._rpart; | return c.m_rpart; | ||||
} | } | ||||
double imag( const EvtComplex& c ) | double imag( const EvtComplex& c ) | ||||
{ | { | ||||
return c._ipart; | return c.m_ipart; | ||||
} | } | ||||
EvtComplex exp( const EvtComplex& c ) | EvtComplex exp( const EvtComplex& c ) | ||||
{ | { | ||||
return exp( c._rpart ) * EvtComplex( cos( c._ipart ), sin( c._ipart ) ); | return exp( c.m_rpart ) * EvtComplex( cos( c.m_ipart ), sin( c.m_ipart ) ); | ||||
} | } | ||||
#endif | #endif |