Logo ROOT   6.08/07
Reference Guide
candleplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Example of candle plot with 2-D histograms.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Georg Troska
10 
11 void candleplot() {
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 
18  TH2I *h1 = new TH2I("h1","Machine A + B",12,dateBegin->Convert(),dateEnd->Convert(),1000,0,1000);
19  TH2I *h2 = new TH2I("h2","Machine B",12,dateBegin->Convert(),dateEnd->Convert(),1000,0,1000);
20 
21  h1->GetXaxis()->SetTimeDisplay(1);
22  h1->GetXaxis()->SetTimeFormat("%m/%y");
23  h1->GetXaxis()->SetTitle("Date [month/year]");
24 
25  float Rand;
26  for (int i = dateBegin->Convert(); i < dateEnd->Convert(); i+=86400*30) {
27  for (int j = 0; j < 1000; j++) {
28  Rand = randnum->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand);
29  Rand = randnum->Gaus(500+sin(i/11000000.)*100,70); h2->Fill(i,Rand);
30  }
31  }
32 
33  h1->SetBarWidth(0.4);
34  h1->SetBarOffset(-0.25);
35 
36  h2->SetBarWidth(0.4);
37  h2->SetBarOffset(0.25);
38  h2->SetLineColor(kRed);
39 
40  TCanvas *c1 = new TCanvas();
41 
42  h1->Draw("candle2");
43  h2->Draw("candle3 same");
44 
45  gPad->BuildLegend(0.6,0.7,0.7,0.8);
46 }
virtual void SetBarOffset(Float_t offset=0.25)
Definition: TH1.h:361
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
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1468
virtual void SetBarWidth(Float_t width=0.5)
Definition: TH1.h:362
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
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
The Canvas class.
Definition: TCanvas.h:41
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
TAxis * GetXaxis()
Definition: TH1.h:324
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39