Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hlGraph1.C File Reference

Detailed Description

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

TList *l = nullptr;
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;
}
if (l && l->At(ihp)) {
Pad->cd();
l->At(ihp)->Draw();
gPad->Update();
}
}
void hlGraph1()
{
auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 700, 500);
Canvas->HighlightConnect("HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)");
const Int_t n = 500;
Double_t x[n], y[n];
l = new TList();
for (Int_t i = 0; i < n; i++) {
auto 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();
}
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kBlue
Definition Rtypes.h:66
#define gPad
The Canvas class.
Definition TCanvas.h:23
A TGraph is an 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:621
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:403
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
The most important graphics class in the ROOT system.
Definition TPad.h:28
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:2378
Base class for several text objects.
Definition TText.h:22
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4
Date
March 2018
Author
Jan Musinsky

Definition in file hlGraph1.C.