![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // Matt.Dobbs@Cern.CH, September 1999 00003 // 00004 // Polarization object for a particle. All angles are in radians. 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 // access methods // 00046 00047 ThreeVector Polarization::normal3d() const { 00048 // unit Hep3Vector for easy manipulation 00049 ThreeVector outvec(0,0,1); // makes unit vector along Z 00050 outvec.setTheta( theta() ); // sets phi keeping mag and theta constant 00051 outvec.setPhi( phi() ); // sets theta keeping mag and phi constant 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 // private methods // 00081 00082 double Polarization::valid_theta( double theta ) { 00083 // this is just absolute value. 00084 theta = ( theta>0 ? theta : -theta ); 00085 // translate to 0 < theta < 2pi 00086 theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) ) 00087 * 2*HepMC_pi; 00088 // now translate to 0 < theta < pi 00089 if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta; 00090 return theta; 00091 } 00092 00093 double Polarization::valid_phi( double phi ) { 00094 // 00095 // translate to -2pi < phi < 2pi 00096 phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi; 00097 // translates to 0 < phi < 2pi 00098 if ( phi < 0 ) phi = 2*HepMC_pi + phi; 00099 return phi; 00100 } 00101 00103 // Friends // 00105 00107 std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) { 00108 return ostr << "(" << polar.theta() 00109 << "," << polar.phi() << ")"; 00110 } 00111 00112 } // HepMC 00113 00114