FFTWComplex.h
1 #ifndef FFTWCOMPLEX_H
2 
3 #define FFTWCOMPLEX_H
4 #include "TMath.h"
5 #include <ostream>
6 #include <complex>
7 
9 
13 public:
14  FFTWComplex():re(0),im(0){};
16 
17  double re;
18  double im;
19 
20  FFTWComplex(double real, double imag=0):re(real),im(imag){}
21 
23  FFTWComplex(const std::complex<double> & c) : re(c.real()), im(c.imag()) {; }
24 
25 
26  inline FFTWComplex operator*(const FFTWComplex &rhs){
27  return FFTWComplex(*this) *= rhs;
28  }
29 
30 
31 
32  inline FFTWComplex& operator*=(const FFTWComplex &rhs){
33  Double_t newRe = re*rhs.re - im*rhs.im;
34  Double_t newIm = im*rhs.re + re*rhs.im;
35  re = newRe;
36  im = newIm;
37  return *this;
38  }
39 
40 
41  inline FFTWComplex operator+(const FFTWComplex &rhs){
42  return FFTWComplex(*this) += rhs;
43  }
44 
45  inline FFTWComplex& operator+=(const FFTWComplex &rhs){
46  re += rhs.re;
47  im += rhs.im;
48  return *this;
49  }
50 
51  inline FFTWComplex operator-(const FFTWComplex &rhs){
52  return FFTWComplex(*this) -= rhs;
53  }
54 
55  inline FFTWComplex& operator-=(const FFTWComplex &rhs){
56  re -= rhs.re;
57  im -= rhs.im;
58  return *this;
59  }
60 
61  inline FFTWComplex operator/(const FFTWComplex &rhs){
62  return FFTWComplex(*this) /= rhs;
63  }
64 
65 
66  inline FFTWComplex& operator/=(const FFTWComplex &rhs){
67  Double_t norm = rhs.getAbsSq();
68  (*this) *= rhs.conj();
69  re /= norm;
70  im /= norm;
71  return *this;
72  }
73 
74  inline void setMagPhase(double mag, double phase){
75  re = mag*TMath::Cos(phase);
76  im = mag*TMath::Sin(phase);
77  }
78 
79  inline double getAbs() const{
80  return TMath::Sqrt(re*re+im*im);
81  }
82 
83  inline double getAbsSq() const{
84  return (re*re+im*im);
85  }
86 
87  inline double getPhase() const{
88  return TMath::ATan2(im,re);
89  }
90 
91  operator std::complex<double>()
92  {
93  return std::complex<double>(re,im);
94 
95  }
96 
97  inline FFTWComplex conj() const
98  {
99  FFTWComplex copy(*this);
100  copy.im = -copy.im;
101  return copy;
102  }
103 
104 };
105 
106 // overload string stream operator... just for fun
107 std::ostream& operator<<(std::ostream& os, const FFTWComplex& val);
108 
109 
110 #endif // FFTWCOMPLEX_H
double im
The imaginary part.
Definition: FFTWComplex.h:18
This is a wrapper class for a complex number.
Definition: FFTWComplex.h:12
FFTWComplex(const std::complex< double > &c)
Definition: FFTWComplex.h:23
double re
Destructor.
Definition: FFTWComplex.h:15
~FFTWComplex()
Default constructor.
Definition: FFTWComplex.h:15