[Notes] ROOT User Guide (2)

来源:互联网 发布:dnf阿修罗智力固伤算法 编辑:程序博客网 时间:2024/06/05 16:15

 

Chapter 3. Histograms

 

Wikipedia: In statistics, a histogram is a graphical display of tabulated frequencies, shown as bars. It shows what proportion of cases fall into each of several categories: it is a form of data binning.

 

Classes:

1-D: TH1C, TH1S, TH1I, TH1F, TH1D

2-D: TH2C, TH2S, TH2I, TH2F, TH2D

3-D: TH3C, TH3S, TH3I, TH3F, TH3D

Profile Histogram: TProfile, TProfile2D

where C denotes char(1 byte), S short(2 bytes), I int(4 bytes), F float(4 bytes), D double(8 bytes).

 

Creating Historgrams

TH1F *h1 = new TH1F("h1","h1 title",100,0,4.4);

TH2F *h2 = new TH2F("h2","h2 title",40,0,4,30,-3,3);

 

Fixed or Variable Bin Size

TH1(const char name,const *title,Int_t nbins, Float_t *xbins)

TH1(const char name,const *title,Int_t nbins, Double_t *xbins)

where xbins is an array of low-edges for each bin. It is an array of size nbins+1.

 

Bin Numbering 

For 1-D, Bin#0 contains the underflow, The last bin contains the overflow.

For 2-D and 3-D, a "global bin" number is defined. Take 3-D for example,  

Int_t bin = h->GetBin(binx,biny,binz);

 

GetBinContent(...) : get the number of items in a specified bin

SetBinContent(..., ...) : set the number of items in a specified bin

 

Filling Histograms

The Fill method computes the bin number corresponding to the given x, y or z argument and increments this bin by the given weight. 

 

Fill Histograms with a function or a histrograms

Fill with a function:

 

Fill with another histrograms:

 

 

Scaling, Adding, Dividing and Multiplying

 

Draw Options: 

There are enormous draw options to display histrograms in different styles. See User Guide for details.

 

Remember these:

  • gRandom->Uniform()
  • gRandom->Gaus(0, 1)
  • kRed
  • kGreen