Example #1
0

## Sort the masses and run the fits
N=0
for mass in sorted(plotter.keys()):
    print 'fitting',str(mass)

    ## Get the histo from MC
    histo = plotter[mass].drawTH1(options.mvv,options.cut,"1",int((options.maxi-options.mini)/4),options.mini,options.maxi)

    ## Set up the fitter 
    fitter=Fitter(['x'])
    if options.doExp==1:
        fitter.jetResonance('model','x')
    else:
        fitter.jetResonanceNOEXP('model','x')
    if options.fixPars!="":
        fixedPars =options.fixPars.split(',')
        for par in fixedPars:
            parVal = par.split(':')
            fitter.w.var(parVal[0]).setVal(float(parVal[1]))
            fitter.w.var(parVal[0]).setConstant(1)
    #fitter.w.var("MH").setVal(mass)
    fitter.importBinnedData(histo,['x'],'data')

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

    ## control plot
    fitter.projection("model","data","x",options.debugFile+"_"+str(int(mass)).zfill(4)+".png",options.mvv,[],[ROOT.RooFit.LineColor(color)])
Example #2
0
def runFits(data,options):
    jsonFile=open(options.json)
    info=json.load(jsonFile)

    meanF = ROOT.TFormula("meanF",info['mean'].replace('MH','x'))
    sigmaF = ROOT.TFormula("sigmaF",info['sigma'].replace('MH','x'))
    alphaF = ROOT.TFormula("alphaF",info['alpha'].replace('MH','x'))
    nF = ROOT.TFormula("nF",info['n'].replace('MH','x'))
    alpha2F = ROOT.TFormula("alpha2F",info['alpha2'].replace('MH','x'))
    n2F = ROOT.TFormula("n2F",info['n2'].replace('MH','x'))
    slopeF = ROOT.TFormula("slopeF",info['slope'].replace('MH','x'))
    fF = ROOT.TFormula("fF",info['f'].replace('MH','x'))



#    axis=ROOT.TAxis(10,array('d',[600,800,900,1000,1250,1500,2000,2500,3000,3500,4000]))
    axis=ROOT.TAxis(10,array('d',[600,650,700,750,800,900,1000,1250,1500,2000,2500]))

    graphs={'mean':ROOT.TGraphErrors(),'sigma':ROOT.TGraphErrors(),'alpha':ROOT.TGraphErrors(),'n':ROOT.TGraphErrors(),'alpha2':ROOT.TGraphErrors(),'n2':ROOT.TGraphErrors(),'f':ROOT.TGraphErrors(),'slope':ROOT.TGraphErrors()}

    for i in range(1,axis.GetNbins()+1):
    
        center=axis.GetBinCenter(i)
        h = data.drawTH1(options.varx,options.cut+"*({vary}>{mini}&&{vary}<{maxi})".format(vary=options.vary,mini=axis.GetBinLowEdge(i),maxi=axis.GetBinUpEdge(i)),str(options.lumi),options.binsx,options.minx,options.maxx) 

        histo=copy.deepcopy(h)
        fitter=Fitter(['M'])
        fitter.w.var("M").setVal((options.maxx-options.minx)/2.0)
        fitter.w.var("M").setMax(options.maxx)
        fitter.w.var("M").setMin(options.minx)
        if options.doExp>=0: ##MICHALIS CHANGED IT
            fitter.jetResonance('model','M')
            fitter.w.var("slope").setVal(slopeF.Eval(center))
            fitter.w.var("slope").setMin(-2)
            fitter.w.var("slope").setMax(2)
            fitter.w.var("slope").setConstant(0)
            fitter.w.var("f").setVal(fF.Eval(center))
            fitter.w.var("f").setMin(0)
            fitter.w.var("f").setMax(1.)
            fitter.w.var("f").setConstant(0)


        else:    
            fitter.jetResonanceNOEXP('model','M')

        fitter.w.var("mean").setVal(meanF.Eval(center))
        fitter.w.var("mean").setMin(meanF.Eval(center)*0.9)
        fitter.w.var("mean").setMax(meanF.Eval(center)*1.1)
        fitter.w.var("sigma").setVal(sigmaF.Eval(center))
        fitter.w.var("sigma").setMin(sigmaF.Eval(center)*0.5)
        fitter.w.var("sigma").setMax(sigmaF.Eval(center)*2)
#        fitter.w.var("alpha").setVal(alphaF.Eval(center))
        fitter.w.var("alpha").setVal(1.59049)
        fitter.w.var("alpha").setConstant(1)

        fitter.w.var("alpha2").setVal(1.3)
        fitter.w.var("alpha2").setConstant(1)


#        fitter.w.var("alpha2").setConstant(1)



        fitter.importBinnedData(histo,['M'],'data')   
        fitter.fit('model','data',[ROOT.RooFit.SumW2Error(1),ROOT.RooFit.Minos(0)])
        fitter.fit('model','data',[ROOT.RooFit.SumW2Error(1),ROOT.RooFit.Minos(1)])
        chi=fitter.projection("model","data","M","debugfitMJJTop_"+options.output+"_"+str(i)+".png")
    
        for var,graph in graphs.iteritems():
            value,error=fitter.fetch(var)
            graph.SetPoint(i-1,center,value)
            graph.SetPointError(i-1,0.0,error)

    F=ROOT.TFile(options.output+".root","RECREATE")
    F.cd()
    for name,graph in graphs.iteritems():
        graph.Write(name)
    F.Close()
Example #3
0
def runFits(data, options):
    #    axis=ROOT.TAxis(10,array('d',[600,800,900,1000,1250,1500,2000,2500,3000,3500,4000]))
    axis = ROOT.TAxis(
        10,
        array('d',
              [600, 650, 700, 750, 800, 900, 1000, 1250, 1500, 2000, 2500]))

    graphs = {
        'mean': ROOT.TGraphErrors(),
        'sigma': ROOT.TGraphErrors(),
        'alpha': ROOT.TGraphErrors(),
        'n': ROOT.TGraphErrors(),
        'alpha2': ROOT.TGraphErrors(),
        'n2': ROOT.TGraphErrors(),
        'slope': ROOT.TGraphErrors(),
        'f': ROOT.TGraphErrors()
    }

    for i in range(1, axis.GetNbins() + 1):

        center = axis.GetBinCenter(i)
        h = data.drawTH1(
            options.varx,
            options.cut + "*({vary}>{mini}&&{vary}<{maxi})".format(
                vary=options.vary,
                mini=axis.GetBinLowEdge(i),
                maxi=axis.GetBinUpEdge(i)), str(options.lumi), options.binsx,
            options.minx, options.maxx)

        histo = copy.deepcopy(h)
        fitter = Fitter(['M'])
        fitter.w.var("M").setVal((options.maxx - options.minx) / 2.0)
        fitter.w.var("M").setMax(options.maxx)
        fitter.w.var("M").setMin(options.minx)

        if options.doExp:
            fitter.jetResonanceNOEXP('model', 'M')
            fitter.w.var("alpha").setVal(1.48)
            fitter.w.var("alpha").setConstant(1)
            fitter.w.var("alpha2").setVal(1.07)
            fitter.w.var("alpha2").setConstant(1)

#            fitter.jetResonance('model','M')

        else:
            fitter.jetResonanceNOEXP('model', 'M')

            fitter.w.var("alpha").setVal(1.48)
            fitter.w.var("alpha").setConstant(1)
            fitter.w.var("alpha2").setVal(1.07)
            fitter.w.var("alpha2").setConstant(1)

        fitter.importBinnedData(histo, ['M'], 'data')
        fitter.fit('model', 'data',
                   [ROOT.RooFit.SumW2Error(1),
                    ROOT.RooFit.Minos(0)])
        fitter.fit('model', 'data',
                   [ROOT.RooFit.SumW2Error(1),
                    ROOT.RooFit.Minos(1)])
        chi = fitter.projection(
            "model", "data", "M",
            "debugfitMJJTop_" + options.output + "_" + str(i) + ".png")

        for var, graph in graphs.iteritems():
            value, error = fitter.fetch(var)
            graph.SetPoint(i - 1, center, value)
            graph.SetPointError(i - 1, 0.0, error)

    F = ROOT.TFile(options.output + ".root", "RECREATE")
    F.cd()
    for name, graph in graphs.iteritems():
        graph.Write(name)
    F.Close()