Physics:PP/9/Histograms

From HandWiki

Histograms

1% complete
   

A most common method to visualize probability distributions is to use Histograms. Histograms can be used to estimate the Probability_distribution using a binned representation, i.e. when we

  1. define range of values we are interpreted in;
  2. divide the entire range of values into a series of intervals (with fixed or variable sizes;
  3. count how many values fall into each interval

Let us illustrate how to create a histogram for a variable in the range [0,1] using fixed bin size, and variable bin size

from ROOT import TH1D
from array import array

# histogram with fixed number of bins
h1=TH1D('test1','test1',100,0,1) # use 100 bins

# variable bins as array 
mbins=array("d",[0,0.1,0.2,0.4,1.0])
h2=TH1D('test2','test2',len(mbins)-1,mbins)

We have prepared two histogram objects, and we can do some manipulation. The first thing is to fill there two histograms with some random data.