def the4BodyConfig(twoBodyConfig, mH=400, syst=0):
    ##     fitterPars = theConfig(Nj, mcdir, initFile)
    optPars = getOptimalPars(mH, optimalPars2)
    minMlvjj = optPars[1]
    maxMlvjj = optPars[2]

    alpha = optPars[4 + syst]

    print 'alpha:', alpha
    lowSideBand = optPars[7]
    highSideBand = optPars[8]

    fitterPars = RooWjjFitterParams(twoBodyConfig)
    fitterPars.binEdges.clear()
    fitterPars.smoothingOrder = 1
    fitterPars.smoothWpJ = 0
    fitterPars.do4body = True
    twoBCut = fitterPars.cuts
    print twoBCut
    if len(fitterPars.cuts) > 0:
        fitterPars.cuts += " && "
    fitterPars.cuts += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minTrunc, fitterPars.var,
        fitterPars.maxTrunc)

    fitterPars.minSBHi = highSideBand[0]
    fitterPars.maxSBHi = highSideBand[1]
    fitterPars.SBHicut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBHicut += " && "
    fitterPars.SBHicut += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minSBHi, fitterPars.var, fitterPars.maxSBHi)
    print 'SBHicut', fitterPars.SBHicut

    fitterPars.minSBLo = lowSideBand[0]
    fitterPars.maxSBLo = lowSideBand[1]
    fitterPars.SBLocut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBLocut += " && "
    fitterPars.SBLocut += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minSBLo, fitterPars.var, fitterPars.maxSBLo)
    print 'SBLocut', fitterPars.SBLocut

    print 'minMlvjj:', minMlvjj, 'maxMlvjj', maxMlvjj
    fitterPars.var = 'fit_mlvjj'
    fitterPars.minMass = minMlvjj
    fitterPars.maxMass = maxMlvjj
    fitterPars.nbins = optPars[3]
    if (fitterPars.nbins < 8):
        fitterPars.nbins = int((fitterPars.maxMass-fitterPars.minMass)/10 + \
                               0.5)
    fitterPars.truncRange = False

    twoJets = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1.)]
    threeJets = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1.)]

    if fitterPars.njets == 3:
        ranges = threeJets
    else:
        ranges = twoJets

    for line in ranges:
        fitterPars.minMasses.push_back(line[0])
        fitterPars.maxMasses.push_back(line[1])
        fitterPars.alphas.push_back(line[2])
        fitterPars.falphas.push_back(line[3])


##         if len(line) > 1:
##             fitterPars.falphas.push_back(line[1])

    return fitterPars
def the4BodyConfig(twoBodyConfig, mH=400, syst=0):
##     fitterPars = theConfig(Nj, mcdir, initFile)
    optPars = getOptimalPars(mH, optimalPars2)
    minMlvjj = optPars[1]
    maxMlvjj = optPars[2]

    alpha = optPars[4+syst]

    print 'alpha:',alpha
    lowSideBand = optPars[7]
    highSideBand = optPars[8]

    fitterPars = RooWjjFitterParams(twoBodyConfig)
    fitterPars.binEdges.clear()
    fitterPars.smoothingOrder = 1
    fitterPars.smoothWpJ = 0
    fitterPars.do4body = True
    twoBCut = fitterPars.cuts
    print twoBCut
    if len(fitterPars.cuts) > 0:
        fitterPars.cuts += " && "
    fitterPars.cuts += '((%s > %f) && (%s < %f))' % (fitterPars.var,
                                                     fitterPars.minTrunc,
                                                     fitterPars.var,
                                                     fitterPars.maxTrunc)

    fitterPars.minSBHi = highSideBand[0]
    fitterPars.maxSBHi = highSideBand[1]
    fitterPars.SBHicut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBHicut += " && "
    fitterPars.SBHicut += '((%s > %f) && (%s < %f))' % (fitterPars.var,
                                                        fitterPars.minSBHi,
                                                        fitterPars.var,
                                                        fitterPars.maxSBHi)
    print 'SBHicut',fitterPars.SBHicut
    
    fitterPars.minSBLo = lowSideBand[0]
    fitterPars.maxSBLo = lowSideBand[1]
    fitterPars.SBLocut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBLocut += " && "
    fitterPars.SBLocut += '((%s > %f) && (%s < %f))' % (fitterPars.var,
                                                        fitterPars.minSBLo,
                                                        fitterPars.var,
                                                        fitterPars.maxSBLo)
    print 'SBLocut',fitterPars.SBLocut

    print 'minMlvjj:',minMlvjj,'maxMlvjj',maxMlvjj
    fitterPars.var = 'fit_mlvjj'
    fitterPars.minMass = minMlvjj
    fitterPars.maxMass = maxMlvjj
    fitterPars.nbins = optPars[3]
    if (fitterPars.nbins < 8):
        fitterPars.nbins = int((fitterPars.maxMass-fitterPars.minMass)/10 + \
                               0.5)
    fitterPars.truncRange = False


    twoJets = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1.)]
    threeJets = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1.)]

    if fitterPars.njets == 3:
        ranges = threeJets
    else:
        ranges = twoJets

    for line in ranges:
        fitterPars.minMasses.push_back(line[0])
        fitterPars.maxMasses.push_back(line[1])
        fitterPars.alphas.push_back(line[2])
        fitterPars.falphas.push_back(line[3])
##         if len(line) > 1:
##             fitterPars.falphas.push_back(line[1])

    return fitterPars
def the4BodyConfig(twoBodyConfig, alpha=1.0, lowSideBand=(55.0, 65.0), highSideBand=(95.0, 115), alphaRange=(0.0, 1.0)):
    ##     fitterPars = theConfig(Nj, mcdir, initFile)

    fitterPars = RooWjjFitterParams(twoBodyConfig)
    fitterPars.binEdges.clear()
    fitterPars.smoothingOrder = 1
    fitterPars.smoothWpJ = 0
    fitterPars.do4body = True
    twoBCut = fitterPars.cuts
    print twoBCut
    if len(fitterPars.cuts) > 0:
        fitterPars.cuts += " && "
    fitterPars.cuts += "((%s > %f) && (%s < %f))" % (
        fitterPars.var,
        fitterPars.minTrunc,
        fitterPars.var,
        fitterPars.maxTrunc,
    )

    fitterPars.minSBHi = highSideBand[0]
    fitterPars.maxSBHi = highSideBand[1]
    fitterPars.SBHicut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBHicut += " && "
    fitterPars.SBHicut += "((%s > %f) && (%s < %f))" % (
        fitterPars.var,
        fitterPars.minSBHi,
        fitterPars.var,
        fitterPars.maxSBHi,
    )
    print "SBHicut", fitterPars.SBHicut

    fitterPars.minSBLo = lowSideBand[0]
    fitterPars.maxSBLo = lowSideBand[1]
    fitterPars.SBLocut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBLocut += " && "
    fitterPars.SBLocut += "((%s > %f) && (%s < %f))" % (
        fitterPars.var,
        fitterPars.minSBLo,
        fitterPars.var,
        fitterPars.maxSBLo,
    )
    print "SBLocut", fitterPars.SBLocut

    print "minMlvjj:", minMlvjj, "maxMlvjj", maxMlvjj
    fitterPars.var = "fit_mlvjj"
    fitterPars.minMass = minMlvjj
    fitterPars.maxMass = maxMlvjj
    fitterPars.nbins = int((fitterPars.maxMass - fitterPars.minMass) / 40 + 0.5)
    if fitterPars.nbins < 8:
        fitterPars.nbins = int((fitterPars.maxMass - fitterPars.minMass) / 10 + 0.5)
    fitterPars.truncRange = False

    ranges = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1.0, alphaRange)]

    for line in ranges:
        fitterPars.minMasses.push_back(line[0])
        fitterPars.maxMasses.push_back(line[1])
        fitterPars.alphas.push_back(line[2])
        fitterPars.falphas.push_back(line[3])
        fitterPars.alphaDowns.push_back(line[4][0])
        fitterPars.alphaUps.push_back(line[4][1])
    ##         if len(line) > 1:
    ##             fitterPars.falphas.push_back(line[1])

    return fitterPars
def the4BodyConfig(twoBodyConfig,
                   alpha=1.,
                   lowSideBand=(55., 65.),
                   highSideBand=(95., 115),
                   alphaRange=(0., 1.)):
    ##     fitterPars = theConfig(Nj, mcdir, initFile)

    fitterPars = RooWjjFitterParams(twoBodyConfig)
    fitterPars.binEdges.clear()
    fitterPars.smoothingOrder = 1
    fitterPars.smoothWpJ = 0
    fitterPars.do4body = True
    twoBCut = fitterPars.cuts
    print twoBCut
    if len(fitterPars.cuts) > 0:
        fitterPars.cuts += " && "
    fitterPars.cuts += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minTrunc, fitterPars.var,
        fitterPars.maxTrunc)

    fitterPars.minSBHi = highSideBand[0]
    fitterPars.maxSBHi = highSideBand[1]
    fitterPars.SBHicut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBHicut += " && "
    fitterPars.SBHicut += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minSBHi, fitterPars.var, fitterPars.maxSBHi)
    print 'SBHicut', fitterPars.SBHicut

    fitterPars.minSBLo = lowSideBand[0]
    fitterPars.maxSBLo = lowSideBand[1]
    fitterPars.SBLocut = twoBCut
    if len(twoBCut) > 0:
        fitterPars.SBLocut += " && "
    fitterPars.SBLocut += '((%s > %f) && (%s < %f))' % (
        fitterPars.var, fitterPars.minSBLo, fitterPars.var, fitterPars.maxSBLo)
    print 'SBLocut', fitterPars.SBLocut

    print 'minMlvjj:', minMlvjj, 'maxMlvjj', maxMlvjj
    fitterPars.var = 'vbf_lvjj_m'
    fitterPars.minMass = minMlvjj
    fitterPars.maxMass = maxMlvjj
    fitterPars.nbins = int((fitterPars.maxMass - fitterPars.minMass) / 40 +
                           0.5)
    if (fitterPars.nbins < 8):
        fitterPars.nbins = int((fitterPars.maxMass-fitterPars.minMass)/10 + \
                               0.5)
    fitterPars.truncRange = False

    ranges = [(fitterPars.minMass, fitterPars.maxMass, alpha, 1., alphaRange)]

    for line in ranges:
        fitterPars.minMasses.push_back(line[0])
        fitterPars.maxMasses.push_back(line[1])
        fitterPars.alphas.push_back(line[2])
        fitterPars.falphas.push_back(line[3])
        fitterPars.alphaDowns.push_back(line[4][0])
        fitterPars.alphaUps.push_back(line[4][1])


##         if len(line) > 1:
##             fitterPars.falphas.push_back(line[1])

    return fitterPars