00001
00002
00003
00004
00006
00007 #include "HepMC/Polarization.h"
00008
00009 namespace HepMC {
00010
00011 Polarization::Polarization( double theta, double phi )
00012 : m_theta( valid_theta(theta) ),
00013 m_phi ( valid_phi(phi) )
00014 { }
00015
00016 Polarization::Polarization( const Polarization& inpolar )
00017 : m_theta( valid_theta( inpolar.theta() ) ),
00018 m_phi ( valid_phi( inpolar.phi() ) )
00019 { }
00020
00021 Polarization::Polarization( const ThreeVector& vec3in )
00022 : m_theta( valid_theta( vec3in.theta() ) ),
00023 m_phi ( valid_phi( vec3in.phi() ) )
00024 { }
00025
00026 void Polarization::swap( Polarization & other)
00027 {
00028 std::swap( m_theta, other.m_theta );
00029 std::swap( m_phi, other.m_phi );
00030 }
00031
00032 Polarization& Polarization::operator=( const Polarization& inpolar ) {
00034 Polarization tmp( inpolar );
00035 swap( tmp );
00036 return *this;
00037 }
00038
00039 void Polarization::print( std::ostream& ostr ) const {
00040 ostr << "Polarization: " << *this << std::endl;
00041 }
00042
00044
00046
00047 ThreeVector Polarization::normal3d() const {
00048
00049 ThreeVector outvec(0,0,1);
00050 outvec.setTheta( theta() );
00051 outvec.setPhi( phi() );
00052 return outvec;
00053 }
00054
00055 double Polarization::set_theta( double theta ) {
00058 return m_theta = valid_theta( theta );
00059 }
00060
00061 double Polarization::set_phi( double phi ) {
00064 return m_phi = valid_phi( phi );
00065 }
00066
00067 void Polarization::set_theta_phi( double theta, double phi ) {
00068 set_theta( theta );
00069 set_phi( phi ) ;
00070 }
00071
00072 ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
00073 set_theta( vec3in.theta() );
00074 set_phi( vec3in.phi() );
00075 return vec3in;
00076 }
00077
00079
00081
00082 double Polarization::valid_theta( double theta ) {
00083
00084 theta = ( theta>0 ? theta : -theta );
00085
00086 theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) )
00087 * 2*HepMC_pi;
00088
00089 if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta;
00090 return theta;
00091 }
00092
00093 double Polarization::valid_phi( double phi ) {
00094
00095
00096 phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi;
00097
00098 if ( phi < 0 ) phi = 2*HepMC_pi + phi;
00099 return phi;
00100 }
00101
00103
00105
00107 std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) {
00108 return ostr << "(" << polar.theta()
00109 << "," << polar.phi() << ")";
00110 }
00111
00112 }
00113
00114