def main():
    filename = read_file_name("NY_OUTPUT.txt")
    can = TCanvas("can","can")
    can.SetGrid()
    mg = TMultiGraph()
    nn = 9

    GR = []
    NAME = []
    px,py = array('d'), array('d')
    f = open(filename[2],'r')
    indicator = 0


    for line in f:
        if(indicator == 0):
            indicator = indicator + 1
            continue
           
        Name, Total, Pos, Neg, TNum = line.split()
        name = Find_Loca(Name)
        name = Name.replace(Name[name:],"")
#        print(name)
       
        px.append((indicator-1)%9); py.append(float(TNum))
        if((indicator)%9 == 0):
            NAME.append(name)
            gr = TGraph( nn, px, py )
            GR.append(gr)
            px,py = array('d'), array('d')
        indicator = indicator + 1

#    print(GR); print(len(GR))
    for i in range(len(GR)):
        GR[i].SetLineWidth(2)
        if "water" in NAME[i]:
            GR[i].SetLineWidth(5); GR[i].SetLineColor(1) ;GR[i].SetMarkerColor(1)
        if "wine" in NAME[i]:
            GR[i].SetMarkerColor(2);GR[i].SetLineColor(2)
        if "beer" in NAME[i]:
            GR[i].SetMarkerColor(5);GR[i].SetLineColor(5)
        if "tea" in NAME[i]:
            GR[i].SetMarkerColor(4);GR[i].SetLineColor(4)
        if "coffee" in NAME[i]:
            GR[i].SetMarkerColor(3);GR[i].SetLineColor(3)
        if "juice" in NAME[i]:
            GR[i].SetMarkerColor(7);GR[i].SetLineColor(7)
        if "COLA" in NAME[i]:
            GR[i].SetMarkerColor(6);GR[i].SetLineColor(6)
        GR[i].GetXaxis().SetTitle("days")
        GR[i].SetMarkerStyle(20)
#        GR[i].Fit("pol4","q")
        mg.Add(GR[i])

    mg.Draw("ALP")

    leg = TLegend(0.65, 0.65, 0.9, 0.8)
    leg.SetBorderSize(0)
    leg.SetFillColor(10)
    for i in range(len(GR)):
        leg_entry = leg.AddEntry(GR[i], NAME[i],"l")
    leg.Draw()
    mg.SetTitle("Total tweets counts at NY")
    mg.GetHistogram().GetXaxis().SetTitle("days")
    mg.GetHistogram().GetXaxis().SetTitleOffset(1)
    mg.GetHistogram().GetXaxis().SetLabelSize(0.03)
    mg.GetHistogram().GetYaxis().SetTitle("Counts")
    mg.GetHistogram().GetYaxis().SetTitleOffset(1.3)
    mg.GetHistogram().GetYaxis().SetLabelSize(0.03)
    mg.GetHistogram().GetXaxis().SetBinLabel(5,"Mon")
    mg.GetHistogram().GetXaxis().SetBinLabel(16,"Tue")
    mg.GetHistogram().GetXaxis().SetBinLabel(28,"Wed")
    mg.GetHistogram().GetXaxis().SetBinLabel(40,"Thu")
    mg.GetHistogram().GetXaxis().SetBinLabel(51,"Fri")
    mg.GetHistogram().GetXaxis().SetBinLabel(63,"Sat")
    mg.GetHistogram().GetXaxis().SetBinLabel(73,"Sun")
    mg.GetHistogram().GetXaxis().SetBinLabel(84,"Mon")
    mg.GetHistogram().GetXaxis().SetBinLabel(96,"Tue")
#    for i in range(len(GR)):
#        mg.GetHistogram().GetXaxis().SetBinLabel(i,DAYS)
#    mg.GetHistogram().GetXaxis().SetLabel("tt")
    
    can.Modified()
    can.Update()
   # can.GetFrame().SetBorderSize( 12 )
    can.Print("Total_tweet_NY.pdf")
예제 #2
0
def main():
    filename = read_file_name(
        "OUTPUT_TWITTER_TXT_generator/NY_OUTPUT_week1n2n3n4.txt")  ##FIXME
    can = TCanvas("can", "can")
    can.SetGrid()
    mg = TMultiGraph()
    nn = 7

    GR = []
    NAME = []
    px, py = array('d'), array('d')
    f = open(filename[2], 'r')
    indicator = 0

    for line in f:
        if (indicator == 0):
            indicator = indicator + 1
            continue

        Name, Total, Pos, Neg, TNum = line.split()
        name = Find_Loca(Name)
        name = Name.replace(Name[name:], "")
        #        print(name)

        px.append((indicator - 1) % 7)
        py.append(float(Neg) / float(Total))
        if ((indicator) % 7 == 0):
            NAME.append(name)
            gr = TGraph(nn, px, py)
            GR.append(gr)
            px, py = array('d'), array('d')
        indicator = indicator + 1


#    print(GR); print(len(GR))
    for i in range(len(GR)):
        GR[i].SetLineWidth(2)
        if "water" in NAME[i]:
            GR[i].SetLineWidth(5)
            GR[i].SetLineColor(1)
            GR[i].SetMarkerColor(1)
        if "wine" in NAME[i]:
            GR[i].SetMarkerColor(2)
            GR[i].SetLineColor(2)
        if "beer" in NAME[i]:
            GR[i].SetMarkerColor(5)
            GR[i].SetLineColor(5)
        if "tea" in NAME[i]:
            GR[i].SetMarkerColor(4)
            GR[i].SetLineColor(4)
        if "coffee" in NAME[i]:
            GR[i].SetMarkerColor(3)
            GR[i].SetLineColor(3)
        if "juice" in NAME[i]:
            GR[i].SetMarkerColor(7)
            GR[i].SetLineColor(7)
        if "COLA" in NAME[i]:
            GR[i].SetMarkerColor(6)
            GR[i].SetLineColor(6)
        GR[i].GetXaxis().SetTitle("days")
        GR[i].SetMarkerStyle(20)
        #        GR[i].Fit("pol4","q")
        mg.Add(GR[i])

    mg.Draw("ALP")

    leg = TLegend(0.75, 0.82, 0.95, 0.95)
    leg.SetBorderSize(0)
    leg.SetFillColor(10)
    for i in range(len(GR)):
        leg_entry = leg.AddEntry(GR[i], NAME[i], "l")
    leg.Draw()
    mg.SetTitle("Negative words propotion at NY(week 1&2&3&4)")  ##FIXME
    mg.GetHistogram().GetXaxis().SetTitle("days")
    mg.GetHistogram().GetXaxis().SetTitleOffset(1)
    mg.GetHistogram().GetXaxis().SetLabelSize(0.03)
    mg.GetHistogram().GetYaxis().SetTitle("Counts")
    mg.GetHistogram().GetYaxis().SetTitleOffset(1.3)
    mg.GetHistogram().GetYaxis().SetLabelSize(0.03)
    mg.GetHistogram().GetXaxis().SetBinLabel(5, "Mon")
    mg.GetHistogram().GetXaxis().SetBinLabel(20, "Tue")
    mg.GetHistogram().GetXaxis().SetBinLabel(35, "Wed")
    mg.GetHistogram().GetXaxis().SetBinLabel(51, "Thu")
    mg.GetHistogram().GetXaxis().SetBinLabel(66, "Fri")
    mg.GetHistogram().GetXaxis().SetBinLabel(81, "Sat")
    mg.GetHistogram().GetXaxis().SetBinLabel(96, "Sun")
    #    mg.GetHistogram().GetXaxis().SetBinLabel(84,"Mon")
    #    mg.GetHistogram().GetXaxis().SetBinLabel(96,"Tue")
    #    for i in range(len(GR)):
    #        mg.GetHistogram().GetXaxis().SetBinLabel(i,DAYS)
    #    mg.GetHistogram().GetXaxis().SetLabel("tt")

    can.Modified()
    can.Update()
    # can.GetFrame().SetBorderSize( 12 )
    can.Print("NEG_NY_week1n2n3n4.pdf")  ##FIXME
예제 #3
0
def mistagSFtopEMu(year_, ana_):
    if year_ == 2017:
        dir = "monohbb.v06.00.05.2017_NCU/withSingleTop/" + ana_ + "/"
    if year_ == 2018:
        dir = "monohbb.v06.00.05.2018_NCU/withSingleTop/" + ana_ + "/"

    print "Top Electron Region"
    print " "

    openfile1 = TFile(dir + "TopE.root")  #

    topmatchTopE = openfile1.Get("h_TopMatch")
    WmatchTopE = openfile1.Get("h_Wmatch")
    unmatchTopE = openfile1.Get("h_unmatch")
    wjetsTopE = openfile1.Get("h_sumWJets")
    dibosonTopE = openfile1.Get("h_sumDiboson")
    unsubtractedDataTopE = openfile1.Get("h_Data")

    failMCsubtractTopE = openfile1.Get("h_ttFailed")
    passMCsubtractTopE = openfile1.Get("h_ttPassed")
    subtractedDataTopE = openfile1.Get("SubtractedData")

    datafailTopE = openfile1.Get("SubtractedDataFailed")
    datapassTopE = openfile1.Get("SubtractedDataPassed")  #
    totaldataTopE = openfile1.Get("h_totaldata")
    totalMCtopE = openfile1.Get("h_tt")

    passedTopEdataBfrSubtract = openfile1.Get("h_Data_Passed")
    wjetsTopEpassed = openfile1.Get("h_sumWJetsPassed")
    dibosonTopEpassed = openfile1.Get("h_sumDibosonPassed")

    failedTopEdataBfrSubtract = openfile1.Get("h_Data_Failed")
    wjetsTopEfailed = openfile1.Get("h_sumWJetsFailed")
    dibosonTopEfailed = openfile1.Get("h_sumDibosonFailed")

    stTopE = openfile1.Get("h_sumST")
    stTopEpassed = openfile1.Get("h_sumSTPassed")
    stTopEfailed = openfile1.Get("h_sumSTFailed")

    print "Top Muon Region"
    print " "

    openfile2 = TFile(dir + "TopMu.root")  #

    topmatchTopMu = openfile2.Get("h_TopMatch")
    WmatchTopMu = openfile2.Get("h_Wmatch")
    unmatchTopMu = openfile2.Get("h_unmatch")
    wjetsTopMu = openfile2.Get("h_sumWJets")
    dibosonTopMu = openfile2.Get("h_sumDiboson")
    unsubtractedDataTopMu = openfile2.Get("h_Data")

    failMCsubtractTopMu = openfile2.Get("h_ttFailed")
    passMCsubtractTopMu = openfile2.Get("h_ttPassed")
    subtractedDataTopMu = openfile2.Get("SubtractedData")

    datafailTopMu = openfile2.Get("SubtractedDataFailed")
    datapassTopMu = openfile2.Get("SubtractedDataPassed")  #
    totaldataTopMu = openfile2.Get("h_totaldata")
    totalMCtopMu = openfile2.Get("h_tt")

    passedTopMudataBfrSubtract = openfile2.Get("h_Data_Passed")
    wjetsTopMupassed = openfile2.Get("h_sumWJetsPassed")
    dibosonTopMupassed = openfile2.Get("h_sumDibosonPassed")

    failedTopMudataBfrSubtract = openfile2.Get("h_Data_Failed")
    wjetsTopMufailed = openfile2.Get("h_sumWJetsFailed")
    dibosonTopMufailed = openfile2.Get("h_sumDibosonFailed")

    stTopMu = openfile2.Get("h_sumST")
    stTopMupassed = openfile2.Get("h_sumSTPassed")
    stTopMufailed = openfile2.Get("h_sumSTFailed")

    print "get histograms from root files: done"
    print " "

    SubtractedDataPassedTopE = datapassTopE.Clone("SubtractedDataPassedTopE")
    SubtractedDataPassedTopMu = datapassTopMu.Clone(
        "SubtractedDataPassedTopMu")

    #merge histogram"
    print "merge histograms"
    print " "

    topmatchMerge = topmatchTopE + topmatchTopMu
    WmatchMerge = WmatchTopE + WmatchTopMu
    unmatchMerge = unmatchTopE + unmatchTopMu
    wjetsMerge = wjetsTopE + wjetsTopMu
    stMerge = stTopE + stTopMu
    dibosonMerge = dibosonTopE + dibosonTopMu
    unsubtractedDataMerge = unsubtractedDataTopE + unsubtractedDataTopMu

    failMCsubtractMerge = failMCsubtractTopE.Clone("failMCsubtractMerge")
    failMCsubtractMerge = failMCsubtractMerge + failMCsubtractTopMu
    passMCsubtractMerge = passMCsubtractTopE.Clone("passMCsubtractMerge")
    passMCsubtractMerge = passMCsubtractMerge + passMCsubtractTopMu
    subtractedDataMerge = subtractedDataTopE + subtractedDataTopMu

    ttData_fraction = arr.array('d')
    ttData_error = arr.array('d')

    totaldataMerge = totaldataTopE + totaldataTopMu
    totaldata = totaldataMerge.Integral()
    totaldataMerge.Rebin(14)

    datafailMerge = datafailTopE + datafailTopMu
    faildata = datafailMerge.Integral()
    datafailMerge.Rebin(14)
    datafailMerge.Sumw2()
    datafailMerge.Divide(totaldataMerge)
    frac_ttData_fail = datafailMerge.Integral()
    ttData_fraction.append(frac_ttData_fail)
    ttData_error.append(datafailMerge.GetBinError(1))

    datapassMerge = datapassTopE + datapassTopMu
    passdata = datapassMerge.Integral()
    datapassMerge.Rebin(14)
    datapassMerge.Sumw2()
    datapassMerge.Divide(totaldataMerge)
    frac_ttData_pass = datapassMerge.Integral()
    ttData_fraction.append(frac_ttData_pass)
    ttData_error.append(datapassMerge.GetBinError(1))

    ttMC_fraction = arr.array('d')
    ttMC_error = arr.array('d')

    totalMCmerge = totalMCtopE + totalMCtopMu
    totalMCmerge.Rebin(14)

    MCfailTopE = failMCsubtractTopE.Clone("MCfailTopE")
    MCfailTopMu = failMCsubtractTopMu.Clone("MCfailTopMu")
    MCfailMerge = MCfailTopE + MCfailTopMu
    MCfailMerge.Rebin(14)
    MCfailMerge.Sumw2()
    MCfailMerge.Divide(totalMCmerge)
    frac_Failed_fin = MCfailMerge.Integral()
    ttMC_fraction.append(frac_Failed_fin)
    ttMC_error.append(MCfailMerge.GetBinError(1))

    MCpassTopE = passMCsubtractTopE.Clone("MCpassTopE")
    MCpassTopMu = passMCsubtractTopMu.Clone("MCpassTopMu")
    MCpassMerge = MCpassTopE + MCpassTopMu
    MCpassMerge.Rebin(14)
    MCpassMerge.Sumw2()
    MCpassMerge.Divide(totalMCmerge)
    frac_Passed_fin = MCpassMerge.Integral()
    ttMC_fraction.append(frac_Passed_fin)
    ttMC_error.append(MCpassMerge.GetBinError(1))

    #print "\nttMC_fraction:", ttMC_fraction
    #print "ttMC_error:", ttMC_error

    sfMerge = datapassMerge.Clone("sfMerge")
    sfMerge.Sumw2()
    sfMerge.Divide(MCpassMerge)

    stacklist = []
    stacklist.append(dibosonMerge)
    stacklist.append(stMerge)
    stacklist.append(wjetsMerge)
    stacklist.append(unmatchMerge)
    stacklist.append(WmatchMerge)
    stacklist.append(topmatchMerge)

    print "merge histograms: done"
    print " "

    print "draw histograms"
    print " "
    #----------------------- canvas 1 -----------------------#

    c1 = TCanvas("c1", "", 800, 900)  #width-height
    c1.SetTopMargin(0.4)
    c1.SetBottomMargin(0.05)
    c1.SetRightMargin(0.1)
    c1.SetLeftMargin(0.15)
    gStyle.SetOptStat(0)

    binvalues1 = []
    for i in range(14):
        binvalue = unsubtractedDataMerge.GetBinContent(i)
        binvalues1.append(binvalue)
    totalmax = max(binvalues1) + 100

    padMain = TPad("padMain", "", 0.0, 0.25, 1.0, 0.97)
    padMain.SetTopMargin(0.4)
    padMain.SetRightMargin(0.05)
    padMain.SetLeftMargin(0.17)
    padMain.SetBottomMargin(0.03)
    padMain.SetTopMargin(0.1)

    padRatio = TPad("padRatio", "", 0.0, 0.0, 1.0, 0.25)
    padRatio.SetRightMargin(0.05)
    padRatio.SetLeftMargin(0.17)
    padRatio.SetTopMargin(0.05)
    padRatio.SetBottomMargin(0.3)
    padMain.Draw()
    padRatio.Draw()

    padMain.cd()

    gPad.GetUymax()
    leg1 = myLegend(coordinate=[0.45, 0.57, 0.65, 0.6])

    unsubtractedDataMerge.SetMaximum(totalmax)
    unsubtractedDataMerge.SetLineColor(1)
    unsubtractedDataMerge.SetMarkerStyle(20)
    unsubtractedDataMerge.SetMarkerSize(1.5)
    unsubtractedDataMerge.GetXaxis().SetLabelSize(0)
    unsubtractedDataMerge.GetXaxis().SetTitleSize(0)
    unsubtractedDataMerge.GetXaxis().SetTitle("DDB")
    unsubtractedDataMerge.GetYaxis().SetTitle("Events/Bin")
    leg1.AddEntry(unsubtractedDataMerge, "Data", "lep")
    unsubtractedDataMerge.Draw("e1")

    stackhisto = myStack(colorlist_=[627, 800, 854, 813, 822, 821],
                         backgroundlist_=stacklist,
                         legendname_=[
                             "Diboson", "Single Top", "W+Jets",
                             "Top (unmtch.)", "Top (W-mtch.)", "Top (mtch.)"
                         ])
    stackhisto[0].Draw("histsame")
    unsubtractedDataMerge.Draw("e1same")
    stackhisto[1].Draw()
    leg1.Draw()

    lt = TLatex()
    lt.DrawLatexNDC(0.23, 0.85,
                    "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}")
    if ana_ == "Inclusive":
        lt.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}")
    if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000":
        words = ana_.split("-")
        if words[2] == "2000":
            lt.DrawLatexNDC(0.17, 0.92,
                            "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}")
        else:
            lt.DrawLatexNDC(
                0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" +
                words[2] + " GeV}}")
    else:
        words = ana_.split("-")
        lt.DrawLatexNDC(
            0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" +
            words[2] + " GeV}}")
    lt.DrawLatexNDC(0.23, 0.8, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}")
    lt.DrawLatexNDC(0.23, 0.75, "#scale[0.5]{#bf{2-prong (bq) enriched}}")
    if year_ == 2017:
        lt.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}")
    if year_ == 2018:
        lt.DrawLatexNDC(0.71, 0.92,
                        "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}")

    padRatio.cd()

    gPad.GetUymax()

    h_totalBkg = topmatchMerge.Clone("h_totalBkg")
    h_totalBkg = h_totalBkg + WmatchMerge + unmatchMerge + wjetsMerge + dibosonMerge
    ratio = dataPredRatio(data_=unsubtractedDataMerge, totalBkg_=h_totalBkg)
    ratio.SetLineColor(1)
    ratio.SetLineWidth(3)
    ratio.SetMarkerSize(1.5)
    ratio.GetXaxis().SetLabelSize(0.13)
    ratio.GetXaxis().SetTitleOffset(1)
    ratio.GetXaxis().SetTitleSize(0.13)
    ratio.GetXaxis().SetTickLength(0.1)
    ratio.GetYaxis().SetLabelSize(0.12)
    ratio.GetYaxis().SetTitleOffset(0.5)
    ratio.GetYaxis().SetTitleSize(0.13)
    ratio.GetYaxis().SetNdivisions(405)
    ratio.GetYaxis().SetTitle("#frac{Data-Pred}{Pred}")
    ratio.GetXaxis().SetTitle("DDB")
    ratio.Draw("e1")

    c1.SaveAs(dir + "Merge_all.pdf")  #

    #----------------------- canvas 2 -----------------------#

    c2 = myCanvas(c="c2")
    gPad.GetUymax()
    leg2 = myLegend()

    binvalues2 = []
    for i in range(14):
        binvalue = subtractedDataMerge.GetBinContent(i)
        binvalues2.append(binvalue)
    ttmax = max(binvalues2) + 50

    failMCsubtractMerge.SetMaximum(ttmax)
    failMCsubtractMerge.SetFillColor(821)
    failMCsubtractMerge.SetLineColor(821)  #922
    failMCsubtractMerge.GetXaxis().SetTitle("DDB")
    failMCsubtractMerge.GetYaxis().SetTitle("Events/Bin")
    leg2.AddEntry(failMCsubtractMerge, "t#bar{t}", "f")

    passMCsubtractMerge.SetFillColor(622)
    passMCsubtractMerge.SetLineColor(622)
    #passMCsubtractMerge.GetXaxis().SetTitle("DDB")
    #passMCsubtractMerge.GetYaxis().SetTitle("Events/Bin")
    leg2.AddEntry(passMCsubtractMerge, "t#bar{t} mistag", "f")

    subtractedDataMerge.SetLineColor(1)
    subtractedDataMerge.SetMarkerStyle(20)
    subtractedDataMerge.SetMarkerSize(1.5)
    #subtractedDataMerge.GetXaxis().SetTitle("DDB")
    #subtractedDataMerge.GetYaxis().SetTitle("Events/Bin")
    leg2.AddEntry(subtractedDataMerge, "Subtracted Data", "lep")

    failMCsubtractMerge.Draw("hist")
    passMCsubtractMerge.Draw("histsame")
    subtractedDataMerge.Draw("e1same")
    leg2.Draw()

    lt2 = TLatex()
    if ana_ == "Inclusive":
        lt2.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}")
    if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000":
        words = ana_.split("-")
        if words[2] == "2000":
            lt2.DrawLatexNDC(
                0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}")
        else:
            lt2.DrawLatexNDC(
                0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" +
                words[2] + " GeV}}")
    else:
        words = ana_.split("-")
        lt2.DrawLatexNDC(
            0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" +
            words[2] + " GeV}}")
    lt2.DrawLatexNDC(0.23, 0.85,
                     "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}")
    lt2.DrawLatexNDC(0.23, 0.8, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}")
    lt2.DrawLatexNDC(0.23, 0.75, "#scale[0.5]{#bf{2-prong (bq) enriched}}")
    if year_ == 2017:
        lt2.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}")
    if year_ == 2018:
        lt2.DrawLatexNDC(0.71, 0.92,
                         "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}")

    c2.SaveAs(dir + "Merged_subtrac.pdf")  #

    #----------------------- canvas 3 -----------------------#

    c3 = myCanvas(c="c3", size=[700, 900])

    pad1 = TPad("pad1", "", 0.01, 0.25, 0.93, 1.0)
    pad1.SetTopMargin(0.1)
    pad1.SetRightMargin(0.05)
    pad1.SetLeftMargin(0.17)
    pad1.SetBottomMargin(0.05)

    pad2 = TPad("pad2", "", 0.0, 0.0, 0.375, 0.24)
    pad2.SetTopMargin(0.0)
    pad2.SetRightMargin(0.0)
    pad2.SetLeftMargin(0.0)
    pad2.SetBottomMargin(0.0)

    pad3 = TPad("pad3", "", 0.38, 0.025, 0.94, 0.25)
    pad2.SetTopMargin(0.05)
    pad2.SetRightMargin(0.0)
    pad2.SetLeftMargin(0.45)
    pad2.SetBottomMargin(0.2)

    pad1.Draw()
    pad2.Draw()
    pad3.Draw()

    #* Pad 1 *#
    pad1.cd()
    leg3 = myLegend(coordinate=[0.65, 0.4, 0.75, 0.5])

    xaxisname = arr.array('d', [1, 2])
    zero1 = np.zeros(2)

    gPad.Modified()
    gPad.SetGridy()

    gr1 = TGraphErrors(2, xaxisname, ttMC_fraction, zero1, ttMC_error)
    gr1.SetTitle("t#bar{t}")
    gr1.SetLineColor(870)
    gr1.SetLineWidth(3)
    gr1.SetMarkerStyle(20)
    gr1.SetMarkerColor(870)
    leg3.AddEntry(gr1, "t#bar{t}", "lep")

    gr2 = TGraphErrors(2, xaxisname, ttData_fraction, zero1, ttData_error)
    gr2.SetTitle("t#bar{t} Data")
    gr2.SetLineColor(1)
    gr2.SetLineWidth(2)
    gr2.SetMarkerStyle(20)
    gr2.SetMarkerColor(1)
    leg3.AddEntry(gr2, "t#bar{t} Data", "lep")

    mg = TMultiGraph("mg", "")
    mg.Add(gr1)
    mg.Add(gr2)
    mg.GetHistogram().SetMaximum(1.5)
    mg.GetHistogram().SetMinimum(0)
    mg.GetYaxis().SetTitle("Fraction")
    mg.GetXaxis().SetLimits(0, 3)
    mg.GetXaxis().SetTickLength(0.03)
    mg.GetXaxis().SetNdivisions(103)
    mg.GetXaxis().ChangeLabel(2, -1, -1, -1, -1, -1, "Fail")
    mg.GetXaxis().ChangeLabel(1, -1, 0)
    mg.GetXaxis().ChangeLabel(-1, -1, 0)
    mg.GetXaxis().ChangeLabel(3, -1, -1, -1, -1, -1, "Pass")
    mg.Draw("AP")
    leg3.Draw()

    lt3 = TLatex()
    if ana_ == "Inclusive":
        lt3.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}")
    if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000":
        words = ana_.split("-")
        if words[2] == "2000":
            lt3.DrawLatexNDC(
                0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}")
        else:
            lt3.DrawLatexNDC(
                0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" +
                words[2] + " GeV}}")
    else:
        words = ana_.split("-")
        lt3.DrawLatexNDC(
            0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" +
            words[2] + " GeV}}")
    lt3.DrawLatexNDC(0.19, 0.855,
                     "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}")
    lt3.DrawLatexNDC(0.19, 0.805, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}")
    lt3.DrawLatexNDC(0.19, 0.755, "#scale[0.5]{#bf{2-prong (bq) enriched}}")
    if year_ == 2017:
        lt3.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}")
    if year_ == 2018:
        lt3.DrawLatexNDC(0.71, 0.92,
                         "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}")
    lt3.Draw()

    pad1.Update()

    #* Pad 2 *#
    pad2.cd()

    MCpassMerge.SetFillColor(0)
    MCpassMerge.SetLineColor(870)
    MCpassMerge.SetLineWidth(3)
    MCpassMerge.SetMarkerColor(870)
    MCpassMerge.SetMarkerStyle(20)
    MCpassMerge.GetYaxis().SetTitle("Fraction")
    MCpassMerge.GetYaxis().SetTitleSize(0.09)
    MCpassMerge.GetYaxis().SetLabelSize(0.1)
    MCpassMerge.GetYaxis().SetNdivisions(404)
    MCpassMerge.SetMaximum(0.3)
    MCpassMerge.SetMinimum(0.0)
    MCpassMerge.GetXaxis().SetTitle("")
    MCpassMerge.GetXaxis().SetLabelOffset(0.02)
    MCpassMerge.GetXaxis().SetLabelSize(0.09)
    MCpassMerge.GetXaxis().SetNdivisions(104)
    MCpassMerge.GetXaxis().ChangeLabel(2, -1, -1, -1, -1, -1, "Pass")
    MCpassMerge.GetXaxis().ChangeLabel(1, -1, 0)
    MCpassMerge.GetXaxis().ChangeLabel(-1, -1, 0)

    datapassMerge.SetFillColor(0)
    datapassMerge.SetLineColor(1)
    datapassMerge.SetLineWidth(2)
    datapassMerge.SetMarkerColor(1)
    datapassMerge.SetMarkerStyle(20)

    MCpassMerge.Draw("e1")
    datapassMerge.Draw("e1histsame")

    #* Pad 3 *#
    pad3.cd()

    SF = sfMerge.Integral()
    print "******"
    print "mistag SF:", SF

    SFfinal = round(SF, 3)
    SFtext = "SF = " + str(SFfinal)

    mistagSFmax = SF + 0.2
    mistagSFmin = SF - 0.2

    sfMerge.SetLineColor(797)
    sfMerge.SetMarkerColor(797)
    sfMerge.SetLineWidth(3)
    sfMerge.SetMaximum(mistagSFmax)
    sfMerge.SetMinimum(mistagSFmin)
    sfMerge.GetXaxis().SetTitle(" ")
    sfMerge.GetXaxis().SetLabelOffset(999)
    sfMerge.GetXaxis().SetLabelSize(0)
    sfMerge.GetXaxis().SetTickLength(0)
    sfMerge.GetYaxis().SetLabelSize(0.1)
    sfMerge.GetYaxis().SetNdivisions(404)
    sfMerge.GetYaxis().SetTitle(" ")

    sfMerge.Draw("e1hist")

    pt = TPaveText(0.21, 0.72, 0.31, 0.8, "brNDC")
    pt.SetBorderSize(0)
    pt.SetTextAlign(12)
    pt.SetFillStyle(0)
    pt.SetTextFont(42)
    pt.SetTextSize(0.1)
    pt.AddText(SFtext)
    pt.Draw()

    c3.SaveAs(dir + "Merge_SF.pdf")  #

    passedBfrSubtactDataMerge = (passedTopEdataBfrSubtract +
                                 passedTopMudataBfrSubtract).Integral()
    failedBfrSubtractDataMerge = (failedTopEdataBfrSubtract +
                                  failedTopMudataBfrSubtract).Integral()

    passbackground = (wjetsTopEpassed + wjetsTopMupassed + dibosonTopEpassed +
                      dibosonTopMupassed + stTopEpassed +
                      stTopMupassed).Integral()
    failbackground = (wjetsTopEfailed + wjetsTopMufailed + dibosonTopEfailed +
                      dibosonTopMufailed + stTopEfailed +
                      stTopMufailed).Integral()
    totalbackground = (wjetsMerge + dibosonMerge + stMerge).Integral()

    #get the statistical uncertainty#

    dx = ttData_error[1]
    print "data efficiency error", dx

    dy = ttMC_error[1]
    print "MC efficiency error", dy

    x = datapassMerge.Integral()
    y = MCpassMerge.Integral()

    statUnc = TMath.Sqrt(((dx**2) / (y**2)) + ((x**2) * (dy**2) / (y**4)))
    #print "statistical Uncertainty in Top (e+muon) CR", statUnc
    #print " "
    print "relative statistical Uncertainty in Top (e+muon) CR", statUnc / SF * 100, " %"
    print " "

    print "DDB Mistag SF and stat: ", round(SF, 3), " +- ", round(statUnc,
                                                                  3), " (stat)"
    #print "theoretical statistical uncertainty of data efficiency", TMath.Sqrt((x*(1-x))/(subtractedDataMerge.Integral()))
    #print "theoretical statistical uncertainty of MC efficiency", TMath.Sqrt((y*(1-y))/(totalMCmerge.Integral()))
    #print " "

    header = ["Process", "Number of Events", "Top (e+muon)"]
    row1 = [
        " ", "DDB mistag SF",
        str(SFfinal) + " +- " + str(round(statUnc, 3)) + " (stat)"
    ]
    row2 = ["tt MC", "Pass (not normalized)", ""]
    row3 = [
        " ", "Pass (normalized)",
        str(round(passMCsubtractMerge.Integral(), 2))
    ]
    row4 = [" ", "Fail (not normalized)", ""]
    row5 = [
        " ", "Fail (normalized)",
        str(round(failMCsubtractMerge.Integral(), 2))
    ]
    row6 = [" ", "Total (not normalized)", ""]
    row7 = [" ", "Total (normalized)", str(round(totalMCmerge.Integral(), 2))]

    inforMC = [row2, row3, row4, row5, row6, row7]

    row8 = [
        "tt DATA", "Pass (before subtraction)",
        str(round(passedBfrSubtactDataMerge, 2))
    ]
    row9 = [" ", "Pass (after subtraction)", str(round(passdata, 2))]
    row10 = [
        " ", "Fail (before subtraction)",
        str(round(failedBfrSubtractDataMerge, 2))
    ]
    row11 = [" ", "Fail (after subtraction)", str(round(faildata, 2))]
    row12 = [
        " ", "Total (before subtraction)",
        str(round(unsubtractedDataMerge.Integral(), 2))
    ]
    row13 = [" ", "Total (after subtraction)", str(round(totaldata, 2))]

    inforDATA = [row8, row9, row10, row11, row12, row13]

    row14 = ["Background", "Pass (normalized)", str(round(passbackground, 2))]
    row15 = [" ", "Fail (normalized)", str(round(failbackground, 2))]
    row16 = [" ", "Total (normalized)", str(round(totalbackground, 2))]

    inforBKG = [row14, row15, row16]

    DDB_mistagSF.makeTable(header, row1, inforMC, inforDATA, inforBKG)
예제 #4
0
def SAME3VsLumi(g1, g2, g3, title, ptype, lineMC1, lineDATA1, lineMC2, lineDATA2, lineMC3, lineDATA3, DoInclusive, dataPeriod):
    canvas = makeCMSCanvas(str(random.random()),"canvas",900,700)
    canvas.cd()
    graph2=copy.deepcopy(g2)
    graph3=copy.deepcopy(g3)
    graph2.SetMarkerColor(kBlue)#electrons
    graph3.SetMarkerColor(kRed)#muons
    multigraph = TMultiGraph()
    if(DoInclusive):
        graph1=copy.deepcopy(g1)
        multigraph.Add(graph1,"AP")
    multigraph.Add(graph2,"AP")
    multigraph.Add(graph3,"AP")
    multigraph.Draw("AP")
    TGaxis.SetMaxDigits(2)
    TGaxis.SetExponentOffset(-0.05, 0.02, "y")
    multigraph.GetXaxis().SetTitle("L [fb^{-1}]")
    multigraph.GetYaxis().SetTitleOffset(1.4)
    if(ptype == "Zmass"):
        multigraph.GetYaxis().SetTitle("M_{Z} [GeV]")
        # multigraph.GetYaxis().SetTitle("M_{l^{+}l^{-}} [GeV]")
        multigraph.SetMaximum(max(multigraph.GetHistogram().GetMaximum(),91.4))
        multigraph.SetMinimum(min(multigraph.GetHistogram().GetMinimum(),89.6))
    elif(ptype == "Zwidth"):
        multigraph.GetYaxis().SetTitle("#Gamma_{Z} [GeV]")
    elif(ptype == "Zmult"):
        multigraph.GetYaxis().SetTitle("#Z / fb^{-1}")
        if(not DoInclusive) :
            multigraph.SetMaximum(max(multigraph.GetHistogram().GetMaximum(),60000.)) # set y axis minimum at 60000.
            multigraph.SetMinimum(0.)     # set y axis minimum at 0. 
            # multigraph.SetMaximum(60000.)  #second type: vs 2016 plots 
            # multigraph.SetMinimum(25000.)      
    printLumiPrelOut(canvas)

    
    # Draw legend 
    legend = TLegend(0.93,0.84,0.99,0.93)
    if(DoInclusive):
        #legend.AddEntry(graph1,"inclusive","P")
        legend.AddEntry(graph1,"BB","P")
        legend.AddEntry(graph2,"BE","P")
        legend.AddEntry(graph3,"EE","P")
    else :
        legend.AddEntry(graph2,"e^{+}e^{-}","P")
        legend.AddEntry(graph3,"#mu^{+}#mu^{-}","P")
    legend.SetFillColor(kWhite)
    legend.SetLineColor(kBlack)
    legend.SetTextFont(43)
    legend.SetTextSize(20)
    legend.Draw()
    canvas.Update()

    
    # Draw letters for data-taking periods
    if(dataPeriod == "data2017"):
        textLetters = TLatex()
        textLetters.SetTextColor(kGray+1)
        textLetters.SetTextSize(0.03)
        if(ptype == "Zmass"):
            textLetters.DrawLatex(2.,  gPad.GetUymin()+0.2,"B")
            textLetters.DrawLatex(9.5, gPad.GetUymin()+0.2,"C")
            textLetters.DrawLatex(16., gPad.GetUymin()+0.2,"D")
            textLetters.DrawLatex(23., gPad.GetUymin()+0.2,"E")
            textLetters.DrawLatex(36., gPad.GetUymin()+0.2,"F")
        elif(ptype == "Zwidth"):
            textLetters.DrawLatex(2.,  gPad.GetUymin()+0.3,"B")
            textLetters.DrawLatex(9.5, gPad.GetUymin()+0.3,"C")
            textLetters.DrawLatex(16., gPad.GetUymin()+0.3,"D")
            textLetters.DrawLatex(23., gPad.GetUymin()+0.3,"E")
            textLetters.DrawLatex(36., gPad.GetUymin()+0.3,"F")
        elif(ptype == "Zmult") :
            textLetters.DrawLatex(2.,  260000,"B")
            textLetters.DrawLatex(9.5, 260000,"C")
            textLetters.DrawLatex(16., 260000,"D")
            textLetters.DrawLatex(23., 260000,"E")
            textLetters.DrawLatex(36., 260000,"F")

    if(dataPeriod == "data2018"):
        textLetters = TLatex()
        textLetters.SetTextColor(kGray+1)
        textLetters.SetTextSize(0.03)
        if(ptype == "Zmass"):
            textLetters.DrawLatex(6.,  gPad.GetUymin() + 0.6,"A")
            textLetters.DrawLatex(16., gPad.GetUymin() + 0.6,"B")
            textLetters.DrawLatex(23., gPad.GetUymin() + 0.6,"C")
            textLetters.DrawLatex(43., gPad.GetUymin() + 0.6,"D")
        elif(ptype == "Zwidth"):
            textLetters.DrawLatex(6.,  gPad.GetUymin() +0.3,"A")
            textLetters.DrawLatex(16., gPad.GetUymin() +0.3,"B")
            textLetters.DrawLatex(23., gPad.GetUymin() +0.3,"C")
            textLetters.DrawLatex(43., gPad.GetUymin() +0.3,"D")
        elif(ptype == "Zmult") :
            textLetters.DrawLatex(6.,  260000,"A")
            textLetters.DrawLatex(16., 260000,"B")
            textLetters.DrawLatex(23., 260000,"C")
            textLetters.DrawLatex(43., 260000,"D")

    
    # ****
    if(dataPeriod == "data2018"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineA = TLine(13.48, down, 13.48, up) # Run2018A up to 13.48 fb-1
        lineA.SetLineColor(kBlack)
        lineA.SetLineStyle(2)
        lineA.Draw()    
        
        lineB = TLine(20.265, down, 20.265, up) # Run2018B up to 20.265 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()
        
        lineC = TLine(26.877, down, 26.877, up) # Run2018C up to 26.877 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw()
        

    if(dataPeriod == "data2017"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineB = TLine(4.793, down, 4.793, up) # Run2017B up to 4.793 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()    
        
        lineC = TLine(14.549, down, 14.549, up) # Run2017C up to 14.549 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw()
        
        lineD = TLine(18.868, down, 18.868, up) # Run2017D up to 18.868 fb-1
        lineD.SetLineColor(kBlack)
        lineD.SetLineStyle(2)
        lineD.Draw()
        
        lineE = TLine(28.293, down, 28.293, up) # Run2017E up to 28.293 fb-1
        lineE.SetLineColor(kBlack)
        lineE.SetLineStyle(2)
        lineE.Draw()

    if(dataPeriod == "data2016"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineB = TLine(5.789, down, 5.789, up) # Run2016B up to 5.789 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()
        
        lineC = TLine(8.366, down, 8.366, up) # Run2016C up to 8.366 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw() 
        
        lineD = TLine(12.616, down, 12.616, up) # Run2016D up to 12.616 fb-1
        lineD.SetLineColor(kBlack)
        lineD.SetLineStyle(2)
        lineD.Draw()    
        
        lineE = TLine(16.624, down, 16.624, up) # Run2016E up to 16.624 fb-1
        lineE.SetLineColor(kBlack)
        lineE.SetLineStyle(2)
        lineE.Draw()    
        
        lineF = TLine(19.725, down, 19.725, up) # Run2016F up to 19.725 fb-1
        lineF.SetLineColor(kBlack)
        lineF.SetLineStyle(2)
        lineF.Draw()    
        
        lineG = TLine(27.268, down, 27.268, up) # Run2016G up to 27.268 fb-1
        lineG.SetLineColor(kBlack)
        lineG.SetLineStyle(2)
        lineG.Draw()       
    # ****
    
    # draw orizontal lines for MC and DATA fit
    if(ptype == "Zmass" or ptype == "Zwidth") :

        leftEnd  = gPad.GetUxmin()
        rightEnd = gPad.GetUxmax()

        if(DoInclusive):
            line1 = TLine(leftEnd,lineMC1,rightEnd,lineMC1)
            line1.SetLineColor(kBlack)
            line1.SetLineStyle(1) 
            line1.Draw()

            line2 = TLine(leftEnd,lineDATA1,rightEnd,lineDATA1)
            line2.SetLineColor(kBlack)
            line2.SetLineStyle(2)
            line2.Draw()
        
        # line for graph 2: color blue
        line3 = TLine(leftEnd,lineMC2,rightEnd,lineMC2)
        line3.SetLineColor(kBlue)
        line3.SetLineStyle(1) 
        line3.Draw()

        line4 = TLine(leftEnd,lineDATA2,rightEnd,lineDATA2)
        line4.SetLineColor(kBlue)
        line4.SetLineStyle(2)
        line4.Draw()
    
        # line for graph 3: color red
        line5 = TLine(leftEnd,lineMC3,rightEnd,lineMC3)
        line5.SetLineColor(kRed)
        line5.SetLineStyle(1) 
        line5.Draw()

        line6 = TLine(leftEnd,lineDATA3,rightEnd,lineDATA3)
        line6.SetLineColor(kRed)
        line6.SetLineStyle(2)
        line6.Draw()
    # ***    

    canvas.SaveAs(title + ".root")
    canvas.SaveAs(title + ".pdf")
    canvas.SaveAs(title + ".png")
    return;
예제 #5
0
def SAME2VsLumi(g1, g2,title, ptype, dataPeriod):
    canvas = makeCMSCanvas(str(random.random()),"canvas",900,700)
    canvas.cd()
    graph1=copy.deepcopy(g1)
    graph2=copy.deepcopy(g2)
    graph1.SetMarkerColor(kBlue)#electrons
    graph2.SetMarkerColor(kRed)#muons
    multigraph = TMultiGraph()
    multigraph.Add(graph1,"AP")
    multigraph.Add(graph2,"AP")
    multigraph.Draw("AP")
    TGaxis.SetMaxDigits(2)
    TGaxis.SetExponentOffset(-0.06, 0.02, "y")
    multigraph.GetXaxis().SetTitle("L [fb^{-1}]")
    multigraph.GetYaxis().SetTitleOffset(1.4)
    if(ptype == "ISO"):
        multigraph.GetYaxis().SetTitle("Isolation")
        gPad.Modified()
        multigraph.SetMinimum(0.5*gPad.GetUymin())
        multigraph.SetMaximum(1.5*gPad.GetUymax())
    elif(ptype == "SIP"):
        multigraph.GetYaxis().SetTitle("SIP")
        multigraph.SetMinimum(min(multigraph.GetHistogram().GetMinimum(),1.))
        multigraph.SetMaximum(max(multigraph.GetHistogram().GetMinimum(),2.2))

        min(multigraph.GetHistogram().GetMinimum(),1.)
    printLumiPrelOut(canvas)

    
    # Draw legend 
    legend = TLegend(0.93,0.84,0.99,0.93)
    legend.AddEntry(graph1,"e^{+}e^{-}","P")
    legend.AddEntry(graph2,"#mu^{+}#mu^{-}","P")
    legend.SetFillColor(kWhite)
    legend.SetLineColor(kBlack)
    legend.SetTextFont(43)
    legend.SetTextSize(20)
    legend.Draw()
    canvas.Update()

    

    # Draw letters for data-taking periods
    if(dataPeriod == "data2017"):
        textLetters = TLatex()
        textLetters.SetTextColor(kGray+1)
        textLetters.SetTextSize(0.03)
        if(ptype == "ISO"):
            textLetters.DrawLatex(2.,  0.8*gPad.GetUymax(),"B")
            textLetters.DrawLatex(9.5, 0.8*gPad.GetUymax(),"C")
            textLetters.DrawLatex(16., 0.8*gPad.GetUymax(),"D")
            textLetters.DrawLatex(23., 0.8*gPad.GetUymax(),"E")
            textLetters.DrawLatex(36., 0.8*gPad.GetUymax(),"F")
        elif(ptype == "SIP"):
            textLetters.DrawLatex(2.,  1.5,"B")    
            textLetters.DrawLatex(9.5, 1.5,"C")
            textLetters.DrawLatex(16., 1.5,"D")
            textLetters.DrawLatex(23., 1.5,"E")
            textLetters.DrawLatex(36., 1.5,"F")

    if(dataPeriod == "data2018"):
        textLetters = TLatex()
        textLetters.SetTextColor(kGray+1)
        textLetters.SetTextSize(0.03)
        if(ptype == "ISO"):
            textLetters.DrawLatex(6.,   0.8*gPad.GetUymax(), "A")
            textLetters.DrawLatex(16.,  0.8*gPad.GetUymax(), "B")
            textLetters.DrawLatex(23.,  0.8*gPad.GetUymax(), "C")
            textLetters.DrawLatex(43.,  0.8*gPad.GetUymax(), "D")
        elif(ptype == "SIP"):
            textLetters.DrawLatex(6.,  1.5, "A")    
            textLetters.DrawLatex(16., 1.5, "B")
            textLetters.DrawLatex(23., 1.5, "C")
            textLetters.DrawLatex(43., 1.5, "D")
         


    # ****
    if(dataPeriod == "data2018"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineA = TLine(13.48, down, 13.48, up) # Run2018A up to 13.48 fb-1
        lineA.SetLineColor(kBlack)
        lineA.SetLineStyle(2)
        lineA.Draw()
        
        lineB = TLine(20.265, down, 20.265, up) # Run2018B up to 20.265 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()
        
        lineC = TLine(26.877, down, 26.877, up) # Run2018C up to 26.877 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw()
        
    # ****
    if(dataPeriod == "data2017"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineB = TLine(4.793, down, 4.793, up) # Run2017B up to 4.793 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()
        
        lineC = TLine(14.549, down, 14.549, up) # Run2017C up to 14.549 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw()
        
        lineD = TLine(18.868, down, 18.868, up) # Run2017D up to 18.868 fb-1
        lineD.SetLineColor(kBlack)
        lineD.SetLineStyle(2)
        lineD.Draw()
        
        lineE = TLine(28.293, down, 28.293, up) # Run2017E up to 28.293 fb-1
        lineE.SetLineColor(kBlack)
        lineE.SetLineStyle(2)
        lineE.Draw()
    
    # ****
    if(dataPeriod == "data2016"):
        # draw vertical lines that divide different data taking periods
        down    = gPad.GetUymin()
        up      = gPad.GetUymax()
        
        lineB = TLine(5.789, down, 5.789, up) # Run2016B up to 5.789 fb-1
        lineB.SetLineColor(kBlack)
        lineB.SetLineStyle(2)
        lineB.Draw()
        
        lineC = TLine(8.366, down, 8.366, up) # Run2016C up to 8.366 fb-1
        lineC.SetLineColor(kBlack)
        lineC.SetLineStyle(2)
        lineC.Draw() 
        
        lineD = TLine(12.616, down, 12.616, up) # Run2016D up to 12.616 fb-1
        lineD.SetLineColor(kBlack)
        lineD.SetLineStyle(2)
        lineD.Draw()    
        
        lineE = TLine(16.624, down, 16.624, up) # Run2016E up to 16.624 fb-1
        lineE.SetLineColor(kBlack)
        lineE.SetLineStyle(2)
        lineE.Draw()    
        
        lineF = TLine(19.725, down, 19.725, up) # Run2016F up to 19.725 fb-1
        lineF.SetLineColor(kBlack)
        lineF.SetLineStyle(2)
        lineF.Draw()    
        
        lineG = TLine(27.268, down, 27.268, up) # Run2016G up to 27.268 fb-1
        lineG.SetLineColor(kBlack)
        lineG.SetLineStyle(2)
        lineG.Draw()       
    # ****
    

    canvas.SaveAs(title + ".root")
    canvas.SaveAs(title + ".pdf")
    canvas.SaveAs(title + ".png")
    return;
예제 #6
0
    ymax = max(ymax, this_ymax)
    ymin = min(ymin, this_ymin)
    #if args.glob: 
    #    thisGraph.RemovePoint(thisGraph.GetN()-1)
    #    thisFunc.SetRange(150, 1700)
    mg.Add(thisGraph)


mg.GetYaxis().SetTitle("#sigma(#Delta t) [ns]")
mg.GetXaxis().SetTitle("A_{eff}")
mg.Draw("ap")

xmin = 120
xmax = 3000
#if args.glob: xmax = 1800 
mg.GetHistogram().SetMinimum(ymin)
mg.GetHistogram().SetMaximum(ymax+ymax/4)

if args.logx: 
    c.SetLogx(1)
    mg.GetXaxis().SetLimits(xmin, xmax)
if args.logy: 
    c.SetLogy(1)
    mg.GetHistogram().SetMinimum(ymin)
    mg.GetHistogram().SetMaximum(ymax*2)
    mg.GetYaxis().SetMoreLogLabels()
    mg.GetYaxis().SetTitleOffset(1.9)
legend.SetBorderSize(0)
legend.SetTextSize(0.03)
legend.Draw("same")
c.SetGrid()
예제 #7
0
label.SetTextSize(0.05)
label.SetTextColor(1)

out_name = 'comp_simulation_elastic_to_rad_elastic.pdf'
can = TCanvas('can', 'can', 1800, 600)
can.Print('{}['.format(out_name))
can.Divide(3, 2)
for ii in range(1, 7):
    can.cd(ii)
    ss = ii - 1
    mg = TMultiGraph()
    mg.Add(g_elas[ss])
    mg.Add(g_rf[ss])
    mg.Add(g_rc[ss])
    mg.Draw('AP')
    mg.GetHistogram().GetXaxis().SetRangeUser(2.5, 10)
    l1 = TLine(2.5, 0.0, 10.0, 0.0)
    l1.SetLineColor(kRed)
    can.Update()
    mg.GetHistogram().SetMinimum(-0.35)
    mg.GetHistogram().SetMaximum(0.35)
    mg.Draw('AP')
    l1.Draw('same')
    label.DrawLatex(0.1, 0.925,
                    '#Delta P_{e} vs P_{e} Rad Elas. and Elas. S' + str(ii))
    label.DrawLatex(0.5, 0.015, 'P_{e} (GeV)')
    label.SetTextAngle(90)
    label.DrawLatex(0.035, 0.5, '#Delta P_{e}')
    label.SetTextAngle(0)
    trash_can.append(label)
    trash_can.append(mg)
def plot_fits_data_sim(canvas,
                       histos_sim,
                       histos_data,
                       x_range,
                       x_bin_step,
                       title_formatter,
                       save_name,
                       label,
                       y_fit_range,
                       y_range=None,
                       title=None,
                       xtitle=None,
                       ytitle=None,
                       hline=None,
                       output_txt=None,
                       start_range=1,
                       end_range=7,
                       manual_fit_par=None,
                       xshift=False):

    canvas.Clear()
    canvas.Divide(3, 2)
    root_is_dumb = []

    #add can shift if starting at non traditional value of 1.
    can_shift = 0
    if start_range < 0: can_shift = -start_range + 1
    if start_range == 0: can_shift = 1
    print(' need to shift canvas by {}'.format(can_shift))

    for i in range(start_range, end_range):  #len(histos)):
        canvas.cd(i + can_shift)

        title_temp = title_formatter.format(i)
        graph_sim, slices_sim, fits_sim = fit_slices(
            histos_sim.get(title_temp, default_histo2d), x_range, x_bin_step,
            y_fit_range, True, 'sim')
        graph_sim.SetMarkerStyle(8)
        graph_sim.SetMarkerSize(1)
        graph_sim.SetMarkerColor(kRed)

        graph_data, slices_data, fits_data = fit_slices(
            histos_data.get(title_temp, default_histo2d), x_range, x_bin_step,
            y_fit_range, False, 'data')
        graph_data.SetMarkerStyle(9)
        graph_data.SetMarkerSize(1)
        graph_data.SetMarkerColor(kBlack)

        multi_graph_data_sim = TMultiGraph()
        multi_graph_data_sim.Add(graph_data)
        multi_graph_data_sim.Add(graph_sim)
        multi_graph_data_sim.Draw('AP')
        multi_graph_data_sim.GetHistogram().GetXaxis().SetRangeUser(
            x_range[0], x_range[1])
        can.Update()

        if y_range:
            multi_graph_data_sim.GetHistogram().SetMinimum(y_range[0])
            multi_graph_data_sim.GetHistogram().SetMaximum(y_range[1])
            multi_graph_data_sim.Draw('AP')
            root_is_dumb.append(multi_graph_data_sim)
        else:
            multi_graph_data_sim.Draw('AP')
            root_is_dumb.append(multi_graph_data_sim)

        if hline:
            line = TLine(x_range[0], hline, x_range[1], hline)
            line.SetLineStyle(8)
            line.SetLineWidth(2)
            line.SetLineColor(kRed)
            line.Draw()
            root_is_dumb.append(line)

        if title:
            multi_graph_data_sim.SetTitle("")
            label.DrawLatex(0.1, 0.925, title + str(i))

        if xtitle:
            label.DrawLatex(0.5, 0.015, xtitle)

        if ytitle:
            label.SetTextAngle(90)
            label.DrawLatex(0.035, 0.5, ytitle)
            label.SetTextAngle(0)

    canvas.Print(save_name)

    # For the slices
    slice_can = TCanvas('slice_can', 'slice_can', 1200, 1600)
    slice_pdfname = title_formatter.split('_{}')[0] + '_slices.pdf'
    slice_can.Print(slice_pdfname + '[')
    for i in range(start_range, end_range):  #usually 1,7
        title = title_formatter.format(i)
        graph_sim, slices_sim, fits_sim, = fit_slices(
            histos_sim.get(title, default_histo2d), x_range, x_bin_step,
            y_fit_range, xshift, 'sim')

        # Size of slices page
        nrows = 5
        ncols = int(np.ceil(len(slices_sim) / nrows) + 1)
        slice_can.Clear()
        slice_can.Divide(ncols, nrows)
        for j, (s, f) in enumerate(zip(slices_sim, fits_sim)):
            slice_can.cd(j + 1)
            s.Draw()
            lab.DrawLatex(
                0.15, 0.84, '#mu = {0:6.4f}, #sigma = {1:6.4f}'.format(
                    f.GetParameter(1), f.GetParameter(2)))

        slice_can.Print(slice_pdfname)
    slice_can.Print(slice_pdfname + ']')
예제 #9
0
fname.append('LG1_SE5')
fname.append('LG1_SE5_2')
fname.append('LG1_SE5_3')
fname.append('LG1_SE5_4')
fname.append('LG1_SE5_NM')
fname.append('PIN1_SE5')
fname.append('PIN1_SE5_NM')

mg = TMultiGraph("mg", "")

for iFile in fname:
    g = TGraph(iFile + ".csv", "%lf,%*lf,%lf")
    g.SetMarkerStyle(8)
    g.SetMarkerSize(0.8)
    mg.Add(g)
    print g, iFile

c = TCanvas("c", "canvas", 800, 600)
c.cd()
gPad.SetLogy()
mg.SetTitle(name + ";Bias Voltage [V];Measured Current [A]"
            )  # set the graph title, x-axis title and y-axis title
mg.Draw("APL PMC PLC")  # draw all the graphs using automatic coloring
mg.GetHistogram().GetYaxis().SetRangeUser(1E-10, 0.001)
# y-axis range
#mg.GetHistogram().GetXaxis().SetRangeUser(0,150); # x-axis range
c.BuildLegend(0.4, 0.8 - 0.05 * len(fname), 0.6, 0.8, "",
              "PL")  # generate the legend and define its position and style

c.Print(name + ".pdf")
예제 #10
0
def report():
    global freed_file
    print'    HeapMonReport.report(): heapmon_file=', freed_file
    
    #findStaticHoles()
          
    tfile = TFile(freed_file, "READ")
    print "   root compression factor = ", tfile.GetCompressionFactor()
   
    mem_canvas = TCanvas("HeapMon_report", "Memory Holes Statistics", 10, 10, 800, 1034);
    mem_canvas.SetFillColor(17);
    mem_canvas.cd()
    
    pad1 = TPad("pad1","pad1",0.01,0.57,0.50,0.93,33);
    pad2 = TPad("pad2","pad2",0.51,0.57,0.99,0.93,33);
    pad3 = TPad("pad3","pad3",0.01,0.01,0.99,0.50,33);
    pad3.SetPhi(210);
    pad3.SetTheta(25);

    pad1.Draw(); pad2.Draw(); pad3.Draw();
    memTree = tfile.Get("holeTree")
    infoTree = tfile.Get("infoTree")
    mallocTree = tfile.Get("mallocTree")
    #holesm_th1i =   TH1I('holesm_th1i', 'Holes size evolution', fcount, 0, fcount)    
    #holesn_th1i =   TH1I('holesn_th1i', 'Holes number evolution', fcount, 0, fcount)  
    #total_th1i  =   TH1I('total_th1i', 'Total memory size evolution', fcount, 0, fcount)
    
    max_hole_size = memTree.GetMaximum("hole_size")
    print "    max_hole_size=", max_hole_size, "    min_hole_size", memTree.GetMinimum("hole_size")
    max_scan_number = memTree.GetMaximum("scan_number")
    print "     max_scan_number=", max_scan_number
    
    memHist1  = TH2I("mem2d","Hole-sizes distribution evolution", 128, -0.5, max_hole_size - 0.5, 50, 0, max_scan_number) 
    memTree.Project("mem2d", "scan_number:hole_size"); 
    
    multiGraph1 = TMultiGraph();
    multiGraph2 = TMultiGraph();

    print " memHist.GetMaximum() = ",    memHist1.GetMaximum();
    
    # Working on a Report
    gStyle.SetOptStat(0);
    gStyle.SetPalette(1);
    gStyle.SetCanvasColor(33);
    gStyle.SetFrameFillColor(18);
    
    memHist1.SetFillColor(30);
    memHist1.SetFillStyle(0);
    memHist1.GetXaxis().SetTitle("Size of holes, kb");
    memHist1.GetXaxis().SetLabelOffset(0.02);
    memHist1.GetXaxis().SetLabelSize(0.02);
    memHist1.GetXaxis().SetTitleSize(0.04);
    memHist1.GetXaxis().SetTitleColor(2);
    memHist1.GetYaxis().SetTitle("Event number");
    memHist1.GetYaxis().SetLabelSize(0.04);
    memHist1.GetXaxis().SetLabelOffset(0.04);
    memHist1.GetYaxis().SetTitleSize(0.04);
    memHist1.GetYaxis().SetTitleColor(2);
    memHist1.GetZaxis().SetTitle("Number of holes");
    memHist1.GetZaxis().SetLabelSize(0.02);
    memHist1.GetZaxis().SetTitleSize(0.04);
    memHist1.GetZaxis().SetTitleColor(2);
    
    title = TPaveLabel(0.1,0.95,0.9,0.99, "Job Memory Usage Plots");
    title.SetFillColor(42);
    title.SetTextFont(42);
    title.Draw();
    
    text_box = TPaveText(0.1,0.51,0.9,0.54);
    text_box.AddText("Malloc freed ('marked') Heap Memory Profile");
    text_box.SetFillColor(42);
    text_box.SetTextAlign(12);
    text_box.SetTextFont(42);
    text_box.Draw();
    
    x1=0.2; y1=0.91; x2=0.8; y2=0.98;

#Drawing upper-left corner Pad1 of the report
    pad1.cd();
    pad1.SetGridx();pad1.SetGridy();
    infoTree.Draw("total_maps_memory:scan_number","", "goff")
    mapsGraph=TGraph(int(infoTree.GetSelectedRows()), infoTree.GetV2(), infoTree.GetV1());    
    mapsGraph.SetLineColor(1); mapsGraph.SetLineWidth(1); #mapsGraph.SetFillStyle(3001); mapsGraph.SetFillColor(2);
    mapsGraph.SetName("total_maps_memory");
    #VmSize, VmLck, VmRSS, VmData, VmStk, VmExe, VmLib;
    infoTree.Draw("VmSize:scan_number", "","goff"); 
    vmsizeGraph=TGraph(int(infoTree.GetSelectedRows()), infoTree.GetV2(), infoTree.GetV1());    
    vmsizeGraph.SetLineColor(2); vmsizeGraph.SetLineWidth(1); #vmsizeGraph.SetFillStyle(3002); vmsizeGraph.SetFillColor(3);
    vmsizeGraph.SetName("VmSize");
    
    infoTree.Draw("VmRSS:scan_number", "", "goff"); 
    vmrssGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmrssGraph.SetLineColor(3); vmrssGraph.SetLineWidth(1); #vmrssGraph.SetFillStyle(3003); vmrssGraph.SetFillColor(4);
    vmrssGraph.SetName("VmRSS"); 
    
    infoTree.Draw("VmData:scan_number", "", "goff"); 
    vmdataGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmdataGraph.SetLineColor(4); vmdataGraph.SetLineWidth(1); #vmdataGraph.SetFillStyle(3004); vmdataGraph.SetFillColor(4);
    vmdataGraph.SetName("VmData"); 
    
    infoTree.Draw("VmStk:scan_number", "", "goff"); 
    vmstkGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmstkGraph.SetLineColor(5); vmstkGraph.SetLineWidth(1); #vmstkGraph.SetFillStyle(3005); vmstkGraph.SetFillColor(4);
    vmstkGraph.SetName("VmStk")
    
    infoTree.Draw("VmExe:scan_number", "", "goff"); 
    vmexeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmexeGraph.SetLineColor(6); vmexeGraph.SetLineWidth(1); #vmexeGraph.SetFillStyle(3003); vmexeGraph.SetFillColor(4);
    vmexeGraph.SetName("VmExe");
    
    infoTree.Draw("VmLib:scan_number", "", "goff"); 
    vmlibGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmlibGraph.SetLineColor(7); vmlibGraph.SetLineWidth(1); #vmlibGraph.SetFillStyle(3003); vmlibGraph.SetFillColor(4);
    vmlibGraph.SetName("VmLib");
  
    infoTree.Draw("VmLck:scan_number", "", "goff"); 
    vmlckGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1());
    vmlckGraph.SetLineColor(8); vmlckGraph.SetLineWidth(1); #vmlckGraph.SetFillStyle(3003); vmlckGraph.SetFillColor(4);
    vmlckGraph.SetName("VmLck");

    infoTree.Draw("total_hole_memory:scan_number", "", "goff");
    holeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1())    
    holeGraph.SetLineColor(9); holeGraph.SetLineWidth(1); #holeGraph.SetFillStyle(3004); holeGraph.SetFillColor(5);
    holeGraph.SetName("HolesSize"); 
        
    mallocTree.Draw("malloc_free:scan_number", "", "goff"); 
    freeGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1())    
    freeGraph.SetLineColor(11); freeGraph.SetLineWidth(1); freeGraph.SetFillStyle(3003); freeGraph.SetFillColor(4);
    freeGraph.SetName("malloc_free");
    
    mallocTree.Draw("malloc_inuse:scan_number", "", "goff"); 
    inuseGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1())    
    inuseGraph.SetLineColor(21); inuseGraph.SetLineWidth(1); inuseGraph.SetFillStyle(3003); inuseGraph.SetFillColor(4);
    inuseGraph.SetName("malloc_inuse");

    mallocTree.Draw("malloc_sbrk:scan_number", "", "goff"); 
    sbrkGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1())    
    sbrkGraph.SetLineColor(31); sbrkGraph.SetLineWidth(1); sbrkGraph.SetFillStyle(3003); sbrkGraph.SetFillColor(4);
    sbrkGraph.SetName("malloc_sbrk");
    
    mallocTree.Draw("malloc_mmap:scan_number", "", "goff"); 
    mmapGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1())    
    mmapGraph.SetLineColor(41); mmapGraph.SetLineWidth(1); mmapGraph.SetFillStyle(3003); mmapGraph.SetFillColor(4);
    mmapGraph.SetName("malloc_mmap");
    
    pad1.cd();
    multiGraph1.Add(mapsGraph);multiGraph1.Add(vmsizeGraph);
    multiGraph1.Add(vmrssGraph);multiGraph1.Add(vmdataGraph);
    multiGraph1.Add(vmlckGraph);multiGraph1.Add(vmexeGraph);
    multiGraph1.Add(vmstkGraph);#multiGraph1.Add(vmlibGraph);
    multiGraph1.Add(inuseGraph);
    multiGraph1.Add(sbrkGraph);multiGraph1.Add(mmapGraph);
    multiGraph1.Add(holeGraph);multiGraph1.Add(freeGraph);


    
    #multiGraph1.SetTitle("PROCESS VM and Malloc MEMORY USAGE"); 
    title.DrawPaveLabel(x1,y1,x2,y2,"PROCESS VM and Malloc MEMORY USAGE","brNDC");

    multiGraph1.Draw("ALg")
    hist = multiGraph1.GetHistogram(); hist.SetXTitle("Event Number"); hist.SetYTitle("Memory, kb");
    legend1 = TLegend(0.84,0.20,0.99,0.90);
    legend1.AddEntry(mapsGraph,  "Maps",            "l");
    legend1.AddEntry(vmsizeGraph,"VmSize",          "l");
    legend1.AddEntry(vmrssGraph, "VmRSS",           "l");
    legend1.AddEntry(vmdataGraph,"VmData",          "l");

    legend1.AddEntry(sbrkGraph,  "MallocSbrk",      "l");
    legend1.AddEntry(inuseGraph, "MallocInuse",     "l");    
    #legend1.AddEntry(vmlibGraph, "VmLib",          "l");
    legend1.AddEntry(mmapGraph,  "MallocMmap",      "l");    
    legend1.AddEntry(freeGraph,  "MallocFree",      "l");
    legend1.AddEntry(holeGraph,  "Freed-Holes",     "l");     
    legend1.AddEntry(vmstkGraph, "VmStk",           "l");
    legend1.AddEntry(vmexeGraph, "VmExe",           "l");
    legend1.AddEntry(vmlckGraph, "VmLck",           "l");
    legend1.Draw();

    #multiGraph1.Draw("ALg")    
    #title.DrawPaveLabel(x1,y1,x2,y2,"Process Memory Usage Charts","brNDC");
    
    
#Drawing upper-left corner Pad1 of the report
    pad2.cd();
    pad2.SetGridx(); pad2.SetGridy();

    infoTree.Draw("total_hole_memory:scan_number", "", "goff");
    holeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1())    
    holeGraph.SetLineColor(9); holeGraph.SetLineWidth(1); holeGraph.SetFillStyle(3004); holeGraph.SetFillColor(5);
    holeGraph.SetName("total_hole_memory"); 

    mallocTree.Draw("malloc_free:scan_number", "", "goff");
    freeGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1())    
    freeGraph.SetLineColor(11); freeGraph.SetLineWidth(1); freeGraph.SetFillStyle(3004); freeGraph.SetFillColor(5);
    freeGraph.SetName("malloc_free");
    
    pad2.cd();
    multiGraph2.Add(holeGraph);
    multiGraph2.Add(freeGraph);
    #multiGraph2.Add(sbrkGraph);
    #multiGraph2.Add(mmapGraph);
    
    #multiGraph2.SetTitle("Free and Marked Holes Memory Graph"); 
    title.DrawPaveLabel(x1,y1,x2,y2,"Malloc Free and Marked Holes Memory","brNDC");
    
    multiGraph2.Draw("ALg")    
    hist = multiGraph2.GetHistogram(); hist.SetXTitle("Event Number"); hist.SetYTitle("Memory, kb");
    
    legend2 = TLegend(0.9,0.30,0.99,0.90);
    legend2.AddEntry(freeGraph,  "Free",   "l");
    legend2.AddEntry(holeGraph,  "Holes",  "l");
    #legend2.AddEntry(inuseGraph, "Inuse",  "l");
    #legend2.AddEntry(mmapGraph,  "Mmap",  "l");
    #legend2.AddEntry(sbrkGraph,  "Sbrk",  "l");

    legend2.Draw()
    #multiGraph2.Draw("ALg")    
    #title.DrawPaveLabel(x1,y1,x2,y2,"Malloc Memory Usage and Deallocation Charts","brNDC");  
  
  #PAD3
    pad3.cd()
    pad3.SetLogz()
    memHist1.Draw("lego2");
    #title.DrawPaveLabel(x1,y1,x2,y2,"TH2I-LEGO2","brNDC");

    mem_canvas.SetBorderSize(1);
    #mem_canvas.Modified()
    mem_canvas.Update()
    mem_canvas.Print(".pdf")
    mem_canvas.Print(".C")