Пример #1
0
def getCorrelation(selection, background, var1, var2):
    from centralConfig import runRanges

    first = False

    histSFAll = None

    first = True
    for runRangeName in runRanges.allNames:
        runRange = getRunRange(runRangeName)
        path = locations[runRange.era].dataSetPathNLL

        plot = getPlot(var1)
        plot.addRegion(selection)
        plot.addRunRange(runRange)

        plot2 = getPlot(var2)
        plot2.addRegion(selection)
        plot2.addRunRange(runRange)

        histSF = getHistogram(path, plot, plot2, runRange, background)

        if first:
            histSFAll = histSF.Clone()
        else:
            histSFAll.Add(histSF, 1.0)

        if first:
            first = False

    return histSFAll.GetCorrelationFactor()
Пример #2
0
def createDistributions(selection, background):
    from centralConfig import runRanges

    first = False

    histSFAll = None

    first = True
    for runRangeName in runRanges.allNames:
        runRange = getRunRange(runRangeName)
        path = locations[runRange.era].dataSetPath

        plot = getPlot("metPlot2D")
        plot.addRegion(selection)
        plot.addRunRange(runRange)

        plot2 = getPlot("nJetsPlot2D")
        plot2.addRegion(selection)
        plot2.addRunRange(runRange)

        histSF = getHistogram(path, plot, plot2, runRange, background)

        if first:
            histSFAll = histSF.Clone()
        else:
            histSFAll.Add(histSF, 1.0)

        if first:
            first = False

    plotDistribution(histSFAll, plot, plot2, background)
Пример #3
0
def main():
	gROOT.SetBatch(True)

	
	histos = ["BB","BE","BBCosPos","BBCSNeg","BECSPos","BECSNeg"]

	labels = ["dimuon_BB","dimuon_BE","dimuon_BBCSPos","dimuon_BBCSNeg","dimuon_BECSPos","dimuon_BECSNeg"]
	
	lambdas = [10,16,22,28,34]
	models = ["ConLL","ConLR","ConRR"]
	#bins = [4,7]
	bins = [4,7,6,5,9,8]

	massPlot = getPlot("massPlotForLimit")
	massPlotSmeared = getPlot("massPlotSmeared")
	massPlotUp = getPlot("massPlotUp")
	massPlotDown = getPlot("massPlotDown")
	massPlotWeighted = getPlot("massPlotWeighted")
	xMax = 5000
	massBins = [400,500,700,1100,1900,3500,xMax]
	massCuts = [400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700,2800,2900,3000,3100,3200,3300,3400,3500]
	
	signalYields = {}
	signalYieldsSingleBin = {}
	
	names = ["default","resolution","scale","ID"]
	
	
	
	massPlots = [massPlot,massPlotSmeared,massPlotUp,massPlotWeighted]
	
	for number, plot in enumerate(massPlots):
		suffix = names[number]
		for i, histo in enumerate(histos):
			label = labels[i]

			for model in models:
				for l in lambdas:
					name = "CITo2Mu_Lam%dTeV%s"%(l,model)
					signal = Process(getattr(Signals,name))
					signalYields["%s_%s"%(name,label)] = {}
					signalYieldsSingleBin["%s_%s"%(name,label)] = {}
					nameDY = "CITo2Mu_Lam100kTeV%s"%(model)
					signalDY = Process(getattr(Signals,nameDY))
					
					sigHist = deepcopy(signal.loadHistogramProjected(plot, bins[i]))
					if histo == "BE":
						sigHist.Add(deepcopy(signal.loadHistogramProjected(plot, 10)))
					if "_BECSPos" in label:
						sigHist.Add(deepcopy(signal.loadHistogramProjected(plot, 12)))
					if "_BECSNeg" in label:
						sigHist.Add(deepcopy(signal.loadHistogramProjected(plot, 11)))
					
					
						
					sigHistDY = deepcopy(signalDY.loadHistogramProjected(plot, bins[i]))
def createEtaDistributions(selection, plotName):
        from centralConfig import runRanges
        
        first = False
        histEEAll = None
        histMMAll = None
        
        
        
        backgrounds = ["TT_Powheg"]
        
        first = True
        for runRangeName in runRanges.allNames:
                runRange = getRunRange(runRangeName)
                path = locations[runRange.era].dataSetPathNonIso
                
                plot = getPlot(plotName)
                plot.addRegion(selection)
                plot.addRunRange(runRange)   
                
                histEE, histMM = getHistograms(path,plot,runRange,backgrounds)
                if first:
                        histEEAll = histEE.Clone()
                        histMMAll = histMM.Clone()
                else:
                        histEEAll.Add(histEE, 1.0)
                        histMMAll.Add(histMM, 1.0)
                
                if first:
                        first = False
                

        
        plotDistribution(histEEAll, histMMAll, plot)
def centralValues(source, path, selection, runRange, isMC, backgrounds):

    if "Central" in selection.name:
        err = systematics.trigger.central.val
    elif "Forward" in selection.name:
        err = systematics.trigger.forward.val
    else:
        err = systematics.trigger.inclusive.val

    #~ print selection
    plot = getPlot("mllPlot")
    plot.addRegion(selection)
    plot.cleanCuts()
    plot.cuts = plot.cuts % runRange.runCut
    plot.firstBin = 20
    plot.lastBin = 10000
    plot.nBins = 1
    plot.cuts = plot.cuts.replace("mll", "p4.M()")
    plot.cuts = plot.cuts.replace("pt > 25", "p4.Pt() > 25")
    plot.cuts = plot.cuts.replace("triggerSummary > 0 &&", "")
    plot.variable = plot.variable.replace("mll", "p4.M()")
    if plot.variable == "pt":
        plot.variable = plot.variable.replace("pt", "p4.Pt()")

    counts = {runRange.label: {}}

    denominators, nominators = getHistograms(path, plot, runRange, isMC,
                                             backgrounds, source)

    counts[runRange.label]["EE"] = getEfficiency(nominators["EE"],
                                                 denominators["EE"], plot.cuts)
    counts[runRange.label]["MuMu"] = getEfficiency(nominators["MuMu"],
                                                   denominators["MuMu"],
                                                   plot.cuts)
    counts[runRange.label]["EMu"] = getEfficiency(nominators["MuEG"],
                                                  denominators["MuEG"],
                                                  plot.cuts)
    counts[runRange.label]["RT"] = (
        counts[runRange.label]["EE"]["Efficiency"] *
        counts[runRange.label]["MuMu"]["Efficiency"]
    )**0.5 / counts[runRange.label]["EMu"]["Efficiency"]
    counts[runRange.label]["RTErrSyst"] = counts[runRange.label]["RT"] * (
        err**2 /
        (2 * counts[runRange.label]["MuMu"]["Efficiency"])**2 + err**2 /
        (2 * counts[runRange.label]["EE"]["Efficiency"])**2 + err**2 /
        (counts[runRange.label]["EMu"]["Efficiency"])**2)**0.5
    counts[runRange.label]["RTErrStat"] = counts[runRange.label]["RT"] * (
        max(counts[runRange.label]["EE"]["UncertaintyUp"],
            counts[runRange.label]["EE"]["UncertaintyDown"])**2 /
        (2 * counts[runRange.label]["EE"]["Efficiency"])**2 +
        max(counts[runRange.label]["MuMu"]["UncertaintyUp"],
            counts[runRange.label]["MuMu"]["UncertaintyDown"])**2 /
        (2 * counts[runRange.label]["MuMu"]["Efficiency"])**2 +
        max(counts[runRange.label]["EMu"]["UncertaintyUp"],
            counts[runRange.label]["EMu"]["UncertaintyDown"])**2 /
        (counts[runRange.label]["EMu"]["Efficiency"])**2)**0.5

    return counts
Пример #6
0
def cutAndCountForRegion(path,baseTreePath,selection,plots,runRange,isMC,backgrounds):
	
	#~ path = "/home/jan/Trees/sw7412v2000Trigger/"
	
	if not isMC:
		trees = getDataTrees(path)
		for label, tree in trees.iteritems():
			trees[label] = tree.CopyTree("nJets > 1")		
	else:
		treesEE = readTrees(path,"EE",source = "",modifier= "")
		treesEM = readTrees(path,"EMu",source = "",modifier= "")
		treesMM = readTrees(path,"MuMu",source = "",modifier= "")		
		trees = {
				"EE":treesEE,
				"MM":treesMM,
				"EM":treesEM,
		}
		
		

	for plotName in plots:
		plot = getPlot(plotName)
		plot.addRegion(selection)
		plot.cleanCuts()
		plot.cuts = plot.cuts % runRange.runCut	

		counts = {}
		eventLists = {}
		#~ massRanges = ["default","edgeMass","zMass","highMass","belowZ","aboveZ"]
		massRanges = ["default","edgeMass","lowMass","zMass","highMass"]
		nLLRegions = ["lowNLL","highNLL"]
		
		counts["default"] = {}
		eventLists["default"] = {}
		for mllCut in massRanges:
			cut = plot.cuts+" && (%s)"%getattr(theCuts.massCuts,mllCut).cut
			cut = cut.replace("p4.M()","mll")
			cut = cut.replace("genWeight*weight*","")
			#~ cut = "genWeight*weight*("+cut+")"
			counts["default"][getattr(theCuts.massCuts,mllCut).name] = getCounts(trees, cut,isMC,backgrounds,plot,runRange,baseTreePath)
			eventLists["default"][getattr(theCuts.massCuts,mllCut).name] = getEventLists(trees,cut,isMC)		

		for nLLRegion in nLLRegions:		
			counts[nLLRegion] = {}
			eventLists[nLLRegion] = {}					
			
			for mllCut in massRanges:
				cut = plot.cuts+" && (%s)"%getattr(theCuts.nLLCuts,nLLRegion).cut
				cut = cut + " && (%s)"%getattr(theCuts.massCuts,mllCut).cut
				cut = cut.replace("p4.M()","mll")
				cut = cut.replace("genWeight*weight*","")
				#~ cut = "genWeight*weight*("+cut+")"
				counts[nLLRegion][getattr(theCuts.massCuts,mllCut).name] = getCounts(trees, cut,isMC,backgrounds,plot,runRange,baseTreePath)
				eventLists[nLLRegion][getattr(theCuts.massCuts,mllCut).name] = getEventLists(trees, cut,isMC)				

		
		return counts, eventLists
def main():

    selections = []
    selections.append("Inclusive")

    path = locations.dataSetPathTrigger

    #~ f = ROOT.TFile("weights_Run2015_25ns.root","recreate")
    f = ROOT.TFile("data_PU_25ns.root", "recreate")
    f.cd()

    histo = TH1F("pileup", "pileup", 60, 0, 60)

    runRange = getRunRange("Run2015_25ns")
    result = {}

    weights = []
    weightSum = 0
    for selectionName in selections:

        selection = getRegion(selectionName)

        plot = getPlot("nVtxPlotWeights")
        plot.addRegion(selection)
        plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut

        histEEMC, histMMMC, histEMMC = getHistograms(path, plot, runRange,
                                                     True, [], "")
        histEE, histMM, histEM = getHistograms(path, plot, runRange, False, [],
                                               "")

        histEE.Add(histMM)
        histEEMC.Add(histMMMC)
        print histEE.GetEntries(), histEEMC.GetEntries()
        histEE.Scale(1. / histEE.GetEntries())
        histEEMC.Scale(1. / histEEMC.Integral())

        for i in range(0, histEE.GetNbinsX() + 1):
            if histEEMC.GetBinContent(i) > 0:
                histo.SetBinContent(i, float(histEE.GetBinContent(i)))
                weights.append(
                    float(histEE.GetBinContent(i)) / histEEMC.GetBinContent(i))
                weightSum += (float(histEE.GetBinContent(i)) /
                              histEEMC.GetBinContent(i))
            else:
                histo.SetBinContent(i, float(histEE.GetBinContent(i)))
                weights.append(1)
                weightSum += 1

        print weights
        print weightSum

    f.Write()
    f.Close()
def createDRDistributions(selection, mllCut=True):
        from centralConfig import runRanges
        
        first = False
        histEEAll = None
        histMMAll = None
        
        
        
        backgrounds = ["TT_Powheg"]
        
        first = True
        for runRangeName in runRanges.allNames:
                runRange = getRunRange(runRangeName)
                path = locations[runRange.era].dataSetPath
                
                plot = getPlot("deltaRPlot")
                plot.addRegion(selection)
                plot.addRunRange(runRange)   
                
                plot.cuts = plot.cuts.replace("deltaR > 0.1 &&", "")
                if not mllCut:
                        plot.cuts = plot.cuts.replace("mll > 20 &&", "")
                print plot.cuts
                
                histEE, histMM = getHistograms(path,plot,runRange,backgrounds)
                if first:
                        histEEAll = histEE.Clone()
                        histMMAll = histMM.Clone()
                else:
                        histEEAll.Add(histEE, 1.0)
                        histMMAll.Add(histMM, 1.0)
                
                if first:
                        first = False
                

        
        plotDistribution(histEEAll, histMMAll, plot, mllCut)
Пример #9
0
def centralValues(path, selection, runRange, isMC, backgrounds):

    plot = getPlot("mllPlot")
    plot.addRegion(selection)
    #~ plot.cleanCuts()
    plot.cuts = plot.cuts % runRange.runCut

    if not "Forward" in selection.name:
        relSyst = systematics.rMuE.central.val
        if "Central" in selection.name:
            region = "central"
        else:
            region = "inclusive"
    else:
        relSyst = systematics.rMuE.forward.val
        region = "forward"

    histEE, histMM = getHistograms(path, plot, runRange, isMC, backgrounds,
                                   region)

    nEE = histEE.Integral()
    nMM = histMM.Integral()

    rMuE = pow(nMM / nEE, 0.5)

    rMuEStatErr = 0.5 * rMuE * (1. / nMM + 1. / nEE)**0.5
    rMuESystErr = rMuE * relSyst

    result = {}
    result["nEE"] = nEE
    result["nMM"] = nMM
    result["rMuE"] = rMuE
    result["rMuEStatErr"] = rMuEStatErr
    result["rMuESystErr"] = rMuESystErr

    return result
Пример #10
0
def main():

    selections = []
    selections.append(regionsToUse.rOutIn.central.name)
    selections.append(regionsToUse.rOutIn.forward.name)

    path = locations.dataSetPath

    runRange = getRunRange("Full2012")
    result = {}
    for selectionName in selections:

        selection = getRegion(selectionName)

        plot = getPlot("mllPlot")
        plot.addRegion(selection)
        plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut
        cuts = plot.cuts
        plot.cuts = plot.cuts + "*(nVertices < 13)"
        histEE, histMM, histEM = getHistograms(path, plot, runRange, False, [],
                                               "")

        print histEE.GetEntries(), histMM.GetEntries(), histEM.GetEntries()
        plot.cuts = cuts
        plot.cuts = plot.cuts + "*(nVertices >= 13 && nVertices < 17)"
        histEE, histMM, histEM = getHistograms(path, plot, runRange, False, [],
                                               "")

        print histEE.GetEntries(), histMM.GetEntries(), histEM.GetEntries()
        plot.cuts = cuts
        plot.cuts = plot.cuts + "*(nVertices >= 17)"
        histEE, histMM, histEM = getHistograms(path, plot, runRange, False, [],
                                               "")

        print histEE.GetEntries(), histMM.GetEntries(), histEM.GetEntries()
Пример #11
0
	from ROOT import TGraphAsymmErrors

	from locations import locations

	import ratios
	
	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
Пример #12
0
        elif args.do2018:
            addLabel = "_2018"
        # ~ for intfe in intfs:
        # ~ for heli in helis:
        plotName = antype[2] + etabin + 'nominal'
        plotNameScaleUp = antype[2] + etabin + 'scaleup'
        plotNameScaleDown = antype[2] + etabin + 'scaledown'
        if antype[2] == 'Ele':
            plotNamePUUp = antype[2] + etabin + 'pileup'
            plotNamePUDown = antype[2] + etabin + 'piledown'
        if antype[2] == 'Mu':
            plotNameSmear = antype[2] + etabin + 'smeared'
            plotNameWeighted = antype[2] + etabin + 'muonid'
        if not csbin == "inc":
            plotName = antype[2] + etabin + unc + csbin
        plot = getPlot(plots[plotName])

        plotScaleUp = getPlot(plots[plotNameScaleUp])
        plotScaleDown = getPlot(plots[plotNameScaleDown])
        if antype[2] == 'Ele':
            plotPUUp = getPlot(plots[plotNamePUUp])
            plotPUDown = getPlot(plots[plotNamePUDown])
        if antype[2] == 'Mu':
            plotWeigthed = getPlot(plots[plotNameWeighted])
            plotSmeared = getPlot(plots[plotNameSmear])

        eventCounts = totalNumberOfGeneratedEvents(path, plot.muon)
        negWeights = negWeightFractions(path, plot.muon)
        if args.do2016:
            lumi = 35.9 * 1000
            if plot.muon:
Пример #13
0
def main():
    ### for data

    histos = ["BB", "BE", "BB", "BE", "BB", "BE"]
    labels = [
        "dielectron_2016_BB", "dielectron_2016_BE", "dielectron_2017_BB",
        "dielectron_2017_BE", "dielectron_2018_BB", "dielectron_2018_BE"
    ]

    css = ["inc", "cspos", "csneg"]
    for cs in css:
        for i, histo in enumerate(histos):
            label = labels[i]
            if cs == "cspos":
                massPlot = getPlot("massPlotEle%sCSPosNoLog" % histo)
                massPlotUp = getPlot("massPlotEle%sScaleUpCSPosNoLog" % histo)
                massPlotDown = getPlot("massPlotEle%sScaleDownCSPosNoLog" %
                                       histo)
                massPlotPUUp = getPlot("massPlotEle%sPUScaleUpCSPosNoLog" %
                                       histo)
                massPlotPUDown = getPlot("massPlotEle%sPUScaleDownCSPosNoLog" %
                                         histo)
            elif cs == "csneg":
                massPlot = getPlot("massPlotEle%sCSNegNoLog" % histo)
                massPlotUp = getPlot("massPlotEle%sScaleUpCSNegNoLog" % histo)
                massPlotDown = getPlot("massPlotEle%sScaleDownCSNegNoLog" %
                                       histo)
                massPlotPUUp = getPlot("massPlotEle%sPUScaleUpCSNegNoLog" %
                                       histo)
                massPlotPUDown = getPlot("massPlotEle%sPUScaleDownCSNegNoLog" %
                                         histo)
            else:
                massPlot = getPlot("massPlotEle%sNoLog" % histo)
                massPlotUp = getPlot("massPlotEle%sScaleUpNoLog" % histo)
                massPlotDown = getPlot("massPlotEle%sScaleDownNoLog" % histo)
                massPlotPUUp = getPlot("massPlotEle%sPUScaleUpNoLog" % histo)
                massPlotPUDown = getPlot("massPlotEle%sPUScaleDownNoLog" %
                                         histo)
            eventCounts = totalNumberOfGeneratedEvents(path, massPlot.muon)
            negWeights = negWeightFractions(path, massPlot.muon)

            if "2016" in label:
                data = Process(Data2016, normalized=True)
                drellyan = Process(getattr(Backgrounds2016, "DrellYan"),
                                   eventCounts, negWeights)
                other = Process(getattr(Backgrounds2016, "Other"), eventCounts,
                                negWeights)
                jets = Process(getattr(Backgrounds2016, "Jets"),
                               eventCounts,
                               negWeights,
                               normalized=True)
            elif "2018" in label:
                data = Process(Data2018, normalized=True)
                drellyan = Process(getattr(Backgrounds2018, "DrellYan"),
                                   eventCounts, negWeights)
                other = Process(getattr(Backgrounds2018, "Other"), eventCounts,
                                negWeights)
                jets = Process(getattr(Backgrounds2018, "Jets"),
                               eventCounts,
                               negWeights,
                               normalized=True)
            else:
                data = Process(Data, normalized=True)
                drellyan = Process(getattr(Backgrounds, "DrellYan"),
                                   eventCounts, negWeights)
                other = Process(getattr(Backgrounds, "Other"), eventCounts,
                                negWeights)
                jets = Process(getattr(Backgrounds, "Jets"),
                               eventCounts,
                               negWeights,
                               normalized=True)

            if cs == "inc":
                fResult = TFile("inputsCI_%s.root" % (label), "RECREATE")
            else:
                fResult = TFile("inputsCI_%s_%s.root" % (cs, label),
                                "RECREATE")

            if "2016" in label:
                lumi = 35.9 * 1000
                if "bbbe" in massPlot.histName:
                    zScaleFac = zScale2016["electrons"][0]
                elif "bb" in massPlot.histName:
                    zScaleFac = zScale2016["electrons"][1]
                elif "be" in massPlot.histName:
                    zScaleFac = zScale2016["electrons"][2]
                else:
                    zScaleFac = zScale2016["electrons"][0]

            elif "2018" in label:
                lumi = 59.97 * 1000
                if "bbbe" in massPlot.histName:
                    zScaleFac = zScale2018["electrons"][0]
                elif "bb" in massPlot.histName:
                    zScaleFac = zScale2018["electrons"][1]
                elif "be" in massPlot.histName:
                    zScaleFac = zScale2018["electrons"][2]
                else:
                    zScaleFac = zScale2018["electrons"][0]
            else:
                lumi = 41.529 * 1000
                if "bbbe" in massPlot.histName:
                    zScaleFac = zScale["electrons"][0]
                elif "bb" in massPlot.histName:
                    zScaleFac = zScale["electrons"][1]
                elif "be" in massPlot.histName:
                    zScaleFac = zScale["electrons"][2]
                else:
                    zScaleFac = zScale["electrons"][0]

            jetHist = deepcopy(jets.loadHistogram(massPlot, lumi, zScaleFac))
            hist = data.loadHistogram(massPlot, lumi, zScaleFac)
            if cs == "inc":
                hist.SetName("dataHist_%s" % (label))
            else:
                hist.SetName("dataHist_%s_%s" % (cs, label))

            dyHist = deepcopy(drellyan.loadHistogram(massPlot, lumi,
                                                     zScaleFac))
            dyHistScaleUp = deepcopy(
                drellyan.loadHistogram(massPlotUp, lumi, zScaleFac))
            dyHistScaleDown = deepcopy(
                drellyan.loadHistogram(massPlotDown, lumi, zScaleFac))
            dyHistPUUp = deepcopy(
                drellyan.loadHistogram(massPlotPUUp, lumi, zScaleFac))
            dyHistPUDown = deepcopy(
                drellyan.loadHistogram(massPlotPUDown, lumi, zScaleFac))

            otherHist = deepcopy(other.loadHistogram(massPlot, lumi,
                                                     zScaleFac))
            otherHistScaleUp = deepcopy(
                other.loadHistogram(massPlotUp, lumi, zScaleFac))
            otherHistScaleDown = deepcopy(
                other.loadHistogram(massPlotDown, lumi, zScaleFac))
            otherHistPUUp = deepcopy(
                other.loadHistogram(massPlotPUUp, lumi, zScaleFac))
            otherHistPUDown = deepcopy(
                other.loadHistogram(massPlotPUDown, lumi, zScaleFac))
            if cs == "inc":
                dyHist.SetName("bkgHistDY_%s" % label)
                dyHistScaleUp.SetName("bkgHistDYScaleUp_%s" % label)
                dyHistScaleDown.SetName("bkgHistDYScaleDown_%s" % label)
                dyHistPUUp.SetName("bkgHistDYPUUp_%s" % label)
                dyHistPUDown.SetName("bkgHistDYPUDown_%s" % label)
                otherHist.SetName("bkgHistOther_%s" % label)
                otherHistScaleUp.SetName("bkgHistOtherScaleUp_%s" % label)
                otherHistScaleDown.SetName("bkgHistOtherScaleDown_%s" % label)
                otherHistPUUp.SetName("bkgHistOtherPUUp_%s" % label)
                otherHistPUDown.SetName("bkgHistOtherPUDown_%s" % label)
            else:
                dyHist.SetName("bkgHistDY_%s_%s" % (cs, label))
                dyHistScaleUp.SetName("bkgHistDYScaleUp_%s_%s" % (cs, label))
                dyHistScaleDown.SetName("bkgHistDYScaleDown_%s_%s" %
                                        (cs, label))
                dyHistPUUp.SetName("bkgHistDYPUUp_%s_%s" % (cs, label))
                dyHistPUDown.SetName("bkgHistDYPUDown_%s_%s" % (cs, label))
                otherHist.SetName("bkgHistOther_%s_%s" % (cs, label))
                otherHistScaleUp.SetName("bkgHistOtherScaleUp_%s_%s" %
                                         (cs, label))
                otherHistScaleDown.SetName("bkgHistOtherScaleDown_%s_%s" %
                                           (cs, label))
                otherHistPUUp.SetName("bkgHistOtherPUUp_%s_%s" % (cs, label))
                otherHistPUDown.SetName("bkgHistOtherPUDown_%s_%s" %
                                        (cs, label))

            if not cs == "inc":
                jetHist.SetName("bkgHistJets_%s_%s" % (cs, label))
            else:
                jetHist.SetName("bkgHistJets_%s" % label)
            jetHist.SetDirectory(fResult)

            dyHist.SetDirectory(fResult)
            dyHistScaleUp.SetDirectory(fResult)
            dyHistScaleDown.SetDirectory(fResult)
            dyHistPUUp.SetDirectory(fResult)
            dyHistPUDown.SetDirectory(fResult)
            otherHist.SetDirectory(fResult)
            otherHistScaleUp.SetDirectory(fResult)
            otherHistScaleDown.SetDirectory(fResult)
            otherHistPUUp.SetDirectory(fResult)
            otherHistPUDown.SetDirectory(fResult)
            hist.SetDirectory(fResult)

            fResult.Write()
            fResult.Close()
Пример #14
0
                        for point in extrabins:
                            params["{0:s}{1:s}_{2:d}GeV".format(
                                intf, heli,
                                point)] = [0. for j in range(len(lvals))]
                            params["{0:s}{1:s}_{2:d}GeV_err".format(
                                intf, heli,
                                point)] = [0. for j in range(len(lvals))]
                            pass
                        for i, lval in enumerate(lvals):
                            hist = None
                            can = r.TCanvas("can", "", 800, 800)
                            stack = r.THStack("stack", "")
                            plotName = antype[2] + etabin + unc
                            if not csbin == "inc":
                                plotName = antype[2] + etabin + unc + csbin
                            plot = getPlot(plots[plotName])

                            eventCounts = totalNumberOfGeneratedEvents(
                                path, plot.muon)
                            negWeights = negWeightFractions(path, plot.muon)
                            if args.do2016:
                                lumi = 35.9 * 1000
                                if plot.muon:
                                    lumi = 36.3 * 1000
                            elif args.do2018:
                                lumi = 59.4 * 1000
                                if plot.muon:
                                    lumi = 61.3 * 1000
                            else:
                                lumi = 41.529 * 1000
                                if plot.muon:
Пример #15
0
def countEvents(selection):
    from centralConfig import runRanges

    first = False

    dataEEAll = None
    dataMMAll = None
    dataSFAll = None

    backgrounds = [
        "Rare", "SingleTop", "TT_Powheg", "Diboson", "DrellYanTauTau",
        "DrellYan"
    ]

    histEEAll = {}
    histMMAll = {}
    histSFAll = {}
    for backgroundName in backgrounds:
        histEEAll[backgroundName] = None
        histMMAll[backgroundName] = None
        histSFAll[backgroundName] = None

    first = True
    for runRangeName in runRanges.allNames:
        runRange = getRunRange(runRangeName)
        plot = getPlot("mllPlot")
        plot.addRegion(selection)
        plot.addRunRange(runRange)

        if "met > 150" in plot.cuts or "met > 100" in plot.cuts:
            path = locations[runRange.era].dataSetPathNLL
        else:
            path = locations[runRange.era].dataSetPath

        dataEE, dataMM = getHistograms(path, plot, runRange, False,
                                       backgrounds)
        if first:
            dataEEAll = dataEE.Clone()
            dataMMAll = dataMM.Clone()
        else:
            dataEEAll.Add(dataEE, 1.0)
            dataMMAll.Add(dataMM, 1.0)

        for backgroundName in backgrounds:
            histEE, histMM = getHistograms(path, plot, runRange, True, [
                backgroundName,
            ])

            if first:
                histEEAll[backgroundName] = histEE.Clone()
                histMMAll[backgroundName] = histMM.Clone()
            else:
                histEEAll[backgroundName].Add(histEE, 1.0)
                histMMAll[backgroundName].Add(histMM, 1.0)
        if first:
            first = False

    dataSFAll = dataEEAll.Clone()
    dataSFAll.Add(dataMMAll, 1.0)

    firstProc = True
    histMCSFAll = None
    histMCEEAll = None
    histMCMMAll = None

    for backgroundName in backgrounds:
        histSFAll[backgroundName] = histEEAll[backgroundName].Clone()
        histSFAll[backgroundName].Add(histMMAll[backgroundName], 1.0)

        if firstProc:
            histMCSFAll = histSFAll[backgroundName].Clone()
            histMCEEAll = histEEAll[backgroundName].Clone()
            histMCMMAll = histMMAll[backgroundName].Clone()
            firstProc = False
        else:
            histMCSFAll.Add(histSFAll[backgroundName].Clone(), 1)
            histMCEEAll.Add(histEEAll[backgroundName].Clone(), 1)
            histMCMMAll.Add(histMMAll[backgroundName].Clone(), 1)

    print "Data: "
    print "EE: ", dataEEAll.Integral()
    print "MM: ", dataMMAll.Integral()
    print "SF: ", dataSFAll.Integral()
    print ""
    print "MC: "
    print "EE: ", histMCEEAll.Integral()
    print "MM: ", histMCMMAll.Integral()
    print "SF: ", histMCSFAll.Integral()
    for backgroundName in backgrounds:
        print ""
        print backgroundName
        print "EE: ", histEEAll[backgroundName].Integral(
        ), histEEAll[backgroundName].Integral() / histMCEEAll.Integral()
        print "MM: ", histMMAll[backgroundName].Integral(
        ), histMMAll[backgroundName].Integral() / histMCMMAll.Integral()
        print "SF: ", histSFAll[backgroundName].Integral(
        ), histSFAll[backgroundName].Integral() / histMCSFAll.Integral()
Пример #16
0
    if len(args.backgrounds) == 0:
        #args.backgrounds = ["Wjets","Other","DrellYan"]
        #~ args.backgrounds = ["Diboson","DrellYan"]
        args.backgrounds = ["Jets"]

    if len(args.signals) != 0:
        args.plotSignal = True
    '''if args.plot == "":
		args.plot = plotList
	'''
    muplots = ["massPlotBB", "massPlotBE"]
    elplots = ["massPlotEleBB", "massPlotEleBE"]
    signals = args.signals
    for i in range(len(muplots)):
        args.signals = signals
        plot_mu = getPlot(muplots[i])
        plot_el = getPlot(elplots[i])
        #plot_mu.logX = False
        #plot_el.logX = False
        '''if len(args.signals) > 0:
			#~ if ("To2E" in args.signals[0] and plotObject.muon) or ("To2Mu" in args.signals[0] and not plotObject.muon):
			args.signals = []
			if plotObject.muon:
				for signal in signals:
					if args.ADD: args.signals.append("ADDGravTo2Mu_"+signal)
					else: args.signals.append("CITo2Mu_"+signal)
			else:
				for signal in signals:
					if args.ADD: args.signals.append("ADDGravTo2E_"+signal)
					else: args.signals.append("CITo2E_"+signal)
		'''
def cutAndCountForRegion(path,
                         selection,
                         plots,
                         runRange,
                         isMC,
                         backgrounds,
                         blind=False):

    if not isMC:
        trees = getDataTrees(path)
        for label, tree in trees.iteritems():
            trees[label] = tree.CopyTree("nJets > 1")
    else:
        treesEE = readTrees(path, "EE", source="", modifier="")
        treesEM = readTrees(path, "EMu", source="", modifier="")
        treesMM = readTrees(path, "MuMu", source="", modifier="")
        trees = {
            "EE": treesEE,
            "MM": treesMM,
            "EM": treesEM,
        }

    for plotName in plots:
        plot = getPlot(plotName)
        plot.addRegion(selection)
        plot.cleanCuts()
        plot.addRunRange(runRange)
        #plot.cuts = plot.cuts % runRange.runCut

        counts = {}
        eventLists = {}
        # ,"highMassOld","highMass","lowMass","lowMassOld", "mass60To81", "mass81To101", "mass101To150",
        massBins = [
            "mass20To60", "mass60To86", "mass86To96", "mass96To150",
            "mass150To200", "mass200To300", "mass300To400", "mass400"
        ]
        nLLRegions = ["lowNLL", "highNLL"]
        MT2Regions = ["highMT2"]  # "lowMT2",
        nBJetsRegions = ["zeroBJets", "oneOrMoreBJets"]

        counts["default"] = {}
        eventLists["default"] = {}

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

        standardCut = plot.cuts
        #for mllCut in massBins:
        #        cut = standardCut + " && (%s)"%getattr(theCuts.massCuts,mllCut).cut
        #        cut = cut + " && (met / caloMet < 5. && nBadMuonJets == 0)"
        #        #~ cut = cut + " && (met / caloMet > 5. && nBadMuonJets > 0)" ### Inverse bad muon cuts
        #        if not (mllCut == "highMassOld" or mllCut == "lowMassOld"):
        #                cut = cut+" && (abs(deltaPhiJetMet1) > 0.4 && abs(deltaPhiJetMet2) > 0.4)"
        #        cut = cut.replace("p4.M()","mll")
        #        cut = cut.replace("p4.Pt()","pt")
        #        cut = cut.replace("metFilterSummary > 0 &&","")
        #        cut = cut.replace("&& metFilterSummary > 0","")
        #        cut = cut.replace("triggerSummary > 0 &&","")
        #        cut = cut.replace("genWeight*","")
        #        cut = cut.replace("prefireWeight*","")
        #        cut = cut.replace("weight*","")
        #        cut = cut.replace("leptonFullSimScaleFactor1*","")
        #        cut = cut.replace("leptonFullSimScaleFactor2*","")
        #        cut = "leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*("+cut+")"
        #        if runRange.era != "2018":
        #                cut = "prefireWeight*"+cut
        #        #~ cut = "genWeight*weight*("+cut+")"
        #
        #
        #        counts["default"][getattr(theCuts.massCuts,mllCut).name] = getCounts(trees, cut,isMC,backgrounds,plot,runRange,path, blind)
        #        #~ eventLists["default"][getattr(theCuts.massCuts,mllCut).name] = getEventLists(trees,cut,isMC)

        for nLLRegion in nLLRegions:
            counts[nLLRegion] = {}
            eventLists[nLLRegion] = {}

            #for mllCut in massBins:
            #        cut = standardCut+" && (%s)"%getattr(theCuts.nLLCuts,nLLRegion).cut
            #        cut = cut + " && (%s)"%getattr(theCuts.massCuts,mllCut).cut
            #        cut = cut + " && (met / caloMet < 5. && nBadMuonJets == 0)"
            #        #~ cut = cut + " && (met / caloMet > 5. && nBadMuonJets > 0)" ### Inverse bad muon cuts
            #        if not (mllCut == "highMassOld" or mllCut == "lowMassOld"):
            #                cut = cut+" && (abs(deltaPhiJetMet1) > 0.4 && abs(deltaPhiJetMet2) > 0.4)"
            #        cut = cut.replace("p4.M()","mll")
            #        cut = cut.replace("p4.Pt()","pt")
            #        cut = cut.replace("metFilterSummary > 0 &&","")
            #        cut = cut.replace("&& metFilterSummary > 0","")
            #        cut = cut.replace("triggerSummary > 0 &&","")
            #        cut = cut.replace("genWeight*","")
            #        cut = cut.replace("prefireWeight*","")
            #        cut = cut.replace("weight*","")
            #        cut = cut.replace("leptonFullSimScaleFactor1*","")
            #        cut = cut.replace("leptonFullSimScaleFactor2*","")
            #        cut = "leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*("+cut+")"
            #        if runRange.era != "2018":
            #                cut = "prefireWeight*"+cut
            #        #~ cut = "genWeight*weight*("+cut+")"
            #
            #        counts[nLLRegion][getattr(theCuts.massCuts,mllCut).name] = getCounts(trees, cut,isMC,backgrounds,plot,runRange,path, blind)

            for MT2Region in MT2Regions:
                for mllCut in massBins:
                    cut = standardCut + " && (%s)" % getattr(
                        theCuts.nLLCuts, nLLRegion).cut
                    cut = cut + " && (%s)" % getattr(theCuts.mt2Cuts,
                                                     MT2Region).cut
                    cut = cut + " && (%s)" % getattr(theCuts.massCuts,
                                                     mllCut).cut
                    cut = cut + " && (met / caloMet < 5. && nBadMuonJets == 0)"
                    #~ cut = cut + " && (met / caloMet > 5. && nBadMuonJets > 0)" ### Inverse bad muon cuts
                    if not (mllCut == "highMassOld" or mllCut == "lowMassOld"):
                        cut = cut + " && (abs(deltaPhiJetMet1) > 0.4 && abs(deltaPhiJetMet2) > 0.4)"
                    cut = cut.replace("p4.M()", "mll")
                    cut = cut.replace("p4.Pt()", "pt")
                    cut = cut.replace("metFilterSummary > 0 &&", "")
                    cut = cut.replace("&& metFilterSummary > 0", "")
                    cut = cut.replace("triggerSummary > 0 &&", "")
                    cut = cut.replace("genWeight*", "")
                    cut = cut.replace("prefireWeight*", "")
                    cut = cut.replace("weight*", "")
                    cut = cut.replace("leptonFullSimScaleFactor1*", "")
                    cut = cut.replace("leptonFullSimScaleFactor2*", "")
                    cut = "leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*(" + cut + ")"
                    if runRange.era != "2018":
                        cut = "prefireWeight*" + cut
                    #~ cut = "genWeight*weight*("+cut+")"

                    counts[nLLRegion][
                        getattr(theCuts.mt2Cuts, MT2Region).name + "_" +
                        getattr(theCuts.massCuts, mllCut).name] = getCounts(
                            trees, cut, isMC, backgrounds, plot, runRange,
                            path, blind)

            for MT2Region in MT2Regions:
                for nBJetsRegion in nBJetsRegions:
                    for mllCut in massBins:
                        cut = standardCut + " && (%s)" % getattr(
                            theCuts.nLLCuts, nLLRegion).cut
                        cut = cut + " && (%s)" % getattr(
                            theCuts.nBJetsCuts, nBJetsRegion).cut
                        cut = cut + " && (%s)" % getattr(
                            theCuts.mt2Cuts, MT2Region).cut
                        cut = cut + " && (%s)" % getattr(
                            theCuts.massCuts, mllCut).cut
                        cut = cut + " && (met / caloMet < 5. && nBadMuonJets == 0)"
                        #~ cut = cut + " && (met / caloMet > 5. && nBadMuonJets > 0)" ### Inverse bad muon cuts
                        if not (mllCut == "highMassOld"
                                or mllCut == "lowMassOld"):
                            cut = cut + " && (abs(deltaPhiJetMet1) > 0.4 && abs(deltaPhiJetMet2) > 0.4)"
                        cut = cut.replace("p4.M()", "mll")
                        cut = cut.replace("p4.Pt()", "pt")
                        cut = cut.replace("metFilterSummary > 0 &&", "")
                        cut = cut.replace("&& metFilterSummary > 0", "")
                        cut = cut.replace("triggerSummary > 0 &&", "")
                        cut = cut.replace("genWeight*", "")
                        cut = cut.replace("prefireWeight*", "")
                        cut = cut.replace("weight*", "")
                        cut = cut.replace("leptonFullSimScaleFactor1*", "")
                        cut = cut.replace("leptonFullSimScaleFactor2*", "")
                        cut = "leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*(" + cut + ")"
                        if runRange.era != "2018":
                            cut = "prefireWeight*" + cut
                        #~ cut = "genWeight*weight*("+cut+")"

                        counts[nLLRegion][
                            getattr(theCuts.mt2Cuts, MT2Region).name + "_" +
                            getattr(theCuts.nBJetsCuts, nBJetsRegion).name +
                            "_" + getattr(
                                theCuts.massCuts, mllCut).name] = getCounts(
                                    trees, cut, isMC, backgrounds, plot,
                                    runRange, path, blind)

        return counts
Пример #18
0
                        help="plot add signals")

    args = parser.parse_args()
    if len(args.backgrounds) == 0:
        args.backgrounds = ["Wjets", "Other", "DrellYan"]
        #~ args.backgrounds = ["Diboson","DrellYan"]

    if len(args.signals) != 0:
        args.plotSignal = True

    if args.plot == "":
        args.plot = plotList

    signals = args.signals
    for plot in args.plot:
        args.signals = signals
        plotObject = getPlot(plot)
        if len(args.signals) > 0:
            #~ if ("To2E" in args.signals[0] and plotObject.muon) or ("To2Mu" in args.signals[0] and not plotObject.muon):
            args.signals = []
            if plotObject.muon:
                for signal in signals:
                    if args.ADD: args.signals.append("ADDGravTo2Mu_" + signal)
                    else: args.signals.append("CITo2Mu_" + signal)
            else:
                for signal in signals:
                    if args.ADD: args.signals.append("ADDGravTo2E_" + signal)
                    else: args.signals.append("CITo2E_" + signal)
        #~ print args.plotSignal
        plotDataMC(args, plotObject)
Пример #19
0
def plot(path,selection,plots,runRange,isMC,backgrounds,cmsExtra):
	

	
	for name in plots:
		plot = getPlot(name)
		plot.addRegion(selection)
		plot.cleanCuts()	
		plot.cuts = plot.cuts % runRange.runCut	


		if isMC:
			histEE, histMM = getHistograms(path,plot,runRange,True, backgrounds)	
		else:
			histEE, histMM = getHistograms(path,plot,runRange,False, backgrounds)	
			
		
		hCanvas = TCanvas("hCanvas", "Distribution", 800,800)
		
		plotPad = ROOT.TPad("plotPad","plotPad",0,0,1,1)
		setTDRStyle()
		plotPad.UseCurrentStyle()
		
		plotPad.Draw()	
		plotPad.cd()	
				
			
		latex = ROOT.TLatex()
		latex.SetTextFont(42)
		latex.SetTextAlign(31)
		latex.SetTextSize(0.04)
		latex.SetNDC(True)
		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)		

		intlumi = ROOT.TLatex()
		intlumi.SetTextAlign(12)
		intlumi.SetTextSize(0.03)
		intlumi.SetNDC(True)					
		

		logScale = plot.log

		if logScale == True:
			plotPad.SetLogy()
			
	
		yMax = histMM.GetBinContent(histMM.GetMaximumBin())
		if plot.yMax == 0:
			if logScale:
				yMax = yMax*1000
			else:
				yMax = yMax*1.5
							
		else: yMax = plot.yMax


		plotPad.DrawFrame(plot.firstBin,plot.yMin,plot.lastBin,yMax,"; %s ; %s" %(plot.xaxis,plot.yaxis))
		
		legend = ROOT.TLegend(0.65,0.7,0.9,0.9)
		legend.SetFillStyle(0)
		legend.SetBorderSize(0)	
		legend.AddEntry(histMM,"#mu#mu events","p")
		legend.AddEntry(histEE,"ee events","p")
		histMM.SetMarkerColor(ROOT.kRed)
		histMM.SetLineColor(ROOT.kRed)
		histMM.SetMarkerStyle(20)
		histEE.SetMarkerStyle(21)
		histMM.Draw("samepe")
		histEE.Draw("samepe")
		legend.Draw("same")
		ROOT.gPad.SetLogy(1)
		
		latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)"%runRange.printval)
		

		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))
		
		
		
		hCanvas.Print("fig/testPlots_%s_%s_%s_%s.pdf"%(selection.name,runRange.label,plot.variablePlotName,plot.additionalName))	
Пример #20
0
        def __init__(self,plot,plot2=None,region="Inclusive",runName = "Run2015_25ns",plotData=True,normalizeToData=False,plotRatio=True,signals=None,useTriggerEmulation=False,personalWork=False,doTopReweighting=False,preliminary=True,forPAS=False,forTWIKI=False,backgrounds = [],produceTheoUncert=False,dontScaleTrig=False,plotSyst=False,doPUWeights=False,jzbType = "None",responseCorr = False ,puCorr = False, peakCorr = False, correctMET = True):
                sys.path.append(pathes.basePath)
                if jzbType == "None":
                        jzbType = dataMCConfig.jzbType
                
                self.jzbType = jzbType
                self.prefix = jzbType 
                
                self.responseCorr = responseCorr
                self.puCorr = puCorr
                self.peakCorr = peakCorr
                self.correctMET = correctMET
                 
                self.dataSetPath = locations.dataSetPath
                if dontScaleTrig:
                        self.dataSetPath = locations.dataSetPathTrigger
                self.runRange = getRunRange(runName)
                
                self.selection = getRegion(region)
                
                self.plotData = plotData
                
                plotList = None
                if "#" in plot:
                        plotList = plot.split("#")
                        plot = plotList[0]
                        plotList = plotList[1:]
                
                self.plot = getPlot(plot)
                self.plot.addRegion(self.selection)
                self.plot.cleanCuts()
                self.plot.cuts = self.plot.cuts % self.runRange.runCut
                
                if plotList != None:
                        self.plot.cuts = self.plot.cuts[:-1]
                        for l in plotList:
                                self.plot.cuts = self.plot.cuts + "&& %s"%(cutString[l])
                        self.plot.cuts = self.plot.cuts + ")"
                

                if plot2 != None:
                        plotList = None
                        if "#" in plot2:
                                plotList = plot2.split("#")
                                plot2 = plotList[0]
                                plotList = plotList[1:]
                        
                        self.plot2 = getPlot(plot2)
                        self.plot2.addRegion(self.selection)
                        self.plot2.cleanCuts()
                        self.plot2.cuts = self.plot2.cuts % self.runRange.runCut
                        
                        if plotList != None:
                                self.plot2.cuts = self.plot2.cuts[:-1]
                                for l in plotList:
                                        self.plot2.cuts = self.plot2.cuts + " && %s"%(cutString[l])
                                self.plot2.cuts = self.plot2.cuts + ")"
                
                if "Inclusive" in region:
                        self.direction = "Inclusive"
                elif "Central" in region:
                        self.direction = "Central"
                elif "Forward" in region:
                        self.direction = "Forward"
                
                
                configurePlot(self.plot, self.jzbType, self.plotData, self.direction, self.responseCorr, self.puCorr, self.peakCorr, self.correctMET, self.correctionMode)
                if plot2 != None:
                        configurePlot(self.plot2, self.jzbType, self.plotData, self.direction, self.responseCorr, self.puCorr, self.peakCorr, self.correctMET, self.correctionMode)
                
                self.normalizeToData = normalizeToData
                self.plotRatio = plotRatio
                self.signals = signals
                if self.signals is not None:
                        self.plotSignal = True
                self.backgrounds = backgrounds
                self.useTriggerEmulation = useTriggerEmulation
                self.personalWork = personalWork
                self.preliminary = preliminary
                self.doTopReweighting = doTopReweighting
                self.forPAS = forPAS
                self.forTWIKI = forTWIKI
                self.DontScaleTrig = dontScaleTrig
                self.doPUWeights = doPUWeights
                
                from corrections import rSFOF   
                self.rSFOF = rSFOF
Пример #21
0
        "scale_down": "massPlotEleBBScaleDownNoLog",
        "PU_up": "massPlotEleBBPUScaleUpNoLog",
        "PU_down": "massPlotEleBBPUScaleDownNoLog"
    }
    eleplots_be = {
        "default": "massPlotEleBE",
        "scale_up": "massPlotEleBEScaleUpNoLog",
        "scale_down": "massPlotEleBEScaleDownNoLog",
        "PU_up": "massPlotEleBEPUScaleUpNoLog",
        "PU_down": "massPlotEleBEPUScaleDownNoLog"
    }
    plot_mu_bb = {}
    plot_el_bb = {}
    plot_mu_be = {}
    plot_el_be = {}
    for key in muplots_bb.keys():
        plot_mu_bb[key] = getPlot(muplots_bb[key])
        plot_mu_bb[key].logX = True
    for key in eleplots_bb.keys():
        plot_el_bb[key] = getPlot(eleplots_bb[key])
        plot_el_bb[key].logX = True
    for key in muplots_be.keys():
        plot_mu_be[key] = getPlot(muplots_be[key])
        plot_mu_be[key].logX = True
    for key in eleplots_be.keys():
        plot_el_be[key] = getPlot(eleplots_be[key])
        plot_el_be[key].logX = True

    plotDataMC(args, plot_mu_bb, plot_el_bb)
    plotDataMC(args, plot_mu_be, plot_el_be)
Пример #22
0
def main():
    ### for data

    histos = ["BB", "BE"]
    labels = ["dielectron_2016", "dielectron_2017", "dielectron_2018"]

    css = ["inc", "cspos", "csneg"]
    for cs in css:
        for i, histo in enumerate(histos):
            for label in labels:
                if not histo == "":
                    label += "_" + histo
                if cs == "cspos":
                    massPlot = getPlot("massPlotEle%sCSPosNoLog" % histo)
                    massPlotUp = getPlot("massPlotEle%sScaleUpCSPosNoLog" %
                                         histo)
                    massPlotDown = getPlot("massPlotEle%sScaleDownCSPosNoLog" %
                                           histo)
                    massPlotPUUp = getPlot("massPlotEle%sPUScaleUpCSPosNoLog" %
                                           histo)
                    massPlotPUDown = getPlot(
                        "massPlotEle%sPUScaleDownCSPosNoLog" % histo)
                    massPlotPrefireUp = getPlot(
                        "massPlotEle%sPrefireUpCSPosNoLog" % histo)
                    massPlotPrefireDown = getPlot(
                        "massPlotEle%sPrefireDownCSPosNoLog" % histo)
                elif cs == "csneg":
                    massPlot = getPlot("massPlotEle%sCSNegNoLog" % histo)
                    massPlotUp = getPlot("massPlotEle%sScaleUpCSNegNoLog" %
                                         histo)
                    massPlotDown = getPlot("massPlotEle%sScaleDownCSNegNoLog" %
                                           histo)
                    massPlotPUUp = getPlot("massPlotEle%sPUScaleUpCSNegNoLog" %
                                           histo)
                    massPlotPUDown = getPlot(
                        "massPlotEle%sPUScaleDownCSNegNoLog" % histo)
                    massPlotPrefireUp = getPlot(
                        "massPlotEle%sPrefireUpCSNegNoLog" % histo)
                    massPlotPrefireDown = getPlot(
                        "massPlotEle%sPrefireDownCSNegNoLog" % histo)
                else:
                    massPlot = getPlot("massPlotEle%sNoLog" % histo)
                    massPlotUp = getPlot("massPlotEle%sScaleUpNoLog" % histo)
                    massPlotDown = getPlot("massPlotEle%sScaleDownNoLog" %
                                           histo)
                    massPlotPUUp = getPlot("massPlotEle%sPUScaleUpNoLog" %
                                           histo)
                    massPlotPUDown = getPlot("massPlotEle%sPUScaleDownNoLog" %
                                             histo)
                    massPlotPrefireUp = getPlot("massPlotEle%sPrefireUpNoLog" %
                                                histo)
                    massPlotPrefireDown = getPlot(
                        "massPlotEle%sPrefireDownNoLog" % histo)
                eventCounts = totalNumberOfGeneratedEvents(path, massPlot.muon)
                negWeights = negWeightFractions(path, massPlot.muon)

                if "2016" in label:
                    data = Process(Data2016, normalized=True)
                    drellyan = Process(getattr(Backgrounds2016, "DrellYan"),
                                       eventCounts, negWeights)
                    other = Process(getattr(Backgrounds2016, "OtherEle"),
                                    eventCounts, negWeights)
                    jets = Process(getattr(Backgrounds2016, "Jets"),
                                   eventCounts,
                                   negWeights,
                                   normalized=True)
                elif "2018" in label:
                    data = Process(Data2018, normalized=True)
                    drellyan = Process(getattr(Backgrounds2018, "DrellYan"),
                                       eventCounts, negWeights)
                    other = Process(getattr(Backgrounds2018, "Other"),
                                    eventCounts, negWeights)
                    jets = Process(getattr(Backgrounds2018, "Jets"),
                                   eventCounts,
                                   negWeights,
                                   normalized=True)
                else:
                    data = Process(Data, normalized=True)
                    drellyan = Process(getattr(Backgrounds, "DrellYan"),
                                       eventCounts, negWeights)
                    other = Process(getattr(Backgrounds, "Other"), eventCounts,
                                    negWeights)
                    jets = Process(getattr(Backgrounds, "Jets"),
                                   eventCounts,
                                   negWeights,
                                   normalized=True)

                if cs == "inc":
                    fResult = TFile("inputsCI_%s.root" % (label), "RECREATE")
                else:
                    fResult = TFile("inputsCI_%s_%s.root" % (cs, label),
                                    "RECREATE")

                if "2016" in label:
                    lumi = 35922.0
                    if "bbbe" in massPlot.histName:
                        zScaleFac = zScale2016["electrons"][0]
                    elif "bb" in massPlot.histName:
                        zScaleFac = zScale2016["electrons"][1]
                    elif "be" in massPlot.histName:
                        zScaleFac = zScale2016["electrons"][2]
                    else:
                        zScaleFac = zScale2016["electrons"][0]

                elif "2018" in label:
                    lumi = 59401.0
                    if "bbbe" in massPlot.histName:
                        zScaleFac = zScale2018["electrons"][0]
                    elif "bb" in massPlot.histName:
                        zScaleFac = zScale2018["electrons"][1]
                    elif "be" in massPlot.histName:
                        zScaleFac = zScale2018["electrons"][2]
                    else:
                        zScaleFac = zScale2018["electrons"][0]
                else:
                    lumi = 41500.0
                    if "bbbe" in massPlot.histName:
                        zScaleFac = zScale["electrons"][0]
                    elif "bb" in massPlot.histName:
                        zScaleFac = zScale["electrons"][1]
                    elif "be" in massPlot.histName:
                        zScaleFac = zScale["electrons"][2]
                    else:
                        zScaleFac = zScale["electrons"][0]

                jetHist = deepcopy(
                    jets.loadHistogram(massPlot, lumi, zScaleFac))
                hist = data.loadHistogram(massPlot, lumi, zScaleFac)
                if cs == "inc":
                    hist.SetName("dataHist_%s" % (label))
                else:
                    hist.SetName("dataHist_%s_%s" % (cs, label))

                dyHist = deepcopy(
                    drellyan.loadHistogram(massPlot, lumi, zScaleFac))
                dyHistScaleUp = deepcopy(
                    drellyan.loadHistogram(massPlotUp, lumi, zScaleFac))
                dyHistScaleDown = deepcopy(
                    drellyan.loadHistogram(massPlotDown, lumi, zScaleFac))
                dyHistPUUp = deepcopy(
                    drellyan.loadHistogram(massPlotPUUp, lumi, zScaleFac))
                dyHistPUDown = deepcopy(
                    drellyan.loadHistogram(massPlotPUDown, lumi, zScaleFac))
                dyHistPrefireUp = deepcopy(
                    drellyan.loadHistogram(massPlotPrefireUp, lumi, zScaleFac))
                dyHistPrefireDown = deepcopy(
                    drellyan.loadHistogram(massPlotPrefireDown, lumi,
                                           zScaleFac))

                otherHist = deepcopy(
                    other.loadHistogram(massPlot, lumi, zScaleFac))
                otherHistScaleUp = deepcopy(
                    other.loadHistogram(massPlotUp, lumi, zScaleFac))
                otherHistScaleDown = deepcopy(
                    other.loadHistogram(massPlotDown, lumi, zScaleFac))
                otherHistPUUp = deepcopy(
                    other.loadHistogram(massPlotPUUp, lumi, zScaleFac))
                otherHistPUDown = deepcopy(
                    other.loadHistogram(massPlotPUDown, lumi, zScaleFac))
                otherHistPrefireUp = deepcopy(
                    other.loadHistogram(massPlotPrefireUp, lumi, zScaleFac))
                otherHistPrefireDown = deepcopy(
                    other.loadHistogram(massPlotPrefireDown, lumi, zScaleFac))
                if cs == "inc":
                    dyHist.SetName("bkgHistDY_%s" % label)
                    dyHistScaleUp.SetName("bkgHistDYScaleUp_%s" % label)
                    dyHistScaleDown.SetName("bkgHistDYScaleDown_%s" % label)
                    dyHistPUUp.SetName("bkgHistDYPUUp_%s" % label)
                    dyHistPUDown.SetName("bkgHistDYPUDown_%s" % label)
                    dyHistPrefireUp.SetName("bkgHistDYPrefireUp_%s" % label)
                    dyHistPrefireDown.SetName("bkgHistDYPrefireDown_%s" %
                                              label)
                    otherHist.SetName("bkgHistOther_%s" % label)
                    otherHistScaleUp.SetName("bkgHistOtherScaleUp_%s" % label)
                    otherHistScaleDown.SetName("bkgHistOtherScaleDown_%s" %
                                               label)
                    otherHistPUUp.SetName("bkgHistOtherPUUp_%s" % label)
                    otherHistPUDown.SetName("bkgHistOtherPUDown_%s" % label)
                    otherHistPrefireUp.SetName("bkgHistOtherPrefireUp_%s" %
                                               label)
                    otherHistPrefireDown.SetName("bkgHistOtherPrefireDown_%s" %
                                                 label)
                else:
                    dyHist.SetName("bkgHistDY_%s_%s" % (cs, label))
                    dyHistScaleUp.SetName("bkgHistDYScaleUp_%s_%s" %
                                          (cs, label))
                    dyHistScaleDown.SetName("bkgHistDYScaleDown_%s_%s" %
                                            (cs, label))
                    dyHistPUUp.SetName("bkgHistDYPUUp_%s_%s" % (cs, label))
                    dyHistPUDown.SetName("bkgHistDYPUDown_%s_%s" % (cs, label))
                    dyHistPrefireUp.SetName("bkgHistDYPrefireUp_%s_%s" %
                                            (cs, label))
                    dyHistPrefireDown.SetName("bkgHistDYPrefireDown_%s_%s" %
                                              (cs, label))
                    otherHist.SetName("bkgHistOther_%s_%s" % (cs, label))
                    otherHistScaleUp.SetName("bkgHistOtherScaleUp_%s_%s" %
                                             (cs, label))
                    otherHistScaleDown.SetName("bkgHistOtherScaleDown_%s_%s" %
                                               (cs, label))
                    otherHistPUUp.SetName("bkgHistOtherPUUp_%s_%s" %
                                          (cs, label))
                    otherHistPUDown.SetName("bkgHistOtherPUDown_%s_%s" %
                                            (cs, label))
                    otherHistPrefireUp.SetName("bkgHistOtherPrefireUp_%s_%s" %
                                               (cs, label))
                    otherHistPrefireDown.SetName(
                        "bkgHistOtherPrefireDown_%s_%s" % (cs, label))

                if not cs == "inc":
                    jetHist.SetName("bkgHistJets_%s_%s" % (cs, label))
                else:
                    jetHist.SetName("bkgHistJets_%s" % label)
                jetHist.SetDirectory(fResult)
                for i in range(0, jetHist.GetNbinsX()):
                    jetHist.SetBinContent(
                        i,
                        jetHist.GetBinContent(i) * jetHist.GetBinWidth(i))
                    jetHist.SetBinError(
                        i,
                        jetHist.GetBinError(i) * jetHist.GetBinWidth(i))
                # ~ print (cs, label, hist.Integral(hist.FindBin(1800),hist.FindBin(6000-0.01)))
                # ~ print (cs, label, dyHist.Integral(dyHist.FindBin(400),dyHist.FindBin(500-0.01)))

                print("Total Background")

                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(120),
                                    dyHist.FindBin(400 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(120),
                                       dyHist.FindBin(400 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(120),
                                     jetHist.FindBin(400 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(400),
                                    dyHist.FindBin(600 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(400),
                                       dyHist.FindBin(600 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(400),
                                     jetHist.FindBin(600 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(600),
                                    dyHist.FindBin(900 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(600),
                                       dyHist.FindBin(900 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(600),
                                     jetHist.FindBin(900 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(900),
                                    dyHist.FindBin(1300 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(900),
                                       dyHist.FindBin(1300 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(900),
                                     jetHist.FindBin(1300 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(1300),
                                    dyHist.FindBin(1800 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(1300),
                                       dyHist.FindBin(1800 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(1300),
                                     jetHist.FindBin(1800 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(6000 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(1800),
                                       dyHist.FindBin(6000 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(6000 - 0.01)))

                print("Drell-Yan")

                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(120),
                                    dyHist.FindBin(400 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(400),
                                    dyHist.FindBin(600 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(600),
                                    dyHist.FindBin(900 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(900),
                                    dyHist.FindBin(1300 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(1300),
                                    dyHist.FindBin(1800 - 0.01)))
                print(
                    cs, label,
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(6000 - 0.01)))

                print("Other")

                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(120),
                                       dyHist.FindBin(400 - 0.01)))
                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(400),
                                       dyHist.FindBin(600 - 0.01)))
                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(600),
                                       dyHist.FindBin(900 - 0.01)))
                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(900),
                                       dyHist.FindBin(1300 - 0.01)))
                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(1300),
                                       dyHist.FindBin(1800 - 0.01)))
                print(
                    cs, label,
                    otherHist.Integral(dyHist.FindBin(1800),
                                       dyHist.FindBin(6000 - 0.01)))
                print("Jets")

                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(120),
                                     jetHist.FindBin(400 - 0.01)))
                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(400),
                                     jetHist.FindBin(600 - 0.01)))
                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(600),
                                     jetHist.FindBin(900 - 0.01)))
                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(900),
                                     jetHist.FindBin(1300 - 0.01)))
                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(1300),
                                     jetHist.FindBin(1800 - 0.01)))
                print(
                    cs, label,
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(6000 - 0.01)))

                print("Data")

                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(120),
                                  dyHist.FindBin(400 - 0.01)))
                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(400),
                                  dyHist.FindBin(600 - 0.01)))
                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(600),
                                  dyHist.FindBin(900 - 0.01)))
                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(900),
                                  dyHist.FindBin(1300 - 0.01)))
                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(1300),
                                  dyHist.FindBin(1800 - 0.01)))
                print(
                    cs, label,
                    hist.Integral(dyHist.FindBin(1800),
                                  dyHist.FindBin(6000 - 0.01)))

                line400 = line % (
                    "400-600",
                    hist.Integral(dyHist.FindBin(400),
                                  dyHist.FindBin(600 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(400),
                                    dyHist.FindBin(600 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(400),
                                       otherHist.FindBin(600 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(400),
                                     jetHist.FindBin(600 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(400),
                                    dyHist.FindBin(600 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(400),
                                       dyHist.FindBin(600 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(400),
                                     jetHist.FindBin(600 - 0.01)))
                line600 = line % (
                    "600-900",
                    hist.Integral(dyHist.FindBin(600),
                                  dyHist.FindBin(900 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(600),
                                    dyHist.FindBin(900 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(600),
                                       otherHist.FindBin(900 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(600),
                                     jetHist.FindBin(900 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(600),
                                    dyHist.FindBin(900 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(600),
                                       dyHist.FindBin(900 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(600),
                                     jetHist.FindBin(900 - 0.01)))
                line900 = line % (
                    "900-1300",
                    hist.Integral(dyHist.FindBin(900),
                                  dyHist.FindBin(1300 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(900),
                                    dyHist.FindBin(1300 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(900),
                                       otherHist.FindBin(1300 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(900),
                                     jetHist.FindBin(1300 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(900),
                                    dyHist.FindBin(1300 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(900),
                                       dyHist.FindBin(1300 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(900),
                                     jetHist.FindBin(1300 - 0.01)))
                line1300 = line % (
                    "1300-1800",
                    hist.Integral(dyHist.FindBin(1300),
                                  dyHist.FindBin(1800 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1300),
                                    dyHist.FindBin(1800 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(1300),
                                       otherHist.FindBin(1800 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(1300),
                                     jetHist.FindBin(1800 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1300),
                                    dyHist.FindBin(1800 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(1300),
                                       dyHist.FindBin(18000 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(1300),
                                     jetHist.FindBin(1800 - 0.01)))
                line1800 = line % (
                    "1800-6000",
                    hist.Integral(dyHist.FindBin(1800),
                                  dyHist.FindBin(600 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(6000 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(1800),
                                       otherHist.FindBin(6000 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(6000 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(6000 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(1800),
                                       dyHist.FindBin(6000 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(6000 - 0.01)))
                print(table % (line400, line600, line900, line1300, line1800))

                line1800 = line % (
                    "1800-2200",
                    hist.Integral(dyHist.FindBin(1800),
                                  dyHist.FindBin(2200 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(2200 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(2200),
                                       otherHist.FindBin(2200 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(2200 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(1800),
                                    dyHist.FindBin(2200 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(1800),
                                       dyHist.FindBin(2200 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(1800),
                                     jetHist.FindBin(2200 - 0.01)))
                line2200 = line % (
                    "2200-2600",
                    hist.Integral(dyHist.FindBin(2200),
                                  dyHist.FindBin(2600 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(2200),
                                    dyHist.FindBin(2600 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(2600),
                                       otherHist.FindBin(2600 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(2200),
                                     jetHist.FindBin(2600 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(2200),
                                    dyHist.FindBin(2600 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(2200),
                                       dyHist.FindBin(2600 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(2200),
                                     jetHist.FindBin(2600 - 0.01)))
                line2600 = line % (
                    "2600-3000",
                    hist.Integral(dyHist.FindBin(2600),
                                  dyHist.FindBin(3000 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(2600),
                                    dyHist.FindBin(3000 - 0.01)) +
                    otherHist.Integral(dyHist.FindBin(3000),
                                       otherHist.FindBin(3000 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(2600),
                                     jetHist.FindBin(3000 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(2600),
                                    dyHist.FindBin(3000 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(2600),
                                       dyHist.FindBin(3000 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(2600),
                                     jetHist.FindBin(3000 - 0.01)))
                line3000 = line % (
                    "3000-3400",
                    hist.Integral(dyHist.FindBin(3000),
                                  dyHist.FindBin(3400 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(3000),
                                    dyHist.FindBin(3400 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(3400),
                                       otherHist.FindBin(3400 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(3000),
                                     jetHist.FindBin(3400 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(3000),
                                    dyHist.FindBin(3400 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(3000),
                                       dyHist.FindBin(3400 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(3000),
                                     jetHist.FindBin(3400 - 0.01)))
                line3400 = line % (
                    "3400-10000",
                    hist.Integral(dyHist.FindBin(3400),
                                  dyHist.FindBin(10000 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(3400),
                                    dyHist.FindBin(10000 - 0.01)) +
                    otherHist.Integral(otherHist.FindBin(10000),
                                       otherHist.FindBin(10000 - 0.01)) +
                    jetHist.Integral(jetHist.FindBin(3400),
                                     jetHist.FindBin(10000 - 0.01)),
                    dyHist.Integral(dyHist.FindBin(3400),
                                    dyHist.FindBin(10000 - 0.01)),
                    otherHist.Integral(dyHist.FindBin(3400),
                                       dyHist.FindBin(10000 - 0.01)),
                    jetHist.Integral(jetHist.FindBin(3400),
                                     jetHist.FindBin(10000 - 0.01)))
                print(table %
                      (line1800, line2200, line2600, line3000, line3400))
                dyHist.SetDirectory(fResult)
                dyHistScaleUp.SetDirectory(fResult)
                dyHistScaleDown.SetDirectory(fResult)
                dyHistPUUp.SetDirectory(fResult)
                dyHistPUDown.SetDirectory(fResult)
                dyHistPrefireUp.SetDirectory(fResult)
                dyHistPrefireDown.SetDirectory(fResult)
                otherHist.SetDirectory(fResult)
                otherHistScaleUp.SetDirectory(fResult)
                otherHistScaleDown.SetDirectory(fResult)
                otherHistPUUp.SetDirectory(fResult)
                otherHistPUDown.SetDirectory(fResult)
                otherHistPrefireUp.SetDirectory(fResult)
                otherHistPrefireDown.SetDirectory(fResult)
                hist.SetDirectory(fResult)

                fResult.Write()
                fResult.Close()
Пример #23
0
def main():
    ### for data

    genPlot = getPlot("etaPtMapGen")
    recoPlot = getPlot("etaPtMapReco")

    drellyanGen = Process(getattr(Backgrounds, "DrellYan"))
    drellyanReco = Process(getattr(Backgrounds, "DrellYan"))

    genPlot = deepcopy(drellyanGen.loadHistogram(genPlot))
    recoPlot = deepcopy(drellyanReco.loadHistogram(recoPlot))

    eff = recoPlot.Clone("bla")
    eff.Divide(genPlot)

    print genPlot.GetBinContent(3, 5)
    print recoPlot.GetBinContent(3, 5)

    hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)

    style = setTDRStyle()
    gStyle.SetOptStat(0)
    gStyle.SetPadRightMargin(0.2)
    gStyle.SetPadBottomMargin(0.1)
    plotPad.UseCurrentStyle()
    gStyle.SetOptStat(0)
    gStyle.SetPadRightMargin(0.2)
    plotPad.Draw()
    plotPad.cd()

    #~ plotPad.DrawFrame(-2.4,0,2.4,2000,"; muon #eta ; muon p_{T} GeV")
    eff.GetZaxis().SetRangeUser(0, 1)
    eff.GetYaxis().SetRangeUser(53, 2000)
    eff.GetZaxis().SetTitle("Trigger+Reconstruction+ID efficiency")
    eff.GetZaxis().SetTitleOffset(1.3)
    eff.GetYaxis().SetTitle("simulated muon p_{T} GeV [GeV]")
    eff.GetYaxis().SetTitleOffset(2)
    eff.GetXaxis().SetTitle("simulated muon #eta")
    eff.Draw("colz")
    plotPad.SetLogy()

    latex = TLatex()
    latex.SetTextFont(42)
    latex.SetTextAlign(31)
    latex.SetTextSize(0.04)
    latex.SetNDC(True)
    latexCMS = TLatex()
    latexCMS.SetTextFont(61)
    latexCMS.SetTextSize(0.055)
    latexCMS.SetNDC(True)
    latexCMSExtra = TLatex()
    latexCMSExtra.SetTextFont(52)
    latexCMSExtra.SetTextSize(0.03)
    latexCMSExtra.SetNDC(True)

    latex.DrawLatex(0.85, 0.96, "(13 TeV)")

    cmsExtra = "Supplementary"
    latexCMS.DrawLatex(0.15, 0.96, "CMS")
    if "Simulation" in cmsExtra:
        yLabelPos = 0.81
    else:
        yLabelPos = 0.96

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

    hCanvas.Print("effMapMuons.pdf")
Пример #24
0
def main():
    ### for data

    histos = ["BB", "BE", "BBCSPos", "BBCSNeg", "BECSPos", "BECSNeg"]
    labels = [
        "dimuon_BB", "dimuon_BE", "dimuon_BBCSPos", "dimuon_BBCSNeg",
        "dimuon_BECSPos", "dimuon_BECSNeg"
    ]

    lambdas = [10, 16, 22, 28, 34]
    models = ["ConLL", "ConLR", "ConRR", "DesLL", "DesLR", "DesRR"]
    bins = [4, 7, 6, 5, 9, 8]

    massPlot = getPlot("massPlotForLimit")
    massPlotSmeared = getPlot("massPlotSmeared")
    massPlotUp = getPlot("massPlotUp")
    massPlotDown = getPlot("massPlotDown")
    massPlotWeighted = getPlot("massPlotWeighted")

    for i, histo in enumerate(histos):
        label = labels[i]

        for model in models:
            for l in lambdas:
                data = Process(Data)
                drellyan = Process(getattr(Backgrounds, "DrellYan"))
                other = Process(getattr(Backgrounds, "Other"))
                name = "CITo2Mu_Lam%dTeV%s" % (l, model)
                signal = Process(getattr(Signals, name))

                name = "CITo2Mu_Lam100kTeV%s" % (model)
                signalDY = Process(getattr(Signals, name))

                fResult = TFile(
                    "inputsCI_%s_%dTeV_%s.root" % (label, l, model),
                    "RECREATE")

                sigHist = deepcopy(
                    signal.loadHistogramProjected(massPlot, bins[i]))
                sigHistSmear = deepcopy(
                    signal.loadHistogramProjected(massPlotSmeared, bins[i]))
                sigHistScaleUp = deepcopy(
                    signal.loadHistogramProjected(massPlotUp, bins[i]))
                sigHistScaleDown = deepcopy(
                    signal.loadHistogramProjected(massPlotDown, bins[i]))
                sigHistWeighted = deepcopy(
                    signal.loadHistogramProjected(massPlotWeighted, bins[i]))
                if histo == "BE":
                    sigHist.Add(
                        deepcopy(signal.loadHistogramProjected(massPlot, 10)))
                    sigHistSmear.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotSmeared,
                                                          10)))
                    sigHistScaleUp.Add(
                        deepcopy(signal.loadHistogramProjected(massPlotUp,
                                                               10)))
                    sigHistScaleDown.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotDown, 10)))
                    sigHistWeighted.Add(
                        deepcopy(
                            signal.loadHistogramProjected(
                                massPlotWeighted, 10)))
                if "_BECSPos" in label:
                    sigHist.Add(
                        deepcopy(signal.loadHistogramProjected(massPlot, 12)))
                    sigHistSmear.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotSmeared,
                                                          12)))
                    sigHistScaleUp.Add(
                        deepcopy(signal.loadHistogramProjected(massPlotUp,
                                                               12)))
                    sigHistScaleDown.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotDown, 12)))
                    sigHistWeighted.Add(
                        deepcopy(
                            signal.loadHistogramProjected(
                                massPlotWeighted, 12)))

                if "_BECSNeg" in label:
                    sigHist.Add(
                        deepcopy(signal.loadHistogramProjected(massPlot, 11)))
                    sigHistSmear.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotSmeared,
                                                          11)))
                    sigHistScaleUp.Add(
                        deepcopy(signal.loadHistogramProjected(massPlotUp,
                                                               11)))
                    sigHistScaleDown.Add(
                        deepcopy(
                            signal.loadHistogramProjected(massPlotDown, 11)))
                    sigHistWeighted.Add(
                        deepcopy(
                            signal.loadHistogramProjected(
                                massPlotWeighted, 11)))

                sigHistDY = deepcopy(
                    signalDY.loadHistogramProjected(massPlot, bins[i]))
                sigHistSmearDY = deepcopy(
                    signalDY.loadHistogramProjected(massPlotSmeared, bins[i]))
                sigHistScaleUpDY = deepcopy(
                    signalDY.loadHistogramProjected(massPlotUp, bins[i]))
                sigHistScaleDownDY = deepcopy(
                    signalDY.loadHistogramProjected(massPlotDown, bins[i]))
                sigHistWeightedDY = deepcopy(
                    signalDY.loadHistogramProjected(massPlotWeighted, bins[i]))
                if histo == "BE":
                    sigHistDY.Add(
                        deepcopy(signalDY.loadHistogramProjected(massPlot,
                                                                 10)))
                    sigHistSmearDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotSmeared, 10)))
                    sigHistScaleUpDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotUp, 10)))
                    sigHistScaleDownDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotDown, 10)))
                    sigHistWeightedDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotWeighted, 10)))
                if "_BECSPos" in label:
                    sigHistDY.Add(
                        deepcopy(signalDY.loadHistogramProjected(massPlot,
                                                                 12)))
                    sigHistSmearDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotSmeared, 12)))
                    sigHistScaleUpDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotUp, 12)))
                    sigHistScaleDownDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotDown, 12)))
                    sigHistWeightedDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotWeighted, 12)))
                if "_BECSNeg" in label:
                    sigHistDY.Add(
                        deepcopy(signalDY.loadHistogramProjected(massPlot,
                                                                 11)))
                    sigHistSmearDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotSmeared, 11)))
                    sigHistScaleUpDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotUp, 11)))
                    sigHistScaleDownDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(massPlotDown, 11)))
                    sigHistWeightedDY.Add(
                        deepcopy(
                            signalDY.loadHistogramProjected(
                                massPlotWeighted, 11)))

                sigHist.Add(sigHistDY, -1)
                sigHistSmear.Add(sigHistSmearDY, -1)
                sigHistScaleUp.Add(sigHistScaleUpDY, -1)
                sigHistScaleDown.Add(sigHistScaleDownDY, -1)
                sigHistWeighted.Add(sigHistWeightedDY, -1)

                hist = data.loadHistogramProjected(massPlot, bins[i])

                if histo == "BE":
                    hist.Add(
                        deepcopy(data.loadHistogramProjected(massPlot, 10)))
                if "_BECSPos" in label:
                    hist.Add(
                        deepcopy(data.loadHistogramProjected(massPlot, 12)))
                if "_BECSNeg" in label:
                    hist.Add(
                        deepcopy(data.loadHistogramProjected(massPlot, 11)))
                hist.SetName("dataHist_%s" % label)

                dyHist = deepcopy(
                    drellyan.loadHistogramProjected(massPlot, bins[i]))
                dyHistSmear = deepcopy(
                    drellyan.loadHistogramProjected(massPlotSmeared, bins[i]))
                dyHistScaleUp = deepcopy(
                    drellyan.loadHistogramProjected(massPlotUp, bins[i]))
                dyHistScaleDown = deepcopy(
                    drellyan.loadHistogramProjected(massPlotDown, bins[i]))
                dyHistWeighted = deepcopy(
                    drellyan.loadHistogramProjected(massPlotWeighted, bins[i]))
                if histo == "BE":
                    dyHist.Add(
                        deepcopy(drellyan.loadHistogramProjected(massPlot,
                                                                 10)))
                    dyHistSmear.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotSmeared, 10)))
                    dyHistScaleUp.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotUp, 10)))
                    dyHistScaleDown.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotDown, 10)))
                    dyHistWeighted.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotWeighted, 10)))
                if "_BECSPos" in label:
                    dyHist.Add(
                        deepcopy(drellyan.loadHistogramProjected(massPlot,
                                                                 12)))
                    dyHistSmear.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotSmeared, 12)))
                    dyHistScaleUp.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotUp, 12)))
                    dyHistScaleDown.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotDown, 12)))
                    dyHistWeighted.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotWeighted, 12)))
                if "_BECSNeg" in label:
                    dyHist.Add(
                        deepcopy(drellyan.loadHistogramProjected(massPlot,
                                                                 11)))
                    dyHistSmear.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotSmeared, 11)))
                    dyHistScaleUp.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotUp, 11)))
                    dyHistScaleDown.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(massPlotDown, 11)))
                    dyHistWeighted.Add(
                        deepcopy(
                            drellyan.loadHistogramProjected(
                                massPlotWeighted, 11)))

                otherHist = deepcopy(
                    other.loadHistogramProjected(massPlot, bins[i]))
                otherHistSmear = deepcopy(
                    other.loadHistogramProjected(massPlotSmeared, bins[i]))
                otherHistScaleUp = deepcopy(
                    other.loadHistogramProjected(massPlotUp, bins[i]))
                otherHistScaleDown = deepcopy(
                    other.loadHistogramProjected(massPlotDown, bins[i]))
                otherHistWeighted = deepcopy(
                    other.loadHistogramProjected(massPlotWeighted, bins[i]))
                if histo == "BE":
                    otherHist.Add(
                        deepcopy(other.loadHistogramProjected(massPlot, 10)))
                    otherHistSmear.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotSmeared, 10)))
                    otherHistScaleUp.Add(
                        deepcopy(other.loadHistogramProjected(massPlotUp, 10)))
                    otherHistScaleDown.Add(
                        deepcopy(other.loadHistogramProjected(
                            massPlotDown, 10)))
                    otherHistWeighted.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotWeighted,
                                                         10)))
                if "_BECSPos" in label:
                    otherHist.Add(
                        deepcopy(other.loadHistogramProjected(massPlot, 12)))
                    otherHistSmear.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotSmeared, 12)))
                    otherHistScaleUp.Add(
                        deepcopy(other.loadHistogramProjected(massPlotUp, 12)))
                    otherHistScaleDown.Add(
                        deepcopy(other.loadHistogramProjected(
                            massPlotDown, 12)))
                    otherHistWeighted.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotWeighted,
                                                         12)))
                if "_BECSNeg" in label:
                    otherHist.Add(
                        deepcopy(other.loadHistogramProjected(massPlot, 11)))
                    otherHistSmear.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotSmeared, 11)))
                    otherHistScaleUp.Add(
                        deepcopy(other.loadHistogramProjected(massPlotUp, 11)))
                    otherHistScaleDown.Add(
                        deepcopy(other.loadHistogramProjected(
                            massPlotDown, 11)))
                    otherHistWeighted.Add(
                        deepcopy(
                            other.loadHistogramProjected(massPlotWeighted,
                                                         11)))

                sigHist.SetName("sigHist_%s" % label)
                sigHistSmear.SetName("sigHistSmeared_%s" % label)
                sigHistScaleUp.SetName("sigHistScaleUp_%s" % label)
                sigHistScaleDown.SetName("sigHistScaleDown_%s" % label)
                sigHistWeighted.SetName("sigHistWeighted_%s" % label)

                dyHist.SetName("bkgHistDY_%s" % label)
                dyHistSmear.SetName("bkgHistDYSmeared_%s" % label)
                dyHistScaleUp.SetName("bkgHistDYScaleUp_%s" % label)
                dyHistScaleDown.SetName("bkgHistDYScaleDown_%s" % label)
                dyHistWeighted.SetName("bkgHistDYWeighted_%s" % label)
                otherHist.SetName("bkgHistOther_%s" % label)
                otherHistSmear.SetName("bkgHistOtherSmeared_%s" % label)
                otherHistScaleUp.SetName("bkgHistOtherScaleUp_%s" % label)
                otherHistScaleDown.SetName("bkgHistOtherScaleDown_%s" % label)
                otherHistWeighted.SetName("bkgHistOtherWeighted_%s" % label)

                if "_BB" in label:
                    fJets = TFile("files/Data-total-jets-BB.root", "OPEN")
                else:
                    fJets = TFile("files/Data-total-jets-BEEE.root", "OPEN")

                jetHist = fJets.Get("TotalJets")
                jetHist.SetName("bkgHistJets_%s" % label)
                jetHist.SetDirectory(fResult)

                sigHist.SetDirectory(fResult)
                sigHistSmear.SetDirectory(fResult)
                sigHistScaleUp.SetDirectory(fResult)
                sigHistScaleDown.SetDirectory(fResult)
                sigHistWeighted.SetDirectory(fResult)
                dyHist.SetDirectory(fResult)
                dyHistSmear.SetDirectory(fResult)
                dyHistScaleUp.SetDirectory(fResult)
                dyHistScaleDown.SetDirectory(fResult)
                dyHistWeighted.SetDirectory(fResult)
                otherHist.SetDirectory(fResult)
                otherHistSmear.SetDirectory(fResult)
                otherHistScaleUp.SetDirectory(fResult)
                otherHistScaleDown.SetDirectory(fResult)
                otherHistWeighted.SetDirectory(fResult)
                hist.SetDirectory(fResult)

                fResult.Write()
                fResult.Close()
Пример #25
0
     "prefireDown": "massPlotEleBBPrefireDownNoLog"
 }
 eleplots_be = {
     "default": "massPlotEleBE",
     "scaleUp": "massPlotEleBEScaleUpNoLog",
     "scaleDown": "massPlotEleBEScaleDownNoLog",
     "PUUp": "massPlotEleBEPUScaleUpNoLog",
     "PUDown": "massPlotEleBEPUScaleDownNoLog",
     "prefireUp": "massPlotEleBEPrefireUpNoLog",
     "prefireDown": "massPlotEleBEPrefireDownNoLog"
 }
 plot_mu_bb = {}
 plot_el_bb = {}
 plot_mu_be = {}
 plot_el_be = {}
 plotGenbb_mu = getPlot("massPlotBBGenNoLog")
 plotGenbe_mu = getPlot("massPlotBEGenNoLog")
 plotGenbb_el = getPlot("massPlotEleBBGenNoLog")
 plotGenbe_el = getPlot("massPlotEleBEGenNoLog")
 plotGenee_el = getPlot("massPlotEleEEGenNoLog")
 for key in muplots_bb.keys():
     plot_mu_bb[key] = getPlot(muplots_bb[key])
     plot_mu_bb[key].logX = True
 for key in eleplots_bb.keys():
     plot_el_bb[key] = getPlot(eleplots_bb[key])
     plot_el_bb[key].logX = True
 for key in muplots_be.keys():
     plot_mu_be[key] = getPlot(muplots_be[key])
     plot_mu_be[key].logX = True
 for key in eleplots_be.keys():
     plot_el_be[key] = getPlot(eleplots_be[key])
Пример #26
0
def compareRecos(path, selection, plots, runRange):
    for name in plots:
        plot = getPlot("mllPlotLowMass")
        plot.addRegion(selection)
        plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut

        plot.cuts = plot.cuts

        trees = {}
        treesPrompt = {}

        trees["EE"], trees["MM"], trees["EM"] = getTrees(path, plot)
        treesPrompt["EE"], treesPrompt["MM"], treesPrompt["EM"] = getTrees(
            "/home/jan/Trees/sw538v0477", plot)

        trees["EE"] = trees["EE"].CopyTree(
            "!((runNr == 194480 && lumiSec >= 9 && lumiSec <=16) || (runNr == 195552 && lumiSec >= 1392 && lumiSec <=1393) || (runNr == 196218 && lumiSec >= 738 && lumiSec <=738) || (runNr == 196239 && lumiSec >= 498 && lumiSec <=502) || (runNr == 199832 && lumiSec >= 58 && lumiSec <=62) || (runNr == 199832 && lumiSec >= 65 && lumiSec <=118) || (runNr == 199832 && lumiSec >= 121 && lumiSec <=139) || (runNr == 199832 && lumiSec >= 142 && lumiSec <=286) || (runNr == 199834 && lumiSec >= 1 && lumiSec <=9) || (runNr == 199834 && lumiSec >= 11 && lumiSec <=11) || (runNr == 199834 && lumiSec >= 14 && lumiSec <=18) || (runNr == 199834 && lumiSec >= 21 && lumiSec <=54) || (runNr == 199834 && lumiSec >= 56 && lumiSec <=57) || (runNr == 199834 && lumiSec >= 62 && lumiSec <=65) || (runNr == 199834 && lumiSec >= 69 && lumiSec <=284) || (runNr == 199834 && lumiSec >= 286 && lumiSec <=503) || (runNr == 199834 && lumiSec >= 505 && lumiSec <=942) || (runNr == 199967 && lumiSec >= 60 && lumiSec <=120) || (runNr == 199967 && lumiSec >= 122 && lumiSec <=170) || (runNr == 199967 && lumiSec >= 172 && lumiSec <=198) || (runNr == 200160 && lumiSec >= 52 && lumiSec <=68) || (runNr == 200161 && lumiSec >= 1 && lumiSec <=97) || (runNr == 200161 && lumiSec >= 100 && lumiSec <=112) || (runNr == 200174 && lumiSec >= 81 && lumiSec <=84) || (runNr == 200177 && lumiSec >= 1 && lumiSec <=56) || (runNr == 200178 && lumiSec >= 1 && lumiSec <=38) || (runNr == 200186 && lumiSec >= 1 && lumiSec <=3) || (runNr == 200186 && lumiSec >= 6 && lumiSec <=24) || (runNr == 203709 && lumiSec >= 1 && lumiSec <=121) || (runNr == 203742 && lumiSec >= 1 && lumiSec <=29) || (runNr == 203777 && lumiSec >= 103 && lumiSec <=113) || (runNr == 203830 && lumiSec >= 82 && lumiSec <=182) || (runNr == 203832 && lumiSec >= 1 && lumiSec <=11) || (runNr == 203833 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203833 && lumiSec >= 73 && lumiSec <=128) || (runNr == 203834 && lumiSec >= 1 && lumiSec <=40) || (runNr == 203835 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203835 && lumiSec >= 73 && lumiSec <=358) || (runNr == 203853 && lumiSec >= 122 && lumiSec <=222) || (runNr == 208352 && lumiSec >= 1 && lumiSec <=15) || (runNr == 208352 && lumiSec >= 17 && lumiSec <=17) || (runNr == 208352 && lumiSec >= 19 && lumiSec <=19))"
        )
        trees["MM"] = trees["MM"].CopyTree(
            "!((runNr == 194480 && lumiSec >= 9 && lumiSec <=16) || (runNr == 195552 && lumiSec >= 1392 && lumiSec <=1393) || (runNr == 196218 && lumiSec >= 738 && lumiSec <=738) || (runNr == 196239 && lumiSec >= 498 && lumiSec <=502) || (runNr == 199832 && lumiSec >= 58 && lumiSec <=62) || (runNr == 199832 && lumiSec >= 65 && lumiSec <=118) || (runNr == 199832 && lumiSec >= 121 && lumiSec <=139) || (runNr == 199832 && lumiSec >= 142 && lumiSec <=286) || (runNr == 199834 && lumiSec >= 1 && lumiSec <=9) || (runNr == 199834 && lumiSec >= 11 && lumiSec <=11) || (runNr == 199834 && lumiSec >= 14 && lumiSec <=18) || (runNr == 199834 && lumiSec >= 21 && lumiSec <=54) || (runNr == 199834 && lumiSec >= 56 && lumiSec <=57) || (runNr == 199834 && lumiSec >= 62 && lumiSec <=65) || (runNr == 199834 && lumiSec >= 69 && lumiSec <=284) || (runNr == 199834 && lumiSec >= 286 && lumiSec <=503) || (runNr == 199834 && lumiSec >= 505 && lumiSec <=942) || (runNr == 199967 && lumiSec >= 60 && lumiSec <=120) || (runNr == 199967 && lumiSec >= 122 && lumiSec <=170) || (runNr == 199967 && lumiSec >= 172 && lumiSec <=198) || (runNr == 200160 && lumiSec >= 52 && lumiSec <=68) || (runNr == 200161 && lumiSec >= 1 && lumiSec <=97) || (runNr == 200161 && lumiSec >= 100 && lumiSec <=112) || (runNr == 200174 && lumiSec >= 81 && lumiSec <=84) || (runNr == 200177 && lumiSec >= 1 && lumiSec <=56) || (runNr == 200178 && lumiSec >= 1 && lumiSec <=38) || (runNr == 200186 && lumiSec >= 1 && lumiSec <=3) || (runNr == 200186 && lumiSec >= 6 && lumiSec <=24) || (runNr == 203709 && lumiSec >= 1 && lumiSec <=121) || (runNr == 203742 && lumiSec >= 1 && lumiSec <=29) || (runNr == 203777 && lumiSec >= 103 && lumiSec <=113) || (runNr == 203830 && lumiSec >= 82 && lumiSec <=182) || (runNr == 203832 && lumiSec >= 1 && lumiSec <=11) || (runNr == 203833 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203833 && lumiSec >= 73 && lumiSec <=128) || (runNr == 203834 && lumiSec >= 1 && lumiSec <=40) || (runNr == 203835 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203835 && lumiSec >= 73 && lumiSec <=358) || (runNr == 203853 && lumiSec >= 122 && lumiSec <=222) || (runNr == 208352 && lumiSec >= 1 && lumiSec <=15) || (runNr == 208352 && lumiSec >= 17 && lumiSec <=17) || (runNr == 208352 && lumiSec >= 19 && lumiSec <=19))"
        )
        trees["EM"] = trees["EM"].CopyTree(
            "!((runNr == 194480 && lumiSec >= 9 && lumiSec <=16) || (runNr == 195552 && lumiSec >= 1392 && lumiSec <=1393) || (runNr == 196218 && lumiSec >= 738 && lumiSec <=738) || (runNr == 196239 && lumiSec >= 498 && lumiSec <=502) || (runNr == 199832 && lumiSec >= 58 && lumiSec <=62) || (runNr == 199832 && lumiSec >= 65 && lumiSec <=118) || (runNr == 199832 && lumiSec >= 121 && lumiSec <=139) || (runNr == 199832 && lumiSec >= 142 && lumiSec <=286) || (runNr == 199834 && lumiSec >= 1 && lumiSec <=9) || (runNr == 199834 && lumiSec >= 11 && lumiSec <=11) || (runNr == 199834 && lumiSec >= 14 && lumiSec <=18) || (runNr == 199834 && lumiSec >= 21 && lumiSec <=54) || (runNr == 199834 && lumiSec >= 56 && lumiSec <=57) || (runNr == 199834 && lumiSec >= 62 && lumiSec <=65) || (runNr == 199834 && lumiSec >= 69 && lumiSec <=284) || (runNr == 199834 && lumiSec >= 286 && lumiSec <=503) || (runNr == 199834 && lumiSec >= 505 && lumiSec <=942) || (runNr == 199967 && lumiSec >= 60 && lumiSec <=120) || (runNr == 199967 && lumiSec >= 122 && lumiSec <=170) || (runNr == 199967 && lumiSec >= 172 && lumiSec <=198) || (runNr == 200160 && lumiSec >= 52 && lumiSec <=68) || (runNr == 200161 && lumiSec >= 1 && lumiSec <=97) || (runNr == 200161 && lumiSec >= 100 && lumiSec <=112) || (runNr == 200174 && lumiSec >= 81 && lumiSec <=84) || (runNr == 200177 && lumiSec >= 1 && lumiSec <=56) || (runNr == 200178 && lumiSec >= 1 && lumiSec <=38) || (runNr == 200186 && lumiSec >= 1 && lumiSec <=3) || (runNr == 200186 && lumiSec >= 6 && lumiSec <=24) || (runNr == 203709 && lumiSec >= 1 && lumiSec <=121) || (runNr == 203742 && lumiSec >= 1 && lumiSec <=29) || (runNr == 203777 && lumiSec >= 103 && lumiSec <=113) || (runNr == 203830 && lumiSec >= 82 && lumiSec <=182) || (runNr == 203832 && lumiSec >= 1 && lumiSec <=11) || (runNr == 203833 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203833 && lumiSec >= 73 && lumiSec <=128) || (runNr == 203834 && lumiSec >= 1 && lumiSec <=40) || (runNr == 203835 && lumiSec >= 1 && lumiSec <=70) || (runNr == 203835 && lumiSec >= 73 && lumiSec <=358) || (runNr == 203853 && lumiSec >= 122 && lumiSec <=222) || (runNr == 208352 && lumiSec >= 1 && lumiSec <=15) || (runNr == 208352 && lumiSec >= 17 && lumiSec <=17) || (runNr == 208352 && lumiSec >= 19 && lumiSec <=19))"
        )

        #~ for name in treesPrompt:
        #~ for ev in treesPrompt[name]:
        #~ print ev.runNr, ev.lumiSec, ev.eventNr
        #~
        #~
        #~
        reRecoOnly = {}
        promptOnly = {}
        inPromptJSONOnly = 0
        inReRecoJSONOnly = 0
        for combination in ["EE", "MM", "EM"]:
            isNotInOtherTree = 0
            isNotInOtherTreePrompt = 0
            inPromptJSONOnly = 0
            inReRecoJSONOnly = 0
            nJets = 0
            nJetsPrompt = 0
            met = 0
            metPrompt = 0
            leptonPt = 0
            leptonPtPrompt = 0
            mll = 0
            mllPrompt = 0
            print trees[combination].GetEntries(
            ), treesPrompt[combination].GetEntries()
            localReRecoOnly = []
            localPromptOnly = []
            for evReReco in trees[combination]:
                found = False
                for evPrompt in treesPrompt[combination]:
                    if evReReco.runNr == evPrompt.runNr and evReReco.lumiSec == evPrompt.lumiSec and evReReco.eventNr == evPrompt.eventNr:
                        found = True
                if not found:
                    localReRecoOnly.append(
                        "%s:%s:%s" %
                        (evReReco.runNr, evReReco.lumiSec, evReReco.eventNr))
                    inReRecoJSONOnly += int(
                        isReRecoOnly(evReReco.runNr, evReReco.lumiSec))
                    lostEvents = getEvent("/home/jan/Trees/sw538v0477",
                                          combination, evReReco.runNr,
                                          evReReco.lumiSec, evReReco.eventNr)
                    if lostEvents.GetEntries() == 0:
                        isNotInOtherTree += 1
                        if not isReRecoOnly(evReReco.runNr, evReReco.lumiSec):
                            print "%d:%d:%d" % (evReReco.runNr,
                                                evReReco.lumiSec,
                                                evReReco.eventNr)
                    else:
                        for lostEvent in lostEvents:
                            if (lostEvent.met > 100 and lostEvent.nJets < 3
                                ) or (lostEvent.met > 150
                                      and lostEvent.nJets < 2):
                                nJets += 1
                            if (lostEvent.nJets == 2 and lostEvent.met < 150
                                ) or (lostEvent.nJets >= 3
                                      and lostEvent.met < 100):
                                met += 1
                            if lostEvent.pt1 < 20 or lostEvent.pt2 < 20:
                                leptonPt += 1
                            if lostEvent.p4.M() < 20 or lostEvent.p4.M() > 70:
                                mll += 1

            print "test"
            for evPrompt in treesPrompt[combination]:
                found = False
                for evReReco in trees[combination]:
                    if evReReco.runNr == evPrompt.runNr and evReReco.lumiSec == evPrompt.lumiSec and evReReco.eventNr == evPrompt.eventNr:
                        found = True
                if not found:
                    localPromptOnly.append(
                        "%s:%s:%s" %
                        (evPrompt.runNr, evPrompt.lumiSec, evPrompt.eventNr))
                    inPromptJSONOnly += int(
                        isPromptOnly(evPrompt.runNr, evPrompt.lumiSec))
                    lostEvents = getEvent(path, combination, evPrompt.runNr,
                                          evPrompt.lumiSec, evPrompt.eventNr)
                    if lostEvents.GetEntries() == 0:
                        isNotInOtherTreePrompt += 1
                        if not isPromptOnly(evPrompt.runNr, evPrompt.lumiSec):
                            print "%d:%d:%d" % (evPrompt.runNr,
                                                evPrompt.lumiSec,
                                                evPrompt.eventNr)
                    else:
                        for lostEvent in lostEvents:
                            if (lostEvent.met > 100 and lostEvent.nJets < 3
                                ) or (lostEvent.met > 150
                                      and lostEvent.nJets < 2):
                                nJetsPrompt += 1
                            if (lostEvent.nJets == 2 and lostEvent.met < 150
                                ) or (lostEvent.nJets >= 3
                                      and lostEvent.met < 100):
                                metPrompt += 1
                            if lostEvent.pt1 < 20 or lostEvent.pt2 < 20:
                                leptonPtPrompt += 1
                            if lostEvent.p4.M() < 20 or lostEvent.p4.M() > 70:
                                mllPrompt += 1
            reRecoOnly[combination] = localReRecoOnly
            promptOnly[combination] = localPromptOnly

            print "%s : %d (%d) ReReco only, %d (%d) Prompt Only" % (
                combination, len(localReRecoOnly), inReRecoJSONOnly,
                len(localPromptOnly), inPromptJSONOnly)
            print isNotInOtherTree, isNotInOtherTreePrompt
            print "ReReco: nJets %d MET %d lepton pt %d mll %d" % (
                nJets, met, leptonPt, mll)
            print "Prompt: nJets %d MET %d lepton pt %d mll %d" % (
                nJetsPrompt, metPrompt, leptonPtPrompt, mllPrompt)
def main():
    ### for data

    histos = ["BB", "BE"]
    labels = ["dimuon_Moriond2017_BB", "dimuon_Moriond2017_BE"]

    bins = [4, 7]

    massPlot = getPlot("massPlotForLimit")
    massPlotSmeared = getPlot("massPlotSmeared")
    massPlotUp = getPlot("massPlotUp")
    massPlotDown = getPlot("massPlotDown")
    massPlotPUUp = getPlot("massPlotPUUp")
    massPlotPUDown = getPlot("massPlotPUDown")
    massPlotWeighted = getPlot("massPlotWeighted")

    for i, histo in enumerate(histos):
        label = labels[i]

        drellyan = Process(getattr(Backgrounds, "DrellYan"))
        other = Process(getattr(Backgrounds, "Other"))
        #~ drellyan = Process(getattr(Signals,"CITo2Mu_Lam34TeVConLL"))

        dyHist = deepcopy(drellyan.loadHistogramProjected(massPlot, bins[i]))
        dyHistSmear = deepcopy(
            drellyan.loadHistogramProjected(massPlotSmeared, bins[i]))
        dyHistScaleUp = deepcopy(
            drellyan.loadHistogramProjected(massPlotUp, bins[i]))
        dyHistScaleDown = deepcopy(
            drellyan.loadHistogramProjected(massPlotDown, bins[i]))
        dyHistPUUp = deepcopy(
            drellyan.loadHistogramProjected(massPlotPUUp, bins[i]))
        dyHistPUDown = deepcopy(
            drellyan.loadHistogramProjected(massPlotPUDown, bins[i]))
        dyHistWeighted = deepcopy(
            drellyan.loadHistogramProjected(massPlotWeighted, bins[i]))
        if "_BE" in label:
            dyHist.Add(deepcopy(drellyan.loadHistogramProjected(massPlot, 10)))
            dyHistSmear.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotSmeared, 10)))
            dyHistScaleUp.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotUp, 10)))
            dyHistScaleDown.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotDown, 10)))
            dyHistPUUp.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotPUUp, 10)))
            dyHistPUDown.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotPUDown, 10)))
            dyHistWeighted.Add(
                deepcopy(drellyan.loadHistogramProjected(massPlotWeighted,
                                                         10)))
        dyHist.Add(deepcopy(other.loadHistogramProjected(massPlot, bins[i])))
        dyHistSmear.Add(
            deepcopy(other.loadHistogramProjected(massPlotSmeared, bins[i])))
        dyHistScaleUp.Add(
            deepcopy(other.loadHistogramProjected(massPlotUp, bins[i])))
        dyHistScaleDown.Add(
            deepcopy(other.loadHistogramProjected(massPlotDown, bins[i])))
        dyHistPUUp.Add(
            deepcopy(other.loadHistogramProjected(massPlotPUUp, bins[i])))
        dyHistPUDown.Add(
            deepcopy(other.loadHistogramProjected(massPlotPUDown, bins[i])))
        dyHistWeighted.Add(
            deepcopy(other.loadHistogramProjected(massPlotWeighted, bins[i])))
        if "_BE" in label:
            dyHist.Add(deepcopy(other.loadHistogramProjected(massPlot, 10)))
            dyHistSmear.Add(
                deepcopy(other.loadHistogramProjected(massPlotSmeared, 10)))
            dyHistScaleUp.Add(
                deepcopy(other.loadHistogramProjected(massPlotUp, 10)))
            dyHistScaleDown.Add(
                deepcopy(other.loadHistogramProjected(massPlotDown, 10)))
            dyHistPUUp.Add(
                deepcopy(other.loadHistogramProjected(massPlotPUUp, 10)))
            dyHistPUDown.Add(
                deepcopy(other.loadHistogramProjected(massPlotPUDown, 10)))
            dyHistWeighted.Add(
                deepcopy(other.loadHistogramProjected(massPlotWeighted, 10)))
        rebin = 500
        dyHist.Rebin(rebin)
        dyHistSmear.Rebin(rebin)
        dyHistPUUp.Rebin(rebin)
        dyHistPUDown.Rebin(rebin)
        dyHistScaleDown.Rebin(rebin)
        dyHistWeighted.Rebin(rebin)
        hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

        plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
        ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
        setTDRStyle()
        plotPad.UseCurrentStyle()
        ratioPad.UseCurrentStyle()
        plotPad.Draw()
        ratioPad.Draw()
        plotPad.cd()

        plotPad.DrawFrame(0, 0.0001, 5000, 500000,
                          "; dimuon mass [GeV]; Events / 500 GeV")
        plotPad.SetLogy()
        dyHist.Draw("samehist")
        dyHist.SetFillColor(kWhite)
        dyHistSmear.SetFillColor(kWhite)
        dyHistScaleDown.SetFillColor(kWhite)
        dyHistWeighted.SetFillColor(kWhite)
        dyHistPUUp.SetFillColor(kWhite)
        dyHistPUDown.SetFillColor(kWhite)
        dyHistSmear.SetLineColor(kRed)
        dyHistScaleDown.SetLineColor(kBlue)
        dyHistWeighted.SetLineColor(kGreen + 2)
        dyHistPUUp.SetLineColor(kOrange + 2)
        dyHistSmear.Draw("samehist")
        dyHistScaleDown.Draw("samehist")
        dyHistWeighted.Draw("samehist")
        dyHistPUUp.Draw("samehist")

        legend = TLegend(0.375, 0.6, 0.925, 0.925)
        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        legend.SetTextFont(42)
        legend.AddEntry(dyHist, "Default", "l")
        legend.AddEntry(dyHistSmear, "Resolution Uncertainty", "l")
        legend.AddEntry(dyHistScaleDown, "Scale Uncertainty", "l")
        legend.AddEntry(dyHistWeighted, "ID Uncertainty", "l")
        legend.AddEntry(dyHistPUUp, "PU Uncertainty", "l")
        legend.Draw()

        ratioPad.cd()
        xMin = 0
        xMax = 5000
        yMax = 1.1
        yMin = 0.9
        if "BE" in label:
            yMax = 1.2
            yMin = 0.8
        ratioGraphs = ratios.RatioGraph(dyHist,
                                        dyHistSmear,
                                        xMin=xMin,
                                        xMax=xMax,
                                        title="Default / Uncert",
                                        yMin=yMin,
                                        yMax=yMax,
                                        ndivisions=10,
                                        color=kRed,
                                        adaptiveBinning=10000)
        ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8)
        ratioGraphs2 = ratios.RatioGraph(dyHist,
                                         dyHistScaleDown,
                                         xMin=xMin,
                                         xMax=xMax,
                                         title="Default / Uncert",
                                         yMin=0.8,
                                         yMax=1.3,
                                         ndivisions=10,
                                         color=kBlue,
                                         adaptiveBinning=10000)
        ratioGraphs2.draw(ROOT.gPad, False, False, True, chi2Pos=0.8)
        ratioGraphs3 = ratios.RatioGraph(dyHist,
                                         dyHistWeighted,
                                         xMin=xMin,
                                         xMax=xMax,
                                         title="Default / Uncert",
                                         yMin=0.8,
                                         yMax=1.3,
                                         ndivisions=10,
                                         color=kGreen + 2,
                                         adaptiveBinning=10000)
        ratioGraphs3.draw(ROOT.gPad, False, False, True, chi2Pos=0.8)
        ratioGraphs4 = ratios.RatioGraph(dyHist,
                                         dyHistPUUp,
                                         xMin=xMin,
                                         xMax=xMax,
                                         title="Default / Uncert",
                                         yMin=0.8,
                                         yMax=1.3,
                                         ndivisions=10,
                                         color=kOrange + 2,
                                         adaptiveBinning=10000)
        ratioGraphs4.draw(ROOT.gPad, False, False, True, chi2Pos=0.8)

        hCanvas.Print("uncertainties_%s.pdf" % label)
Пример #28
0
def main():



        parser = argparse.ArgumentParser(description='R(out/in) measurements.')
        
        parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False,
                                                  help="Verbose mode.")
        parser.add_argument("-s", "--selection", dest = "selection" , action="append", default=[],
                                                  help="selection which to apply.")
        parser.add_argument("-p", "--plot", dest="plots", action="append", default=[],
                                                  help="select dependencies to study, default is all.")
        parser.add_argument("-r", "--runRange", dest="runRange", action="append", default=[],
                                                  help="name of run range.")
        parser.add_argument("-b", "--backgrounds", dest="backgrounds", action="append", default=[],
                                                  help="backgrounds to plot.")      
        parser.add_argument("-x", "--private", action="store_true", dest="private", default=False,
                                                  help="plot is private work.")   
                                        
        args = parser.parse_args()


        
        if len(args.backgrounds) == 0:
                args.backgrounds = ["DrellYan", "RareTTZOnZ","RareZZLowMassOnZ","RareWZOnZ"]

        args.runRange = [RR["2016"].name, RR["2017"].name ,RR["2018"].name]
        
        args.selection = ["DrellYanControl", "SignalHighMT2DeltaPhiJetMetFit"]
        
        template = plotTemplate()
        
        histos = {}
        merged = {}
        runRanges = [getRunRange(runRangeName) for runRangeName in args.runRange]
        for selectionName in args.selection:
                histos[selectionName] = {}
                selection = getRegion(selectionName)
                for runRangeName in args.runRange:
                        runRange = getRunRange(runRangeName)
                        
                        plot = getPlot("mllPlot")
                        plot.addRegion(selection)
                        plot.cleanCuts()
                        plot.addRunRange(runRange)      
                        
                        histo = getHistogram(plot, runRange, args.backgrounds, "Inclusive")
                        histos[selectionName][runRangeName] = histo
                for i,runRangeName in enumerate(args.runRange):
                        if i == 0:
                                merged[selectionName] = histos[selectionName][runRangeName].Clone()
                        else:
                                merged[selectionName].Add(histos[selectionName][runRangeName], 1)
                merged[selectionName].Scale(1.0/merged[selectionName].Integral())
        
        #["DrellYanControl", "SignalInclusiveHighMT2"]
        merged["DrellYanControl"].SetLineColor(ROOT.kBlack)
        merged["DrellYanControl"].SetLineWidth(2)
        merged["DrellYanControl"].SetLineStyle(2)
        merged["DrellYanControl"].SetMarkerSize(0)
        merged["SignalHighMT2DeltaPhiJetMetFit"].SetLineColor(ROOT.kRed)
        merged["SignalHighMT2DeltaPhiJetMetFit"].SetLineWidth(2)
        merged["SignalHighMT2DeltaPhiJetMetFit"].SetMarkerSize(0)
        template.setPrimaryPlot(merged["DrellYanControl"], "histE", label="Z backgrounds in CR")
        template.addSecondaryPlot(merged["SignalHighMT2DeltaPhiJetMetFit"], "histE", label="Z backgrounds in fit SR")
        template.labelX = "mll [GeV]"
        template.labelY = "a.u."
        template.hasLegend = True
        template.logY = True
        template.maximumY = 3
        template.minimumY = 1e-5
        template.setFolderName("onZMllShapes")
        template.draw()
        template.saveAs("cr_fitsr")
Пример #29
0
def plotIsolation(selection):
    from centralConfig import runRanges

    first = False
    histEEPromptAll = None
    histMMPromptAll = None
    histEEHeavyFlavourAll = None
    histMMHeavyFlavourAll = None
    histEEFakeAll = None
    histMMFakeAll = None

    fake = "!((pt1 < pt 2)*(abs(pdgId1)==11 || abs(pdgId1)==13 || (abs(pdgId1) == 22 && (abs(motherPdgId1) == 11 || abs(motherPdgId1) == 13 )))   || (pt1 > pt 2)*(abs(pdgId2)==11 || abs(pdgId2)==13) || (abs(pdgId2) == 22 && (abs(motherPdgId2) == 11 || abs(motherPdgId2) == 13 )))"
    dilep = "((pt1 < pt 2)*(abs(motherPdgId1)== 24 || abs(motherPdgId1)== 23 || abs(grandMotherPdgId1)== 24 || abs(grandMotherPdgId1)== 23) || (pt1 > pt 2)*(abs(motherPdgId2)== 24 || abs(motherPdgId2)== 23 || abs(grandMotherPdgId2)== 24 || abs(grandMotherPdgId2)== 23))"

    backgrounds = ["TT_Powheg"]

    first = True
    for runRangeName in runRanges.allNames:
        runRange = getRunRange(runRangeName)
        path = locations[runRange.era].dataSetPathNonIso

        plot = getPlot("trailingIsoPlot")
        plot.addRegion(selection)
        plot.addRunRange(runRange)

        tmpCuts = plot.cuts

        plot.cuts = plot.cuts + "*(%s && !%s && !(pdgId1 == -9999 || pdgId2 == -9999))" % (
            dilep, fake)

        histEEPrompt, histMMPrompt = getHistograms(path, plot, runRange,
                                                   backgrounds)
        if first:
            histEEPromptAll = histEEPrompt.Clone()
            histMMPromptAll = histMMPrompt.Clone()
        else:
            histEEPromptAll.Add(histEEPrompt, 1.0)
            histMMPromptAll.Add(histMMPrompt, 1.0)

        plot.cuts = tmpCuts + "*(!%s && !%s && !(pdgId1 == -9999 || pdgId2 == -9999))" % (
            dilep, fake)

        histEEHeavyFlavour, histMMHeavyFlavour = getHistograms(
            path, plot, runRange, backgrounds)

        if first:
            histEEHeavyFlavourAll = histEEHeavyFlavour.Clone()
            histMMHeavyFlavourAll = histMMHeavyFlavour.Clone()
        else:
            histEEHeavyFlavourAll.Add(histEEHeavyFlavour, 1.0)
            histMMHeavyFlavourAll.Add(histMMHeavyFlavour, 1.0)

        plot.cuts = tmpCuts + "*(%s && !(pdgId1 == -9999 || pdgId2 == -9999))" % (
            fake)

        histEEFake, histMMFake = getHistograms(path, plot, runRange,
                                               backgrounds)
        #~
        if first:
            histEEFakeAll = histEEFake.Clone()
            histMMFakeAll = histMMFake.Clone()
        else:
            histEEFakeAll.Add(histEEFake, 1.0)
            histMMFakeAll.Add(histMMFake, 1.0)

        if first:
            first = False

    plotDistribution(histEEPromptAll, histEEHeavyFlavourAll, histEEFakeAll,
                     "electrons")
    plotDistribution(histMMPromptAll, histMMHeavyFlavourAll, histMMFakeAll,
                     "muons")
Пример #30
0
def main():
    ### for data

    histos = ["BB", "BE"]
    labels = ["dimuon_Moriond2017_BB", "dimuon_Moriond2017_BE"]

    lambdas = [10, 16, 22, 28, 34]
    models = ["ConLL", "ConLR", "ConRR", "DesLL", "DesLR", "DesRR"]
    bins = [4, 7]

    massPlot = getPlot("massPlotForLimit")
    massPlotSmeared = getPlot("massPlotSmeared")
    massPlotUp = getPlot("massPlotUp")
    massPlotDown = getPlot("massPlotDown")
    massPlotWeighted = getPlot("massPlotWeighted")

    binning = [400, 500, 700, 1100, 1900, 3500]

    name = "CITo2Mu_Lam10TeVConLL"
    signal = Process(getattr(Signals, name))

    sigHistRaw = deepcopy(signal.loadHistogramProjected(massPlot, 1))
    sigHistWeightedRaw = deepcopy(
        signal.loadHistogramProjected(massPlotWeighted, 1))

    sigHist = ROOT.TH1F("sigHist", "sigHist",
                        len(binning) - 1, array('f', binning))
    sigHistWeighted = ROOT.TH1F("sigHistWeighted", "sigHistWeighted",
                                len(binning) - 1, array('f', binning))
    sigHist.Sumw2()
    sigHistWeighted.Sumw2()
    for index, lower in enumerate(binning):
        if index < len(binning) - 1:
            sigHist.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistRaw.Integral(
                        sigHistRaw.FindBin(lower),
                        sigHistRaw.FindBin(binning[index + 1] - 0.001))))
            sigHistWeighted.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistWeightedRaw.Integral(
                        sigHistWeightedRaw.FindBin(lower),
                        sigHistWeightedRaw.FindBin(binning[index + 1] -
                                                   0.001))))

    hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)
    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    setTDRStyle()
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()

    plotPad.DrawFrame(400, 0, 3500, 3500, "; m [GeV]; Events")

    sigHist.Draw("samehist")
    sigHistWeighted.Draw("samehist")
    sigHistWeighted.SetLineColor(kRed)
    ratioPad.cd()
    ratioGraphs = ratios.RatioGraph(sigHist,
                                    sigHistWeighted,
                                    xMin=400,
                                    xMax=3500,
                                    title="Default/Weighted",
                                    yMin=0.8,
                                    yMax=1.2,
                                    ndivisions=10,
                                    color=ROOT.kBlack,
                                    adaptiveBinning=10000)
    ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8)

    ROOT.gPad.RedrawAxis()
    plotPad.RedrawAxis()
    ratioPad.RedrawAxis()
    hCanvas.Print("weighting.pdf")

    name = "CITo2Mu_Lam10TeVConLL"
    signal = Process(getattr(Signals, name))

    sigHistRaw = deepcopy(signal.loadHistogramProjected(massPlot, 4))
    sigHistWeightedRaw = deepcopy(
        signal.loadHistogramProjected(massPlotWeighted, 4))

    sigHist = ROOT.TH1F("sigHist", "sigHist",
                        len(binning) - 1, array('f', binning))
    sigHistWeighted = ROOT.TH1F("sigHistWeighted", "sigHistWeighted",
                                len(binning) - 1, array('f', binning))
    sigHist.Sumw2()
    sigHistWeighted.Sumw2()
    for index, lower in enumerate(binning):
        if index < len(binning) - 1:
            sigHist.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistRaw.Integral(
                        sigHistRaw.FindBin(lower),
                        sigHistRaw.FindBin(binning[index + 1] - 0.001))))
            sigHistWeighted.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistWeightedRaw.Integral(
                        sigHistWeightedRaw.FindBin(lower),
                        sigHistWeightedRaw.FindBin(binning[index + 1] -
                                                   0.001))))

    hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)
    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    setTDRStyle()
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()

    plotPad.DrawFrame(400, 0, 3500, 3500, "; m [GeV]; Events")

    sigHist.Draw("samehist")
    sigHistWeighted.Draw("samehist")
    sigHistWeighted.SetLineColor(kRed)
    ratioPad.cd()
    ratioGraphs = ratios.RatioGraph(sigHist,
                                    sigHistWeighted,
                                    xMin=400,
                                    xMax=3500,
                                    title="Default/Weighted",
                                    yMin=0.8,
                                    yMax=1.2,
                                    ndivisions=10,
                                    color=ROOT.kBlack,
                                    adaptiveBinning=10000)
    ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8)

    ROOT.gPad.RedrawAxis()
    plotPad.RedrawAxis()
    ratioPad.RedrawAxis()
    hCanvas.Print("weightingBB.pdf")
    name = "CITo2Mu_Lam10TeVConLL"
    signal = Process(getattr(Signals, name))

    sigHistRaw = deepcopy(signal.loadHistogramProjected(massPlot, 7))
    sigHistWeightedRaw = deepcopy(
        signal.loadHistogramProjected(massPlotWeighted, 7))

    sigHist = ROOT.TH1F("sigHist", "sigHist",
                        len(binning) - 1, array('f', binning))
    sigHistWeighted = ROOT.TH1F("sigHistWeighted", "sigHistWeighted",
                                len(binning) - 1, array('f', binning))
    sigHist.Sumw2()
    sigHistWeighted.Sumw2()
    for index, lower in enumerate(binning):
        if index < len(binning) - 1:
            sigHist.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistRaw.Integral(
                        sigHistRaw.FindBin(lower),
                        sigHistRaw.FindBin(binning[index + 1] - 0.001))))
            sigHistWeighted.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistWeightedRaw.Integral(
                        sigHistWeightedRaw.FindBin(lower),
                        sigHistWeightedRaw.FindBin(binning[index + 1] -
                                                   0.001))))

    hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)
    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    setTDRStyle()
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()

    plotPad.DrawFrame(400, 0, 3500, 3500, "; m [GeV]; Events")

    sigHist.Draw("samehist")
    sigHistWeighted.Draw("samehist")
    sigHistWeighted.SetLineColor(kRed)
    ratioPad.cd()
    ratioGraphs = ratios.RatioGraph(sigHist,
                                    sigHistWeighted,
                                    xMin=400,
                                    xMax=3500,
                                    title="Default/Weighted",
                                    yMin=0.8,
                                    yMax=1.2,
                                    ndivisions=10,
                                    color=ROOT.kBlack,
                                    adaptiveBinning=10000)
    ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8)

    ROOT.gPad.RedrawAxis()
    plotPad.RedrawAxis()
    ratioPad.RedrawAxis()
    hCanvas.Print("weightingBE.pdf")
    name = "CITo2Mu_Lam10TeVConLL"
    signal = Process(getattr(Signals, name))

    sigHistRaw = deepcopy(signal.loadHistogramProjected(massPlot, 10))
    sigHistWeightedRaw = deepcopy(
        signal.loadHistogramProjected(massPlotWeighted, 10))

    sigHist = ROOT.TH1F("sigHist", "sigHist",
                        len(binning) - 1, array('f', binning))
    sigHistWeighted = ROOT.TH1F("sigHistWeighted", "sigHistWeighted",
                                len(binning) - 1, array('f', binning))
    sigHist.Sumw2()
    sigHistWeighted.Sumw2()
    for index, lower in enumerate(binning):
        if index < len(binning) - 1:
            sigHist.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistRaw.Integral(
                        sigHistRaw.FindBin(lower),
                        sigHistRaw.FindBin(binning[index + 1] - 0.001))))
            sigHistWeighted.SetBinContent(
                index + 1,
                max(
                    0,
                    sigHistWeightedRaw.Integral(
                        sigHistWeightedRaw.FindBin(lower),
                        sigHistWeightedRaw.FindBin(binning[index + 1] -
                                                   0.001))))

    hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)
    plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1)
    ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3)
    setTDRStyle()
    plotPad.UseCurrentStyle()
    ratioPad.UseCurrentStyle()
    plotPad.Draw()
    ratioPad.Draw()
    plotPad.cd()

    plotPad.DrawFrame(400, 0, 3500, 3500, "; m [GeV]; Events")

    sigHist.Draw("samehist")
    sigHistWeighted.Draw("samehist")
    sigHistWeighted.SetLineColor(kRed)
    ratioPad.cd()
    ratioGraphs = ratios.RatioGraph(sigHist,
                                    sigHistWeighted,
                                    xMin=400,
                                    xMax=3500,
                                    title="Default/Weighted",
                                    yMin=0.8,
                                    yMax=1.2,
                                    ndivisions=10,
                                    color=ROOT.kBlack,
                                    adaptiveBinning=10000)
    ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8)

    ROOT.gPad.RedrawAxis()
    plotPad.RedrawAxis()
    ratioPad.RedrawAxis()
    hCanvas.Print("weightingEE.pdf")
Пример #31
0
        return tempHist
def Addstack(Stacklist):
        tempStack=Stacklist[0]
        for i in range(1,3):
                tempStack.Add(Stacklist[i])
        return tempStack 
def Stacks(processes,lumi,plot,zScale):
        stacks=[]
        for i in range(3):
                stacks.append(TheStack(processes[i],lumi[i],plot,zScale[i]))
        return stacks

datamubb=[]
datamube=[]
data_mu=[Process(Data2016, normalized=True),Process(Data, normalized=True),Process(Data2018, normalized=True)]
plot_mu_bb = getPlot("massPlotBB")
plot_mu_be = getPlot("massPlotBE")
lumi_mu = [36.3*1000,42.135*1000,61.608*1000]
zScaleFac_mu = [zScale2016["muons"],zScale["muons"],zScale2018["muons"]]
for i in range(3):
	datamubb.append(data_mu[i].loadHistogram(plot_mu_bb,lumi_mu[i],zScaleFac_mu[i]))
	datamube.append(data_mu[i].loadHistogram(plot_mu_be,lumi_mu[i],zScaleFac_mu[i]))

bng=[50, 120,150,200,300,400,500,690,900,1250,1610, 2000, 4000, 6070]
#bng=[60,120,400,600,900,1300,1800,6000]
bng=numpy.asarray(bng,dtype=numpy.float64)
datamubb2016=ROOT.TH1D("datamubb2016","datamubb2016",len(bng)-1,bng)
datamubb2017=ROOT.TH1D("datamubb2017","datamubb2017",len(bng)-1,bng)
datamubb2018=ROOT.TH1D("datamubb2018","datamubb2018",len(bng)-1,bng)
datamube2016=ROOT.TH1D("datamube2016","datamube2016",len(bng)-1,bng)
datamube2017=ROOT.TH1D("datamube2017","datamube2017",len(bng)-1,bng)
Пример #32
0
def plot(path, selection, plots, runRange, isMC, backgrounds, cmsExtra):

    for name in plots:
        plot = getPlot(name)
        plot.addRegion(selection)
        plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut

        if isMC:
            histEE, histMM = getHistograms(path, plot, runRange, True,
                                           backgrounds)
        else:
            histEE, histMM = getHistograms(path, plot, runRange, False,
                                           backgrounds)

        hCanvas = TCanvas("hCanvas", "Distribution", 800, 800)

        plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1)
        setTDRStyle()
        plotPad.UseCurrentStyle()

        plotPad.Draw()
        plotPad.cd()

        latex = ROOT.TLatex()
        latex.SetTextFont(42)
        latex.SetTextAlign(31)
        latex.SetTextSize(0.04)
        latex.SetNDC(True)
        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)

        intlumi = ROOT.TLatex()
        intlumi.SetTextAlign(12)
        intlumi.SetTextSize(0.03)
        intlumi.SetNDC(True)

        logScale = plot.log

        if logScale == True:
            plotPad.SetLogy()

        yMax = histMM.GetBinContent(histMM.GetMaximumBin())
        if plot.yMax == 0:
            if logScale:
                yMax = yMax * 1000
            else:
                yMax = yMax * 1.5

        else:
            yMax = plot.yMax

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

        legend = ROOT.TLegend(0.65, 0.7, 0.9, 0.9)
        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        legend.AddEntry(histMM, "#mu#mu events", "p")
        legend.AddEntry(histEE, "ee events", "p")
        histMM.SetMarkerColor(ROOT.kRed)
        histMM.SetLineColor(ROOT.kRed)
        histMM.SetMarkerStyle(20)
        histEE.SetMarkerStyle(21)
        histMM.Draw("samepe")
        histEE.Draw("samepe")
        legend.Draw("same")
        ROOT.gPad.SetLogy(1)

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

        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))

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