LCOV - code coverage report
Current view: top level - TEvtGen/HepMC - Polarization.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 54 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 21 0.0 %

          Line data    Source code
       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           0 :     : m_theta( 0. ),
      13           0 :       m_phi( 0. ),
      14           0 :       m_defined( false )
      15           0 :     { }
      16             : 
      17             :     Polarization::Polarization( double theta, double phi )
      18           0 :     : m_theta( valid_theta(theta) ),
      19           0 :       m_phi  ( valid_phi(phi) ),
      20           0 :       m_defined( true )
      21           0 :     { }
      22             : 
      23             :     Polarization::Polarization( const Polarization& inpolar )
      24           0 :     : m_theta( valid_theta( inpolar.theta() ) ),
      25           0 :       m_phi  ( valid_phi(   inpolar.phi()   ) ),
      26           0 :       m_defined( inpolar.is_defined() )
      27           0 :     { }
      28             : 
      29             :     Polarization::Polarization( const ThreeVector& vec3in ) 
      30           0 :     : m_theta( valid_theta( vec3in.theta() ) ),
      31           0 :       m_phi  ( valid_phi(   vec3in.phi()   ) ),
      32           0 :       m_defined( true )
      33           0 :     { }
      34             : 
      35             :     void Polarization::swap( Polarization & other)
      36             :     {
      37           0 :         std::swap( m_theta, other.m_theta );
      38           0 :         std::swap( m_phi,   other.m_phi   );
      39           0 :         std::swap( m_defined, other.m_defined );
      40           0 :     }
      41             : 
      42             :     Polarization& Polarization::operator=( const Polarization& inpolar ) {
      43             :         /// best practices implementation
      44           0 :         Polarization tmp( inpolar );
      45           0 :         swap( tmp ); 
      46             :         return *this;
      47           0 :     }
      48             : 
      49             :     void Polarization::print( std::ostream& ostr ) const {
      50           0 :         ostr << "Polarization: " << *this << std::endl;
      51           0 :     }
      52             : 
      53             :     ////////////////////
      54             :     // access methods //
      55             :     ////////////////////
      56             : 
      57             :     ThreeVector  Polarization::normal3d() const {
      58             :         // unit Hep3Vector for easy manipulation
      59           0 :         ThreeVector outvec(0,0,1);      // makes unit vector along Z
      60           0 :         outvec.setTheta( theta() ); // sets phi keeping mag and theta constant
      61           0 :         outvec.setPhi( phi() );     // sets theta keeping mag and phi constant
      62           0 :         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           0 :         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           0 :         return m_phi = valid_phi( phi );
      75             :     }
      76             :     
      77             :     bool Polarization::is_defined( ) const {
      78           0 :         return m_defined;
      79             :     }
      80             :     
      81             :     void Polarization::set_undefined() {
      82           0 :         m_defined = false;
      83           0 :         m_theta = 0.;
      84           0 :         m_phi = 0.;
      85           0 :     }
      86             : 
      87             :     void Polarization::set_theta_phi( double theta, double phi ) {
      88           0 :         set_theta( theta );
      89           0 :         set_phi( phi ) ;
      90           0 :         m_defined = true;
      91           0 :     }
      92             : 
      93             :     ThreeVector Polarization::set_normal3d( const ThreeVector& vec3in ) {
      94           0 :         set_theta( vec3in.theta() );
      95           0 :         set_phi( vec3in.phi() );
      96           0 :         m_defined = true;
      97           0 :         return vec3in;
      98             :     }
      99             : 
     100             :     /////////////////////
     101             :     // private methods //
     102             :     /////////////////////
     103             : 
     104             :     double Polarization::valid_theta( double theta ) {
     105             :         // this is just absolute value.
     106           0 :         theta = ( theta>0 ? theta : -theta );
     107             :         // translate to 0 < theta < 2pi
     108           0 :         theta = ( theta/(2*HepMC_pi) - int(theta/(2*HepMC_pi)) ) 
     109           0 :                 * 2*HepMC_pi;
     110             :         // now translate to 0 < theta < pi
     111           0 :         if ( theta > HepMC_pi ) theta = 2*HepMC_pi - theta;
     112           0 :         return theta;
     113             :     }
     114             : 
     115             :     double Polarization::valid_phi( double phi ) {
     116             :         //
     117             :         // translate to -2pi < phi < 2pi
     118           0 :         phi = ( phi/(2*HepMC_pi) - int(phi/(2*HepMC_pi)) ) * 2*HepMC_pi;
     119             :         // translates to 0 < phi < 2pi
     120           0 :         if ( phi < 0 ) phi = 2*HepMC_pi + phi;
     121           0 :         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           0 :         return ostr << "(" << polar.theta() 
     131           0 :                     << ","  << polar.phi() << ")";
     132             :     }
     133             :     
     134             : } // HepMC
     135             : 
     136             : 

Generated by: LCOV version 1.11