ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4629
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
float Float_t
Definition: RtypesCore.h:53
int Int_t
Definition: RtypesCore.h:41
void Class()
Definition: Class.C:29
void Error(const char *location, const char *msgfmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:264
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
The TH1 histogram class.
Definition: TH1.h:80
Mother of all ROOT objects.
Definition: TObject.h:58
#define gPad
Definition: TVirtualPad.h:288
TAxis * GetXaxis()
Definition: TH1.h:319