BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtComplex.hh
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of the EvtGen package developed jointly
5// for the BaBar and CLEO collaborations. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/COPYRIGHT
9// Copyright (C) 1998 Caltech, UCSB
10//
11// Module: EvtGen/EvtVector4R.hh
12//
13// Description: Class to describe complex numbers
14//
15// Modification history:
16//
17// RYD December 5, 1998 Created
18//
19//------------------------------------------------------------------------
20
21#ifndef EVTCOMPLEX_HH
22#define EVTCOMPLEX_HH
23
24#include "EvtConst.hh"
25#include <iostream>
26#include <math.h>
27
29
30 inline friend EvtComplex operator*( double d, const EvtComplex& c );
31 inline friend EvtComplex operator*( const EvtComplex& c, double d );
32 inline friend EvtComplex operator/( const EvtComplex& c, double d );
33 inline friend EvtComplex operator/( double d, const EvtComplex& c );
34 inline friend EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 );
35 inline friend EvtComplex operator/( const EvtComplex& c1, const EvtComplex& c2 );
36 inline friend EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 );
37 inline friend EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 );
38 inline friend EvtComplex operator-( const EvtComplex& c );
39 inline friend EvtComplex conj( const EvtComplex& c );
40 inline friend double abs( const EvtComplex& c );
41 inline friend double abs2( const EvtComplex& c );
42 inline friend double arg( const EvtComplex& c ); // added by FS
43 inline friend double real( const EvtComplex& c );
44 inline friend double imag( const EvtComplex& c );
45 inline friend EvtComplex exp( const EvtComplex& c );
46 friend std::ostream& operator<<( std::ostream& s, const EvtComplex& c );
47
48public:
49 EvtComplex() : _rpart( 0.0 ), _ipart( 0.0 ) {}
50 EvtComplex( double rpart, double ipart = 0.0 ) : _rpart( rpart ), _ipart( ipart ) {}
51 EvtComplex( const EvtComplex& c ) : _rpart( c._rpart ), _ipart( c._ipart ) {}
52 inline EvtComplex& operator*=( double d );
53 inline EvtComplex& operator/=( double d );
56 inline EvtComplex& operator=( const EvtComplex& c );
57 inline EvtComplex& operator+=( const EvtComplex& c );
58 inline EvtComplex& operator-=( const EvtComplex& c );
59 inline EvtComplex& operator+=( double d );
60 inline EvtComplex& operator-=( double d );
61 inline int operator==( const EvtComplex c );
62 inline int operator!=( const EvtComplex c );
63
64private:
65 double _rpart, _ipart;
66};
67
71
73
74 _rpart = c._rpart;
75 _ipart = c._ipart;
76
77 return *this;
78}
79
81
82 _rpart += c._rpart;
83 _ipart += c._ipart;
84
85 return *this;
86}
87
89
90 _rpart -= c._rpart;
91 _ipart -= c._ipart;
92
93 return *this;
94}
95
97
98 _rpart += d;
99
100 return *this;
101}
102
104
105 _rpart -= d;
106
107 return *this;
108}
109
110EvtComplex operator*( double d, const EvtComplex& c ) {
111
112 return EvtComplex( c._rpart * d, c._ipart * d );
113}
114
115EvtComplex operator*( const EvtComplex& c, double d ) {
116
117 return EvtComplex( c._rpart * d, c._ipart * d );
118}
119
120EvtComplex operator/( const EvtComplex& c, double d ) {
121
122 return EvtComplex( c._rpart / d, c._ipart / d );
123}
124
126
127 _rpart *= d;
128 _ipart *= d;
129
130 return *this;
131}
132
134
135 _rpart /= d;
136 _ipart /= d;
137
138 return *this;
139}
140
141EvtComplex operator/( double d, const EvtComplex& c ) {
142
143 double Num = d / ( c._rpart * c._rpart + c._ipart * c._ipart );
144
145 return EvtComplex( Num * c._rpart, -Num * c._ipart );
146}
147
148EvtComplex operator/( const EvtComplex& c1, const EvtComplex& c2 ) {
149
150 double inv = 1.0 / ( c2._rpart * c2._rpart + c2._ipart * c2._ipart );
151
152 return EvtComplex( inv * ( c1._rpart * c2._rpart + c1._ipart * c2._ipart ),
153 inv * ( c1._ipart * c2._rpart - c1._rpart * c2._ipart ) );
154}
155
156EvtComplex operator*( const EvtComplex& c1, const EvtComplex& c2 ) {
157
158 return EvtComplex( c1._rpart * c2._rpart - c1._ipart * c2._ipart,
159 c1._rpart * c2._ipart + c1._ipart * c2._rpart );
160}
161
162EvtComplex operator-( const EvtComplex& c1, const EvtComplex& c2 ) {
163
164 return EvtComplex( c1._rpart - c2._rpart, c1._ipart - c2._ipart );
165}
166
167EvtComplex operator+( const EvtComplex& c1, const EvtComplex& c2 ) {
168
169 return EvtComplex( c1._rpart + c2._rpart, c1._ipart + c2._ipart );
170}
171
173
174 return _rpart == c._rpart && _ipart == c._ipart;
175}
176
178
179 return _rpart != c._rpart || _ipart != c._ipart;
180}
181
182EvtComplex operator-( const EvtComplex& c ) { return EvtComplex( -c._rpart, -c._ipart ); }
183
184EvtComplex conj( const EvtComplex& c ) { return EvtComplex( c._rpart, -c._ipart ); }
185
186double abs( const EvtComplex& c ) {
187
188 double c2 = c._rpart * c._rpart + c._ipart * c._ipart;
189 if ( c2 <= 0.0 ) return 0.0;
190 return sqrt( c2 );
191}
192
193double abs2( const EvtComplex& c ) { return c._rpart * c._rpart + c._ipart * c._ipart; }
194
195double arg( const EvtComplex& c ) { // added by FS
196 if ( ( c._rpart == 0 ) && ( c._ipart == 0 ) ) { return 0.0; }
197 if ( c._rpart == 0 )
198 {
199 if ( c._ipart > 0 ) { return EvtConst::pi / 2; }
200 else { return -EvtConst::pi / 2; }
201 }
202 else { return atan2( c._ipart, c._rpart ); }
203}
204
205double real( const EvtComplex& c ) { return c._rpart; }
206
207double imag( const EvtComplex& c ) { return c._ipart; }
208
210
211 return exp( c._rpart ) * EvtComplex( cos( c._ipart ), sin( c._ipart ) );
212}
213
214#endif
EvtComplex conj(const EvtComplex &c)
double imag(const EvtComplex &c)
EvtComplexPtrPtr * EvtComplexPtrPtrPtr
Definition EvtComplex.hh:70
double abs2(const EvtComplex &c)
EvtComplex exp(const EvtComplex &c)
EvtComplex operator/(const EvtComplex &c, double d)
EvtComplex * EvtComplexPtr
Definition EvtComplex.hh:68
EvtComplex operator*(double d, const EvtComplex &c)
EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
double arg(const EvtComplex &c)
EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
EvtComplexPtr * EvtComplexPtrPtr
Definition EvtComplex.hh:69
XmlRpcServer s
EvtComplex & operator+=(const EvtComplex &c)
Definition EvtComplex.hh:80
friend EvtComplex conj(const EvtComplex &c)
friend double imag(const EvtComplex &c)
friend std::ostream & operator<<(std::ostream &s, const EvtComplex &c)
EvtComplex & operator=(const EvtComplex &c)
Definition EvtComplex.hh:72
friend double abs2(const EvtComplex &c)
EvtComplex(const EvtComplex &c)
Definition EvtComplex.hh:51
friend EvtComplex exp(const EvtComplex &c)
EvtComplex & operator*=(double d)
friend EvtComplex operator/(const EvtComplex &c, double d)
int operator!=(const EvtComplex c)
EvtComplex(double rpart, double ipart=0.0)
Definition EvtComplex.hh:50
friend EvtComplex operator*(double d, const EvtComplex &c)
EvtComplex & operator-=(const EvtComplex &c)
Definition EvtComplex.hh:88
EvtComplex & operator/=(double d)
friend EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
friend double arg(const EvtComplex &c)
friend EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
int operator==(const EvtComplex c)
static const double pi
Definition EvtConst.hh:27