ROOT
git-r3/HEAD
Reference Guide
Loading...
Searching...
No Matches
hist026_THStack_color_scheme.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook
4
/// \preview This example demonstrates how to use the accessible color schemes with THStack.
5
/// In this example, the color scheme with six colors is used.
6
/// It also shows that the grayscale version is an acceptable alternative.
7
///
8
/// \macro_image
9
/// \macro_code
10
///
11
/// \date October 2024
12
/// \author Olivier Couet
13
14
void
hist026_THStack_color_scheme()
15
{
16
auto
c1
=
new
TCanvas
();
17
auto
hs =
new
THStack
(
"hs"
,
"Stacked 1D histograms colored using 6-colors scheme"
);
18
19
// Create six 1-d histograms and add them in the stack
20
auto
h1st =
new
TH1F
(
"h1st"
,
"A"
, 100, -4, 4);
21
h1st->FillRandom(
"gaus"
, 20000);
22
h1st->SetFillColor(
kP6Blue
);
23
hs->Add(h1st);
24
25
auto
h2st =
new
TH1F
(
"h2st"
,
"B"
, 100, -4, 4);
26
h2st->FillRandom(
"gaus"
, 15000);
27
h2st->SetFillColor(
kP6Yellow
);
28
hs->Add(h2st);
29
30
auto
h3st =
new
TH1F
(
"h3st"
,
"C"
, 100, -4, 4);
31
h3st->FillRandom(
"gaus"
, 10000);
32
h3st->SetFillColor(
kP6Red
);
33
hs->Add(h3st);
34
35
auto
h4st =
new
TH1F
(
"h4st"
,
"D"
, 100, -4, 4);
36
h4st->FillRandom(
"gaus"
, 10000);
37
h4st->SetFillColor(
kP6Grape
);
38
hs->Add(h4st);
39
40
auto
h5st =
new
TH1F
(
"h5st"
,
"E"
, 100, -4, 4);
41
h5st->FillRandom(
"gaus"
, 10000);
42
h5st->SetFillColor(
kP6Gray
);
43
hs->Add(h5st);
44
45
auto
h6st =
new
TH1F
(
"h6st"
,
"F"
, 100, -4, 4);
46
h6st->FillRandom(
"gaus"
, 10000);
47
h6st->SetFillColor(
kP6Violet
);
48
hs->Add(h6st);
49
50
// draw the stack with colors
51
hs->Draw();
52
TLegend
*
l
=
gPad
->BuildLegend(.8, .55, 1., .9,
""
,
"F"
);
53
l
->SetLineWidth(0);
54
l
->SetFillStyle(0);
55
56
// draw the stack using gray-scale
57
auto
c2
=
new
TCanvas
();
58
c2
->SetGrayscale();
59
hs->Draw();
60
l
->Draw();
61
}
kP6Red
@ kP6Red
Definition
Rtypes.h:70
kP6Grape
@ kP6Grape
Definition
Rtypes.h:70
kP6Gray
@ kP6Gray
Definition
Rtypes.h:70
kP6Yellow
@ kP6Yellow
Definition
Rtypes.h:70
kP6Violet
@ kP6Violet
Definition
Rtypes.h:70
kP6Blue
@ kP6Blue
Definition
Rtypes.h:70
gPad
#define gPad
Definition
TVirtualPad.h:322
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:878
THStack
Definition
THStack.h:40
TLegend
Definition
TLegend.h:23
c1
return c1
Definition
legend1.C:41
c2
return c2
Definition
legend2.C:14
l
TLine l
Definition
textangle.C:4
tutorials
hist
hist026_THStack_color_scheme.C
ROOTgit-r3/HEAD - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1