Пример #1
0
def main():
        
        

        parser = argparse.ArgumentParser(description='create cut justification plots.')
        
        parser.add_argument("-u", "--use", action="store_true", dest="use", default=False,
                                                  help="Use existing.")

        args = parser.parse_args()


        cutRegions = ["basicCut","nJets2Cut","met150Cut","deltaPhiCut","signalRegionCut"]
        NllCutRegions = ["lowNll","highNll"]
        nBCutRegions = NBCuts.keys()
        mllCutRegions = ["20To60","60To86","86To96","96To150","150To200","200To300","300To400","Above400"]
        
        
        
        
        if not args.use:
                counts = {}
                
                for cutRegion in cutRegions:
                        addCut = signalRegionCuts[cutRegion]
                        useNLL = False
                        if "met > 150" in addCut:
                                useNLL = True
                        counts[cutRegion] = getEventCount(getRegion("Inclusive"), addCut, "mllPlot", useNLL) 
                        print cutRegion
                        
                cutRegion = "signalRegionCut"
                for nBCut in nBCutRegions:
                        for nllCut in NllCutRegions:
                                for mllCut in mllCutRegions:
                                        addCut = "%s && %s && %s && %s"%(signalRegionCuts[cutRegion], NllCuts[nllCut], NBCuts[nBCut], mllCuts[mllCut])
                                        cutName = "%s_%s_%s_%s"%(cutRegion, nllCut, nBCut, mllCut)
                                        useNLL = True
                                        counts[cutName] = getEventCount(getRegion("Inclusive"), addCut, "mllPlot", useNLL) 
                                        print cutName
                                        
                with open("shelves/cutFlowMC.pkl", "w") as fi:
                        pickle.dump(counts, fi)
        else:
                with open("shelves/cutFlowMC.pkl", "r") as fi:
                        counts = pickle.load(fi)                           
         
        makeCutflowTable(counts)
Пример #2
0
def main():



	parser = argparse.ArgumentParser(description='rMuE measurements.')
	
	parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False,
						  help="Verbose mode.")
	parser.add_argument("-m", "--mc", action="store_true", dest="mc", default=False,
						  help="use MC, default is to use data.")
	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 = backgroundLists.default
	if len(args.plots) == 0:
		args.plots = plotLists.default
	if len(args.selection) == 0:
		
			args.selection.append("Inclusive")	
	

			
	if len(args.runRange) == 0:
		args.runRange.append(runRanges.name)		

	path = locations.dataSetPath

	

	cmsExtra = ""
	if args.private:
		cmsExtra = "Private Work"
		if args.mc:
			cmsExtra = "#splitline{Private Work}{Simulation}"
	elif args.mc:
		cmsExtra = "Simulation"	
	else:
		cmsExtra = "Preliminary"
	for runRangeName in args.runRange:
		runRange = getRunRange(runRangeName)
	
		for selectionName in args.selection:
			
			selection = getRegion(selectionName)

			plot(path,selection,args.plots,runRange,args.mc,args.backgrounds,cmsExtra)		
Пример #3
0
def main():

    parser = argparse.ArgumentParser(
        description='create cut justification plots.')

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

    args = parser.parse_args()

    if len(args.selection) == 0:
        args.selection.append("Inclusive")

    for selectionName in args.selection:
        selection = getRegion(selectionName)
        plotIsolation(selection)
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()
Пример #5
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()
Пример #6
0
def main():

    parser = argparse.ArgumentParser(
        description='create cut justification plots.')

    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("-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 = backgroundLists.Loose
    if len(args.selection) == 0:
        args.selection.append("Region")

    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.dataSetPathLoose

    cmsExtra = ""
    if args.private:
        cmsExtra = "#splitline{Private Work}{Simulation}"
    else:
        cmsExtra = "Simulation"

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in args.selection:

            selection = getRegion(selectionName)

            plotIsolationEff(path, selection, runRange, cmsExtra,
                             args.backgrounds)
Пример #7
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
Пример #8
0
def makeResultPlot(path,
                   selection,
                   runRange,
                   cmsExtra,
                   edgeShape=False,
                   edgeShapeMC=False,
                   differentEdgePositions=False):

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

    plotDY = getPlot("mllPlot")

    if "Forward" in selection.name:
        plotDY.addRegion(getRegion("DrellYanControlForward"))
        region = "forward"
    elif "Central" in selection.name:
        plotDY.addRegion(getRegion("DrellYanControlCentral"))
        region = "central"
    else:
        plotDY.addRegion(getRegion("DrellYanControl"))
        region = "inclusive"
    plotDY.cleanCuts()
    plotDY.cuts = plotDY.cuts % runRange.runCut

    plotDYScale = getPlot("mllPlotROutIn")

    if "Forward" in selection.name:
        plotDYScale.addRegion(getRegion("DrellYanControlForward"))
    elif "Central" in selection.name:
        plotDYScale.addRegion(getRegion("DrellYanControlCentral"))
    else:
        plotDYScale.addRegion(getRegion("DrellYanControl"))
    plotDYScale.cleanCuts()
    plotDYScale.cuts = plotDYScale.cuts % runRange.runCut

    histEE, histMM, histEM = getHistograms(path, plot, runRange, False, [])
    histSF = histEE.Clone("histSF")
    histSF.Add(histMM.Clone())

    print histSF.Integral()

    histEEDY, histMMDY, histEMDY = getHistograms(path, plotDY, runRange, False,
                                                 [])
    histSFDY = histEEDY.Clone("histSFDY")
    histSFDY.Add(histMMDY.Clone())

    print histSFDY.Integral()

    histEEDYScale, histMMDYScale, histEMDYScale = getHistograms(
        path, plotDY, runRange, False, [])
    histSFDYScale = histEEDYScale.Clone("histSFDYScale")
    histSFDYScale.Add(histMMDYScale.Clone())

    print histSFDYScale.Integral()

    histOFSF = histEM.Clone("histOFSF")
    histOFEE = histEM.Clone("histOFEE")
    histOFMM = histEM.Clone("histOFMM")
    histOFSF.Scale(getattr(rSFOF, region).val)
    histOFEE.Scale(getattr(rEEOF, region).val)
    histOFMM.Scale(getattr(rMMOF, region).val)

    if region == "inclusive":
        histSFDY.Scale(zPredictions.legacy.SF.central.val +
                       (zPredictions.legacy.SF.forward.val) /
                       histSFDYScale.Integral(histSFDYScale.FindBin(81),
                                              histSFDYScale.FindBin(101)))
        #~ histEEDY.Scale((getattr(zPredictions,bSelection).EE.central.val + getattr(zPredictions,bSelection).EE.forward.val) / histEEDYScale.Integral(histEEDYScale.FindBin(81),histEEDYScale.FindBin(101)))
        #~ histMMDY.Scale((getattr(zPredictions,bSelection).MM.central.val + getattr(zPredictions,bSelection).MM.forward.val) / histMMDYScale.Integral(histMMDYScale.FindBin(81),histMMDYScale.FindBin(101)))
    else:
        histSFDY.Scale(
            getattr(zPredictions.legacy.SF, region).val /
            histSFDYScale.Integral(histSFDYScale.FindBin(81),
                                   histSFDYScale.FindBin(101)))
        #~ histEEDY.Scale(getattr(zPredictions.legacy.EE,region).val / histEEDYScale.Integral(histEEDYScale.FindBin(81),histEEDYScale.FindBin(101)))
        #~ histMMDY.Scale(getattr(getattr(zPredictions,bSelection).MM,region).val / histMMDYScale.Integral(histMMDYScale.FindBin(81),histMMDYScale.FindBin(101)))

    nbins = histSFDY.GetNbinsX()
    for i in range(0, nbins + 1):
        if i >= histSFDY.FindBin(71.):
            histSF.SetBinContent(i, 0.)
            histOFSF.SetBinContent(i, 0.)
            histSFDY.SetBinContent(i, 0.)

    makePlot(histSF,
             histOFSF,
             selection,
             plot,
             runRange,
             region,
             cmsExtra,
             "SF",
             histSFDY,
             edgeShape=edgeShape,
             edgeShapeMC=edgeShapeMC,
             differentEdgePositions=differentEdgePositions)
Пример #9
0
def main():
	
	
	

	parser = argparse.ArgumentParser(description='edge fitter reloaded.')
	
	parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False,
						  help="Verbose mode.")
	parser.add_argument("-S", "--sample", action="store", dest="sample", default="all",
						  help="choose a sample to convert, default is all.")
	parser.add_argument("-s", "--selection", dest = "selection" , action="store", default="SignalInclusive",
						  help="selection which to apply.")	
	parser.add_argument("-r", "--runRange", dest="runRange", action="append", default=[],
						  help="name of run range.")
					
	args = parser.parse_args()	
	
	canv = TCanvas("canv", "canv",800,800)
	plotPad = ROOT.TPad("plotPad","plotPad",0,0,1,1)
	style=setTDRStyle()	
	plotPad.UseCurrentStyle()
	plotPad.Draw()	
	plotPad.cd()
	
	path = locations.dataSetPathNLL
	baseTreePath = locations.dataSetPath
	
	if len(args.selection) == 0:
		args.selection.append(regionsToUse.signal.inclusive.name)	
	if len(args.runRange) == 0:
		args.runRange.append(runRanges.name)



	region = args.selection
	
	print region
	
	from defs import Regions
	if not region in dir(Regions):
		print "invalid region, exiting"
		sys.exit()
	else:	
		Selection = getattr(Regions,region)
		
	backgrounds = ["TT_Powheg"]
	
	cmsExtra = "Simulation"
	
	for runRangeName in args.runRange:
		runRange = getRunRange(runRangeName)
	
		for selection in ["defaultMll","defaultNLL","lowNLL","highNLL","lowMll","highMll"]:
			
			Counts = {}
			
			selectedRegion = getRegion(region)
		
			plot = getPlot(plotNames[selection])
			plot.addRegion(selectedRegion)
			
			plot.cuts = plot.cuts % runRange.runCut
			plot.cleanCuts()
			
			plot.cuts = plot.cuts.replace("p4.M()","mll")		
			
			
			histEE, histMM, histEM = getHistograms(path,baseTreePath,plot,runRange,backgrounds)
			#~ histEE.Scale(triggerEffs.inclusive.effEE.val)
			#~ histMM.Scale(triggerEffs.inclusive.effMM.val)
			#~ histEM.Scale(triggerEffs.inclusive.effEM.val)
			histEM.Scale(rSFOF.inclusive.valMC)
			histSF = histEE.Clone("histSF")
			histSF.Add(histMM.Clone())
			
			makePlot(histSF,histEM,selection,plot,runRange,cmsExtra)
			
			histSFOF = histSF.Clone()
			histSFOF.Add(histEM,-1)
Пример #10
0
def main():

    parser = argparse.ArgumentParser(description='rMuE measurements.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="use MC, default is to use data.")
    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("-c",
                        "--centralValues",
                        action="store_true",
                        dest="central",
                        default=False,
                        help="calculate effinciecy central values")
    parser.add_argument("-b",
                        "--backgrounds",
                        dest="backgrounds",
                        action="append",
                        default=[],
                        help="backgrounds to plot.")
    parser.add_argument("-d",
                        "--dependencies",
                        action="store_true",
                        dest="dependencies",
                        default=False,
                        help="make dependency plots")
    parser.add_argument("-z",
                        "--signalRegion",
                        action="store_true",
                        dest="signalRegion",
                        default=False,
                        help="make rMuE in signal region plot")
    parser.add_argument("-f",
                        "--fit",
                        action="store_true",
                        dest="fit",
                        default=False,
                        help="do dependecy fit")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")
    parser.add_argument("-w",
                        "--write",
                        action="store_true",
                        dest="write",
                        default=False,
                        help="write results to central repository")

    args = parser.parse_args()

    if len(args.backgrounds) == 0:
        args.backgrounds = backgroundLists.default
    if len(args.plots) == 0:
        args.plots = plotLists.rMuE
    if len(args.selection) == 0:

        if args.signalRegion:
            #~ args.selection.append(regionsToUse.signal.central.name)
            #~ args.selection.append(regionsToUse.signal.forward.name)
            args.selection.append(regionsToUse.signal.inclusive.name)
        else:
            #~ args.selection.append(regionsToUse.rMuE.central.name)
            #~ args.selection.append(regionsToUse.rMuE.forward.name)
            args.selection.append(regionsToUse.rMuE.inclusive.name)

    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.dataSetPath

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
        if args.mc:
            cmsExtra = "#splitline{Private Work}{Simulation}"
    elif args.mc:
        cmsExtra = "Simulation"
    else:
        cmsExtra = "Preliminary"
    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in args.selection:

            selection = getRegion(selectionName)

            if args.central:
                centralVal = centralValues(path, selection, runRange, args.mc,
                                           args.backgrounds)
                if args.mc:
                    outFilePkl = open(
                        "shelves/rMuE_%s_%s_MC.pkl" %
                        (selection.name, runRange.label), "w")
                else:
                    outFilePkl = open(
                        "shelves/rMuE_%s_%s.pkl" %
                        (selection.name, runRange.label), "w")
                pickle.dump(centralVal, outFilePkl)
                outFilePkl.close()

            if args.dependencies:
                dependencies(path, selection, args.plots, runRange, args.mc,
                             args.backgrounds, cmsExtra, args.fit)
            if args.signalRegion:
                signalRegion(path, selection, args.plots, runRange, args.mc,
                             args.backgrounds, cmsExtra)

            if args.write:
                import subprocess
                if args.mc:
                    bashCommand = "cp shelves/rMuE_%s_%s_MC.pkl %s/shelves" % (
                        selection.name, runRange.label, pathes.basePath)
                else:
                    bashCommand = "cp shelves//rMuE_%s_%s.pkl %s/shelves" % (
                        selection.name, runRange.label, pathes.basePath)
                process = subprocess.Popen(bashCommand.split())
Пример #11
0
    def __init__(self,
                 plot,
                 region="SignalInclusive",
                 runName="Full2012",
                 plotData=True,
                 plotMC=True,
                 normalizeToData=False,
                 plotRatio=True,
                 signals=None,
                 stackSignal=False,
                 useTriggerEmulation=False,
                 useDataTrigEff=False,
                 doTopReweighting=False,
                 personalWork=False,
                 preliminary=True,
                 forPAS=False,
                 forTWIKI=False,
                 backgrounds=[],
                 dontScaleTrig=False,
                 plotSyst=False,
                 doPUWeights=False,
                 normalizeToBinWidth=False):
        sys.path.append(pathes.basePath)

        #~ self.dataSetPath = locations.dataSetPathNLL
        self.dataSetPath = locations.dataSetPath
        if dontScaleTrig:
            self.dataSetPath = locations.dataSetPath
            #~ self.dataSetPath = locations.dataSetPathNLL
        self.runRange = getRunRange(runName)

        if "Central" in region:
            self.etaRegion = "central"
        elif "Forward" in region:
            self.etaRegion = "forward"
        else:
            self.etaRegion = "inclusive"

        self.selection = getRegion(region)

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

        self.plotData = plotData
        self.plotMC = plotMC
        self.plotSyst = plotSyst
        self.normalizeToData = normalizeToData
        self.plotRatio = plotRatio
        self.signals = signals
        self.stackSignal = stackSignal
        if self.signals is not None:
            self.plotSignal = True
        self.backgrounds = backgrounds
        self.useTriggerEmulation = useTriggerEmulation
        self.useDataTrigEff = useDataTrigEff
        self.personalWork = personalWork
        self.preliminary = preliminary
        self.doTopReweighting = doTopReweighting
        self.forPAS = forPAS
        self.forTWIKI = forTWIKI
        self.DontScaleTrig = dontScaleTrig
        self.doPUWeights = doPUWeights
        self.normalizeToBinWidth = normalizeToBinWidth

        from corrections import rSFOF
        self.rSFOF = rSFOF
def getYields(runRange):
    import ratios

    import pickle

    path = locations[runRange.era].dataSetPathNLL

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

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

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

    signalBins = []
    signalCuts = {}

    plot = getPlot("mllPlotROutIn")

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

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

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

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

    counts = {}

    eventCounts = totalNumberOfGeneratedEvents(path)

    defaultCut = plot.cuts

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

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

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

        #print plot.cuts

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

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

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

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

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

            sfErrRel = sferr / sf

            saveCut = plot.cuts

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

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

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

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

            plot.cuts = saveCut

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    outFilePkl = open("shelves/%s.pkl" % fileName, "w")
    pickle.dump(counts, outFilePkl)
    outFilePkl.close()
Пример #13
0
def makeResultPlot(path,selection,runRange,cmsExtra):
	
	plot = getPlot("mllPlot")
	plot.addRegion(selection)
	plot.cleanCuts()
	plot.cuts = plot.cuts % runRange.runCut			
	print plot.cuts
	plotDY = getPlot("mllPlot")
	
	if "Forward" in selection.name:
		plotDY.addRegion(getRegion("DrellYanControlForward"))
		region = "forward"
	elif "Central" in selection.name:
		plotDY.addRegion(getRegion("DrellYanControlCentral"))
		region = "central"
	else:		
		plotDY.addRegion(getRegion("DrellYanControl"))
		region = "inclusive"
	plotDY.cleanCuts()
	plotDY.cuts = plotDY.cuts % runRange.runCut		

	plotDYScale = getPlot("mllPlotROutIn")
	
	if "Forward" in selection.name:
		plotDYScale.addRegion(getRegion("DrellYanControlForward"))
	elif "Central" in selection.name:
		plotDYScale.addRegion(getRegion("DrellYanControlCentral"))
	else:		
		plotDYScale.addRegion(getRegion("DrellYanControl"))
	plotDYScale.cleanCuts()
	plotDYScale.cuts = plotDYScale.cuts % runRange.runCut		
	
	
	
	histEE, histMM, histEM = getHistograms(path,plot,runRange,False,[])
	histSF = histEE.Clone("histSF")
	histSF.Add(histMM.Clone())

	histEEDY, histMMDY, histEMDY = getHistograms(path,plotDY,runRange,False,[])
	histSFDY = histEEDY.Clone("histSFDY")
	histSFDY.Add(histMMDY.Clone())	

	histEEDYScale, histMMDYScale, histEMDYScale = getHistograms(path,plotDY,runRange,False,[])
	histSFDYScale = histEEDYScale.Clone("histSFDYScale")
	histSFDYScale.Add(histMMDYScale.Clone())	
	
	
	histOFSF = histEM.Clone("histOFSF")
	histOFEE = histEM.Clone("histOFEE")
	histOFMM = histEM.Clone("histOFMM")
	histOFSF.Scale(getattr(rSFOF,region).val)
	histOFEE.Scale(getattr(rEEOF,region).val)
	histOFMM.Scale(getattr(rMMOF,region).val)

	if region == "inclusive":
		histSFDY.Scale((zPredictions.SF.central.val + zPredictions.SF.forward.val) / histSFDYScale.Integral(histSFDYScale.FindBin(81),histSFDYScale.FindBin(101)))
		histEEDY.Scale((zPredictions.EE.central.val + zPredictions.EE.forward.val) / histEEDYScale.Integral(histEEDYScale.FindBin(81),histEEDYScale.FindBin(101)))
		histMMDY.Scale((zPredictions.MM.central.val + zPredictions.MM.forward.val) / histMMDYScale.Integral(histMMDYScale.FindBin(81),histMMDYScale.FindBin(101)))
	else:
		histSFDY.Scale(getattr(zPredictions.SF,region).val / histSFDYScale.Integral(histSFDYScale.FindBin(81),histSFDYScale.FindBin(101)))
		histEEDY.Scale(getattr(zPredictions.EE,region).val / histEEDYScale.Integral(histEEDYScale.FindBin(81),histEEDYScale.FindBin(101)))
		histMMDY.Scale(getattr(zPredictions.MM,region).val / histMMDYScale.Integral(histMMDYScale.FindBin(81),histMMDYScale.FindBin(101)))
	histSFDY.Scale(0)
	histEEDY.Scale(0)
	histMMDY.Scale(0)
	
	makePlot(histSF,histOFSF,selection,plot,runRange,region,cmsExtra,"SF",histSFDY)
	makePlot(histEE,histOFEE,selection,plot,runRange,region,cmsExtra,"EE",histEEDY)
	makePlot(histMM,histOFMM,selection,plot,runRange,region,cmsExtra,"MM",histMMDY)
Пример #14
0
def main():
	
	

	parser = argparse.ArgumentParser(description='rSFOF from control region.')
	
	parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False,
						  help="Verbose mode.")		
	parser.add_argument("-d", "--dependencies", action="store_true", dest="dependencies", default=False,
						  help="SF/OF dependency crosschecks.")								  			  	
	parser.add_argument("-m", "--mc", action="store_true", dest="mc", default=False,
						  help="add MC.")								  			  	
	parser.add_argument("-c", "--control", action="store_true", dest="control", default=False,
						  help="use control region.")								  			  	
	parser.add_argument("-r", "--runRange", dest="runRange", action="append", default=[],
						  help="name of run range.")
	parser.add_argument("-x", "--private", action="store_true", dest="private", default=False,
						  help="plot is private work.")	
	parser.add_argument("-b", "--backgrounds", dest="backgrounds", action="append", default=[],
						  help="backgrounds to plot.")
	parser.add_argument("-p", "--plot", dest="plots", action="append", default=[],
						  help="select dependencies to study, default is all.")
						  					
	args = parser.parse_args()


	if len(args.backgrounds) == 0:
		args.backgrounds = backgroundLists.rSFOF
	if len(args.plots) == 0:
		args.plots = plotLists.default


	selections = []
	
	if args.control:
		
		selections.append(regionsToUse.rSFOF.central.name)	
		selections.append(regionsToUse.rSFOF.forward.name)	
		selections.append(regionsToUse.rSFOF.inclusive.name)	
	else:	
		selections.append("SignalATLAS")	
		#~ selections.append(regionsToUse.signal.central.name)	
		#~ selections.append(regionsToUse.signal.forward.name)	
		#~ selections.append(regionsToUse.signal.inclusive.name)	
	
	if len(args.runRange) == 0:
		args.runRange.append(runRanges.name)	
			

	path = locations.dataSetPath	
	path = "/home/jan/Trees/sw538v0477/"	


	cmsExtra = ""
	if args.private:
		cmsExtra = "Private Work"
	else:
		cmsExtra = "Preliminary"

	for runRangeName in args.runRange:
		runRange = getRunRange(runRangeName)
	
		for selectionName in selections:
			
			selection = getRegion(selectionName)
			if args.dependencies:
				makeDependencyPlot(path,selection,args.plots,args.mc,args.backgrounds,runRange,cmsExtra)
			else:	
				makeResultPlot(path,selection,runRange,cmsExtra)
Пример #15
0
def main():
	
	

	parser = argparse.ArgumentParser(description='rSFOF from control region.')
	
	parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False,
						  help="Verbose mode.")
	parser.add_argument("-m", "--mc", action="store_true", dest="mc", default=False,
						  help="use MC, default is to use data.")
	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("-c", "--centralValues", action="store_true", dest="central", default=False,
						  help="calculate effinciecy central values")
	parser.add_argument("-C", "--ptCut",action="store", dest="ptCut", default="pt2515",
						  help="modify the pt cuts")
	parser.add_argument("-b", "--backgrounds", dest="backgrounds", action="append", default=[],
						  help="backgrounds to plot.")
	parser.add_argument("-d", "--dependencies", action="store_true", dest="dependencies", default= False,
						  help="make dependency plots")	
	parser.add_argument("-l", "--dilepton", action="store_true", dest="dilepton", default=False,
						  help="use dilepton triggers as baseline.")	
	parser.add_argument("-e", "--effectiveArea", action="store_true", dest="effectiveArea", default=False,
						  help="use effective area PU corrections.")	
	parser.add_argument("-D", "--deltaBeta", action="store_true", dest="deltaBeta", default=False,
						  help="use delta beta PU corrections.")	
	parser.add_argument("-R", "--constantConeSize", action="store_true", dest="constantConeSize", default=False,
						  help="use constant cone of R=0.3 for iso.")	
	parser.add_argument("-f", "--fit", action="store_true", dest="fit", default= False,
						  help="do dependecy fit")	
	parser.add_argument("-x", "--private", action="store_true", dest="private", default=False,
						  help="plot is private work.")	
	parser.add_argument("-i", "--illustrate", action="store_true", dest="illustrate", default=False,
						  help="plot dependency illustrations.")	
	parser.add_argument("-w", "--write", action="store_true", dest="write", default=False,
						  help="write results to central repository")	
	parser.add_argument("-n", "--nonNormalized", action="store_true", dest="nonNormalized", default=False,
						  help="do not normalize to cross section")	
					
	args = parser.parse_args()


	if len(args.backgrounds) == 0:
		args.backgrounds = ["TTJets_Madgraph","TTJets_aMCatNLO","TT_aMCatNLO","TT_Powheg"]
	if len(args.plots) == 0:
		args.plots = plotLists.default
	if len(args.selection) == 0:
		args.selection.append(regionsToUse.signal.central.name)	
		args.selection.append(regionsToUse.signal.forward.name)	
		args.selection.append(regionsToUse.signal.inclusive.name)	
	if len(args.runRange) == 0:
		args.runRange.append(runRanges.name)	
			

	path = locations.dataSetPathTrigger
	
	if args.dilepton:
		source = "DiLeptonTrigger"
		modifier = "DiLeptonTrigger"
	else:
		source = ""		
		modifier = ""	
		
	print args.selection
	cmsExtra = ""
	if args.private:
		cmsExtra = "Private Work"
		if args.mc:
			cmsExtra = "#splitline{Private Work}{Simulation}"
	elif args.mc:
		cmsExtra = "Simulation"	
	else:
		cmsExtra = "Preliminary"

	for runRangeName in args.runRange:
		runRange = getRunRange(runRangeName)
	
		for selectionName in args.selection:
			
			selection = getRegion(selectionName)
			
				
			doPlot(source,modifier,path,selection,args.plots,runRange,args.mc,args.backgrounds,cmsExtra)
Пример #16
0
def main():

    parser = argparse.ArgumentParser(
        description='create cut justification plots.')

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

    args = parser.parse_args()

    if len(args.selection) == 0:
        args.selection.append("SignalDeltaPhi")

    variables = [
        "nJetsPlotC", "htPlotC", "sumMlbPlot", "metPlot150", "ptllPlot",
        "deltaPhiPlot", "mt2Plot"
    ]  #
    axes = []
    for var in variables:
        axis = getPlot(var).xaxis
        axis = axis.split(" [")[0]
        axes.append(axis)

    sample = "TT_Powheg"

    for selectionName in args.selection:
        selection = getRegion(selectionName)
        template = plotTemplate2D()

        corrHist = ROOT.TH2F("", "", len(variables), 0,
                             len(variables) + 1, len(variables), 0,
                             len(variables) + 1)

        for i, var in enumerate(variables):
            corrHist.GetXaxis().SetBinLabel(i + 1, axes[i])
            corrHist.GetXaxis().ChangeLabel(i + 1, 90)
            corrHist.GetYaxis().SetBinLabel(i + 1, axes[i])

        for i, var1 in enumerate(variables):
            for j, var2 in enumerate(variables):
                if j <= i:
                    corr = getCorrelation(selection, sample, var1, var2)
                    corrHist.SetBinContent(i + 1, j + 1, corr)
                else:
                    corrHist.SetBinContent(i + 1, j + 1, -5)

        corrHist.GetZaxis().SetRangeUser(-1, 1)
        corrHist.GetZaxis().SetTitleOffset(1.1)

        template.setPrimaryPlot(corrHist, "COLZ TEXT")
        template.labelZ = "Correlation (#rho_{xy})"

        template.latexCMS.posX = 0.15 + 0.02

        template.latexCMS.posY = 0.95 - 0.02
        template.latexCMS.align = 13
        template.latexCMS.size = 0.06

        template.latexCMSExtra.posX = 0.15 + 0.02
        template.latexCMSExtra.posY = 0.86
        template.latexCMSExtra.simPosY = 0.84
        template.latexCMSExtra.size = 0.03

        template.lumiInt = 137
        template.latexLumi.posY = 0.9575
        template.latexLumi.size = 0.045

        template.latexRegion.text = selection.labelSubRegion
        template.latexRegion.size = 0.03
        template.latexRegion.posX = 0.15 + 0.02
        template.latexRegion.posY = 0.81
        template.latexRegion.align = 13

        template.labeledAxisX = True
        template.labeledAxisY = True

        ROOT.gStyle.SetPaintTextFormat("4.2f")

        ndiv = len(axes) - 1
        template.nDivX = -8
        template.nDivY = -8

        template.draw()
        template.setFolderName("correlation")
        template.saveAs("corrs_%s_%s" % (selection.name, sample))
Пример #17
0
def main():
    parser = argparse.ArgumentParser(description='edge fitter reloaded.')

    parser.add_argument("-r",
                        "--runRange",
                        dest="runRange",
                        action="store",
                        default=None,
                        help="name of run range.")
    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="selection which to apply.")

    backgroundZZ = "RareZZOnZ"
    backgroundVV = "RareZZLowMassOnZ"  # taking only the onZ part from this one

    args = parser.parse_args()

    runRange = getRunRange(args.runRange)
    if args.plots == []:
        args.plots = ["mllPlot", "mllWidePlotC"]

    if args.selection == []:
        args.selection = [
            "SignalLowNLL24HighMT2ZeroB", "SignalLowNLL24HighMT2OneB",
            "SignalHighNLL24HighMT2ZeroB", "SignalHighNLL24HighMT2OneB"
        ]

    path = locations[runRange.era].dataSetPathNLL
    #path = locations[runRange.era].dataSetPath
    eventCounts = totalNumberOfGeneratedEvents(path, "", "")

    procZZ = Process(getattr(Backgrounds[runRange.era], backgroundZZ),
                     eventCounts)
    procVV = Process(getattr(Backgrounds[runRange.era], backgroundVV),
                     eventCounts)

    for selectionName in args.selection:
        selection = getRegion(selectionName)
        for plotName in args.plots:
            plot = getPlot(plotName)
            plot.addRegion(selection)
            plot.addRunRange(runRange)

            plot.cuts = plot.cuts.replace("metFilterSummary > 0 &&", "")
            plot.cuts = plot.cuts.replace("&& metFilterSummary > 0", "")
            #plot.cuts = plot.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && mll > 40 && mll < 60")
            treesEE = readTrees(path, "EE")
            treesMM = readTrees(path, "MuMu")
            treesEM = readTrees(path, "EMu")

            template = plotTemplate()

            picklePath = "/home/home4/institut_1b/teroerde/Doktorand/SUSYFramework/frameWorkBase/shelves/scaleFactor_{runRange}_ZZTo4L.pkl"
            with open(picklePath.format(runRange=runRange.label), "r") as fi:
                scaleFac = pickle.load(fi)
            sf = scaleFac["scaleFac"]

            histZZ = procZZ.createCombinedHistogram(runRange.lumi,
                                                    plot,
                                                    treesEE,
                                                    treesMM,
                                                    shift=1.,
                                                    scalefacTree1=sf,
                                                    scalefacTree2=sf)

            #print histZZ.GetEntries()

            histVV = procVV.createCombinedHistogram(runRange.lumi,
                                                    plot,
                                                    treesEE,
                                                    treesMM,
                                                    shift=1.,
                                                    scalefacTree1=sf,
                                                    scalefacTree2=sf)

            # rMuE subtraction
            from corrections import corrections
            corrs = corrections[runRange.era].rMuELeptonPt.inclusive
            corrMap = {}
            corrMap["offset"] = corrs.ptOffset
            corrMap["falling"] = corrs.ptFalling
            corrMap["etaParabolaBase"] = corrs.etaParabolaBase
            corrMap["etaParabolaMinus"] = corrs.etaParabolaMinus
            corrMap["etaParabolaPlus"] = corrs.etaParabolaPlus
            corrMap["norm"] = corrs.norm
            rt = corrections[runRange.era].rSFOFTrig.inclusive.val

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

            histVV_OF = procVV.createCombinedHistogram(runRange.lumi,
                                                       plot,
                                                       treesEM,
                                                       "None",
                                                       shift=1.,
                                                       scalefacTree1=sf,
                                                       scalefacTree2=sf)
            histVV.Add(histVV_OF, -1)

            #normalize in Z-peak region (only properly works for mll plots and with correct binning)
            ZZCount = histZZ.Integral(histZZ.FindBin(86 + 0.1),
                                      histZZ.FindBin(96 - 0.1))
            VVCount = histVV.Integral(histVV.FindBin(86 + 0.1),
                                      histVV.FindBin(96 - 0.1))

            #histVV.Scale(ZZCount/VVCount)
            print ZZCount / VVCount

            if "Wide" in plotName:
                print selectionName, ZZCount / VVCount

            histZZ.SetLineColor(ROOT.kRed)
            histZZ.SetLineWidth(2)
            histZZ.SetMarkerSize(0)
            histZZ.SetFillStyle(0)
            histVV.SetLineColor(ROOT.kBlack)
            histVV.SetLineWidth(2)
            histVV.SetMarkerSize(0)
            histVV.SetFillStyle(0)

            template.setPrimaryPlot(histZZ, "histE", "ZZTo2L2Nu")
            template.addSecondaryPlot(histVV, "histE", "ZZTo2L2NuMass18")
            template.hasLegend = True
            template.cutsText = selection.labelSubRegion
            template.lumiInt = runRange.printval
            template.maximumScale = 1e3
            template.logY = True
            template.minimumY = 0.01

            template.setFolderName("compareMCSamples")
            template.draw()
            template.saveAs("comparison_%s_%s_%s" %
                            (plotName, selection.name, runRange.label))
            template.clean()
Пример #18
0
def centralValues(source, modifier, path, selection, runRange, isMC,
                  nonNormalized, backgrounds, cmsExtra):

    plot = getPlot("mllPlotROutIn")
    plot.addRegion(selection)
    plot.cleanCuts()

    plot.cuts = plot.cuts % runRange.runCut

    plotSignal = getPlot("mllPlot")

    if "Forward" in selection.name:
        plotSignal.addRegion(getRegion("SignalForward"))
        label = "forward"
    elif "Central" in selection.name:
        plotSignal.addRegion(getRegion("SignalCentral"))
        label = "central"
    else:
        plotSignal.addRegion(getRegion("SignalInclusive"))
        label = "inclusive"

    plotSignal.cleanCuts()
    plotSignal.cuts = plotSignal.cuts % runRange.runCut

    histEE, histMM, histEM = getHistograms(path, source, modifier, plot,
                                           runRange, isMC, nonNormalized,
                                           backgrounds, label)
    histSF = histEE.Clone("histSF")
    histSF.Add(histMM.Clone())

    histEESignal, histMMSignal, histEMSignal = getHistograms(
        path, source, modifier, plotSignal, runRange, isMC, nonNormalized,
        backgrounds, label)
    histSFSignal = histEESignal.Clone("histSFSignal")
    histSFSignal.Add(histMMSignal.Clone())
    result = {}

    lowMassLow = mllBinsOld.lowMass.low
    lowMassHigh = mllBinsOld.lowMass.high
    peakLow = mllBinsOld.onZ.low
    peakHigh = mllBinsOld.onZ.high
    highMassLow = mllBinsOld.highMass.low
    highMassHigh = mllBinsOld.highMass.high

    highMassRSFOFLow = mllBinsOld.highMassRSFOF.low
    highMassRSFOFHigh = mllBinsOld.highMassRSFOF.high

    eeLowMassErr = ROOT.Double()
    eeLowMass = histEE.IntegralAndError(histEE.FindBin(lowMassLow + 0.01),
                                        histEE.FindBin(lowMassHigh - 0.01),
                                        eeLowMassErr)
    eeHighMassErr = ROOT.Double()
    eeHighMass = histEE.IntegralAndError(
        histEE.FindBin(highMassRSFOFLow + 0.01),
        histEE.FindBin(highMassRSFOFHigh - 0.01), eeHighMassErr)

    ee = eeLowMass + eeHighMass
    eeErr = (eeLowMassErr**2 + eeHighMassErr**2)**0.5

    mmLowMassErr = ROOT.Double()
    mmLowMass = histMM.IntegralAndError(histMM.FindBin(lowMassLow + 0.01),
                                        histMM.FindBin(lowMassHigh - 0.01),
                                        mmLowMassErr)
    mmHighMassErr = ROOT.Double()
    mmHighMass = histMM.IntegralAndError(
        histMM.FindBin(highMassRSFOFLow + 0.01),
        histMM.FindBin(highMassRSFOFHigh - 0.01), mmHighMassErr)

    mm = mmLowMass + mmHighMass
    mmErr = (mmLowMassErr**2 + mmHighMassErr**2)**0.5

    ofLowMassErr = ROOT.Double()
    ofLowMass = histEM.IntegralAndError(histEM.FindBin(lowMassLow + 0.01),
                                        histEM.FindBin(lowMassHigh - 0.01),
                                        ofLowMassErr)
    ofHighMassErr = ROOT.Double()
    ofHighMass = histEM.IntegralAndError(
        histEM.FindBin(highMassRSFOFLow + 0.01),
        histEM.FindBin(highMassRSFOFHigh - 0.01), ofHighMassErr)

    of = ofLowMass + ofHighMass
    ofErr = (ofLowMassErr**2 + ofHighMassErr**2)**0.5

    sf = ee + mm
    sfLowMass = eeLowMass + mmLowMass
    sfHighMass = eeHighMass + mmHighMass
    sfErr = (eeErr**2 + mmErr**2)**0.5
    sfLowMassErr = (eeLowMassErr**2 + mmLowMassErr**2)**0.5
    sfHighMassErr = (eeHighMassErr**2 + mmHighMassErr**2)**0.5

    eeLowMassErrSignal = ROOT.Double()
    eeLowMassSignal = histEESignal.IntegralAndError(
        histEESignal.FindBin(lowMassLow + 0.01),
        histEESignal.FindBin(lowMassHigh - 0.01), eeLowMassErrSignal)
    eeHighMassErrSignal = ROOT.Double()
    eeHighMassSignal = histEESignal.IntegralAndError(
        histEESignal.FindBin(highMassRSFOFLow + 0.01),
        histEESignal.FindBin(highMassRSFOFHigh - 0.01), eeHighMassErrSignal)

    eeSignal = eeLowMassSignal + eeHighMassSignal
    eeErrSignal = (eeLowMassErrSignal**2 + eeHighMassErrSignal**2)**0.5

    mmLowMassErrSignal = ROOT.Double()
    mmLowMassSignal = histMMSignal.IntegralAndError(
        histMMSignal.FindBin(lowMassLow + 0.01),
        histMMSignal.FindBin(lowMassHigh - 0.01), mmLowMassErrSignal)
    mmHighMassErrSignal = ROOT.Double()
    mmHighMassSignal = histMMSignal.IntegralAndError(
        histMMSignal.FindBin(highMassRSFOFLow + 0.01),
        histMMSignal.FindBin(highMassRSFOFHigh - 0.01), mmHighMassErrSignal)

    mmSignal = mmLowMassSignal + mmHighMassSignal
    mmErrSignal = (mmLowMassErrSignal**2 + mmHighMassErrSignal**2)**0.5

    ofLowMassErrSignal = ROOT.Double()
    ofLowMassSignal = histEMSignal.IntegralAndError(
        histEMSignal.FindBin(lowMassLow + 0.01),
        histEMSignal.FindBin(lowMassHigh - 0.01), ofLowMassErrSignal)
    ofHighMassErrSignal = ROOT.Double()
    ofHighMassSignal = histEMSignal.IntegralAndError(
        histEMSignal.FindBin(highMassRSFOFLow + 0.01),
        histEMSignal.FindBin(highMassRSFOFHigh - 0.01), ofHighMassErrSignal)

    ofSignal = ofLowMassSignal + ofHighMassSignal
    ofErrSignal = (ofLowMassErrSignal**2 + ofHighMassErrSignal**2)**0.5

    sfSignal = eeSignal + mmSignal
    sfLowMassSignal = eeLowMassSignal + mmLowMassSignal
    sfHighMassSignal = eeHighMassSignal + mmHighMassSignal
    sfErrSignal = (eeErrSignal**2 + mmErrSignal**2)**0.5
    sfLowMassErrSignal = (eeLowMassErrSignal**2 + mmLowMassErrSignal**2)**0.5
    sfHighMassErrSignal = (eeHighMassErrSignal**2 +
                           mmHighMassErrSignal**2)**0.5

    rsfof = float(sf) / float(of)
    rsfofErr = rsfof * (sfErr**2 / sf**2 + ofErr**2 / of**2)**0.5
    rsfofLowMass = float(sfLowMass) / float(ofLowMass)
    rsfofLowMassErr = rsfof * (sfLowMassErr**2 / sfLowMass**2 +
                               ofLowMassErr**2 / ofLowMass**2)**0.5
    rsfofHighMass = float(sfHighMass) / float(ofHighMass)
    rsfofHighMassErr = rsfof * (sfHighMassErr**2 / sf**2 +
                                ofHighMassErr**2 / of**2)**0.5

    rsfofSignal = float(sfSignal) / float(ofSignal)
    rsfofErrSignal = rsfofSignal * (sfErrSignal**2 / sfSignal**2 +
                                    ofErrSignal**2 / ofSignal**2)**0.5
    rsfofLowMassSignal = float(sfLowMassSignal) / float(ofLowMassSignal)
    if sfLowMassSignal > 0 and ofLowMassSignal > 0:
        rsfofLowMassErrSignal = rsfofLowMassSignal * (
            sfLowMassErrSignal**2 / sfLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        rsfofLowMassErrSignal = 0
    rsfofHighMassSignal = float(sfHighMassSignal) / float(ofHighMassSignal)
    rsfofHighMassErrSignal = rsfofHighMassSignal * (
        sfHighMassErrSignal**2 / sfHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5

    rEEOF = float(ee) / float(of)
    if ee > 0 and of > 0:
        rEEOFErr = rEEOF * (eeErr**2 / ee**2 + ofErr**2 / of**2)**0.5
    else:
        rEEOFErr = 0
    rEEOFLowMass = float(eeLowMass) / float(ofLowMass)
    if eeLowMass > 0 and ofLowMass > 0:
        rEEOFLowMassErr = rEEOFLowMass * (eeLowMassErr**2 / eeLowMass**2 +
                                          ofLowMassErr**2 / ofLowMass**2)**0.5
    else:
        rEEOFLowMassErr = 0
    rEEOFHighMass = float(eeHighMass) / float(ofHighMass)
    if eeHighMass > 0 and ofHighMass > 0:
        rEEOFHighMassErr = rEEOFHighMass * (
            eeHighMassErr**2 / eeHighMass**2 +
            ofHighMassErr**2 / ofHighMass**2)**0.5
    else:
        rEEOFHighMassErr = 0

    rEEOFSignal = float(eeSignal) / float(ofSignal)
    rEEOFErrSignal = rEEOFSignal * (eeErrSignal**2 / eeSignal**2 +
                                    ofErrSignal**2 / ofSignal**2)**0.5
    rEEOFLowMassSignal = float(eeLowMassSignal) / float(ofLowMassSignal)
    if eeLowMassSignal > 0 and ofLowMassSignal > 0:
        rEEOFLowMassErrSignal = rEEOFLowMassSignal * (
            eeLowMassErrSignal**2 / eeLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        rEEOFLowMassErrSignal = 0
    rEEOFHighMassSignal = float(eeHighMassSignal) / float(ofHighMassSignal)
    rEEOFHighMassErrSignal = rEEOFHighMassSignal * (
        eeHighMassErrSignal**2 / eeHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5

    rMMOF = float(mm) / float(of)
    rMMOFErr = rMMOF * (mmErr**2 / mm**2 + ofErr**2 / of**2)**0.5
    rMMOFLowMass = float(mmLowMass) / float(ofLowMass)
    rMMOFLowMassErr = rMMOFLowMass * (mmLowMassErr**2 / mmLowMass**2 +
                                      ofLowMassErr**2 / ofLowMass**2)**0.5
    rMMOFHighMass = float(mmHighMass) / float(ofHighMass)
    rMMOFHighMassErr = rMMOFHighMass * (mmHighMassErr**2 / mmHighMass**2 +
                                        ofHighMassErr**2 / ofHighMass**2)**0.5

    rMMOFSignal = float(mmSignal) / float(ofSignal)
    rMMOFErrSignal = rMMOFSignal * (mmErrSignal**2 / mmSignal**2 +
                                    ofErrSignal**2 / ofSignal**2)**0.5
    rMMOFLowMassSignal = float(mmLowMassSignal) / float(ofLowMassSignal)
    if mmLowMassSignal > 0 and ofLowMassSignal > 0:
        rMMOFLowMassErrSignal = rMMOFLowMassSignal * (
            mmLowMassErrSignal**2 / mmLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        rMMOFLowMassErrSignal = 0
    rMMOFHighMassSignal = float(mmHighMassSignal) / float(ofHighMassSignal)
    rMMOFHighMassErrSignal = rMMOFHighMassSignal * (
        mmHighMassErrSignal**2 / mmHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5

    transferFaktor = rsfofSignal / rsfof
    transferFaktorErr = transferFaktor * (
        (rsfofErr / rsfof)**2 + (rsfofErrSignal / rsfofSignal)**2)**0.5
    if rEEOF > 0:
        transferFaktorEE = rEEOFSignal / rEEOF
    else:
        transferFaktorEE = 0
    if rEEOF > 0 and rEEOFSignal > 0:
        transferFaktorEEErr = transferFaktorEE * (
            (rEEOFErr / rEEOF)**2 + (rEEOFErrSignal / rEEOFSignal)**2)**0.5
    else:
        transferFaktorEEErr = 0
    transferFaktorMM = rMMOFSignal / rMMOF
    transferFaktorMMErr = transferFaktorMM * (
        (rMMOFErr / rMMOF)**2 + (rMMOFErrSignal / rMMOFSignal)**2)**0.5

    transferFaktorLowMass = rsfofLowMassSignal / rsfofLowMass
    if rsfofLowMass > 0 and rsfofLowMassSignal > 0:
        transferFaktorLowMassErr = transferFaktorLowMass * (
            (rsfofLowMassErr / rsfofLowMass)**2 +
            (rsfofLowMassErrSignal / rsfofLowMassSignal)**2)**0.5
    else:
        transferFaktorLowMassErr = 0
    if rEEOFLowMass > 0:
        transferFaktorEELowMass = rEEOFLowMassSignal / rEEOFLowMass
    else:
        transferFaktorEELowMass = 0
    if rEEOFLowMass > 0 and rEEOFLowMassSignal > 0:
        transferFaktorEELowMassErr = transferFaktorEELowMass * (
            (rEEOFLowMassErr / rEEOFLowMass)**2 +
            (rEEOFLowMassErrSignal / rEEOFLowMassSignal)**2)**0.5
    else:
        transferFaktorEELowMassErr = 0
    transferFaktorMMLowMass = rMMOFLowMassSignal / rMMOFLowMass
    if rMMOFLowMass > 0 and rMMOFLowMassSignal > 0:
        transferFaktorMMLowMassErr = transferFaktorMMLowMass * (
            (rMMOFLowMassErr / rMMOFLowMass)**2 +
            (rMMOFLowMassErrSignal / rMMOFLowMassSignal)**2)**0.5
    else:
        transferFaktorMMLowMassErr = 0

    transferFaktorHighMass = rsfofHighMassSignal / rsfofHighMass
    transferFaktorHighMassErr = transferFaktorHighMass * (
        (rsfofHighMassErr / rsfofHighMass)**2 +
        (rsfofHighMassErrSignal / rsfofHighMassSignal)**2)**0.5
    if rEEOFHighMass > 0:
        transferFaktorEEHighMass = rEEOFHighMassSignal / rEEOFHighMass
    else:
        transferFaktorEEHighMass = 0
    if rEEOFHighMass > 0 and rEEOFHighMassSignal > 0:
        transferFaktorEEHighMassErr = transferFaktorEEHighMass * (
            (rEEOFHighMassErr / rEEOFHighMass)**2 +
            (rEEOFHighMassErrSignal / rEEOFHighMassSignal)**2)**0.5
    else:
        transferFaktorEEHighMassErr = 0
    transferFaktorMMHighMass = rMMOFHighMassSignal / rMMOFHighMass
    transferFaktorMMHighMassErr = transferFaktorMMHighMass * (
        (rMMOFHighMassErr / rMMOFHighMass)**2 +
        (rMMOFHighMassErrSignal / rMMOFHighMassSignal)**2)**0.5

    result = {}
    result["EE"] = ee
    result["MM"] = mm
    result["SF"] = sf
    result["OF"] = of
    result["EELowMass"] = eeLowMass
    result["MMLowMass"] = mmLowMass
    result["SFLowMass"] = eeLowMass + mmLowMass
    result["OFLowMass"] = ofLowMass
    result["EEHighMass"] = eeHighMass
    result["MMHighMass"] = mmHighMass
    result["SFHighMass"] = eeHighMass + mmHighMass
    result["OFHighMass"] = ofHighMass

    result["EESignal"] = eeSignal
    result["MMSignal"] = mmSignal
    result["SFSignal"] = sfSignal
    result["OFSignal"] = ofSignal
    result["EELowMassSignal"] = eeLowMassSignal
    result["MMLowMassSignal"] = mmLowMassSignal
    result["SFLowMassSignal"] = eeLowMassSignal + mmLowMassSignal
    result["OFLowMassSignal"] = ofLowMassSignal
    result["EEHighMassSignal"] = eeHighMassSignal
    result["MMHighMassSignal"] = mmHighMassSignal
    result["SFHighMassSignal"] = eeHighMassSignal + mmHighMassSignal
    result["OFHighMassSignal"] = ofHighMassSignal

    result["rSFOFLowMass"] = sfLowMass / ofLowMass
    result["rSFOFErrLowMass"] = result["rSFOFLowMass"] * (
        sfLowMassErr**2 / sfLowMass**2 + ofLowMassErr**2 / ofLowMass**2)**0.5
    result["rEEOFLowMass"] = eeLowMass / ofLowMass
    result["rEEOFErrLowMass"] = result["rEEOFLowMass"] * (
        (eeLowMassErr**2)**0.5**2 / sfLowMass**2 +
        ofLowMassErr**2 / ofLowMass**2)**0.5
    result["rMMOFLowMass"] = mmLowMass / ofLowMass
    result["rMMOFErrLowMass"] = result["rMMOFLowMass"] * (
        (mmLowMassErr**2)**0.5**2 / sfLowMass**2 +
        ofLowMassErr**2 / ofLowMass**2)**0.5
    result["rSFOFHighMass"] = sfHighMass / ofHighMass
    result["rSFOFErrHighMass"] = result["rSFOFHighMass"] * (
        sfHighMassErr**2 / sfHighMass**2 +
        ofHighMassErr**2 / ofHighMass**2)**0.5
    result["rEEOFHighMass"] = eeHighMass / ofHighMass
    result["rEEOFErrHighMass"] = result["rEEOFHighMass"] * (
        (eeHighMassErr**2)**0.5**2 / sfHighMass**2 +
        ofHighMassErr**2 / ofHighMass**2)**0.5
    result["rMMOFHighMass"] = mmHighMass / ofHighMass
    result["rMMOFErrHighMass"] = result["rMMOFHighMass"] * (
        (mmHighMassErr**2)**0.5**2 / sfHighMass**2 +
        ofHighMassErr**2 / ofHighMass**2)**0.5

    result["rSFOFLowMassSignal"] = sfLowMassSignal / ofLowMassSignal
    if sfLowMassSignal > 0 and ofLowMassSignal > 0:
        result["rSFOFErrLowMassSignal"] = result["rSFOFLowMassSignal"] * (
            sfLowMassErrSignal**2 / sfLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        result["rSFOFErrLowMassSignal"] = 0
    result["rEEOFLowMassSignal"] = eeLowMassSignal / ofLowMassSignal
    if eeLowMassSignal > 0 and ofLowMassSignal > 0:
        result["rEEOFErrLowMassSignal"] = result["rEEOFLowMassSignal"] * (
            eeLowMassErrSignal**2 / eeLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        result["rEEOFErrLowMassSignal"] = 0
    result["rMMOFLowMassSignal"] = mmLowMassSignal / ofLowMassSignal
    if mmLowMassSignal > 0 and ofLowMassSignal > 0:
        result["rMMOFErrLowMassSignal"] = result["rMMOFLowMassSignal"] * (
            mmLowMassErrSignal**2 / mmLowMassSignal**2 +
            ofLowMassErrSignal**2 / ofLowMassSignal**2)**0.5
    else:
        result["rMMOFErrLowMassSignal"] = 0
    result["rSFOFHighMassSignal"] = sfHighMassSignal / ofHighMassSignal
    result["rSFOFErrHighMassSignal"] = result["rSFOFHighMassSignal"] * (
        sfHighMassErrSignal**2 / sfHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5
    result["rEEOFHighMassSignal"] = eeHighMassSignal / ofHighMassSignal
    result["rEEOFErrHighMassSignal"] = result["rEEOFHighMassSignal"] * (
        eeHighMassErrSignal**2 / eeHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5
    result["rMMOFHighMassSignal"] = mmHighMassSignal / ofHighMassSignal
    result["rMMOFErrHighMassSignal"] = result["rMMOFHighMassSignal"] * (
        mmHighMassErrSignal**2 / mmHighMassSignal**2 +
        ofHighMassErrSignal**2 / ofHighMassSignal**2)**0.5

    result["rSFOF"] = rsfof
    result["rSFOFErr"] = rsfofErr
    result["rEEOF"] = rEEOF
    result["rEEOFErr"] = rEEOFErr
    result["rMMOF"] = rMMOF
    result["rMMOFErr"] = rMMOFErr
    result["rSFOFSignal"] = rsfofSignal
    result["rSFOFErrSignal"] = rsfofErrSignal
    result["rEEOFSignal"] = rEEOFSignal
    result["rEEOFErrSignal"] = rEEOFErrSignal
    result["rMMOFSignal"] = rMMOFSignal
    result["rMMOFErrSignal"] = rMMOFErrSignal
    result["transfer"] = transferFaktor
    result["transferErr"] = transferFaktorErr
    result["transferEE"] = transferFaktorEE
    result["transferEEErr"] = transferFaktorEEErr
    result["transferMM"] = transferFaktorMM
    result["transferMMErr"] = transferFaktorMMErr

    result["transferLowMass"] = transferFaktorLowMass
    result["transferLowMassErr"] = transferFaktorLowMassErr
    result["transferEELowMass"] = transferFaktorEELowMass
    result["transferEELowMassErr"] = transferFaktorEELowMassErr
    result["transferMMLowMass"] = transferFaktorMMLowMass
    result["transferMMLowMassErr"] = transferFaktorMMLowMassErr
    result["transferHighMass"] = transferFaktorHighMass
    result["transferHighMassErr"] = transferFaktorHighMassErr
    result["transferEEHighMass"] = transferFaktorEEHighMass
    result["transferEEHighMassErr"] = transferFaktorEEHighMassErr
    result["transferMMHighMass"] = transferFaktorMMHighMass
    result["transferMMHighMassErr"] = transferFaktorMMHighMassErr

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

    parser = argparse.ArgumentParser(description='rMuE measurements.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="use MC, default is to use data.")
    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 = backgroundLists.default
    if len(args.plots) == 0:
        args.plots = plotLists.default
    if len(args.selection) == 0:

        args.selection.append("Inclusive")

    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.dataSetPath

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
        if args.mc:
            cmsExtra = "#splitline{Private Work}{Simulation}"
    elif args.mc:
        cmsExtra = "Simulation"
    else:
        cmsExtra = "Preliminary"
    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in args.selection:

            selection = getRegion(selectionName)

            plot(path, selection, args.plots, runRange, args.mc,
                 args.backgrounds, cmsExtra)
Пример #20
0
def main():

    parser = argparse.ArgumentParser(description='rSFOF from control region.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="use MC, default is to use data.")
    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("-c",
                        "--centralValues",
                        action="store_true",
                        dest="central",
                        default=False,
                        help="calculate effinciecy central values")
    parser.add_argument("-C",
                        "--ptCut",
                        action="store",
                        dest="ptCut",
                        default="pt2515",
                        help="modify the pt cuts")
    parser.add_argument("-b",
                        "--backgrounds",
                        dest="backgrounds",
                        action="append",
                        default=[],
                        help="backgrounds to plot.")
    parser.add_argument("-d",
                        "--dependencies",
                        action="store_true",
                        dest="dependencies",
                        default=False,
                        help="make dependency plots")
    parser.add_argument("-l",
                        "--dilepton",
                        action="store_true",
                        dest="dilepton",
                        default=False,
                        help="use dilepton triggers as baseline.")
    parser.add_argument("-e",
                        "--effectiveArea",
                        action="store_true",
                        dest="effectiveArea",
                        default=False,
                        help="use effective area PU corrections.")
    parser.add_argument("-D",
                        "--deltaBeta",
                        action="store_true",
                        dest="deltaBeta",
                        default=False,
                        help="use delta beta PU corrections.")
    parser.add_argument("-R",
                        "--constantConeSize",
                        action="store_true",
                        dest="constantConeSize",
                        default=False,
                        help="use constant cone of R=0.3 for iso.")
    parser.add_argument("-f",
                        "--fit",
                        action="store_true",
                        dest="fit",
                        default=False,
                        help="do dependecy fit")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")
    parser.add_argument("-i",
                        "--illustrate",
                        action="store_true",
                        dest="illustrate",
                        default=False,
                        help="plot dependency illustrations.")
    parser.add_argument("-w",
                        "--write",
                        action="store_true",
                        dest="write",
                        default=False,
                        help="write results to central repository")
    parser.add_argument("-n",
                        "--nonNormalized",
                        action="store_true",
                        dest="nonNormalized",
                        default=False,
                        help="do not normalize to cross section")

    args = parser.parse_args()

    if len(args.backgrounds) == 0:
        args.backgrounds = backgroundLists.rSFOF
    if len(args.plots) == 0:
        args.plots = plotLists.rSFOF
    if len(args.selection) == 0:
        #~ args.selection.append(regionsToUse.rSFOF.central.name)
        #~ args.selection.append(regionsToUse.rSFOF.forward.name)
        args.selection.append(regionsToUse.rSFOF.inclusive.name)
    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    if args.mc:
        path = locations.dataSetPathMC
    else:
        path = locations.dataSetPath

    if args.dilepton:
        source = "DiLeptonTrigger"
        modifier = "DiLeptonTrigger"
    else:
        source = ""
        modifier = ""

    #~ if args.constantConeSize:
    #~ if args.effectiveArea:
    #~ source = "EffAreaIso%s"%source
    #~ elif args.deltaBeta:
    #~ source = "DeltaBetaIso%s"%source
    #~ else:
    #~ print "Constant cone size (option -R) can only be used in combination with effective area (-e) or delta beta (-D) pileup corrections."
    #~ print "Using default miniIso cone with PF weights instead"
    #~ else:
    #~ if args.effectiveArea:
    #~ source = "MiniIsoEffAreaIso%s"%source
    #~ elif args.deltaBeta:
    #~ source = "MiniIsoDeltaBetaIso%s"%source
    #~ else:
    #~ source = "MiniIsoPFWeights%s"%source

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
        if args.mc:
            cmsExtra = "#splitline{Private Work}{Simulation}"
    elif args.mc:
        cmsExtra = "Simulation"
    else:
        cmsExtra = "Preliminary"

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in args.selection:

            selection = getRegion(selectionName)

            if args.central:

                centralVal = centralValues(source, modifier, path, selection,
                                           runRange, args.mc,
                                           args.nonNormalized,
                                           args.backgrounds, cmsExtra)
                if args.mc:
                    outFilePkl = open(
                        "shelves/rSFOF_%s_%s_MC.pkl" %
                        (selection.name, runRange.label), "w")
                    #~ outFilePkl = open("shelves/rSFOF_%s_%s_MC_old.pkl"%(selection.name,runRange.label),"w")
                else:
                    outFilePkl = open(
                        "shelves/rSFOF_%s_%s.pkl" %
                        (selection.name, runRange.label), "w")
                    #~ outFilePkl = open("shelves/rSFOF_%s_%s_old.pkl"%(selection.name,runRange.label),"w")
                pickle.dump(centralVal, outFilePkl)
                outFilePkl.close()

            if args.dependencies:
                dependencies(source, modifier, path, selection, args.plots,
                             runRange, args.mc, args.nonNormalized,
                             args.backgrounds, cmsExtra, args.fit, args.ptCut)

            if args.illustrate:
                illustration(selectionName)

            if args.write:
                import subprocess
                if args.mc:
                    bashCommand = "cp shelves/rSFOF_%s_%s_MC.pkl %s/shelves" % (
                        selection.name, runRange.label, pathes.basePath)
                else:
                    bashCommand = "cp shelves/rSFOF_%s_%s.pkl %s/shelves" % (
                        selection.name, runRange.label, pathes.basePath)
                process = subprocess.Popen(bashCommand.split())
def main():
    parser = argparse.ArgumentParser(
        description='produce cut & count event yields.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-B",
                        "--blind",
                        action="store_true",
                        dest="blind",
                        default=False,
                        help="Blind SR in data")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="use MC, default is to use data.")
    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("-w",
                        "--write",
                        action="store_true",
                        dest="write",
                        default=False,
                        help="write results to central repository")

    args = parser.parse_args()

    if len(args.backgrounds) == 0:
        args.backgrounds = backgroundLists.default
    if len(args.plots) == 0:
        args.plots = plotLists.signal
    if len(args.selection) == 0:
        args.selection.append(regionsToUse.signal.inclusive.name)
    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)
        path = locations[runRange.era].dataSetPathNLL
        for selectionName in args.selection:

            selection = getRegion(selectionName)

            if args.write:

                import subprocess

                bashCommand = "cp shelves/cutAndCountNLL_%s_%s.pkl %s/shelves" % (
                    selection.name, runRange.label, pathes.basePath)
                process = subprocess.Popen(bashCommand.split())

            else:
                counts = cutAndCountForRegion(path, selection, args.plots,
                                              runRange, args.mc,
                                              args.backgrounds, args.blind)
                outFile = open(
                    "shelves/cutAndCountNLL_%s_%s.pkl" %
                    (selection.name, runRange.label), "w")
                pickle.dump(counts, outFile)
                outFile.close()
Пример #22
0
def main():

    parser = argparse.ArgumentParser(description='rMuE measurements.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-r",
                        "--runRange",
                        dest="runRange",
                        action="append",
                        default=[],
                        help="name of run range.")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")

    args = parser.parse_args()

    plots = plotLists.fake

    selections = ["Region"]

    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.fakeDataSetPath

    #~ path = "/home/jan/Trees/sw538v0477"

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
    else:
        cmsExtra = "Preliminary"

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in selections:

            selection = getRegion(selectionName)

            #~ fakeRate(path,selection,plots,runRange,cmsExtra)
            #~ fakeRateCentral(path,selection,plots,runRange,cmsExtra)
    path = locations.dataSetPath

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in selections:

            selection = getRegion(selectionName)

            #~ promptRate(path,selection,plots,runRange,cmsExtra)
            #~ promptRateCentral(path,selection,plots,runRange,cmsExtra)
    selections = ["SignalCentral", "SignalForward"]

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in selections:

            selection = getRegion(selectionName)

            nonPromptPrediction(path, selection, plots, runRange, cmsExtra)
Пример #23
0
def signalRegion(path, selection, plots, runRange, isMC, backgrounds,
                 cmsExtra):
    plots = ["mllPlotRMuESignal"]
    for name in plots:
        plot = getPlot(name)
        plot.addRegion(selection)
        #~ plot.cleanCuts()
        plot.cuts = plot.cuts % runRange.runCut

        if not "Forward" in selection.name:
            corr = rSFOF.central.val
            corrErr = rSFOF.central.err
            if "Central" in selection.name:
                region = "central"
            else:
                region = "inclusive"
        else:
            corr = rSFOF.forward.val
            corrErr = rSFOF.forward.err
            region = "forward"

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

        rMuEMeasured = rMuEMeasure(histEE, histMM)
        rMuE, rMuEUncert = rMuEFromSFOF(histEE, histMM, histEM, corr, corrErr)

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

        style = setTDRStyle()
        plotPad.UseCurrentStyle()
        plotPad.Draw()
        plotPad.cd()

        plotPad.DrawFrame(plot.firstBin, 0, plot.lastBin, 5,
                          "; %s ; %s" % (plot.xaxis, "r_{#mu e}"))
        latex = ROOT.TLatex()
        latex.SetTextSize(0.04)
        latex.SetNDC(True)

        if "Central" in selection.name:
            centralName = "ZPeakControlCentral"
        elif "Forward" in selection.name:
            centralName = "ZPeakControlForward"
        else:
            centralName = "ZPeakControl"

        if os.path.isfile("shelves/rMuE_%s_%s.pkl" %
                          (centralName, runRange.label)):
            centralVals = pickle.load(
                open("shelves/rMuE_%s_%s.pkl" % (centralName, runRange.label),
                     "rb"))
        else:
            centralVals = centralValues(path, getRegion(centralName), runRange,
                                        False, backgrounds)

        x = array("f", [plot.firstBin, plot.lastBin])
        y = array("f", [centralVals["rMuE"], centralVals["rMuE"]])
        ex = array("f", [0., 0.])
        ey = array("f",
                   [centralVals["rMuESystErr"], centralVals["rMuESystErr"]])
        ge = ROOT.TGraphErrors(2, x, y, ex, ey)
        ge.SetFillColor(ROOT.kOrange - 9)
        ge.SetFillStyle(1001)
        ge.SetLineColor(ROOT.kWhite)
        ge.Draw("SAME 3")

        rmueLine = ROOT.TF1("rmueline", "%f" % centralVals["rMuE"],
                            plot.firstBin, plot.lastBin)
        rmueLine.SetLineColor(ROOT.kOrange + 3)
        rmueLine.SetLineWidth(3)
        rmueLine.SetLineStyle(2)
        rmueLine.Draw("SAME")

        arrayRMuEHigh = array("f", rMuE["up"])
        arrayRMuELow = array("f", rMuE["down"])
        arrayRMuEMeasured = array("f", rMuEMeasured["vals"])
        arrayRMuEHighUncert = array("f", rMuEUncert["up"])
        arrayRMuELowUncert = array("f", rMuEUncert["down"])
        arrayRMuEMeasuredUncert = array("f", rMuEMeasured["errs"])
        xValues = []
        xValuesUncert = []

        for x in range(0, histEE.GetNbinsX()):
            xValues.append(plot.firstBin +
                           (plot.lastBin - plot.firstBin) / plot.nBins + x *
                           ((plot.lastBin - plot.firstBin) / plot.nBins))
            xValuesUncert.append(0)

        arrayXValues = array("f", xValues)
        arrayXValuesUncert = array("f", xValuesUncert)

        graphHigh = ROOT.TGraphErrors(histEE.GetNbinsX(), arrayXValues,
                                      arrayRMuEHigh, arrayXValuesUncert,
                                      arrayRMuEHighUncert)
        graphLow = ROOT.TGraphErrors(histEE.GetNbinsX(), arrayXValues,
                                     arrayRMuELow, arrayXValuesUncert,
                                     arrayRMuEHighUncert)
        graphMeasured = ROOT.TGraphErrors(histEE.GetNbinsX(), arrayXValues,
                                          arrayRMuEMeasured,
                                          arrayXValuesUncert,
                                          arrayRMuEMeasuredUncert)

        graphHigh.SetMarkerStyle(21)
        graphLow.SetMarkerStyle(22)
        graphMeasured.SetMarkerStyle(23)
        graphHigh.SetMarkerColor(ROOT.kRed)
        graphLow.SetMarkerColor(ROOT.kBlue)
        graphHigh.SetLineColor(ROOT.kRed)
        graphLow.SetLineColor(ROOT.kBlue)

        graphHigh.Draw("sameEP0")
        graphLow.Draw("sameEP0")
        graphMeasured.Draw("sameEP0")

        legend = TLegend(0.5, 0.6, 0.95, 0.95)
        legend.SetFillStyle(0)
        legend.SetBorderSize(0)
        entryHist = TH1F()
        entryHist.SetFillColor(ROOT.kWhite)
        legend.AddEntry(entryHist, selection.latex, "h")
        legend.AddEntry(
            graphHigh,
            "r_{#mu e} = N_{SF}/N_{OF} + #sqrt{(N_{SF}/N_{OF})^{2} -1}", "p")
        legend.AddEntry(
            graphLow,
            "r_{#mu e} = N_{SF}/N_{OF} - #sqrt{(N_{SF}/N_{OF})^{2} -1}", "p")
        legend.AddEntry(rmueLine, "r_{#mu e} from Z peak", "l")
        legend.AddEntry(ge, "Syst. Uncert. of r_{#mu e}", "f")
        legend.AddEntry(
            graphMeasured,
            "r_{#mu e} = #sqrt{N_{#mu#mu}/N_{ee}} in SF signal region", "p")

        legend.Draw("same")

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

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

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

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

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

        plotPad.RedrawAxis()
        if isMC:
            hCanvas.Print("fig/rMuESignal_%s_%s_%s_%s_MC.pdf" %
                          (selection.name, runRange.label,
                           plot.variablePlotName, plot.additionalName))
        else:
            hCanvas.Print("fig/rMuESignal_%s_%s_%s_%s.pdf" %
                          (selection.name, runRange.label,
                           plot.variablePlotName, plot.additionalName))
Пример #24
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")
Пример #25
0
def main():
    parser = argparse.ArgumentParser(description='rSFOF from control region.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-l",
                        "--lowMass",
                        action="store_true",
                        dest="lowMass",
                        default=False,
                        help="plot low mass dependency")
    parser.add_argument("-o",
                        "--highMass",
                        action="store_true",
                        dest="highMass",
                        default=False,
                        help="plot high mass dependency")
    parser.add_argument("-c",
                        "--control",
                        action="store_true",
                        dest="control",
                        default=False,
                        help="use control region")
    parser.add_argument("-b",
                        "--bins",
                        action="store_true",
                        dest="bins",
                        default=False,
                        help="plot in bins instead of cumulative")
    parser.add_argument("-r",
                        "--runRange",
                        dest="runRange",
                        action="append",
                        default=[],
                        help="name of run range.")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")

    args = parser.parse_args()

    plotName = ""
    if args.lowMass:
        plotName = "mllPlotLowMass"
    elif args.highMass:
        plotName = "mllPlotHighMass"
    selections = []
    if args.control:
        selections.append(regionsToUse.rSFOF.central.name)
        selections.append(regionsToUse.rSFOF.forward.name)
        selections.append(regionsToUse.rSFOF.inclusive.name)
    else:
        selections.append(regionsToUse.signal.central.name)
        selections.append(regionsToUse.signal.forward.name)
        selections.append(regionsToUse.signal.inclusive.name)
    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.dataSetPath

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
    else:
        cmsExtra = "Preliminary"
    print cmsExtra
    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in selections:

            selection = getRegion(selectionName)

            lumiDependency(path, plotName, selection, runRange, cmsExtra,
                           args.bins)
Пример #26
0
	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
	histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram		
def main():

    parser = argparse.ArgumentParser(
        description='Trigger efficiency measurements.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="use MC, default is to use data.")
    parser.add_argument(
        "-n",
        "--new",
        action="store_true",
        dest="new",
        default=False,
        help="new approach, using single lepton for dependencies.")
    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("-c",
                        "--centralValues",
                        action="store_true",
                        dest="central",
                        default=False,
                        help="calculate effinciecy central values")
    parser.add_argument("-b",
                        "--backgrounds",
                        dest="backgrounds",
                        action="append",
                        default=[],
                        help="backgrounds to plot.")
    parser.add_argument("-d",
                        "--dependencies",
                        action="store_true",
                        dest="dependencies",
                        default=False,
                        help="make dependency plots")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")
    parser.add_argument("-w",
                        "--write",
                        action="store_true",
                        dest="write",
                        default=False,
                        help="write results to central repository")

    args = parser.parse_args()

    if len(args.backgrounds) == 0:
        args.backgrounds = backgroundLists.trigger
    if len(args.plots) == 0:
        args.plots = plotLists.trigger
    if len(args.selection) == 0:
        args.selection.append(regionsToUse.triggerEfficiencies.central.name)
        args.selection.append(regionsToUse.triggerEfficiencies.forward.name)
        args.selection.append(regionsToUse.triggerEfficiencies.inclusive.name)
    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.triggerDataSetPath
    if args.mc:
        path = locations.dataSetPath

    source = baselineTrigger.name

    log.logHighlighted(
        "Calculating trigger efficiencies on %s triggered dataset" % source)
    log.logHighlighted("Using trees from %s " % path)

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
        if args.mc:
            cmsExtra = "#splitline{Private Work}{Simulation}"
    elif args.mc:
        cmsExtra = "Simulation"
    else:
        cmsExtra = "Preliminary"

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in args.selection:

            selection = getRegion(selectionName)

            if args.central:
                centralVal = centralValues(source, path, selection, runRange,
                                           args.mc, args.backgrounds)
                if args.mc:
                    outFilePkl = open(
                        "shelves/triggerEff_%s_%s_%s_MC.pkl" %
                        (selection.name, source, runRange.label), "w")
                else:
                    outFilePkl = open(
                        "shelves/triggerEff_%s_%s_%s.pkl" %
                        (selection.name, source, runRange.label), "w")
                pickle.dump(centralVal, outFilePkl)
                outFilePkl.close()

            if args.dependencies:
                dependencies(source, path, selection, args.plots, runRange,
                             args.mc, args.backgrounds, cmsExtra)

            if args.write:
                import subprocess
                if args.mc:
                    bashCommand = "cp shelves/triggerEff_%s_%s_%s_MC.pkl %s/shelves" % (
                        selection.name, source, runRange.label,
                        pathes.basePath)
                else:
                    bashCommand = "cp shelves/triggerEff_%s_%s_%s.pkl %s/shelves" % (
                        selection.name, source, runRange.label,
                        pathes.basePath)
                process = subprocess.Popen(bashCommand.split())
Пример #28
0
def main():

    parser = argparse.ArgumentParser(description='rSFOF from control region.')

    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        default=False,
                        help="Verbose mode.")
    parser.add_argument("-d",
                        "--dependencies",
                        action="store_true",
                        dest="dependencies",
                        default=False,
                        help="SF/OF dependency crosschecks.")
    parser.add_argument("-m",
                        "--mc",
                        action="store_true",
                        dest="mc",
                        default=False,
                        help="add MC.")
    parser.add_argument("-c",
                        "--control",
                        action="store_true",
                        dest="control",
                        default=False,
                        help="use control region.")
    parser.add_argument("-r",
                        "--runRange",
                        dest="runRange",
                        action="append",
                        default=[],
                        help="name of run range.")
    parser.add_argument("-x",
                        "--private",
                        action="store_true",
                        dest="private",
                        default=False,
                        help="plot is private work.")
    parser.add_argument("-e",
                        "--edgeShape",
                        action="store_true",
                        dest="edgeShape",
                        default=False,
                        help="add 8 TeV excess shape.")
    parser.add_argument("-s",
                        "--edgeShapeMC",
                        action="store_true",
                        dest="edgeShapeMC",
                        default=False,
                        help="add 13 TeV MC signals")
    parser.add_argument(
        "-D",
        "--differentEdgePositions",
        action="store_true",
        dest="differentEdgePositions",
        default=False,
        help="add 13 TeV MC signals at different edge positions")
    parser.add_argument("-b",
                        "--backgrounds",
                        dest="backgrounds",
                        action="append",
                        default=[],
                        help="backgrounds to plot.")
    parser.add_argument("-p",
                        "--plot",
                        dest="plots",
                        action="append",
                        default=[],
                        help="select dependencies to study, default is all.")

    args = parser.parse_args()

    if len(args.backgrounds) == 0:
        args.backgrounds = backgroundLists.rSFOF
    if len(args.plots) == 0:
        args.plots = plotLists.default

    selections = []

    if args.control:

        selections.append(regionsToUse.rSFOF.central.name)
        selections.append(regionsToUse.rSFOF.forward.name)
        selections.append(regionsToUse.rSFOF.inclusive.name)
    else:
        selections.append(regionsToUse.signalOld.central.name)
        #~ selections.append(regionsToUse.signal.forward.name)
        #~ selections.append(regionsToUse.signal.inclusive.name)

    if len(args.runRange) == 0:
        args.runRange.append(runRanges.name)

    path = locations.dataSetPathTrigger

    cmsExtra = ""
    if args.private:
        cmsExtra = "Private Work"
    else:
        cmsExtra = "Preliminary"
        #~ cmsExtra = ""

    for runRangeName in args.runRange:
        runRange = getRunRange(runRangeName)

        for selectionName in selections:

            selection = getRegion(selectionName)
            if args.dependencies:
                makeDependencyPlot(path, selection, args.plots, args.mc,
                                   args.backgrounds, runRange, cmsExtra)
            else:
                makeResultPlot(
                    path,
                    selection,
                    runRange,
                    cmsExtra,
                    edgeShape=args.edgeShape,
                    edgeShapeMC=args.edgeShapeMC,
                    differentEdgePositions=args.differentEdgePositions)
Пример #29
0
def centralValues(source,modifier,path,selection,runRange,isMC,nonNormalized,backgrounds,cmsExtra):


        plot = getPlot("mllPlotRSFOFCentralVal")
        #plot = getPlot("mllPlot")
        plot.addRegion(selection)
        #plot.cleanCuts()
        plot.addRunRange(runRange)
        #plot.cuts = plot.cuts % runRange.runCut
        plot.cuts = plot.cuts.replace("p4.M()","mll")
        plot.variable = plot.variable.replace("p4.M()","mll")
        plot.cuts = plot.cuts.replace("p4.Pt()","pt")
        plot.cuts = plot.cuts.replace("&& metFilterSummary > 0","")
        #~ plot.cuts = plot.cuts.replace("triggerSummary > 0 &&","")
        #~ plot.cuts = plot.cuts.replace("genWeight*weight*","")
        #~ plot.cuts = plot.cuts.replace("weight*","")
        plot.variable = plot.variable.replace("p4.Pt()","pt")        
        
        #plot.cuts = plot.cuts.replace("mll","p4.M()")
        #plot.variable = plot.variable.replace("mll","p4.M()")
        #plot.cuts = plot.cuts.replace("pt > 25","p4.Pt() > 25")
        #~ plot.variable = plot.variable.replace("pt","p4.Pt()")        

        plotSignal = getPlot("mllPlot")
        

        
        if "Forward" in selection.name:
                plotSignal.addRegion(getRegion("SignalForward"))
                label = "forward"
        elif "Central" in selection.name:
                plotSignal.addRegion(getRegion("SignalCentral"))
                label = "central"
        else:           
                plotSignal.addRegion(getRegion("SignalInclusiveHighMT2"))
                label = "inclusive"

        plotSignal.cleanCuts()
        plotSignal.cuts = plotSignal.cuts % runRange.runCut     
        plotSignal.cuts = plotSignal.cuts.replace("p4.M()","mll")
        plotSignal.variable = plotSignal.variable.replace("p4.M()","mll")    
        plotSignal.cuts = plotSignal.cuts.replace("p4.Pt()","pt")
        plotSignal.cuts = plotSignal.cuts.replace("&& metFilterSummary > 0","")
        #~ plotSignal.cuts = plotSignal.cuts.replace("triggerSummary > 0 &&","")
        #~ plotSignal.cuts = plot.cuts.replace("genWeight*weight*","")
        #~ plotSignal.cuts = plot.cuts.replace("weight*","")
        plotSignal.variable = plotSignal.variable.replace("p4.Pt()","pt")
        
        #plotSignal.cuts = plotSignal.cuts.replace("mll","p4.M()")
        #plotSignal.variable = plotSignal.variable.replace("mll","p4.M()")
        #plotSignal.variable = plotSignal.variable.replace("pt > 25","p4.Pt() > 25")     

        
        tempCut = plot.cuts
        #plot.cuts = plot.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && (mll>20 && mll < 70)")
        #plot.cuts = plot.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && (p4.M()>20 && p4.M() < 70)")
        
        #~ print plot.cuts

        #histEELow, histMMLow, histEMLow = getHistograms(path,source,modifier,plot,runRange,isMC,nonNormalized,backgrounds,label)
        #histSFLow = histEELow.Clone("histSFLow")
        #histSFLow.Add(histMMLow.Clone())
        

        histEE, histMM, histEM = getHistograms(path,source,modifier,plot,runRange,isMC,nonNormalized,backgrounds,label)
        histSF = histEE.Clone("histSF")
        histSF.Add(histMM.Clone())
        
        #plot.cuts = tempCut
        #plot.cuts = plot.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && mll>110")
        #plot.cuts = plot.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && p4.M()>110")
        #~ plot.cuts = plot.cuts+"&& (mll>110)"
        
        #histEEHigh, histMMHigh, histEMHigh = getHistograms(path,source,modifier,plot,runRange,isMC,nonNormalized,backgrounds,label)
        #histSFHigh = histEEHigh.Clone("histSFHigh")
        #histSFHigh.Add(histMMHigh.Clone())
        
        plot.cuts = tempCut
        print plot.cuts
        if isMC:
                tempCut = plotSignal.cuts
                
                #plotSignal.cuts = plotSignal.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && (mll>20 && mll < 70)")
                #plotSignal.cuts = plotSignal.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && (p4.M()>20 && p4.M() < 70)")
                #histEESignalLow, histMMSignalLow, histEMSignalLow = getHistograms(path,source,modifier,plotSignal,runRange,isMC,nonNormalized,backgrounds,label)
                #histSFSignalLow = histEESignalLow.Clone("histSFSignalLow")
                #histSFSignalLow.Add(histMMSignalLow.Clone())
                
                histEESignal, histMMSignal, histEMSignal = getHistograms(path,source,modifier,plotSignal,runRange,isMC,nonNormalized,backgrounds,label)
                histSFSignal = histEESignal.Clone("histSFSignal")
                histSFSignal.Add(histMMSignal.Clone())
                
                plotSignal.cuts = tempCut
                #plotSignal.cuts = plotSignal.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && mll>110")
                #plotSignal.cuts = plotSignal.cuts.replace("chargeProduct < 0", "chargeProduct < 0 && p4.M()>110")
                #histEESignalHigh, histMMSignalHigh, histEMSignalHigh = getHistograms(path,source,modifier,plotSignal,runRange,isMC,nonNormalized,backgrounds,label)
                #histSFSignalHigh = histEESignalHigh.Clone("histSFSignalHigh")
                #histSFSignalHigh.Add(histMMSignalHigh.Clone())
                
                plotSignal.cuts = tempCut
        
        result = {}
                        

        #eeLowMassErr = ROOT.Double()
        #~ eeLowMass = histEELow.IntegralAndError(plot.firstBin,plot.lastBin,eeLowMassErr)
        #eeLowMass = histEELow.IntegralAndError(histEELow.GetXaxis().FindBin(plot.firstBin),histEELow.GetXaxis().FindBin(plot.lastBin)-1,eeLowMassErr)
        #eeHighMassErr = ROOT.Double()
        #eeHighMass = histEEHigh.IntegralAndError(histEEHigh.GetXaxis().FindBin(plot.firstBin),histEEHigh.GetXaxis().FindBin(plot.lastBin)-1,eeHighMassErr)
        
        eeErr = ROOT.Double()
        ee = histEE.IntegralAndError(1,histMM.GetNbinsX(),eeErr)
        
        #ee = eeLowMass + eeHighMass
        #eeErr = (eeLowMassErr**2 + eeHighMassErr**2)**0.5
        
        #mmLowMassErr = ROOT.Double()
        #mmLowMass = histMMLow.IntegralAndError(histMMLow.GetXaxis().FindBin(plot.firstBin),histMMLow.GetXaxis().FindBin(plot.lastBin)-1,mmLowMassErr)
        #mmHighMassErr = ROOT.Double()
        #mmHighMass = histMMHigh.IntegralAndError(histMMHigh.GetXaxis().FindBin(plot.firstBin),histMMHigh.GetXaxis().FindBin(plot.lastBin)-1,mmHighMassErr)
        
        mmErr = ROOT.Double()
        mm = histMM.IntegralAndError(1,histMM.GetNbinsX(),mmErr)
        
        #mm = mmLowMass + mmHighMass
        #mmErr = (mmLowMassErr**2 + mmHighMassErr**2)**0.5
        
        #ofLowMassErr = ROOT.Double()
        #ofLowMass = histEMLow.IntegralAndError(histEMLow.GetXaxis().FindBin(plot.firstBin),histEMLow.GetXaxis().FindBin(plot.lastBin)-1,ofLowMassErr)
        #ofHighMassErr = ROOT.Double()
        #ofHighMass = histEMHigh.IntegralAndError(histEMHigh.GetXaxis().FindBin(plot.firstBin),histEMHigh.GetXaxis().FindBin(plot.lastBin)-1,ofHighMassErr)
        
        ofErr = ROOT.Double()
        of = histEM.IntegralAndError(1,histEM.GetNbinsX(),ofErr)
        
        #of = ofLowMass + ofHighMass
        #ofErr = (ofLowMassErr**2 + ofHighMassErr**2)**0.5
        
        
        sf = ee + mm 
        #sfLowMass = eeLowMass + mmLowMass 
        #sfHighMass = eeHighMass + mmHighMass 
        sfErr = (eeErr**2 + mmErr**2)**0.5
        #sfLowMassErr = (eeLowMassErr**2 + mmLowMassErr**2)**0.5
        #sfHighMassErr = (eeHighMassErr**2 + mmHighMassErr**2)**0.5      
        
        print sf, of
        
        rsfof = float(sf)/float(of)
        rsfofErr = rsfof*(sfErr**2/sf**2+ofErr**2/of**2)**0.5
        #rsfofLowMass = float(sfLowMass)/float(ofLowMass)
        #rsfofLowMassErr = rsfofLowMass*(sfLowMassErr**2/sfLowMass**2+ofLowMassErr**2/ofLowMass**2)**0.5
        #rsfofHighMass = float(sfHighMass)/float(ofHighMass)
        #rsfofHighMassErr = rsfofHighMass*(sfHighMassErr**2/sf**2+ofHighMassErr**2/of**2)**0.5
        
        
        rEEOF = float(ee)/float(of)
        if ee > 0 and of > 0:
                rEEOFErr = rEEOF * (eeErr**2/ee**2 + ofErr**2/of**2)**0.5
        else:
                rEEOFErr = 0
        #rEEOFLowMass = float(eeLowMass)/float(ofLowMass)
        #if eeLowMass > 0 and ofLowMass > 0:
                #rEEOFLowMassErr = rEEOFLowMass * (eeLowMassErr**2/eeLowMass**2 + ofLowMassErr**2/ofLowMass**2)**0.5
        #else:
                #rEEOFLowMassErr = 0
        #rEEOFHighMass = float(eeHighMass)/float(ofHighMass)
        #if eeHighMass > 0 and ofHighMass > 0:
                #rEEOFHighMassErr = rEEOFHighMass * (eeHighMassErr**2/eeHighMass**2 + ofHighMassErr**2/ofHighMass**2)**0.5
        #else:
                #rEEOFHighMassErr = 0    
        
        rMMOF = float(mm)/float(of)
        rMMOFErr = rMMOF * (mmErr**2/mm**2 + ofErr**2/of**2)**0.5
        #rMMOFLowMass = float(mmLowMass)/float(ofLowMass)
        #rMMOFLowMassErr = rMMOFLowMass * (mmLowMassErr**2/mmLowMass**2 + ofLowMassErr**2/ofLowMass**2)**0.5
        #rMMOFHighMass = float(mmHighMass)/float(ofHighMass)
        #rMMOFHighMassErr = rMMOFHighMass * (mmHighMassErr**2/mmHighMass**2 + ofHighMassErr**2/ofHighMass**2)**0.5
        
        
        result = {}
        result["EE"] = ee
        result["MM"] = mm
        result["SF"] = sf
        result["OF"] = of
        #result["EELowMass"] = eeLowMass
        #result["MMLowMass"] = mmLowMass
        #result["SFLowMass"] = eeLowMass + mmLowMass
        #result["OFLowMass"] = ofLowMass
        #result["EEHighMass"] = eeHighMass
        #result["MMHighMass"] = mmHighMass
        #result["SFHighMass"] = eeHighMass + mmHighMass
        #result["OFHighMass"] = ofHighMass
        
        #result["rSFOFLowMass"] = sfLowMass / ofLowMass
        #result["rSFOFErrLowMass"] = result["rSFOFLowMass"]*(sfLowMassErr**2/sfLowMass**2+ofLowMassErr**2/ofLowMass**2)**0.5
        #result["rEEOFLowMass"] = eeLowMass / ofLowMass
        #result["rEEOFErrLowMass"] =  result["rEEOFLowMass"]*((eeLowMassErr**2)**0.5**2/sfLowMass**2+ofLowMassErr**2/ofLowMass**2)**0.5
        #result["rMMOFLowMass"] = mmLowMass / ofLowMass
        #result["rMMOFErrLowMass"] =  result["rMMOFLowMass"]*((mmLowMassErr**2)**0.5**2/sfLowMass**2+ofLowMassErr**2/ofLowMass**2)**0.5
        #result["rSFOFHighMass"] = sfHighMass / ofHighMass
        #result["rSFOFErrHighMass"] = result["rSFOFHighMass"]*(sfHighMassErr**2/sfHighMass**2+ofHighMassErr**2/ofHighMass**2)**0.5
        #result["rEEOFHighMass"] = eeHighMass / ofHighMass
        #result["rEEOFErrHighMass"] =  result["rEEOFHighMass"]*((eeHighMassErr**2)**0.5**2/sfHighMass**2+ofHighMassErr**2/ofHighMass**2)**0.5
        #result["rMMOFHighMass"] = mmHighMass / ofHighMass
        #result["rMMOFErrHighMass"] =  result["rMMOFHighMass"]*((mmHighMassErr**2)**0.5**2/sfHighMass**2+ofHighMassErr**2/ofHighMass**2)**0.5
                
        result["rSFOF"] = rsfof
        result["rSFOFErr"] = rsfofErr
        result["rEEOF"] = rEEOF
        result["rEEOFErr"] = rEEOFErr
        result["rMMOF"] = rMMOF
        result["rMMOFErr"] = rMMOFErr   

        
        if isMC:
                
                
                #eeLowMassErrSignal = ROOT.Double()
                #eeLowMassSignal = histEESignalLow.IntegralAndError(histEESignalLow.GetXaxis().FindBin(plotSignal.firstBin),histEESignalLow.GetXaxis().FindBin(plotSignal.lastBin)-1,eeLowMassErr)
                #eeHighMassErrSignal = ROOT.Double()
                #eeHighMassSignal = histEESignalHigh.IntegralAndError(histEESignalHigh.GetXaxis().FindBin(plotSignal.firstBin),histEESignalHigh.GetXaxis().FindBin(plotSignal.lastBin)-1,eeHighMassErr)
                eeErrSignal = ROOT.Double()
                eeSignal = histEESignal.IntegralAndError(1,histEESignal.GetNbinsX(),eeErrSignal)
                
                #eeSignal = eeLowMassSignal + eeHighMassSignal
                #eeErrSignal = (eeLowMassErrSignal**2 + eeHighMassErrSignal**2)**0.5
                
                #mmLowMassErrSignal = ROOT.Double()
                #mmLowMassSignal = histMMSignalLow.IntegralAndError(histMMSignalLow.GetXaxis().FindBin(plotSignal.firstBin),histMMSignalLow.GetXaxis().FindBin(plotSignal.lastBin)-1,mmLowMassErr)
                #mmHighMassErrSignal = ROOT.Double()
                #mmHighMassSignal = histMMSignalHigh.IntegralAndError(histMMSignalHigh.GetXaxis().FindBin(plotSignal.firstBin),histMMSignalHigh.GetXaxis().FindBin(plotSignal.lastBin)-1,mmHighMassErr)
                
                mmErrSignal = ROOT.Double()
                mmSignal = histMMSignal.IntegralAndError(1,histMMSignal.GetNbinsX(),mmErrSignal)
                
                #mmSignal = mmLowMassSignal + mmHighMassSignal
                #mmErrSignal = (mmLowMassErrSignal**2 + mmHighMassErrSignal**2)**0.5
                
                #ofLowMassErrSignal = ROOT.Double()
                #ofLowMassSignal = histEMSignalLow.IntegralAndError(histEMSignalLow.GetXaxis().FindBin(plotSignal.firstBin),histEMSignalLow.GetXaxis().FindBin(plotSignal.lastBin)-1,ofLowMassErr)
                #ofHighMassErrSignal = ROOT.Double()
                #ofHighMassSignal = histEMSignalHigh.IntegralAndError(histEMSignalHigh.GetXaxis().FindBin(plotSignal.firstBin),histEMSignalHigh.GetXaxis().FindBin(plotSignal.lastBin)-1,ofHighMassErr)
                
                ofErrSignal = ROOT.Double()
                ofSignal = histEMSignal.IntegralAndError(1,histEESignal.GetNbinsX(),ofErrSignal)
                
                #ofSignal = ofLowMassSignal + ofHighMassSignal
                #ofErrSignal = (ofLowMassErrSignal**2 + ofHighMassErrSignal**2)**0.5     
                
                sfSignal = eeSignal + mmSignal 
                #sfLowMassSignal = eeLowMassSignal + mmLowMassSignal
                #sfHighMassSignal = eeHighMassSignal + mmHighMassSignal
                sfErrSignal = (eeErrSignal**2 + mmErrSignal**2)**0.5
                #sfLowMassErrSignal = (eeLowMassErrSignal**2 + mmLowMassErrSignal**2)**0.5
                #sfHighMassErrSignal = (eeHighMassErrSignal**2 + mmHighMassErrSignal**2)**0.5
                
                rsfofSignal = float(sfSignal)/float(ofSignal)   
                rsfofErrSignal = rsfofSignal*(sfErrSignal**2/sfSignal**2+ofErrSignal**2/ofSignal**2)**0.5
                #rsfofLowMassSignal = float(sfLowMassSignal)/float(ofLowMassSignal)
                #if sfLowMassSignal > 0 and ofLowMassSignal > 0:
                        #rsfofLowMassErrSignal = rsfofLowMassSignal*(sfLowMassErrSignal**2/sfLowMassSignal**2+ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #rsfofLowMassErrSignal = 0
                #rsfofHighMassSignal = float(sfHighMassSignal)/float(ofHighMassSignal)
                #rsfofHighMassErrSignal = rsfofHighMassSignal*(sfHighMassErrSignal**2/sfHighMassSignal**2+ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5
                
                rEEOFSignal = float(eeSignal)/float(ofSignal)
                rEEOFErrSignal = rEEOFSignal * (eeErrSignal**2/eeSignal**2 + ofErrSignal**2/ofSignal**2)**0.5
                #rEEOFLowMassSignal = float(eeLowMassSignal)/float(ofLowMassSignal)
                #if eeLowMassSignal > 0 and ofLowMassSignal > 0:
                        #rEEOFLowMassErrSignal = rEEOFLowMassSignal * (eeLowMassErrSignal**2/eeLowMassSignal**2 + ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #rEEOFLowMassErrSignal = 0
                #rEEOFHighMassSignal = float(eeHighMassSignal)/float(ofHighMassSignal)
                #rEEOFHighMassErrSignal = rEEOFHighMassSignal * (eeHighMassErrSignal**2/eeHighMassSignal**2 + ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5
        
                rMMOFSignal = float(mmSignal)/float(ofSignal)
                rMMOFErrSignal = rMMOFSignal * (mmErrSignal**2/mmSignal**2 + ofErrSignal**2/ofSignal**2)**0.5
                #rMMOFLowMassSignal = float(mmLowMassSignal)/float(ofLowMassSignal)
                #if mmLowMassSignal > 0 and ofLowMassSignal > 0:
                        #rMMOFLowMassErrSignal = rMMOFLowMassSignal * (mmLowMassErrSignal**2/mmLowMassSignal**2 + ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #rMMOFLowMassErrSignal = 0
                #rMMOFHighMassSignal = float(mmHighMassSignal)/float(ofHighMassSignal)
                #rMMOFHighMassErrSignal = rMMOFHighMassSignal * (mmHighMassErrSignal**2/mmHighMassSignal**2 + ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5   
                
                transferFaktor = rsfofSignal/rsfof
                transferFaktorErr = transferFaktor*((rsfofErr/rsfof)**2+(rsfofErrSignal/rsfofSignal)**2)**0.5
                if rEEOF > 0:
                        transferFaktorEE = rEEOFSignal/rEEOF
                else:
                        transferFaktorEE = 0
                if rEEOF > 0 and rEEOFSignal > 0:
                        transferFaktorEEErr = transferFaktorEE*((rEEOFErr/rEEOF)**2+(rEEOFErrSignal/rEEOFSignal)**2)**0.5
                else:
                        transferFaktorEEErr = 0
                transferFaktorMM = rMMOFSignal/rMMOF
                transferFaktorMMErr = transferFaktorMM*((rMMOFErr/rMMOF)**2+(rMMOFErrSignal/rMMOFSignal)**2)**0.5
                
                #transferFaktorLowMass = rsfofLowMassSignal/rsfofLowMass
                #if rsfofLowMass > 0 and rsfofLowMassSignal > 0:
                        #transferFaktorLowMassErr = transferFaktorLowMass*((rsfofLowMassErr/rsfofLowMass)**2+(rsfofLowMassErrSignal/rsfofLowMassSignal)**2)**0.5
                #else:
                        #transferFaktorLowMassErr = 0
                #if rEEOFLowMass > 0:
                        #transferFaktorEELowMass = rEEOFLowMassSignal/rEEOFLowMass
                #else:
                        #transferFaktorEELowMass = 0
                #if rEEOFLowMass > 0 and rEEOFLowMassSignal > 0:
                        #transferFaktorEELowMassErr = transferFaktorEELowMass*((rEEOFLowMassErr/rEEOFLowMass)**2+(rEEOFLowMassErrSignal/rEEOFLowMassSignal)**2)**0.5
                #else:
                        #transferFaktorEELowMassErr = 0
                #transferFaktorMMLowMass = rMMOFLowMassSignal/rMMOFLowMass
                #if rMMOFLowMass > 0 and rMMOFLowMassSignal > 0:
                        #transferFaktorMMLowMassErr = transferFaktorMMLowMass*((rMMOFLowMassErr/rMMOFLowMass)**2+(rMMOFLowMassErrSignal/rMMOFLowMassSignal)**2)**0.5
                #else:
                        #transferFaktorMMLowMassErr = 0
                
                #transferFaktorHighMass = rsfofHighMassSignal/rsfofHighMass
                #transferFaktorHighMassErr = transferFaktorHighMass*((rsfofHighMassErr/rsfofHighMass)**2+(rsfofHighMassErrSignal/rsfofHighMassSignal)**2)**0.5
                #if rEEOFHighMass > 0:
                        #transferFaktorEEHighMass = rEEOFHighMassSignal/rEEOFHighMass
                #else:
                        #transferFaktorEEHighMass = 0
                #if rEEOFHighMass > 0 and rEEOFHighMassSignal > 0:
                        #transferFaktorEEHighMassErr = transferFaktorEEHighMass*((rEEOFHighMassErr/rEEOFHighMass)**2+(rEEOFHighMassErrSignal/rEEOFHighMassSignal)**2)**0.5
                #else:
                        #transferFaktorEEHighMassErr = 0
                #transferFaktorMMHighMass = rMMOFHighMassSignal/rMMOFHighMass
                #transferFaktorMMHighMassErr = transferFaktorMMHighMass*((rMMOFHighMassErr/rMMOFHighMass)**2+(rMMOFHighMassErrSignal/rMMOFHighMassSignal)**2)**0.5               
                
                result["EESignal"] = eeSignal
                result["MMSignal"] = mmSignal
                result["SFSignal"] = sfSignal
                result["OFSignal"] = ofSignal
                #result["EELowMassSignal"] = eeLowMassSignal
                #result["MMLowMassSignal"] = mmLowMassSignal
                #result["SFLowMassSignal"] = eeLowMassSignal + mmLowMassSignal
                #result["OFLowMassSignal"] = ofLowMassSignal
                #result["EEHighMassSignal"] = eeHighMassSignal
                #result["MMHighMassSignal"] = mmHighMassSignal
                #result["SFHighMassSignal"] = eeHighMassSignal + mmHighMassSignal
                #result["OFHighMassSignal"] = ofHighMassSignal
                
                #result["rSFOFLowMassSignal"] = sfLowMassSignal / ofLowMassSignal
                #if sfLowMassSignal > 0 and ofLowMassSignal > 0:
                        #result["rSFOFErrLowMassSignal"] = result["rSFOFLowMassSignal"]*(sfLowMassErrSignal**2/sfLowMassSignal**2+ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #result["rSFOFErrLowMassSignal"] = 0
                #result["rEEOFLowMassSignal"] = eeLowMassSignal / ofLowMassSignal
                #if eeLowMassSignal > 0 and ofLowMassSignal > 0:
                        #result["rEEOFErrLowMassSignal"] =  result["rEEOFLowMassSignal"]*(eeLowMassErrSignal**2/eeLowMassSignal**2+ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #result["rEEOFErrLowMassSignal"] = 0
                #result["rMMOFLowMassSignal"] = mmLowMassSignal / ofLowMassSignal
                #if mmLowMassSignal > 0 and ofLowMassSignal > 0:
                        #result["rMMOFErrLowMassSignal"] =  result["rMMOFLowMassSignal"]*(mmLowMassErrSignal**2/mmLowMassSignal**2+ofLowMassErrSignal**2/ofLowMassSignal**2)**0.5
                #else:
                        #result["rMMOFErrLowMassSignal"] = 0
                        
                #result["rSFOFHighMassSignal"] = sfHighMassSignal / ofHighMassSignal
                #result["rSFOFErrHighMassSignal"] = result["rSFOFHighMassSignal"]*(sfHighMassErrSignal**2/sfHighMassSignal**2+ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5
                #result["rEEOFHighMassSignal"] = eeHighMassSignal / ofHighMassSignal
                #result["rEEOFErrHighMassSignal"] =  result["rEEOFHighMassSignal"]*(eeHighMassErrSignal**2/eeHighMassSignal**2+ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5
                #result["rMMOFHighMassSignal"] = mmHighMassSignal / ofHighMassSignal
                #result["rMMOFErrHighMassSignal"] =  result["rMMOFHighMassSignal"]*(mmHighMassErrSignal**2/mmHighMassSignal**2+ofHighMassErrSignal**2/ofHighMassSignal**2)**0.5
                
                result["rSFOFSignal"] = rsfofSignal
                result["rSFOFErrSignal"] = rsfofErrSignal
                result["rEEOFSignal"] = rEEOFSignal
                result["rEEOFErrSignal"] = rEEOFErrSignal
                result["rMMOFSignal"] = rMMOFSignal
                result["rMMOFErrSignal"] = rMMOFErrSignal
                
                result["transfer"] = transferFaktor
                result["transferErr"] = transferFaktorErr
                result["transferEE"] = transferFaktorEE
                result["transferEEErr"] = transferFaktorEEErr
                result["transferMM"] = transferFaktorMM
                result["transferMMErr"] = transferFaktorMMErr
                
                #result["transferLowMass"] = transferFaktorLowMass
                #result["transferLowMassErr"] = transferFaktorLowMassErr
                #result["transferEELowMass"] = transferFaktorEELowMass
                #result["transferEELowMassErr"] = transferFaktorEELowMassErr
                #result["transferMMLowMass"] = transferFaktorMMLowMass
                #result["transferMMLowMassErr"] = transferFaktorMMLowMassErr
                #result["transferHighMass"] = transferFaktorHighMass
                #result["transferHighMassErr"] = transferFaktorHighMassErr
                #result["transferEEHighMass"] = transferFaktorEEHighMass
                #result["transferEEHighMassErr"] = transferFaktorEEHighMassErr
                #result["transferMMHighMass"] = transferFaktorMMHighMass
                #result["transferMMHighMassErr"] = transferFaktorMMHighMassErr
                
        
        return result