00001 // @(#)root/base:$Id: TVirtualFFT.h 32181 2010-02-02 10:03:01Z brun $ 00002 // Author: Anna Kreshuk 10/04/2006 00003 00004 #ifndef ROOT_TVirtualFFT 00005 #define ROOT_TVirtualFFT 00006 00007 ////////////////////////////////////////////////////////////////////////// 00008 // 00009 // TVirtualFFT 00010 // 00011 // TVirtualFFT is an interface class for Fast Fourier Transforms. 00012 // 00013 // 00014 // 00015 // The default FFT library is FFTW. To use it, FFTW3 library should already 00016 // be installed, and ROOT should be have fftw3 module enabled, with the directories 00017 // of fftw3 include file and library specified (see installation instructions). 00018 // Function SetDefaultFFT() allows to change the default library. 00019 // 00020 // Available transform types: 00021 // FFT: 00022 // - "C2CFORWARD" - a complex input/output discrete Fourier transform (DFT) 00023 // in one or more dimensions, -1 in the exponent 00024 // - "C2CBACKWARD"- a complex input/output discrete Fourier transform (DFT) 00025 // in one or more dimensions, +1 in the exponent 00026 // - "R2C" - a real-input/complex-output discrete Fourier transform (DFT) 00027 // in one or more dimensions, 00028 // - "C2R" - inverse transforms to "R2C", taking complex input 00029 // (storing the non-redundant half of a logically Hermitian array) 00030 // to real output 00031 // - "R2HC" - a real-input DFT with output in "halfcomplex" format, 00032 // i.e. real and imaginary parts for a transform of size n stored as 00033 // r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1 00034 // - "HC2R" - computes the reverse of FFTW_R2HC, above 00035 // - "DHT" - computes a discrete Hartley transform 00036 // 00037 // Sine/cosine transforms: 00038 // Different types of transforms are specified by parameter kind of the SineCosine() static 00039 // function. 4 different kinds of sine and cosine transforms are available 00040 // DCT-I (REDFT00 in FFTW3 notation)- kind=0 00041 // DCT-II (REDFT10 in FFTW3 notation)- kind=1 00042 // DCT-III(REDFT01 in FFTW3 notation)- kind=2 00043 // DCT-IV (REDFT11 in FFTW3 notation)- kind=3 00044 // DST-I (RODFT00 in FFTW3 notation)- kind=4 00045 // DST-II (RODFT10 in FFTW3 notation)- kind=5 00046 // DST-III(RODFT01 in FFTW3 notation)- kind=6 00047 // DST-IV (RODFT11 in FFTW3 notation)- kind=7 00048 // Formulas and detailed descriptions can be found in the chapter 00049 // "What FFTW really computes" of the FFTW manual 00050 // 00051 // NOTE: FFTW computes unnormalized transforms, so doing a transform, followed by its 00052 // inverse will give the original array, multiplied by normalization constant 00053 // (transform size(N) for FFT, 2*(N-1) for DCT-I, 2*(N+1) for DST-I, 2*N for 00054 // other sine/cosine transforms) 00055 // 00056 // How to use it: 00057 // Call to the static function FFT returns a pointer to a fast fourier transform 00058 // with requested parameters. Call to the static function SineCosine returns a 00059 // pointer to a sine or cosine transform with requested parameters. Example: 00060 // { 00061 // Int_t N = 10; Double_t *in = new Double_t[N]; 00062 // TVirtualFFT *fftr2c = TVirtualFFT::FFT(1, &N, "R2C"); 00063 // fftr2c->SetPoints(in); 00064 // fftr2c->Transform(); 00065 // Double_t re, im; 00066 // for (Int_t i=0; i<N; i++) 00067 // fftr2c->GetPointComplex(i, re, im); 00068 // ... 00069 // fftr2c->SetPoints(in2); 00070 // ... 00071 // fftr2c->SetPoints(in3); 00072 // ... 00073 // } 00074 // Different options are explained in the function comments 00075 // 00076 // 00077 // 00078 // 00079 // 00080 ////////////////////////////////////////////////////////////////////////// 00081 00082 #ifndef ROOT_TObject 00083 #include "TObject.h" 00084 #endif 00085 00086 #ifndef ROOT_TString 00087 #include "TString.h" 00088 #endif 00089 00090 class TComplex; 00091 00092 class TVirtualFFT: public TObject { 00093 00094 protected: 00095 static TVirtualFFT *fgFFT; //current transformer 00096 static TString fgDefault; //default transformer 00097 00098 public: 00099 00100 TVirtualFFT(){}; 00101 virtual ~TVirtualFFT(); 00102 00103 virtual Int_t *GetN() const = 0; 00104 00105 virtual Int_t GetNdim() const = 0; 00106 virtual Option_t *GetType() const = 0; 00107 virtual Int_t GetSign() const = 0; 00108 virtual Option_t *GetTransformFlag() const = 0; 00109 virtual void Init(Option_t *flag,Int_t sign, const Int_t *kind) = 0; 00110 virtual Bool_t IsInplace() const = 0; 00111 00112 virtual void GetPoints(Double_t *data, Bool_t fromInput = kFALSE) const = 0; 00113 virtual Double_t GetPointReal(Int_t ipoint, Bool_t fromInput = kFALSE) const = 0; 00114 virtual Double_t GetPointReal(const Int_t *ipoint, Bool_t fromInput = kFALSE) const = 0; 00115 virtual void GetPointComplex(Int_t ipoint, Double_t &re, Double_t &im, Bool_t fromInput=kFALSE) const = 0; 00116 virtual void GetPointComplex(const Int_t *ipoint, Double_t &re, Double_t &im, Bool_t fromInput=kFALSE) const = 0; 00117 virtual Double_t* GetPointsReal(Bool_t fromInput=kFALSE) const = 0; 00118 virtual void GetPointsComplex(Double_t *re, Double_t *im, Bool_t fromInput = kFALSE) const = 0; 00119 virtual void GetPointsComplex(Double_t *data, Bool_t fromInput = kFALSE) const = 0; 00120 00121 virtual void SetPoint(Int_t ipoint, Double_t re, Double_t im = 0) = 0; 00122 virtual void SetPoint(const Int_t *ipoint, Double_t re, Double_t im = 0) = 0; 00123 virtual void SetPoints(const Double_t *data) = 0; 00124 virtual void SetPointComplex(Int_t ipoint, TComplex &c) = 0; 00125 virtual void SetPointsComplex(const Double_t *re, const Double_t *im) =0; 00126 virtual void Transform() = 0; 00127 00128 static TVirtualFFT* FFT(Int_t ndim, Int_t *n, Option_t *option); 00129 static TVirtualFFT* SineCosine(Int_t ndim, Int_t *n, Int_t *r2rkind, Option_t *option); 00130 static TVirtualFFT* GetCurrentTransform(); 00131 00132 static void SetTransform(TVirtualFFT *fft); 00133 static const char* GetDefaultFFT(); 00134 static void SetDefaultFFT(const char *name =""); 00135 00136 ClassDef(TVirtualFFT, 0); //abstract interface for FFT calculations 00137 }; 00138 00139 #endif