How to do FFT in PyROOT?

I’m trying to do a Fourier Transform using TVirtualFFT in PyROOT. Unfortunately the way to do this involves passing an Int_t * to the static TVirtualFFT::FFT function. I don’t know why it has to be an address of an integer instead of just the integer since it’s just an array size…but anyways PyROOT apparently doesn’t deal with it properly:

In [13]: n_size = g.GetN()+1

In [14]: fft_own = ROOT.TVirtualFFT.FFT(1,n_size,"R2C ES K")
TypeError                                 Traceback (most recent call last)
<ipython-input-14-54d40ffbd8cb> in <module>()
----> 1 fft_own = ROOT.TVirtualFFT.FFT(1,n_size,"R2C ES K")

TypeError: static TVirtualFFT* TVirtualFFT::FFT(Int_t ndim, Int_t* n, Option_t* option) =>
    could not convert argument 2

Is there a standard way to use FFTs in PyROOT that I don’t know about? Note that I want to do a FFT of a voltage vs time TGraph (or the arrays inside the TGraph), not directly on a TH1.



from the looks of it, you try to pass n_size as an integer, where an integer pointer is expected. Use array.array(‘i’, [n_size]) from module array.


Thanks, that worked.

Unfortunately I couldn’t figure out how to use TVirtualFFT before I realized numpy has a much easier interface to FFTs, so I’m switching to that.