Logo ROOT  
Reference Guide
exec1.C File Reference

Detailed Description

Echo object at mouse position. Example of macro called when a pad is redrawn one must create a TExec object in the following way

TExec ex("ex",".x exec1.C");
ex.Draw();

this macro prints the bin number and the bin content when one clicks on the histogram contour of any histogram in a pad

void exec1()
{
if (!gPad) {
Error("exec1", "gPad is null, you are not supposed to run this macro");
return;
}
int event = gPad->GetEvent();
if (event != 11) return;
int px = gPad->GetEventX();
TObject *select = gPad->GetSelected();
if (!select) return;
if (select->InheritsFrom(TH1::Class())) {
TH1 *h = (TH1*)select;
Float_t xx = gPad->AbsPixeltoX(px);
Float_t x = gPad->PadtoX(xx);
Int_t binx = h->GetXaxis()->FindBin(x);
printf("event=%d, hist:%s, bin=%d, content=%f\n",event,h->GetName(),binx,h->GetBinContent(binx));
}
}
Author
Rene Brun

Definition in file exec1.C.

ex
Double_t ex[n]
Definition: legend1.C:17
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TExec
Definition: TExec.h:28
h
#define h(i)
Definition: RSha256.hxx:124
TObject
Definition: TObject.h:37
TH1
Definition: TH1.h:57
gPad
#define gPad
Definition: TVirtualPad.h:287
Class
void Class()
Definition: Class.C:29
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187