1 //////////////////////////////////////////////////////////////////////////
2 // Matt.Dobbs@Cern.CH, September 1999
4 // Polarization object for a particle. All angles are in radians.
5 //////////////////////////////////////////////////////////////////////////
7 #include "HepMC/Polarization.h"
11 Polarization::Polarization( )
17 Polarization::Polarization( double theta, double phi )
18 : m_theta( valid_theta(theta) ),
19 m_phi ( valid_phi(phi) ),
23 Polarization::Polarization( const Polarization& inpolar )
24 : m_theta( valid_theta( inpolar.theta() ) ),
25 m_phi ( valid_phi( inpolar.phi() ) ),
26 m_defined( inpolar.is_defined() )
29 Polarization::Polarization( const ThreeVector& vec3in )
30 : m_theta( valid_theta( vec3in.theta() ) ),
31 m_phi ( valid_phi( vec3in.phi() ) ),
35 void Polarization::swap( Polarization & other)
37 std::swap( m_theta, other.m_theta );
38 std::swap( m_phi, other.m_phi );
39 std::swap( m_defined, other.m_defined );
42 Polarization& Polarization::operator=( const Polarization& inpolar ) {
43 /// best practices implementation
44 Polarization tmp( inpolar );
49 void Polarization::print( std::ostream& ostr ) const {
50 ostr << "Polarization: " << *this << std::endl;
57 ThreeVector Polarization::normal3d() const {
58 // unit Hep3Vector for easy manipulation
59 ThreeVector outvec(0,0,1); // makes unit vector along Z
60 outvec.setTheta( theta() ); // sets phi keeping mag and theta constant
61 outvec.setPhi( phi() ); // sets theta keeping mag and phi constant
65 double Polarization::set_theta( double theta ) {
66 /// Theta is restricted to be between 0 --> pi
67 /// if an out of range value is given, it is translated to this range.
68 return m_theta = valid_theta( theta );
71 double Polarization::set_phi( double phi ) {
72 /// Phi is restricted to be between 0 --> 2pi
73 /// if an out of range value is given, it is translated to this range.
74 return m_phi = valid_phi( phi );
77 bool Polarization::is_defined( ) const {
81 void Polarization::set_undefined() {
87 void Polarization::set_theta_phi( double theta, double phi ) {
93 ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
94 set_theta( vec3in.theta() );
95 set_phi( vec3in.phi() );
100 /////////////////////
101 // private methods //
102 /////////////////////
104 double Polarization::valid_theta( double theta ) {
105 // this is just absolute value.
106 theta = ( theta>0 ? theta : -theta );
107 // translate to 0 < theta < 2pi
108 theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) )
110 // now translate to 0 < theta < pi
111 if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta;
115 double Polarization::valid_phi( double phi ) {
117 // translate to -2pi < phi < 2pi
118 phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi;
119 // translates to 0 < phi < 2pi
120 if ( phi < 0 ) phi = 2*HepMC_pi + phi;
128 /// write theta and phi to the output stream
129 std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) {
130 return ostr << "(" << polar.theta()
131 << "," << polar.phi() << ")";