示例#1
0
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 ( )
print parms

# Add another function.
gauss1 = Function ( "Gaussian", datarep1 )
gauss1.addTo ( hist )

# Do another fit, should fit to linear sum
gauss1.fit ()
示例#2
0
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 )

exp1.fit() # always fit to linear sum

# Build an array which is the sum of two columns and add it to the ntuple
label = "Raw sum"
ntuple [ label ] = ntuple [ 'TkrEnergy' ] + ntuple [ 'CalEnergyCorr' ]

# Histogram the new column
sum_hist = Display ( 'Histogram', ntuple, (label, ) )
canvas.addDisplay ( sum_hist )