""" -*- mode:python -*-

Draw from the unit interval, histogram and fit with a Constant function.

@author J. Chiang <jchiang@slac.stanford.edu>
"""
#
# $Id: ConstantModelFit.py.in,v 1.7 2005/05/22 14:36:46 pfkeb Exp $
#
## import sys
## sys.path.reverse()
## sys.path.append('@top_srcdir@/python')
## sys.path.append('@top_builddir@/python')
## sys.path.reverse()
import setPath

import random
import hippoplotter as plot

nt = plot.newNTuple( ([],), ("x",) )

npts = 10000
for i in range(npts):
    x = random.uniform(0, 1)
    nt.addRow((x,))

hist = plot.Histogram(nt, "x")
hist.setRange ( 'x', 0., 1. )
hist.setBinWidth ( 'x', 0.02 )

histRep = hist.getDataRep()

constant = plot.hippo.Function( "Constant", histRep)
constant.addTo(hist)
constant.fit()

print "Fitting a Constant function returns ", constant.parameters()[0]
print "Which is Entries / bin divided by the bin width, i.e. density"

