This tutorial demonstrates how to use the highlight mode on graph.
{
if (!Canvas2) return;
if (!histo) return;
Int_t hbin = histo->FindBin(
p);
auto bh = (
TBox *)Canvas2->FindObject(
"TBox");
if (!bh) {
bh->SetFillStyle(3001);
}
bh->SetX1(histo->GetBinLowEdge(hbin));
bh->SetY1(histo->GetMinimum());
bh->SetX2(histo->GetBinWidth(hbin) + histo->GetBinLowEdge(hbin));
bh->SetY2(histo->GetBinContent(hbin));
auto th = (
TText *)Canvas2->FindObject(
"TText");
if (!th) {
th->SetName("TText");
th->SetTextColor(bh->GetFillColor());
}
th->SetText(histo->GetXaxis()->GetXmax()*0.75, histo->GetMaximum()*0.5,
if (ihp == -1) {
delete bh;
delete th;
}
Canvas2->Modified();
Canvas2->Update();
if (!redraw) return;
Canvas2->cd();
bh->Draw();
th->Draw();
Canvas2->Update();
savepad->cd();
}
void hlGraph2()
{
auto dir =
gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
file->GetObject(
"ntuple", ntuple);
if (!ntuple) return;
const char *cut = "pz > 3.0";
ntuple->
Draw(
"px:py", cut);
auto info =
new TText(0.0, 4.5,
"please move the mouse over the graph");
info->SetTextAlign(22);
info->SetTextSize(0.03);
info->SetTextColor(
kRed+1);
info->Draw();
auto Canvas2 =
new TCanvas(
"Canvas2",
"Canvas2", 505, 0, 600, 400);
ntuple->
Draw(
"TMath::Sqrt(px*px + py*py + pz*pz)>>histo(100, 0, 15)", cut);
ntuple->
Draw(
"px:py:pz:i", cut,
"goff");
}
winID h TVirtualViewer3D TVirtualGLPainter p
virtual void HighlightConnect(const char *slot)
This is "simplification" for function TCanvas::Connect with Highlighted signal for specific slot.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
A TGraph is an object made of two arrays X and Y with npoints each.
1-D histogram with a float per channel (see TH1 documentation)}
A simple TTree restricted to a list of float variables only.
Mother of all ROOT objects.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Base class for several text objects.
void Draw(Option_t *opt) override
Default Draw method for all objects.
virtual Double_t * GetV3()
virtual Double_t * GetV1()
virtual Double_t * GetV4()
virtual Double_t * GetV2()
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Double_t Sqrt(Double_t x)
Returns the square root of x.