Hi Ed,
Look at (for example) THistPainter::GetObjectInfo,
you will see these lines:
Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
gPad->AbsPixeltoX(px) converts from pixel coordinates to pad coordinates
in the general case where you have sub-pads. What you do is only OK if you
have one single pad.
gPad->PadtoX(xx) converts from the pad coordinates back to the original
user coordinates (In case of log scale, they are different).
Rene Brun
On Thu, 7 Nov 2002, Ed Oltman wrote:
> Hello,
> I have a class derived from TH1F that overrides DistancetoPrimitive(). (I
> want
> a TH1F that gets selected when ever the mouse is between the histogram line
> and
> the y=0 axis.) I use gPad->PixeltoX/Y() routines. The gPad->PixelToX works
> fine:
> x is what it should be. The y is totally goofy. For example, when the
> displayed y-range is between 0 and 16000, gPad->PixeltoY returns -20657 when
> it
> should be 0 and -6242 when it should be 16000. (numbers here are
> approximate)
>
> What is going wrong? When I display the Status Bar, the displayed y-value
> is
> correct.
>
> I am using root 3.03/9a on win2k. I use cint and vc++ 6.0 to make my class
> into
> a dll.
>
> Thanks..
>
> //--------------------------------------------------------------------------
> ---
> Int_t CRange::DistancetoPrimitive(Int_t px,Int_t py)
> {
> Int_t dist = 999999;
> double x = gPad->PixeltoX(px);
> double y = gPad->PixeltoY(py);
>
> // debug print
> printf("x = %f y = %f pixx = %d pixy = %d\n",x,y,px,py);
>
>
> int bin = FindBin(x);
> if (bin<1 || bin>GetNbinsX()) return dist;
> double yHist = GetBinContent(bin);
> if (yHist>0.)
> {
> if (y<yHist && y>0.) dist = 2;
> }
> else
> {
> if (y>yHist && y<0.) dist = 2;
> }
> return dist;
> }
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:16 MET