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