Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/// gPad->AddExec("ex1", ".x exec1.C");
8/// ~~~
9/// this macro prints the bin number and the bin content when one clicks
10/// on the histogram contour of any histogram in a pad
11///
12/// \macro_code
13///
14/// \authors Rene Brun, Sergey Linev
15
16
17void exec1()
18{
19 if (!gPad) {
20 Error("exec1", "gPad is null, you are not supposed to run this macro");
21 return;
22 }
23
24 Int_t event = gPad->GetEvent();
25 int px = gPad->GetEventX();
26 TObject *select = gPad->GetSelected();
27
28 if (select && select->InheritsFrom(TH1::Class())) {
29 TH1 *h = (TH1*)select;
30 Float_t xx = gPad->AbsPixeltoX(px);
31 Float_t x = gPad->PadtoX(xx);
32 Int_t binx = h->GetXaxis()->FindBin(x);
33 printf("event=%d, hist:%s, bin=%d, content=%f\n", event, h->GetName(), binx, h->GetBinContent(binx));
34 }
35}
36
#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:185
#define gPad
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:293
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
static TClass * Class()
TAxis * GetXaxis()
Definition TH1.h:324
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
Double_t x[n]
Definition legend1.C:17