Logo ROOT  
Reference Guide
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.
6/// \macro_image
7/// \macro_code
9/// \authors Georg Troska, Olivier Couet
11void candleplotstack()
14 TRandom *rng = new TRandom();
15 TDatime *dateBegin = new TDatime(2010,1,1,0,0,0);
16 TDatime *dateEnd = new TDatime(2011,1,1,0,0,0);
17 int bins = 1000;
18 TH2I *h1 = new TH2I("h1","Machine A",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
19 TH2I *h2 = new TH2I("h2","Machine B",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
20 TH2I *hsum = new TH2I("h4","Sum",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
22 float Rand;
23 for (int i = dateBegin->Convert(); i < dateEnd->Convert(); i+=86400*30) {
24 for (int j = 0; j < 1000; j++) {
25 Rand = rng->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand); hsum->Fill(i,Rand);
26 Rand = rng->Gaus(500+sin(i/12000000.)*100,50); h2->Fill(i,Rand); hsum->Fill(i,Rand);
27 }
28 }
30 h2->SetLineColor(kRed);
31 hsum->SetFillColor(kGreen);
32 TCanvas *c1 = new TCanvas();
34 THStack *hs = new THStack("hs","Machine A+B");
35 hs->Add(h1);
36 hs->Add(h2,"candle2");
37 hs->Add(hsum, "violin1");
38 hs->Draw("candle3");
39 hs->GetXaxis()->SetNdivisions(410);
41 gPad->SetGrid(1,0);
43 hs->GetXaxis()->SetTimeDisplay(1);
44 hs->GetXaxis()->SetTimeFormat("%m/%y");
45 hs->GetXaxis()->SetTitle("Date [month/year]");
47 c1->Modified();
49 gPad->BuildLegend(0.75,0.75,0.95,0.95,"");
@ kRed
Definition: Rtypes.h:66
@ kGreen
Definition: Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
#define gPad
Definition: TVirtualPad.h:288
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:236
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:162
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1053
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
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3348
2-D histogram with an int per channel (see TH1 documentation)}
Definition: TH2.h:216
Int_t Fill(Double_t) override
Invalid Fill method.
Definition: TH2.cxx:358
The Histogram stack class.
Definition: THStack.h:38
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:365
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Definition: THStack.cxx:450
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition: THStack.cxx:610
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:274
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1808
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition: RVec.hxx:1758
return c1
Definition: legend1.C:41
TH1F * h1
Definition: legend1.C:5
Definition: hsum.py:1