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) powerlaw.fit()
# this directory. # full_path = sys.path[0] + '/' + 'aptuple.tnt' nt1 = ntc.createNTuple ( full_path ) canvas.setPlotMatrix ( 2, 3 ) from hippo import Display hist = Display ( "Histogram", nt1, ("Cost", ) ) canvas.addDisplay( hist ) # Get the data representation so we can add function to it. datarep1 = hist.getDataRep() from hippo import Function gauss = Function ( "Gaussian", datarep1 ) gauss.addTo ( hist ) # Get the function parameters and display them. print "Before fitting" parmnames = gauss.parmNames ( ) print parmnames parms = gauss.parameters ( ) print parms # Now do the fitting. gauss.fit ( ) print "After fitting" parms = gauss.parameters ( )
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 ) powerlaw.fit()
from hippo import Cut hits_cut = Cut ( ntuple, ('TkrTotalHits',) ) canvas.addDisplay ( hits_cut ) hits_cut.setLog ( 'y', True ) hits_cut.addTarget ( hist ) hits_cut.setCutRange ( 4, 110, 'x' ) # Change the range of the displayed data hist.setRange ( 'x', 40, 700 ) # fit a function to the histogram from hippo import Function datarep = hist.getDataRep () exp1 = Function ( "Exponential", datarep ) exp1.addTo ( hist ) exp1.fit () # Print the results of the fit pnames = exp1.parmNames () print pnames parms = exp1.parameters () print parms # add another function to the histogram and fit the linear sum exp2 = Function ( "Exponential", datarep ) exp2.addTo ( hist )