ROOT
Version master
master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
v6.04
Reference Guide
►
ROOT
•
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
10
TList
*
l
=
nullptr
;
11
12
void
HighlightHisto
(
TVirtualPad
*
pad
,
TObject
*obj,
Int_t
ihp
,
Int_t
y
)
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
29
void
gr301_highlight1
()
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
}
g
#define g(i)
Definition
RSha256.hxx:105
h
#define h(i)
Definition
RSha256.hxx:106
Int_t
int Int_t
Definition
RtypesCore.h:45
Double_t
double Double_t
Definition
RtypesCore.h:59
kBlue
@ kBlue
Definition
Rtypes.h:66
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
gPad
#define gPad
Definition
TVirtualPad.h:308
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition
TGraph.h:41
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:645
TList
A doubly linked list.
Definition
TList.h:38
TObject
Mother of all ROOT objects.
Definition
TObject.h:41
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition
TObject.cxx:292
TPad
The most important graphics class in the ROOT system.
Definition
TPad.h:28
TString::Format
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
TText
Base class for several text objects.
Definition
TText.h:22
TVirtualPad
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition
TVirtualPad.h:51
y
Double_t y[n]
Definition
legend1.C:17
x
Double_t x[n]
Definition
legend1.C:17
n
const Int_t n
Definition
legend1.C:16
l
TLine l
Definition
textangle.C:4
tutorials
visualisation
graphs
gr301_highlight1.C
ROOT master - Reference Guide Generated on Mon Feb 24 2025 14:45:13 (GVA Time) using Doxygen 1.10.0