Logo ROOT   6.14/05
Reference Guide
exec1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Echo object at mouse position.
4 /// Example of macro called when a pad is redrawn
5 /// one must create a TExec object in the following way
6 /// ~~~{.cpp}
7 /// TExec ex("ex",".x exec1.C");
8 /// ex.Draw();
9 /// ~~~
10 /// this macro prints the bin number and the bin content when one clicks
11 /// on the histogram contour of any histogram in a pad
12 ///
13 /// \macro_code
14 ///
15 /// \author Rene Brun
16 
17 
18 void exec1()
19 {
20  if (!gPad) {
21  Error("exec1", "gPad is null, you are not supposed to run this macro");
22  return;
23  }
24 
25  int event = gPad->GetEvent();
26  if (event != 11) return;
27  int px = gPad->GetEventX();
28  TObject *select = gPad->GetSelected();
29  if (!select) return;
30  if (select->InheritsFrom(TH1::Class())) {
31  TH1 *h = (TH1*)select;
32  Float_t xx = gPad->AbsPixeltoX(px);
33  Float_t x = gPad->PadtoX(xx);
34  Int_t binx = h->GetXaxis()->FindBin(x);
35  printf("event=%d, hist:%s, bin=%d, content=%f\n",event,h->GetName(),binx,h->GetBinContent(binx));
36  }
37 }
38 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
float Float_t
Definition: RtypesCore.h:53
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4770
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
void Class()
Definition: Class.C:29
void Error(const char *location, const char *msgfmt,...)
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
#define h(i)
Definition: RSha256.hxx:106
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
The TH1 histogram class.
Definition: TH1.h:56
Mother of all ROOT objects.
Definition: TObject.h:37
#define gPad
Definition: TVirtualPad.h:285
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315