]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TEvtGen/HepMC/Polarization.h
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / TEvtGen / HepMC / Polarization.h
1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_POLARIZATION_H
3 #define HEPMC_POLARIZATION_H
4
5 //////////////////////////////////////////////////////////////////////////
6 // Matt.Dobbs@Cern.CH, September 1999, refer to:
7 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
8 // High Energy Physics", Computer Physics Communications (to be published).
9 //
10 // Polarization object for a particle. All angles are in radians.
11 //////////////////////////////////////////////////////////////////////////
12
13 #include "HepMC/SimpleVector.h"
14 #include <iostream>
15 #include <cmath>
16
17 namespace HepMC {
18
19     static const double HepMC_pi = 3.14159265358979323846;  // copy of pi from CLHEP
20     
21     //! The Polarization class stores theta and phi for a GenParticle
22
23     ///
24     /// \class  Polarization
25     /// HepMC::Polarization stores a particle's theta and phi in radians.
26     /// Use of this information is optional. 
27     /// By default, the polarization is set to zero.
28     ///
29     class Polarization {
30
31         /// print polarization information
32         friend std::ostream& operator<<( std::ostream&, const Polarization& );
33
34     public:
35         /// default constructor
36         Polarization( );
37         /// constructor requiring at least one value
38         Polarization( double theta, double phi = 0 );
39         /// construct from another polarization object
40         Polarization( const Polarization& inpolar );
41         /// construct using the polar and azimuthal angles from a ThreeVector
42         Polarization( const ThreeVector& vec3in );
43         virtual       ~Polarization() {}
44
45         /// swap
46         void swap( Polarization & other);
47         /// make a copy
48         Polarization& operator=( const Polarization& inpolar );
49         /// equality requires that theta and phi are equal
50         bool          operator==( const Polarization& ) const;
51         /// inequality results if either theta or phi differ
52         bool          operator!=( const Polarization& ) const;
53
54         /// print theta and phi
55         void          print( std::ostream& ostr = std::cout ) const;
56     
57         ////////////////////
58         // access methods //
59         ////////////////////
60         double        theta() const;    //!< returns polar angle in radians
61         double        phi() const;      //!< returns azimuthal angle in radians
62         ThreeVector   normal3d() const; //!< unit 3 vector for easy manipulation
63         bool          is_defined() const;   //!< returns true if the Polarization has been defined
64
65         /// set polar angle in radians 
66         double        set_theta( double theta );
67         /// set azimuthal angle in radians 
68         double        set_phi( double phi );
69         /// set both polar and azimuthal angles in radians
70         void          set_theta_phi( double theta, double phi );
71         /// sets polarization according to direction of 3 vec
72         ThreeVector   set_normal3d( const ThreeVector& vec3in ); 
73         /// declares the Polarization as undefined and zeros the values
74         void          set_undefined();
75
76     private:
77         /// private method to return a polar angle in the correct range
78         double valid_theta( double theta );
79         /// private method to return an azimuthal angle in the correct range
80         double valid_phi( double phi );
81
82     private:
83         double m_theta; //polar angle of polarization in radians 0< theta <pi
84         double m_phi;   //azimuthal angle of polarization in rad. 0< phi <2pi
85         bool   m_defined; //used to flag if the Polarization has been defined
86     };
87
88     ///////////////////////////
89     // INLINE Access Methods //
90     ///////////////////////////
91
92     inline double Polarization::theta() const { return m_theta; }
93     inline double Polarization::phi() const { return m_phi; }
94
95     ///////////////////////////
96     // INLINE Operators      //
97     ///////////////////////////
98
99     inline bool Polarization::operator==( const Polarization& a ) const 
100     {
101         return ( a.theta() == this->theta() && a.phi() == this->phi() && a.is_defined() == this->is_defined() );
102     }
103
104     inline bool Polarization::operator!=(const Polarization& a ) const 
105     {
106         return !( a == *this );
107     }
108
109 } // HepMC
110
111 #endif  // HEPMC_POLARIZATION_H
112 //--------------------------------------------------------------------------