Code Monkey home page Code Monkey logo

Comments (4)

alanedelman avatar alanedelman commented on June 5, 2024 1

mostly i figure if the histogram knows its widths i shouldn't have to type it

if useful you might crossreference other histograms in the julia ecosystem:
https://github.com/mitmath/18338/blob/master/JuliaNotebooks/0.0%20Histogramming.ipynb
see the word normalize used in different ways

from fhist.jl.

Moelf avatar Moelf commented on June 5, 2024

we model after this function:
https://root.cern.ch/doc/master/classTH1.html#aaf053a4b487c46b9e20c0bf534b34012

if option "width" is specified, the integral is the sum of the bin contents multiplied by the bin width in x.

maybe the answer is to specifically fix normalize? or we could add a ; width=false to integral() function and use that in normalize

from fhist.jl.

Moelf avatar Moelf commented on June 5, 2024

we actually use StatsBase under the hood haha, but yeah, HEP is weird.

There's not enough bandwidth in the community rn but one day I wish we could have a separate histogram package and StatsBase use that one, and we can sort out different "properties" of histograms by using the type system (where now there's like isdensity https://github.com/JuliaStats/StatsBase.jl/blob/39d0433f5044f8cafaa902cf31b3f83979585657/src/hist.jl#L190 field ad-hoc)

from fhist.jl.

Moelf avatar Moelf commented on June 5, 2024

ROOT's behavior when having variable bin width:

In [10]: ROOT.TH1D("test", "test", 3, array.array("d", [0, 1, 2, 4]))
Out[10]: <cppyy.gbl.TH1D object at 0x5de8700>

In [11]: t.Fill(0.5, 0.5)
Out[11]: 1

In [12]: t.Fill(0.5, 0.5)
Out[12]: 1

In [14]: t
Out[14]: <cppyy.gbl.TH1D object at 0x605e730>

In [15]: t.Integral()
Out[15]: 1.0

In [16]: t.Fill(2.5, 0.5)
Out[16]: 3

In [17]: t.Integral()
Out[17]: 1.5

In [18]: t.Integral("width")
Out[18]: 2.0

as for different "normalize()", see discussion: https://root-forum.cern.ch/t/different-ways-of-normalizing-histograms/15582

Method 4

In [28]: t.Scale(1. / t.Integral())

In [29]: t.GetBinContent(3)
Out[29]: 0.3333333333333333

Method 6

# re-make t
In [30]: t = ROOT.TH1D("test", "test", 3, array.array("d", [0, 1, 2, 4]))
TROOT::Append:0: RuntimeWarning: Replacing existing TH1: test (Potential memory leak).

In [31]: t.Fill(0.5, 0.5)
Out[31]: 1

In [32]: t.Fill(0.5, 0.5)
Out[32]: 1

In [33]: t.Fill(2.5, 0.5)
Out[33]: 3

In [34]: t.Scale(1. / t.Integral("width"))

In [35]: t.GetBinContent(3)
Out[35]: 0.25

In [36]: t.Integral()
Out[36]: 0.75

In [37]: t.Integral("width")
Out[37]: 1.0

from fhist.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.