Skip to content

Histplot errorbars #429

Open
Open
@meisonlikesicecream

Description

@meisonlikesicecream

I find the documentation of the histplot function [0] slightly confusing/contradictive. I stumbled upon this when I wanted to plot a simple weighted 1D histogram with sqrt(w2) errorbars (which I assumed was the default, but apparently not). I have not checked if the following issues are true for histtypes other than histtype=‘errorbar’.

This line about the yerr parameter "Following modes are supported: - True, sqrt(N) errors or poissonian interval when w2 is specified" [1] makes it sound like if yerr == True, then sqrt(N) is used for the errors if w2 is NOT specified, and that the poissonian interval is used if w2 IS specified. However, this is not the case: it always does the poissonian interval even if w2 is None because in the Plottable class definition it always initialises with the method “poisson” [2], which therefore, will always run the poissonian interval [3]. If w2 is specified, and yerr!=None, then it crashes because of [4].

This leads me to another confusion: which error calculation do we want for weighted histograms? The following line about the w2 parameter "Sum of the histogram weights squared for poissonian interval error calculation" [5] makes it sound like we always want to use the poissonian error for weighted histograms, while this line "If w2 has integer values (likely to be data) poisson interval is calculated, otherwise the resulting error is symmetric sqrt(w2)" [6] makes it sound like the poisson interval should only be used for integer values. Again, "sqrt" is never used if w2method is None because of [3], even if w2 has integer values.

Also, if you specify to use the “sqrt” method, it never uses the variances (i.e. w2) for calculating the errors [7]...

I'm happy submit a PR if someone can explain what the intended usage is :-)

  1. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/plot.py#L57
  2. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/plot.py#L95
  3. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/utils.py#L154
  4. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/utils.py#L183
  5. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/plot.py#L280
  6. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/plot.py#L99
  7. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/plot.py#LL104C12-L106C89
  8. https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/utils.py#L193-L194

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions