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(
        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)
@shorthands errorhist

Related question in StatsBase

Example of errorhist in Plots.jl