Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

fix: Set from_numpy fSumw2 equal to entries #98

Merged
merged 2 commits into from Mar 18, 2021

Conversation

matthewfeickert
Copy link
Member

Resolves #97 given @henryiii's proposed solution.

The call hist.Sumw2(kTRUE) [in ROOT] sets the variances equal to the entries. Then the error is the square root of the entries. Uproot is setting the variance equal to the square of the entries, making the error equal to the entries. I think it's a simple bug due to the fact "sumw2" has a square in it, so it looks like it should be set with a square.

In ROOT, hist.Sumw2() sets the variances of the histogram equal to the
entries, and so the uncertainties are equal to the square root of the
entries
Copy link
Member

@jpivarski jpivarski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is right. The default weights should have errors equal to the square root of the values, so the errors squared should be equal to the values.

I'll deploy a new version with this fix—thank you!

@jpivarski jpivarski merged commit dc5e17e into master Mar 18, 2021
@jpivarski jpivarski deleted the fix/sumw2-variances-equal-value branch March 18, 2021 16:49
@matthewfeickert
Copy link
Member Author

matthewfeickert commented Mar 18, 2021

Oh thanks @jpivarski! You were super speedy, but I also did a test and with this change all the test on uproot3 still pass:

$ pip list
Package         Version Location
--------------- ------- -----------------------------------------------------
attrs           20.3.0
awkward0        0.15.5
cachetools      4.2.1
iniconfig       1.1.1
lz4             3.1.3
mock            4.0.3
numpy           1.20.1
packaging       20.9
pip             21.0.1
pluggy          0.13.1
py              1.10.0
pyparsing       2.4.7
pytest          6.2.2
setuptools      54.1.2
toml            0.10.2
uproot3         3.14.4  /home/feickert/Code/GitHub/Scikit-HEP/uproot3
uproot3-methods 0.10.0  /home/feickert/Code/GitHub/Scikit-HEP/uproot3-methods
wheel           0.36.2
xxhash          2.0.0
$ python -m pytest -sx tests/
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.7, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/feickert/Code/GitHub/Scikit-HEP/uproot3
collected 224 items / 2 skipped / 222 selected                                                                                                                                                            

tests/test_cache.py ....
tests/test_issues.py ......................ss.......s.......s....
tests/test_jagged.py sss
tests/test_rntuple.py .
tests/test_stlvector.py ........
tests/test_tree.py ................................sssss.
tests/test_versions.py ..............
tests/test_write.py ................................................................................................................

============================================================================================ warnings summary =============================================================================================
tests/test_issues.py::Test::test_issue76
tests/test_issues.py::Test::test_issue243
tests/test_issues.py::Test::test_issue243_new
tests/test_issues.py::Test::test_issue371
tests/test_issues.py::Test::test_issue367
tests/test_issues.py::Test::test_issue399
tests/test_stlvector.py::Test::test_vector_of_vector_of_numbers
tests/test_stlvector.py::Test::test_strings3
tests/test_stlvector.py::Test::test_unsplit
  /home/feickert/.pyenv/versions/uproot3-dev/lib/python3.8/site-packages/awkward0/array/base.py:398: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
    return cls.numpy.array(value, copy=False)

tests/test_write.py::test_tree_twodim
tests/test_write.py::test_tree_threedim
  /home/feickert/bin/root/lib/ROOT/pythonization/_rdataframe.py:82: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    tmp = numpy.empty(len(cpp_reference), dtype=numpy.object)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================================== 212 passed, 14 skipped, 11 warnings in 23.38s ==============================================================================

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question on behavior of weights and variances
2 participants