Skip to content

TRatioPlot axes sync #9263

@belmakier

Description

@belmakier

Disclaimer: I'm new to this sort of thing but keen to contribute. Please let me know if I'm going about this the wrong way!

Explain what you would like to see improved

At present, changing the x axis range on the lower panel of a TRatioPlot does not automatically zoom the top panel. The axes update but the histogram is not redrawn with the correct scale.

Optional: share how it could be improved

As far as I can tell, what happens is this:

THistPainter::Paint() is called
    -> PaintInit() is called, this populates the Hparam structure with the old axis ranges
    -> PaintFrame() is called
          -> RecalculateRange() is called
                 -> gPad->RangeAxis() is called with the old ranges, and emits the RangeAxisChanged() signal
                 -> TRatioPlot::RangeAxisChanged() updates the axis ranges for the top panel
          -> The frame is painted with the old axis ranges
    -> The histogram is drawn with old ranges

The most straightforward way that I can see to fix this is to simply call PaintInit() and PaintFrame() again, directly after. This does solve the problem but seems quite inelegant.

Another idea would be to emit the RangeAxisChanged() signal before PaintInit() so that all the painting proceeds with correct ranges. This could be done by overloading a TPad::RangeAxis() to have an implementation with no arguments that only emits the signal.

To Reproduce

Simple macro - try zooming on the lower axis:
{ TH1D* hist = new TH1D("hist", "hist", 512, -10, 10); hist->FillRandom("gaus", 10000); TF1 *func = new TF1("func", "gaus"); hist->Fit(func); TRatioPlot *plot = new TRatioPlot(hist); plot->Draw(); }

Setup

  1. ROOT 6.25/01
  2. macOS 11.4
  3. build from git

Additional context

There is a comment
"// @todo: Updating is not working when zooming on the lower plot. Axes update, but upper hist only on resize"
in TRatioPlot.cxx so I assume at least one other person knows about this behavior

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions