Logo ROOT   6.08/07
Reference Guide
candleplotstack.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
7 /// \macro_code
8 ///
9 /// \authors Georg Troska, Olivier Couet
10 
11 void candleplotstack()
12 {
14  TRandom *randnum = 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  TH2I *h1 = new TH2I("h1","Machine A",12,dateBegin->Convert(),dateEnd->Convert(),1000,0,1000);
18  TH2I *h2 = new TH2I("h2","Machine B",12,dateBegin->Convert(),dateEnd->Convert(),1000,0,1000);
19  TH2I *h3 = new TH2I("h3","Machine C",12,dateBegin->Convert(),dateEnd->Convert(),1000,0,1000);
20 
21  float Rand;
22  for (int i = dateBegin->Convert(); i < dateEnd->Convert(); i+=86400*30) {
23  for (int j = 0; j < 1000; j++) {
24  Rand = randnum->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand);
25  Rand = randnum->Gaus(500+sin(i/11000000.)*100,70); h2->Fill(i,Rand);
26  Rand = randnum->Gaus(500+sin(i/11000000.)*100,90); h3->Fill(i,Rand);
27  }
28  }
29 
30  h2->SetLineColor(kRed);
31  h3->SetLineColor(kRed+3);
32  TCanvas *c1 = new TCanvas();
33 
34  THStack *hs = new THStack("hs","Machine A+B+C");
35  hs->Add(h1);
36  hs->Add(h2);
37  hs->Add(h3,"candle2");
38  hs->Draw("candle3");
39 
40  hs->GetXaxis()->SetTimeDisplay(1);
41  hs->GetXaxis()->SetTimeFormat("%m/%y");
42  hs->GetXaxis()->SetTitle("Date [month/year]");
43 
44  c1->Modified();
45 
46  gPad->BuildLegend(0.75,0.75,0.95,0.95,"");
47 }
The Histogram stack class.
Definition: THStack.h:35
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:999
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:235
return c1
Definition: legend1.C:41
Definition: Rtypes.h:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition: THStack.cxx:587
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1468
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:431
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:31
TH1F * h1
Definition: legend1.C:5
double sin(double)
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:167
The Canvas class.
Definition: TCanvas.h:41
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:345
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:181
#define gPad
Definition: TVirtualPad.h:289
THist< 2, int, THistStatContent > TH2I
Definition: THist.hxx:310
tomato 2-D histogram with an int per channel (see TH1 documentation)}
Definition: TH2.h:216
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
void Modified(Bool_t flag=1)
Definition: TPad.h:399
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39