Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist057_TExec_th1.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

gPad->AddExec("ex1", ".x hist057_TExec_th1.C");
#define gPad

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

{
if (!gPad) {
Error("hist057_TExec_th1", "gPad is null, you are not supposed to run this macro");
return;
}
Int_t event = gPad->GetEvent();
int px = gPad->GetEventX();
TObject *select = gPad->GetSelected();
if (select && 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));
}
}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:41
Double_t x[n]
Definition legend1.C:17
Date
November 2022
Authors
Rene Brun, Sergey Linev

Definition in file hist057_TExec_th1.C.