Trouble with TCanvas getObjectInfo


I am using getObjectInfo on a TH2F to get information on the bin the mouse is over. The canvas for the TH2F is connected to is adopted by an embedded canvas in a standalone GUI. The x position comes back okay, but the y postion is way off, returning a negative value much of the time. I pulled out the getObjectInfo code into mine, and found that gPad->PadtoY(gPad->AbsPixeltoY(py) seems to be the problem.

Does anyone know how to get the correct value, or why I’m getting an incorrect value?

Im using root 5.12//00



Hi Dan,

I will propose you to use signals/slots mechanism. Connecting your method to the signal ProcessedEvent(Int_t event,Int_t px,Int_t py,TObject* selected) of TCanvas, will allow you to get all you need. Please see the attached macro as an example how it works. A TH2F object will be drawn after you click the Draw button. After that you can see the ‘GetObjectInfo’ output written into the last part of the status bar.

Cheers, Ilka
embstatTH2.C (5.44 KB)

Thanks for your response. My code is set up the same way as in your code. The only difference in the implementation is that I replaced the getObjectInfo function with the relevent code from TH1, and cast the *Object inout to a *TH2F. I did this because the y-bin information was incorrect. I now see that

Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));

gives an incorrect answer. For an axis from 0 to 1 the reply will be negative from 0.0 to ~ 0.9 where it will hit zero, and return a positive number from ~0.9 to 1.0. Interestingly, things will work correctly once every ~100 runs or so, making me think that something is not getting properly initialized, but since I can not figure out any pattern to when it works, I don’t know where to look.

Thanks again


I tried Ilka’s example. It draws a surface. Try to use the option COL instead of SURF1 and you will get the correct x,y values.