ROOT
v6-22
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
Class
void Class()
Definition:
Class.C:29
h
#define h(i)
Definition:
RSha256.hxx:106
Int_t
int Int_t
Definition:
RtypesCore.h:43
Float_t
float Float_t
Definition:
RtypesCore.h:55
Error
void Error(const char *location, const char *msgfmt,...)
gPad
#define gPad
Definition:
TVirtualPad.h:287
TH1
The TH1 histogram class.
Definition:
TH1.h:56
TObject
Mother of all ROOT objects.
Definition:
TObject.h:37
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition:
TObject.cxx:443
x
Double_t x[n]
Definition:
legend1.C:17
tutorials
hist
exec1.C
ROOT v6-22 - Reference Guide Generated on Fri Apr 1 2022 11:53:28 (GVA Time) using Doxygen 1.9.4