ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hlGraph1.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_graphs
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
=
nullptr
;
12
13
void
HighlightHisto(
TVirtualPad
*pad,
TObject
*obj,
Int_t
ihp,
Int_t
y
)
14
{
15
auto
Pad = (
TVirtualPad
*)pad->
FindObject
(
"Pad"
);
16
if
(!Pad)
17
return
;
18
19
if
(ihp == -1) {
// after highlight disabled
20
Pad->
Clear
();
21
return
;
22
}
23
24
if
(
l
&&
l
->At(ihp)) {
25
Pad->cd();
26
l
->At(ihp)->
Draw
();
27
gPad
->Update();
28
}
29
}
30
31
void
hlGraph1()
32
{
33
auto
Canvas =
new
TCanvas
(
"Canvas"
,
"Canvas"
, 0, 0, 700, 500);
34
Canvas->HighlightConnect(
"HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)"
);
35
const
Int_t
n
= 500;
36
Double_t
x
[
n
],
y
[
n
];
37
l
=
new
TList
();
38
39
for
(
Int_t
i = 0; i <
n
; i++) {
40
auto
h
=
new
TH1F
(
TString::Format
(
"h_%03d"
, i),
""
, 100, -3.0, 3.0);
41
h
->FillRandom(
"gaus"
, 1000);
42
h
->Fit(
"gaus"
,
"Q"
);
43
h
->SetMaximum(250.0);
// for n > 200
44
l
->Add(
h
);
45
x
[i] = i;
46
y
[i] =
h
->GetFunction(
"gaus"
)->GetParameter(2);
47
}
48
49
auto
g
=
new
TGraph
(
n
,
x
,
y
);
50
g
->SetMarkerStyle(6);
51
g
->Draw(
"AP"
);
52
53
auto
Pad =
new
TPad
(
"Pad"
,
"Pad"
, 0.3, 0.4, 1.0, 1.0);
54
Pad->SetFillColor(
kBlue
- 10);
55
Pad->Draw();
56
Pad->cd();
57
auto
info =
new
TText
(0.5, 0.5,
"please move the mouse over the graPad"
);
58
info->SetTextAlign(22);
59
info->Draw();
60
Canvas->cd();
61
62
g
->SetHighlight();
63
}
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
gPad
#define gPad
Definition
TVirtualPad.h:308
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:623
TList
A doubly linked list.
Definition
TList.h:38
TObject
Mother of all ROOT objects.
Definition
TObject.h:41
TObject::Clear
virtual void Clear(Option_t *="")
Definition
TObject.h:119
TObject::FindObject
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition
TObject.cxx:420
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
hlGraph1.C
ROOT master - Reference Guide Generated on Thu Dec 19 2024 09:47:24 (GVA Time) using Doxygen 1.9.8