Logo ROOT  
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
18void 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
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
float Float_t
Definition: RtypesCore.h:57
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
#define gPad
Definition: TVirtualPad.h:288
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
static TClass * Class()
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
Double_t x[n]
Definition: legend1.C:17