""" -*- 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