# 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 ?

cheers,
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)
{
}

if(event == kButton1Up)
{
if (xmin > xmax)
{
Double_t temp = xmin;
xmin = xmax;
xmax = temp;
}
}

cheers
olivier

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?

cheers
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.

Hi,

to have the real min and max from the histo, I think I must use:
what do you think ?
cheers

Yes that should be better … try it.

Hi,

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 ?
cheers
olivier

Try gPad->Update() before calling these functions

YES, my zoom synchronisation is now perfect

Thank a lot …

cheers
Olivier

sorry, a last question , an esthetic one.

It seems that I lose the VirtualBox (kHollow) from the ZOOM.
Do you have an idea ?
cheers

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: