NaN errors when projecting THnSparse

I have a THnSparseT<ArrayD> (filled using RDataFrame using the declare and fill functions here) whose projections end up with nan errors in some bins. None of the THnSparse bins have nan errors–it only happens in the projections.

Are there any typical causes for this? Details follow.


The number of bins with nan errors is 0 in the original THnSparse:

len([x for x in xrange(horig.GetNbins()) if math.isnan(horig.GetBinError2(x))]) == 0

If I project horig, which has 2 dimensions, to a TH2, then 13 bins have nan errors (this is true with or without Projection option 'E'):

In [16]: testproj = horig.Projection(1, 0)

In [17]: nantestproj = [(x, y) for x in xrange(testproj.GetNbinsX()) for y in xrange(testproj.GetNbinsY()) if math.isnan(testproj.GetBinError(x, y))]

In [18]: len(nantestproj)
Out[18]: 13

If I first rebin horig to have fewer bins, then project it to a TH2, none of the bins have nan errors:

In[9]: hrebin = horig.Rebin(array('i', [1000, 250]))

In[10]: testproj = hrebin.Projection(1, 0)

In [11]: nantestproj = [(x, y) for x in xrange(testproj.GetNbinsX()) for y in xrange(testproj.GetNbinsY()) if math.isnan(testproj.GetBinError(x, y))]

In [12]: nantestproj
Out[12]: []

If I project to axis 0, there are 7 bins with nan errors:

In [6]: testproj0 = horig.Projection(0, 'E')

In [7]: nantestproj0 = [x for x in xrange(testproj0.GetNbinsX()) if math.isnan(testproj0.GetBinError(x))]

In [8]: len(nantestproj0)
Out[8]: 7

while axis 1 has 2:

In [13]: testproj1 = horig.Projection(1, 'E')

In [14]: nantestproj1 = [x for x in xrange(testproj1.GetNbinsX()) if math.isnan(testproj1.GetBinError(x))]

In [15]: len(nantestproj1)
Out[15]: 2

The 1D bins with nan errors do not appear to correspond to their 2D counterparts:

In [24]: nantestproj
Out[24]: 
[(4460, 1771),
 (4955, 1689),
 (7165, 937),
 (8877, 743),
 (8988, 1856),
 (9643, 639),
 (10022, 1103),
 (10322, 1555),
 (11081, 640),
 (12734, 1792),
 (13762, 511),
 (14111, 845),
 (21480, 239)]

In [25]: nantestproj0
Out[25]: [4460, 8988, 10022, 10322, 11081, 14111, 21480]

In [26]: nantestproj1
Out[26]: [743, 845]

If I refill the histogram with the exact same script as before, different bins end up with nan errors.

These nan errors crop up only if I use a certain double branch from a friend chain as a weight to fill the THnSparse. Weights from other float branches do not seem to have this problem, even if the weight column in RDataFrame is a double. Could the type of the branch be causing this…?


ROOT Version: 6.16.00
Platform: Not Provided
Compiler: Not Provided


That’s indeed weird. I’m off until Monday, I will have a look then! Please ping me here should you not hear back from me by Tuesday!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.