Skip to content

feat: write 2D and 3D profile histograms (#1534) - #1855

Open
sumitsaraswat362 wants to merge 2 commits into
scikit-hep:mainfrom
sumitsaraswat362:feat-1534-write-tprofile2d-tprofile3d
Open

sumitsaraswat362 wants to merge 2 commits into
scikit-hep:mainfrom
sumitsaraswat362:feat-1534-write-tprofile2d-tprofile3d

Conversation

@sumitsaraswat362

Copy link
Copy Markdown
Contributor

Closes #1534.

This adds support for writing 2D and 3D profile histograms to ROOT files, resolving the request from @wiso in #1534:

  1. Writing 2D and 3D profiles in identify.to_writable:

    • Supports objects with kind="MEAN" using boost_histogram.storage.Mean or WeightedMean.
    • Formats bin contents and statistics to match ROOT memory layout (data.T.reshape(-1)).
    • Computes fTsumw, fTsumw2, coordinate moments (fTsumwx*, fTsumwy*, fTsumwz*), and profiled moments (fTsumwz* for 2D, fTsumwt* for 3D).
    • Pads discrete categorical axes (IntCategory, StrCategory) to include the ROOT bin 0 underflow slot.
  2. Reading and converting in TProfile2D.to_boost and TProfile3D.to_boost:

    • Implemented full to_boost() methods replacing the earlier placeholders.
    • Transposes and reshapes fBinEntries, raw contents, and fSumw2 into boost-histogram storage.
    • Recovers weighted variances via (sum_of_bin_weights**2) / effective_counts matching ROOT TProfileHelper.h.
    • Slices off the padded underflow slot for categorical axes.
    • Preserves exact fill statistics in metadata for round-trip parity.
  3. Tests:

    • Regression test replicating @wiso reproducer with IntCategory and Regular axes.
    • Unweighted and weighted 2D and 3D profile creation and round-trip tests.
    • Bitwise parity tests against official CERN ROOT files uproot-issue-227a.root and uproot-issue-227b.root, verifying all members, raw array bytes, values(), and errors() match bit-for-bit.

@sumitsaraswat362 sumitsaraswat362 changed the title feat: support writing 2D and 3D profile histograms (#1534) feat: write 2D and 3D profile histograms (#1534) Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7e49a5a) to head (06fc1a9).

Additional details and impacted files
Files with missing lines Coverage Δ
src/uproot/behaviors/TProfile2D.py 100.00% <100.00%> (ø)
src/uproot/behaviors/TProfile3D.py 100.00% <100.00%> (ø)
src/uproot/writing/identify.py 100.00% <100.00%> (ø)

@ariostas

Copy link
Copy Markdown
Member

Let's wait for #1766 before this. I'll work on wrapping that one up

@sumitsaraswat362

Copy link
Copy Markdown
Contributor Author

Sounds good, I will rebase once #1766 lands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2D PlottableHistogram with kind='MEAN' (i.e. 2D profile plots) not supported yet

2 participants