00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef EVTCOMPLEX_HH
00022 #define EVTCOMPLEX_HH
00023
00024 #include <iostream>
00025 #include <math.h>
00026 #include "EvtGenBase/EvtConst.hh"
00027
00028 class EvtComplex {
00029
00030 inline friend EvtComplex operator*(double d,const EvtComplex& c);
00031 inline friend EvtComplex operator*(const EvtComplex& c,double d);
00032 inline friend EvtComplex operator/(const EvtComplex& c,double d);
00033 inline friend EvtComplex operator/(double d,const EvtComplex& c);
00034 inline friend EvtComplex operator*(const EvtComplex& c1,const EvtComplex& c2);
00035 inline friend EvtComplex operator/(const EvtComplex& c1,const EvtComplex& c2);
00036 inline friend EvtComplex operator+(const EvtComplex& c1,const EvtComplex& c2);
00037 inline friend EvtComplex operator-(const EvtComplex& c1,const EvtComplex& c2);
00038 inline friend EvtComplex operator-(const EvtComplex& c);
00039 inline friend EvtComplex conj(const EvtComplex& c);
00040 inline friend double abs(const EvtComplex& c);
00041 inline friend double abs2(const EvtComplex& c);
00042 inline friend double arg(const EvtComplex& c);
00043 inline friend double real(const EvtComplex& c);
00044 inline friend double imag(const EvtComplex& c);
00045 inline friend EvtComplex exp(const EvtComplex& c);
00046 friend std::ostream& operator<<(std::ostream& s, const EvtComplex& c);
00047
00048 public:
00049 EvtComplex():_rpart(0.0),_ipart(0.0){}
00050 EvtComplex(double rpart,double ipart=0.0):_rpart(rpart),_ipart(ipart){}
00051 EvtComplex(const EvtComplex& c):_rpart(c._rpart),_ipart(c._ipart){}
00052 inline EvtComplex& operator*=(double d);
00053 inline EvtComplex& operator/=(double d);
00054 EvtComplex& operator*=(EvtComplex c);
00055 EvtComplex& operator/=(EvtComplex c);
00056 inline EvtComplex& operator=(const EvtComplex& c);
00057 inline EvtComplex& operator+=(const EvtComplex& c);
00058 inline EvtComplex& operator-=(const EvtComplex& c);
00059 inline EvtComplex& operator+=(double d);
00060 inline EvtComplex& operator-=(double d);
00061 inline int operator==(const EvtComplex c);
00062 inline int operator!=(const EvtComplex c);
00063 private:
00064 double _rpart,_ipart;
00065 };
00066
00067
00068 typedef EvtComplex* EvtComplexPtr;
00069 typedef EvtComplexPtr* EvtComplexPtrPtr;
00070 typedef EvtComplexPtrPtr* EvtComplexPtrPtrPtr;
00071
00072
00073 EvtComplex& EvtComplex::operator=(const EvtComplex& c){
00074
00075 _rpart=c._rpart;
00076 _ipart=c._ipart;
00077
00078 return *this;
00079 }
00080
00081 EvtComplex& EvtComplex::operator+=(const EvtComplex& c){
00082
00083 _rpart+=c._rpart;
00084 _ipart+=c._ipart;
00085
00086 return *this;
00087 }
00088
00089 EvtComplex& EvtComplex::operator-=(const EvtComplex& c){
00090
00091 _rpart-=c._rpart;
00092 _ipart-=c._ipart;
00093
00094 return *this;
00095 }
00096
00097 EvtComplex& EvtComplex::operator+=(double d){
00098
00099 _rpart+=d;
00100
00101 return *this;
00102 }
00103
00104 EvtComplex& EvtComplex::operator-=(double d){
00105
00106 _rpart-=d;
00107
00108 return *this;
00109 }
00110
00111 EvtComplex operator*(double d,const EvtComplex& c){
00112
00113 return EvtComplex(c._rpart*d,c._ipart*d);
00114
00115 }
00116
00117 EvtComplex operator*(const EvtComplex& c, double d){
00118
00119 return EvtComplex(c._rpart*d,c._ipart*d);
00120
00121 }
00122
00123
00124
00125 EvtComplex operator/(const EvtComplex& c,double d){
00126
00127 return EvtComplex(c._rpart/d,c._ipart/d);
00128
00129 }
00130
00131 EvtComplex& EvtComplex::operator*=(double d){
00132
00133 _rpart*=d;
00134 _ipart*=d;
00135
00136 return *this;
00137
00138 }
00139
00140
00141 EvtComplex& EvtComplex::operator/=(double d){
00142
00143 _rpart/=d;
00144 _ipart/=d;
00145
00146 return *this;
00147 }
00148
00149 EvtComplex operator/(double d,const EvtComplex& c) {
00150
00151 double Num=d/(c._rpart*c._rpart+c._ipart*c._ipart);
00152
00153 return EvtComplex( Num*c._rpart, -Num*c._ipart );
00154
00155 }
00156
00157
00158
00159 EvtComplex operator/(const EvtComplex& c1,const EvtComplex& c2){
00160
00161 double inv=1.0/(c2._rpart*c2._rpart+c2._ipart*c2._ipart);
00162
00163 return EvtComplex(inv*(c1._rpart*c2._rpart+c1._ipart*c2._ipart),
00164 inv*(c1._ipart*c2._rpart-c1._rpart*c2._ipart));
00165
00166 }
00167
00168 EvtComplex operator*(const EvtComplex& c1,const EvtComplex& c2){
00169
00170 return EvtComplex(c1._rpart*c2._rpart-c1._ipart*c2._ipart,
00171 c1._rpart*c2._ipart+c1._ipart*c2._rpart);
00172
00173 }
00174
00175 EvtComplex operator-(const EvtComplex& c1,const EvtComplex& c2){
00176
00177 return EvtComplex(c1._rpart-c2._rpart,c1._ipart-c2._ipart);
00178
00179 }
00180
00181 EvtComplex operator+(const EvtComplex& c1,const EvtComplex& c2){
00182
00183 return EvtComplex(c1._rpart+c2._rpart,c1._ipart+c2._ipart);
00184
00185 }
00186
00187 int EvtComplex::operator==(const EvtComplex c){
00188
00189 return _rpart==c._rpart&&_ipart==c._ipart;
00190
00191 }
00192
00193 int EvtComplex::operator!=(const EvtComplex c){
00194
00195 return _rpart!=c._rpart||_ipart!=c._ipart;
00196
00197 }
00198
00199
00200 EvtComplex operator-(const EvtComplex& c){
00201
00202 return EvtComplex(-c._rpart,-c._ipart);
00203
00204 }
00205
00206 EvtComplex conj(const EvtComplex& c){
00207
00208 return EvtComplex(c._rpart,-c._ipart);
00209
00210 }
00211
00212 double abs(const EvtComplex& c){
00213
00214 double c2=c._rpart*c._rpart+c._ipart*c._ipart;
00215 if (c2<=0.0) return 0.0;
00216 return sqrt(c2);
00217
00218 }
00219
00220
00221 double abs2(const EvtComplex& c){
00222
00223 return c._rpart*c._rpart+c._ipart*c._ipart;
00224 }
00225
00226
00227 double arg(const EvtComplex& c){
00228 if ((c._rpart==0)&&(c._ipart==0)) {return 0.0;}
00229 if (c._rpart==0){
00230 if (c._ipart>0){
00231 return EvtConst::pi/2;
00232 } else {
00233 return -EvtConst::pi/2;
00234 }
00235 } else {
00236 return atan2(c._ipart,c._rpart);
00237 }
00238 }
00239
00240 double real(const EvtComplex& c){
00241
00242 return c._rpart;
00243
00244 }
00245
00246 double imag(const EvtComplex& c){
00247
00248 return c._ipart;
00249
00250 }
00251
00252 EvtComplex exp(const EvtComplex& c){
00253
00254 return exp(c._rpart)*EvtComplex(cos(c._ipart),sin(c._ipart));
00255
00256 }
00257
00258
00259
00260 #endif
00261
00262
00263
00264
00265
00266
00267