Logo ROOT  
Reference Guide
hlGraph1.C File Reference

Detailed Description

This tutorial demonstrates how to use the highlight mode on graph.

TList *l = 0;
void HighlightHisto(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y);
void hlGraph1()
{
auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 700, 500);
const Int_t n = 500;
Double_t x[n], y[n];
TH1F *h;
l = new TList();
for (Int_t i = 0; i < n; i++) {
h = new TH1F(TString::Format("h_%03d", i), "", 100, -3.0, 3.0);
h->FillRandom("gaus", 1000);
h->Fit("gaus", "Q");
h->SetMaximum(250.0); // for n > 200
l->Add(h);
x[i] = i;
y[i] = h->GetFunction("gaus")->GetParameter(2);
}
auto g = new TGraph(n, x, y);
g->SetMarkerStyle(6);
g->Draw("AP");
auto Pad = new TPad("Pad", "Pad", 0.3, 0.4, 1.0, 1.0);
Pad->SetFillColor(kBlue-10);
Pad->Draw();
Pad->cd();
auto info = new TText(0.5, 0.5, "please move the mouse over the graPad");
info->SetTextAlign(22);
info->Draw();
Canvas->cd();
g->SetHighlight();
Canvas->HighlightConnect("HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)");
}
void HighlightHisto(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
{
auto Pad = (TVirtualPad *)pad->FindObject("Pad");
if (!Pad) return;
if (ihp == -1) { // after highlight disabled
Pad->Clear();
return;
}
Pad->cd();
l->At(ihp)->Draw();
gPad->Update();
}
#define g(i)
Definition: RSha256.hxx:105
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
@ kBlue
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:286
The Canvas class.
Definition: TCanvas.h:31
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
A doubly linked list.
Definition: TList.h:44
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Clear(Option_t *="")
Definition: TObject.h:100
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:321
The most important graphics class in the ROOT system.
Definition: TPad.h:29
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
Base class for several text objects.
Definition: TText.h:23
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
auto * l
Definition: textangle.C:4
Date
March 2018
Author
Jan Musinsky

Definition in file hlGraph1.C.