ROOT
git-r3/HEAD
Reference Guide
Loading...
Searching...
No Matches
legend1.C
Go to the documentation of this file.
1
{
2
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"c1"
,600,500);
3
gStyle
->SetOptStat(0);
4
5
TH1F
*
h1
=
new
TH1F
(
"h1"
,
"TLegend Example"
,200,-10,10);
6
h1
->FillRandom(
"gaus"
,30000);
7
h1
->SetFillColor(
kGreen
);
8
h1
->SetFillStyle(3003);
9
h1
->Draw();
10
11
TF1
*
f1
=
new
TF1
(
"f1"
,
"1000*TMath::Abs(sin(x)/x)"
,-10,10);
12
f1
->SetLineColor(
kBlue
);
13
f1
->SetLineWidth(4);
14
f1
->Draw(
"same"
);
15
16
const
Int_t
n
= 20;
17
Double_t
x
[
n
],
y
[
n
],
ex
[
n
],
ey
[
n
];
18
for
(
Int_t
i=0;i<
n
;i++) {
19
x
[i] = i*0.1;
20
y
[i] = 1000*sin(
x
[i]+0.2);
21
x
[i] = 17.8*
x
[i]-8.9;
22
ex
[i] = 1.0;
23
ey
[i] = 10.*i;
24
}
25
TGraphErrors
*
gr
=
new
TGraphErrors
(
n
,
x
,
y
,
ex
,
ey
);
26
gr
->SetName(
"gr"
);
27
gr
->SetLineColor(
kRed
);
28
gr
->SetLineWidth(2);
29
gr
->SetMarkerStyle(21);
30
gr
->SetMarkerSize(1.3);
31
gr
->SetMarkerColor(7);
32
gr
->Draw(
"P"
);
33
34
leg
=
new
TLegend
(0.1,0.7,0.48,0.9);
35
leg
->SetHeader(
"The Legend Title"
);
36
leg
->AddEntry(
h1
,
"Histogram filled with random numbers"
,
"f"
);
37
leg
->AddEntry(
"f1"
,
"Function abs(#frac{sin(x)}{x})"
,
"l"
);
38
leg
->AddEntry(
"gr"
,
"Graph with error bars"
,
"lep"
);
39
leg
->Draw();
40
41
return
c1
;
42
}
43
Int_t
int Int_t
Signed integer 4 bytes (int).
Definition
RtypesCore.h:59
Double_t
double Double_t
Double 8 bytes.
Definition
RtypesCore.h:73
kRed
@ kRed
Definition
Rtypes.h:67
kGreen
@ kGreen
Definition
Rtypes.h:67
kBlue
@ kBlue
Definition
Rtypes.h:67
gStyle
externTStyle * gStyle
Definition
TStyle.h:442
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TF1
Definition
TF1.h:182
TGraphErrors
Definition
TGraphErrors.h:26
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:878
TLegend
Definition
TLegend.h:23
c1
return c1
Definition
legend1.C:41
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
ey
Double_t ey[n]
Definition
legend1.C:17
gr
TGraphErrors * gr
Definition
legend1.C:25
ex
Double_t ex[n]
Definition
legend1.C:17
h1
TH1F * h1
Definition
legend1.C:5
f1
TF1 * f1
Definition
legend1.C:11
leg
leg
Definition
legend1.C:34
graf2d
graf
doc
macros
legend1.C
ROOTgit-r3/HEAD - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1