# histo.Integral() vs looping tree to get sumw

**URL:** <https://root-forum.cern.ch/t/histo-integral-vs-looping-tree-to-get-sumw/63256>\
**Category:** ROOT\
**Tags:** tree, hist\
**Created:** [March 31, 2025, 6:29pm UTC](https://root-forum.cern.ch/t/histo-integral-vs-looping-tree-to-get-sumw/63256 "2025-03-31T18:29:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvergis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bbce88/32.png) [@cvergis](https://root-forum.cern.ch/u/cvergis)\
**Post date:** [March 31, 2025, 6:29pm UTC](https://root-forum.cern.ch/t/histo-integral-vs-looping-tree-to-get-sumw/63256/1 "2025-03-31T18:29:49Z")

</div>

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:

```auto
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:

```auto
[cvergis@]$ python3 loop.py
3.69314590372313

```

and compared it to the:

```auto
[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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 31, 2025, 7:16pm UTC](https://root-forum.cern.ch/t/histo-integral-vs-looping-tree-to-get-sumw/63256/2 "2025-03-31T19:16:17Z")

</div>

In your “`${HOME}/.rootrc`” file, add:  
`Hist.Precision.1D: double`

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 14, 2025, 7:16pm UTC](https://root-forum.cern.ch/t/histo-integral-vs-looping-tree-to-get-sumw/63256/3 "2025-04-14T19:16:54Z")

</div>

Closed on April 14, 2025, 7:16pm UTC

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