00001
00002
00003
00004
00006
00007 #include "HepMC/Polarization.h"
00008
00009 namespace HepMC {
00010
00011 Polarization::Polarization( )
00012 : m_theta( 0. ),
00013 m_phi( 0. ),
00014 m_defined( false )
00015 { }
00016
00017 Polarization::Polarization( double theta, double phi )
00018 : m_theta( valid_theta(theta) ),
00019 m_phi ( valid_phi(phi) ),
00020 m_defined( true )
00021 { }
00022
00023 Polarization::Polarization( const Polarization& inpolar )
00024 : m_theta( valid_theta( inpolar.theta() ) ),
00025 m_phi ( valid_phi( inpolar.phi() ) ),
00026 m_defined( inpolar.is_defined() )
00027 { }
00028
00029 Polarization::Polarization( const ThreeVector& vec3in )
00030 : m_theta( valid_theta( vec3in.theta() ) ),
00031 m_phi ( valid_phi( vec3in.phi() ) ),
00032 m_defined( true )
00033 { }
00034
00035 void Polarization::swap( Polarization & other)
00036 {
00037 std::swap( m_theta, other.m_theta );
00038 std::swap( m_phi, other.m_phi );
00039 std::swap( m_defined, other.m_defined );
00040 }
00041
00042 Polarization& Polarization::operator=( const Polarization& inpolar ) {
00044 Polarization tmp( inpolar );
00045 swap( tmp );
00046 return *this;
00047 }
00048
00049 void Polarization::print( std::ostream& ostr ) const {
00050 ostr << "Polarization: " << *this << std::endl;
00051 }
00052
00054
00056
00057 ThreeVector Polarization::normal3d() const {
00058
00059 ThreeVector outvec(0,0,1);
00060 outvec.setTheta( theta() );
00061 outvec.setPhi( phi() );
00062 return outvec;
00063 }
00064
00065 double Polarization::set_theta( double theta ) {
00068 return m_theta = valid_theta( theta );
00069 }
00070
00071 double Polarization::set_phi( double phi ) {
00074 return m_phi = valid_phi( phi );
00075 }
00076
00077 bool Polarization::is_defined( ) const {
00078 return m_defined;
00079 }
00080
00081 void Polarization::set_undefined() {
00082 m_defined = false;
00083 m_theta = 0.;
00084 m_phi = 0.;
00085 }
00086
00087 void Polarization::set_theta_phi( double theta, double phi ) {
00088 set_theta( theta );
00089 set_phi( phi ) ;
00090 m_defined = true;
00091 }
00092
00093 ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
00094 set_theta( vec3in.theta() );
00095 set_phi( vec3in.phi() );
00096 m_defined = true;
00097 return vec3in;
00098 }
00099
00101
00103
00104 double Polarization::valid_theta( double theta ) {
00105
00106 theta = ( theta>0 ? theta : -theta );
00107
00108 theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) )
00109 * 2*HepMC_pi;
00110
00111 if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta;
00112 return theta;
00113 }
00114
00115 double Polarization::valid_phi( double phi ) {
00116
00117
00118 phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi;
00119
00120 if ( phi < 0 ) phi = 2*HepMC_pi + phi;
00121 return phi;
00122 }
00123
00125
00127
00129 std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) {
00130 return ostr << "(" << polar.theta()
00131 << "," << polar.phi() << ")";
00132 }
00133
00134 }
00135
00136