Vertical errors for historgrams

In my field of research (HEP), the vertical errors for the histograms are widely used.
Usually, they are calculated assuming narrow bins and Poisson distribution for the number of entries,
i.e. the error is sqrt(Nentries)

It is clear how to extend Plots.scatterbins for such errors.
While, it gets more complicated (implementation-wise) when the

  • data are weighted
  • histogram is normalized

Plots use StatsBase.Histogram that does not give access to the entries weights inside of individual bins. This information seems to be lost once Histogram is created.

Any ideas on the problem?

Here is my errorhist recipe for the Poisson error.

@recipe function f(::Type{Val{:errorhist}}, x, y, z)
    h = Plots._make_hist(
        (y,),
        plotattributes[:bins],
        normed = plotattributes[:normalize],
        weights = plotattributes[:weights],
    )
    x := h.edges[1]
    y := h.weights
    seriestype := :scatterbins
    # 
    @series begin
        primary := false
        seriestype := :yerror
        x := Plots._bin_centers(h.edges[1])
        yerror --> map(x->x < 0 ? 0.0 : sqrt(x), h.weights)
    end
    ()
end
@shorthands errorhist

Related question in StatsBase
https://github.com/JuliaStats/StatsBase.jl/issues/597

Example of errorhist in Plots.jl
https://github.com/JuliaPlots/Plots.jl/issues/2630#issuecomment-623425872