Skip to content

shower dist histogram storage could lead to rounding errors #2924

@kosack

Description

@kosack

Describe the bug

I want to soon implement support arbitrary shaped shower distributions, and noticed this when looking at the data: the histogram is returned as a float32 array from TableLoader.read_simulation_distrubution() which could lead to a wrong flux if not careful. Note that so far, what is used in the code to date is not affected, but this could cause errors in the future if updates are made.

To Reproduce
Steps to reproduce the behavior:

Image
print("A:", int(dist["histogram"].sum()))
print("B:", dist["n_entries"].sum())
print("C:", dist["histogram"].astype(np.int64).sum())
A: 17773303808
B: 17774000000
C: 17774000000

As can be seen, case A gives he wrong answer, which could lead to an incorrect flux measurement. In th currnt code we use case B.

Expected behavior
histogram entries should be stored as integers, and summing should work as expected with no floating point rounding errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions