Logo ROOT   6.12/07
Reference Guide
thstackpalettecolor.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Palette coloring for histograms' stack is activated thanks to the options `PFC`
5 /// (Palette Fill Color), `PLC` (Palette Line Color) and `AMC` (Palette Marker Color).
6 /// When one of these options is given to `THStack::Draw` the histograms in the
7 /// `THStack` get their color from the current color palette defined by
8 /// `gStyle->SetPalette(...)`. The color is determined according to the number of
9 /// histograms.
10 ///
11 /// In this example four histograms are displayed with palette coloring.
12 /// The color of each histogram is picked inside the palette `kOcean`.
13 ///
14 /// \macro_image
15 /// \macro_code
16 ///
17 /// \author Olivier Couet
18 
19 void thstackpalettecolor()
20 {
21  THStack *hs = new THStack("hs","Stacked 1D histograms colored using kOcean palette");
22 
24 
25  // Create three 1-d histograms and add them in the stack
26  TH1F *h1st = new TH1F("h1st","test hstack",100,-4,4);
27  h1st->FillRandom("gaus",20000);
28  hs->Add(h1st);
29 
30  TH1F *h2st = new TH1F("h2st","test hstack",100,-4,4);
31  h2st->FillRandom("gaus",15000);
32  hs->Add(h2st);
33 
34  TH1F *h3st = new TH1F("h3st","test hstack",100,-4,4);
35  h3st->FillRandom("gaus",10000);
36  hs->Add(h3st);
37 
38  // draw the stack
39  hs->Draw("pfc nostack");
40 }
The Histogram stack class.
Definition: THStack.h:31
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:448
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3414
Definition: TColor.h:109
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition: THStack.cxx:362
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1459