import pyroot_logon
config = __import__(opts.modeConfig)
from ROOT import gROOT
## gROOT.ProcessLine('.L RooWjjFitterParams.h+');
gROOT.ProcessLine('.L EffTableReader.cc+')
gROOT.ProcessLine('.L EffTableLoader.cc+')
gROOT.ProcessLine('.L RooWjjFitterUtils.cc+');
gROOT.ProcessLine('.L RooWjjMjjFitter.cc+');
from ROOT import RooWjjMjjFitter, RooFitResult, \
     RooMsgService, RooFit

RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)
tmpInitFile = opts.startingFile

fitterPars = config.theConfig(opts.Nj, opts.mcdir, tmpInitFile)
theFitter = RooWjjMjjFitter(fitterPars)

def writeValToFile(optVar, newVal, filename, outname = None,
                   theVars = optVars):
    if outname == None:
        outname = filename
    newStart = open(filename).readlines()
    for tmpVar in theVars:
        compliment = tmpVar.replace('U', 'D')
        if optVar == tmpVar:
            theVal = newVal
        else:
            theVal = theVars[tmpVar]
        if (theVal >= 0):
            newStart = [re.sub('^{0} = [ ]*[-0-9\.]*'.format(tmpVar),
                               '{0} = {1:.3f}'.format(tmpVar, theVal), x) \
    fitterPars.minMass = fitterPars.binEdges[0]
    fitterPars.minFit = fitterPars.minMass

if opts.lumi:
    fitterPars.intLumi = opts.lumi
    
if fitterPars.includeMuons and fitterPars.includeElectrons:
    modeString = ''
elif fitterPars.includeMuons:
    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)
Ejemplo n.º 3
0
import pyroot_logon
config = __import__(opts.modeConfig)
from ROOT import gROOT
## gROOT.ProcessLine('.L RooWjjFitterParams.h+');
gROOT.ProcessLine('.L EffTableReader.cc+')
gROOT.ProcessLine('.L EffTableLoader.cc+')
gROOT.ProcessLine('.L RooWjjFitterUtils.cc+')
gROOT.ProcessLine('.L RooWjjMjjFitter.cc+')
from ROOT import RooWjjMjjFitter, RooFitResult, \
     RooMsgService, RooFit

RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)
tmpInitFile = opts.startingFile

fitterPars = config.theConfig(opts.Nj, opts.mcdir, tmpInitFile)
theFitter = RooWjjMjjFitter(fitterPars)


def writeValToFile(optVar, newVal, filename, outname=None, theVars=optVars):
    if outname == None:
        outname = filename
    newStart = open(filename).readlines()
    for tmpVar in theVars:
        compliment = tmpVar.replace('U', 'D')
        if optVar == tmpVar:
            theVal = newVal
        else:
            theVal = theVars[tmpVar]
        if (theVal >= 0):
            newStart = [re.sub('^{0} = [ ]*[-0-9\.]*'.format(tmpVar),
                               '{0} = {1:.3f}'.format(tmpVar, theVal), x) \
    parser.add_option("--NP", action="store_true", dest="NP", default=False, help="put NP on the plot")
    parser.add_option("--Err", dest="Err", default=-1.0, type="float", help="error band level")
    (opts, args) = parser.parse_args()

    import pyroot_logon

    config = __import__(opts.modeConfig)

    from ROOT import TFile, Double, Long, gROOT, TCanvas

    ## gROOT.ProcessLine('.L RooWjjFitterParams.h+');
    gROOT.ProcessLine(".L EffTableReader.cc+")
    gROOT.ProcessLine(".L EffTableLoader.cc+")
    gROOT.ProcessLine(".L RooWjjFitterUtils.cc+")
    gROOT.ProcessLine(".L RooWjjMjjFitter.cc+")
    from ROOT import RooWjjMjjFitter, RooFit, RooMsgService, RooArgList, RooArgSet
    from math import sqrt

    RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)

    fitterPars = config.theConfig(opts.Nj, opts.mcdir, opts.startingFile, opts.toydataFile)

    theFitter = RooWjjMjjFitter(fitterPars)

    theFitter.makeFitter(False)
    theFitter.loadData()

    theFitter.loadParameters(opts.startingFile)

    (frames, cans) = plot2BodyDist(theFitter, fitterPars, 0, 3, opts.Err, opts.NP)
Ejemplo n.º 5
0
    fitterPars.minMass = fitterPars.binEdges[0]
    fitterPars.minFit = fitterPars.minMass

if opts.lumi:
    fitterPars.intLumi = opts.lumi
    
if fitterPars.includeMuons and fitterPars.includeElectrons:
    modeString = ''
elif fitterPars.includeMuons:
    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)
Ejemplo n.º 6
0
config = __import__(opts.modeConfig)
from ROOT import TGraph, TF1, gPad, TFile, Double, Long, gROOT
## gROOT.ProcessLine('.L RooWjjFitterParams.h+');
gROOT.ProcessLine('.L EffTableReader.cc+')
gROOT.ProcessLine('.L EffTableLoader.cc+')
gROOT.ProcessLine('.L RooWjjFitterUtils.cc+')
gROOT.ProcessLine('.L RooWjjMjjFitter.cc+')
from ROOT import RooWjjMjjFitter, RooFitResult, \
     RooMsgService, RooFit

RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)
tmpInitFile = opts.startingFile

fitterPars = config.theConfig(opts.Nj, -100.0, -100.0, opts.mcdir, tmpInitFile,
                              opts.toydataFile)
theFitter = RooWjjMjjFitter(fitterPars)

Npts = 7


def optimizeVar(optVar, start, step, iteration, tryFit=True, theVars=optVars):

    global g_minFOM, minPoint

    optGraph = TGraph(Npts)
    optGraph.SetName('graph_{0}_{1}'.format(optVar, iteration))
    SetPoints = 0
    minFOM = 10000.
    minVal = 0.
    for point in range(0, Npts):
        newVal = start + step * point
#fitterPars.truncRange = True
if opts.ParamWpJ<0:
    fitterPars.smoothingOrder = 0
    

if fitterPars.includeMuons and fitterPars.includeElectrons:
    modeString = ''
elif fitterPars.includeMuons:
    modeString = 'Muon'
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)
if fitterPars.includeMuons and fitterPars.includeElectrons:
    modeString = ''
elif fitterPars.includeMuons:
    modeString = 'Muon'
elif fitterPars.includeElectrons:
    modeString = 'Electron'
else:
    modeString = ''

dibosonParameterize = 0
if opts.btag:
    dibosonParameterize = 2
    fitterPars.constrainWpJShape = True
    fitterPars.constrainDibosonShape = True

theFitter = RooWjjMjjFitter(fitterPars)

theFitter.makeDibosonPdf(dibosonParameterize)
theFitter.makeFitter((opts.ParamWpJ>=0))

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

# chi2 = Double(0.)
#ndf = Long(2)
extraNdf = 0
if not opts.btag:
    extraNdf = 2
## if (fitterPars.doNewPhysics):
##     extraNdf += 1
## if not fitterPars.constrainDiboson:
from math import sqrt


RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)

fitterPars = config.theConfig(opts.Nj, opts.mcdir, opts.startingFile, opts.toydataFile, opts.TTbarMUSUsystopt, opts.e_minT, opts.e_maxT)
if fitterPars.includeMuons and fitterPars.includeElectrons:
    modeString = ''
elif fitterPars.includeMuons:
    modeString = 'Muon'
elif fitterPars.includeElectrons:
    modeString = 'Electron'
else:
    modeString = ''

theFitter = RooWjjMjjFitter(fitterPars)

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"
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)
Ejemplo n.º 11
0
                      help='error band level')
    (opts, args) = parser.parse_args()

    import pyroot_logon
    config = __import__(opts.modeConfig)

    from ROOT import TFile, Double, Long, gROOT, TCanvas
    ## gROOT.ProcessLine('.L RooWjjFitterParams.h+');
    gROOT.ProcessLine('.L EffTableReader.cc+')
    gROOT.ProcessLine('.L EffTableLoader.cc+')
    gROOT.ProcessLine('.L RooWjjFitterUtils.cc+')
    gROOT.ProcessLine('.L RooWjjMjjFitter.cc+')
    from ROOT import RooWjjMjjFitter, RooFit, \
         RooMsgService, RooArgList, RooArgSet
    from math import sqrt

    RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)

    fitterPars = config.theConfig(opts.Nj, opts.mcdir, opts.startingFile,
                                  opts.toydataFile )

    theFitter = RooWjjMjjFitter(fitterPars)

    theFitter.makeFitter(False)
    theFitter.loadData()

    theFitter.loadParameters(opts.startingFile)

    (frames, cans) = plot2BodyDist(theFitter, fitterPars,
                                   0, 3, opts.Err, opts.NP)
Ejemplo n.º 12
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)