Problem with sparse projection

Dear Experts,

I would like to make a projection from a sparse type object to 1-dimensional histogram in variable bin sizes but I got wrong number of entries at the end of projection which I don’t understand where I’m doing wrong.

I defined 3 different histogram with following intervals to check the code ,

hist1- from 0 to first bin,
hist2- first bin to second bin in the loop,
hist3- second bin to last bin.

I’m expecting that hist2-(hist3-hist1) should be 0, but I got different numbers for each projection bin.

Root file and the relevant macro is attached. Please help me to solve this problem.

Thank you very much,
Kind regards to All,
Ayben
test.C (1.6 KB)
sparse.root (1.06 MB)

Hi,
well I wasn’t able to run Your script as I get this error
error: invalid conversion from ‘TObject*’ to ‘THnSparse*’
but I think the problem is on the line

cause I would expect

If it’s true that out_0_to_x + out_x_to_x1 = out_0_to_x1, then Your formula with absolute value works only for out_0_to_x1 > out_0_to_x, not in < case.