Ejemplo n.º 1
0
def make_tgrapherrors(name,
                      title,
                      color=1,
                      marker=20,
                      marker_size=1,
                      width=1,
                      asym_err=False,
                      style=1,
                      x=None,
                      y=None):
    if (x and y) is None:
        gr = TGraphErrors() if not asym_err else TGraphAsymmErrors()
    else:
        gr = TGraphErrors(len(x), array(x, 'd'), array(
            y, 'd')) if not asym_err else TGraphAsymmErrors(
                len(x), array(x, 'd'), array(y), 'd')
    gr.SetTitle(title)
    gr.SetName(name)
    gr.SetMarkerStyle(marker)
    gr.SetMarkerColor(color)
    gr.SetLineColor(color)
    gr.SetMarkerSize(marker_size)
    gr.SetLineWidth(width)
    gr.SetLineStyle(style)
    return gr
Ejemplo n.º 2
0
def Sigma_Calc(g,i_,x,y,xe,ye,percentage):
    #print'Creating TGraph with new uncertainty band'
    # sigma factor. What to multiply uncertainties by, assuming current uncertainties are 1 sigma. 
    #print'percentage/100. = ',percentage/100.
    sf = TMath.ErfInverse(percentage/100.)*TMath.Sqrt(2) # sigma value for desired percentage events contained in distribution 
    #print"sf = ",sf

    #for i in range(i_ - 1):
    #print'i_ = ',i_
    for i in range(i_):
        ye[i] = ye[i]*sf # multiply 1 sigma uncertainties by new sigma value. 

    #print sf,'sig errors = ',ye   

    #ng = TGraphErrors(i_ - 1, x, y, xe, ye)
    ng = TGraphErrors(i_, x, y, xe, ye)

    if percentage == 90: j = 2
    if percentage == 99.5: j = 4

    ng.SetMarkerStyle(g.GetMarkerStyle())
    ng.SetLineStyle(g.GetLineStyle())
    #ng.SetMarkerColor(g.GetMarkerColor() + j)
    #ng.SetLineColor(g.GetLineColor() + j)
    ng.SetFillColor(g.GetFillColor() + j)
    #ng.SetName(g.GetName())

    ng.SetFillStyle(g.GetFillStyle())

    return ng
Ejemplo n.º 3
0
def load_cck():

    #model by Guillermo at. al.
    f = open("data/data-dtdy-y_0-RHIC-clean_CCK.dat", "read")
    sigma = []
    for line in f:
        if line[0] == "#": continue
        p = line.split("\t")
        t = float(p[3])
        nucl = float(p[4])
        hs = float(p[8])
        sigma.append({"t": t, "nucl": nucl, "hs": hs})

    #correction from gamma-Au to AuAu by Michal
    k_auau = 9.0296

    #scaling to XnXn
    kx = 0.1702

    gCCK = TGraphErrors(len(sigma))
    for i in xrange(len(sigma)):
        gCCK.SetPoint(i, sigma[i]["t"], sigma[i]["hs"] * k_auau * kx)

    gCCK.SetLineColor(rt.kRed)
    gCCK.SetLineWidth(3)
    gCCK.SetLineStyle(rt.kDashed)  # 9

    return gCCK
Ejemplo n.º 4
0
def load_ms():

    #model by Heikki and Bjorn
    f = open("data/to_star_ms.txt", "read")
    t_sigma = []
    for line in f:
        if line[0] == "#": continue
        point = line.split(" ")
        t_sigma.append([float(point[0]), float(point[1])])

    #scaling to XnXn
    kx = 0.1702

    gMS = TGraphErrors(len(t_sigma))
    for i in xrange(len(t_sigma)):
        gMS.SetPoint(i, t_sigma[i][0], t_sigma[i][1] * kx)

    gMS.SetLineColor(rt.kViolet)
    gMS.SetLineWidth(3)
    gMS.SetLineStyle(rt.kDashDotted)  # kDashed

    return gMS
Ejemplo n.º 5
0
        Number_of_Atom(Avalanche_region1,
                       math.pow(math.pow(10, 10 + i * 0.5), 0.33)))
    print str(
        Number_of_Atom(Avalanche_region1,
                       math.pow(math.pow(10, 10 + i * 0.5), 0.33)))
    print str(
        Number_of_Atom(Avalanche_region,
                       math.pow(math.pow(10, 10 + i * 0.5), 0.33)))

c = TCanvas("c1", "c1", 0, 0, 500, 500)

gStyle.SetOptFit()
gr = TGraphErrors(17, xarray, yarray, xarrayerror, yarrayerror)
gr1 = TGraphErrors(17, xarray, yarray1, xarrayerror, yarrayerror)

gr.SetLineStyle(1)
gr.SetMarkerColor(2)
gr.SetMarkerStyle(8)
gr.SetLineWidth(2)

gr1.SetLineStyle(1)
gr1.SetMarkerColor(3)
gr1.SetMarkerStyle(8)
gr1.SetLineWidth(2)

gr1.SetTitle(";Concentration(1/cm^{3}) ;# of impurities ")
gr1.GetHistogram().SetMaximum(30)
gr1.GetHistogram().SetMinimum(0)
gr1.GetXaxis().SetLimits(math.pow(10, 10 + 0 * 0.5),
                         math.pow(10, 10 + 16 * 0.5))
Ejemplo n.º 6
0
def makePlot1D(filepath, foutname, plottitle='', masstitle=''):
    br = 1 if 'Resonant' in plottitle else 0.68
    limits = parseLimitFiles2D(filepath, br)

    xaxis = []
    xseclist = []
    xsecerr = []
    cent = []
    obs = []
    up1 = []
    up2 = []
    down1 = []
    down2 = []
    maxval = 0
    minval = 999
    for m in sorted(limits):
        l = limits[m]
        xaxis.append(m)
        xseclist.append(l.xsec)
        xsecerr.append(l.xsec * .2)
        cent.append(l.cent)
        up1.append(l.up1 - l.cent)
        up2.append(l.up2 - l.cent)
        down1.append(l.cent - l.down1)
        down2.append(l.cent - l.down2)
        obs.append(l.obs)
        maxval = max(maxval, l.up2)
        minval = min(minval, l.down2)

    N = len(xaxis)

    up1Sigma = array('f', up1)
    up2Sigma = array('f', up2)
    down1Sigma = array('f', down1)
    down2Sigma = array('f', down2)
    cent = array('f', cent)
    obs = array('f', obs)
    xarray = array('f', xaxis)
    xsecarray = array('f', xseclist)
    xsecerrarray = array('f', xsecerr)
    zeros = array('f', [0 for i in xrange(N)])

    graphXsec = TGraphErrors(N, xarray, xsecarray, zeros, xsecerrarray)

    graphCent = TGraph(N, xarray, cent)
    graphObs = TGraph(N, xarray, obs)
    graph1Sigma = TGraphAsymmErrors(N, xarray, cent, zeros, zeros, down1Sigma,
                                    up1Sigma)
    graph2Sigma = TGraphAsymmErrors(N, xarray, cent, zeros, zeros, down2Sigma,
                                    up2Sigma)

    c = TCanvas('c', 'c', 700, 600)
    c.SetLogy()
    c.SetLeftMargin(.15)

    graph2Sigma.GetXaxis().SetTitle(masstitle + ' [GeV]')
    graph2Sigma.GetYaxis().SetTitle(
        '95% C.L. upper limit [#sigma/#sigma_{theory}]')
    c2 = root.kOrange
    c1 = root.kGreen + 1
    graph2Sigma.SetLineColor(c2)
    graph1Sigma.SetLineColor(c1)
    graph2Sigma.SetFillColor(c2)
    graph1Sigma.SetFillColor(c1)
    graph2Sigma.SetMinimum(0.5 * minval)
    graph2Sigma.SetMaximum(10 * maxval)
    graphCent.SetLineWidth(2)
    graphCent.SetLineStyle(2)
    graphObs.SetLineColor(1)
    graphObs.SetLineWidth(3)
    graphObs.SetMarkerStyle(20)
    graphObs.SetMarkerSize(1)
    graphObs.SetMarkerColor(1)
    graph1Sigma.SetLineStyle(0)
    graph2Sigma.SetLineStyle(0)

    leg = TLegend(0.55, 0.7, 0.9, 0.9)
    leg.AddEntry(graphCent, 'Expected', 'L')
    if not BLIND:
        leg.AddEntry(graphObs, 'Observed', 'Lp')
    leg.AddEntry(graph1Sigma, '1 std. dev.', 'F')
    leg.AddEntry(graph2Sigma, '2 std. dev.', 'F')
    leg.SetFillStyle(0)
    leg.SetBorderSize(0)

    graph2Sigma.Draw('A3')
    graph1Sigma.Draw('3 same')
    graphCent.Draw('same L')
    if not BLIND:
        graphObs.Draw('same Lp')

    subscript = 'SR' if 'Resonant' in plottitle else 'FC'
    coupling = '0.1' if 'Resonant' in plottitle else '0.25'

    graphXsec.SetLineColor(2)
    graphXsec.SetLineWidth(2)
    graphXsec.SetLineStyle(2)
    graphXsec.SetFillColor(2)
    graphXsec.SetFillStyle(3005)
    graphXsec.Draw('same L3')
    '''
  if not scale:
    if 'Resonant' in plottitle:
      leg.AddEntry(graphXsec,'Theory #splitline{a_{%s}=b_{%s}=%s}{m_{#chi}=100 GeV}'%(subscript,subscript,coupling),'l')
    else:
      leg.AddEntry(graphXsec,'Theory #splitline{a_{%s}=b_{%s}=%s}{m_{#chi}=10 GeV}'%(subscript,subscript,coupling),'l')
  '''
    if not BLIND:
        findIntersect1D(graphObs, graphXsec, xaxis[0], xaxis[-1])
    findIntersect1D(graphCent, graphXsec, xaxis[0], xaxis[-1])

    leg.Draw()

    label = TLatex()
    label.SetNDC()
    label.SetTextSize(0.8 * c.GetTopMargin())
    label.SetTextFont(62)
    label.SetTextAlign(11)
    label.DrawLatex(0.15, 0.94, "CMS")
    label.SetTextFont(52)
    label.SetTextSize(0.6 * c.GetTopMargin())
    #  label.DrawLatex(0.25,0.94,"Preliminary")
    label.SetTextFont(42)
    label.SetTextSize(0.7 * c.GetTopMargin())
    label.DrawLatex(0.19, 0.83, plottitle)
    if 'Resonant' in plottitle:
        label.DrawLatex(0.19, 0.75, "a_{SR} = b_{SR} = %s" % coupling)
        label.DrawLatex(0.19, 0.68, "m_{#chi}=100 GeV")
    else:
        label.DrawLatex(0.19, 0.75, "g_{DM}^{V}=1,g_{q}^{V}=0.25")
        label.DrawLatex(0.19, 0.68, "m_{#chi}=1 GeV")
    label.SetTextSize(0.6 * c.GetTopMargin())
    label.SetTextFont(42)
    label.SetTextAlign(31)  # align right
    label.DrawLatex(0.95, 0.94, "%.1f fb^{-1} (13 TeV)" % (plotConfig.lumi))

    c.SaveAs(foutname + '.pdf')
    c.SaveAs(foutname + '.png')
Ejemplo n.º 7
0
def draw(hist,
         var_type,
         log='',
         plotdir=None,
         plotname='foop',
         more_hists=None,
         write_csv=False,
         stats=None,
         bounds=None,
         errors=False,
         shift_overflows=False,
         csv_fname=None,
         scale_errors=None,
         rebin=None,
         plottitle='',
         colors=None,
         linestyles=None,
         cwidth=None,
         cheight=None,
         imagetype='svg',
         xtitle=None,
         ytitle=None,
         xline=None,
         yline=None,
         draw_str=None,
         normalize=False,
         normalization_bounds=None,
         linewidths=None,
         markersizes=None,
         no_labels=False,
         graphify=False,
         translegend=(0.0, 0.0)):
    assert os.path.exists(plotdir)
    if not has_root:
        return

    if normalization_bounds is not None:
        assert bounds is None
    if bounds is not None:
        assert normalization_bounds is None

    cvn = TCanvas('cvn-' + plotname, '', 700 if cwidth is None else cwidth,
                  600 if cheight is None else cheight)

    hists = [
        hist,
    ]
    if more_hists != None:
        hists = hists + more_hists

    xmin, xmax, ymax = None, None, None
    ih = 0
    for htmp in hists:
        if rebin is not None:
            htmp.Rebin(rebin)
        if scale_errors is not None:
            factor = float(
                scale_errors[0]) if len(scale_errors) == 1 else float(
                    scale_errors[ih])
            for ibin in range(htmp.GetNbinsX() + 2):
                htmp.SetBinError(ibin, htmp.GetBinError(ibin) * factor)

        if not normalize:
            assert normalization_bounds is None
            if bounds is not None:
                ibin_start = htmp.FindBin(bounds[0])
                ibin_end = htmp.FindBin(bounds[1])
                this_y_max = GetMaximumWithBounds(
                    htmp,
                    htmp.GetXaxis().GetBinLowEdge(ibin_start),
                    htmp.GetXaxis().GetBinUpEdge(ibin_end))
            else:
                this_y_max = htmp.GetMaximum()
        else:  # renormalize the hist within these bounds
            if normalization_bounds is None:
                factor = 1. / htmp.Integral() if htmp.Integral() > 0.0 else 0.0
                htmp.Scale(factor)
                this_y_max = htmp.GetMaximum()
            else:
                ibin_start = 0 if normalization_bounds[
                    0] is None else htmp.FindBin(normalization_bounds[0])
                ibin_end = htmp.GetNbinsX(
                ) if normalization_bounds[1] is None else htmp.FindBin(
                    normalization_bounds[1])
                factor = htmp.Integral(ibin_start, ibin_end) if htmp.Integral(
                    ibin_start, ibin_end
                ) > 0.0 else 0.0  # NOTE this is inclusive, i.e. includes <ibin_end>
                htmp.Scale(factor)
                this_y_max = GetMaximumWithBounds(
                    htmp,
                    htmp.GetXaxis().GetBinLowEdge(ibin_start),
                    htmp.GetXaxis().GetBinUpEdge(ibin_end))

        if ymax is None or this_y_max > ymax:
            ymax = this_y_max

        if xmin is None or htmp.GetBinLowEdge(1) < xmin:
            xmin = htmp.GetBinLowEdge(1)
        if xmax is None or htmp.GetXaxis().GetBinUpEdge(
                htmp.GetNbinsX()) > xmax:
            xmax = htmp.GetXaxis().GetBinUpEdge(htmp.GetNbinsX())

        ih += 1

    if bounds is not None:
        xmin, xmax = bounds
    hframe = TH1D('hframe', '', hist.GetNbinsX(), xmin, xmax)
    if not no_labels and (var_type == 'string' or var_type == 'bool'):
        for ib in range(1, hframe.GetNbinsX() + 1):
            hframe.GetXaxis().SetBinLabel(ib, hist.GetXaxis().GetBinLabel(ib))

    if 'y' in log:
        hframe.SetMaximum(3 * ymax)
    else:
        hframe.SetMaximum(1.2 * ymax)
    if var_type == 'bool':
        hframe.GetXaxis().SetLabelSize(0.1)

    if plottitle == '':
        plottitle = plotname

    if xtitle is None:
        xtitle = hist.GetXaxis().GetTitle()
    if ytitle is None:
        ytitle = hframe.GetYaxis().GetTitle()

    hframe.SetTitle(plottitle + ';' + xtitle + ';' + ytitle)
    # gStyle.SetTitleFontSize(.075)
    # gStyle.SetTitleY(gStyle.GetTitleY() + .0004)
    if cwidth is not None:
        gStyle.SetTitleOffset(0.99 * gStyle.GetTitleOffset('y'), 'y')
    # gStyle.SetTitleFillStyle(0)
    # hframe.SetTitleSize(gStyle.GetTitleSize())
    # hframe.SetTitleFont(gStyle.GetTitleFont())
    hframe.Draw('txt')

    if shift_overflows:
        for htmp in hists:
            if htmp == None:
                continue
            underflows, overflows = 0.0, 0.0
            first_shown_bin, last_shown_bin = -1, -1
            for ib in range(0, htmp.GetXaxis().GetNbins() + 2):
                if htmp.GetXaxis().GetBinCenter(ib) <= xmin:
                    underflows += htmp.GetBinContent(ib)
                    htmp.SetBinContent(ib, 0.0)
                elif first_shown_bin == -1:
                    first_shown_bin = ib
                else:
                    break
            for ib in reversed(range(0, htmp.GetXaxis().GetNbins() + 2)):
                if htmp.GetXaxis().GetBinCenter(ib) >= xmax:
                    overflows += htmp.GetBinContent(ib)
                    htmp.SetBinContent(ib, 0.0)
                elif last_shown_bin == -1:
                    last_shown_bin = ib
                else:
                    break

            if 'd_hamming' in plotname:
                print htmp.GetTitle()
                print '  underflow', underflows, htmp.GetBinContent(
                    first_shown_bin)
                print '  overflow', overflows, htmp.GetBinContent(
                    last_shown_bin)
                print '  first', htmp.GetXaxis().GetBinCenter(first_shown_bin)
                print '  last', htmp.GetXaxis().GetBinCenter(last_shown_bin)
            htmp.SetBinContent(
                first_shown_bin,
                underflows + htmp.GetBinContent(first_shown_bin))
            htmp.SetBinContent(last_shown_bin,
                               overflows + htmp.GetBinContent(last_shown_bin))

    if colors is None:
        assert len(hists) < 5
        colors = (kRed, kBlue - 4, kGreen + 2, kOrange + 1
                  )  # 632, 596, 418, 801
    else:
        assert len(hists) <= len(colors)
    if linestyles is None:
        # assert len(hists) < 5
        linestyles = [1 for _ in range(len(hists))]
    else:
        assert len(hists) <= len(linestyles)

    # legends
    x0, y0, x1, y1 = 0.57 + translegend[0], 0.66 + translegend[
        1], 0.99 + translegend[0], 0.88 + translegend[1]
    if len(hists) < 5:
        leg = TLegend(x0, y0, x1, y1)
    else:
        leg = TLegend(x0, y0 - 0.05, x1, y1)
    leg.SetFillColor(0)
    leg.SetFillStyle(0)
    leg.SetBorderSize(0)

    # draw
    if graphify:
        graphs = []
        for ih in range(len(hists)):
            htmp = hists[ih]
            n_bins = hists[ih].GetNbinsX()
            xvals, yvals, xerrs, yerrs = array(
                'f', [0 for i in range(n_bins)]), array(
                    'f', [0 for i in range(n_bins)]), array(
                        'f', [0 for i in range(n_bins)]), array(
                            'f', [0 for i in range(n_bins)])
            for ib in range(1, n_bins + 1):  # NOTE ignoring overflows
                xvals[ib - 1] = hists[ih].GetXaxis().GetBinCenter(ib)
                xerrs[ib - 1] = 0.0
                yvals[ib - 1] = hists[ih].GetBinContent(ib)
                yerrs[ib - 1] = hists[ih].GetBinError(ib) if errors else 0.0
            gr = TGraphErrors(n_bins, xvals, yvals, xerrs, yerrs)

            if markersizes is not None:
                imark = ih if len(markersizes) > 1 else 0
                gr.SetMarkerSize(markersizes[imark])
            gr.SetMarkerColor(colors[ih])
            if linewidths is None:
                if ih < 6:  # and len(hists) < 5:
                    gr.SetLineWidth(6 - ih)
            else:
                ilw = ih if len(linewidths) > 1 else 0
                gr.SetLineWidth(linewidths[ilw])
            gr.SetLineColor(colors[ih])
            # if int(linewidth) == 1:
            #     gr.SetLineColorAlpha(colors[ih], 0.4)
            gr.SetLineStyle(linestyles[ih])

            if draw_str is None:
                draw_str = 'lpz'
            if hists[ih].Integral() != 0.0:
                gr.Draw(draw_str + ' same')

                statstr = ''
                if stats is not None:
                    if 'rms' in stats:
                        statstr += ' (%.2f)' % htmp.GetRMS()
                    if 'mean' in stats:
                        statstr += ' (%.2f)' % htmp.GetMean()
                    if '0-bin' in stats:
                        statstr += ' (%.2f)' % htmp.GetBinContent(1)

                leg.AddEntry(gr, hists[ih].GetTitle() + ' ' + statstr, 'pl')

            graphs.append(
                gr
            )  # yes, you really do have to do this to keep root from giving you only one graph
    else:
        if draw_str is None:
            draw_str = 'hist same'
        else:
            draw_str += ' same'
        if errors:
            draw_str += ' e'
        for ih in range(len(hists)):
            htmp = hists[ih]

            if stats is not None:
                if 'rms' in stats:
                    htmp.SetTitle(htmp.GetTitle() +
                                  (' (%.2f)' % htmp.GetRMS()))
                if 'mean' in stats:
                    htmp.SetTitle(htmp.GetTitle() +
                                  (' (%.2f)' % htmp.GetMean()))
                if '0-bin' in stats:
                    htmp.SetTitle(htmp.GetTitle() +
                                  (' (%.2f)' % htmp.GetBinContent(1)))

            htmp.SetLineColor(colors[ih])
            if markersizes is not None:
                imark = ih if len(markersizes) > 1 else 0
                htmp.SetMarkerSize(markersizes[imark])
            htmp.SetMarkerColor(colors[ih])
            htmp.SetLineStyle(linestyles[ih])
            if linewidths is None:
                if ih < 6:  # and len(hists) < 5:
                    htmp.SetLineWidth(6 - ih)
            else:
                ilw = ih if len(linewidths) > 1 else 0
                htmp.SetLineWidth(linewidths[ilw])

            leg.AddEntry(htmp, htmp.GetTitle(), 'l')
            htmp.Draw(draw_str)

    leg.Draw()

    if xline is not None:
        # if xline < hframe.GetXaxis().GetXmin() or xline > hframe.GetXaxis().GetXmax():  # make sure we got valid a x position for the line
        #     print 'WARNING plotting x line at %f out of bounds (%f, %f)' % (float(xmin), hframe.GetXaxis().GetXmin(), hframe.GetXaxis().GetXmax())
        # xl = TLine(xline, hframe.GetYaxis().GetXmin(), xline, 0.5*ymax)
        xl = TLine(xline, -0.1 * ymax, xline, 0.5 * ymax)
        xl.SetLineStyle(2)
        xl.Draw()
    if yline is not None:
        # if yline < hframe.GetYaxis().GetXmin() or xline > hframe.GetYaxis().GetXmax():  # make sure we got valid a x position for the line
        #     print 'WARNING plotting y line at %f out of bounds (%f, %f)' % (float(ymin), hframe.GetYaxis().GetXmin(), hframe.GetYaxis().GetXmax())
        yl = TLine(hframe.GetXaxis().GetXmin(), yline,
                   hframe.GetXaxis().GetXmax(), yline)
        yl.Draw()

    cvn.SetLogx('x' in log)
    cvn.SetLogy('y' in log)
    if not os.path.exists(plotdir + '/plots'):
        print 'ERROR dir \'' + plotdir + '/plots\' d.n.e.'
        assert False

    if write_csv:
        assert more_hists == None
        if csv_fname == None:
            write_hist_to_file(plotdir + '/plots/' + plotname + '.csv', hist)
        else:
            write_hist_to_file(csv_fname, hist)
    cvn.SaveAs(plotdir + '/plots/' + plotname + '.' + imagetype)
Ejemplo n.º 8
0
yarray_QQ_RMS.append(f1F.GetMeanError())
yarray_QQ_RMS.append(f2F.GetMeanError())
yarray_QQ_RMS.append(f3F.GetMeanError())
yarray_QQ_RMS.append(f4F.GetMeanError())
yarray_WW_RMS.append(f5F.GetMeanError())
yarray_WW_RMS.append(f6F.GetMeanError())
yarray_WW_RMS.append(f7F.GetMeanError())
yarray_WW_RMS.append(f8F.GetMeanError())
#===============================#

c = TCanvas("c1", "c1", 0, 0, 500, 500)

gr_QQ = TGraphErrors(4, xarray, yarray_QQ, xarray_error, yarray_QQ_RMS)
gr_QQ.SetLineColor(1)
gr_QQ.SetLineWidth(1)
gr_QQ.SetLineStyle(1)
gr_QQ.SetMarkerColor(2)
gr_QQ.SetMarkerStyle(1)
gr_QQ.SetMarkerSize(1)
gr_QQ.GetXaxis().SetTitle("E[TeV]")
gr_QQ.GetYaxis().SetTitle("<T_{delay}>[ns]")

gr_WW = TGraphErrors(4, xarray, yarray_WW, xarray_error, yarray_WW_RMS)
gr_WW.SetLineColor(3)
gr_WW.SetLineWidth(1)
gr_WW.SetLineStyle(1)
gr_WW.SetMarkerColor(4)
gr_WW.SetMarkerStyle(1)
gr_WW.SetMarkerSize(1)
#gr.GetXaxis().SetTitle("E[TeV]")
#gr.GetXaxis().SetTitleColor(4)
Ejemplo n.º 9
0
def acceptance(year):
    genPoints = [
        1800, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000
    ]

    treeSign = {}
    ngenSign = {}
    nevtSign = {}
    nevtSign_eta = {}
    nevtSign_dEta = {}
    eff = TGraphErrors()
    eff_eta = TGraphErrors()
    eff_dEta = TGraphErrors()

    for i, m in enumerate(genPoints):
        ngenSign[m] = 0.
        nevtSign[m] = 0.
        nevtSign_eta[m] = 0.
        nevtSign_dEta[m] = 0.

        if year == "run2":
            years = ['2016', '2017', '2018']
        else:
            years = [year]

        for yr in years:
            signName = "MC_signal_{}_M{}".format(yr, m)
            sfile = TFile(ACCEPTANCEDIR + signName + "_acceptanceHist.root",
                          "READ")

            ngenSign[m] += sample["ZpBB_M" + str(m)]['genEvents'][yr]

            #all_events_hist = sfile.Get('all_events')
            #nEvents = all_events_hist.GetBinContent(1)
            #ngenSign[m] += nEvents

            passing_events_hist = sfile.Get('passing')
            eta_flag_hist = sfile.Get('eta_flag')
            dEta_flag_hist = sfile.Get('dEta_flag')

            nEvents = passing_events_hist.GetBinContent(1)
            nEvents_eta = eta_flag_hist.GetBinContent(1)
            nEvents_dEta = dEta_flag_hist.GetBinContent(1)

            nevtSign[m] += nEvents
            nevtSign_eta[m] += nEvents_eta
            nevtSign_dEta[m] += nEvents_dEta

            sfile.Close()

        print m, ":", nevtSign[m], "/", ngenSign[
            m], "=", nevtSign[m] / ngenSign[m]
        if nevtSign[m] == 0 or ngenSign[m] < 0: continue
        n = eff.GetN()
        eff.SetPoint(n, m, nevtSign[m] / ngenSign[m])
        eff.SetPointError(n, 0, math.sqrt(nevtSign[m]) / ngenSign[m])
        eff_eta.SetPoint(n, m, nevtSign_eta[m] / ngenSign[m])
        eff_eta.SetPointError(n, 0, math.sqrt(nevtSign_eta[m]) / ngenSign[m])
        eff_dEta.SetPoint(n, m, nevtSign_dEta[m] / ngenSign[m])
        eff_dEta.SetPointError(n, 0, math.sqrt(nevtSign_dEta[m]) / ngenSign[m])

    eff.SetMarkerColor(4)
    eff.SetMarkerStyle(24)
    eff.SetMarkerSize(2)
    eff.SetLineColor(4)
    eff.SetLineWidth(3)
    eff_eta.SetMarkerColor(2)
    eff_eta.SetMarkerStyle(23)
    eff_eta.SetMarkerSize(2)
    eff_eta.SetLineColor(2)
    eff_eta.SetLineWidth(2)
    eff_eta.SetLineStyle(2)
    eff_dEta.SetMarkerColor(418)
    eff_dEta.SetMarkerStyle(23)
    eff_dEta.SetMarkerSize(2)
    eff_dEta.SetLineColor(418)
    eff_dEta.SetLineWidth(2)
    eff_dEta.SetLineStyle(2)

    n = eff.GetN()
    maxEff = 0.

    leg = TLegend(0.15, 0.7, 0.95, 0.8)
    leg.SetBorderSize(0)
    leg.SetFillStyle(0)  #1001
    leg.SetFillColor(0)
    #leg.SetY1(leg.GetY2()-len([x for x in channels if eff[x].GetN() > 0])/2.*0.045)

    leg.AddEntry(eff, "total")
    leg.AddEntry(eff_eta, "|#eta|<2.5")
    leg.AddEntry(eff_dEta, "#Delta#eta<1.1")

    #legS = TLegend(0.5, 0.85-0.045, 0.9, 0.85)
    #legS.SetBorderSize(0)
    #legS.SetFillStyle(0) #1001
    #legS.SetFillColor(0)
    #legS.AddEntry(eff['sum'], "Total efficiency (1 b tag + 2 b tag)", "pl")

    c1 = TCanvas("c1", "Signal Acceptance", 1200, 800)
    c1.cd(1)
    eff.Draw("APL")
    eff_eta.Draw("SAME, PL")
    eff_dEta.Draw("SAME, PL")
    leg.Draw()
    #legS.Draw()
    #setHistStyle(eff["sum"], 1.1)
    eff.SetTitle(";m_{Z'} (GeV);Acceptance")
    eff.SetMinimum(0.)
    eff.SetMaximum(max(1.5, maxEff * 1.5))  #0.65

    eff.GetXaxis().SetTitleSize(0.045)
    eff.GetYaxis().SetTitleSize(0.045)
    eff.GetYaxis().SetTitleOffset(1.1)
    eff.GetXaxis().SetTitleOffset(1.05)
    eff.GetXaxis().SetRangeUser(1500, 8000)
    c1.SetTopMargin(0.05)
    #drawCMS(-1, "Simulation Preliminary", year=year) #Preliminary
    #drawCMS(-1, "Work in Progress", year=year, suppressCMS=True)
    drawCMS(-1, "", year=year, suppressCMS=True)
    drawAnalysis("")

    c1.Print("plots/Efficiency/" + year + "_Acceptance.pdf")
    c1.Print("plots/Efficiency/" + year + "_Acceptance.png")
Ejemplo n.º 10
0
            H8_Projection_40TeV.Scale(1 / H8_Projection_40TeV.Integral())
            Fraction_WW_Use = H8_Projection_40TeV.GetBinContent(Sort_particle)
            Fraction_WW_40TeV.append(Fraction_WW_Use)
            Y_Error_WW_40TeV.append(
                np.sqrt(H8_Projection_40TeV.GetEntries() * Fraction_WW_Use *
                        (1 - Fraction_WW_Use)) /
                H8_Projection_40TeV.GetEntries())
        else:
            Y_Error_WW_40TeV.append(0)
            Fraction_WW_40TeV.append(0)

    gr_QQ_5TeV = TGraphErrors(4, X_PT, Fraction_QQ_5TeV, X_Error,
                              Y_Error_QQ_5TeV)
    gr_QQ_5TeV.SetLineColor(1)
    gr_QQ_5TeV.SetLineWidth(1)
    gr_QQ_5TeV.SetLineStyle(1)
    gr_QQ_5TeV.SetMarkerColor(1)
    gr_QQ_5TeV.SetMarkerStyle(8)
    gr_QQ_5TeV.SetMarkerSize(1)
    gr_QQ_5TeV.GetXaxis().SetTitle("Log(PT)")
    gr_QQ_5TeV.GetYaxis().SetTitle("Arbitrary")

    gr_WW_5TeV = TGraphErrors(4, X_PT, Fraction_WW_5TeV, X_Error,
                              Y_Error_WW_5TeV)
    gr_WW_5TeV.SetLineColor(2)
    gr_WW_5TeV.SetLineWidth(1)
    gr_WW_5TeV.SetLineStyle(1)
    gr_WW_5TeV.SetMarkerColor(2)
    gr_WW_5TeV.SetMarkerStyle(8)
    gr_WW_5TeV.SetMarkerSize(1)
Ejemplo n.º 11
0
            else:
                yarray3.append(Pre_selection)

        xarray.append(Electric_field)
        xarrayerror.append(0)
        yarrayerror.append(0)

c = TCanvas("c1", "c1", 0, 0, 500, 500)

gStyle.SetOptFit()
gr = TGraphErrors(21, xarray, yarray, xarrayerror, yarrayerror)
gr1 = TGraphErrors(21, xarray, yarray1, xarrayerror, yarrayerror)
gr2 = TGraphErrors(21, xarray, yarray2, xarrayerror, yarrayerror)
gr3 = TGraphErrors(21, xarray, yarray3, xarrayerror, yarrayerror)

gr.SetLineStyle(1)
gr.SetMarkerColor(2)
gr.SetMarkerStyle(8)
gr.SetLineWidth(2)
gr1.SetLineStyle(1)
gr1.SetMarkerColor(3)
gr1.SetMarkerStyle(8)
gr1.SetLineWidth(2)
gr2.SetLineStyle(1)
gr2.SetMarkerColor(4)
gr2.SetMarkerStyle(8)
gr2.SetLineWidth(2)
gr3.SetLineStyle(1)
gr3.SetMarkerColor(5)
gr3.SetMarkerStyle(8)
gr3.SetLineWidth(2)
Ejemplo n.º 12
0
gStyle.SetOptFit()
yarray_4K_1_gr = TGraphErrors(1000, xarray, yarray_4K_1, xarrayerror,
                              yarrayerror)
yarray_4K_2_gr = TGraphErrors(1000, xarray, yarray_4K_2, xarrayerror,
                              yarrayerror)
yarray_4K_3_gr = TGraphErrors(1000, xarray, yarray_4K_3, xarrayerror,
                              yarrayerror)
yarray_77K_1_gr = TGraphErrors(1000, xarray, yarray_77K_1, xarrayerror,
                               yarrayerror)
yarray_77K_2_gr = TGraphErrors(1000, xarray, yarray_77K_2, xarrayerror,
                               yarrayerror)
yarray_77K_3_gr = TGraphErrors(1000, xarray, yarray_77K_3, xarrayerror,
                               yarrayerror)

yarray_4K_1_gr.SetLineStyle(1)
yarray_4K_1_gr.SetMarkerColor(2)
yarray_4K_1_gr.SetMarkerStyle(8)
yarray_4K_1_gr.SetLineWidth(1)

yarray_4K_2_gr.SetLineStyle(1)
yarray_4K_2_gr.SetMarkerColor(3)
yarray_4K_2_gr.SetMarkerStyle(8)
yarray_4K_2_gr.SetLineWidth(1)

yarray_4K_3_gr.SetLineStyle(1)
yarray_4K_3_gr.SetMarkerColor(4)
yarray_4K_3_gr.SetMarkerStyle(8)
yarray_4K_3_gr.SetLineWidth(1)

yarray_77K_1_gr.SetLineStyle(1)
Ejemplo n.º 13
0
for k2,v2, in efficiencies["Cleaned"]["125"].items():
  temp.append( (int(k2),float(v2[0]), float(v2[1]) ) )
temp.sort(key=lambda tup: tup[0])
for i in temp: 
  xVals.append(i[0])
  yVals.append(i[1])
  errx.append(0)
  erry.append(i[2])
for i in range(len(erry) ): 
  print erry[i] , yVals[i] * (1 - yVals[i]), (yVals[i] * (1 - yVals[i]) / erry[i]), (yVals[i] * (1 - yVals[i]) / erry[i]) **(1/2.0)
  erry[i] = (yVals[i] * (1 - yVals[i]) / erry[i]) **(1/2.0)
g125C = TGraphErrors(9,xVals,yVals,errx,erry)
g125C.SetLineColor(ROOT.kGreen+2)
g125C.SetLineWidth(3)
g125C.SetMarkerColor(ROOT.kGreen+2)
g125C.SetLineStyle(1)
g125C.SetMarkerSize(1)
g125C.SetMarkerStyle(8)
g125C.SetTitle("")
g125C.GetXaxis().SetTitle("m_{a} GeV")
#g125C.GetXaxis().SetTitleSize(1)
g125C.GetYaxis().SetTitle("Reconstruction Efficiency")
#g125C.GetYaxis().SetTitleSize(1)

temp = []
xVals = array( 'd' )
yVals = array( 'd' )
errx = array( 'd' )
erry = array( 'd' )
for k2,v2, in efficiencies["Cleaned"]["300"].items():
  temp.append( (int(k2),float(v2[0]), float(v2[1])) )
g_purity.SetLineWidth(2)
g_acceptance.Draw("PL")
g_acceptance.SetMarkerStyle(23)
g_acceptance.SetLineColor(kGreen + 2)
g_acceptance.SetLineWidth(2)
g_reco_eff.Draw("PL")
g_reco_eff.SetLineColor(kGray + 2)
g_reco_eff.SetLineWidth(2)
g_reco_eff.SetMarkerStyle(29)
g_reco_eff.SetMarkerSize(1.5)
g_reco_eff_data.Draw("PL")
g_data_eff.Draw("PL")
g_data_eff.SetLineColor(kRed + 1)
g_data_eff.SetLineWidth(2)
g_data_eff.SetMarkerStyle(4)
g_data_eff.SetLineStyle(2)
g_reco_eff_data.SetLineColor(kGray + 2)
g_reco_eff_data.SetLineWidth(2)
g_reco_eff_data.SetMarkerStyle(30)
g_reco_eff_data.SetMarkerSize(1.5)
g_reco_eff_data.SetLineStyle(2)

l = TLegend(0.46, 0.16, 0.85, 0.425)
l.SetBorderSize(0)
l.SetShadowColor(0)

l.AddEntry(g_purity, "Purity #it{P}", "lp")
l.AddEntry(g_acceptance, "Acceptance #it{A}", "lp")

l.AddEntry(g_eff, "MuCS-MC tagging efficiency #it{#epsilon}_{tag}^{MuCS-MC}",
           "lp")
Ejemplo n.º 15
0
leg.AddEntry(jetToMETRatePlot, "MET", "l")
leg.AddEntry(jetToElectronRatePlot, "Electrons", "l")
leg.AddEntry(jetToMuonRatePlot, "Muons", "l")

## Removing stat info
#jetRatePlot.SetStats(False)
#jetToMuonRatePlot.SetStats(False)
#jetToElectronRatePlot.SetStats(False)
## jetToPhotonRatePlot.SetStats(False)
#jetToMETRatePlot.SetStats(False)

# Plotting stuff
ratePlot.Add(jetRatePlot, "A3L")
jetRatePlot.SetFillStyle(1001)
jetRatePlot.SetLineWidth(2)
jetRatePlot.SetLineStyle(1)
ratePlot.Add(jetToMuonRatePlot, "A3")
jetToMuonRatePlot.SetFillStyle(1001)
jetToMuonRatePlot.SetLineWidth(2)
jetToMuonRatePlot.SetLineStyle(1)
ratePlot.Add(jetToElectronRatePlot, "A3")
jetToElectronRatePlot.SetFillStyle(1001)
jetToElectronRatePlot.SetLineWidth(2)
jetToElectronRatePlot.SetLineStyle(1)
# ratePlot.Add(jetToPhotonRatePlot, "A3")
# jetToPhotonRatePlot.SetFillStyle(1001)
# jetToPhotonRatePlot.SetLineWidth(2)
# jetToPhotonRatePlot.SetLineStyle(1)
ratePlot.Add(jetToMETRatePlot, "A3")
jetToMETRatePlot.SetFillStyle(1001)
jetToMETRatePlot.SetLineWidth(2)
Ejemplo n.º 16
0
c1.Divide(1,2,small,small)

c1.cd(1)
gPad.SetPad(small, 0.3, 1.-small, 1.-small)
gPad.SetBottomMargin(small)

labelSize=10
makerSize = 0.3

gStyle.SetEndErrorSize(0)

gr = TGraphErrors( n, energyVec, recoEnergyVec, energyErrorVec, recoEnergyErrorVec )
gr.SetName('gr')
gr.SetLineColor( 1 )
gr.SetLineWidth( 1 )
gr.SetLineStyle( 2 )
gr.SetMarkerColor( 2 )
gr.SetMarkerStyle( 20 )
gr.SetMarkerSize( makerSize )
textsize = labelSize/(gPad.GetWh()*gPad.GetAbsHNDC())
gr.SetTitle( '' )
gr.GetXaxis().SetTitle( 'E_{particle} (GeV)' )
gr.GetYaxis().SetTitle( 'E_{reco} (GeV)' )
gr.GetYaxis().SetTitleSize(textsize)
gr.GetYaxis().SetLabelSize(textsize)
gr.GetYaxis().SetTitleOffset(1.4)
gr.GetYaxis().SetRangeUser(2, 100)
gPad.SetLeftMargin(0.15)
gr.Draw( 'AP' )

func1 = TF1('fun1', 'x', 0., 100.)
Ejemplo n.º 17
0
    y_axis_pars.append(datapoint[1])
    error_vals.append(datapoint[2])

Title = arg1 + " vs " + arg2
c1 = TCanvas("c1", Title)
#c1.SetGrid()

gr = TGraphErrors(len(x_axis_pars), x_axis_pars, y_axis_pars,
                  array('f', [0 for i in range(len(x_axis_pars))]), error_vals)

if "ke" in arg1:
    gr.GetXaxis().SetTitle(arg1 + "/MeV")
else:
    gr.GetXaxis().SetTitle(arg1 + "/mm")
if "ke" in arg2:
    gr.GetYaxis().SetTitle(arg2 + "/MeV")
else:
    gr.GetYaxis().SetTitle(arg2 + "/mm")

gr.SetTitle(Title)
gr.Fit(fit)
gr.SetMarkerStyle(5)
gr.SetMarkerColor(4)
gr.SetLineColor(1)
gr.SetLineWidth(1)
gr.SetLineStyle(1)

gr.Draw("AP")
gr.SetName(Title)
new_file.WriteTObject(gr)