ROOT
v6-22
Reference Guide
hlGraph1.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_graPads
3
///
4
/// This tutorial demonstrates how to use the highlight mode on graph.
5
///
6
/// \macro_code
7
///
8
/// \date March 2018
9
/// \author Jan Musinsky
10
11
TList
*
l
= 0;
12
13
void
HighlightHisto(
TVirtualPad
*pad,
TObject
*obj,
Int_t
ihp,
Int_t
y
);
14
15
16
void
hlGraph1()
17
{
18
auto
Canvas =
new
TCanvas
(
"Canvas"
,
"Canvas"
, 0, 0, 700, 500);
19
const
Int_t
n
= 500;
20
Double_t
x
[
n
],
y
[
n
];
21
TH1F
*
h
;
22
l
=
new
TList
();
23
24
for
(
Int_t
i = 0; i <
n
; i++) {
25
h
=
new
TH1F
(
TString::Format
(
"h_%03d"
, i),
""
, 100, -3.0, 3.0);
26
h
->FillRandom(
"gaus"
, 1000);
27
h
->Fit(
"gaus"
,
"Q"
);
28
h
->SetMaximum(250.0);
// for n > 200
29
l
->Add(
h
);
30
x
[i] = i;
31
y
[i] =
h
->GetFunction(
"gaus"
)->GetParameter(2);
32
}
33
34
auto
g
=
new
TGraph
(
n
,
x
,
y
);
35
g
->SetMarkerStyle(6);
36
g
->Draw(
"AP"
);
37
38
auto
Pad =
new
TPad
(
"Pad"
,
"Pad"
, 0.3, 0.4, 1.0, 1.0);
39
Pad->SetFillColor(
kBlue
-10);
40
Pad->Draw();
41
Pad->cd();
42
auto
info =
new
TText
(0.5, 0.5,
"please move the mouse over the graPad"
);
43
info->SetTextAlign(22);
44
info->Draw();
45
Canvas->cd();
46
47
g
->SetHighlight();
48
Canvas->HighlightConnect(
"HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)"
);
49
}
50
51
52
void
HighlightHisto(
TVirtualPad
*pad,
TObject
*obj,
Int_t
ihp,
Int_t
y
)
53
{
54
auto
Pad = (
TVirtualPad
*)pad->
FindObject
(
"Pad"
);
55
if
(!Pad)
return
;
56
57
if
(ihp == -1) {
// after highlight disabled
58
Pad->
Clear
();
59
return
;
60
}
61
62
Pad->cd();
63
l
->At(ihp)->Draw();
64
gPad
->Update();
65
}
g
#define g(i)
Definition:
RSha256.hxx:105
h
#define h(i)
Definition:
RSha256.hxx:106
Int_t
int Int_t
Definition:
RtypesCore.h:43
Double_t
double Double_t
Definition:
RtypesCore.h:57
kBlue
@ kBlue
Definition:
Rtypes.h:64
gPad
#define gPad
Definition:
TVirtualPad.h:287
TCanvas
The Canvas class.
Definition:
TCanvas.h:27
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:571
TList
A doubly linked list.
Definition:
TList.h:44
TObject
Mother of all ROOT objects.
Definition:
TObject.h:37
TObject::Clear
virtual void Clear(Option_t *="")
Definition:
TObject.h:115
TObject::FindObject
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition:
TObject.cxx:321
TPad
The most important graphics class in the ROOT system.
Definition:
TPad.h:29
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:2311
TText
Base class for several text objects.
Definition:
TText.h:23
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
auto * l
Definition:
textangle.C:4
tutorials
graphs
hlGraph1.C
ROOT v6-22 - Reference Guide Generated on Fri Apr 1 2022 11:53:27 (GVA Time) using Doxygen 1.9.4