Ejemplo n.º 1
0
def combinedPlotNominal(files, normalize, ratio):

    files = files.split(',')
    dataFile = [file for file in files if ".data." in file][0]
    files.remove(dataFile)
    files.insert(0, dataFile)
    if any("Pythia" in file for file in files):
        pythiaFile = [file for file in files if "Pythia" in file][0]
        files.remove(pythiaFile)
        files.insert(1, pythiaFile)

    if any("Sherpa" in file for file in files):
        sherpaFile = [file for file in files if "Sherpa" in file][0]
        files.remove(sherpaFile)
        files.insert(2, sherpaFile)
    # Save output to directory of first file
    outDir = dataFile[:-5] + '/'
    if not os.path.exists(outDir):
        os.mkdir(outDir)
    if normalize:
        outDir += "combinedPlotNominal_normalized/"
    else:
        outDir += "combinedPlotNominal/"
    if not os.path.exists(outDir):
        os.mkdir(outDir)
    if not os.path.exists(outDir + '/eps'):
        os.mkdir(outDir + '/eps')
    AtlasStyle.SetAtlasStyle()

    gROOT.ProcessLine("gErrorIgnoreLevel = 2000")  #Ignore TCanvas::Print info

    inFiles = []
    nomDirs = []
    for file in files:

        inFiles.append(TFile.Open(file, "READ"))
        keyList = [key.GetName() for key in inFiles[-1].GetListOfKeys()
                   ]  #List of top level objects
        dirList = [key for key in keyList
                   if "Iteration" in key]  #List of all directories

        nomDir = [dir for dir in dirList if "Nominal" in dir]
        if (not len(nomDir) == 1):
            print "Error, nominal directories are ", nomDir
            return
        else:
            nomDirs.append(inFiles[-1].Get(nomDir[0]))

    c1 = TCanvas()

    ################ Set Color Palate ####################3
    # Data, Herwig, Pythia8, Sherpa
    colors = [kBlack, kRed, kBlue, kViolet, kCyan]
    markers = [20, 21, 23, 22, 33, 34]
    #  colorMax = 240.
    #  colorMin = 0. #20.
    #  numInputs = len( nomDirs )
    #  colors = []
    #  if len(nomDirs) == 2:
    #    colors = [kBlack, kRed]
    #  else:
    #    for iDir, nomDir in enumerate(nomDirs):
    #      colorNum = int( colorMin+(colorMax-colorMin)*iDir/numInputs)
    #      colors.append( gStyle.GetColorPalette( colorNum ))

    ##################### Plot All Nominal #################################

    print "Plotting nominal hists "
    oneLine = TF1("zl1", "1", -10000, 10000)
    oneLine.SetTitle("")
    oneLine.SetLineWidth(1)
    oneLine.SetLineStyle(2)
    oneLine.SetLineColor(kBlack)

    histList = [key.GetName() for key in nomDirs[0].GetListOfKeys()]
    for histName in histList:
        if "prof_" in histName or "ptSlice" in histName:
            continue

        tmpHist = nomDirs[0].Get(histName)
        if not type(tmpHist) == TH1F and not type(
                tmpHist) == TH1D and not type(
                    tmpHist) == TGraphErrors:  #Can't draw bands if not 1D
            continue

        leg = TLegend(0.65, 0.72, 0.9, 0.93)
        leg.SetFillStyle(0)
        leg.SetTextFont(42)
        #!    leg = TLegend(0.83, 0.15, 0.99, 0.95)
        if ratio:
            pad1 = TPad("pad1", "", 0, 0.32, 1, 1)
            pad2 = TPad("pad2", "", 0, 0, 1, 0.32)
            #!      pad1 = TPad("pad1", "", 0, 0.3, 0.83, 1)
            #!      pad2 = TPad("pad2", "", 0, 0, 0.83, 0.3)
            pad1.SetBottomMargin(0.01)
            pad2.SetTopMargin(0)
            pad2.SetBottomMargin(0.45)
            pad1.Draw()
            pad2.Draw()
        else:
            #!      pad1 = TPad("pad1", "", 0, 0, 0.83, 1)
            pad1.Draw()
        pad1.cd()

        nomHists = []
        drawString = ""
        maxVal = []
        maxBinX = []

        for iDir, nomDir in enumerate(nomDirs):
            thisFileStr = files[iDir].split('.')[2]
            if "all" in thisFileStr:
                thisFileStr = files[iDir].split('.')[1]

            nomHist = nomDir.Get(histName)
            nomHist.SetName(nomHist.GetName())
            if "Beta" in histName:
                nomHist.Rebin(2)
            if "alpha" in histName:
                nomHist.Rebin(4)
            if "ptAsym" in histName:
                nomHist.Rebin(4)

            if "Eta" in histName and not type(nomHist) == TGraphErrors:
                nomHist.Rebin(4)

            if ("recoilPt" in histName):
                for iBin in range(1, nomHist.GetNbinsX() + 1):
                    nomHist.SetBinContent(
                        iBin,
                        nomHist.GetBinContent(iBin) /
                        nomHist.GetBinWidth(iBin))

            if normalize and not type(
                    nomHist) == TGraphErrors and nomHist.Integral() > 0.:
                nomHist.Scale(1. / nomHist.Integral())

            if "Sherpa" in files[iDir] and "MJB" in histName:
                for iBin in range(31, nomHist.GetNbinsX() + 1):
                    nomHist.SetBinContent(iBin, 0)
                    nomHist.SetBinError(iBin, 0)

            nomHist.SetLineColor(colors[iDir])
            nomHist.SetMarkerColor(colors[iDir])
            nomHist.SetMarkerStyle(markers[iDir])
            thisEntry = leg.AddEntry(
                nomHist,
                thisFileStr.replace('d', 'D').replace(
                    'Sherpa', 'Sherpa 2.1').replace('Herwig', 'Herwig++'),
                "lp")
            thisEntry.SetTextColor(colors[iDir])
            #nomHist.SetMinimum(0.9)
            #      if( "jetPt" in histName or "jetEnergy" in histName):
            #        maxBinX.append(nomHist.FindLastBinAbove(0)+1)
            #        nomHist.SetMaximum(1.5*nomHist.GetMaximum())
            #        nomHist.SetMinimum(0.000101)
            #      else:
            nomHist.SetMaximum(1.5 * nomHist.GetMaximum())
            #nomHist.SetMinimum(0.000101)
            if ("MJB" in histName):
                nomHist.SetMinimum(0.0000101)
                #nomHist.GetXaxis().SetRangeUser( 500, 2800 ) #!!public
                #nomHist.SetMaximum(1.06) #!!public
                #nomHist.SetMinimum(0.9701) #!!public
                nomHist.GetXaxis().SetRangeUser(300, 2800)
                nomHist.SetMaximum(1.2)
                nomHist.SetMinimum(0.8999)
                nomHist.GetXaxis().SetMoreLogLabels(True)
                nomHist.GetYaxis().SetTitle(
                    "#LT p_{T}^{lead jet}/p_{T}^{recoil} #GT")
                nomHist.GetYaxis().SetTitleSize(0.09)
                nomHist.GetYaxis().SetTitleOffset(0.7)
                nomHist.GetYaxis().SetLabelSize(0.06)
                nomHist.GetYaxis().SetLabelOffset(0.01)
                nomHist.SetMarkerSize(.8)
                nomHist.SetLineWidth(1)
            elif ("Pt" in histName):
                nomHist.GetYaxis().SetTitle("AU")
                if ("jet0" in histName):
                    nomHist.GetXaxis().SetRangeUser(200, 2000)
                else:
                    nomHist.GetXaxis().SetRangeUser(0, 800)
            else:
                nomHist.GetYaxis().SetTitle("AU")
            if ("recoilPt" in histName):
                nomHist.GetYaxis().SetTitle("1/N dp_{T}^{recoil}/dN")
                nomHist.GetXaxis().SetRangeUser(300, 3000)
            if not type(nomHist) == TGraphErrors:
                #drawString = "histsamep"
                drawString = "psame"
            else:
                drawString = "apsame"
                nomHist.SetMarkerStyle(33)
                nomHist.SetMarkerSize(1.5)
                nomHist.SetLineWidth(4)

            nomHists.append(nomHist)
            maxVal.append(nomHist.GetMaximum())

        maxDir = maxVal.index(max(maxVal))
        nomHists[maxDir].Draw(drawString)
        if maxBinX:
            maxBinX = max(maxBinX)
            for iDir, nomDir in enumerate(nomDirs):
                nomHists[iDir].GetXaxis().SetRange(1, maxBinX)
        for iDir, nomDir in enumerate(nomDirs):
            nomHists[iDir].Draw(drawString)
        oneLine.Draw("same")
        for iDir, nomDir in enumerate(nomDirs):
            nomHists[iDir].Draw(drawString)
        nomHists[0].Draw(drawString)  ## Draw data on top

        if ratio:
            pad2.cd()
            ratioHists = []

            for iDir in range(1, len(nomDirs)):
                #ratioHists.append( nomHists[0].Clone() )
                #ratioHists[iDir-1].Add(nomHists[iDir], -1.)
                #ratioHists[iDir-1].Divide(nomHists[iDir])
                ratioHists.append(nomHists[iDir].Clone())
                ratioHists[iDir - 1].Divide(nomHists[0])

                ratioHists[iDir - 1].SetMarkerColor(colors[iDir])
                ratioHists[iDir - 1].SetMarkerStyle(markers[iDir])
                ratioHists[iDir - 1].SetLineColor(colors[iDir])
                if iDir == 1:
                    ratioHists[iDir - 1].SetMaximum(2)
                    ratioHists[iDir - 1].SetMinimum(0.5)
                    ratioHists[iDir - 1].GetXaxis().SetLabelOffset(.015)
                    ratioHists[iDir - 1].GetXaxis().SetTitleOffset(1.3)
                    ratioHists[iDir - 1].GetXaxis().SetLabelSize(0.13)
                    ratioHists[iDir - 1].GetXaxis().SetTitleSize(0.16)
                    #          ratioHists[iDir-1].GetXaxis().SetTitle(nomHists[0].GetXaxis().GetTitle());
                    ratioHists[iDir - 1].GetXaxis().SetMoreLogLabels()
                    ratioHists[iDir - 1].GetYaxis().SetLabelSize(0.13)
                    ratioHists[iDir - 1].GetYaxis().SetTitleSize(0.16)
                    ratioHists[iDir - 1].GetYaxis().SetLabelOffset(.01)
                    ratioHists[iDir - 1].GetYaxis().SetTitleOffset(0.37)
                    #ratioHists[iDir-1].GetYaxis().SetTitle("Significance")
                    ratioHists[iDir - 1].GetYaxis().SetTitle("   MC / Data")
                    ratioHists[iDir - 1].GetYaxis().SetNdivisions(7)
                    if ("Pt" in histName):
                        if ("jet0" in histName):
                            ratioHists[iDir - 1].GetXaxis().SetRangeUser(
                                200, 2000)
                        else:
                            ratioHists[iDir - 1].GetXaxis().SetRangeUser(
                                0, 800)
                    if ("MJB" in histName):
                        #ratioHists[iDir-1].GetXaxis().SetRangeUser( 500, 2800 ) #!!public
                        ratioHists[iDir - 1].GetXaxis().SetRangeUser(300, 2500)
                        ratioHists[iDir - 1].SetMaximum(1.05)
                        ratioHists[iDir - 1].SetMinimum(0.95)
                        ratioHists[iDir - 1].GetXaxis().SetTitle(
                            "p_{T}^{recoil} [GeV]")
                    if ("recoilPt" in histName):
                        ratioHists[iDir - 1].GetXaxis().SetRangeUser(300, 3000)
                        ratioHists[iDir - 1].GetXaxis().SetTitle(
                            "p_{T}^{recoil} [GeV]")

        #     if( "jetBeta" in histName):
        #       ratioHists[iDir-1].SetMaximum(1)
        #       ratioHists[iDir-1].SetMinimum(-1)

            ratioHists[0].Draw("p")
            oneLine.Draw("same")
            for iDir in range(1, len(nomDirs)):
                ratioHists[iDir - 1].Draw("psame")

        c1.cd()
        leg.Draw()
        AtlasStyle.ATLAS_LABEL(0.2, 0.88, 1, "    Preliminary")
        AtlasStyle.myText(0.2, 0.82, 1, "#sqrt{s} = 13 TeV, 3.3 fb^{-1}")
        AtlasStyle.myText(0.2, 0.76, 1, "Multijet Events")
        typeText = "anti-k_{t} R = 0.4"
        if "_LC_" in dataFile:
            typeText += ", LC+JES (in-situ)"
        else:
            typeText += ", EM+JES (in-situ)"
        AtlasStyle.myText(0.2, 0.7, 1, typeText)
        AtlasStyle.myText(0.2, 0.64, 1, "#left|#eta^{lead jet}#right| < 1.2")
        #    AtlasStyle.myText(0.1,0.75,1, "m_{jj} Correction")

        if "MJB" in histName:
            pad1.SetLogx()
            if ratio:
                pad2.SetLogx()
        else:
            pad1.SetLogx(0)
            if ratio:
                pad2.SetLogx(0)
        #if "Pt" in histName or "alpha" in histName:
        pad1.SetLogy()
        c1.SaveAs(outDir + nomHist.GetName() + "_logy.png")
        c1.SaveAs(outDir + "/eps/" + nomHist.GetName() + "_logy.eps")
        pad1.SetLogy(0)
        c1.SaveAs((outDir + nomHist.GetName() + ".png"))
        c1.SaveAs((outDir + "/eps/" + nomHist.GetName() + ".eps"))
        c1.SaveAs((outDir + "/eps/" + nomHist.GetName() + ".pdf"))
        c1.Clear()

    for inFile in inFiles:
        inFile.Close()
Ejemplo n.º 2
0
def make_time_rod_evo(error_dict, rod_dict, results, doLock):
 
    c2 = TCanvas( 'c2', 'c2', 1000, 600)
    leg = TLegend(0.18,0.85,0.45,0.55)
    leg.SetLineColor(0)
    leg.SetFillStyle(0)
    leg.SetShadowColor(0)
    leg.SetBorderSize(0)
    leg.SetNColumns(2)
     
    R15 = TLine(431,0,431,60)
    R15.SetLineColorAlpha(kPink+10,0.4)
    R15.SetLineWidth(4)

    R16 = TLine(1820,0,1820,60)
    R16.SetLineColorAlpha(kMagenta+10,0.4)
    R16.SetLineWidth(4)

    R17 = TLine(3376,0,3376,60)
    R17.SetLineColorAlpha(kGreen-3,0.4)
    R17.SetLineWidth(4)


    TS1 = TLine(431,0,432,60)
    TS1.SetLineColorAlpha(kPink+10,0.5)
    TS1.SetLineWidth(5)

    TS2 = TLine(1415,0,1415,60)
    TS2.SetLineColorAlpha(kMagenta+3,0.5)
    TS2.SetLineWidth(5)

    leg2 = TLegend(0.18,0.45,0.35,0.55)
    leg2.SetLineColor(0)
    leg2.SetFillStyle(0)
    leg2.SetShadowColor(0)
    leg2.SetBorderSize(0)
    gStyle.SetLegendTextSize(0.030)

    leg2.AddEntry(R15, "End of 2015", 'lf')
    leg2.AddEntry(R16, "End of 2016", 'lf')
    leg2.AddEntry(R17, "End of 2017", 'lf')
    #leg2.AddEntry(TS2, "TS2", 'lf')


    for key,val in rod_dict.items(): 
        TS1.SetY2(val*0.5)
        TS2.SetY2(val+1)

        R15.SetY2(val*0.3)
        R16.SetY2(val*0.5)
        R17.SetY2(val*0.8)

        times = {}
        times.clear()
        for e in error_bits:
            times['0x'+e] = [0] 
        for error in results:
            pos_rod  = error.text.find("ROD") + 4
            pos_lock = error.text.find("Lock") + 15
            pos_buff = error.text.find("buffer") + 17

            if error.msgID == 'TRT::ROD05Module':
                rod  = '0x'+str(error.text[pos_rod:pos_rod+6])
            else:
                rod  = str(error.text[pos_rod:pos_rod+8])

            lock = str(error.text[pos_lock:pos_lock+3])
            buff = str(error.text[pos_buff:pos_buff+3])

            if key == rod and doLock and lock != '0xf':
                times[lock].append(error.sb_total_time)


        leg.Clear()
        mg = TMultiGraph()

        for e in error_bits:
            errs = []
            for i,x in enumerate(times['0x'+e]):
                errs.append(i+0.0)
            errs.append(errs[-1])
            #times['0x'+e].append(1800.0)
            times['0x'+e].append(results[-1].sb_total_time)
            gr = TGraph(len(times['0x'+e]), array(times['0x'+e]), array(errs))
            gr.SetMarkerSize(0.7)
            if bin(int('0x'+e, 16))[2:].zfill(4) == '0111':
                leg.AddEntry(gr,'GOL 3',"lp");
            elif bin(int('0x'+e, 16))[2:].zfill(4) == '1011':
                leg.AddEntry(gr,'GOL 2',"lp");
            elif bin(int('0x'+e, 16))[2:].zfill(4) == '1101':
                leg.AddEntry(gr,'GOL 1',"lp");
            elif bin(int('0x'+e, 16))[2:].zfill(4) == '1110':
                leg.AddEntry(gr,'GOL 0',"lp");
            else:
                leg.AddEntry(gr,bin(int('0x'+e, 16))[2:].zfill(4),"lp");
            mg.Add(gr,"pl");

        mg.SetTitle("; Hours of stable beams; # of rocketio io lock errors");
        mg.Draw("PMC PLC a");
        R15.Draw()
        R16.Draw()
        R17.Draw()
        #TS1.Draw()
        #TS2.Draw()
        
        AtlasStyle.ATLAS_LABEL(0.19,.88, 1, "Internal")
        leg.Draw()
        leg2.Draw()
        AtlasStyle.myText(0.4, 0.88, kBlack, "ROD: " + key)
        
        
        leg.SetMargin(0.5)
        gPad.Modified()
        mg.GetXaxis().SetLimits(0,results[-1].sb_total_time)
        mg.SetMinimum(0.)
        mg.SetMaximum(val+1)
        c2.Update()
        c2.Print("plots/time_"+key+".pdf")
        c2.Clear()
Ejemplo n.º 3
0
def make_plot_all_rods(error_dict, rod_dict, name):
    

    leg = TLegend(0,0,0,0)
    if 'lock' in name:
        leg = TLegend(0.18,0.85,0.50,0.55)
    else:
        leg = TLegend(0.18,0.85,0.40,0.55)
    leg.SetLineColor(0)
    leg.SetFillStyle(0)
    leg.SetShadowColor(0)
    leg.SetBorderSize(0)
    leg.SetNColumns(3)
    gStyle.SetLegendTextSize(0.045)

   
    v_hists = []
    #for e,c in zip(error_bits, error_colors):
    for e in error_bits:
        h = TH1F('h'+e,'h'+e, len(rod_dict), 0, len(rod_dict))
        h.SetFillStyle(1001)
        h.SetLineWidth(0)
        v_hists.append(h)
        v_hists[-1].SetDirectory(0)
        if bin(int('0x'+e, 16))[2:].zfill(4) == '0111':
            leg.AddEntry(v_hists[-1],'GOL 3',"f");
        elif bin(int('0x'+e, 16))[2:].zfill(4) == '1011':
            leg.AddEntry(v_hists[-1],'GOL 2',"f");
        elif bin(int('0x'+e, 16))[2:].zfill(4) == '1101':
            leg.AddEntry(v_hists[-1],'GOL 1',"f");
        elif bin(int('0x'+e, 16))[2:].zfill(4) == '1110':
            leg.AddEntry(v_hists[-1],'GOL 0',"f");
        else:
            leg.AddEntry(v_hists[-1],bin(int('0x'+e, 16))[2:].zfill(4),"f");
    h = leg.GetY2()-leg.GetY1();
    w = leg.GetX2()-leg.GetX1()*.6;
    leg.SetMargin(leg.GetNColumns()*h/(leg.GetNRows()*w))
    

    for key,val in error_dict.items():
        idx_rod = 0
        for i, key2 in enumerate(rod_dict):
            if key2 == key[:8]:
                idx_rod = i
        v_hists[int(key[11:12], 16)].Fill(idx_rod, val)
  
    stack  = THStack("stack","stack")
    for hist in v_hists:
        stack.Add(hist)

    if 'buff' in name:
        c1 = TCanvas( 'c1', 'c1', 2000, 500)
    else:
        c1 = TCanvas( 'c1', 'c1', 1000, 500)


    h1 = TH1F('h_1','h_1', len(rod_dict), 0, len(rod_dict))
    for i, key in enumerate(rod_dict):
        h1.GetXaxis().SetBinLabel(i+1,key)
        h1.SetBinContent(i+1,rod_dict[key])

 
    h1.GetXaxis().LabelsOption("v")
    h1.GetXaxis().SetTitle("ROD")
    h1.GetXaxis().SetTitleOffset(2.2)
    h1.GetYaxis().SetTitle("# of rocketio errors")
    h1.SetLineColor(kRed)
    h1.SetLineWidth(1)

    leg.AddEntry(h1,'total',"l");
    
    c1.SetBottomMargin(0.23)  
    h1.GetXaxis().SetTitle("ROD")
    h1.Draw("HIST")
    stack.Draw("PFC PLC SAME HIST")
    h1.Draw("SAMEHIST")
    AtlasStyle.ATLAS_LABEL(0.19,.88, 1, "Internal")
    leg.Draw()
    c1.Update()
    c1.Print("plots/"+name +".pdf")
    c1.Clear()
Ejemplo n.º 4
0
def make_minute_plots(buff_dict, lock_dict, results):

    hl0 = TH1F('hl0','hl0', 50, 0, 1)
    hl4 = TH1F('hl4','hl4', 50, 0, 1)
    hl8 = TH1F('hl8','hl8', 50, 0, 1)
    hl8.GetXaxis().SetTitle("Fraction of fill length")
    hl8.GetYaxis().SetTitle("Arbitrary units/ 0.02")
    hb0 = TH1F('hb0','h0', 50, 0, 1)
    hb4 = TH1F('hb4','h4', 50, 0, 1)
    hb8 = TH1F('hb8','h8', 50, 0, 1)
    hb8.GetXaxis().SetTitle("Fraction of fill length")
    hb8.GetYaxis().SetTitle("Arbitrary units/ 0.02")

    change_colors_min(hl0, hl4, hl8)
    change_colors_min(hb0, hb4, hb8)


    h0_lock_beg = []
    h0_lock_end = []
    h4_lock_beg = []
    h4_lock_end = []
    h8_lock_beg = []
    h8_lock_end = []

    h0_buff_beg = []
    h0_buff_end = []
    h4_buff_beg = []
    h4_buff_end = []
    h8_buff_beg = []
    h8_buff_end = []

    for r in lock_dict:
        temp0 = TH1F('htl0'+r,'htl0'+r, 80, 0, 240)
        temp1 = TH1F('htl1'+r,'htl1'+r, 80, 0, 240)
        temp2 = TH1F('htl2'+r,'htl2'+r, 96, 0, 480)
        temp3 = TH1F('htl3'+r,'htl3'+r, 96, 0, 480)
        temp4 = TH1F('htl4'+r,'htl4'+r, 180,0, 900)
        temp5 = TH1F('htl5'+r,'htl5'+r, 180,0, 900)
        
        temp0.SetLineWidth(0)
        temp0.SetFillStyle(1001)
        temp1.SetLineWidth(0)
        temp1.SetFillStyle(1001)
        temp2.SetLineWidth(0)
        temp2.SetFillStyle(1001)
        temp3.SetLineWidth(0)
        temp3.SetFillStyle(1001)
        temp4.SetLineWidth(0)
        temp4.SetFillStyle(1001)
        temp5.SetLineWidth(0)
        temp5.SetFillStyle(1001)

        h0_lock_beg.append(temp0)
        h0_lock_end.append(temp1)
        h0_lock_beg[-1].SetDirectory(0)
        h0_lock_end[-1].SetDirectory(0)

        h4_lock_beg.append(temp2)
        h4_lock_end.append(temp3)
        h4_lock_beg[-1].SetDirectory(0)
        h4_lock_end[-1].SetDirectory(0)

        h8_lock_beg.append(temp4)
        h8_lock_end.append(temp5)
        h8_lock_beg[-1].SetDirectory(0)
        h8_lock_end[-1].SetDirectory(0)

    for r in buff_dict:
        temp0 = TH1F('htb0'+r,'htb0'+r, 80, 0, 240)
        temp1 = TH1F('htb1'+r,'htb1'+r, 80, 0, 240)
        temp2 = TH1F('htb2'+r,'htb2'+r, 96, 0, 480)
        temp3 = TH1F('htb3'+r,'htb3'+r, 96, 0, 480)
        temp4 = TH1F('htb4'+r,'htb4'+r, 180,0, 900)
        temp5 = TH1F('htb5'+r,'htb5'+r, 180,0, 900)
        
        temp0.SetLineWidth(0)
        temp0.SetFillStyle(1001)
        temp1.SetLineWidth(0)
        temp1.SetFillStyle(1001)
        temp2.SetLineWidth(0)
        temp2.SetFillStyle(1001)
        temp3.SetLineWidth(0)
        temp3.SetFillStyle(1001)
        temp4.SetLineWidth(0)
        temp4.SetFillStyle(1001)
        temp5.SetLineWidth(0)
        temp5.SetFillStyle(1001)

        h0_buff_beg.append(temp0)
        h0_buff_end.append(temp1)
        h0_buff_beg[-1].SetDirectory(0)
        h0_buff_end[-1].SetDirectory(0)

        h4_buff_beg.append(temp2)
        h4_buff_end.append(temp3)
        h4_buff_beg[-1].SetDirectory(0)
        h4_buff_end[-1].SetDirectory(0)

        h8_buff_beg.append(temp4)
        h8_buff_end.append(temp5)
        h8_buff_beg[-1].SetDirectory(0)
        h8_buff_end[-1].SetDirectory(0)

    for error in results:
        pos_rod  = error.text.find("ROD") + 4
        pos_lock = error.text.find("Lock") + 15
        pos_buff = error.text.find("buffer") + 17

        if error.msgID == 'TRT::ROD05Module':
            rod  = '0x'+str(error.text[pos_rod:pos_rod+6])
        else:
            rod  = str(error.text[pos_rod:pos_rod+8])

        lock = str(error.text[pos_lock:pos_lock+3])
        buff = str(error.text[pos_buff:pos_buff+3])

        for i,key in enumerate(lock_dict):
            if key == rod and lock != '0xf' and error.sb_length > 0.5 and error.sb == 1:
                frac = error.sb_time_run/error.sb_length
                if error.sb_length  < 4:
                    hl0.Fill(frac)
                    h0_lock_beg[i].Fill(error.sb_time_run*60)
                    h0_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
                elif error.sb_length < 8:
                    hl4.Fill(frac)
                    h4_lock_beg[i].Fill(error.sb_time_run*60)
                    h4_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
                else:       
                    hl8.Fill(frac) 
                    h8_lock_beg[i].Fill(error.sb_time_run*60)
                    h8_lock_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
        for i,key2 in enumerate(buff_dict):
           if key2 == rod and buff != '0xf' and error.sb_length > 0.5 and error.sb == 1:
               frac = error.sb_time_run/error.sb_length
               if error.sb_length  < 4:
                   hb0.Fill(frac)
                   h0_buff_beg[i].Fill(error.sb_time_run*60)
                   h0_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
               elif error.sb_length < 8:
                   hb4.Fill(frac)
                   h4_buff_beg[i].Fill(error.sb_time_run*60)
                   h4_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
               else:
                   hb8.Fill(frac) 
                   h8_buff_beg[i].Fill(error.sb_time_run*60)
                   h8_buff_end[i].Fill(error.sb_length*60 - error.sb_time_run*60)
    
    leg3 = TLegend(0.23,0.85,0.45,0.75)
    leg3.SetLineColor(0)
    leg3.SetFillStyle(0)
    leg3.SetShadowColor(0)
    leg3.SetBorderSize(0)

    leg3.AddEntry(hl0, "Fill Length: 0-4 hours", "lf")
    leg3.AddEntry(hl4, "Fill Length: 4-8 hours", "lf")
    leg3.AddEntry(hl8, "Fill Length: 8+  hours", "lf")

    c3 = TCanvas( 'c3', 'c3', 1000, 600)
    hl8.DrawNormalized("HIST",1)
    hl0.DrawNormalized("HISTSAME",1)
    hl4.DrawNormalized("HISTSAME",1)
    AtlasStyle.ATLAS_LABEL(0.24,.88, 1, "Internal")
    leg3.Draw()
    AtlasStyle.myText(0.5, 0.88, kBlack, "All RODs: lock errors")
    c3.Update()
    c3.Print("plots/frac_all_lock.pdf")
    c3.Clear()

    hb8.DrawNormalized("HIST",1)
    hb0.DrawNormalized("HISTSAME",1)
    hb4.DrawNormalized("HISTSAME",1)
    AtlasStyle.ATLAS_LABEL(0.24,.88, 1, "Internal")
    leg3.Draw()
    AtlasStyle.myText(0.5, 0.88, kBlack, "All RODs: buffer errors")
    c3.Update()
    c3.Print("plots/frac_all_buff.pdf")
   
    print_single_min(h0_lock_beg, h0_lock_end, "min_lock_0_4", "Lock errors, 0-4 hour fills")
    print_single_min(h4_lock_beg, h4_lock_end, "min_lock_4_8", "Lock errors, 4-8 hour fills")
    print_single_min(h8_lock_beg, h8_lock_end, "min_lock_8",   "Lock errors, 8+  hour fills")
    
    print_single_min(h0_buff_beg, h0_buff_end, "min_buff_0_4", "Buffer errors, 0-4 hour fills")
    print_single_min(h4_buff_beg, h4_buff_end, "min_buff_4_8", "Buffer errors, 4-8 hour fills")
    print_single_min(h8_buff_beg, h8_buff_end, "min_buff_8",   "Buffer errors, 8+  hour fills")
Ejemplo n.º 5
0
def print_single_min(vec_beg, vec_end, name, text):

    total_beg = vec_beg[0].Clone()
    c = 0
    for v in vec_beg:
        if c != 0:
            total_beg.Add(vec_beg[c])
        c = c + 1
    
    norm = 1/total_beg.Integral()
    total_beg.Scale(norm)

    if 'buff' in name:
        legb = TLegend(0.25,0.93,0.90,0.60)
        legb.SetNColumns(5)
    else:
        legb = TLegend(0.60,0.80,0.90,0.60)
        legb.SetNColumns(2)
    legb.SetLineColor(0)
    legb.SetFillStyle(0)
    legb.SetShadowColor(0)
    legb.SetBorderSize(0)

    if 'buff' in name:
        lege = TLegend(0.25,0.93,0.90,0.60)
        lege.SetNColumns(5)
    else:
        lege = TLegend(0.22,0.90,0.52,0.70)
        lege.SetNColumns(2)
    lege.SetLineColor(0)
    lege.SetFillStyle(0)
    lege.SetShadowColor(0)
    lege.SetBorderSize(0)


    #vec_beg = sorted(vec_beg, key=lambda x: x.Integral(), reverse=True)


    stack1  = THStack("stack1","stack1")
    for v in vec_beg:
        if v.Integral() != 0:
            v.Scale(norm)
            legb.AddEntry(v, v.GetTitle()[4:], "f")
            stack1.Add(v)

    total_end = vec_end[0].Clone()
    c = 0
    for v in vec_end:
        if c != 0:
            total_end.Add(vec_end[c])
        c = c + 1
    
    norm = 1/total_end.Integral()
    total_end.Scale(norm)

    stack2  = THStack("stack2","stack2")
    for v in vec_end:
        if v.Integral() != 0:
            v.Scale(norm)
            lege.AddEntry(v, v.GetTitle()[4:], "f")
            stack2.Add(v)


    total_beg.SetLineColor(kRed)
    total_beg.SetLineWidth(1)
    total_end.SetLineColor(kRed)
    total_end.SetLineWidth(1)

    total_beg.GetXaxis().SetTitle("Minutes after stable beams declared [min]")
    total_end.GetXaxis().SetTitle("Minutes before stable beams ended [min]")

    if '0_4' in name:
        total_beg.GetYaxis().SetTitle("Arbitrary units / 3 mins")
        total_end.GetYaxis().SetTitle("Arbitrary units / 3 mins")
    else:
        total_beg.GetYaxis().SetTitle("Arbitrary units / 5 mins")
        total_end.GetYaxis().SetTitle("Arbitrary units / 5 mins")

    c4 = TCanvas( 'c4', 'c4',1000, 1200)
    c4.Divide(1,2)
    c4.cd(1)
    total_beg.Draw("HIST")
    stack1.Draw("PFC PLC SAME HIST")
    total_beg.Draw("SAMEHIST")
    AtlasStyle.ATLAS_LABEL(0.18,.96, 1, "Internal")
    AtlasStyle.myText(0.40, 0.96, kBlack, text)
    legb.Draw()
    c4.cd(2)
    total_end.Draw("HIST")
    stack2.Draw("PFC PLC SAME HIST")
    total_end.Draw("SAMEHIST")
    AtlasStyle.ATLAS_LABEL(0.18,.96, 1, "Internal")
    AtlasStyle.myText(0.40, 0.96, kBlack, text)
    lege.Draw()
    c4.Update()
    c4.Print("plots/"+name+".pdf")
Ejemplo n.º 6
0
#
#    mc_effBin = h_mc_triggers[iT].FindFirstBinAbove(0.995)
####
#
#    effPt = h_triggers[iT].GetXaxis().GetBinLowEdge( effBin )

        leg = ROOT.TLegend(0.6, 0.4, 0.9, 0.9)
        leg.AddEntry(h_triggers[0], "Data " + trigger, "l")
        leg.AddEntry(h_triggers[2], "MC", "l")
        leg.AddEntry(h_triggers[4], "Biased MC", "l")

        h_triggers[0].Draw()
        h_triggers[2].Draw("same")
        h_triggers[4].Draw("same")

        AtlasStyle.ATLAS_LABEL(0.3, 0.34, 1, "  Internal")
        AtlasStyle.myText(0.3, 0.28, 1, "#sqrt{s} = 13 TeV, 3.6 fb^{-1}")
        #    AtlasStyle.myText(0.3,0.22,2, "99.5\% Efficient: %.0f GeV" %(effPt[0]) )
        AtlasStyle.myText(
            0.3, 0.22, 2, "Data: %.0f, MC: %.0f, MCbiased: %.0f GeV" %
            (effPt[0], effPt[2], effPt[4]))

        leg.Draw("same")

        plotName = upDir + '/combinedPlots/' + histName[
            0] + '_Recoil_' + trigger + '.png'
        #    plotName += h_data_triggers[iT].GetName()+'.png'
        c1.SaveAs(plotName)

        c1.Clear()
Ejemplo n.º 7
0
                            # drawing plots
                            if (NPlots == 0): histo.Draw("HIST")
                            else: histo.Draw("Same HIST")

                            c.Update()

                            # legend
                            legend.AddEntry(histo, LegendEntryList[NPlots],
                                            "l")
                            legend.Draw("Same")

                            # ATLAS Style Setting
                            AtlasStyle.ATLAS_LABEL(
                                0.5,
                                0.85,
                                internal=ATLAS_Internal,
                                preliminary=ATLAS_Preliminary,
                                color=1)
                            AtlasStyle.myText(0.5, 0.8, 1, "#sqrt{s} = 13 TeV")

                            # create ratio plots in pad2
                            if (EnableHistoCombination & EnableRatioPlots):

                                ## save reference plot, i.e. NPlots == 0
                                if (NPlots == 0):
                                    refHisto = histo

                                    ## else plot ratio histos
                                else:
                                    # change to pad2
                                    pad2.cd()
Ejemplo n.º 8
0
def plotNominal(file, f_plotSys, f_addGagik):

  outDir = file[:-5]+'/'
  if not os.path.exists(outDir):
    os.mkdir(outDir)
  outDir += "plotNominal/"
  if not os.path.exists(outDir):
    os.mkdir(outDir)
  if not os.path.exists(outDir+'/eps'):
    os.mkdir(outDir+'/eps')
  AtlasStyle.SetAtlasStyle()

  gROOT.ProcessLine("gErrorIgnoreLevel = 2000") #Ignore TCanvas::Print info

  inFile = TFile.Open(file, "READ");
  keyList = [key.GetName() for key in inFile.GetListOfKeys()] #List of top level objects
  dirList = [key for key in keyList if "Iteration" in key] #List of all directories

  #nomDir = [dir for dir in dirList if "NoCorr" in dir]
  nomDir = [dir for dir in dirList if "Nominal" in dir]
  if( not len(nomDir) == 1):
    print "Error, nominal directories are ", nomDir
    return
  else:
    nomDir = inFile.Get( nomDir[0] )

  c1 = TCanvas()



##################### Plot All Nominal With Systematic Bands  #################################

  print "Plotting nominal hists "

  if(f_plotSys):
    sysDirNameList = [dir for dir in dirList if not "Nominal" in dir]
    sysDirList = []
    for sysDirName in sysDirNameList:
      sysDirList.append( inFile.Get(sysDirName) )

    ## Combine systematics in types ##
    #sysTypes = ["MJB_a", "MJB_b", "MJB_ptt", "MJB_pta", "Flavor", "EtaIntercalibration"]
    sysTypes = ["ZJ", "GJ", "MJB", "Flavor", "EtaIntercalibration", "All"]
    if "All" in sysTypes:
      colorOffset = 240./(len(sysTypes)-1)
    else:
      colorOffset = 240./len(sysTypes)

  histList = [key.GetName() for key in nomDir.GetListOfKeys()]
  for histName in histList:
    if "prof_" in histName or "ptSlice" in histName:
      continue

    nomHist = nomDir.Get( histName )
    nomHist.SetName(nomHist.GetName())

    if not type(nomHist) == TH1F and not type(nomHist) == TH1D and not type(nomHist) == TGraphErrors:  #Can't draw bands if not 1D
      continue

    leg = TLegend(0.83, 0.15, 0.99, 0.95)
    pad1 = TPad("pad1", "", 0, 0, 0.83, 1)
    pad1.Draw()
    pad1.cd()
    leg.AddEntry( nomHist, "Nominal", "lp" )
    #nomHist.SetMinimum(0.9)
    if( "Pt" in histName or "Energy" in histName):
      nomHist.GetXaxis().SetRange(nomHist.FindFirstBinAbove(0), nomHist.FindLastBinAbove(0)+1 )
    nomHist.SetMaximum(1.5*nomHist.GetMaximum())
    nomHist.SetMinimum(0.0001)
    if( "MJB" in histName) :
      nomHist.GetXaxis().SetRangeUser( 300, 2500 )
      nomHist.SetMaximum(1.1)
      nomHist.SetMinimum(0.9)
      nomHist.GetXaxis().SetMoreLogLabels(True)
#    nomHist.SetMarkerSize(.75)
    if( "recoilPt" in histName):
      nomHist.GetYaxis().SetTitle("Entries / GeV")
      nomHist.GetXaxis().SetRangeUser( 500, 3100 )
      if( "recoilPt" in histName):
        for iBin in range(1, nomHist.GetNbinsX()+1):
          nomHist.SetBinContent(iBin, nomHist.GetBinContent(iBin)/ nomHist.GetBinWidth(iBin))
    nomHist.Draw()
    if not type(nomHist) == TGraphErrors:
      nomHist.Draw("p")
    else:
      nomHist.SetMarkerStyle(33)
      nomHist.SetMarkerSize(1.5)
      nomHist.SetLineWidth(4)
      nomHist.Draw("ap")

    if(f_plotSys):
      ## Get list of systematic histograms ##
      fullHistList = []
      for thisSysDir in sysDirList:
        fullHistList.append( thisSysDir.Get(histName) )
        fullHistList[-1].SetDirectory(0)

      ## Add systematic bands ##
      sysHistList = []
      for iTopSys, topSysName in enumerate(sysTypes):

        if topSysName == 'All':
          subHistList = [thisHist for thisName, thisHist in zip(sysDirNameList, fullHistList) if any(otherTopName in thisName for otherTopName in sysTypes) ]
        else:
          subHistList = [thisHist for thisName, thisHist in zip(sysDirNameList, fullHistList) if topSysName in thisName]

        sysHistUp, sysHistDn = plotSysRatios.getCombinedSysHist(nomHist, subHistList, topSysName)
        for iBin in range(1, nomHist.GetNbinsX()+1):
          sysHistUp.SetBinContent( iBin, nomHist.GetBinContent(iBin)*(1.+sysHistUp.GetBinContent(iBin)) )
          sysHistDn.SetBinContent( iBin, nomHist.GetBinContent(iBin)*(1.+sysHistDn.GetBinContent(iBin)) )

        if topSysName == 'All':
          color = kBlack
        else:
          color = gStyle.GetColorPalette(int(colorOffset*(iTopSys+1)))

        sysHistUp.SetLineColor(color)
        sysHistUp.SetMarkerColor(color)
        sysHistUp.SetMarkerSize(1.5)
        sysHistUp.SetMarkerStyle(34)
        sysHistDn.SetLineColor(color)
        sysHistDn.SetMarkerColor(color)
        sysHistDn.SetMarkerSize(1.5)
        sysHistDn.SetMarkerStyle(34)
        if( "Pt" in histName or "Energy" in histName):
          sysHistUp.GetXaxis().SetRange(sysHistUp.FindFirstBinAbove(0), sysHistUp.FindLastBinAbove(0)+1)
          sysHistDn.GetXaxis().SetRange(sysHistDn.FindFirstBinAbove(0), sysHistDn.FindLastBinAbove(0)+1)
        if not type(nomHist) == TGraphErrors:
          sysHistUp.Draw("same hist l")
          sysHistDn.Draw("same hist l")
        else:
          sysHistUp.SetMarkerStyle(4)
          sysHistUp.SetMarkerSize(1.2)
          sysHistUp.Draw("same l")
          sysHistDn.SetMarkerStyle(4)
          sysHistDn.SetMarkerSize(1.2)
          sysHistDn.Draw("same l")

        if( topSysName == "EtaIntercalibration"):
          leg.AddEntry( sysHistUp, "EIC", "lp")
        else:
          leg.AddEntry( sysHistUp, topSysName, "lp")

        # Save them in a list
        sysHistList.append( sysHistUp )
        sysHistList.append( sysHistDn )

#    ### Add MC for Data MJB! ###
#    if( "data" in file and "MJB" in histName ):
#      filePath = os.path.dirname( file )
#      if( "initial" in file):
#        mcFile = glob.glob( filePath+"/*mc14*MJB_initial.root")
#      elif( "final" in file):
#        mcFile = glob.glob( filePath+"/*mc14*MJB_final.root")
#      if len(mcFile) == 1:
#        mcFile = TFile.Open(mcFile[0], "READ")
#        mcKeyList = [key.GetName() for key in mcFile.GetListOfKeys()] #List of top level objects
#        mcDirList = [key for key in mcKeyList if "Iteration" in key] #List of all directories
#        #mcDir = [dir for dir in dirList if "NoCorr" in dir]
#        mcDir = [dir for dir in dirList if "Nominal" in dir]
#        if len(mcDir) == 1:
#          mcDir = mcFile.Get( mcDir[0] )
#          mcHist = mcDir.Get(histName)
#          mcHist.SetMarkerColor(kRed)
#          mcHist.SetLineColor(kRed)
#          mcHist.SetMarkerStyle(33)
#          mcHist.SetMarkerSize(1.3)
#          mcHist.Draw("same p")
#          leg.AddEntry(mcHist, "MC", "lp")
#
#    ### Add Gagik for DoubleMJB! ###
#    if( f_addGagik ):
#      if( "DoubleMJB" in histName ):
#        filePath = os.path.dirname( file )
#        gagikFile = TFile.Open(filePath+"/ThirdCycle.EM4.sherpa.1.v11.root", "READ")
#        gagikHist = gagikFile.Get("g_DoMC_fmean_vs_recoil")
#        gagikHist.SetMarkerColor(kRed)
#        gagikHist.SetLineColor(kRed)
#        gagikHist.SetMarkerStyle(33)
#        gagikHist.SetMarkerSize(1.3)
#        gagikHist.Draw("same p")
#        leg.AddEntry(gagikHist, "8 TeV", "lp")
#

    nomHist.Draw("same p")
    c1.cd()
    leg.Draw()
    AtlasStyle.ATLAS_LABEL(0.2,0.88, 1,"    Internal")
    AtlasStyle.myText(0.2,0.82,1, "#sqrt{s} = 13 TeV, 3.3 fb^{-1}")

    if "Pt" in histName or "alpha" in histName:
      pad1.SetLogy()
      c1.SaveAs(outDir+nomHist.GetName()+"_logy.png" )
      c1.SaveAs(outDir+'/eps/'+nomHist.GetName()+"_logy.eps" )
      pad1.SetLogy(0)
    if "MJB" in histName:
      pad1.SetLogx()
    c1.SaveAs((outDir+nomHist.GetName()+".png") )
    c1.SaveAs((outDir+'/eps/'+nomHist.GetName()+".eps") )
    c1.Clear()



  inFile.Close()
Ejemplo n.º 9
0
def plot1D(Hists, SampleTypes, SampleNames):

    histName = '_'.join(Hists[0].GetName().split('_')[1:])
    plotRatio = args.plotRatio

    ## Setup Canvas ##
    c0 = ROOT.TCanvas(histName)
    logx = False
    logy = False
    # TODO need a logXList of variables for choosing this.  Get from a config file?
    ##    #extraText=[]
    ##    #logXList = [ "mjj", "m3j", "chi", "m12", "m13", "m23" ]   # madd all two-jet mass plots have logX
    ##    logXList = [ "chi" ]   # madd all two-jet mass plots have logX
    ##    for v in logXList:
    ##      if v == hName: logx = True
    ###      elif v in hName and "for_mjj" in hName : logx = True
    ##      elif v in hName and not "__" in hName: logx = True
    ##    if logx: hists[i].GetYaxis().SetMoreLogLabels(1)
    ##
    ##    if logx:
    ##      c0.SetLogx()
    ##      if (plotRatio):
    ##        pad1.SetLogx()
    ##        pad2.SetLogx()
    ##    else:
    ##      c0.SetLogx(0)
    ##      if (plotRatio):
    ##        pad1.SetLogx(0)
    ##        pad2.SetLogx(0)

    setMaximum(Hists)

    if plotRatio:
        pad1, pad2, zeroLine, oneLine = getRatioObjects(c0, logx, logy)
        pad1.cd()

    leg = configureLegend(SampleTypes, Hists, SampleNames)
    ### Configure draw string ###
    for iH, hist in enumerate(Hists):
        drawString = ""
        if iH != 0:
            drawString += 'same'
        drawString += 'hist'
        #drawString += 'histe'
        if not "data" == SampleTypes[iH]:
            #if args.stackBkg:
            #  drawString += 'fe'
            #else:
            drawString += ''
        else:
            drawString += 'ep'

        print drawString
        Hists[iH].Draw(drawString)

    ## Setup Ratio Plots
    if plotRatio:
        ratioHists = []  #Ratio histograms
        iRatioHist = SampleTypes.index(args.ratioWRT)
        for iHist, hist in enumerate(Hists):
            if iHist == iRatioHist: continue

            ## get relevant hists ##
            tmpRatioHist = Hists[iRatioHist].Clone(hist.GetName() + '_ratio')
            tmpHist = hist.Clone('tmp')

            ## create ratio ##
            if type(tmpHist) == ROOT.THStack:
                tmpStackHist = getCombinedStack(tmpHist)
                for iStack, stackHist in enumerate(tmpHist.GetHists()):
                    if iStack == 0:
                        tmpStackHist = stackHist.Clone('tmp2')
                    else:
                        tmpStackHist.Add(stackHist)
                tmpRatioHist.Add(tmpStackHist, -1.)
                tmpRatioHist.Divide(tmpStackHist)
            else:
                tmpRatioHist.Add(tmpHist, -1.)
                tmpRatioHist.Divide(tmpHist)

            # flip it so excess is still positive on ratio
            if args.ratioWRT == 'bkg' or args.ratioWRT == 'stack':
                tmpRatioHist.Scale(-1.0)

            ## If ratio value is 0 then there should be no ratio drawn
            for iBin in range(1, tmpRatioHist.GetNbinsX() + 1):
                if Hists[iRatioHist].GetBinContent(iBin) == 0:
                    tmpRatioHist.SetBinContent(iBin, 0)
                    tmpRatioHist.SetBinError(iBin, 0)

            configureRatioHist(tmpHist, tmpRatioHist)
            ratioHists.append(tmpRatioHist)

    ## Draw Ratio Plots
    if plotRatio:
        pad2.cd()
        for iHist, ratioHist in enumerate(ratioHists):
            ratioHists[iHist].SetStats(0)
            if iHist == 0:
                ratioHists[iHist].DrawCopy("p")
                ratioHists[iHist].SetMarkerSize(0)
                ratioHists[iHist].DrawCopy("same e0")
            else:
                ratioHists[iHist].Draw("same fhist")
        zeroLine.Draw("same")

        c0.cd()

    leg.Draw("same")
    AtlasStyle.ATLAS_LABEL(0.20, 0.88, 1, "Internal")
    sqrtSLumiText = getSqrtSLumiText(args.lumi)
    AtlasStyle.myText(0.20, 0.82, 1, sqrtSLumiText)
    if len(args.plotText) > 0:
        AtlasStyle.myText(0.20, 0.76, 1, args.plotText)

    if any(
            extraTextString.split(',')[0] in histName
            for extraTextString in extraText):
        extraTextString = [
            extraTextString for extraTextString in extraText
            if extraTextString.split(',')[0] in histName
        ][0]
        if len(args.plotText) > 0:
            AtlasStyle.myText(0.20, 0.64, 1, extraTextString.split(',')[1])
        else:
            AtlasStyle.myText(0.20, 0.75, 1, extraTextString.split(',')[1])

    c0.Print(args.outDir + "/" + args.outputTag + "_" + histName +
             args.outputVersion + ".png", "png")  #,"png")

    ## Draw y-log plots ##
    if plotRatio:
        pad1.SetLogy()
        pad1.cd()
    else:
        c0.SetLogy()

    setMaximum(Hists, True)
    ### Redraw using new logY maximum ###
    for iH, hist in enumerate(Hists):
        drawString = ""
        if iH != 0:
            drawString += 'same'
        drawString += 'histe'
        if not "data" == SampleTypes[iH]:
            drawString += 'fe'
        else:
            drawString += 'ep'

        Hists[iH].Draw(drawString)

    c0.Print(args.outDir + "/" + args.outputTag + "_" + histName +
             args.outputVersion + "_logY.png", "png")  #,"png")

    ## TODO Draw log versions?

    if plotRatio:
        pad1.Delete()
        pad2.Delete()


#  c0.Delete()

    return
Ejemplo n.º 10
0
def plot1D( Hists, SampleTypes ):

  histName = '_'.join(Hists[0].GetName().split('_')[1:] )
  plotRatio = args.plotRatio

  ## Setup Canvas ##
  c0 = ROOT.TCanvas(histName)
  logx = False
  logy = False
# TODO need a logXList of variables for choosing this.  Get from a config file?
##    #extraText=[]
##    #logXList = [ "mjj", "m3j", "chi", "m12", "m13", "m23" ]   # madd all two-jet mass plots have logX
##    logXList = [ "chi" ]   # madd all two-jet mass plots have logX
##    for v in logXList:
##      if v == hName: logx = True
###      elif v in hName and "for_mjj" in hName : logx = True
##      elif v in hName and not "__" in hName: logx = True
##    if logx: hists[i].GetYaxis().SetMoreLogLabels(1)
##
##    if logx:
##      c0.SetLogx()
##      if (plotRatio):
##        pad1.SetLogx()
##        pad2.SetLogx()
##    else:
##      c0.SetLogx(0)
##      if (plotRatio):
##        pad1.SetLogx(0)
##        pad2.SetLogx(0)
  if plotRatio:
    pad1, pad2, zeroLine, oneLine = getRatioObjects(logx, logy)

  leg = configureLegend(SampleTypes, Hists)
  ### Configure draw string ###
  for iH, hist in enumerate(Hists):
    drawString = ""
    if iH != 0:
      drawString += 'same'
    drawString += 'histe'
    if len(args.dataType) > 0 and not "data" == SampleTypes[iH]:
      # not data so can make sure markers are not seen - see error bars
      if not "stack" == SampleTypes[iH]:
        Hists[iH].SetMarkerSize( 0.0 )
      if not "bkg" == SampleTypes[iH]:
        drawString += 'fe'
      else: #why is this here?
        drawString += 'fe'
    else:
      drawString += 'ep'

    Hists[iH].Draw( drawString )

  leg.Draw("same")
  AtlasStyle.ATLAS_LABEL(0.20,0.88)
  sqrtSLumiText = getSqrtSLumiText( args.lumi )
  AtlasStyle.myText(0.20,0.82,1, sqrtSLumiText)
  if len(args.plotText)>0:
    AtlasStyle.myText(0.20,0.76,1, args.plotText)


  if any( extraTextString.split(',')[0] in histName for extraTextString in extraText ):
    extraTextString = [extraTextString for extraTextString in extraText if extraTextString.split(',')[0] in histName][0]
    if len(args.plotText)>0:
      AtlasStyle.myText(0.20,0.64, 1,extraTextString.split(',')[1])
    else:
      AtlasStyle.myText(0.20,0.75, 1,extraTextString.split(',')[1])

  c0.Print( args.plotDir + "/" + args.outputTag + "_" + histName + args.outputVersion + ".png","png") #,"png")

## TODO Draw log versions?

  return