JuliaHEP / UpROOT.jl

Julia package to access CERN ROOT files, wraps Python package uproot
Other
15 stars 3 forks source link

Histogram edges retrieval bug #21

Open gipert opened 3 years ago

gipert commented 3 years ago

I cannot read histograms from this ROOT file. I think it's a floating point arithmetic issue.

julia> using UpROOT
julia> UpROOT.TFile("histos.root")["h_comp_roi"]
ERROR: Histogram edge vectors must be 1 longer than corresponding weight dimensions
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] Histogram
   @ ~/.julia/packages/StatsBase/DU1bT/src/hist.jl:193 [inlined]
 [3] Histogram (repeats 2 times)
   @ ~/.julia/packages/StatsBase/DU1bT/src/hist.jl:199 [inlined]
 [4] roothist2jl(x::PyCall.PyObject)
   @ UpROOT ~/.julia/packages/UpROOT/YRyC3/src/pyjlconv.jl:58
 [5] py2jl(x::PyCall.PyObject)
   @ UpROOT ~/.julia/packages/UpROOT/YRyC3/src/pyjlconv.jl:78
 [6] getindex(tdir::TDirectory, objname::String)
   @ UpROOT ~/.julia/packages/UpROOT/YRyC3/src/tdirectory.jl:33
 [7] top-level scope
   @ REPL[8]:1

The right edges in the original histograms are 0:0.2:100, but the reconstructed range is 0.0:0.20000000000000004:99.80000000000003, which explains the error.

If I remove this if ... else here:

https://github.com/JuliaHEP/UpROOT.jl/blob/master/src/pyjlconv.jl#L45-L47

and just return edge, everything works as expected. Why trying to convert the histogram edges to a range object? Is there a performance gain?