Skip to content

Conversation

@siliataider
Copy link
Contributor

This Pull request:

Changes or fixes:

Previously, slicing was implemented at the pythonization level: when slicing a histogram, the values within the specified slice were kept and the ones outside were set to 0, without resizing the sliced axis (leading to inconsistencies..).
This PR implements the slicing logic in TH1 directly, adapting the pythonizations to make use of the new internal functions.

Other changes are made to enhance the interface and fully comply with the UHI specifications, improvements can be summarized here:

  • The sliced axis is resized after slicing, which correctly adjusts the statistics.
  • Integration operations now support full-range integration, non-flow integration, and ranged integration.
  • Histograms can now be set with either a scalar, numpy.ndarray, or any ArrayLike instance.
  • Broadcasting is now also supported (e.g., h[0:2, 0:2] = np.array([[42], [3]])).
  • Enhance error handling.

Checklist:

  • tested changes locally

@siliataider siliataider self-assigned this May 15, 2025
@siliataider siliataider removed the request for review from lmoneta May 15, 2025 13:57
@siliataider siliataider force-pushed the UHI-indexing branch 3 times, most recently from 9e29340 to 61272a7 Compare May 15, 2025 15:01
Copy link
Contributor

@silverweed silverweed left a comment

Choose a reason for hiding this comment

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

I know I wasn't a requested reviewer but I have a couple of comments :)

@github-actions
Copy link

github-actions bot commented May 15, 2025

Test Results

    19 files      19 suites   3d 15h 49m 12s ⏱️
 2 758 tests  2 758 ✅ 0 💤 0 ❌
50 908 runs  50 908 ✅ 0 💤 0 ❌

Results for commit abc7b47.

♻️ This comment has been updated with latest results.

Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

Thank you a lot for this prompt effort to improve the implementation according to bleeding edge testing! I have a few quick remarks for a first iteration of the review

@siliataider siliataider marked this pull request as draft May 19, 2025 07:44
Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

Thanks for pushing for this! Just a few quick pass-by comments

@siliataider siliataider marked this pull request as ready for review May 21, 2025 14:49
@siliataider siliataider requested a review from silverweed May 21, 2025 14:49
@siliataider siliataider requested a review from vepadulano May 21, 2025 17:46
@siliataider siliataider force-pushed the UHI-indexing branch 6 times, most recently from 89d21aa to ee76b59 Compare May 22, 2025 13:42
Copy link
Contributor

@silverweed silverweed left a comment

Choose a reason for hiding this comment

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

A couple of last comments :)

Copy link
Contributor

@silverweed silverweed left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@siliataider
Copy link
Contributor Author

Thanks a lot @vepadulano and @silverweed for the thorough rounds of review, I really appreciate it :)

@siliataider siliataider requested a review from vepadulano May 23, 2025 07:30
@siliataider siliataider dismissed vepadulano’s stale review May 23, 2025 07:51

Approved verbally

@siliataider siliataider merged commit 709304b into root-project:master May 23, 2025
23 checks passed
@smuzaffar
Copy link
Contributor

@siliataider , CMSSW DQM bin-by-bin comparison tests are failing with error [a] ( see cms-sw/cmssw#49452 ) . We see this error in both of our ROOT master based IBs and Ibs with ROOT 6.36. I guess the change here is causing this failure. Is there something we should fix on our side or this change introduce a bug?

[a]

PR file successfully opened
Traceback (most recent call last):
  File "/cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/49419/49598/CMSSW_16_0_X_2025-11-21-1100/bin/el8_amd64_gcc13/compareHistograms.py", line 345, in <module>
    create_dif(args.base_file, args.pr_file, args.pr_number, args.test_number, cmssw_version, args.num_processes, args.output_dir)
  File "/cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/49419/49598/CMSSW_16_0_X_2025-11-21-1100/bin/el8_amd64_gcc13/compareHistograms.py", line 80, in create_dif
    compare(shared_paths, pr_flat_dict, base_flat_dict, paths_to_save_in_pr, paths_to_save_in_base)
  File "/cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/49419/49598/CMSSW_16_0_X_2025-11-21-1100/bin/el8_amd64_gcc13/compareHistograms.py", line 182, in compare
    pr_array = np.array(pr_item)
  File "/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02916/el8_amd64_gcc13/lcg/root/6.36.05-302290958d85790e78b48654c2f216ba/lib/ROOT/_pythonization/_uhi.py", line 367, in _getitem
    uhi_index = _compute_common_index(self, index)
  File "/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02916/el8_amd64_gcc13/lcg/root/6.36.05-302290958d85790e78b48654c2f216ba/lib/ROOT/_pythonization/_uhi.py", line 223, in _compute_common_index
    return [_compute_uhi_index(self, idx, axis, include_flow_bins) for axis, idx in enumerate(index)]
  File "/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02916/el8_amd64_gcc13/lcg/root/6.36.05-302290958d85790e78b48654c2f216ba/lib/ROOT/_pythonization/_uhi.py", line 223, in <listcomp>
    return [_compute_uhi_index(self, idx, axis, include_flow_bins) for axis, idx in enumerate(index)]
  File "/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02916/el8_amd64_gcc13/lcg/root/6.36.05-302290958d85790e78b48654c2f216ba/lib/ROOT/_pythonization/_uhi.py", line 192, in _compute_uhi_index
    return _process_index_for_axis(self, index, axis)
  File "/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02916/el8_amd64_gcc13/lcg/root/6.36.05-302290958d85790e78b48654c2f216ba/lib/ROOT/_pythonization/_uhi.py", line 180, in _process_index_for_axis
    raise IndexError(f"Histogram index {index - 1} out of range for axis {axis}. Valid range: (0,{nbins})")
IndexError: Histogram index 30 out of range for axis 0. Valid range: (0,30)

@smuzaffar
Copy link
Contributor

@siliataider , should I open a github issue if there is no quick answer/solution the the problem I mentioned above

@siliataider
Copy link
Contributor Author

siliataider commented Nov 25, 2025

hi @smuzaffar , thanks for reporting this, if you don't need to access/compare the contents of the underflow/overflow bins, you can use pr_item.values() to get a NumPy array of your bin values and proceed with your comparison (instead of np.array(pr_item), that shouldn't raise any indexing errors, in the meantime could you open an issue with a small reproducer? I will look into it

@smuzaffar
Copy link
Contributor

@siliataider , see #20511

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants