Logo ROOT   6.14/05
Reference Guide
cumulative.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook -js
4 /// Illustrate use of the TH1::GetCumulative method.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author M. Schiller
10 
11 #include <cassert>
12 #include <cmath>
13 
14 #include "TH1.h"
15 #include "TH1D.h"
16 #include "TCanvas.h"
17 #include "TRandom.h"
18 
19 TCanvas *cumulative()
20 {
21  TH1* h = new TH1D("h", "h", 100, -5., 5.);
22  gRandom->SetSeed();
23  h->FillRandom("gaus", 1u << 16);
24  // get the cumulative of h
25  TH1* hc = h->GetCumulative();
26  // check that c has the "right" contents
27  Double_t* integral = h->GetIntegral();
28  for (Int_t i = 1; i <= hc->GetNbinsX(); ++i) {
29  assert(std::abs(integral[i] * h->GetEntries() - hc->GetBinContent(i)) < 1e-7);
30  }
31  // draw histogram together with its cumulative distribution
32  TCanvas* c = new TCanvas;
33  c->Divide(1,2);
34  c->cd(1);
35  h->Draw();
36  c->cd(2);
37  hc->Draw();
38  c->Update();
39 
40  return c;
41 }
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4770
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
int Int_t
Definition: RtypesCore.h:41
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:589
TH1 * GetCumulative(Bool_t forward=kTRUE, const char *suffix="_cumulative") const
Return a pointer to an histogram containing the cumulative The cumulative can be computed both in the...
Definition: TH1.cxx:2537
virtual Double_t * GetIntegral()
Return a pointer to the array of bins integral.
Definition: TH1.cxx:2515
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3421
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
#define h(i)
Definition: RSha256.hxx:106
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
The TH1 histogram class.
Definition: TH1.h:56
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual Double_t GetEntries() const
Return the current number of entries.
Definition: TH1.cxx:4185
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:284
#define c(i)
Definition: RSha256.hxx:101
virtual Int_t GetNbinsX() const
Definition: TH1.h:291
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248