THnSparse::Projection() does not recalculate fTsumw etc

When I use the method THnSparse::Projection() to create a new THnSparse, I notice that GetSumw() returns 0 and GetSumwx(dim) exits with an error:
“Error in TArrayD::operator[]: index 1 out of bounds (size: 0, this: 0x2403e00)”

I think this is because in the projected THnSparse, the following structures are not set up:
fTsumw(0), fTsumw2(-1), fTsumwx(dim), fTsumwx2(dim)

Calling THnSparse::Sumw2() after making the projection does not help since THnSparse::GetCalculateErrors() returns true, in which case Sumw2() exits without taking any action.

Though I can write a function to loop over the filled bins in the THnSparse and get the integral, I wanted to still find out if my understanding of the workings of THnSparse::Projection(), as listed above, is correct.

Please see attaching THnSparse.stats.C for an example where I create and fill an 8 dimensional (8D) histogram. From this 8D histogram, I project out a 5 dimensional (5D) histogram. If this script is executed in CINT, the issues I found with THnSparse:Projection() can be recreating by calling GetSumw() and GetSumwx(1) on the 5D histogram.

Thanks in advance for the help.
THnSparse.stats.C (805 Bytes)