Esempio n. 1
0
def makeBeamspotCutPlots(name, points):
    nPoints = len(points)

    x = TGraphErrors(nPoints)
    x.SetName(name)
    x.SetTitle(name + "  x; lb; x [mm]")
    y = TGraphErrors(nPoints)
    y.SetName(name)
    y.SetTitle(name + "  y; lb; y [mm]")
    z = TGraphErrors(nPoints)
    z.SetName(name)
    z.SetTitle(name + "  z; lb; z [mm]")
    sx = TGraphErrors(nPoints)
    sx.SetName(name)
    sx.SetTitle(name + "  sx; lb; #sigma(x) [mm]")
    sy = TGraphErrors(nPoints)
    sy.SetName(name)
    sy.SetTitle(name + "  sy; lb; #sigma(y) [mm]")
    sz = TGraphErrors(nPoints)
    sz.SetName(name)
    sz.SetTitle(name + "  sz; lb; #sigma(z) [mm]")

    xrms = TGraphErrors(nPoints)
    xrms.SetName(name + "_rms")
    xrms.SetTitle(name + "_rms" + "  x")
    yrms = TGraphErrors(nPoints)
    yrms.SetName(name + "_rms")
    yrms.SetTitle(name + "_rms" + "  y")
    zrms = TGraphErrors(nPoints)
    zrms.SetName(name + "_rms")
    zrms.SetTitle(name + "_rms" + "  z")
    sxrms = TGraphErrors(nPoints)
    sxrms.SetName(name + "_rms")
    sxrms.SetTitle(name + "_rms" + "  sx")
    syrms = TGraphErrors(nPoints)
    syrms.SetName(name + "_rms")
    syrms.SetTitle(name + "_rms" + "  sy")
    szrms = TGraphErrors(nPoints)
    szrms.SetName(name + "_rms")
    szrms.SetTitle(name + "_rms" + "  sz")

    graphs.extend([x, y, z, sx, sy, sz, xrms, yrms, zrms, sxrms, syrms, szrms])
    print len(points)
    for i in range(len(points)):
        xval = points[i][0]
        yvals = points[i][1]

        xerr = 0

        x.SetPoint(i, xval, yvals[0][0])
        y.SetPoint(i, xval, yvals[1][0])
        z.SetPoint(i, xval, yvals[2][0])
        sx.SetPoint(i, xval, yvals[3][0])
        sy.SetPoint(i, xval, yvals[4][0])
        sz.SetPoint(i, xval, yvals[5][0])

        x.SetPointError(i, xerr, yvals[0][1])
        y.SetPointError(i, xerr, yvals[1][1])
        z.SetPointError(i, xerr, yvals[2][1])
        sx.SetPointError(i, xerr, yvals[3][1])
        sy.SetPointError(i, xerr, yvals[4][1])
        sz.SetPointError(i, xerr, yvals[5][1])

        xrms.SetPoint(i, xval, yvals[0][2])
        yrms.SetPoint(i, xval, yvals[1][2])
        zrms.SetPoint(i, xval, yvals[2][2])
        sxrms.SetPoint(i, xval, yvals[3][2])
        syrms.SetPoint(i, xval, yvals[4][2])
        szrms.SetPoint(i, xval, yvals[5][2])

        xrms.SetPointError(i, xerr, yvals[0][3])
        yrms.SetPointError(i, xerr, yvals[1][3])
        zrms.SetPointError(i, xerr, yvals[2][3])
        sxrms.SetPointError(i, xerr, yvals[3][3])
        syrms.SetPointError(i, xerr, yvals[4][3])
        szrms.SetPointError(i, xerr, yvals[5][3])

    c = TCanvas("cx")
    c.Divide(3, 1)
    c.cd(1)
    x.Draw("ap")
    c.cd(2)
    y.Draw("ap+Y+")
    c.cd(3)
    yaxis_xrms = TGaxis(-1, 0.2, 1, 0.2, -1, 2, 510, "+R")
    yaxis_xrms.ImportAxisAttributes(y.GetHistogram().GetYaxis())
    #g = TMultiGraph()
    #g.Add(x,"aXp")
    #g.Add(y,"aY*")
    #g.Draw("a")
    # graphs.append(g)
    #   aa = y.GetHistogram()

    #x.Draw("ap")
    yaxis_xrms.Draw()
    #axis.PaintAxis(0,0.5,0.1,0.6,0.4,1.4,510,"+R")
    #y.Draw("pY+sames")
    #b.Draw("sames")
    c.Modified()
    c.Update()
    #c.Print()
    canvases.append(c)
Esempio n. 2
0
    def __reweightCanvas(self, can, addLabels, addTopXNumbers):
        import numpy as np, ROOT
        from ROOT import TGaxis, TLatex, kBlack
        if can.GetPrimitive('pad_top'):
            self.__reweightCanvas(can.GetPrimitive('pad_top'), False,
                                  addTopXNumbers)
        if can.GetPrimitive('pad_bot'):
            self.__reweightCanvas(can.GetPrimitive('pad_bot'), self.addLabels,
                                  False)
        if can.GetPrimitive('pad_bot') or can.GetPrimitive('pad_bot'): return
        can.cd()
        # First we "remove" previous axis
        xaxis = GetXaxis(can)
        # Now create new axis
        #xaxis.SetName("__xaxis_ignored")
        # Now draw new canvas
        #xmin, xmax = GetXaxisRanges(can)
        #import os
        #c = ROOT.TCanvas(self.func.GetName(),self.func.GetName())
        #self.func.Draw()
        #c.SaveAs( os.path.join( 'e26_RunByRun_noAdjustment', c.GetName() +'.pdf' ) )
        #can.cd()
        #chopt = "+C" + ("U" if not addLabels else "")
        chopt = "+CU"
        axis = TGaxis(can.GetUxmin(), can.GetUymin(), can.GetUxmax(),
                      can.GetUymin(), self.func.GetName(),
                      10000 * self.N3 + 100 * self.N2 + 1 * self.N1, chopt)
        axis.SetNoExponent(False)
        #axis.SetExponentOffset()
        if xaxis:
            axis.ImportAxisAttributes(xaxis)
            xaxis.SetTickLength(0)
            xaxis.SetLabelOffset(999.)
        if self.labelSize: axis.SetLabelSize(self.labelSize)
        #1 + 100*N2 + *N3N
        axis.Draw()
        from .PlotFunctions import tobject_collector
        if addTopXNumbers:
            _, ymax = GetYaxisRanges(can,
                                     check_all=True,
                                     ignorezeros=True,
                                     ignoreErrors=False)
            for xc in self.xcenters:
                text = TLatex(self.func.Eval(xc), ymax, str(xc))
                text.SetTextFont(43)
                text.SetTextSize(2)
                text.SetTextAlign(12)
                text.SetTextAngle(90)
                text.SetTextColor(ROOT.kBlack)
                text.Draw()
                tobject_collector.append(text)
        if addLabels:
            binLow, binHigh, nBins = self.__getXEdges(chopt)
            #labelPos = map( lambda x: (x,self.func.GetX(x),(self.func.GetX(x)-self.xedges[0])/(self.xedges[-1]-self.xedges[0]))
            #              , np.linspace(binLow,binHigh, nBins) )
            labelPos = map(
                lambda x:
                (x, self.func.Eval(x), (self.func.Eval(x) - self.xedges[0]) /
                 (self.xedges[-1] - self.xedges[0])),
                np.linspace(binLow, binHigh, nBins))
            ypos = can.GetUymin() - 0.04 * (can.GetUymax() - can.GetUymin())
            #labels = []
            for x, mx, pmx in labelPos:
                text = TLatex(mx, ypos, str(x))
                text.SetTextFont(43)
                #text.SetTextSizePixels(textPerc)
                text.SetTextAlign(23)
                text.SetTextColor(ROOT.kBlack)
                text.SetTextSize(14)
                text.Draw()
                tobject_collector.append(text)
                #labels.append(text)
            #gxc = (self.xedges[-1]-self.xedges[0] )/2
            #lLabels = len(labels)
            #for i, text in enumerate(labels):
            #    xc = text.GetBBoxCenter()
            #    if xc < gxc:
            #        if i+1 < lLabels:
            #            text2 = labels[i+1]
            #            while conflict(text.GetBBox(),text2.GetBBox()):
            #                sizes[i] = possible_sizes[sizes[i]+1]
            #                 text.SetTextSize( getNewSize

        ##AdjustBinSize (Double_t A1, Double_t A2, Int_t nold, Double_t &BinLow, Double_t &BinHigh, Int_t &nbins, Double_t &BinWidth)
        #lLabels = [labels.At(i) for i in range(labels.GetEntries())]
        tobject_collector.append(axis)
        #can.Modified()
        #can.Update()
        return axis