Example #1
0
    flat.SetParameter(0, 1.)
    flat.SetParLimits(0, 0.95, 1.05)

    sfTruth.Fit(flat)
    canvas.addObject(flat)

    linear = ROOT.TF1('linear', '[0] + [1] * x', scaleFactor.GetXaxis().GetXmin(), scaleFactor.GetXaxis().GetXmax())
    linear.SetParameters(1., 0.01)
    linear.SetParLimits(0, 0.95, 1.05)
    linear.SetParLimits(1, -0.0001, 0.0001)

    sfTruth.Fit(linear)
    canvas.addObject(linear)

    text = 'flat = %.3f #pm %.3f' % (flat.GetParameter(0), flat.GetParError(0))
    canvas.addText(text, 0.3, 0.25, 0.5, 0.2)

    text = 'line = %.6f + %.6f * p_{T}' % (linear.GetParameter(0), linear.GetParameter(1))
    canvas.addText(text, 0.3, 0.35, 0.5, 0.25)



canvas.xtitle = binningTitle
canvas.printWeb(outputName, 'scaleFactor_' + binningName, logy = False)


print 'Fit Results:'
for iBin, (bin, _) in enumerate(fitBins):
    print '%15s [%.3f +- %.3f]' % (bin, scaleFactor.GetBinContent(iBin + 1), scaleFactor.GetBinError(iBin + 1))

print '\nTruth Results:'
Example #2
0
    result.Fit(power)
    canvas.addObject(power)

    outputFile.cd()
    power.Write(PRODUCT + '_fit')

    text = 'f = %.4f + %.3f#times(p_{T} ' % (power.GetParameter(0),
                                             power.GetParameter(1))
    if power.GetParameter(2) >= 0.:
        text += ' - '
    else:
        text += ' + '
    text += '%.2f)^{%.2f}' % (abs(
        power.GetParameter(2)), power.GetParameter(3))

    canvas.addText(text, 0.4, 0.15, 0.6, 0.2)

    for ibin, (cont, err) in contents.items():
        result.SetBinContent(ibin, cont)
        result.SetBinError(ibin, err)

    # Throw toys and get uncertainties
    # draw one normal parameter for total systematic (assume full correlation across bins)
    # draw one normal parameter per bin for statistical
    # 68% percentile on both sides become the up & down variations

    original = tuple(power.GetParameter(i) for i in range(power.GetNpar()))

    ntoys = 200
    npx = 100