Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Phi.h

Go to the documentation of this file.
00001 //===============================================
00002 //                Phi class
00003 //===============================================
00004 //
00005 //  A utility class to implement the cyclic nature
00006 //  of the phi variable in the range  -Pi <-> Pi
00007 // 
00008 //  The constructor uses a double number, which is reduced to
00009 //  the required range by repeated addition or subtraction of 2*Pi
00010 // 
00011 //  The operation in any arithmetic expression involving Phi and
00012 //  double numbers is understood in this way:
00013 //
00014 //  - wherever any double number is used then it is implicitly converted
00015 //    to a Phi as per the constructor. The operation then proceeds exactly
00016 //    as if the expression contained only 
00017 //
00018 // -  The user can add and subtract Phi objects and the result is automatically
00019 //  kept within a cyclic range.
00020 //
00021 //  -The difference between two PHI objects always represents the smallest 
00022 //   angle between them, signed according to whether this is clockwise
00023 //   or anticlockwise.
00024 //
00025 // - Most operations are convertable to use a double arguments where sensible. 
00026 //
00027 
00028 
00029 #ifndef PHI_H
00030 #define PHI_H
00031 //#include "GaudiKernel/MsgStream.h"
00032 class Phi;
00033 class MsgStream;
00034 //output operators for the Athena MessageStream 
00035 MsgStream& operator << ( MsgStream&, const Phi& ) ;      
00036 MsgStream& operator << ( MsgStream&, const Phi* const) ; 
00037 
00042 class Phi {
00043   
00044  private:
00045   
00046   double m_val ;
00047   
00048   void reduce() {
00049     while( m_val >  s_upperLimit )  { m_val -= s_range ; }
00050     while( m_val <= s_lowerLimit  ) { m_val += s_range ; }
00051   }
00052   static const double s_upperLimit;
00053   static const double s_lowerLimit;
00054   static const double s_range;
00055   
00056   
00057   
00058  public:
00059   
00060   // Constructors:
00061   Phi() { this->m_val = 0. ;  }
00062   Phi( const double init ) { this->m_val = init ; this->reduce() ; }
00063   Phi( Phi& src ) { this->m_val = src.m_val ; } 
00064   
00065   // Arithmetic:
00066   
00067   Phi& operator= ( const Phi& rhs ) { 
00068     this->m_val = rhs.m_val; 
00069     return *this; 
00070   }
00071   
00072   Phi& operator+= ( Phi& rhs )  { 
00073     this->m_val += rhs.m_val ; 
00074     reduce() ;
00075     return *this; 
00076   }
00077   
00078   Phi& operator-= ( Phi& in )  { 
00079     this->m_val -= in.m_val;
00080     reduce() ;
00081     return *this; 
00082   }
00083   
00084   Phi operator+ ( Phi& in )  const { 
00085     Phi result( this->m_val + in.m_val ) ;
00086     return result ;
00087   }
00088   
00089   Phi operator- ( Phi& in )  const { 
00090     Phi result(this->m_val - in.m_val ) ;
00091     return result ;
00092   }
00093   
00094   // boolean 
00095   bool operator< ( Phi& in ) const { return this->m_val < in.m_val ; }
00096   bool operator> ( Phi& in ) const { return this->m_val > in.m_val ; }
00097   
00098   // Conversions
00099   operator double() const { return this->m_val ; }
00100   // debug
00101   double lowerLimit() const {return s_lowerLimit;}
00102   double upperLimit() const {return s_upperLimit;}
00103   double range     () const {return s_range;}
00104   double val()        const {return m_val;}
00105 };
00106 #endif
00107 

Generated on Thu Feb 21 14:30:46 2002 for Atlfast by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001