Echo object at mouse position and show a graphics line.
Example of macro called when a mouse event occurs in a pad.
Example:
hpxpy->Draw("colz");
gPad->AddExec(
"ex2",
".x hist058_TExec_th2.C");
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
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 CLING as a development engine.
void hist058_TExec_th2()
{
Error(
"hist058_TExec_th2",
"gPad is null, you are not supposed to run this macro");
return;
}
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);
int pyold =
gPad->GetUniqueID();
gVirtualX->DrawLine(pxmin, pyold, pxmax, pyold);
}
TH2 *
h =
dynamic_cast<TH2 *
>(select);
return;
delete c2->GetPrimitive(
"Projection");
else
c2 =
new TCanvas(
"c2",
"Projection Canvas", 710, 10, 700, 500);
Int_t biny =
h->GetYaxis()->FindBin(
y);
TH1D *hp =
h->ProjectionX(
"", biny, biny);
padsav->cd();
}
int Int_t
Signed integer 4 bytes (int).
float Float_t
Float 4 bytes (float).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
1-D histogram with a double per channel (see TH1 documentation)
void SetTitle(const char *title) override
Change/set the title.
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.
void SetName(const char *name) override
Change the name of this histogram.
Service class for 2-D histogram classes.
Mother of all ROOT objects.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
- Date
- February 2023
- Authors
- Rene Brun, Sergey Linev
Definition in file hist058_TExec_th2.C.