Wrong coordinates when clicking a histogram

I have a GUI PyROOT app, with one window displaying TH2D, which, when clicked, displays another window with proper graphs. The point is, that the result of TCanvas.AbsPixelToX/Y() in the first window depend somehow on the contents of the graphs plotted in the second window. This looks some sort of memory leak, but it is… python.

I attach my app, stripped of most of the unnecessary code (it was pretty advanced, so stripping took me quite long - sorry for not needed GUI elements).

When mouse is hovering over the TH2D in the main window, the coordinates of canvas are displayed (GetEventX/Y() and AbsPixelToX/Y(), lines 100-105). When one clicks a “pixel” on TH2D second window opens. From the second window, from the menu, please select Analysis->Derivative. Then click on the TH2D again. You can spot, that coordinates from AbsPixelToX/Y() are wrong when clicking (but not when hovering!). When clicking for the second time, they are OK

However, if you change the content of the graph that is draw after choosing Analysis->Derivative, the coordinates can be correct. To do this comment line 359 and uncomment 360. So the number of point in the graph is the same, but the range is divided by 10…

What can be wrong?
etos.py (13.3 KB)

Hi,

There are two separate issues.

First of, on the C++ side, objects can be located by name, so having 4 canvases all called ‘Canvas’ is bound to cause problems. Likewise, gPad is a pointer to the current canvas. Mixing it together with the canvas you’re actually interested in, may case the code to act on an unrelated canvas based on what happened in the canvas that gPad is currently pointing to.

The second issue I do not quite understand, but there’s an update missing somewhere. That is, after renaming the canvases, calling ‘canv.Update()’ just before canv.AbsPixeltoX() solves the issue, but I can’t find the location where the Update() should have been done in the first place. (And if you don’t rename, you’ll see the last created canvas updating, rather than the one that contains the TH2D.)

HTH,
Wim

Thanks, it seems to solve the problem.

However, I think there may be slight redundancy in ROOT - first you create a TRootEmbeddedCanvas giving it its name, then you have to call on it GetCanvas() and give the resulting canvas the name too, if I understand correctly…