# Suming Half the Weights in a 1D Histogram

**URL:** <https://root-forum.cern.ch/t/suming-half-the-weights-in-a-1d-histogram/52231>\
**Category:** Newbie\
**Tags:** python, hist\
**Created:** [November 5, 2022, 6:45pm UTC](https://root-forum.cern.ch/t/suming-half-the-weights-in-a-1d-histogram/52231 "2022-11-05T18:45:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RNugent](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/53a042/32.png) [@RNugent](https://root-forum.cern.ch/u/RNugent)\
**Post date:** [November 5, 2022, 6:45pm UTC](https://root-forum.cern.ch/t/suming-half-the-weights-in-a-1d-histogram/52231/1 "2022-11-05T18:45:23Z")

</div>

I’m trying to sum the weights of a 1D histogram from the lowest x-axis value to the middle x-axis value (in this case the position of an energy deposit from the centre of a chamber). Is there a way to define the interval in which GetSumOfWeights() is ran over. My code is listed below. Thanks.

tree = myfile.Get(‘nEXOevents’)  
xpos = ROOT.std.vector(‘float’)()  
ypos = ROOT.std.vector(‘float’)()  
zpos = ROOT.std.vector(‘float’)()  
energy = ROOT.std.vector(‘float’)()

tree.SetBranchAddress(‘Xpos’,xpos)  
tree.SetBranchAddress(‘Ypos’,ypos)  
tree.SetBranchAddress(‘Zpos’, zpos)  
tree.SetBranchAddress(‘EnergyDeposit’,energy)

evtno = 1  
tree.GetEntry(evtno)

xposlist = [xpos.at(i) for i in range(xpos.size())]  
yposlist = [ypos.at(i) for i in range(ypos.size())]  
zposlist = [zpos.at(i) for i in range(zpos.size())]

h1z = ROOT.TH1F(‘’,‘Energy Deposit in the z-axis from a 2e event’,100,min(zposlist)-1,max(zposlist)+1)

for i in range(xpos.size()):  
h1z.Fill(zpos.at(i),energy.at(i))

minz = min(zposlist)  
maxz = max(zposlist)  
halfz = (minz + maxz) /2

_ROOT Version:_ 6.24.06  
_Platform:_ Windows 11  
_Compiler:_ JupyterHub

* * *

---

<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:** [November 5, 2022, 8:42pm UTC](https://root-forum.cern.ch/t/suming-half-the-weights-in-a-1d-histogram/52231/2 "2022-11-05T20:42:46Z")

</div>

`h1z.Integral(1, h1z.FindFixBin(halfz))`
