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 # Generate some data, fill the static histograms and NTuple. for i in range(10000): x = gauss( mean, sigma ) sthist.addValues ( (x, ) ) ntuple.addRow ( (x, ) ) if i < 1000 : sthists.addValues ( (x, ) ) # only fill with first 1000 # Print some statistics from static histogram # Could do same for dynamic datarep = sthist.getDataRep() print "Histogram :" print " Title : " + sthist.getTitle() print " Entries : %i" % sthist.numberOfEntries() print " Mean = %f" % datarep.getMean ( 'x' ) print " Rms = %f" % datarep.getRMS ( 'x' ) # Print the average X value on the display
# 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 hist = Display('Histogram', nt, ('x', )) canvas.addDisplay(hist) # Set the x and y axis on log scale hist.setLog('x', True) hist.setLog('y', True) # fit to power law function from hippo import Function datarep = hist.getDataRep() powerlaw = Function("PowerLaw", datarep) powerlaw.addTo(hist)
# 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 hist = Display ( 'Histogram', nt, ( 'x', ) ) canvas.addDisplay ( hist ) # Set the x and y axis on log scale hist.setLog ( 'x', True ) hist.setLog ( 'y', True ) # fit to power law function from hippo import Function datarep = hist.getDataRep () powerlaw = Function ( "PowerLaw", datarep ) powerlaw.addTo( hist )