Fork me on GitHub

source: svn/trunk/Utilities/HepMC/src/Polarization.cc@ 444

Last change on this file since 444 was 349, checked in by severine ovyn, 16 years ago

first test

File size: 3.2 KB
Line 
1//////////////////////////////////////////////////////////////////////////
2// Matt.Dobbs@Cern.CH, September 1999
3//
4// Polarization object for a particle. All angles are in radians.
5//////////////////////////////////////////////////////////////////////////
6
7#include "Polarization.h"
8
9namespace HepMC {
10
11 Polarization::Polarization( double theta, double phi )
12 : m_theta( valid_theta(theta) ),
13 m_phi ( valid_phi(phi) )
14 { }
15
16 Polarization::Polarization( const Polarization& inpolar )
17 : m_theta( valid_theta( inpolar.theta() ) ),
18 m_phi ( valid_phi( inpolar.phi() ) )
19 { }
20
21 Polarization::Polarization( const ThreeVector& vec3in )
22 : m_theta( valid_theta( vec3in.theta() ) ),
23 m_phi ( valid_phi( vec3in.phi() ) )
24 { }
25
26 void Polarization::swap( Polarization & other)
27 {
28 std::swap( m_theta, other.m_theta );
29 std::swap( m_phi, other.m_phi );
30 }
31
32 Polarization& Polarization::operator=( const Polarization& inpolar ) {
33 /// best practices implementation
34 Polarization tmp( inpolar );
35 swap( tmp );
36 return *this;
37 }
38
39 void Polarization::print( std::ostream& ostr ) const {
40 ostr << "Polarization: " << *this << std::endl;
41 }
42
43 ////////////////////
44 // access methods //
45 ////////////////////
46
47 ThreeVector Polarization::normal3d() const {
48 // unit Hep3Vector for easy manipulation
49 ThreeVector outvec(0,0,1); // makes unit vector along Z
50 outvec.setTheta( theta() ); // sets phi keeping mag and theta constant
51 outvec.setPhi( phi() ); // sets theta keeping mag and phi constant
52 return outvec;
53 }
54
55 double Polarization::set_theta( double theta ) {
56 /// Theta is restricted to be between 0 --> pi
57 /// if an out of range value is given, it is translated to this range.
58 return m_theta = valid_theta( theta );
59 }
60
61 double Polarization::set_phi( double phi ) {
62 /// Phi is restricted to be between 0 --> 2pi
63 /// if an out of range value is given, it is translated to this range.
64 return m_phi = valid_phi( phi );
65 }
66
67 void Polarization::set_theta_phi( double theta, double phi ) {
68 set_theta( theta );
69 set_phi( phi ) ;
70 }
71
72 ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
73 set_theta( vec3in.theta() );
74 set_phi( vec3in.phi() );
75 return vec3in;
76 }
77
78 /////////////////////
79 // private methods //
80 /////////////////////
81
82 double Polarization::valid_theta( double theta ) {
83 // this is just absolute value.
84 theta = ( theta>0 ? theta : -theta );
85 // translate to 0 < theta < 2pi
86 theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) )
87 * 2*HepMC_pi;
88 // now translate to 0 < theta < pi
89 if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta;
90 return theta;
91 }
92
93 double Polarization::valid_phi( double phi ) {
94 //
95 // translate to -2pi < phi < 2pi
96 phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi;
97 // translates to 0 < phi < 2pi
98 if ( phi < 0 ) phi = 2*HepMC_pi + phi;
99 return phi;
100 }
101
102 /////////////
103 // Friends //
104 /////////////
105
106 /// write theta and phi to the output stream
107 std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) {
108 return ostr << "(" << polar.theta()
109 << "," << polar.phi() << ")";
110 }
111
112} // HepMC
113
114
Note: See TracBrowser for help on using the repository browser.