ROOT logo
// echo object at mouse position
void exec1()
{
   //example of macro called when a pad is redrawn
   //one must create a TExec object in the following way
   // TExec ex("ex",".x exec1.C");
   // ex.Draw();
   // this macro prints the bin number and the bin content when one clicks
   //on the histogram contour of any histogram in a pad
   //Author: Rene Brun
   
   int event = gPad->GetEvent();
   if (event != 11) return;
   int px = gPad->GetEventX();
   TObject *select = gPad->GetSelected();
   if (!select) return;
   if (select->InheritsFrom("TH1")) {
      TH1 *h = (TH1*)select;
      Float_t xx = gPad->AbsPixeltoX(px);
      Float_t x  = gPad->PadtoX(xx);
      Int_t binx = h->GetXaxis()->FindBin(x);
      printf("event=%d, hist:%s, bin=%d, content=%f\n",event,h->GetName(),binx,h->GetBinContent(binx));
   }
}

 exec1.C:1
 exec1.C:2
 exec1.C:3
 exec1.C:4
 exec1.C:5
 exec1.C:6
 exec1.C:7
 exec1.C:8
 exec1.C:9
 exec1.C:10
 exec1.C:11
 exec1.C:12
 exec1.C:13
 exec1.C:14
 exec1.C:15
 exec1.C:16
 exec1.C:17
 exec1.C:18
 exec1.C:19
 exec1.C:20
 exec1.C:21
 exec1.C:22
 exec1.C:23
 exec1.C:24
 exec1.C:25
 exec1.C:26