Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr301_highlight1.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3///
4/// \preview This tutorial demonstrates how to use the highlight mode on graph, thanks to the TCanvas [HighlightConnect](https://root.cern/doc/master/classTCanvas.html#a462b8dc286a2d29152fefa9b31f89920) method.
5///
6/// \macro_code
7/// \date March 2018
8/// \author Jan Musinsky
9
10TList *l = nullptr;
11
13{
14 auto Pad = (TVirtualPad *)pad->FindObject("Pad");
15 if (!Pad) return;
16
17 if (ihp == -1) { // after highlight disabled
18 Pad->Clear();
19 return;
20 }
21
22 if (l && l->At(ihp)) {
23 Pad->cd();
24 l->At(ihp)->Draw();
25 gPad->Update();
26 }
27}
28
30{
31 auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 700, 500);
32 Canvas->HighlightConnect("HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)");
33 const Int_t n = 500;
34 Double_t x[n], y[n];
35 l = new TList();
36
37 for (Int_t i = 0; i < n; i++) {
38 auto h = new TH1F(TString::Format("h_%03d", i), "", 100, -3.0, 3.0);
39 h->FillRandom("gaus", 1000);
40 h->Fit("gaus", "Q");
41 h->SetMaximum(250.0); // for n > 200
42 l->Add(h);
43 x[i] = i;
44 y[i] = h->GetFunction("gaus")->GetParameter(2);
45 }
46
47 auto g = new TGraph(n, x, y);
48 g->SetMarkerStyle(6);
49 g->Draw("AP");
50
51 auto Pad = new TPad("Pad", "Pad", 0.3, 0.4, 1.0, 1.0);
52 Pad->SetFillColor(kBlue-10);
53 Pad->Draw();
54 Pad->cd();
55 auto info = new TText(0.5, 0.5, "please move the mouse over the graPad");
56 info->SetTextAlign(22);
57 info->Draw();
58 Canvas->cd();
59
60 g->SetHighlight();
61}
#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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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:645
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
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