Zoom synchronization

Dear rooters,

I would like to synchronise the zoom of a histogram with the minimum and maximum of a TGaxis:
I have 2 pads in my canvas: one in the bottom with my histogram and one in the top with a TGaxis.
When I zoom on my histo I recover the xmin and xmax and pass them to TGaxis via SetWmin(xmin) and SetWmax(xmax).

After some Zoom, the result become very bad: the limit of the histogram and the TGaxis are differents (see the plot in attachment).
The Zoom on a histo is equivalent to SetRange(firsbin,lastbin).
So I think there is approximation problem between the Integres values (firsbin,lastbin) and Doulbe_t value (xmin, xmax).
Do you know how I can solve my problem ?

By advance thank you

olivier dadoun
Image 5.pdf (7.85 KB)

how do you recover xmin and xmax after a zoom on the histogram ?

I am using those following lines:

if(event == kButton1Down)
xmin = gPad->AbsPixeltoX(gPad->GetEventX());

if(event == kButton1Up)
xmax = gPad->AbsPixeltoX(gPad->GetEventX());
if (xmin > xmax)
Double_t temp = xmin;
xmin = xmax;
xmax = temp;


Ok, it looks correct. Can you print xmin and xmax in these pieces of code and check if they are the same values shown by the TGaxis on top of your plot ?

the echo (from the code source ) of xmin and xmax are the same value shown in the TGaxis, but not in the histogram
(the difference become worse and worse while the number of zoom increase).
In attachment a result after a lot of zoom (5 or 6):
xmin=250.027 and xmax=260
The Min and Max look like good for TGaxis but not for the histo.
I think it 's a precision problem, don’t you think?

Image 1.pdf (14.8 KB)

Yes that makes sense because the histogram is binned. When you zoom the histogram the number of bins diplayed is always an integer (we do not display a part of a bin). So when you zoom several time you get less and les bins displayed and the error becomes bigger and bigger. Instead of using xmin and xmax as you are doing now you should compute them as the histogram zoom does it. Make sure that the xmin and xmax you compute correspond to bins boundaries.

ok thank you.
But I can’t pass a integer value for max and min value for TGaxis.
I can do this only for TAxis with : SetRange(Int_t first, Int_t last ).
So the only way is to obtain the real value of the xmin and xmax after the ZOOM.
How I can manage it ?

thank you

You should not pass an integer value to TGaxis. TGaxis wants double to defines its limit. But the double you pass must correspond to the bins boundaries of the zoomed part you see on the screen. So you should compute xmin and xmax to make sure they correspond to bin boundaries.


to have the real min and max from the histo, I think I must use:
xmin = gPad->GetUxmin();
xmax = gPad->GetUxmax();
instead of
what do you think ?

Yes that should be better … try it.


no, using gPad->GetUxmax() and gPad->GetUxmin(),
my TGaxis is in late of one ZOOM compare to my histo, i.e
after 2 zoom my TGaxis take the xmin and xmax value from the first histo ZOOM (but the values are good).

Do you have something to suggest me ?

Try gPad->Update() before calling these functions

YES, my zoom synchronisation is now perfect :slight_smile:

Thank a lot …


sorry, a last question , an esthetic one.

With gPad->Update(),
It seems that I lose the VirtualBox (kHollow) from the ZOOM.
Do you have an idea ?

I am not sure about what you are talking about…

When you zoom on a histo the xmin and xmax limit are represented by a virtual box on the histo:
gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow)

I see…
No, for the time being I do not have a clue on how to get it back.
gPad->Update() redraw the picture in gPad from the list of primitives stored in it. That box is not of course as it is only temporary. That is why you lose it I guess.

Ok, I find a solution, I udpate gPad only when kButton1Up:
if(event == kButton1Up)gPad->Update();

now the virtual box for the zoom is there
(i.e gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow)