Exemplo n.º 1
0
if options.function == 'erfexp':
    fitter.erfexp('model', 'x')
    parameterization['type'] = 'erfexp'

if options.function == 'erfexpCB':
    fitter.erfexpCB('model', 'x')
    parameterization['type'] = 'erfexpCB'

if options.function == 'erfexpTimesCB':
    fitter.erfexpTimesCB('model', 'x')
    parameterization['type'] = 'erfexpTimesCB'

if options.function.find('bernstein') != -1:
    order = int(options.function.split('_')[1])
    fitter.bernstein('model', 'x', order)
    parameterization['type'] = 'bernstein'
    parameterization['order'] = order

fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(1)])
fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(1)])

fitter.projection("model", "data", "x", "debug" + options.output + ".png")

if parameterization['type'] == 'expo':
    val, err = fitter.fetch('c_0')
    parameterization['c_0'] = val
    parameterization['c_0Err'] = err

if parameterization['type'] == 'erfexp':
    for i in range(0, 3):
def interpolate(histos, axis, options):
    #create 2D histogram
    histo2D = ROOT.TH2D("histo2D", "histo2D", options.binsx, options.minx,
                        options.maxx, options.binsy, options.miny,
                        options.maxy)

    if options.fitFunc == "bernstein3":
        order = 3
    if options.fitFunc == "bernstein4":
        order = 4
    if options.fitFunc == "bernstein5":
        order = 5
    if options.fitFunc == "bifur":
        order = 3

    graphs = []
    for i in range(0, order):
        graphs.append(ROOT.TGraphErrors())

    #run the fits
    for N, h in enumerate(histos):
        center = axis.GetBinCenter(N + 1)
        fitter = Fitter(['mjj'])
        fitter.w.var("mjj").setVal(40)
        fitter.w.var("mjj").setMax(options.maxy)
        fitter.w.var("mjj").setMin(options.miny)
        if options.fitFunc == "bernstein3":
            fitter.bernstein('model', 'mjj', 3)
        if options.fitFunc == "bernstein4":
            fitter.bernstein('model', 'mjj', 4)
        if options.fitFunc == "bernstein5":
            fitter.bernstein('model', 'mjj', 5)
        if options.fitFunc == "bifur":
            fitter.bifur('model', 'mjj')

        fitter.importBinnedData(h, ['mjj'], 'data')
        fitter.fit('model', 'data')
        fitter.fit('model', 'data')
        fitter.projection("model", "data", "mjj",
                          "debugProjectionFit_" + str(N) + ".png")
        for j, g in enumerate(graphs):
            c, cerr = fitter.fetch("c_" + str(j))
            g.SetPoint(N, center, c)
            g.SetPointError(N, 0.0, cerr)

    ##OK now interpolate and make histograms!
    #first make the function
    fitter = Fitter(['mjj'])
    if options.fitFunc == "bernstein3":
        fitter.bernstein('model', 'mjj', 3)
        order = 3

    if options.fitFunc == "bernstein4":
        fitter.bernstein('model', 'mjj', 4)
        order = 4

    if options.fitFunc == "bernstein5":
        fitter.bernstein('model', 'mjj', 5)
        order = 5

    if options.fitFunc == "bifur":
        fitter.bifur('model', 'mjj')
        order = 3

    fitter.w.var("mjj").setVal(80)
    fitter.w.var("mjj").setMax(options.maxy)
    fitter.w.var("mjj").setMin(options.miny)
    for i in range(1, histo2D.GetNbinsX() + 1):
        x = histo2D.GetXaxis().GetBinCenter(i)
        print 'Bin:', i, 'Evaluating function at x=', x
        for j, g in enumerate(graphs):
            print "c_" + str(j), "=", g.Eval(x)
            fitter.w.var("c_" + str(j)).setVal(g.Eval(x, 0, "S"))

        histogram = fitter.w.pdf("model").createHistogram("mjj", options.binsy)
        for k in range(1, histo2D.GetNbinsY() + 1):
            bin = histo2D.GetBin(i, k)
            histo2D.SetBinContent(bin, histogram.GetBinContent(k))

    return graphs, histo2D