Logo ROOT  
Reference Guide
candleplotstack.C File Reference

Detailed Description

View in nbviewer Open in SWAN Example showing how a THStack with candle plot option.

void candleplotstack()
{
TRandom *rng = new TRandom();
TDatime *dateBegin = new TDatime(2010,1,1,0,0,0);
TDatime *dateEnd = new TDatime(2011,1,1,0,0,0);
int bins = 1000;
TH2I *h1 = new TH2I("h1","Machine A",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
TH2I *h2 = new TH2I("h2","Machine B",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
TH2I *hsum = new TH2I("h4","Sum",6,dateBegin->Convert(),dateEnd->Convert(),bins,0,1000);
float Rand;
for (int i = dateBegin->Convert(); i < dateEnd->Convert(); i+=86400*30) {
for (int j = 0; j < 1000; j++) {
Rand = rng->Gaus(500+sin(i/10000000.)*100,50); h1->Fill(i,Rand); hsum->Fill(i,Rand);
Rand = rng->Gaus(500+sin(i/12000000.)*100,50); h2->Fill(i,Rand); hsum->Fill(i,Rand);
}
}
h2->SetLineColor(kRed);
hsum->SetFillColor(kGreen);
TCanvas *c1 = new TCanvas();
THStack *hs = new THStack("hs","Machine A+B");
hs->Add(h1);
hs->Add(h2,"candle2");
hs->Add(hsum, "violin1");
hs->Draw("candle3");
hs->GetXaxis()->SetNdivisions(410);
gPad->SetGrid(1,0);
hs->GetXaxis()->SetTimeFormat("%m/%y");
hs->GetXaxis()->SetTitle("Date [month/year]");
c1->Modified();
gPad->BuildLegend(0.75,0.75,0.95,0.95,"");
}
Authors
Georg Troska, Olivier Couet

Definition in file candleplotstack.C.

TRandom::Gaus
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:263
kGreen
@ kGreen
Definition: Rtypes.h:66
THStack
Definition: THStack.h:38
hsum
Definition: hsum.py:1
THStack::Add
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:361
TAxis::SetTimeFormat
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1020
sin
double sin(double)
TAxis::SetTimeDisplay
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
h1
TH1F * h1
Definition: legend1.C:5
THStack::GetXaxis
TAxis * GetXaxis() const
Get x axis of the histogram used to draw the stack.
Definition: THStack.cxx:603
TRandom
Definition: TRandom.h:27
TH2I
2-D histogram with an int per channel (see TH1 documentation)}
Definition: TH2.h:212
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
kRed
@ kRed
Definition: Rtypes.h:66
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
TStyle::SetTimeOffset
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1803
TCanvas
Definition: TCanvas.h:23
TAttAxis::SetNdivisions
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:228
gPad
#define gPad
Definition: TVirtualPad.h:287
TDatime
Definition: TDatime.h:37
TDatime::Convert
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
THStack::Draw
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:447
c1
return c1
Definition: legend1.C:41