def theConfig(Nj, mcdir="", initFile=""):
    fitterPars = RooWjjFitterParams()
    fitterPars.MCDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.WpJDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    if len(mcdir) > 0:
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewReducedQCDTrees/"
    fitterPars.DataDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.NewPhysicsDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.muonData = "WmunuJets_DataAll_GoldenJSON_2p1invfb.root"
    fitterPars.electronData = "WenuJets_DataAll_GoldenJSON_2p1invfb_SinglE_EleH.root"

    fitterPars.initParamsFile = initFile

    fitterPars.minMass = 60.0
    fitterPars.maxMass = 300.0
    fitterPars.nbins = 24
    fitterPars.truncRange = True
    fitterPars.minTrunc = 130.0
    fitterPars.maxTrunc = 170.0
    fitterPars.njets = Nj

    fitterPars.cuts = (
        "(W_mt > 50.) "
        + "&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) "
        + "&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) "
        + "&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) "
        + "&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) "
    )

    return fitterPars
Ejemplo n.º 2
0
def theConfig(Nj, mcdir='', initFile=''):
    fitterPars = RooWjjFitterParams()
    fitterPars.MCDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.WpJDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewReducedQCDTrees/"
    fitterPars.DataDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.NewPhysicsDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_2p1invfb.root'
    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_2p1invfb_SinglE_EleH.root'

    fitterPars.initParamsFile = initFile

    fitterPars.minMass = 60.
    fitterPars.maxMass = 300.
    fitterPars.nbins = 24
    fitterPars.truncRange = True
    fitterPars.minTrunc = 130.
    fitterPars.maxTrunc = 170.
    fitterPars.njets = Nj

    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) '

    return fitterPars
def theConfig(Nj, mcdir = '', initFile = ''):
    fitterPars = RooWjjFitterParams()
    fitterPars.MCDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.WpJDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewReducedQCDTrees/"
    fitterPars.DataDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.NewPhysicsDirectory = "root://cmssrv32.fnal.gov//store/user/lnujj/WjjTrees/NewKfitRDTree/RD_"
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_2p1invfb.root'
    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_2p1invfb_SinglE_EleH.root'

    fitterPars.initParamsFile = initFile

    fitterPars.minMass = 50.
    fitterPars.maxMass = 120.
    fitterPars.nbins = 14
    fitterPars.truncRange = True
    fitterPars.minTrunc = 65.
    fitterPars.maxTrunc = 95.
    fitterPars.njets = Nj

    return fitterPars
def theConfig(Nj, e_FSU, e_FMU, mcdir = '', initFile = '', toydataFile = ''):
    fitterPars = RooWjjFitterParams()
    fitterPars.MCDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.WpJDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = '/uscms_data/d1/kalanand/WjjTrees/NewReducedQCDTrees/'
    fitterPars.initParamsFile = initFile
    # fitterPars.constraintParamsFile = "HWWConstraints2Jets.txt";
    fitterPars.DataDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_2p1invfb.root'
    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_2p1invfb_SinglE_EleH.root'
    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.fitToyDataset = False
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile
    fitterPars.minMass = 60.
    fitterPars.maxMass = 300.
    fitterPars.nbins = 24
    fitterPars.truncRange = True
    fitterPars.minTrunc = 130.
    fitterPars.maxTrunc = 170.
    fitterPars.njets = Nj

    fitterPars.useExternalMorphingPars = True
    fitterPars.e_fSU = e_FSU
    fitterPars.e_fMU = e_FMU
       
    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) '

    return fitterPars
def theConfig(Nj, e_FSU, e_FMU, mcdir = '', initFile = '', toydataFile = ''):
    fitterPars = RooWjjFitterParams()
    fitterPars.MCDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.WpJDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = '/uscms_data/d1/kalanand/WjjTrees/NewReducedQCDTrees/'
    fitterPars.initParamsFile = initFile
    # fitterPars.constraintParamsFile = "HWWConstraints2Jets.txt";
    fitterPars.DataDirectory = '/uscms_data/d1/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_2p1invfb.root'
    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_2p1invfb_SinglE_EleH.root'
    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.fitToyDataset = True
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile
    fitterPars.minMass = 60.
    fitterPars.maxMass = 300.
    fitterPars.nbins = 24
    fitterPars.truncRange = True
    fitterPars.minTrunc = 130.
    fitterPars.maxTrunc = 170.
    fitterPars.njets = Nj

    fitterPars.useExternalMorphingPars = False
    fitterPars.e_fSU = e_FSU
    fitterPars.e_fMU = e_FMU
       
    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) '

    return fitterPars
def theConfig(Nj, mcdir='', initFile='', mH=400):
    optPars = getOptimalPars(mH, optimalPars2)
    minMlvjj = optPars[1]
    maxMlvjj = optPars[2]
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/RD_"
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    fitterPars.QCDDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/"
    fitterPars.initParamsFile = initFile
    # fitterPars.constraintParamsFile = "HWWConstraints2Jets.txt";
    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = False

    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.minMass = 40.
    fitterPars.maxMass = 200.
    fitterPars.nbins = 30
    fitterPars.intLumi = 4700.

    fitterPars.binEdges.push_back(fitterPars.minMass)
    #fitterPars.binEdges.push_back(40.)
    fitterPars.binEdges.push_back(45.)
    fitterPars.binEdges.push_back(50.)
    fitterPars.binEdges.push_back(55.)
    fitterPars.binEdges.push_back(60.)
    fitterPars.binEdges.push_back(65.)
    fitterPars.binEdges.push_back(70.)
    fitterPars.binEdges.push_back(75.)
    fitterPars.binEdges.push_back(80.)
    fitterPars.binEdges.push_back(85.)
    fitterPars.binEdges.push_back(95.)
    fitterPars.binEdges.push_back(105.)
    fitterPars.binEdges.push_back(115.)
    fitterPars.binEdges.push_back(125.)
    fitterPars.binEdges.push_back(135.)
    fitterPars.binEdges.push_back(145.)
    fitterPars.binEdges.push_back(160.)
    fitterPars.binEdges.push_back(175.)
    fitterPars.binEdges.push_back(200.)

    ##     binEdge = fitterPars.minMass
    ##     print binEdge,' ',
    ##     while (binEdge <= fitterPars.maxMass):
    ##         binEdge += round(0.14*binEdge)
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass

    print "mass range:", fitterPars.minMass, '-', fitterPars.maxMass

    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:', fitterPars.minFit, '-', fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back(
        "EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back(
        "EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back(
        "EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.constrainDiboson = True
    fitterPars.useExternalMorphingPars = False

    jetCut = '(ggdevt == %i)' % (Nj)
    if (Nj < 2):
        jetCut = '((ggdevt == 2) || (ggdevt == 3))'

    fitterPars.cuts = '(fit_status==0) ' + \
                      '&& %s ' % (jetCut) + \
                      '&& (fit_mlvjj > %0.1f) && (fit_mlvjj < %0.1f) ' % \
                      (minMlvjj, maxMlvjj)

    return fitterPars
Ejemplo n.º 7
0
def theConfig(Nj, mcdir='', initFile='', toydataFile=''):
    fitterPars = RooWjjFitterParams()

    fitterPars.MCDirectory = '/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/RD_'
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = '/uscms_data/d2/kalanand/WjjTrees/NewReducedQCDTrees/'
    fitterPars.initParamsFile = initFile

    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = False
    ##    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_4p7invfb.root'
    ##     fitterPars.electronData = 'SingleEleAndEleTwoPFJetTrigger.root'
    fitterPars.electronData = 'EleTwoCaloJetTrigger.root'
    fitterPars.includeElectrons = True

    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'

    fitterPars.fitToyDataset = False
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile

    fitterPars.minMass = 30.
    fitterPars.maxMass = 400.
    fitterPars.nbins = 34
    fitterPars.intLumi = 3819.994

    fitterPars.binEdges.push_back(fitterPars.minMass)

    binEdge = fitterPars.minMass
    print binEdge, ' ',
    while (binEdge <= fitterPars.maxMass):
        binEdge += round(0.15 * binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge, ' ',

    fitterPars.binEdges[fitterPars.binEdges.size() - 1] = fitterPars.maxMass
    ##     fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size()-1]

    print "mass range:", fitterPars.minMass, '-', fitterPars.maxMass

    fitterPars.truncRange = True
    fitterPars.blind = True
    fitterPars.minTrunc = 130.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 170.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = 60.
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = 400.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:', fitterPars.minFit, '-', fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back(
        "EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back(
        "EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    #### Add the information for Electron each epoch ####
    #### Epoch Luminosities are 215.274+664.732=880.006, 927.947, 323.164, 412.359, 246.527, 1909.9970 (Sum Lumi = 4700).
    ##     ## Epochs 1+7
    ##     fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    ##     fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    ##     fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    ##     fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    ##     fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    ##     fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    ##     fitterPars.lumiPerEpochElectron.push_back(880.006)
    ## Epoch 2
    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v4-PFEE-EleJets.txt"
    )
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v4-PFEE-EleJets.txt"
    )
    fitterPars.eleMHTEffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(927.947)
    ## Epoch 3
    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_05Aug2011ReReco-v1-2E33.txt"
    )
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_05Aug2011ReReco-v1-2E33.txt"
    )
    fitterPars.eleMHTEffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(323.164)
    ## Epoch 4
    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v6-2E33.txt"
    )
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v6-2E33.txt"
    )
    fitterPars.eleMHTEffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(412.359)
    ## Epoch 5
    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v6-3E33.txt"
    )
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v6-3E33.txt"
    )
    fitterPars.eleMHTEffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(246.527)
    ## Epoch 6
    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_post-epsCaloLWA.txt"
    )
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_post-epsCaloLWA.txt"
    )
    fitterPars.eleMHTEffFiles.push_back(
        "EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(1909.9970)

    fitterPars.useExternalMorphingPars = False

    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) ' + \
                      '&& (JetPFCor_Pt[0] > 40) '

    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 theConfig(Nj, mcdir="", initFile=""):
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    # fitterPars.MCDirectory = "root://cmseos.fnal.gov:1094//eos/uscms/store/user/lnujj/HCP2012METfix/ReducedTrees/RD_"
    fitterPars.MCDirectory = "/uscms_data/d1/andersj/Wjj/2012/data/ReducedTrees/RD_"

    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if len(mcdir) > 0:
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    # fitterPars.QCDDirectory = 'root://cmseos:1094//eos/uscms/store/user/lnujj/2012_RDTrees_PAT/'
    fitterPars.initParamsFile = initFile
    # fitterPars.constraintParamsFile = "HWWConstraints2Jets.txt";
    fitterPars.DataDirectory = fitterPars.MCDirectory
    # fitterPars.DataDirectory = "/uscms_data/d1/andersj/Wjj/2012/data/ICHEP2012/ReducedTrees/RD_"
    # fitterPars.muonData = 'SingleMu_0p56fb_Golden.root'
    # fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_5p1invfb.root'
    fitterPars.muonData = "WmunuJets_DataAll_GoldenJSON_12p0invfb.root"
    fitterPars.includeMuons = True
    # fitterPars.electronData = 'WenuJets_DataSingleElectron_GoldenJSON_2012_xxpxinvfb.root'
    # fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_5p1invfb.root'
    fitterPars.electronData = "WenuJets_DataAllSingleElectronTrigger_GoldenJSON_11p9invfb.root"
    fitterPars.includeElectrons = True

    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.minMass = 45.0
    # fitterPars.minMass = 50.
    fitterPars.maxMass = 200.0
    fitterPars.nbins = 17
    fitterPars.intLumi = 12000
    # fitterPars.intLumi = 3500.
    # fitterPars.intLumi = 539.385+21.297
    # fitterPars.intLumi = 297.848+21.297+48.465

    fitterPars.binEdges.push_back(fitterPars.minMass)
    # fitterPars.binEdges.push_back(40.)
    # fitterPars.binEdges.push_back(45.)
    fitterPars.binEdges.push_back(50.0)
    fitterPars.binEdges.push_back(55.0)
    fitterPars.binEdges.push_back(60.0)
    fitterPars.binEdges.push_back(65.0)
    fitterPars.binEdges.push_back(70.0)
    fitterPars.binEdges.push_back(75.0)
    fitterPars.binEdges.push_back(80.0)
    fitterPars.binEdges.push_back(85.0)
    fitterPars.binEdges.push_back(95.0)
    fitterPars.binEdges.push_back(105.0)
    fitterPars.binEdges.push_back(115.0)
    fitterPars.binEdges.push_back(125.0)
    fitterPars.binEdges.push_back(135.0)
    fitterPars.binEdges.push_back(145.0)
    fitterPars.binEdges.push_back(160.0)
    fitterPars.binEdges.push_back(175.0)
    fitterPars.binEdges.push_back(200.0)

    ##     binEdge = fitterPars.minMass
    ##     print binEdge,' ',
    ##     while (binEdge <= fitterPars.maxMass):
    ##         binEdge += round(0.14*binEdge)
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass

    print "mass range:", fitterPars.minMass, "-", fitterPars.maxMass

    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 65.0

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.0
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc

    print "truncate:", fitterPars.truncRange, ":", fitterPars.minTrunc, "-", fitterPars.maxTrunc
    print "fit range:", fitterPars.minFit, "-", fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True
    fitterPars.externalConstraints = False

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTable2012/scaleFactor-Run2012ABC-RecoToIso.txt")
    fitterPars.muHLTEffFiles.push_back("EffTable2012/efficiency-Run2012ABC-IsoToIsoMuHLT.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    fitterPars.eleIdEffFiles.push_back("EffTable2012/scaleFactor-Run2012ABC-GsfElectronToId.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTable2012/scaleFactor-Run2012ABC-SCToElectron.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTable2012/efficiency-Run2012ABC-WP80ToHLTEle.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.constrainDiboson = True
    fitterPars.useExternalMorphingPars = False

    jetCut = "(ggdevt == %i)" % (Nj)
    if Nj < 2:
        jetCut = "((ggdevt == 2) || (ggdevt == 3))"

    fitterPars.cuts = "(fit_status==0) " + "&& %s " % (jetCut) + "&& (W_mt > 30) "

    return fitterPars
def theConfig(Nj, mcdir='', initFile=''):
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_VBF/RD_"
    ##     fitterPars.WpJDirectory = str(fitterPars.MCDirectory).replace("PAT", "AOD")
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.initParamsFile = initFile
    fitterPars.constraintParamsFile = initFile
    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True
    fitterPars.overwriteDibosonPDFWithVBFWW = True

    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.minMass = 40.
    fitterPars.maxMass = 200.
    fitterPars.nbins = 30
    fitterPars.intLumi = 5020.

    fitterPars.binEdges.push_back(fitterPars.minMass)
    #fitterPars.binEdges.push_back(40.)
    fitterPars.binEdges.push_back(45.)
    fitterPars.binEdges.push_back(50.)
    fitterPars.binEdges.push_back(55.)
    fitterPars.binEdges.push_back(60.)
    fitterPars.binEdges.push_back(65.)
    fitterPars.binEdges.push_back(70.)
    fitterPars.binEdges.push_back(75.)
    fitterPars.binEdges.push_back(80.)
    fitterPars.binEdges.push_back(85.)
    fitterPars.binEdges.push_back(95.)
    fitterPars.binEdges.push_back(105.)
    fitterPars.binEdges.push_back(115.)
    fitterPars.binEdges.push_back(125.)
    fitterPars.binEdges.push_back(135.)
    fitterPars.binEdges.push_back(145.)
    fitterPars.binEdges.push_back(160.)
    fitterPars.binEdges.push_back(175.)
    fitterPars.binEdges.push_back(200.)

    ##     binEdge = fitterPars.minMass
    ##     print binEdge,' ',
    ##     while (binEdge <= fitterPars.maxMass):
    ##         binEdge += round(0.14*binEdge)
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass

    print "mass range:", fitterPars.minMass, '-', fitterPars.maxMass

    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:', fitterPars.minFit, '-', fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back(
        "EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back(
        "EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back(
        "EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.constrainDiboson = True
    fitterPars.useExternalMorphingPars = False

    fitterPars.var = "vbf_wjj_m"

    fitterPars.cuts = '(vbf_event==1) ' + \
        '&& (JetPFCor_bDiscriminator[vbf_waj_id] < 1.74) ' + \
        '&& (JetPFCor_bDiscriminator[vbf_wbj_id] < 1.74) ' + \
        '&& (vbf_lvjj_m > %0.1f) && (vbf_lvjj_m < %0.1f) ' % \
        (minMlvjj, maxMlvjj)

    return fitterPars
def theConfig(Nj, mcdir = '', initFile = '', toydataFile = ''):
    fitterPars = RooWjjFitterParams()

    fitterPars.MCDirectory = '/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/RD_'
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = '/uscms_data/d2/kalanand/WjjTrees/NewReducedQCDTrees/'
    fitterPars.initParamsFile = initFile

    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = False
##    fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_4p7invfb.root'
##     fitterPars.electronData = 'SingleEleAndEleTwoPFJetTrigger.root'
    fitterPars.electronData = 'EleTwoCaloJetTrigger.root'
    fitterPars.includeElectrons = True

    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'

    fitterPars.fitToyDataset = False
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile

    fitterPars.minMass = 30.
    fitterPars.maxMass = 400.
    fitterPars.nbins = 34
    fitterPars.intLumi = 3819.994

    fitterPars.binEdges.push_back(fitterPars.minMass)

    binEdge = fitterPars.minMass
    print binEdge,' ',
    while (binEdge <= fitterPars.maxMass):
        binEdge += round(0.15*binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge,' ',

    fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass
##     fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size()-1]
    
    print "mass range:",fitterPars.minMass,'-',fitterPars.maxMass
    
    fitterPars.truncRange = True
    fitterPars.blind = True
    fitterPars.minTrunc = 130.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 170.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = 60.
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = 400.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:',fitterPars.minFit,'-',fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back("EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

#### Add the information for Electron each epoch ####
#### Epoch Luminosities are 215.274+664.732=880.006, 927.947, 323.164, 412.359, 246.527, 1909.9970 (Sum Lumi = 4700).
##     ## Epochs 1+7
##     fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
##     fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
##     fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
##     fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
##     fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
##     fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
##     fitterPars.lumiPerEpochElectron.push_back(880.006)
    ## Epoch 2
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v4-PFEE-EleJets.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v4-PFEE-EleJets.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(927.947)
    ## Epoch 3
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_05Aug2011ReReco-v1-2E33.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_05Aug2011ReReco-v1-2E33.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(323.164)
    ## Epoch 4
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v6-2E33.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v6-2E33.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(412.359)
    ## Epoch 5
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_PromptReco-v6-3E33.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_PromptReco-v6-3E33.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(246.527)
    ## Epoch 6
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsWP80ToHLTEle27_May10ReReco.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_post-epsCaloLWA.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_post-epsCaloLWA.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    fitterPars.lumiPerEpochElectron.push_back(1909.9970)



    fitterPars.useExternalMorphingPars = False
       
    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) ' + \
                      '&& (JetPFCor_Pt[0] > 40) '

    return fitterPars
def theConfig(Nj, mcdir = '', initFile = '', toydataFile = '', implementTTbarScaleMatchingSystOption = 0, e_minT = -1.0, e_maxT = -1.0):
    fitterPars = RooWjjFitterParams()

    fitterPars.smoothingOrder = 0
    fitterPars.MCDirectory = '/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_AOD/RD_'
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.initParamsFile = initFile

    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
##     fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True

##     fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.fitToyDataset = False
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile
    fitterPars.implementTTbarScaleMatchingSystOption = implementTTbarScaleMatchingSystOption

    fitterPars.minMass = 30.
    fitterPars.maxMass = 400.
    fitterPars.nbins = 34
    fitterPars.intLumi = 5020.

    fitterPars.binEdges.push_back(fitterPars.minMass)

    binEdge = fitterPars.minMass
    print binEdge,' ',

## ### Scan between Min=120-140 (Max=160-180)
##     while (binEdge < 120.0):
##         binEdge += round(0.15*binEdge)
##         fitterPars.binEdges.push_back(binEdge)
##         print binEdge,' ',

##     binEdge=120;
##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
##     print 'replaced with ',binEdge,' '

##     while (binEdge < 140.0):
##         binEdge += 2.0
##         fitterPars.binEdges.push_back(binEdge)
##         print binEdge,' ',

##     binEdge=140;
##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
##     print 'replaced with ', binEdge,' ',

##     binEdge=160;
##     fitterPars.binEdges.push_back(binEdge)
##     print binEdge,' ',
    
##     while (binEdge < 182.0):
##         binEdge += 2.0
##         fitterPars.binEdges.push_back(binEdge)
##         print binEdge,' ',

##     binEdge=182;
##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
##     print 'replaced with ',binEdge,' ',
    
    while (binEdge <= fitterPars.maxMass):
        binEdge += round(0.15*binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge,' ',




    fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass
##     fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size()-1]
    
    print "mass range:",fitterPars.minMass,'-',fitterPars.maxMass
    
    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 130.
    if e_minT>0:
        fitterPars.minTrunc = e_minT

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 170.
    if e_maxT>0:
        fitterPars.maxTrunc = e_maxT
    
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = 60.
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = 400.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:',fitterPars.minFit,'-',fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back("EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back("EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

##     fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
##     fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
##     fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_Ele.txt")
##     fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_post-epsCaloLWA.txt")
##     fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_post-epsCaloLWA.txt")
##     fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
##     fitterPars.lumiPerEpochElectron.push_back(3700)

    fitterPars.useExternalMorphingPars = False

    jetCut = '(evtNJ == %i)' % (Nj)
    if (Nj < 2):
        jetCut = '((evtNJ == 2) || (evtNJ == 3))'
       
    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& %s ' % (jetCut) + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) ' + \
                      '&& (JetPFCor_Pt[0] > 40) '

    return fitterPars
Ejemplo n.º 13
0
def theConfig(Nj, mcdir='', initFile='', btag=False, toydataFile=""):
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    # fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_PAT/RD_"
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/OriginalTree_PAT/"
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    ##fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.QCDDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_PAT/"

    fitterPars.initParamsFile = initFile
    fitterPars.constraintParamsFile = initFile
    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True
    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.toydataFile = toydataFile

    fitterPars.minMass = 40.
    fitterPars.maxMass = 150.
    fitterPars.nbins = 32
    fitterPars.intLumi = 5020.

    binEdge = fitterPars.minMass
    fitterPars.binEdges.push_back(binEdge)
    print binEdge, ' ',
    while (binEdge < fitterPars.maxMass):
        binEdge += round(0.10 * binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge, ' ',

##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass
    fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size() - 1]

    print "mass range:", fitterPars.minMass, '-', fitterPars.maxMass

    fitterPars.truncRange = False
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:', fitterPars.minFit, '-', fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = False
    fitterPars.constrainDibosonShape = False
    fitterPars.constrainWpJShape = False
    fitterPars.constrainWpJ = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back(
        "EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back(
        "EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back(
        "EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.useExternalMorphingPars = False

    ##     jetCut = '(jetPFCor_Pt[%i] < 2) ' % (Nj)
    ##     for j in range(0, Nj):
    ##         jetCut += '&& (JetPFCor_Pt[%i] > 30) ' % (j)
    ##    jetCut = '(ggdevt == %i)' % (Nj)
    ##     if (Nj < 2):
    ##         jetCut = '((ggdevt == 2) || (ggdevt == 3))'

    btagCut = 1.74

    fitterPars.cuts = '(sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>20.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.5) ' + \
                      '&& (abs(JetPFCor_dphiMET[0])>0.4) '
    fitterPars.cuts += '&& (JetPFCor_Pt[2]<30) '
    #fitterPars.cuts += '&& (fit_status==0) '

    if btag:
        fitterPars.useWbbPDF = False
        fitterPars.cuts += '&& ( (JetPFCor_bDiscriminator[0]>%.2f) || (JetPFCor_bDiscriminator[1]>%.2f) ) ' % (
            btagCut, btagCut)
        fitterPars.cuts += '&& (JetPFCor_Pt[1]>35) '
    else:
        fitterPars.useWbbPDF = False
        fitterPars.cuts += '&& (JetPFCor_bDiscriminator[0]<%.2f) && (JetPFCor_bDiscriminator[1]<%.2f) ' % (
            btagCut, btagCut)
        fitterPars.cuts += '&& (JetPFCor_Pt[1]>35.) '

    return fitterPars
def theConfig(Nj,
              mcdir='',
              initFile='',
              toydataFile='',
              implementTTbarScaleMatchingSystOption=0,
              e_minT=-1.0,
              e_maxT=-1.0):
    fitterPars = RooWjjFitterParams()

    fitterPars.smoothingOrder = 0
    fitterPars.MCDirectory = '/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_AOD/RD_'
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = True
    fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.initParamsFile = initFile

    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    ##     fitterPars.electronData = 'WenuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True

    ##     fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.fitToyDataset = False
    fitterPars.ToyDatasetDirectory = '/uscms_data/d1/ilyao/KinematicFitterS11/ErrorScans/1KMCSets/'
    fitterPars.toydataFile = toydataFile
    fitterPars.implementTTbarScaleMatchingSystOption = implementTTbarScaleMatchingSystOption

    fitterPars.minMass = 30.
    fitterPars.maxMass = 400.
    fitterPars.nbins = 34
    fitterPars.intLumi = 5020.

    fitterPars.binEdges.push_back(fitterPars.minMass)

    binEdge = fitterPars.minMass
    print binEdge, ' ',

    ## ### Scan between Min=120-140 (Max=160-180)
    ##     while (binEdge < 120.0):
    ##         binEdge += round(0.15*binEdge)
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     binEdge=120;
    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
    ##     print 'replaced with ',binEdge,' '

    ##     while (binEdge < 140.0):
    ##         binEdge += 2.0
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     binEdge=140;
    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
    ##     print 'replaced with ', binEdge,' ',

    ##     binEdge=160;
    ##     fitterPars.binEdges.push_back(binEdge)
    ##     print binEdge,' ',

    ##     while (binEdge < 182.0):
    ##         binEdge += 2.0
    ##         fitterPars.binEdges.push_back(binEdge)
    ##         print binEdge,' ',

    ##     binEdge=182;
    ##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = binEdge;
    ##     print 'replaced with ',binEdge,' ',

    while (binEdge <= fitterPars.maxMass):
        binEdge += round(0.15 * binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge, ' ',

    fitterPars.binEdges[fitterPars.binEdges.size() - 1] = fitterPars.maxMass
    ##     fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size()-1]

    print "mass range:", fitterPars.minMass, '-', fitterPars.maxMass

    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 130.
    if e_minT > 0:
        fitterPars.minTrunc = e_minT

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 170.
    if e_maxT > 0:
        fitterPars.maxTrunc = e_maxT

    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = 60.
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = 400.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break

    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:', fitterPars.minFit, '-', fitterPars.maxFit

    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back(
        "EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back(
        "EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    fitterPars.eleIdEffFiles.push_back(
        "EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back(
        "EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back(
        "EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back(
        "EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back(
        "EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    ##     fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    ##     fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    ##     fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_Ele.txt")
    ##     fitterPars.eleJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet30_FracLumi_post-epsCaloLWA.txt")
    ##     fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_Jet25Not30_FracLumi_post-epsCaloLWA.txt")
    ##     fitterPars.eleMHTEffFiles.push_back("EffTableDir/eleEffsHLTEle2jPfMht_data_LWA_PfMht.txt")
    ##     fitterPars.lumiPerEpochElectron.push_back(3700)

    fitterPars.useExternalMorphingPars = False

    jetCut = '(evtNJ == %i)' % (Nj)
    if (Nj < 2):
        jetCut = '((evtNJ == 2) || (evtNJ == 3))'

    fitterPars.cuts = '(W_mt > 50.) ' + \
                      '&& %s ' % (jetCut) + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.2) ' + \
                      '&& (sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>45.) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor>0.3) ' + \
                      '&& (JetPFCor_Pt[1]/Mass2j_PFCor<0.7) ' + \
                      '&& (JetPFCor_Pt[0] > 40) '

    return fitterPars
def theConfig(Nj, mcdir = '', initFile = ''):
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_VBF/RD_"
##     fitterPars.WpJDirectory = str(fitterPars.MCDirectory).replace("PAT", "AOD")
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.initParamsFile = initFile
    fitterPars.constraintParamsFile = initFile;
    fitterPars.DataDirectory = fitterPars.MCDirectory
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True    
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True
    fitterPars.overwriteDibosonPDFWithVBFWW = True
    
    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.minMass = 40.
    fitterPars.maxMass = 200.
    fitterPars.nbins = 30
    fitterPars.intLumi = 5020.
    
    fitterPars.binEdges.push_back(fitterPars.minMass)
    #fitterPars.binEdges.push_back(40.)
    fitterPars.binEdges.push_back(45.)
    fitterPars.binEdges.push_back(50.)
    fitterPars.binEdges.push_back(55.)
    fitterPars.binEdges.push_back(60.)
    fitterPars.binEdges.push_back(65.)
    fitterPars.binEdges.push_back(70.)
    fitterPars.binEdges.push_back(75.)
    fitterPars.binEdges.push_back(80.)
    fitterPars.binEdges.push_back(85.)
    fitterPars.binEdges.push_back(95.)
    fitterPars.binEdges.push_back(105.)
    fitterPars.binEdges.push_back(115.)
    fitterPars.binEdges.push_back(125.)
    fitterPars.binEdges.push_back(135.)
    fitterPars.binEdges.push_back(145.)
    fitterPars.binEdges.push_back(160.)
    fitterPars.binEdges.push_back(175.)
    fitterPars.binEdges.push_back(200.)

##     binEdge = fitterPars.minMass
##     print binEdge,' ',
##     while (binEdge <= fitterPars.maxMass):
##         binEdge += round(0.14*binEdge)
##         fitterPars.binEdges.push_back(binEdge)
##         print binEdge,' ',

##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass

    print "mass range:",fitterPars.minMass,'-',fitterPars.maxMass
    
    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break


    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc
    
    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:',fitterPars.minFit,'-',fitterPars.maxFit
    
    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    
    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back("EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back("EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.constrainDiboson = True
    fitterPars.useExternalMorphingPars = False

    fitterPars.var = "vbf_wjj_m"

    fitterPars.cuts = '(vbf_event==1) ' + \
        '&& (JetPFCor_bDiscriminator[vbf_waj_id] < 1.74) ' + \
        '&& (JetPFCor_bDiscriminator[vbf_wbj_id] < 1.74) ' + \
        '&& (vbf_lvjj_m > %0.1f) && (vbf_lvjj_m < %0.1f) ' % \
        (minMlvjj, maxMlvjj)

    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 theConfig(Nj, mcdir = '', initFile = '', btag = False, toydataFile=""):
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    # fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_PAT/RD_"
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/OriginalTree_PAT/"
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    ##fitterPars.QCDDirectory = fitterPars.MCDirectory[:-3]
    fitterPars.QCDDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree_PAT/"
        
    fitterPars.initParamsFile = initFile
    fitterPars.constraintParamsFile = initFile
    fitterPars.DataDirectory = fitterPars.MCDirectory 
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True    
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = True
    fitterPars.NewPhysicsDirectory = fitterPars.MCDirectory
    fitterPars.toydataFile = toydataFile
    
    fitterPars.minMass = 40.
    fitterPars.maxMass = 150.
    fitterPars.nbins = 32
    fitterPars.intLumi = 5020.
    
    binEdge = fitterPars.minMass
    fitterPars.binEdges.push_back(binEdge)
    print binEdge,' ',
    while (binEdge < fitterPars.maxMass):
        binEdge += round(0.10*binEdge)
        fitterPars.binEdges.push_back(binEdge)
        print binEdge,' ',

##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass
    fitterPars.maxMass = fitterPars.binEdges[fitterPars.binEdges.size()-1]

    print "mass range:",fitterPars.minMass,'-',fitterPars.maxMass
    
    fitterPars.truncRange = False
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break


    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc
    
    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:',fitterPars.minFit,'-',fitterPars.maxFit
    
    fitterPars.njets = Nj
    fitterPars.constrainDiboson = False
    fitterPars.constrainDibosonShape = False
    fitterPars.constrainWpJShape = False
    fitterPars.constrainWpJ = True

    
    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back("EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back("EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.useExternalMorphingPars = False

##     jetCut = '(jetPFCor_Pt[%i] < 2) ' % (Nj)
##     for j in range(0, Nj):
##         jetCut += '&& (JetPFCor_Pt[%i] > 30) ' % (j)
##    jetCut = '(ggdevt == %i)' % (Nj)
##     if (Nj < 2):
##         jetCut = '((ggdevt == 2) || (ggdevt == 3))'

    btagCut = 1.74

    fitterPars.cuts = '(sqrt(JetPFCor_Pt[0]**2+JetPFCor_Pt[1]**2+2*JetPFCor_Pt[0]*JetPFCor_Pt[1]*cos(JetPFCor_Phi[0]-JetPFCor_Phi[1]))>20.) ' + \
                      '&& (abs(JetPFCor_Eta[0]-JetPFCor_Eta[1])<1.5) ' + \
                      '&& (abs(JetPFCor_dphiMET[0])>0.4) '
    fitterPars.cuts += '&& (JetPFCor_Pt[2]<30) '
    #fitterPars.cuts += '&& (fit_status==0) '

    if btag:
        fitterPars.useWbbPDF = False
        fitterPars.cuts += '&& ( (JetPFCor_bDiscriminator[0]>%.2f) || (JetPFCor_bDiscriminator[1]>%.2f) ) ' % (btagCut,btagCut)
        fitterPars.cuts += '&& (JetPFCor_Pt[1]>35) '
    else:
        fitterPars.useWbbPDF = False
        fitterPars.cuts += '&& (JetPFCor_bDiscriminator[0]<%.2f) && (JetPFCor_bDiscriminator[1]<%.2f) ' % (btagCut,btagCut)
        fitterPars.cuts += '&& (JetPFCor_Pt[1]>35.) '

    return fitterPars
def theConfig(Nj, mcdir = '', initFile = '', mH = 400):
    optPars = getOptimalPars(mH, optimalPars2)
    minMlvjj = optPars[1]
    maxMlvjj = optPars[2]
    fitterPars = RooWjjFitterParams()
    fitterPars.smoothingOrder = 1
    fitterPars.MCDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/RD_"
    fitterPars.WpJDirectory = fitterPars.MCDirectory
    if (len(mcdir) > 0):
        fitterPars.WpJDirectory = mcdir
        fitterPars.toyWpJ = False
    fitterPars.QCDDirectory = "/uscms_data/d2/kalanand/WjjTrees/Full2011DataFall11MC/ReducedTree/"
    fitterPars.initParamsFile = initFile
    # fitterPars.constraintParamsFile = "HWWConstraints2Jets.txt";
    fitterPars.DataDirectory = fitterPars.MCDirectory 
    fitterPars.muonData = 'WmunuJets_DataAll_GoldenJSON_4p7invfb.root'
    fitterPars.includeMuons = True    
    fitterPars.electronData = 'WenuJets_DataAllSingleElectronTrigger_GoldenJSON_4p7invfb.root'
    fitterPars.includeElectrons = False
   
    fitterPars.NewPhysicsDirectory = '/uscms_data/d2/kalanand/WjjTrees/ReducedTree/NewKfitRDTree/RD_'
    fitterPars.minMass = 40.
    fitterPars.maxMass = 200.
    fitterPars.nbins = 30
    fitterPars.intLumi = 4700.

    
    fitterPars.binEdges.push_back(fitterPars.minMass)
    #fitterPars.binEdges.push_back(40.)
    fitterPars.binEdges.push_back(45.)
    fitterPars.binEdges.push_back(50.)
    fitterPars.binEdges.push_back(55.)
    fitterPars.binEdges.push_back(60.)
    fitterPars.binEdges.push_back(65.)
    fitterPars.binEdges.push_back(70.)
    fitterPars.binEdges.push_back(75.)
    fitterPars.binEdges.push_back(80.)
    fitterPars.binEdges.push_back(85.)
    fitterPars.binEdges.push_back(95.)
    fitterPars.binEdges.push_back(105.)
    fitterPars.binEdges.push_back(115.)
    fitterPars.binEdges.push_back(125.)
    fitterPars.binEdges.push_back(135.)
    fitterPars.binEdges.push_back(145.)
    fitterPars.binEdges.push_back(160.)
    fitterPars.binEdges.push_back(175.)
    fitterPars.binEdges.push_back(200.)

##     binEdge = fitterPars.minMass
##     print binEdge,' ',
##     while (binEdge <= fitterPars.maxMass):
##         binEdge += round(0.14*binEdge)
##         fitterPars.binEdges.push_back(binEdge)
##         print binEdge,' ',

##     fitterPars.binEdges[fitterPars.binEdges.size()-1] = fitterPars.maxMass

    print "mass range:",fitterPars.minMass,'-',fitterPars.maxMass
    
    fitterPars.truncRange = True
    fitterPars.blind = False
    fitterPars.minTrunc = 65.

    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minTrunc:
            fitterPars.minTrunc = binMin
            break
        binMin = binEdge

    fitterPars.maxTrunc = 94.
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxTrunc:
            fitterPars.maxTrunc = binEdge
            break

    fitterPars.minFit = fitterPars.minMass
    binMin = fitterPars.minMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.minFit:
            fitterPars.minFit = binMin
            break
        binMin = binEdge

    fitterPars.maxFit = fitterPars.maxMass
    for binEdge in fitterPars.binEdges:
        if binEdge > fitterPars.maxFit:
            fitterPars.maxFit = binEdge
            break


    fitterPars.minWmass = fitterPars.minTrunc
    fitterPars.maxWmass = fitterPars.maxTrunc
    
    print 'truncate:',fitterPars.truncRange,':', fitterPars.minTrunc,'-',\
          fitterPars.maxTrunc
    print 'fit range:',fitterPars.minFit,'-',fitterPars.maxFit
    
    fitterPars.njets = Nj
    fitterPars.constrainDiboson = True

    
    fitterPars.doEffCorrections = True
    fitterPars.muIdEffFiles.push_back("EffTableDir/muonEffsRecoToIso_ScaleFactors.txt")
    fitterPars.muHLTEffFiles.push_back("EffTableDir/muonEffsIsoToHLT_data_LP_LWA.txt")
    fitterPars.lumiPerEpochMuon.push_back(fitterPars.intLumi)

    
    fitterPars.eleIdEffFiles.push_back("EffTableDir/eleEffsRecoToWP80_ScaleFactors.txt")
    fitterPars.eleRecoEffFiles.push_back("EffTableDir/eleEffsSCToReco_ScaleFactors.txt")
    fitterPars.eleHLTEffFiles.push_back("EffTableDir/eleEffsSingleElectron.txt")
    fitterPars.eleJ30EffFiles.push_back("EffTableDir/FullyEfficient.txt")
    fitterPars.eleJ25NoJ30EffFiles.push_back("EffTableDir/FullyEfficient_Jet2NoJet1.txt")
    fitterPars.eleMHTEffFiles.push_back("EffTableDir/FullyEfficient_MHT.txt")
    fitterPars.eleWMtEffFiles.push_back("EffTableDir/WMt50TriggerEfficiency.txt")
    fitterPars.lumiPerEpochElectron.push_back(fitterPars.intLumi)

    fitterPars.constrainDiboson = True
    fitterPars.useExternalMorphingPars = False

    jetCut = '(ggdevt == %i)' % (Nj)
    if (Nj < 2):
        jetCut = '((ggdevt == 2) || (ggdevt == 3))'

    fitterPars.cuts = '(fit_status==0) ' + \
                      '&& %s ' % (jetCut) + \
                      '&& (fit_mlvjj > %0.1f) && (fit_mlvjj < %0.1f) ' % \
                      (minMlvjj, maxMlvjj)
    if mH == 180:
        fitterPars.cuts += '&& (abs(ang_hs) <= 0.64) ' + \
                           '&& (JetPFCor_QGLikelihood[0] >= 0.26) ' + \
                           '&& (JetPFCor_QGLikelihood[1] >= 0.23) ' + \
                           '&& (ang_hb < 0.72) ' + \
                           '&& (abs(ang_ha)<0.84) ' + \
                           '&& (ptlvjj >=4.) && (ptlvjj <= 52.) ' +\
                           '&& (abs(ylvjj) <= 1.55) '
    if mH == 250:
        fitterPars.cuts += '&& (abs(ang_hs) <= 0.42) ' + \
                           '&& (JetPFCor_QGLikelihood[0] >= 0.25) ' + \
                           '&& (JetPFCor_QGLikelihood[1] >= 0.28) ' + \
                           '&& (ang_hb < 0.46) ' + \
                           '&& (abs(ang_ha)<0.64) ' + \
                           '&& (ptlvjj >=8.) && (ptlvjj <= 118.) ' +\
                           '&& (abs(ylvjj) <= 1.7) '
    if mH == 400:
        fitterPars.cuts += '&& (abs(ang_hs) <= 0.40) ' + \
                           '&& (JetPFCor_QGLikelihood[0] >= 0.21) ' + \
                           '&& (JetPFCor_QGLikelihood[1] >= 0.27) ' + \
                           '&& (ang_hb < 0.52) ' + \
                           '&& (abs(ang_ha)<0.92) ' + \
                           '&& (ptlvjj <= 148.) ' +\
                           '&& (abs(ylvjj) <= 1.95) '

    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.,
                   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