BOSS 7.0.4
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 <iostream>
25#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);
63private:
64 double _rpart,_ipart;
65};
66
67
71
72
74
75 _rpart=c._rpart;
76 _ipart=c._ipart;
77
78 return *this;
79}
80
82
83 _rpart+=c._rpart;
84 _ipart+=c._ipart;
85
86 return *this;
87}
88
90
91 _rpart-=c._rpart;
92 _ipart-=c._ipart;
93
94 return *this;
95}
96
98
99 _rpart+=d;
100
101 return *this;
102}
103
105
106 _rpart-=d;
107
108 return *this;
109}
110
111EvtComplex operator*(double d,const EvtComplex& c){
112
113 return EvtComplex(c._rpart*d,c._ipart*d);
114
115}
116
117EvtComplex operator*(const EvtComplex& c, double d){
118
119 return EvtComplex(c._rpart*d,c._ipart*d);
120
121}
122
123
124
125EvtComplex operator/(const EvtComplex& c,double d){
126
127 return EvtComplex(c._rpart/d,c._ipart/d);
128
129}
130
132
133 _rpart*=d;
134 _ipart*=d;
135
136 return *this;
137
138}
139
140
142
143 _rpart/=d;
144 _ipart/=d;
145
146 return *this;
147}
148
149EvtComplex operator/(double d,const EvtComplex& c) {
150
151double Num=d/(c._rpart*c._rpart+c._ipart*c._ipart);
152
153return EvtComplex( Num*c._rpart, -Num*c._ipart );
154
155}
156
157
158
160
161 double inv=1.0/(c2._rpart*c2._rpart+c2._ipart*c2._ipart);
162
163 return EvtComplex(inv*(c1._rpart*c2._rpart+c1._ipart*c2._ipart),
164 inv*(c1._ipart*c2._rpart-c1._rpart*c2._ipart));
165
166}
167
169
170 return EvtComplex(c1._rpart*c2._rpart-c1._ipart*c2._ipart,
171 c1._rpart*c2._ipart+c1._ipart*c2._rpart);
172
173}
174
176
177 return EvtComplex(c1._rpart-c2._rpart,c1._ipart-c2._ipart);
178
179}
180
182
183 return EvtComplex(c1._rpart+c2._rpart,c1._ipart+c2._ipart);
184
185}
186
188
189 return _rpart==c._rpart&&_ipart==c._ipart;
190
191}
192
194
195 return _rpart!=c._rpart||_ipart!=c._ipart;
196
197}
198
199
201
202 return EvtComplex(-c._rpart,-c._ipart);
203
204}
205
207
208 return EvtComplex(c._rpart,-c._ipart);
209
210}
211
212double abs(const EvtComplex& c){
213
214 double c2=c._rpart*c._rpart+c._ipart*c._ipart;
215 if (c2<=0.0) return 0.0;
216 return sqrt(c2);
217
218}
219
220
221double abs2(const EvtComplex& c){
222
223 return c._rpart*c._rpart+c._ipart*c._ipart;
224}
225
226
227double arg(const EvtComplex& c){ //added by FS
228 if ((c._rpart==0)&&(c._ipart==0)) {return 0.0;}
229 if (c._rpart==0){
230 if (c._ipart>0){
231 return EvtConst::pi/2;
232 } else {
233 return -EvtConst::pi/2;
234 }
235 } else {
236 return atan2(c._ipart,c._rpart);
237 }
238}
239
240double real(const EvtComplex& c){
241
242 return c._rpart;
243
244}
245
246double imag(const EvtComplex& c){
247
248 return c._ipart;
249
250}
251
253
254 return exp(c._rpart)*EvtComplex(cos(c._ipart),sin(c._ipart));
255
256}
257
258
259
260#endif
261
262
263
264
265
266
267
EvtComplex conj(const EvtComplex &c)
Definition: EvtComplex.hh:206
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:246
EvtComplexPtrPtr * EvtComplexPtrPtrPtr
Definition: EvtComplex.hh:70
double abs2(const EvtComplex &c)
Definition: EvtComplex.hh:221
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
EvtComplex operator/(const EvtComplex &c, double d)
Definition: EvtComplex.hh:125
EvtComplex * EvtComplexPtr
Definition: EvtComplex.hh:68
EvtComplex operator*(double d, const EvtComplex &c)
Definition: EvtComplex.hh:111
EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
Definition: EvtComplex.hh:175
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
Definition: EvtComplex.hh:181
EvtComplexPtr * EvtComplexPtrPtr
Definition: EvtComplex.hh:69
XmlRpcServer s
Definition: HelloServer.cpp:11
double sin(const BesAngle a)
double cos(const BesAngle a)
EvtComplex & operator+=(const EvtComplex &c)
Definition: EvtComplex.hh:81
friend EvtComplex conj(const EvtComplex &c)
Definition: EvtComplex.hh:206
friend double imag(const EvtComplex &c)
Definition: EvtComplex.hh:246
friend std::ostream & operator<<(std::ostream &s, const EvtComplex &c)
EvtComplex & operator=(const EvtComplex &c)
Definition: EvtComplex.hh:73
friend double real(const EvtComplex &c)
Definition: EvtComplex.hh:240
friend double abs2(const EvtComplex &c)
Definition: EvtComplex.hh:221
EvtComplex(const EvtComplex &c)
Definition: EvtComplex.hh:51
friend EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
EvtComplex & operator*=(double d)
Definition: EvtComplex.hh:131
friend EvtComplex operator/(const EvtComplex &c, double d)
Definition: EvtComplex.hh:125
int operator!=(const EvtComplex c)
Definition: EvtComplex.hh:193
EvtComplex(double rpart, double ipart=0.0)
Definition: EvtComplex.hh:50
friend EvtComplex operator*(double d, const EvtComplex &c)
Definition: EvtComplex.hh:111
EvtComplex & operator-=(const EvtComplex &c)
Definition: EvtComplex.hh:89
EvtComplex & operator/=(double d)
Definition: EvtComplex.hh:141
friend EvtComplex operator-(const EvtComplex &c1, const EvtComplex &c2)
Definition: EvtComplex.hh:175
friend double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
friend EvtComplex operator+(const EvtComplex &c1, const EvtComplex &c2)
Definition: EvtComplex.hh:181
int operator==(const EvtComplex c)
Definition: EvtComplex.hh:187
friend double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
static const double pi
Definition: EvtConst.hh:28