Hi Paul,
here a little macro as a starting point:
note this only works
with mouse button 1 (left) since root reserves the other two:
------------
void ex2()
{
int event = gPad->GetEvent();
// cout << "event "<< event << endl;
if (event != 1) return;
int px = gPad->GetEventX();
int py = gPad->GetEventY();
TObject *select = gPad->GetSelected();
if (!select) return;
if (select->InheritsFrom("TH2")) {
TH2 *h = (TH2*)select;
Float_t xx = gPad->AbsPixeltoX(px);
Float_t x = gPad->PadtoX(xx);
Int_t binx = h->GetXaxis()->FindBin(x);
Float_t yy = gPad->AbsPixeltoY(py);
Float_t y = gPad->PadtoY(yy);
Int_t biny = h->GetYaxis()->FindBin(y);
cout << "hist: " << h->GetName()
<< " bins = " << binx << " " << biny
<< " cont= " << h->GetBinContent(binx, biny)
<< endl;
}
}
--------------------------
To use it do e.g. with hsimple.root from the tutorials:
root [0] TFile f("hsimple.root")
root [1] hpxpy->Draw()
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [2] c1->AddExec("ex2",".x ex2.C")
root [3] hist: hpxpy bins = 13 25 cont= 28
hist: hpxpy bins = 33 14 cont= 4
hist: hpxpy bins = 31 31 cont= 3
----------------------
Then click with mouse 1 in the scatter plot.
see also:
http://root.cern.ch/root/htmldoc/TPad.html#TPad:AddExec
Cheers
Otto
On Mon, 15 Jul 2002, P.Dixon wrote:
> Hi,
>
> I have a series of data points - each with an x and y value and an
> associated name. What I want to be able to do is produce a scatter plot
> (using the x and y values) so that if I right click on a point, I can see
> the associated name (or run a function to list the attributes of this
> point - x, y and name).
>
> I'm not sure which way to set about this - does anyone have any
> suggestions?
>
> Cheers,
> Paul
>
> -------------------------------------------------------------------------------
> Paul Dixon Email: P.Dixon@qmw.ac.uk
> Department of Physics Phone: (020) 7882 5054
> Queen Mary, University of London Fax : (020) 7882 5054
> Mile End Road, London E1 4NS URL : http://hepwww.ph.qmw.ac.uk/~pd
> -------------------------------------------------------------------------------
>
--
Otto Schaile Sektion Physik, LMU Muenchen
Phone: +49 89 289 14070 Am Coulombwall 1, D-85748 Garching, Germany
GSM: +49 160 1553598
FAX: +49 89 289 14072 EMail: Otto.Schaile@Physik.Uni-Muenchen.DE
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:59 MET