Ejemplo n.º 1
0
def getHistograms(path,plot,runRange,isMC,backgrounds,EM=False):


	treesEE = readTrees(path,"EE")
	treesEM = readTrees(path,"EMu")
	treesMM = readTrees(path,"MuMu")
		
	
	
	if isMC:
		
		eventCounts = totalNumberOfGeneratedEvents(path)	
		processes = []
		for background in backgrounds:
			processes.append(Process(getattr(Backgrounds,background),eventCounts))
		
		histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram		
		histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram

		
		if EM:
			histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram		
		
	else:
		histoEE = getDataHist(plot,treesEE)
		histoMM = getDataHist(plot,treesMM)
		if EM:
			histoEM = getDataHist(plot,treesEM)
	
	if EM:
		return histoEE , histoMM, histoEM
	else:
		return histoEE , histoMM
Ejemplo n.º 2
0
def getHistogram(plot, runRange, backgrounds, region):
    path = locations[runRange.era].dataSetPath
    treesEE = readTrees(path, "EE")
    treesEM = readTrees(path, "EMu")
    treesMM = readTrees(path, "MuMu")

    eventCounts = totalNumberOfGeneratedEvents(path)
    processes = []
    for background in backgrounds:
        processes.append(
            Process(getattr(Backgrounds[runRange.era], background),
                    eventCounts))

    triggerSF_EE, _ = getTriggerScaleFactor("EE", region, runRange)
    triggerSF_MM, _ = getTriggerScaleFactor("MuMu", region, runRange)

    histoEE = TheStack(processes,
                       runRange.lumi,
                       plot,
                       treesEE,
                       "None",
                       1.0,
                       triggerSF_EE,
                       1.0,
                       useTriggerEmulation=True).theHistogram
    histoMM = TheStack(processes,
                       runRange.lumi,
                       plot,
                       treesMM,
                       "None",
                       1.0,
                       triggerSF_MM,
                       1.0,
                       useTriggerEmulation=True).theHistogram

    histSF = histoEE.Clone()
    histSF.Add(histoMM.Clone(), 1)

    return histSF
def getHistograms(path,plot,runRange,isMC,backgrounds):

	treesEE = readTrees(path,"EE")
	treesEM = readTrees(path,"EMu")
	treesMM = readTrees(path,"MuMu")
		
	
	
	if isMC:
		
		eventCounts = totalNumberOfGeneratedEvents(path)	
		processes = []
		for background in backgrounds:
			processes.append(Process(getattr(Backgrounds,background),eventCounts))
		histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram		
		histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram
		histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram		
		
	else:
		histoEE = getDataHist(plot,treesEE)
		histoMM = getDataHist(plot,treesMM)
		histoEM = getDataHist(plot,treesEM)
	
	return histoEE , histoMM, histoEM
Ejemplo n.º 4
0
def getHistograms(path, plot, runRange, isMC, backgrounds, region, EM=False):

    treesEE = readTrees(path, "EE")
    treesEM = readTrees(path, "EMu")
    treesMM = readTrees(path, "MuMu")

    if isMC:

        eventCounts = totalNumberOfGeneratedEvents(path)
        processes = []
        for background in backgrounds:
            processes.append(
                Process(getattr(Backgrounds, background), eventCounts))

        histoEE = TheStack(processes, runRange.lumi, plot, treesEE, "None",
                           1.0, 1.0, 1.0).theHistogram
        histoMM = TheStack(processes, runRange.lumi, plot, treesMM, "None",
                           1.0, 1.0, 1.0).theHistogram
        histoEE.Scale(getattr(triggerEffs, region).effEE.val)
        histoMM.Scale(getattr(triggerEffs, region).effMM.val)

        if EM:
            histoEM = TheStack(processes, runRange.lumi, plot, treesEM, "None",
                               1.0, 1.0, 1.0).theHistogram
            histoEM.Scale(getattr(triggerEffs, region).effEM.val)

    else:
        histoEE = getDataHist(plot, treesEE)
        histoMM = getDataHist(plot, treesMM)
        if EM:
            histoEM = getDataHist(plot, treesEM)

    if EM:
        return histoEE, histoMM, histoEM
    else:
        return histoEE, histoMM
def getCounts(trees,
              cut,
              isMC,
              backgrounds,
              plot,
              runRange,
              path,
              blind=False):

    rMuEPars = corrections[runRange.era].rMuELeptonPt.inclusive

    corrMap = {}
    corrMapUp = {}
    corrMapDn = {}
    if isMC:
        corrMap["offset"] = rMuEPars.ptOffsetMC
        corrMap["falling"] = rMuEPars.ptFallingMC
        corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBaseMC
        corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinusMC
        corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlusMC
        corrMap["norm"] = rMuEPars.normMC
    else:
        corrMap["offset"] = rMuEPars.ptOffset
        corrMap["falling"] = rMuEPars.ptFalling
        corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBase
        corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinus
        corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlus
        corrMap["norm"] = rMuEPars.norm

    rMuEDummy = "({norm:.3f}*( ({offset:.3f} + {falling:.3f}/{pt})*({etaParabolaBase} + ({eta}<-1.6)*{etaParabolaMinus:.3f}*pow({eta}+1.6, 2)+({eta}>1.6)*{etaParabolaPlus:.3f}*pow({eta}-1.6,2) )))"
    rMuE_El = rMuEDummy.format(pt="pt1", eta="eta1", **corrMap)
    rMuE_Mu = rMuEDummy.format(pt="pt2", eta="eta2", **corrMap)
    rMuEWeight = "(0.5*(%s + pow(%s, -1)))" % (rMuE_El, rMuE_Mu)

    rMuEWeight_EE = "(0.5*pow(%s, -1))" % (rMuE_Mu)
    rMuEWeight_MM = "(0.5*(%s))" % (rMuE_El)

    variationUpFlat = "(1 + 0.05)"  #
    variationDnFlat = "(1 - 0.05)"  #
    variationUpPt = "(1 + 0.05*max(110.0 - {pt},0)/90.0)"  #
    variationDnPt = "(1 - 0.05*max(110.0 - {pt},0)/90.0)"  #
    variationUpEta = "(1 + 0.05*abs(max({eta}-1.2,0))/1.2 )"  #
    variationDnEta = "(1 - 0.05*abs(max({eta}-1.2,0))/1.2 )"  #

    # Flat uncertainty
    rMuE_ElUpFlat = "(%s*%s)" % (rMuE_El, variationUpFlat)
    rMuE_MuUpFlat = "(%s*%s)" % (rMuE_Mu, variationUpFlat)
    rMuEWeightUpFlat = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpFlat,
                                                     rMuE_MuUpFlat)
    rMuEWeightUpFlat_MM = "(0.5*(%s))" % (rMuE_ElUpFlat)
    rMuEWeightUpFlat_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpFlat)

    rMuE_ElDnFlat = "(%s*%s)" % (rMuE_El, variationDnFlat)
    rMuE_MuDnFlat = "(%s*%s)" % (rMuE_Mu, variationDnFlat)
    rMuEWeightDnFlat = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnFlat,
                                                     rMuE_MuDnFlat)
    rMuEWeightDnFlat_MM = "(0.5*(%s))" % (rMuE_ElDnFlat)
    rMuEWeightDnFlat_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnFlat)

    # Pt uncertainty
    rMuE_ElUpPt = "(%s*%s)" % (rMuE_El, variationUpPt.format(pt="pt1"))
    rMuE_MuUpPt = "(%s*%s)" % (rMuE_Mu, variationUpPt.format(pt="pt2"))
    rMuEWeightUpPt = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpPt, rMuE_MuUpPt)
    rMuEWeightUpPt_MM = "(0.5*(%s))" % (rMuE_ElUpPt)
    rMuEWeightUpPt_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpPt)

    rMuE_ElDnPt = "(%s*%s)" % (rMuE_El, variationDnPt.format(pt="pt1"))
    rMuE_MuDnPt = "(%s*%s)" % (rMuE_Mu, variationDnPt.format(pt="pt2"))
    rMuEWeightDnPt = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnPt, rMuE_MuDnPt)
    rMuEWeightDnPt_MM = "(0.5*(%s))" % (rMuE_ElDnPt)
    rMuEWeightDnPt_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnPt)

    # Pt uncertainty
    rMuE_ElUpEta = "(%s*%s)" % (rMuE_El, variationUpEta.format(eta="eta1"))
    rMuE_MuUpEta = "(%s*%s)" % (rMuE_Mu, variationUpEta.format(eta="eta2"))
    rMuEWeightUpEta = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpEta, rMuE_MuUpEta)
    rMuEWeightUpEta_MM = "(0.5*(%s))" % (rMuE_ElUpEta)
    rMuEWeightUpEta_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpEta)

    rMuE_ElDnEta = "(%s*%s)" % (rMuE_El, variationDnEta.format(eta="eta1"))
    rMuE_MuDnEta = "(%s*%s)" % (rMuE_Mu, variationDnEta.format(eta="eta2"))
    rMuEWeightDnEta = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnEta, rMuE_MuDnEta)
    rMuEWeightDnEta_MM = "(0.5*(%s))" % (rMuE_ElDnEta)
    rMuEWeightDnEta_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnEta)

    plot.cuts = cut.replace(
        "prefireWeight*leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*",
        "")

    cutRMuEScaled = "%s*%s" % (rMuEWeight, plot.cuts)
    cutRMuEScaledUpFlat = "%s*%s" % (rMuEWeightUpFlat, plot.cuts)
    cutRMuEScaledDnFlat = "%s*%s" % (rMuEWeightDnFlat, plot.cuts)
    cutRMuEScaledUpPt = "%s*%s" % (rMuEWeightUpPt, plot.cuts)
    cutRMuEScaledDnPt = "%s*%s" % (rMuEWeightDnPt, plot.cuts)
    cutRMuEScaledUpEta = "%s*%s" % (rMuEWeightUpEta, plot.cuts)
    cutRMuEScaledDnEta = "%s*%s" % (rMuEWeightDnEta, plot.cuts)

    cutRMuEScaled_EE = "%s*%s" % (rMuEWeight_EE, plot.cuts)
    cutRMuEScaledUpFlat_EE = "%s*%s" % (rMuEWeightUpFlat_EE, plot.cuts)
    cutRMuEScaledDnFlat_EE = "%s*%s" % (rMuEWeightDnFlat_EE, plot.cuts)
    cutRMuEScaledUpPt_EE = "%s*%s" % (rMuEWeightUpPt_EE, plot.cuts)
    cutRMuEScaledDnPt_EE = "%s*%s" % (rMuEWeightDnPt_EE, plot.cuts)
    cutRMuEScaledUpEta_EE = "%s*%s" % (rMuEWeightUpEta_EE, plot.cuts)
    cutRMuEScaledDnEta_EE = "%s*%s" % (rMuEWeightDnEta_EE, plot.cuts)

    cutRMuEScaled_MM = "%s*%s" % (rMuEWeight_MM, plot.cuts)
    cutRMuEScaledUpFlat_MM = "%s*%s" % (rMuEWeightUpFlat_MM, plot.cuts)
    cutRMuEScaledDnFlat_MM = "%s*%s" % (rMuEWeightDnFlat_MM, plot.cuts)
    cutRMuEScaledUpPt_MM = "%s*%s" % (rMuEWeightUpPt_MM, plot.cuts)
    cutRMuEScaledDnPt_MM = "%s*%s" % (rMuEWeightDnPt_MM, plot.cuts)
    cutRMuEScaledUpEta_MM = "%s*%s" % (rMuEWeightUpEta_MM, plot.cuts)
    cutRMuEScaledDnEta_MM = "%s*%s" % (rMuEWeightDnEta_MM, plot.cuts)

    if isMC:
        RT = corrections[runRange.era].rSFOFTrig.inclusive.valMC
        RTErr = corrections[runRange.era].rSFOFTrig.inclusive.errMC
    else:
        RT = corrections[runRange.era].rSFOFTrig.inclusive.val
        RTErr = corrections[runRange.era].rSFOFTrig.inclusive.err

    if isMC:
        source = ""
        modifier = ""
        eventCounts = totalNumberOfGeneratedEvents(path, source, modifier)
        processes = []
        for background in backgrounds:
            processes.append(
                Process(getattr(Backgrounds[runRange.era], background),
                        eventCounts))

        n = {}
        for region in [
                "inclusive",
        ]:
            histEE = TheStack(processes, runRange.lumi, plot, trees["EE"],
                              "None", 1.0,
                              getTriggerScaleFactor("EE", region, runRange),
                              1.0).theHistogram
            histMM = TheStack(processes, runRange.lumi, plot, trees["MM"],
                              "None", 1.0,
                              getTriggerScaleFactor("MM", region, runRange),
                              1.0).theHistogram
            histEM = TheStack(processes, runRange.lumi, plot, trees["EM"],
                              "None", 1.0,
                              getTriggerScaleFactor("EM", region, runRange),
                              1.0).theHistogram

            triggerEffs = corrections[runRange.era]
            histEE.Scale(getattr(triggerEffs, region).effEE.val)
            histMM.Scale(getattr(triggerEffs, region).effMM.val)
            histEM.Scale(getattr(triggerEffs, region).effEM.val)

            # central value
            plot.cuts = cutRMuEScaled
            histEMRMuEScaled = TheStack(processes, runRange.lumi, plot,
                                        trees["EM"], "None", 1.0, 1.0,
                                        1.0).theHistogram
            histEMRMuEScaled.Scale(getattr(triggerEffs, region).effEM.val)

            # flat uncertainty
            plot.cuts = cutRMuEScaledUpFlat
            histEMRMuEScaledUpFlat = TheStack(processes, runRange.lumi, plot,
                                              trees["EM"], "None", 1.0, 1.0,
                                              1.0).theHistogram
            histEMRMuEScaledUpFlat.Scale(
                getattr(triggerEffs, region).effEM.val)

            plot.cuts = cutRMuEScaledDnFlat
            histEMRMuEScaledDownFlat = TheStack(processes, runRange.lumi, plot,
                                                trees["EM"], "None", 1.0, 1.0,
                                                1.0).theHistogram
            histEMRMuEScaledDownFlat.Scale(
                getattr(triggerEffs, region).effEM.val)

            # pt uncertainty
            plot.cuts = cutRMuEScaledUpPt
            histEMRMuEScaledUpPt = TheStack(processes, runRange.lumi, plot,
                                            trees["EM"], "None", 1.0, 1.0,
                                            1.0).theHistogram
            histEMRMuEScaledUpPt.Scale(getattr(triggerEffs, region).effEM.val)

            plot.cuts = cutRMuEScaledDnPt
            histEMRMuEScaledDownPt = TheStack(processes, runRange.lumi, plot,
                                              trees["EM"], "None", 1.0, 1.0,
                                              1.0).theHistogram
            histEMRMuEScaledDownPt.Scale(
                getattr(triggerEffs, region).effEM.val)

            # eta uncertainty
            plot.cuts = cutRMuEScaledUpEta
            histEMRMuEScaledUpEta = TheStack(processes, runRange.lumi, plot,
                                             trees["EM"], "None", 1.0, 1.0,
                                             1.0).theHistogram
            histEMRMuEScaledUpEta.Scale(getattr(triggerEffs, region).effEM.val)

            plot.cuts = cutRMuEScaledDnEta
            histEMRMuEScaledDownEta = TheStack(processes, runRange.lumi, plot,
                                               trees["EM"], "None", 1.0, 1.0,
                                               1.0).theHistogram
            histEMRMuEScaledDownEta.Scale(
                getattr(triggerEffs, region).effEM.val)

            eeErr = ROOT.Double()
            ee = histEE.IntegralAndError(0, -1, eeErr)
            mmErr = ROOT.Double()
            mm = histMM.IntegralAndError(0, -1, mmErr)
            emErr = ROOT.Double()
            em = histEM.IntegralAndError(0, -1, emErr)

            #central value
            emRMuEScaledErr = ROOT.Double()
            emRMuEScaled = histEMRMuEScaled.IntegralAndError(
                0, -1, emRMuEScaledErr)

            # flat uncertainty
            emRMuEScaledUpFlatErr = ROOT.Double()
            emRMuEScaledUpFlat = histEMRMuEScaledUpFlat.IntegralAndError(
                0, -1, emRMuEScaledUpFlatErr)
            emRMuEScaledDownFlatErr = ROOT.Double()
            emRMuEScaledDownFlat = histEMRMuEScaledDownFlat.IntegralAndError(
                0, -1, emRMuEScaledDownFlatErr)

            # pt uncertainty
            emRMuEScaledUpPtErr = ROOT.Double()
            emRMuEScaledUpPt = histEMRMuEScaledUpPt.IntegralAndError(
                0, -1, emRMuEScaledUpPtErr)
            emRMuEScaledDownPtErr = ROOT.Double()
            emRMuEScaledDownPt = histEMRMuEScaledDownPt.IntegralAndError(
                0, -1, emRMuEScaledDownPtErr)

            # eta uncertainty
            emRMuEScaledUpEtaErr = ROOT.Double()
            emRMuEScaledUpEta = histEMRMuEScaledUpEta.IntegralAndError(
                0, -1, emRMuEScaledUpEtaErr)
            emRMuEScaledDownEtaErr = ROOT.Double()
            emRMuEScaledDownEta = histEMRMuEScaledDownEta.IntegralAndError(
                0, -1, emRMuEScaledDownEtaErr)

            n["EMRMuEScaled"] = emRMuEScaled * RT
            n["EMRMuEScaledUpFlat"] = emRMuEScaledUpFlat * RT
            n["EMRMuEScaledDownFlat"] = emRMuEScaledDownFlat * RT
            n["EMRMuEScaledUpPt"] = emRMuEScaledUpPt * RT
            n["EMRMuEScaledDownPt"] = emRMuEScaledDownPt * RT
            n["EMRMuEScaledUpEta"] = emRMuEScaledUpEta * RT
            n["EMRMuEScaledDownEta"] = emRMuEScaledDownEta * RT

            n["MM"] = mm
            n["EE"] = ee
            n["EM"] = em
            n["MMStatErr"] = float(mmErr)
            n["EEStatErr"] = float(eeErr)
            n["EMStatErr"] = float(emErr)

    else:
        n = {}
        for region in [
                "inclusive",
        ]:
            if blind:
                n["MM"] = createHistoFromTree(trees["EM"], "mll",
                                              cutRMuEScaled_MM, 100, 0,
                                              10000).Integral(0, -1) * RT
                n["EE"] = createHistoFromTree(trees["EM"], "mll",
                                              cutRMuEScaled_EE, 100, 0,
                                              10000).Integral(0, -1) * RT
            else:
                n["MM"] = trees["MM"].GetEntries(plot.cuts)
                n["EE"] = trees["EE"].GetEntries(plot.cuts)
            n["EM"] = trees["EM"].GetEntries(plot.cuts)

            n["EMRMuEScaled"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled, 100, 0, 10000).Integral(
                    0, -1) * RT
            n["EMRMuEScaled_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_EE, 100, 0, 10000).Integral(
                    0, -1) * RT
            n["EMRMuEScaled_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_MM, 100, 0, 10000).Integral(
                    0, -1) * RT

            n["EMRMuEScaledUpRT"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled, 10, 0, 10000).Integral(
                    0, -1) * (RT + RTErr)
            n["EMRMuEScaledDownRT"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled, 10, 0, 10000).Integral(
                    0, -1) * (RT - RTErr)
            n["EMRMuEScaledUpFlat"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpFlat, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownFlat"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnFlat, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledUpPt"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpPt, 10, 0, 10000).Integral(
                    0, -1) * RT
            n["EMRMuEScaledDownPt"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnPt, 10, 0, 10000).Integral(
                    0, -1) * RT
            n["EMRMuEScaledUpEta"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpEta, 10, 0, 10000).Integral(
                    0, -1) * RT
            n["EMRMuEScaledDownEta"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnEta, 10, 0, 10000).Integral(
                    0, -1) * RT

            n["EMRMuEScaledUpRT_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_EE, 10, 0, 10000).Integral(
                    0, -1) * (RT + RTErr)
            n["EMRMuEScaledDownRT_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_EE, 10, 0, 10000).Integral(
                    0, -1) * (RT - RTErr)
            n["EMRMuEScaledUpFlat_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpFlat_EE, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownFlat_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnFlat_EE, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledUpPt_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpPt_EE, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownPt_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnPt_EE, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledUpEta_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpEta_EE, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownEta_EE"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnEta_EE, 10, 0,
                10000).Integral(0, -1) * RT

            n["EMRMuEScaledUpRT_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_MM, 10, 0, 10000).Integral(
                    0, -1) * (RT + RTErr)
            n["EMRMuEScaledDownRT_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaled_MM, 10, 0, 10000).Integral(
                    0, -1) * (RT - RTErr)
            n["EMRMuEScaledUpFlat_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpFlat_MM, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownFlat_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnFlat_MM, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledUpPt_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpPt_MM, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownPt_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnPt_MM, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledUpEta_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledUpEta_MM, 10, 0,
                10000).Integral(0, -1) * RT
            n["EMRMuEScaledDownEta_MM"] = createHistoFromTree(
                trees["EM"], "mll", cutRMuEScaledDnEta_MM, 10, 0,
                10000).Integral(0, -1) * RT

            n["MMStatErr"] = n["MM"]**0.5
            n["EEStatErr"] = n["EE"]**0.5
            n["EMStatErr"] = n["EM"]**0.5

    n["cut"] = cut
    return n
Ejemplo n.º 6
0
	ptCut = "pt1 > 20 && pt2 > 20"#(pt1 > 10 && pt2 > 20 || pt1 > 20 && pt2 > 10)
	ptCutLabel = "20"#"20(10)"
	variable = "p4.M()"
	cuts = "weight*(chargeProduct < 0 && %s  && abs(eta1) < 2.4 && abs(eta2) < 2.4  && p4.M() > 20 && ((abs(eta1) < 1.4 || abs(eta1) > 1.6) && (abs(eta2) < 1.4 || abs(eta2) > 1.6)))"%(ptCut)


	SampleName = "TT_Powheg"
	runRange = getRunRange("Run2015_25ns")
	
	plot = getPlot("mllPlot")
	selection = getRegion("SignalInclusive")
	plot.addRegion(selection)
	plot.cleanCuts()
	plot.cuts = plot.cuts % runRange.runCut			
	
	eventCounts = totalNumberOfGeneratedEvents(path)
	processes = [Process(getattr(Backgrounds,"TT_Powheg"),eventCounts)]

	treesEE = readTrees(path,"EE")
	treesEM = readTrees(path,"EMu")
	treesMM = readTrees(path,"MuMu")


	histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram		
	histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram
	histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram		
	#~ histoEE.Scale(getattr(triggerEffs,"central").effEE.valMC)
	#~ histoMM.Scale(getattr(triggerEffs,"central").effMM.valMC)	
	#~ histoEM.Scale(getattr(triggerEffs,"central").effEM.valMC)	

def getYields(runRange):
    import ratios

    import pickle

    path = locations[runRange.era].dataSetPathNLL

    EE = readTrees(path, "EE")
    EM = readTrees(path, "EMu")
    MM = readTrees(path, "MuMu")

    ### Mass bins for Morion 2017 SRs, summed low and high mass regions + legacy regions
    massRegions = [
        "mass20To60", "mass60To86", "mass86To96", "mass96To150",
        "mass150To200", "mass200To300", "mass300To400", "mass400"
    ]

    ### Two likelihood bins and MT2 cut
    nLLRegions = ["lowNLL", "highNLL"]
    MT2Regions = ["highMT2"]
    nBJetsRegions = ["zeroBJets", "oneOrMoreBJets"]

    signalBins = []
    signalCuts = {}

    plot = getPlot("mllPlotROutIn")

    for massRegion in massRegions:
        for nLLRegion in nLLRegions:
            for MT2Region in MT2Regions:
                for nBJetsRegion in nBJetsRegions:
                    signalBins.append(
                        "%s_%s_%s_%s" %
                        (massRegion, nLLRegion, MT2Region, nBJetsRegion))
                    signalCuts["%s_%s_%s_%s" %
                               (massRegion, nLLRegion, MT2Region,
                                nBJetsRegion)] = "%s && %s && %s && %s" % (
                                    massCuts[massRegion], nLLCuts[nLLRegion],
                                    MT2Cuts[MT2Region],
                                    NBJetsCuts[nBJetsRegion])

    selection = getRegion("SignalHighMT2DeltaPhiJetMet")
    backgrounds = [
        "RareWZOnZ", "RareZZLowMassOnZ", "RareTTZOnZ", "RareRestOnZ"
    ]

    plot.addRegion(selection)
    plot.addRunRange(runRange)
    plot.cuts = plot.cuts.replace("p4.M()", "mll")
    plot.variable = plot.variable.replace("p4.M()", "mll")

    if runRange.era == "2018":
        plot.cuts = plot.cuts.replace("chargeProduct < 0 &&",
                                      "chargeProduct < 0 && vetoHEM == 1 &&")

    counts = {}

    eventCounts = totalNumberOfGeneratedEvents(path)

    defaultCut = plot.cuts

    ### loop over signal regions
    for signalBin in signalBins:

        ### Add signal cut and remove those that are renamed or already applied
        ### on NLL datasets
        plot.cuts = defaultCut.replace(
            "chargeProduct < 0",
            "chargeProduct < 0 && %s" % (signalCuts[signalBin]))
        plot.cuts = plot.cuts.replace("metFilterSummary > 0 &&", "")
        plot.cuts = plot.cuts.replace("&& metFilterSummary > 0", "")
        plot.cuts = plot.cuts.replace("triggerSummary > 0 &&", "")
        plot.cuts = plot.cuts.replace("p4.Pt()", "pt")

        plot.cuts = "bTagWeight*" + plot.cuts

        #print plot.cuts

        eventCountSF = 0
        eventYieldSF = 0
        eventYieldEE = 0
        eventYieldMM = 0
        eventYieldSFTotErr = 0
        eventYieldSFStatErr = 0
        eventYieldEEStatErr = 0
        eventYieldMMStatErr = 0
        eventYieldSFSystErr = 0
        eventYieldSFUp = 0
        eventYieldEEUp = 0
        eventYieldMMUp = 0
        eventYieldSFDown = 0
        eventYieldEEDown = 0
        eventYieldMMDown = 0

        eventYieldOF = 0
        eventYieldOFTotErr = 0
        eventYieldOFStatErr = 0
        eventYieldOFSystErr = 0
        eventYieldOFUp = 0
        eventYieldOFDown = 0

        counts["%s_bySample" % signalBin] = {}

        processes = []
        for background in backgrounds:
            proc = Process(getattr(Backgrounds[runRange.era], background),
                           eventCounts)
            processes.append(proc)

            picklePath = "/home/home4/institut_1b/teroerde/Doktorand/SUSYFramework/frameWorkBase/shelves/scaleFactor_{runRange}_{background}.pkl"
            sf = 1.0
            sferr = 0.0
            if proc.label in ["WZ", "ZZ", "TTZ"]:
                if proc.label == "WZ":
                    backgroundName = "WZTo3LNu"
                elif proc.label == "ZZ":
                    backgroundName = "ZZTo4L"
                elif proc.label == "TTZ":
                    backgroundName = "ttZToLL"
                import pickle
                with open(
                        picklePath.format(runRange=runRange.label,
                                          background=backgroundName),
                        "r") as fi:
                    scaleFac = pickle.load(fi)
                sf = scaleFac["scaleFac"]
                sferr = scaleFac["scaleFacErr"]
            else:
                sferr = proc.uncertainty

            sfErrRel = sferr / sf

            saveCut = plot.cuts

            histoEE = proc.createCombinedHistogram(
                runRange.lumi,
                plot,
                EE,
                "None",
                1.0,
                getTriggerScaleFactor("EE", "inclusive", runRange)[0] * sf,
                1.0,
                TopWeightUp=False,
                TopWeightDown=False,
                signal=False,
                doTopReweighting=True,
                doPUWeights=False,
                normalizeToBinWidth=False,
                useTriggerEmulation=False)
            histoMM = proc.createCombinedHistogram(
                runRange.lumi,
                plot,
                MM,
                "None",
                1.0,
                getTriggerScaleFactor("MM", "inclusive", runRange)[0] * sf,
                1.0,
                TopWeightUp=False,
                TopWeightDown=False,
                signal=False,
                doTopReweighting=True,
                doPUWeights=False,
                normalizeToBinWidth=False,
                useTriggerEmulation=False)

            # RSFOF weighted EMu sample with rMuE parametrization
            rMuEPars = corrections[runRange.era].rMuELeptonPt.inclusive
            RT = corrections[runRange.era].rSFOFTrig.inclusive.val
            corrMap = {}
            corrMap["offset"] = rMuEPars.ptOffsetMC
            corrMap["falling"] = rMuEPars.ptFallingMC
            corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBaseMC
            corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinusMC
            corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlusMC
            corrMap["norm"] = rMuEPars.normMC

            rMuEDummy = "({norm:.3f}*(({offset:.3f} + {falling:.3f}/{pt})*({etaParabolaBase} + ({eta}<-1.6)*{etaParabolaMinus:.3f}*pow({eta}+1.6, 2)+({eta}>1.6)*{etaParabolaPlus:.3f}*pow({eta}-1.6,2) )))"
            rMuE_El = rMuEDummy.format(pt="pt1", eta="eta1", **corrMap)
            rMuE_Mu = rMuEDummy.format(pt="pt2", eta="eta2", **corrMap)
            rMuEWeight = "(0.5*(%s + pow(%s, -1)))*%.3f" % (rMuE_Mu, rMuE_El,
                                                            RT)

            #tmpCut = plot.cuts
            plot.cuts = "%s*%s" % (rMuEWeight, plot.cuts)
            histoEM = proc.createCombinedHistogram(
                runRange.lumi,
                plot,
                EM,
                "None",
                1.0,
                getTriggerScaleFactor("EM", "inclusive", runRange)[0] * sf,
                1.0,
                TopWeightUp=False,
                TopWeightDown=False,
                signal=False,
                doTopReweighting=True,
                doPUWeights=False,
                normalizeToBinWidth=False,
                useTriggerEmulation=False)
            #plot.cuts = tmpCut

            plot.cuts = saveCut

            statErrEE = ROOT.Double()
            statErrMM = ROOT.Double()
            statErrEM = ROOT.Double()

            eventCountSF += histoEE.GetEntries() + histoMM.GetEntries()

            procYield = histoEE.IntegralAndError(
                0, -1, statErrEE) + histoMM.IntegralAndError(0, -1, statErrMM)
            procYield_EE = histoEE.IntegralAndError(0, -1, statErrEE)
            procYield_MM = histoMM.IntegralAndError(0, -1, statErrMM)

            #if "mass20To60" in signalBin and proc.label == "ZZ":
            #print signalBin, procYield

            eventYieldSF += procYield
            eventYieldSFUp += (procYield) * (1 + sfErrRel)
            eventYieldSFDown += (procYield) * (1 - sfErrRel)

            eventYieldEE += procYield_EE
            eventYieldEEUp += (procYield_EE) * (1 + sfErrRel)
            eventYieldEEDown += (procYield_EE) * (1 - sfErrRel)

            eventYieldMM += procYield_MM
            eventYieldMMUp += (procYield_MM) * (1 + sfErrRel)
            eventYieldMMDown += (procYield_MM) * (1 - sfErrRel)

            eventYieldSFStatErr = (eventYieldSFStatErr**2 + statErrEE**2 +
                                   statErrMM**2)**0.5
            eventYieldEEStatErr = (eventYieldEEStatErr**2 + statErrEE**2)**0.5
            eventYieldMMStatErr = (eventYieldMMStatErr**2 + statErrMM**2)**0.5
            eventYieldSFSystErr = (eventYieldSFSystErr**2 +
                                   (eventYieldSF * sfErrRel)**2)**0.5

            eventYieldOF += histoEM.IntegralAndError(0, -1, statErrEM)
            eventYieldOFUp += histoEM.Integral(0, -1) * (1 + proc.uncertainty)
            eventYieldOFDown += histoEM.Integral(0,
                                                 -1) * (1 - proc.uncertainty)

            eventYieldOFStatErr = (eventYieldOFStatErr**2 + statErrEM**2)**0.5
            eventYieldOFSystErr = (eventYieldOFSystErr**2 +
                                   (eventYieldOF * sfErrRel)**2)**0.5

            counts["%s_bySample" % signalBin][proc.label] = procYield

            if proc.label in ["WZ", "ZZ", "TTZ", "Rare"]:
                # uncertainty from just this one sample. Used to treat uncertainties uncorrelated between WZ,ZZ,TTZ,Rare
                counts["%s_SingleErr%s" % (signalBin, proc.label)] = (
                    ((procYield) * sfErrRel)**2 + statErrEE**2 +
                    statErrMM**2)**0.5

            #if proc.label == "ZZ" and "highNLL" in signalBin:
            #print signalBin, gotten

        eventYieldSFTotErr = (eventYieldSFStatErr**2 +
                              eventYieldSFSystErr**2)**0.5
        eventYieldOFTotErr = (eventYieldOFStatErr**2 +
                              eventYieldOFSystErr**2)**0.5

        eventCountSF = histoEE.GetEntries() + histoMM.GetEntries()

        counts["%s_SF" % signalBin] = eventYieldSF
        counts["%s_EE" % signalBin] = eventYieldEE
        counts["%s_MM" % signalBin] = eventYieldMM
        counts["%s_SF_Stat" % signalBin] = eventYieldSFStatErr
        counts["%s_EE_Stat" % signalBin] = eventYieldEEStatErr
        counts["%s_MM_Stat" % signalBin] = eventYieldMMStatErr
        counts["%s_SF_Syst" % signalBin] = eventYieldSFSystErr
        counts["%s_SF_Up" % signalBin] = eventYieldSFUp
        counts["%s_EE_Up" % signalBin] = eventYieldEEUp
        counts["%s_MM_Up" % signalBin] = eventYieldMMUp
        counts["%s_SF_Down" % signalBin] = eventYieldSFDown
        counts["%s_EE_Down" % signalBin] = eventYieldEEDown
        counts["%s_MM_Down" % signalBin] = eventYieldMMDown
        counts["MCEvents_%s_SF" % signalBin] = eventCountSF

        counts["%s_OF" % signalBin] = eventYieldOF
        counts["%s_OF_Stat" % signalBin] = eventYieldOFStatErr
        counts["%s_OF_Syst" % signalBin] = eventYieldOFSystErr
        counts["%s_OF_Err" % signalBin] = eventYieldOFTotErr
        counts["%s_OF_Up" % signalBin] = eventYieldOFUp
        counts["%s_OF_Down" % signalBin] = eventYieldOFDown

    fileName = "RareOnZBG_%s" % (runRange.label)

    outFilePkl = open("shelves/%s.pkl" % fileName, "w")
    pickle.dump(counts, outFilePkl)
    outFilePkl.close()
def getHistograms(path, plot, runRange, isMC, backgrounds, source):

    if not isMC:
        treesEE = readTrees(path, "EE", modifier="TriggerPFHT")
        treesMuMu = readTrees(path, "MuMu", modifier="TriggerPFHT")
        treesEMu = readTrees(path, "EMu", modifier="TriggerPFHT")

        denominatorHistoEE = TH1F("", "", plot.nBins, plot.firstBin,
                                  plot.lastBin)
        for name, tree in treesEE.iteritems():
            if name == "MergedData":
                denominatorHistoEE.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        plot.cuts,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())
        denominatorHistoMuMu = TH1F("", "", plot.nBins, plot.firstBin,
                                    plot.lastBin)
        for name, tree in treesMuMu.iteritems():
            if name == "MergedData":
                denominatorHistoMuMu.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        plot.cuts,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())
        denominatorHistoMuEG = TH1F("", "", plot.nBins, plot.firstBin,
                                    plot.lastBin)
        for name, tree in treesEMu.iteritems():
            if name == "MergedData":
                denominatorHistoMuEG.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        plot.cuts,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())

        cutsEE = plot.cuts.replace(
            "chargeProduct < 0",
            "chargeProduct < 0 && %s" % theCuts.triggerCuts.EE.cut)
        cutsOF = plot.cuts.replace(
            "chargeProduct < 0",
            "chargeProduct < 0 && %s" % theCuts.triggerCuts.EM.cut)
        cutsMuMu = plot.cuts.replace(
            "chargeProduct < 0",
            "chargeProduct < 0 && %s" % theCuts.triggerCuts.MM.cut)

        nominatorHistoEE = TH1F("", "", plot.nBins, plot.firstBin,
                                plot.lastBin)
        for name, tree in treesEE.iteritems():
            if name == "MergedData":
                nominatorHistoEE.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        cutsEE,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())
        nominatorHistoMuMu = TH1F("", "", plot.nBins, plot.firstBin,
                                  plot.lastBin)
        for name, tree in treesMuMu.iteritems():
            if name == "MergedData":
                nominatorHistoMuMu.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        cutsMuMu,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())
        nominatorHistoMuEG = TH1F("", "", plot.nBins, plot.firstBin,
                                  plot.lastBin)
        for name, tree in treesEMu.iteritems():
            if name == "MergedData":
                nominatorHistoMuEG.Add(
                    createHistoFromTree(tree,
                                        plot.variable,
                                        cutsOF,
                                        plot.nBins,
                                        plot.firstBin,
                                        plot.lastBin,
                                        binning=plot.binning).Clone())
    else:
        treesEE = readTrees(path, "EE")
        treesMuMu = readTrees(path, "MuMu")
        treesEMu = readTrees(path, "EMu")

        eventCounts = totalNumberOfGeneratedEvents(path)
        processes = []
        for background in backgrounds:
            processes.append(
                Process(getattr(Backgrounds, background), eventCounts))

        nominatorStackEE = TheStack(processes,
                                    runRange.lumi,
                                    plot,
                                    treesEE,
                                    "None",
                                    1.0,
                                    1.0,
                                    1.0,
                                    useTriggerEmulation=True)
        nominatorStackMuMu = TheStack(processes,
                                      runRange.lumi,
                                      plot,
                                      treesMuMu,
                                      "None",
                                      1.0,
                                      1.0,
                                      1.0,
                                      useTriggerEmulation=True)
        nominatorStackMuEG = TheStack(processes,
                                      runRange.lumi,
                                      plot,
                                      treesEMu,
                                      "None",
                                      1.0,
                                      1.0,
                                      1.0,
                                      useTriggerEmulation=True)

        denominatorStackEE = TheStack(processes, runRange.lumi, plot, treesEE,
                                      "None", 1.0, 1.0, 1.0)
        denominatorStackMuMu = TheStack(processes, runRange.lumi, plot,
                                        treesMuMu, "None", 1.0, 1.0, 1.0)
        denominatorStackMuEG = TheStack(processes, runRange.lumi, plot,
                                        treesEMu, "None", 1.0, 1.0, 1.0)

        denominatorHistoEE = denominatorStackEE.theHistogram
        denominatorHistoMuMu = denominatorStackMuMu.theHistogram
        denominatorHistoMuEG = denominatorStackMuEG.theHistogram

        nominatorHistoEE = nominatorStackEE.theHistogram
        nominatorHistoMuMu = nominatorStackMuMu.theHistogram
        nominatorHistoMuEG = nominatorStackMuEG.theHistogram

    return {
        "EE": denominatorHistoEE,
        "MuMu": denominatorHistoMuMu,
        "MuEG": denominatorHistoMuEG
    }, {
        "EE": nominatorHistoEE,
        "MuMu": nominatorHistoMuMu,
        "MuEG": nominatorHistoMuEG
    }
Ejemplo n.º 9
0
def signalRegion(path, selection, plots, runRange, backgrounds, cmsExtra):
    plots = ["mllPlot"]
    for name in plots:
        plot = getPlot(name)
        plot.addRegion(selection)
        #~ plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut
        #~ plot.cuts = plot.cuts.replace("2.4","1.4")
        #~ plot.cuts = plot.cuts.replace("weight*","")
        print runRange.lumi
        if "Signal" in selection.name:
            plot.nBins = int(plot.nBins / 2)
            plot.yaxis = "Events / 10 GeV"
        fake = "!(pdgIdETH1*pdgIdETH2==-11*11 || pdgIdETH1*pdgIdETH2==-13*13 || pdgIdETH1*pdgIdETH2==-11*13)"

        dilep = "(motherPdgIdETH1*motherPdgIdETH2==-24*24 || motherPdgIdETH1*grandMotherPdgIdETH2==-24*24 || grandMotherPdgIdETH1*motherPdgIdETH2==-24*24 || grandMotherPdgIdETH1*grandMotherPdgIdETH2==-24*24)"
        #~ plot.cuts = plot.cuts+"*!(!(motherPdgIdETH1*motherPdgIdETH2==-24*24 || grandMotherPdgIdETH1*grandMotherPdgIdETH2==-24*24 || motherPdgIdETH1*grandMotherPdgIdETH2==-24*24 || grandMotherPdgIdETH1*motherPdgIdETH2==-24*24) || !(pdgIdETH1*pdgIdETH2==-11*11 || pdgIdETH1*pdgIdETH2==-13*13 || pdgIdETH1*pdgIdETH2==-11*13))"
        #~ plot.cuts = plot.cuts+"*!((motherPdgIdETH1 == grandMotherPdgIdETH1) || (motherPdgIdETH2 == grandMotherPdgIdETH2))"
        #~ plot.cuts = plot.cuts+"*!((motherPdgIdETH1 == grandMotherPdgIdETH1) || (motherPdgIdETH2 == grandMotherPdgIdETH2) || (abs(motherPdgIdETH1) == 24 && abs(motherPdgIdETH2) == 24  )) "
        #~ plot.cuts = plot.cuts+"*!((abs(motherPdgIdETH1) == 15 && abs(motherPdgIdETH2) == 24) || (abs(motherPdgIdETH2) == 15 && abs(motherPdgIdETH1) == 24) || (abs(motherPdgIdETH1) == 15 && abs(motherPdgIdETH2) == 15) || (abs(motherPdgIdETH1) == 24 && abs(motherPdgIdETH2) == 24  )) "

        #~ plot.cuts = plot.cuts+"*(!(abs(motherPdgIdETH1*motherPdgIdETH2)==24*24 || abs(motherPdgIdETH1*motherPdgIdETH2)==15*24 || abs(motherPdgIdETH1*motherPdgIdETH2)==15*15) || !(pdgIdETH1*pdgIdETH2==-11*11 || pdgIdETH1*pdgIdETH2==-13*13 || pdgIdETH1*pdgIdETH2==-11*13))"

        #~ plot.cuts = plot.cuts+"*(!(abs(motherPdgId1*motherPdgId2)==24*24 || abs(motherPdgId1*motherPdgId2)==15*24 || abs(motherPdgId1*motherPdgId2)==15*15) || !(pdgId1*pdgId2==-11*11 || pdgId1*pdgId2==-13*13 || pdgId1*pdgId2==-11*13))"
        #~ plot.cuts = plot.cuts+"*!(%s && !%s)"%(dilep,fake)
        plot.cuts = plot.cuts + "*!(%s && !%s)" % (dilep, fake)
        print plot.cuts

        if not "Forward" in selection.name:
            corr = rSFOF.central.val
            corrErr = rSFOF.central.err
            if "Central" in selection.name:
                region = "central"
            else:
                region = "inclusive"
        else:
            corr = rSFOF.forward.val
            corrErr = rSFOF.forward.err
            region = "forward"
        #~
        eventCounts = totalNumberOfGeneratedEvents(path)
        print eventCounts
        #~ for background in backgrounds:
        #~ process = Process(getattr(Backgrounds,background),eventCounts)
        #~ for subprocess in process.samples:
        #~
        #~ print subprocess
        #~ treeEE, treeMM, treeEM = getTrees(path,plot,runRange, subprocess,region)
        #~ for ev in treeMM:

        #~ print ev.pdgIdETH1, ev.motherPdgIdETH1, ev.grandMotherPdgIdETH1, "--", ev.pdgIdETH2, ev.motherPdgIdETH2, ev.grandMotherPdgIdETH2

        #~ print treeEE.GetEntries(), treeMM.GetEntries(), treeEM.GetEntries()
        histEE, histMM, histOF = getHistograms(path, plot, runRange,
                                               backgrounds, region)
        print histEE.Integral(1, histEE.GetNbinsX()), histMM.Integral(
            1, histEE.GetNbinsX()), histOF.Integral(1, histEE.GetNbinsX())
        print histEE.GetEntries(), histMM.GetEntries(), histOF.GetEntries()

        nEEScaledErr = ROOT.Double()
        nMMScaledErr = ROOT.Double()
        nEMScaledErr = ROOT.Double()

        nEEScaled = histEE.IntegralAndError(1, histEE.GetNbinsX(),
                                            nEEScaledErr)
        nMMScaled = histMM.IntegralAndError(1, histEE.GetNbinsX(),
                                            nMMScaledErr)
        nEMScaled = histOF.IntegralAndError(1, histEE.GetNbinsX(),
                                            nEMScaledErr)

        result = {
            "nEE": histEE.GetEntries(),
            "nMM": histMM.GetEntries(),
            "nEM": histOF.GetEntries(),
            "nEEScaled": nEEScaled,
            "nEEScaledErr": float(nEEScaledErr),
            "nMMScaled": nMMScaled,
            "nMMScaledErr": float(nMMScaledErr),
            "nEMScaled": nEMScaled,
            "nEMScaledErr": float(nEMScaledErr)
        }

        outFilePkl = open(
            "shelves/nonPromptMC_%s_%s" % (selection.name, runRange.label),
            "w")
        pickle.dump(result, outFilePkl)
        outFilePkl.close()

        hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)
        plotPad = TPad("plotPad", "plotPad", 0, 0, 1, 1)

        style = setTDRStyle()
        plotPad.UseCurrentStyle()
        plotPad.Draw()
        plotPad.cd()
        logScale = plot.log
        if plot.variable == "met" or plot.variable == "type1Met" or plot.variable == "tcMet" or plot.variable == "caloMet" or plot.variable == "mht":
            logScale = True

        yMax = histEE.GetBinContent(
            histEE.GetMaximumBin()) + histMM.GetBinContent(
                histMM.GetMaximumBin())

        if logScale:
            yMax = yMax * 1.5
        else:
            yMax = yMax * 1.5


#~

        plotPad.DrawFrame(plot.firstBin, plot.yMin, plot.lastBin, yMax,
                          "; %s ; %s" % (plot.xaxis, plot.yaxis))

        histSF = histEE.Clone("histSF")
        histSF.Add(histMM.Clone())

        histSF.SetMarkerStyle(20)
        histOF.SetLineColor(ROOT.kBlue)
        histOF.SetMarkerSize(0)
        histEE.SetLineColor(ROOT.kRed)
        histMM.SetLineColor(ROOT.kGreen + 3)
        histEE.SetLineStyle(ROOT.kDashed)
        histMM.SetLineStyle(ROOT.kDashed)

        histSF.Draw("samep")
        histOF.Draw("samehiste")
        histEE.Draw("samehist")
        histMM.Draw("samehist")

        latex = ROOT.TLatex()
        latex.SetTextSize(0.04)
        latex.SetNDC(True)

        legend = TLegend(0.5, 0.55, 0.95, 0.9)
        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        entryHist = TH1F()
        entryHist.SetFillColor(ROOT.kWhite)
        legend.AddEntry(entryHist, selection.latex, "h")
        legend.AddEntry(histSF, "SF", "p")
        legend.AddEntry(histEE, "EE", "l")
        legend.AddEntry(histMM, "MM", "l")
        legend.AddEntry(histOF, "OF", "l")

        legend.Draw("same")

        latex = ROOT.TLatex()
        latex.SetTextFont(42)
        latex.SetNDC(True)
        latex.SetTextAlign(31)
        latex.SetTextSize(0.04)

        latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (8 TeV)" % runRange.printval)

        latexCMS = ROOT.TLatex()
        latexCMS.SetTextFont(61)
        latexCMS.SetTextSize(0.06)
        latexCMS.SetNDC(True)
        latexCMSExtra = ROOT.TLatex()
        latexCMSExtra.SetTextFont(52)
        latexCMSExtra.SetTextSize(0.045)
        latexCMSExtra.SetNDC(True)

        latexCMS.DrawLatex(0.19, 0.88, "CMS")
        if "Simulation" in cmsExtra:
            yLabelPos = 0.81
        else:
            yLabelPos = 0.84

        latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra))

        plotPad.RedrawAxis()
        hCanvas.Print("fig/nonPromptMC_%s_%s_%s_%s.pdf" %
                      (selection.name, runRange.label, plot.variablePlotName,
                       plot.additionalName))