Echo object at mouse position and show a graphics line.
Example of macro called when a mouse event occurs in a pad.
Example:
Root >
c1.AddExec(
"ex2",
".x exec2.C");
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
When moving the mouse in the canvas, a second canvas shows the projection along X of the bin corresponding to the Y position of the mouse. The resulting histogram is fitted with a gaussian. A "dynamic" line shows the current bin position in Y. This more elaborated example can be used as a starting point to develop more powerful interactive applications exploiting CINT as a development engine.
void exec2()
{
Error(
"exec2",
"gPad is null, you are not supposed to run this macro");
return;
}
if(!select) return;
int pyold =
gPad->GetUniqueID();
int px =
gPad->GetEventX();
int py =
gPad->GetEventY();
float uxmin =
gPad->GetUxmin();
float uxmax =
gPad->GetUxmax();
int pxmin =
gPad->XtoAbsPixel(uxmin);
int pxmax =
gPad->XtoAbsPixel(uxmax);
if(pyold)
gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
if(
c2)
delete c2->GetPrimitive(
"Projection");
Int_t biny =
h->GetYaxis()->FindBin(
y);
TH1D *hp =
h->ProjectionX(
"",biny,biny);
char title[80];
sprintf(title,"Projection of biny=%d",biny);
}
void Error(const char *location, const char *msgfmt,...)
1-D histogram with a double per channel (see TH1 documentation)}
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
virtual void SetName(const char *name)
Change the name of this histogram.
Service class for 2-Dim histogram classes.
Mother of all ROOT objects.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
- Author
- Rene Brun
Definition in file exec2.C.