ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cumulative.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Illustrate use of the TH1::GetCumulative method.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author M. Schiller
9 
10 #include <cassert>
11 #include <cmath>
12 
13 #include "TH1.h"
14 #include "TH1D.h"
15 #include "TCanvas.h"
16 #include "TRandom.h"
17 
18 TCanvas* cumulative()
19 {
20  TH1* h = new TH1D("h", "h", 100, -5., 5.);
21  gRandom->SetSeed();
22  h->FillRandom("gaus", 1u << 16);
23  // get the cumulative of h
24  TH1* hc = h->GetCumulative();
25  // check that c has the "right" contents
26  Double_t* integral = h->GetIntegral();
27  for (Int_t i = 1; i <= hc->GetNbinsX(); ++i) {
28  assert(std::abs(integral[i] * h->GetEntries() - hc->GetBinContent(i)) < 1e-7);
29  }
30  // draw histogram together with its cumulative distribution
31  TCanvas* c = new TCanvas;
32  c->Divide(1,2);
33  c->cd(1);
34  h->Draw();
35  c->cd(2);
36  hc->Draw();
37  c->Update();
38 
39  return c;
40 }
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4629
return c
#define assert(cond)
Definition: unittest.h:542
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
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:2445
int Int_t
Definition: RtypesCore.h:41
virtual Int_t GetNbinsX() const
Definition: TH1.h:296
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
virtual Double_t GetEntries() const
return the current number of entries
Definition: TH1.cxx:4051
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Definition: vector.h:450
virtual Double_t * GetIntegral()
Return a pointer to the array of bins integral.
Definition: TH1.cxx:2422
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
The TH1 histogram class.
Definition: TH1.h:80
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:1073
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179