Loading [MathJax]/extensions/tex2jax.js
Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
cumulative.C File Reference

Detailed Description

View in nbviewer Open in SWAN Illustrate use of the TH1::GetCumulative method.

#include <cassert>
#include <cmath>
#include "TH1.h"
#include "TH1D.h"
#include "TCanvas.h"
#include "TRandom.h"
TCanvas *cumulative()
{
TH1* h = new TH1D("h", "h", 100, -5., 5.);
h->FillRandom("gaus", 1u << 16);
// get the cumulative of h
TH1* hc = h->GetCumulative();
// check that c has the "right" contents
Double_t* integral = h->GetIntegral();
for (Int_t i = 1; i <= hc->GetNbinsX(); ++i) {
assert(std::abs(integral[i] * h->GetEntries() - hc->GetBinContent(i)) < 1e-7);
}
// draw histogram together with its cumulative distribution
TCanvas* c = new TCanvas;
c->Divide(1,2);
c->cd(1);
h->Draw();
c->cd(2);
hc->Draw();
c->Update();
return c;
}
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)}
Definition TH1.h:618
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
TH1 * GetCumulative(Bool_t forward=kTRUE, const char *suffix="_cumulative") const
Return a pointer to an histogram containing the cumulative content.
Definition TH1.cxx:2608
virtual Int_t GetNbinsX() const
Definition TH1.h:296
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
virtual Double_t * GetIntegral()
Return a pointer to the array of bins integral.
Definition TH1.cxx:2578
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:4993
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1177
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:608
Author
M. Schiller

Definition in file cumulative.C.