]>
Commit | Line | Data |
---|---|---|
0ca57c2f | 1 | ////////////////////////////////////////////////////////////////////////// |
2 | // Matt.Dobbs@Cern.CH, September 1999 | |
3 | // | |
4 | // Polarization object for a particle. All angles are in radians. | |
5 | ////////////////////////////////////////////////////////////////////////// | |
6 | ||
7 | #include "HepMC/Polarization.h" | |
8 | ||
9 | namespace HepMC { | |
10 | ||
11 | Polarization::Polarization( ) | |
12 | : m_theta( 0. ), | |
13 | m_phi( 0. ), | |
14 | m_defined( false ) | |
15 | { } | |
16 | ||
17 | Polarization::Polarization( double theta, double phi ) | |
18 | : m_theta( valid_theta(theta) ), | |
19 | m_phi ( valid_phi(phi) ), | |
20 | m_defined( true ) | |
21 | { } | |
22 | ||
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() ) | |
27 | { } | |
28 | ||
29 | Polarization::Polarization( const ThreeVector& vec3in ) | |
30 | : m_theta( valid_theta( vec3in.theta() ) ), | |
31 | m_phi ( valid_phi( vec3in.phi() ) ), | |
32 | m_defined( true ) | |
33 | { } | |
34 | ||
35 | void Polarization::swap( Polarization & other) | |
36 | { | |
37 | std::swap( m_theta, other.m_theta ); | |
38 | std::swap( m_phi, other.m_phi ); | |
39 | std::swap( m_defined, other.m_defined ); | |
40 | } | |
41 | ||
42 | Polarization& Polarization::operator=( const Polarization& inpolar ) { | |
43 | /// best practices implementation | |
44 | Polarization tmp( inpolar ); | |
45 | swap( tmp ); | |
46 | return *this; | |
47 | } | |
48 | ||
49 | void Polarization::print( std::ostream& ostr ) const { | |
50 | ostr << "Polarization: " << *this << std::endl; | |
51 | } | |
52 | ||
53 | //////////////////// | |
54 | // access methods // | |
55 | //////////////////// | |
56 | ||
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 | |
62 | return outvec; | |
63 | } | |
64 | ||
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 ); | |
69 | } | |
70 | ||
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 ); | |
75 | } | |
76 | ||
77 | bool Polarization::is_defined( ) const { | |
78 | return m_defined; | |
79 | } | |
80 | ||
81 | void Polarization::set_undefined() { | |
82 | m_defined = false; | |
83 | m_theta = 0.; | |
84 | m_phi = 0.; | |
85 | } | |
86 | ||
87 | void Polarization::set_theta_phi( double theta, double phi ) { | |
88 | set_theta( theta ); | |
89 | set_phi( phi ) ; | |
90 | m_defined = true; | |
91 | } | |
92 | ||
93 | ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) { | |
94 | set_theta( vec3in.theta() ); | |
95 | set_phi( vec3in.phi() ); | |
96 | m_defined = true; | |
97 | return vec3in; | |
98 | } | |
99 | ||
100 | ///////////////////// | |
101 | // private methods // | |
102 | ///////////////////// | |
103 | ||
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)) ) | |
109 | * 2*HepMC_pi; | |
110 | // now translate to 0 < theta < pi | |
111 | if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta; | |
112 | return theta; | |
113 | } | |
114 | ||
115 | double Polarization::valid_phi( double phi ) { | |
116 | // | |
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; | |
121 | return phi; | |
122 | } | |
123 | ||
124 | ///////////// | |
125 | // Friends // | |
126 | ///////////// | |
127 | ||
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() << ")"; | |
132 | } | |
133 | ||
134 | } // HepMC | |
135 | ||
136 |