StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Polarization.cc
1 // Matt.Dobbs@Cern.CH, September 1999
3 //
4 // Polarization object for a particle. All angles are in radians.
6 
7 #include "HepMC/Polarization.h"
8 
9 namespace HepMC {
10 
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 
24  : m_theta( valid_theta( inpolar.theta() ) ),
25  m_phi ( valid_phi( inpolar.phi() ) ),
26  m_defined( inpolar.is_defined() )
27  { }
28 
30  : m_theta( valid_theta( vec3in.theta() ) ),
31  m_phi ( valid_phi( vec3in.phi() ) ),
32  m_defined( true )
33  { }
34 
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 
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 
54  // access methods //
56 
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 ) {
68  return m_theta = valid_theta( theta );
69  }
70 
71  double Polarization::set_phi( double phi ) {
74  return m_phi = valid_phi( phi );
75  }
76 
77  bool Polarization::is_defined( ) const {
78  return m_defined;
79  }
80 
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 
94  set_theta( vec3in.theta() );
95  set_phi( vec3in.phi() );
96  m_defined = true;
97  return vec3in;
98  }
99 
101  // private methods //
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 
125  // Friends //
127 
129  std::ostream& operator<<( std::ostream& ostr, const Polarization& polar ) {
130  return ostr << "(" << polar.theta()
131  << "," << polar.phi() << ")";
132  }
133 
134 } // HepMC
135 
136 
void print(std::ostream &ostr=std::cout) const
print theta and phi
Definition: Polarization.cc:49
double theta() const
The polar angle.
void set_undefined()
declares the Polarization as undefined and zeros the values
Definition: Polarization.cc:81
double set_theta(double theta)
set polar angle in radians
Definition: Polarization.cc:65
ThreeVector set_normal3d(const ThreeVector &vec3in)
sets polarization according to direction of 3 vec
Definition: Polarization.cc:93
void setPhi(double)
Set phi keeping magnitude and theta constant (BaBar).
ThreeVector is a simple representation of a position or displacement 3 vector.
Definition: SimpleVector.h:131
ThreeVector normal3d() const
unit 3 vector for easy manipulation
Definition: Polarization.cc:57
double theta() const
returns polar angle in radians
Definition: Polarization.h:92
Polarization()
default constructor
Definition: Polarization.cc:11
double phi() const
The azimuth angle.
double set_phi(double phi)
set azimuthal angle in radians
Definition: Polarization.cc:71
The Polarization class stores theta and phi for a GenParticle.
Definition: Polarization.h:29
void swap(Polarization &other)
swap
Definition: Polarization.cc:35
Polarization & operator=(const Polarization &inpolar)
make a copy
Definition: Polarization.cc:42
void set_theta_phi(double theta, double phi)
set both polar and azimuthal angles in radians
Definition: Polarization.cc:87
bool is_defined() const
returns true if the Polarization has been defined
Definition: Polarization.cc:77
void setTheta(double)
Set theta keeping magnitude and phi constant (BaBar).
double phi() const
returns azimuthal angle in radians
Definition: Polarization.h:93