BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
InstallArea/include/MdcGeom/MdcGeom/BesAngle.h
Go to the documentation of this file.
1#ifndef __BBRANGLE_H__
2#define __BBRANGLE_H__
3////////////////////////////////
4////////////////////////////////
5//
6// BaBar angles are in radians, and degress should inly be used
7// when absolutely necessary. Automatic conversions to and from
8// the radians form are provided, but you have to manually
9// go to and from degrees
10//
11// By convention, angles are represented as (-pi, pi]
12//
13#include "MdcGeom/Constants.h"
14#include <math.h>
15
16
18{
19public:
20 inline BesAngle();
21 inline BesAngle(const double);
22 inline ~BesAngle();
23
24 inline operator double() const { return _phi;}; // automatic conversion to double
25
26 inline double rad() const;
27 inline double deg() const;
28 // convention : returns value in [-180, 180]
29
30 inline double posRad() const;
31 inline double posDeg() const;
32 // returns 0 to 360. This is not the BaBar convention, and should not
33 // be used for handing off values to anyone else's code
34
35 inline void setRad(const double);
36 inline void setDeg(const double);
37
38 inline double arc(double radius) const;
39
40 inline void setSector(int n, int max);
41 inline void setSector(int n, int max, BesAngle phi_0);
42
43 inline BesAngle operator + (const BesAngle&) const;
44 inline BesAngle operator + (const double) const; //assumes double in radians
45 inline BesAngle operator - (const BesAngle&) const;
46 inline BesAngle operator - (const double) const; //assumes double in radians
47 inline BesAngle operator * (const double) const;
48 inline BesAngle operator / (const double) const;
49 inline friend BesAngle operator * (const double, const BesAngle&);
50
51 inline void operator = (const BesAngle);
52 inline void operator += (BesAngle);
53 inline void operator -= (BesAngle);
54 inline void operator += (double); //assumes double in radians
55 inline void operator -= (double); //assumes double in radians
56 inline void operator *= (double);
57 inline void operator /= (double);
58
59 // note : > and < should have no well defined meaning ?
60
61 inline int sector(int max);
62 inline int sector(int max, BesAngle phi_0);
63 // convention : returns values [1..max]
64//hxt HepString degString() const;
65 inline friend double sin(const BesAngle);
66 inline friend double cos(const BesAngle);
67 inline friend double tan(const BesAngle);
68
69 // class static constants defined in .cc file
70 // these are generally available as Constants::pi, Constants::twoPi, etc,
71 // and once the BaBar/Constants class is in a release they should be
72 /// used instead.
73
74 static const double pi;
75 static const double twoPi;
76
77 // old names, forwarded for migration BobJ May 21 97
78 inline double Rad() const { return rad(); }
79 inline double Deg() const { return deg(); }
80//hxt inline HepString DegString() const { return degString(); }
81 inline int Sector(int max) { return sector(max); }
82 inline int Sector(int max, BesAngle phi_0) { return sector(max, phi_0); }
83
84protected:
85 double _phi;
86
87 inline static double normalize(double);
88
89 static const double toDegrees;
90//hxt static const HepString degChar, deg1Char, deg2Char;
91
92};
93
94//
95// Methods for BesAngle
96//
97
98inline double BesAngle::normalize(double angle) {
99 if (angle < - Constants::pi) {
100 angle += Constants::twoPi;
101 if (angle < - Constants::pi) angle = fmod(angle+ Constants::pi, Constants::twoPi) + Constants::pi;
102 }
103 else if (angle > Constants::pi) {
104 angle -= Constants::twoPi;
105 if (angle > Constants::pi) angle = fmod(angle+Constants::pi, Constants::twoPi) - Constants::pi;
106 }
107 return angle;
108}
109
110inline BesAngle::BesAngle() : _phi(0)
111{ }
112
113inline BesAngle::BesAngle(const double phi) : _phi(normalize(phi))
114{}
115
117
118inline double BesAngle::rad() const
119{ return _phi; }
120
121inline double BesAngle::deg() const
122{ return _phi * Constants::radToDegrees; }
123
124inline double BesAngle::posRad() const
125{
126 if (_phi >= 0.0) return _phi;
127 else return _phi + Constants::twoPi;
128}
129
130inline double BesAngle::posDeg() const
131{ return posRad() * Constants::radToDegrees; }
132
133inline void BesAngle::setRad(const double phi)
134{ _phi = normalize(phi); }
135
136inline void BesAngle::setDeg(const double phi)
138
139inline double BesAngle::arc(double radius) const
140{ return radius * rad(); }
141
142inline void BesAngle::setSector(int n, int max)
143{ setRad((n + 0.5) * Constants::twoPi / max); }
144
145inline void BesAngle::setSector(int n, int max, BesAngle phi_0)
146{ setRad((n + 0.5) * Constants::twoPi / max + phi_0._phi); }
147
149{ return BesAngle(_phi + a._phi); }
150
151inline BesAngle BesAngle::operator + (const double a) const
152{ return BesAngle(_phi + a); }
153
155{ return BesAngle(_phi - a._phi); }
156
157inline BesAngle BesAngle::operator - (const double a) const
158{ return BesAngle(_phi - a); }
159
160inline BesAngle BesAngle::operator * (const double x) const
161{ return BesAngle(_phi * x); }
162
163inline BesAngle BesAngle::operator / (const double x) const
164{ return BesAngle(_phi / x); }
165
166inline BesAngle operator * (const double x, const BesAngle &a)
167{ return BesAngle(a * x); }
168
169inline void BesAngle::operator = (const BesAngle a)
170{ _phi = normalize(a._phi);
171}
172
174{ _phi = normalize(_phi + a._phi );
175}
176
177inline void BesAngle::operator += (double a)
178{ _phi = normalize(_phi + a);
179}
180
182{ _phi = normalize(_phi - a._phi );
183}
184
185inline void BesAngle::operator -= (double a)
186{ _phi = normalize(_phi - a);
187}
188
189inline void BesAngle::operator *= (double x)
190{ _phi = normalize(_phi*x);
191}
192
193inline void BesAngle::operator /= (double x)
194{ _phi = normalize(_phi/x);
195}
196
197inline int BesAngle::sector(int max)
198{
199 double phi = _phi;
200 if (phi < 0) phi += Constants::twoPi;
201 return ( int (phi / (Constants::twoPi / max) ) + 1 );
202}
203
204inline int BesAngle::sector(int max, BesAngle phi_0)
205{
206 BesAngle t( _phi - phi_0._phi);
207 return t.sector(max);
208}
209
210inline double sin(const BesAngle a)
211{ return sin(a._phi); }
212
213inline double cos(const BesAngle a)
214{ return cos(a._phi); }
215
216inline double tan(const BesAngle a)
217{ return tan(a._phi); }
218
219#endif
220
221
const Int_t n
Double_t x[10]
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
BesAngle operator*(const double x, const BesAngle &a)
friend double sin(const BesAngle)
friend double tan(const BesAngle)
double arc(double radius) const
BesAngle operator-(const BesAngle &) const
static const double pi
used instead.
BesAngle operator/(const double) const
friend double cos(const BesAngle)
int Sector(int max, BesAngle phi_0)
BesAngle operator+(const BesAngle &) const
friend BesAngle operator*(const double, const BesAngle &)
int t()
Definition: t.c:1