Skip to content

Conversation

ferdymercury
Copy link
Collaborator

@ferdymercury ferdymercury commented Apr 22, 2025

This Pull request:

Changes or fixes:

Fixes #14538

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

Copy link
Member

@linev linev left a comment

Choose a reason for hiding this comment

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

Great!

Features was implemented long-long time ago in JSROOT,
now it is time to have it in ROOT.

But several changes are required:

  • exclude loop repetition in TH1::GetRangeOfFilledWeights
  • if TH1::AutoZoom is invoked, it only should affect that histogram and not change zooming in all other histograms in the pad
  • same true for TAxis::AutoZoom - it only should change properties of this axis and not all histograms in the pad
  • but must be checked with superimposed histograms, THStack, TMultiGraph - they all can have side effects
  • fix failures with roottest

Copy link

github-actions bot commented Apr 22, 2025

Test Results

    19 files      19 suites   3d 13h 46m 21s ⏱️
 3 662 tests  3 615 ✅ 0 💤 47 ❌
68 172 runs  68 120 ✅ 5 💤 47 ❌

For more details on these failures, see this check.

Results for commit 06a128a.

♻️ This comment has been updated with latest results.

@ferdymercury
Copy link
Collaborator Author

  • if TH1::AutoZoom is invoked, it only should affect that histogram and not change zooming in all other histograms in the pad

This is already the behavior 'most of the time'. Only if DrawFrame was called before, the multi-analysis is run.
I was trying to mimick what Unzoom was doing, why should it be different?

@linev
Copy link
Member

linev commented Apr 22, 2025

Only if DrawFrame was called before, the multi-analysis is run.

DrawFrame is special use-case and not used with THStack or TMultiGraph painting.
And Unzoom() can behave differently as AutoZoom().

@linev
Copy link
Member

linev commented Apr 23, 2025

We need to wait with this PR until roottest merged into ROOT master.
Then one can sync all changes in one PR.

@ferdymercury
Copy link
Collaborator Author

I thought it was already merged, and I had rebased and synced into one.

@linev
Copy link
Member

linev commented Apr 23, 2025

I thought it was already merged

Yes, now I also see roottest in main repository. Things changing very fast!

@linev
Copy link
Member

linev commented Apr 23, 2025

I tried your code and have several more comments.

  1. For 1-D histogram with few entries TH1::AutoZoom() changes zooming for Y axis which is not nice.
  2. Selected range is exact position of the non-zero bins. If peak is very sharp and has just single bin width - produced result is unusable. One need some default margins on the left and right side of the peak.
  3. If there are several peaks - AutoZoom always show all peaks and not most significant one. Also if histogram already pre-zoomed to some range - peak should be searched in this range.

See my simple demo.
autozoom.C.txt

With THStack method does not work.

With superimposed histograms AutoZoom works only when first histogram is selected - for all others histogram method has no effect. At the same time Unzoom works for all histograms. Here correspondent demo:

autozoom_same.C.txt

@ferdymercury
Copy link
Collaborator Author

  1. For 1-D histogram with few entries TH1::AutoZoom() changes zooming for Y axis which is not nice.

I guess that's a feature of "TH1::UnZoom" that is also not nice, that could be handled in a separate PR ?

2. Selected range is exact position of the non-zero bins. If peak is very sharp and has just single bin width - produced result is unusable. One need some default margins on the left and right side of the peak.

I have implemented this now. It could be modified to accept a relative percentage rather than a fixed number of bins if wanted.

3. If there are several peaks - AutoZoom always show all peaks and not most significant one.

I do not understand what you mean. I am proposing AutoZoom to show all peaks, rather than the most significant.

3. Also if histogram already pre-zoomed to some range - peak should be searched in this range.

I kind of disagree, sometimes I like to zoom in to see a specific thing, and then AutoZoom to zoom out to the filled range. Maybe ZoomToFit is a better word for the function??

With superimposed histograms AutoZoom works only when first histogram is selected - for all others histogram method has no effect.

I had made a mistake. Is now fixed, thanks for finding out. You need though to click on the x-axis and click on AutoZoomAll, not AutoZoom. An equivalent function can be created in the TH1::AutoZoomAll if you think it's worth.

With THStack method does not work.

Support has been added now, via TAxis::AutozoomAll.

@ferdymercury ferdymercury requested a review from linev April 23, 2025 15:32
@linev
Copy link
Member

linev commented Apr 24, 2025

Still, AutoZoom on simple TH1 with few entries changes Y-zoom,
And current range is not taken into account when search for the range.

@ferdymercury
Copy link
Collaborator Author

Still, AutoZoom on simple TH1 with few entries changes Y-zoom

But Unzoom does the same, it's changing that too. It's zooming in rather than out.

And current range is not taken into account when search for the range.

Yes, but I argue that that's intended. Autozoom in matplotlib works also like that.

@linev
Copy link
Member

linev commented Apr 24, 2025

But Unzoom does the same, it's changing that too. It's zooming in rather than out.

Then one need to fix Unzoom too. It is not nice behavior.

Autozoom in matplotlib works also like that.

Use-case is simple. One makes approx zooming with mouse and then call method to get peak fully displayed.
Therefore behavior of matplotlib is not best approach here.

@ferdymercury
Copy link
Collaborator Author

Then one need to fix Unzoom too. It is not nice behavior.

Last commit tries to fix that.

@dpiparo
Copy link
Member

dpiparo commented Apr 27, 2025

@couet @linev is this ready to be merged?

@linev
Copy link
Member

linev commented Apr 28, 2025

@dpiparo No, there several issues with the PR.

@ferdymercury
Copy link
Collaborator Author

ferdymercury commented Aug 10, 2025

In my opinion this is ready to be merged.

The remaining comments by @linev are debatable from my point of view. For example, I disagree with the feature that zooms to a visible peak even if there might be higher peaks outside the currently visible range, since it goes against the typical behavior of eg matplotlib. If this is really wanted, then this should be a separate function that could be implemented in a separate PR. It could be called Smartzoom insted of Autozoom.

Besides, that SmartZoom solution is overcomplicated from the coding point of view, and hard to maintain, we need to pass as argument a vector with all preset zoom ranges for all dimensions, as well as if include or not overflow, etc etc, ie bugprone for many corner cases, if we have 5 histograms on top of each other, etc. I would propose to keep it simple as is and not delay this feature any X more years. No one is using it now, so if we introduce it and someone complains that why don't we have a new feature doing the extra recursive zoom, then we could think if it's worth to spend the time in implementing it.

Fixes root-project#14538

[hist] restore original class comment in order not to change streamerinfo checksum

[hist] prevent spurious looping on dimensions not belonging to the
derived class

as found out by linev

[hist] Split: 1 autozooms parent histogram, 1 autozooms all hists on pad

[hist] fix bug in max starting value and reset iterator before reusing

[hist] allow specifying a margin in GetRangeOfFilledWeights

[hist] adapt calls to new margin signature and add a margin of 1 bin

[hist] add safety check for static_cast
Default drawing histogram option is to leave a YMARGIN range of 10% in YMAX. So if you call Unzoom, it was calling GetMaximum, which calculated the exact maximum, and then called SetMaximum, thus overwriting the stored value. Use instead GetMaximumStored to prevent recalculation if not set by user.

[hist] Unzoom: add sanity check before casting
[test] add some extra bytes

[test] give more informative error output on stress failure
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.

[ROOT-5125] Autozoom functionality for TH1/TH2/TH3 or TAxis classes

4 participants