Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist051_Graphics_candle_plot_stack.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Example showing how a THStack with candle plot option.
5///
6/// \macro_image (tcanvas_js)
7/// \macro_code
8///
9/// \date May 2024
10/// \authors Georg Troska, Olivier Couet
11
13{
15 auto rng = new TRandom();
16 auto dateBegin = new TDatime(2010, 1, 1, 0, 0, 0);
17 auto dateEnd = new TDatime(2011, 1, 1, 0, 0, 0);
18 int bins = 1000;
19 auto h1 = new TH2I("h1", "Machine A", 6, dateBegin->Convert(), dateEnd->Convert(), bins, 0, 1000);
20 auto h2 = new TH2I("h2", "Machine B", 6, dateBegin->Convert(), dateEnd->Convert(), bins, 0, 1000);
21 auto hsum = new TH2I("h4", "Sum", 6, dateBegin->Convert(), dateEnd->Convert(), bins, 0, 1000);
22
23 float Rand;
24 for (int i = dateBegin->Convert(); i < dateEnd->Convert(); i += 86400 * 30) {
25 for (int j = 0; j < 1000; j++) {
26 Rand = rng->Gaus(500 + sin(i / 10000000.) * 100, 50);
27 h1->Fill(i, Rand);
28 hsum->Fill(i, Rand);
29 Rand = rng->Gaus(500 + sin(i / 12000000.) * 100, 50);
30 h2->Fill(i, Rand);
31 hsum->Fill(i, Rand);
32 }
33 }
34
35 h2->SetLineColor(kRed);
36 hsum->SetFillColor(kGreen);
37 TCanvas *c1 = new TCanvas();
38
39 auto hs = new THStack("hs", "Machine A+B");
40 hs->Add(h1);
41 hs->Add(h2, "candle2");
42 hs->Add(hsum, "violin1");
43 hs->Draw("candle3");
44 hs->GetXaxis()->SetNdivisions(410);
45
46 gPad->SetGrid(1, 0);
47
48 hs->GetXaxis()->SetTimeDisplay(1);
49 hs->GetXaxis()->SetTimeFormat("%d/%m/%y");
50 hs->GetXaxis()->SetNdivisions(-6);
51 hs->GetXaxis()->SetTitle("Date [day/month/year]");
52 c1->Modified();
53
54 gPad->BuildLegend(0.75, 0.75, 0.95, 0.95, "");
55}
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
The Canvas class.
Definition TCanvas.h:23
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
2-D histogram with an int per channel (see TH1 documentation)
Definition TH2.h:227
The Histogram stack class.
Definition THStack.h:40
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition TStyle.cxx:1915
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5