modeString = 'Muon'
elif fitterPars.includeElectrons:
    modeString = 'Electron'
else:
    modeString = ''

theFitter = RooWjjMjjFitter(fitterPars)

if opts.compile:
    print 'compile complete'
    assert(False)

#theFitter.getWorkSpace().Print()
theFitter.makeFitter((opts.ParamWpJ>=0))

totalPdf = theFitter.getWorkSpace().pdf('totalPdf')
#theFitter.getWorkSpace().Print()
theFitter.getWorkSpace().var('nDiboson').setConstant(False)

# if opts.ParamWpJ < 0:
#     theFitter.getWorkSpace().var('fMU').setConstant(True)
#     theFitter.getWorkSpace().var('fSU').setConstant(True)

# theFitter.getWorkSpace().var('nDiboson').setConstant()
#theFitter.getWorkSpace().var('nTTbar').setConstant()
# theFitter.getWorkSpace().var('nSingleTop').setConstant()
# theFitter.getWorkSpace().var('nZjets').setConstant()
#theFitter.getWorkSpace().var('nWjets').setConstant()
theFitter.getWorkSpace().var('nQCD').setConstant()

if (opts.Nj == 3):
    modeString = "Muon"
elif fitterPars.includeElectrons:
    modeString = "Electron"
else:
    modeString = ""

theFitter = RooWjjMjjFitter(fitterPars)

if opts.compile:
    print "compile complete"
    assert False

# theFitter.getWorkSpace().Print()
theFitter.makeFitter((opts.ParamWpJ >= 0))

totalPdf = theFitter.getWorkSpace().pdf("totalPdf")
# theFitter.getWorkSpace().Print()
theFitter.getWorkSpace().var("nDiboson").setConstant(False)

# if opts.ParamWpJ < 0:
#     theFitter.getWorkSpace().var('fMU').setConstant(True)
#     theFitter.getWorkSpace().var('fSU').setConstant(True)

# theFitter.getWorkSpace().var('nDiboson').setConstant()
# theFitter.getWorkSpace().var('nTTbar').setConstant()
# theFitter.getWorkSpace().var('nSingleTop').setConstant()
# theFitter.getWorkSpace().var('nZjets').setConstant()
# theFitter.getWorkSpace().var('nWjets').setConstant()
theFitter.getWorkSpace().var("nQCD").setConstant()

if opts.Nj == 3:
Пример #3
0
    modeString = 'Muon'
elif fitterPars.includeElectrons:
    modeString = 'Electron'
else:
    modeString = ''

theFitter = RooWjjMjjFitter(fitterPars)

if opts.compile:
    print 'compile complete'
    assert(False)

#theFitter.getWorkSpace().Print()
theFitter.makeFitter((opts.ParamWpJ>=0))

totalPdf = theFitter.getWorkSpace().pdf('totalPdf')
#theFitter.getWorkSpace().Print()
theFitter.getWorkSpace().var('nDiboson').setConstant(False)

# if opts.ParamWpJ < 0:
#     theFitter.getWorkSpace().var('fMU').setConstant(True)
#     theFitter.getWorkSpace().var('fSU').setConstant(True)

# theFitter.getWorkSpace().var('nDiboson').setConstant()
#theFitter.getWorkSpace().var('nTTbar').setConstant()
# theFitter.getWorkSpace().var('nSingleTop').setConstant()
# theFitter.getWorkSpace().var('nZjets').setConstant()
#theFitter.getWorkSpace().var('nWjets').setConstant()
theFitter.getWorkSpace().var('nQCD').setConstant()

if (opts.Nj == 3):
elif fitterPars.includeElectrons:
    modeString = 'Electron'
else:
    modeString = ''


theFitter = RooWjjMjjFitter(fitterPars)

#theFitter.getWorkSpace().Print()
theFitter.makeFitter((opts.ParamWpJ>=0))
theFitter.loadData()


#theFitter.getWorkSpace().Print()
#theFitter.getWorkSpace().var('nDiboson').setConstant(True)
if theFitter.getWorkSpace().var('fMU'):
    theFitter.getWorkSpace().var('fMU').setConstant(True)
    theFitter.getWorkSpace().var('fSU').setConstant(True)
theFitter.resetYields()
#theFitter.getWorkSpace().var('nQCD').setConstant(True)
#theFitter.getWorkSpace().var('nSingleTop').setConstant(True)
#theFitter.getWorkSpace().var('nZjets').setConstant(True)

fr = theFitter.fit()

#assert(False)

# tries = 1
# while (fr.covQual() != 3) and (tries < 2):
#     print "Fit didn't converge well.  Will try again."
#     fr = theFitter.fit(True)
##     extraNdf += 1
## ndf = Long(3+extraNdf)
ndf = Long(1+extraNdf)
print ' *** uncorrected chi2 ***'
chi2 = theFitter.computeChi2(ndf, False)
print ' *** corrected chi2 ***'
ndf = Long(1+extraNdf)
chi2 = theFitter.computeChi2(ndf, True)
print ' *** '
chi2 = 0
# chi2frame.Draw()

# assert False, "fit done"

yields = fr.floatParsFinal()
mass = theFitter.getWorkSpace().var(fitterPars.var)
iset = RooArgSet(mass)
covMatrix = TMatrixDSym(fr.covarianceMatrix())

sig2 = 0.
sig2All = 0.
for v1 in range(0, covMatrix.GetNrows()):
    for v2 in range(0, covMatrix.GetNcols()):
        if ((yields[v1].GetName())[0] == 'n') and \
               ((yields[v2].GetName())[0] == 'n'):
            #print v1, yields[v1].GetName(),',', v2, yields[v2].GetName()
            if not (yields[v1].GetName() == 'nDiboson') \
                   and not (yields[v2].GetName() == 'nDiboson'):
                sig2 += covMatrix(v1, v2)
            sig2All += covMatrix(v1, v2)
theFitter.makeFitter(False)

#theFitter.getWorkSpace().Print()
fr = theFitter.fit()

extraNdf = 0
if not fitterPars.constrainDiboson:
    extraNdf += 1
ndf = Long(fr.floatParsFinal().getSize()-5+extraNdf)
chi2 = theFitter.computeChi2(ndf)
# chi2frame.Draw()

# assert False, "fit done"

yields = fr.floatParsFinal()
mass = theFitter.getWorkSpace().var(fitterPars.var)
iset = RooArgSet(mass)
covMatrix = TMatrixDSym(fr.covarianceMatrix())

sig2 = 0.
for v1 in range(0, covMatrix.GetNrows()):
    for v2 in range(0, covMatrix.GetNcols()):
        if ((yields[v1].GetName())[0] == 'n') and \
               ((yields[v2].GetName())[0] == 'n'):
            #print v1, yields[v1].GetName(),',', v2, yields[v2].GetName()
            sig2 += covMatrix(v1, v2)

from plotMjjFit import plot2BodyDist

if (opts.Err >= 0) and (opts.Err < 1):
    opts.Err = sqrt(sig2)*1.37
def qPlot(fitterPars):
    from ROOT import kRed, kBlack, kGreen, kOrange, kMagenta, kCyan, THStack, \
         RooWjjMjjFitter, RooWjjFitterUtils, TCanvas
    
    fitUtils = RooWjjFitterUtils(fitterPars)
    theFitter = RooWjjMjjFitter(fitterPars)

    thePdf = theFitter.makeFitter(False)
    theFitter.loadParameters(fitterPars.initParamsFile)

    theFitter.getWorkSpace().Print()

    q = theFitter.getWorkSpace().var(fitterPars.var)
    q.SetTitle("Q = m_{l#nujj}-m_{jj}-M_{W}")

    pdfs = thePdf.pdfList()
    coefs = thePdf.coefList()
    shapeHist = THStack('shapeHist', 'shapeHist')

    sumYield = 0.
    for i in range(pdfs.getSize()-1, -1, -1):
        tmpHist = pdfs[i].createHistogram('h_' + pdfs[i].GetName(), q)
        theName = pdfs[i].GetName()[:3]
        tmpHist.SetFillStyle(1001)
        if theName == 'dib':
            tmpHist.SetFillColor(kOrange)
            tmpHist.SetLineColor(kOrange)
        elif theName == 'WpJ':
            tmpHist.SetFillColor(kRed)
            tmpHist.SetLineColor(kRed)
        elif theName == 'ttP':
            tmpHist.SetFillColor(kBlack)
            tmpHist.SetLineColor(kBlack)
        elif theName == 'stP':
            tmpHist.SetFillColor(kBlack)
            tmpHist.SetLineColor(kBlack)
        elif theName == 'qcd':
            tmpHist.SetFillColor(kGreen)
            tmpHist.SetLineColor(kGreen)
        elif theName == 'ZpJ':
            tmpHist.SetFillColor(kMagenta)
            tmpHist.SetLineColor(kMagenta)
        
##         tmpHist.Draw()
##         gPad.Update()
##         gPad.WaitPrimitive()

        tmpHist.Scale(coefs[i].getVal())
        sumYield += coefs[i].getVal()
        if (coefs[i].getVal() > 0.):
            shapeHist.Add(tmpHist)

    totalShapeHist = thePdf.createHistogram("totalShapeHist", q)
    totalShapeHist.Print()

    dataHist = fitUtils.newEmptyHist("theData")
    if fitterPars.includeMuons:
        tmpHist = fitUtils.File2Hist(fitterPars.DataDirectory+fitterPars.muonData,
                                     "tmpData", False, 0, False, 1.0,
                                     fitUtils.fullCuts())
        dataHist.Add(tmpHist)

    if fitterPars.includeElectrons:
        tmpHist = fitUtils.File2Hist(fitterPars.DataDirectory+fitterPars.electronData,
                                     "tmpData", True, 0, False, 1.0,
                                     fitUtils.fullCuts())
        dataHist.Add(tmpHist)

    totalShapeHist.Scale(sumYield)
##     shapeHist.SetLineColor(kCyan+3)
##     shapeHist.SetMarkerColor(kCyan+3)

    cq = TCanvas('cq', 'Q')
    shapeHist.Draw('')
    shapeHist.GetXaxis().SetTitle(q.GetTitle() + ' (GeV)')
    shapeHist.GetYaxis().SetTitle('Events / (%0.0f GeV)' % ((fitterPars.maxMass-fitterPars.minMass)/fitterPars.nbins))
    dataHist.Draw('same')
    cq.Modified()
    #totalShapeHist.Draw('same')
    dataHist.Chi2Test(totalShapeHist,"UUNORMP")
    print "KS test:",dataHist.KolmogorovTest(totalShapeHist)
    return (cq, shapeHist, totalShapeHist)
Пример #8
0
def qPlot(fitterPars):
    from ROOT import kRed, kBlack, kGreen, kOrange, kMagenta, kCyan, THStack, \
         RooWjjMjjFitter, RooWjjFitterUtils, TCanvas

    fitUtils = RooWjjFitterUtils(fitterPars)
    theFitter = RooWjjMjjFitter(fitterPars)

    thePdf = theFitter.makeFitter(False)
    theFitter.loadParameters(fitterPars.initParamsFile)

    theFitter.getWorkSpace().Print()

    q = theFitter.getWorkSpace().var(fitterPars.var)
    q.SetTitle("Q = m_{l#nujj}-m_{jj}-M_{W}")

    pdfs = thePdf.pdfList()
    coefs = thePdf.coefList()
    shapeHist = THStack('shapeHist', 'shapeHist')

    sumYield = 0.
    for i in range(pdfs.getSize() - 1, -1, -1):
        tmpHist = pdfs[i].createHistogram('h_' + pdfs[i].GetName(), q)
        theName = pdfs[i].GetName()[:3]
        tmpHist.SetFillStyle(1001)
        if theName == 'dib':
            tmpHist.SetFillColor(kOrange)
            tmpHist.SetLineColor(kOrange)
        elif theName == 'WpJ':
            tmpHist.SetFillColor(kRed)
            tmpHist.SetLineColor(kRed)
        elif theName == 'ttP':
            tmpHist.SetFillColor(kBlack)
            tmpHist.SetLineColor(kBlack)
        elif theName == 'stP':
            tmpHist.SetFillColor(kBlack)
            tmpHist.SetLineColor(kBlack)
        elif theName == 'qcd':
            tmpHist.SetFillColor(kGreen)
            tmpHist.SetLineColor(kGreen)
        elif theName == 'ZpJ':
            tmpHist.SetFillColor(kMagenta)
            tmpHist.SetLineColor(kMagenta)


##         tmpHist.Draw()
##         gPad.Update()
##         gPad.WaitPrimitive()

        tmpHist.Scale(coefs[i].getVal())
        sumYield += coefs[i].getVal()
        if (coefs[i].getVal() > 0.):
            shapeHist.Add(tmpHist)

    totalShapeHist = thePdf.createHistogram("totalShapeHist", q)
    totalShapeHist.Print()

    dataHist = fitUtils.newEmptyHist("theData")
    if fitterPars.includeMuons:
        tmpHist = fitUtils.File2Hist(
            fitterPars.DataDirectory + fitterPars.muonData, "tmpData", False,
            0, False, 1.0, fitUtils.fullCuts())
        dataHist.Add(tmpHist)

    if fitterPars.includeElectrons:
        tmpHist = fitUtils.File2Hist(
            fitterPars.DataDirectory + fitterPars.electronData, "tmpData",
            True, 0, False, 1.0, fitUtils.fullCuts())
        dataHist.Add(tmpHist)

    totalShapeHist.Scale(sumYield)
    ##     shapeHist.SetLineColor(kCyan+3)
    ##     shapeHist.SetMarkerColor(kCyan+3)

    cq = TCanvas('cq', 'Q')
    shapeHist.Draw('')
    shapeHist.GetXaxis().SetTitle(q.GetTitle() + ' (GeV)')
    shapeHist.GetYaxis().SetTitle(
        'Events / (%0.0f GeV)' %
        ((fitterPars.maxMass - fitterPars.minMass) / fitterPars.nbins))
    dataHist.Draw('same')
    cq.Modified()
    #totalShapeHist.Draw('same')
    dataHist.Chi2Test(totalShapeHist, "UUNORMP")
    print "KS test:", dataHist.KolmogorovTest(totalShapeHist)
    return (cq, shapeHist, totalShapeHist)