Esempio n. 1
0
def plotSummary(name, closure, xmin=0, xmax=1, xTitle='m_{vis} [GeV]'):
    histoSmoothRatios = []
    for hname, graph in closure.data['True/Est'].items():
        if 'Histo' in hname and 'Smooth' in hname and not 'Error' in hname:
            histoSmoothRatios.append(graph)
    ################ Plot ratios
    histoDummyRatio = Hist(1, xmin, xmax, type='F')
    values = []
    for ratio in histoSmoothRatios:
        for p in xrange(ratio.GetN()):
            values.append(ratio.GetY()[p])
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    for ratio in histoSmoothRatios:
        ratio.SetLineColor(ROOT.kGray + 3)
        ratio.SetLineWidth(1)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('Ratio_Summary_Canvas')
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    for ratio in histoSmoothRatios:
        ratio.Draw('l same')
    canvasRatio.Print(
        'results/{NAME}_NonClosure_Ratio_Summary.png'.format(NAME=name))
def plotDataMC(name, closureData, closureMC, bins, xTitle='m_{vis} [GeV]'):
    binid = hash(str(bins))
    #
    histoRatioData = closureData.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatioData = closureData.data['True/Est'][
        'Histo_{H}_Smooth'.format(H=binid)]
    histoSmoothRatioErrorData = closureData.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    histoRatioMC = closureMC.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatioMC = closureMC.data['True/Est']['Histo_{H}_Smooth'.format(
        H=binid)]
    histoSmoothRatioErrorMC = closureMC.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    #
    ################ Plot ratios
    histoDummyRatio = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoRatioData.GetMaximum())
    values.append(histoRatioData.GetMinimum())
    values.append(histoRatioMC.GetMaximum())
    values.append(histoRatioMC.GetMinimum())
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    histoRatioData.SetMarkerColor(ROOT.kBlack)
    histoSmoothRatioData.SetLineColor(ROOT.kGray + 3)
    histoSmoothRatioData.SetLineWidth(2)
    histoSmoothRatioErrorData.SetLineColor(ROOT.kGray + 1)
    histoSmoothRatioErrorData.SetFillColor(ROOT.kGray + 1)
    ##
    histoRatioMC.SetMarkerColor(ROOT.kRed)
    histoRatioMC.SetMarkerStyle(21)
    histoSmoothRatioMC.SetLineColor(ROOT.kRed)
    histoSmoothRatioMC.SetLineWidth(2)
    histoSmoothRatioErrorMC.SetLineColor(ROOT.kRed - 7)
    #histoSmoothRatioErrorMC.SetFillColorAlpha(ROOT.kRed-7, 0.35)
    histoSmoothRatioErrorMC.SetFillStyle(3344)
    histoSmoothRatioErrorMC.SetFillColor(ROOT.kRed - 7)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name))
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    histoSmoothRatioErrorData.Draw('fl same')
    histoSmoothRatioData.Draw('pl same')
    histoSmoothRatioErrorMC.Draw('fl same')
    histoSmoothRatioMC.Draw('pl same')
    histoRatioData.Draw('E1 same')
    histoRatioMC.Draw('E1 same')
    #
    legend = ROOT.TLegend(0.15, 0.75, 0.45, 0.9)
    legend.SetFillColor(0)
    legend.SetLineColor(0)
    legend.AddEntry(histoRatioMC, 'MC', 'lp')
    legend.AddEntry(histoRatioData, 'Data', 'lp')
    legend.Draw()
    canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))
Esempio n. 3
0
def plotClosure(name,
                closure,
                bins,
                smoothWidth=0.1,
                kernelDistance='Adapt',
                doErrors=False,
                xTitle='m_{vis} [GeV]'):
    binid = hash(str(bins))
    closure.computeHisto('True', bins)
    closure.computeHisto('Est', bins)
    closure.computeRatio('Est', 'True', 'Histo_{H}'.format(H=binid),
                         smoothWidth, kernelDistance, doErrors)
    #
    histoTrue = closure.data['True']['Histo_{H}'.format(H=binid)]
    histoEst = closure.data['Est']['Histo_{H}'.format(H=binid)]
    histoRatio = closure.data['True/Est']['Histo_{H}'.format(H=binid)]
    histoSmoothRatio = closure.data['True/Est']['Histo_{H}_Smooth'.format(
        H=binid)]
    histoSmoothRatioError = closure.data['True/Est'][
        'Histo_{H}_SmoothError'.format(H=binid)]
    #
    ############ plot raw distributions
    histoDummy = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoTrue.GetMaximum())
    values.append(histoTrue.GetMinimum())
    values.append(histoEst.GetMaximum())
    values.append(histoEst.GetMinimum())
    maxi = max(values) * 1.1
    mini = min(values)
    histoDummy.SetAxisRange(mini, maxi, 'Y')
    ##
    histoTrue.SetMarkerColor(ROOT.kBlack)
    histoEst.SetMarkerStyle(24)
    histoEst.SetMarkerColor(ROOT.kGray + 3)
    ##
    canvas = Canvas(800, 800)
    canvas.SetName('{NAME}_Canvas'.format(NAME=name))
    histoDummy.SetXTitle(xTitle)
    histoDummy.SetYTitle('Events')
    histoDummy.Draw()
    histoTrue.Draw('same')
    histoEst.Draw('same')
    legend = ROOT.TLegend(0.4, 0.7, 0.9, 0.9)
    legend.SetFillColor(0)
    legend.SetLineColor(0)
    legend.AddEntry(histoTrue, 'True background', 'lp')
    legend.AddEntry(histoEst, 'Estimated background', 'lp')
    legend.Draw()
    canvas.Print('results/{NAME}_NonClosure.png'.format(NAME=name))

    ################ Plot ratios
    histoDummyRatio = Hist(1, bins[0], bins[-1], type='F')
    values = []
    values.append(histoRatio.GetMaximum())
    values.append(histoRatio.GetMinimum())
    maxi = max(values)
    mini = min(values)
    maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9
    mini = mini * 1.1 if mini < 0 else mini * 0.9
    histoDummyRatio.SetAxisRange(mini, maxi, 'Y')
    ##
    histoRatio.SetMarkerColor(ROOT.kBlack)
    histoSmoothRatio.SetLineColor(ROOT.kGray + 3)
    histoSmoothRatio.SetLineWidth(2)
    histoSmoothRatioError.SetLineColor(ROOT.kGray + 1)
    histoSmoothRatioError.SetFillColor(ROOT.kGray + 1)
    ##
    canvasRatio = Canvas(800, 800)
    canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name))
    histoDummyRatio.SetXTitle(xTitle)
    histoDummyRatio.SetYTitle('Ratio')
    histoDummyRatio.Draw()
    histoSmoothRatioError.Draw('fl same')
    histoSmoothRatio.Draw('pl same')
    histoRatio.Draw('same')
    canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))