""" -*- mode: python -*- Create an NTuple with power-law distribution and histogram it on log log scale @author J. Chiang <*****@*****.**> """ from load_hippo import app, canvas import random, math shoot = random.uniform # Create empty NTuple of 4 columns that we can fill by row. from hippo import NTuple, NTupleController nt = NTuple() nt.setLabels(['x']) xmin = 1. xmax = 100. gamma = 2.1 xpmax = math.pow(xmax, 1. - gamma) xpmin = math.pow(xmin, 1. - gamma) nsamp = 10000 for i in range(nsamp): x = shoot(0, 1) xx = math.pow(x * (xpmax - xpmin) + xpmin, 1. / (1. - gamma)) nt.addRow((xx, )) from hippo import Display
sthist.setLabel ( 'x', 'X' ) sthist.setRange ( 'x', 0, 100) sthist.setBinWidth ( 'x', 1. ) canvas.addDisplay ( sthist ) # Create second static histogram and add it to canvas sthists = Display ( "Static Histogram" ) sthists.setTitle ( "Gaussian Distribution (low statistics)" ) sthists.setLabel ( 'x', 'X' ) sthists.setRange ( 'x', 0, 100) sthists.setBinWidth ( 'x', 1. ) canvas.addDisplay ( sthists ) # Create empty NTuple and set the column label. # Setting the column labels sets the number of columns ntuple = NTuple ( ) ntuple.setTitle ( 'Gaussian Distribution' ) ntuple.setLabels ( ('X value', ) ) # Register the NTuple so the Inspector can see it. NTupleController.instance().registerNTuple ( ntuple ) # Create dynamic histogram and attach it to NTuple. # It will automatically adjust its range, title, and labels dyhist = Display ( "Histogram", ntuple, ('X value', ) ) canvas.addDisplay ( dyhist ) mean = 45 sigma = 10 gauss = random.gauss
# compute errors assuming poisson fluctuations in electrons zerr = numarray.sqrt((abs(numarray.random_array.poisson(z)-z)*c.gain)**2.0+c.rdnoise**2.0) # Populate x and y arrays k = 0 for i in range(c.nxpts) : for j in range(c.nypts) : y[k] = j x[k] = i k += 1 # Generate the N-Tuple for the input data. Hippodraw needs it in this form from hippo import NTuple nt = NTuple () # empty one nt.addColumn ( 'x', x ) nt.addColumn ( 'y', y ) nt.addColumn ( 'z', z ) nt.addColumn ( 'xerr', xerr ) nt.addColumn ( 'yerr', yerr ) nt.addColumn ( 'zerr', zerr ) # Input data has been read, now fitter function need to configured from hippo import FitterFactory factory = FitterFactory.instance() fitters = factory.names() fittertouse = fitters[1] # fitters[1] -> Migrad Chi^2 minimisation migrad = factory.create (fittertouse)
""" -*- mode: python -*- Create an NTuple with power-law distribution and histogram it on log log scale @author J. Chiang <*****@*****.**> """ from load_hippo import app, canvas import random, math shoot = random.uniform # Create empty NTuple of 4 columns that we can fill by row. from hippo import NTuple, NTupleController nt = NTuple () nt.setLabels ( [ 'x' ] ) xmin = 1. xmax = 100. gamma = 2.1 xpmax = math.pow ( xmax, 1. - gamma ) xpmin = math.pow ( xmin, 1. - gamma ) nsamp = 10000 for i in range(nsamp): x = shoot(0, 1) xx = math.pow ( x*( xpmax - xpmin ) + xpmin, 1./ (1. - gamma) ) nt.addRow ( (xx, ) ) from hippo import Display