I’m using the following piece of code to compute the number of entries in a tree, taking into account the fact that each entry has a weight which can be a user-defined TFormula. It’s somewhat more convenient than defining a TTreeFormula and looping over all entries manually.
The code (compiled with g++ and ROOT 6.02) runs without problems most of the time, but sometimes fails unpredictably: computing the Integral returns 0.
I have checked the following:
the TTree is sane, the weights are nonzero, and anyway:
I get the same error without using a weight
tempHist->GetEntries() returns the correct number (same as myTree->GetEntries())
looping over the bins of tempHist and summing the values given by GetBinContent() returns the correct value
writing tempHist to a file, then opening this file, getting the histogram, and computing its integral returns the correct (nonzero) value
Is this a bug or a feature? Of course there are ways around it, but I would like to know whether this behaviour can be expected for some reason I’m not aware of, or not…
I put the root file and the test script in /afs/cern.ch/user/s/swertz/public/temp_testbug
But when I try running it on lxplus, there is no problem.
Actually, there is no problem either when I execute the macro with ROOT 5.34.09. The problem appears when using 6.02.05, which is weird, because the root file causing the problem was created by a program compiled with this very same version.
Thanks for looking into it. I don’t understand why you say you cannot reproduce the bug, since the output you get is precisely the issue: the integral is zero, while it shouldn’t be (number of entries > 0, weights >0)!
I meant I cannot reproduce the behaviour you describe:
The code (compiled with g++ and ROOT 6.02) runs without problems most of the time, but sometimes fails unpredictably: computing the Integral returns 0.
I never saw anything different from 0 all the time.
Oh, I see! What I meant was that running the code on the file I shared, I always get the same (problematic) result, but that it runs (consistently) fine on other files.
The few lines are in a function part of a bigger project which reads many different files. The file I shared is one with which the problem appears (not the only one); if you want I can also share one for which everything runs fine?
we are working on a fix which will be included in the next root versions. I’ll let you know when it is available in the repository.
Thanks a lot for reporting.
The fix is applied in both master and 6.02 patch branches.
If you cannot update the ROOT version, you can just call TH1::BufferEmpty() after having called the TTree::Draw method, as a simple workaround.
Well, I’ve just updated to ROOT 6.04 and still experience this issue when using pyRoot (compiled C++ works fine)…
Could there be a link with [Wrong Event Count in ROOT 6.02.10 It’s also supposed to be fixed in 6.04, but I get the same problem with this version…