/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcGeom/MdcGeom-00-01-17/MdcGeom/BesAngle.h

Go to the documentation of this file.
00001 #ifndef __BBRANGLE_H__
00002 #define __BBRANGLE_H__
00005 //
00006 // BaBar angles are in radians, and degress should inly be used
00007 // when absolutely necessary. Automatic conversions to and from
00008 // the radians form are provided, but you have to manually
00009 // go to and from degrees
00010 //
00011 // By convention, angles are represented as (-pi, pi]
00012 //
00013 #include "MdcGeom/Constants.h"
00014 #include <math.h>
00015 
00016 
00017 class BesAngle
00018 {
00019 public:
00020   inline BesAngle();
00021   inline BesAngle(const double);
00022   inline ~BesAngle();
00023 
00024   inline operator double() const  { return _phi;};   // automatic conversion to double
00025 
00026   inline double rad() const;  
00027   inline double deg() const;  
00028   // convention : returns value in [-180, 180]
00029 
00030   inline double posRad() const;
00031   inline double posDeg() const;
00032   // returns 0 to 360.  This is not the BaBar convention, and should not 
00033   // be used for handing off values to anyone else's code
00034 
00035   inline void setRad(const double);
00036   inline void setDeg(const double);
00037 
00038   inline double arc(double radius) const;
00039 
00040   inline void setSector(int n, int max);
00041   inline void setSector(int n, int max, BesAngle phi_0);
00042 
00043   inline BesAngle operator + (const BesAngle&) const;
00044   inline BesAngle operator + (const double) const;  //assumes double in radians
00045   inline BesAngle operator - (const BesAngle&) const;
00046   inline BesAngle operator - (const double) const;  //assumes double in radians
00047   inline BesAngle operator * (const double) const;
00048   inline BesAngle operator / (const double) const;
00049   inline friend BesAngle operator * (const double, const BesAngle&);
00050 
00051   inline void operator = (const BesAngle);
00052   inline void operator += (BesAngle);
00053   inline void operator -= (BesAngle);
00054   inline void operator += (double);  //assumes double in radians
00055   inline void operator -= (double);  //assumes double in radians
00056   inline void operator *= (double);
00057   inline void operator /= (double);
00058 
00059   // note : > and < should have no well defined meaning ?
00060 
00061   inline int sector(int max);
00062   inline int sector(int max, BesAngle phi_0); 
00063    // convention : returns values [1..max]
00064 //hxt   HepString degString() const;
00065   inline friend double sin(const BesAngle);
00066   inline friend double cos(const BesAngle);
00067   inline friend double tan(const BesAngle);
00068 
00069   // class static constants defined in .cc file
00070   // these are generally available as Constants::pi, Constants::twoPi, etc,
00071   // and once the BaBar/Constants class is in a release they should be
00073 
00074   static const double pi;
00075   static const double twoPi;
00076 
00077   // old names, forwarded for migration BobJ May 21 97
00078   inline double Rad() const { return rad(); }
00079   inline double Deg() const { return deg(); }
00080 //hxt   inline HepString DegString() const { return degString(); }
00081   inline int Sector(int max) { return sector(max); }
00082   inline int Sector(int max, BesAngle phi_0) { return sector(max, phi_0); }
00083 
00084 protected:
00085   double _phi;
00086 
00087   inline static double normalize(double);
00088 
00089   static const double toDegrees;
00090 //hxt   static  const HepString degChar, deg1Char, deg2Char;
00091 
00092 };
00093 
00094 //
00095 // Methods for BesAngle
00096 //
00097 
00098 inline double BesAngle::normalize(double angle) {
00099   if (angle < - Constants::pi) {
00100     angle += Constants::twoPi;
00101     if (angle < - Constants::pi) angle = fmod(angle+ Constants::pi, Constants::twoPi) + Constants::pi; 
00102   }
00103   else if (angle > Constants::pi) {
00104     angle -= Constants::twoPi;
00105     if (angle > Constants::pi) angle = fmod(angle+Constants::pi, Constants::twoPi) - Constants::pi;
00106   }
00107   return angle;
00108 }
00109 
00110 inline BesAngle::BesAngle() : _phi(0)
00111 { }
00112 
00113 inline BesAngle::BesAngle(const double phi) : _phi(normalize(phi))
00114 {}
00115 
00116 inline BesAngle::~BesAngle() {}
00117 
00118 inline double BesAngle::rad() const
00119 { return _phi; }
00120 
00121 inline double BesAngle::deg() const
00122 { return _phi *  Constants::radToDegrees; }
00123 
00124 inline double BesAngle::posRad() const
00125 { 
00126   if (_phi >= 0.0) return _phi; 
00127   else return _phi + Constants::twoPi;
00128 }
00129 
00130 inline double BesAngle::posDeg() const
00131 { return posRad() *  Constants::radToDegrees; }
00132 
00133 inline void BesAngle::setRad(const double phi)
00134 { _phi = normalize(phi); }
00135 
00136 inline void BesAngle::setDeg(const double phi)
00137 { setRad(phi / Constants::radToDegrees); }
00138 
00139 inline double BesAngle::arc(double radius) const
00140 { return radius * rad(); }
00141 
00142 inline void BesAngle::setSector(int n, int max)
00143 { setRad((n + 0.5) * Constants::twoPi / max); }
00144 
00145 inline void BesAngle::setSector(int n, int max, BesAngle phi_0)
00146 { setRad((n + 0.5) * Constants::twoPi / max + phi_0._phi); }
00147 
00148 inline BesAngle BesAngle::operator + (const BesAngle &a) const
00149 { return BesAngle(_phi + a._phi); }
00150 
00151 inline BesAngle BesAngle::operator + (const double a) const
00152 { return BesAngle(_phi + a); }
00153 
00154 inline BesAngle BesAngle::operator - (const BesAngle &a) const
00155 { return BesAngle(_phi - a._phi); }
00156 
00157 inline BesAngle BesAngle::operator - (const double a) const
00158 { return BesAngle(_phi - a); }
00159 
00160 inline BesAngle BesAngle::operator * (const double x) const
00161 { return BesAngle(_phi * x); }
00162 
00163 inline BesAngle BesAngle::operator / (const double x) const
00164 { return BesAngle(_phi / x); }
00165 
00166 inline BesAngle operator * (const double x, const BesAngle &a)
00167 { return BesAngle(a * x); }
00168 
00169 inline void BesAngle::operator = (const BesAngle a)
00170 { _phi = normalize(a._phi); 
00171 }
00172 
00173 inline void BesAngle::operator += (BesAngle a)
00174 { _phi = normalize(_phi + a._phi );
00175 }
00176 
00177 inline void BesAngle::operator += (double a)
00178 { _phi = normalize(_phi + a); 
00179 }
00180 
00181 inline void BesAngle::operator -= (BesAngle a)
00182 { _phi = normalize(_phi - a._phi ); 
00183 }
00184 
00185 inline void BesAngle::operator -= (double a)
00186 { _phi = normalize(_phi - a); 
00187 }
00188 
00189 inline void BesAngle::operator *= (double x)
00190 { _phi = normalize(_phi*x); 
00191 }
00192 
00193 inline void BesAngle::operator /= (double x)
00194 { _phi = normalize(_phi/x); 
00195 }
00196 
00197 inline int BesAngle::sector(int max)
00198 { 
00199   double phi = _phi;
00200   if (phi < 0) phi += Constants::twoPi;
00201   return ( int (phi / (Constants::twoPi / max) ) + 1 );
00202 }
00203 
00204 inline int BesAngle::sector(int max, BesAngle phi_0)
00205 { 
00206   BesAngle t( _phi - phi_0._phi);
00207   return t.sector(max);
00208 }
00209 
00210 inline double sin(const BesAngle a)
00211 { return sin(a._phi); }
00212 
00213 inline double cos(const BesAngle a)
00214 { return cos(a._phi); }
00215 
00216 inline double tan(const BesAngle a)
00217 { return tan(a._phi); }
00218 
00219 #endif
00220 
00221 

Generated on Tue Nov 29 23:13:30 2016 for BOSS_7.0.2 by  doxygen 1.4.7