I’ve been trying to locate the peaks of a 2-d distribution using the TSpectrum2 class, but I just keep getting segfault errors (see attachment).
I guess the problem is the signature of the TSpectrum2::SearchHighRes function I am trying to use:
I am trying to use two numpy matrices as source and dest, as shown in the example attached.
May anybody suggest me a workaround, or a different array/vector/list/matrix data type compatible with this signature? I have also tried to use ROOT’s vector<vector> but I didn’t manage to get SearchHighRes working this way either.
The attached files provide:
[ul][li]a minimal (not) working example spectrum.py (380 Bytes)[/li]
[li]a rootfile containing the source histogram hh.root (65.3 KB)[/li]
[li]and the complete error stack trace spectrum-errors.txt (6.03 KB)[/li][/ul]
Here’s what you’re up against: numpy does not support C-style 2D arrays particularly well, float in python is double in C, and in C there are float** and float[][] and they are not the same.
Now, if you insist, you can beat this into shape, but to make it even semi-usable, it would probably have to go something like this:[code]import array
for i in xrange(binsx):
source[i], c_source[i] = new_numpy1d_with_pointer( binsy )
dest[i], c_dest[i] = new_numpy1d_with_pointer( binsy )[/code]
This builds an array of pointers to arrays of C floats in c_source and c_dest, and that will work, as although PyROOT does not know about float**, it passes the array pointer as void*, which is fine. It also builds source and dest to a) keep the arrays alive from the reference counting, and b) still be usable in the expected way.