Hello,
I am encountering an issue with getting the total yields from a weighted histogram. I have the values in the TTree, which I want to apply certain selections.
I tried the following code:
import ROOT as R
f=R.TFile("test.root")
t=f.Get("tree")
sumw=0
for i,el in enumerate(t):
sumw+= t.weight
print(sumw)
Which gives:
[cvergis@ ]$ python3 loop.py
3.69314590372313
and compared it to the:
[cvergis@l ]$ root test.root
------------------------------------------------------------------
| Welcome to ROOT 6.34.04 https://root.cern |
| (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Feb 14 2025, 00:00:00 |
| From tags/6-34-04@6-34-04 |
| With g++ (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5) |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
Attaching file test.root as _file0...
(TFile *) 0x5612c53bcb80
root [1] tree->Draw("1>>h2(5,-5,5)","(1)*weight","goff")
(long long) 531310
root [2] h2->Integral()
(double) 3.6930571
My problem is that the two outcome numbers are not equal and I don’t understand why or which one to trust.