FFT Fourier Analysis of a TH2 to get Fourier coefficient

Hello root-users!

I have started using root a few days ago. (Version 5.17/04)
My problem is:
A Fourier Analysis of a 2D Histogram, to get the first coefficients of the transformation.

My code:

TH2 *fft_900=0; (this is supposed to be the resulting histogram)

fft_900 = h2_900->FFT(fft_900, “MAG R2C ES”);
this is supposed to be the analysis.
h2_900 is a TH2F histogram to be analysed.

According to
the method FFT is for “Fourier transforms of TH1 and TH2”,
It is a method of all TH2* classes, inherited from TH1.
but the error message says "invalid conversion from TH1* to TH2*"
It seems not to accept the TH2F histogram as input.

Please help me.
Thank you in advance.

Hi Valerie,

fft_900 = (TH2D*)h2_900->FFT(fft_900, “MAG R2C ES”);

Internally, in the function TH1::TransformHisto(), a TH2D object is created for 2-dim transforms.


Dear Anna!

Thank you for your help!
At least the program can be compiled without errors now.

Nevertheless I still don’t see any results.
The output is a blank Histogram. And in the root file I find no output histogram saved.
I thought maybe it is in some 1D format so tried to use TransformHisto.
It needs a TVirtualFFT* as in put, so I tried to use this method:

fft_900 = (TH2D*)h2_900->FFT(fft_900, “MAG R2C ES”);

Int_t n[2]={nbins+1,nbins+1};
TVirtualFFT *fft_own = TVirtualFFT::FFT(2,n,“MAG ES K”);
TH2 *fft1_900=0;
fft1_900->TH1::TransformHisto(fft_own, fft1_900, “MAG”);

The error is now “plugin not found” althoug TVirtualFFT.h is included.

I never programmed before, maybe that’s why root seems so complicated to me.
Is there not a good manual? Something that explains it well from the beginning?

Hi Valerie,

Do you have the fftw library installed, as explained at the bottom of this page: http://root.cern.ch/root/Install.html?
Can you try to run the tutorial in ROOTSYS/tutorials/fft? Do you get an empty historam there too?


Hi Anna,

the root system is installed on our central computer, but I have asked and the fftw is included.
The 1d FFT Tutorial runs properly, the output is not empty an the histogram is saved in the root-file (unlike the 2d case).
So I finally don’t need TVirtualFFT?

Hi Valerie,

In principle, if you only want to transform a histogram, you shouldn’t need TVirtualFFT, as it’s all done inside the TH1::FFT() function. Could you save the original histogram, that you can’t transform, in a root file, and attach it here? I’ll try to transform it myself and see if I get a non-empty result

Hi anna,

thank you very much for trying to help me!
As far as I can see, my rootfile has 100MB.
I have tried to save only one histogram in a new root file, hoping it would get smaller, but I didn’t manage to do that.
I did not find any explications in the manual to save only this single histogram. Even this took me almost one hour.
Maybe it is like everybody says and root is strong, but all I see is that it is complicated and even the smallest steps take a long time.
I have managed to get my problem running in Matlab. This in only two days. It works and the data read in is even much faster than in root.
Maybe it is better to forget root.
But thank you so much anna, that you tried to help me.
I have seen that you wrote all this FFT stuff for root.
Have a nice evening.

The first thing to do when you have this kind of question is to spend 3 minutes reading a few sections of the Users Guide. In this particular case,
reading the chapter about histograms, see
you would have seen (page 39) and go there much faster by reading the index to find the section "Saving/Reading Histograms to/from a File"
To come back to your problem, you simply have to do

TFile *fin = TFile::Open("mybigfile.root"); TH1 *h = (TH1*)fin->Get("name of one histogram to import"); TFile *fout = TFile::Open("smallfile.root","recreate"); h->Write();