예제 #1
0
    def plotNSamples(cls, npatterns, etBins, etaBins, outname='nPatterns.pdf'):
        """Plot number of samples per bin"""
        logger = Logger.getModuleLogger("PlotNSamples")
        from ROOT import TCanvas, gROOT, kTRUE, kFALSE, TH2I, TText
        gROOT.SetBatch(kTRUE)
        c1 = TCanvas("plot_patterns_signal", "a", 0, 0, 800, 400)
        c1.Draw()
        shape = [len(etBins) - 1, len(etaBins) - 1]
        histo1 = TH2I(
            "text_stats",
            "#color[4]{Signal}/#color[2]{Background} available statistics",
            shape[0], 0, shape[0], shape[1], 0, shape[1])
        #histo1 = TH2I("text_stats", "Signal/Background available statistics", shape[0], 0, shape[0], shape[1], 0, shape[1])
        histo1.SetStats(kFALSE)
        histo1.Draw("TEXT")
        histo1.SetXTitle("E_{T}")
        histo1.SetYTitle("#eta")
        histo1.GetXaxis().SetTitleSize(0.04)
        histo1.GetYaxis().SetTitleSize(0.04)
        histo1.GetXaxis().SetLabelSize(0.04)
        histo1.GetYaxis().SetLabelSize(0.04)
        histo1.GetXaxis().SetTickSize(0)
        histo1.GetYaxis().SetTickSize(0)
        ttest = TText()
        ttest.SetTextAlign(22)
        for etBin in range(shape[0]):
            for etaBin in range(shape[1]):
                key = 'et%d_eta%d' % (etBin, etaBin)
                ttest.SetTextColor(4)
                ttest.DrawText(.5 + etBin, .75 + etaBin,
                               's: ' + str(npatterns['sgnPattern_' + key]))

                ttest.SetTextColor(2)
                ttest.DrawText(.5 + etBin, .25 + etaBin,
                               'b: ' + str(npatterns['bkgPattern_' + key]))

                try:
                    histo1.GetYaxis().SetBinLabel(
                        etaBin + 1, '#bf{%d} : %.2f->%.2f' %
                        (etaBin, etaBins[etaBin], etaBins[etaBin + 1]))
                except Exception:
                    logger.error("Couldn't retrieve eta bin %d bounderies.",
                                 etaBin)
                    histo1.GetYaxis().SetBinLabel(etaBin + 1, str(etaBin))
                try:
                    histo1.GetXaxis().SetBinLabel(
                        etBin + 1, '#bf{%d} : %d->%d [GeV]' %
                        (etBin, etBins[etBin], etBins[etBin + 1]))
                except Exception:
                    logger.error("Couldn't retrieve et bin %d bounderies.",
                                 etBin)
                    histo1.GetXaxis().SetBinLabel(etBin + 1, str(etaBin))
        c1.SetGrid()
        c1.Update()
        c1.SaveAs(outname)
def rooFit106():

    print ">>> setup model..."
    x = RooRealVar("x", "x", -3, 3)
    mean = RooRealVar("mean", "mean of gaussian", 1, -10, 10)
    sigma = RooRealVar("sigma", "width of gaussian", 1, 0.1, 10)
    gauss = RooGaussian("gauss", "gauss", x, mean, sigma)
    data = gauss.generate(RooArgSet(x), 10000)  # RooDataSet
    gauss.fitTo(data)

    print ">>> plot pdf and data..."
    frame = x.frame(Name("frame"), Title("RooPlot with decorations"),
                    Bins(40))  # RooPlot
    data.plotOn(frame)
    gauss.plotOn(frame)

    print ">>> RooGaussian::paramOn - add box with pdf parameters..."
    # https://root.cern.ch/doc/master/classRooAbsPdf.html#aa43b2556a1b419bad2b020ba9b808c1b
    # Layout(Double_t xmin, Double_t xmax, Double_t ymax)
    # left edge of box starts at 20% of x-axis
    gauss.paramOn(frame, Layout(0.55))

    print ">>> RooDataSet::statOn - add box with data statistics..."
    # https://root.cern.ch/doc/master/classRooAbsData.html#a538d58020b296a1623323a84d2bb8acb
    # x size of box is from 55% to 99% of x-axis range, top of box is at 80% of y-axis range)
    data.statOn(frame, Layout(0.20, 0.55, 0.8))

    print ">>> add text and arrow..."
    text = TText(2, 100, "Signal")
    text.SetTextSize(0.04)
    text.SetTextColor(kRed)
    frame.addObject(text)

    arrow = TArrow(2, 100, -1, 50, 0.01, "|>")
    arrow.SetLineColor(kRed)
    arrow.SetFillColor(kRed)
    arrow.SetLineWidth(3)
    frame.addObject(arrow)

    print ">>> persist frame with all decorations in ROOT file..."
    file = TFile("rooFit106.root", "RECREATE")
    frame.Write()
    file.Close()

    # To read back and plot frame with all decorations in clean root session do
    #   [0] TFile f("rooFit106.root")
    #   [1] xframe->Draw()

    print ">>> draw functions and toy data on canvas..."
    canvas = TCanvas("canvas", "canvas", 100, 100, 800, 600)
    gPad.SetLeftMargin(0.15)
    gPad.SetRightMargin(0.05)
    frame.GetYaxis().SetTitleOffset(1.6)
    frame.GetYaxis().SetLabelOffset(0.010)
    frame.GetYaxis().SetTitleSize(0.045)
    frame.GetYaxis().SetLabelSize(0.042)
    frame.GetXaxis().SetTitleSize(0.045)
    frame.GetXaxis().SetLabelSize(0.042)
    frame.Draw()
    canvas.SaveAs("rooFit106.png")
예제 #3
0
def markPad(text, x=0.14, y=0.007, size=0.013, color=1, canvas=None, npad=-1):
    """
    Puts a line of text on a specific canvas and pad. If none are specified, the current pad is used
    """
    import rootpy
    from rootpy.plotting import Canvas
    from ROOT import TText
    t = TText()
    if npad >= 0 and canvas:
        canvas.cd(npad)  #select pad (0 = whole canvas)
    t.SetTextSize(size)
    t.SetTextColor(color)
    t.DrawTextNDC(x, y, text)
예제 #4
0
def main():

    cc.cd()
    cc.SetBorderMode(0)
    cc.SetFixedAspectRatio(1)
    cc.FeedbackMode(1)

    gStyle.SetOptStat(0)
    gStyle.SetGridStyle(1)
    gStyle.SetGridColor(11)
    hh = TH2D('hh', ';Y;X', 2, 2, 4, 14, 2, 16)
    hi = TH2I('hi', ';Y;X', 2, 2, 4, 14, 2, 16)
    setupHists([hh, hi])
    xax, yax = hh.GetXaxis(), hh.GetYaxis()
    hh.Draw('COLZ')
    hi.Draw('TEXTSAME')

    gPad.SetLogz()
    gPad.SetGrid(1, 1)
    gPad.SetLeftMargin(0.05)
    gPad.SetRightMargin(0.12)

    tt1 = TPaveText(0.05, 0.94, 0.22, 1.0, 'NDC')
    ttL = TPaveText(0.05, 0.905, 0.2, 0.93, 'NDC')
    ttR = TPaveText(0.75, 0.905, 0.9, 0.93, 'NDC')

    ttLM = TPaveText(2, 0.5, 2.5, 1)
    ttRM = TPaveText(3.5, 0.5, 4, 1)

    ttM = TPaveText(0.6, 0.94, 0.9, 1, 'NDC')
    ttime = TPaveText(2.8, 1.5, 3.3, 1.9)
    tchan = TPaveText(0, 0, 0.9, 1)
    setupPaveTexts([tt1, ttM, ttime, tchan, ttL, ttR, ttLM, ttRM])
    ttM.SetTextColor(2)

    tarrow = TText(2.9, 0.25, 'Beam Left')
    arrow = TArrow(2.85, 0.5, 2.75, 0.5, 0.02, '|>')
    arrow.SetAngle(40)
    arrow.SetFillColor(1)
    arrow.SetLineWidth(2)

    tt = TText()
    tt.SetTextColor(1)
    tt.SetTextAngle(90)
    tt.SetTextSize(0.04)
    tt.DrawText(4.07, 9, 'kHz')
    tt.SetTextAngle(0)
    tt.SetTextColor(2)
    tt.DrawTextNDC(0.23, 0.905, 'SHMS PCAL FADC SCALERS')
    ttL.AddText('Left+')
    ttR.AddText('-Right')

    cc.cd()
    for xx in [ttM, tt1, ttL, ttR, arrow, tarrow, ttime, ttLM, ttRM]:
        xx.Draw()
    cc2.cd()
    tchan.Draw('NDC')
    cc.cd()

    xmin, xmax = xax.GetXmin(), xax.GetXmax()
    ymin, ymax = yax.GetXmin(), yax.GetXmax()

    gPad.SetEditable(0)

    while True:

        zvals = getScalars()

        for ii in range(len(zvals)):
            hh.SetBinContent(xax.FindBin(XVALS[ii] + 1),
                             yax.FindBin(16 - YVALS[ii]), zvals[ii])
            hi.SetBinContent(xax.FindBin(XVALS[ii] + 1),
                             yax.FindBin(16 - YVALS[ii]), zvals[ii])

        for xx in [ttime, ttM, tt1, ttLM, ttRM]:
            xx.Clear()
        [left, right, maximum] = calcRates(zvals)
        tt1.AddText('Total:  %.1f MHz' % ((left + right) / 1000))
        ttLM.AddText('Left total: %.1f MHz' % (left / 1000))
        ttRM.AddText('Right total: %.1f MHz' % (right / 1000))
        ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz' % (maximum))
        ttime.AddText(makeTime())

        if not gPad: sys.exit()

        #if gPad.GetEvent()==11:
        #   xy=pix2xy(gPad)
        #ee=ECAL.findChannelXY(xy[0],xy[1])
        #if ee:
        #   tchan.Clear()
        #tchan.AddText(printChannel(ee))
        #  cc2.Modified()
        #  cc2.Update()
        #elif gPad.GetEvent()==12:
        #   tchan.Clear()
        #  cc2.Modified()
        # cc2.Update()

        cc.Modified()
        cc.Update()

        time.sleep(1)
def setLHCbStyle():
    global lhcbStyle
    global lhcbText
    global lhcbLatex

    lhcbStyle = TStyle("lhcbStyle", "Standard LHCb plots style")

    # use times new roman
    lhcbFont = 132
    # line thickness
    lhcbWidth = 2
    lhcbTSize = 0.06

    #// use plain black on white colors
    lhcbStyle.SetFrameBorderMode(0)
    lhcbStyle.SetCanvasBorderMode(0)
    lhcbStyle.SetPadBorderMode(0)
    lhcbStyle.SetPadColor(0)
    lhcbStyle.SetCanvasColor(0)
    lhcbStyle.SetStatColor(0)
    lhcbStyle.SetPalette(1)

    lhcbStyle.SetLegendBorderSize(0)
    lhcbStyle.SetLegendFont(132)
    lhcbStyle.SetFillColor(1)
    lhcbStyle.SetFillStyle(1001)

    # set the paper & margin sizes
    lhcbStyle.SetPaperSize(20, 26)

    lhcbStyle.SetPadTopMargin(0.1)

    lhcbStyle.SetPadRightMargin(0.05)
    lhcbStyle.SetPadBottomMargin(0.16)
    lhcbStyle.SetPadLeftMargin(0.14)

    # use large fonts
    lhcbStyle.SetTextFont(lhcbFont)
    lhcbStyle.SetTextSize(lhcbTSize)
    #  lhcbStyle.SetTextSize(0.08)
    lhcbStyle.SetLabelFont(lhcbFont, "x")
    lhcbStyle.SetLabelFont(lhcbFont, "y")
    lhcbStyle.SetLabelFont(lhcbFont, "z")
    lhcbStyle.SetLabelSize(lhcbTSize, "x")
    lhcbStyle.SetLabelSize(lhcbTSize, "y")
    lhcbStyle.SetLabelSize(lhcbTSize, "z")
    lhcbStyle.SetTitleFont(lhcbFont)
    lhcbStyle.SetTitleFont(lhcbFont, "x")
    lhcbStyle.SetTitleFont(lhcbFont, "y")
    lhcbStyle.SetTitleFont(lhcbFont, "z")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "x")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "y")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "z")

    # use bold lines and markers
    lhcbStyle.SetLineWidth(lhcbWidth)
    lhcbStyle.SetFrameLineWidth(lhcbWidth)
    lhcbStyle.SetHistLineWidth(lhcbWidth)
    lhcbStyle.SetFuncWidth(lhcbWidth)
    lhcbStyle.SetGridWidth(lhcbWidth)
    lhcbStyle.SetLineStyleString(2, "[12 12]")
    lhcbStyle.SetMarkerStyle(20)
    lhcbStyle.SetMarkerSize(1.0)

    # label offsets
    lhcbStyle.SetLabelOffset(0.010)

    #titles
    lhcbStyle.SetTitleOffset(0.95, "X")
    lhcbStyle.SetTitleOffset(0.95, "Y")
    lhcbStyle.SetTitleOffset(1.2, "Z")
    lhcbStyle.SetTitleFillColor(0)
    lhcbStyle.SetTitleStyle(0)
    lhcbStyle.SetTitleBorderSize(0)
    lhcbStyle.SetTitleFont(lhcbFont, "title")
    lhcbStyle.SetTitleX(0.0)
    lhcbStyle.SetTitleY(1.0)
    lhcbStyle.SetTitleW(1.0)
    lhcbStyle.SetTitleH(0.05)

    # by default, do not display histogram decorations:
    lhcbStyle.SetOptStat(0)
    #lhcbStyle.SetOptStat("emr")     # show only nent -e , mean - m , rms -r
    #lhcbStyle.SetStatFormat("6.3g") # specified as c printf options
    lhcbStyle.SetOptTitle(0)
    lhcbStyle.SetOptFit(0)
    #lhcbStyle.SetOptFit(1011) # order is probability, Chi2, errors, parameters

    # look of the statistics box:
    lhcbStyle.SetStatBorderSize(0)
    lhcbStyle.SetStatFont(lhcbFont)
    lhcbStyle.SetStatFontSize(0.05)
    lhcbStyle.SetStatX(0.93)
    lhcbStyle.SetStatY(0.88)
    lhcbStyle.SetStatW(0.20)
    lhcbStyle.SetStatH(0.15)

    # put tick marks on top and RHS of plots
    lhcbStyle.SetPadTickX(1)
    lhcbStyle.SetPadTickY(1)

    # histogram divisions: only 5 in x to avoid label overlaps
    lhcbStyle.SetNdivisions(505, "x")
    lhcbStyle.SetNdivisions(505, "y")
    lhcbStyle.SetNdivisions(505, "z")

    # define style for text
    lhcbLabel = TText()
    lhcbLabel.SetTextFont(lhcbFont)
    lhcbLabel.SetTextColor(1)
    lhcbLabel.SetTextSize(0.04)
    lhcbLabel.SetTextAlign(12)

    # define style of latex text
    lhcbLatex = TLatex()
    lhcbLatex.SetTextFont(lhcbFont)
    lhcbLatex.SetTextColor(1)
    lhcbLatex.SetTextSize(0.04)
    lhcbLatex.SetTextAlign(12)

    # set this style
    gROOT.SetStyle("lhcbStyle")
    gROOT.ForceStyle()
    return
예제 #6
0
def main():

    cc.cd()
    cc.SetBorderMode(0)
    cc.SetFixedAspectRatio(1)
    cc.FeedbackMode(1)

    gStyle.SetOptStat(0)
    gStyle.SetGridStyle(0)
    gStyle.SetGridColor(18)

    nbinsX = 0
    for ix in range(len(SECTORSPERREGION)):
        nbinsX += SECTORSPERREGION[ix]
    hh = TH2D('hh', ';Strip;Sector', STRIPSPERSECTOR, 0, STRIPSPERSECTOR,
              nbinsX, 0, nbinsX)
    setupHists([hh])
    hh.Draw('COLZ')

    gPad.SetLogz()
    gPad.SetLeftMargin(0.09)
    gPad.SetRightMargin(0.11)

    tt2 = TPaveText(240, 43, 500, 45)
    ttime = TPaveText(100, -5.5, 412, -3)
    setupPaveTexts([tt2, ttime])
    tt2.SetTextSize(0.03)

    lll = TLine()
    lll.SetLineColor(15)
    y1 = SECTORSPERREGION[0]
    y2 = SECTORSPERREGION[0] + SECTORSPERREGION[1]
    lll.DrawLine(0, y1, STRIPSPERSECTOR, y1)
    lll.DrawLine(0, y2, STRIPSPERSECTOR, y2)

    tt = TText()
    tt.SetTextColor(1)
    tt.SetTextAngle(90)
    tt.SetTextSize(0.04)
    tt.DrawText(532, 22, 'Hz')
    tt.SetTextSize(0.06)
    tt.SetTextAngle(0)
    tt.SetTextColor(1)
    tt.DrawTextNDC(0.1, 0.93, 'SVT Scalers')

    tt.SetTextSize(0.03)
    tt.DrawText(-42, 4, 'R1')
    tt.DrawText(-42, 16, 'R2')
    tt.DrawText(-42, 32, 'R3')

    cc.cd()
    for xx in [ttime, tt2]:
        xx.Draw()
    cc.cd()

    gPad.SetEditable(0)

    while True:

        iy = 0
        for ch in SVT.chans:
            loadPV(ch)
            ch = ch.vals
            data = ch['PVVAL']
            time2 = ch['PVTIMEVAL']

            if time2 > 10:
                print 'More than 10 seconds since message:  ' + ch['PVNAME']
                for ii in range(512):
                    data[ii] = 0

            if iy < SECTORSPERREGION[0]:
                region = 1
                sector = iy
            elif iy < SECTORSPERREGION[0] + SECTORSPERREGION[1]:
                region = 2
                sector = iy - SECTORSPERREGION[0]
            else:
                region = 3
                sector = iy - SECTORSPERREGION[0] - SECTORSPERREGION[1]

            if data == None or len(data) != STRIPSPERSECTOR:
                print 'Error Reading ' + ch['PVNAME']
                continue
            for ix in range(STRIPSPERSECTOR):
                hh.SetBinContent(ix, iy + 1, data[ix])
            iy += 1

        for xx in [ttime, tt2]:
            xx.Clear()

        [r1, r2, r3] = calcRates(SVT.chans)
        tt2.AddText('Sums:  R1 / R2 / R3 = %.2E / %.2E / %.2E Hz' %
                    (r1, r2, r3))

        ttime.AddText(makeTime())

        if not gPad: sys.exit()

        cc.Modified()
        cc.Update()

        time.sleep(POLLPERIOD)
예제 #7
0
    def plotL1AndTightL1Counters(self):
        hEvent = self.fileHandler.getHistogram('count/Events_Count')
        hAllL1 = self.fileHandler.getHistogram('count/L1Muon_Count')
        hAllL13x3 = self.fileHandler.getHistogram('count/L1Muon3x3_Count')
        hTightL1 = self.fileHandler.getHistogram('count/L1TightMuons_Count')
        hTightL13x3 = self.fileHandler.getHistogram(
            'count/L1TightMuons3x3_Count')

        hL1 = self.fileHandler.getHistogram('count/energyDeposit_L1_Count')
        hL1Reco = self.fileHandler.getHistogram(
            'count/energyDeposit_L1Reco_Count')
        hL1RecoHo = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoHo_Count')
        hL1RecoHoTight = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoHoTight_Count')
        hL1RecoTight = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoTight_Count')
        hL1RecoTightHo = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoTightHo_Count')
        hL1RecoHoNoThr = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoHoNoThr_Count')
        hL1RecoGaHoNoThr = self.fileHandler.getHistogram(
            'count/energyDeposit_L1RecoGaHoNoThr_Count')

        histogramList = [
            hEvent, hL1, hL1Reco, hL1RecoHo, hL1RecoHoTight, hL1RecoTight,
            hL1RecoTightHo, hL1RecoHoNoThr, hL1RecoGaHoNoThr
        ]

        names = [
            'hEvent', 'hL1', 'hL1Reco', 'hL1RecoHo', 'hL1RecoHoTight',
            'hL1RecoTight', 'hL1RecoTightHo', 'hL1RecoHoNoThr',
            'hL1RecoGaHoNoThr'
        ]
        nL1 = hL1.GetBinContent(2)

        self.commandLine.output(
            '###############################################')
        for i, h in enumerate(histogramList):
            self.commandLine.output('%-20s:%8d\t=> %6.2f%% +/- %5.2f%%' %
                                    (names[i], h.GetBinContent(2),
                                     calcPercent(h.GetBinContent(2), nL1),
                                     calcSigma(h.GetBinContent(2), nL1) * 100))
        self.commandLine.output(
            '###############################################')

        nL1Reco = hL1Reco.GetBinContent(2)
        nL1RecoHo = hL1RecoHo.GetBinContent(2)
        nL1RecoHoTight = hL1RecoHoTight.GetBinContent(2)
        nL1RecoTight = hL1RecoTight.GetBinContent(2)
        nL1RecoTightHo = hL1RecoTightHo.GetBinContent(2)

        N_BINS = 4

        binContents = [nL1, nL1Reco, nL1RecoHo, nL1RecoHoTight]
        binLabels = [
            'L1', 'L1 -> Reco', 'L1 + R -> HO', 'L1 + R + HO -> tight'
        ]

        binContentsInverted = [nL1, nL1Reco, nL1RecoTight, nL1RecoTightHo]
        binLabelsInverted = [
            'L1', 'L1 -> Reco', 'L1 + R -> tight', 'L1 + R + tight -> HO'
        ]

        c = TCanvas('cL1AndTightL1Count', 'L1AndTightL1Count')

        h = TH1D('hL1AndTightL1Count', 'L1 Cutflow', 4, -0.5, N_BINS - .5)
        hInverted = TH1D('hL1AndTightL1CountInverted', 'L1 Efficiency', 4,
                         -0.5, N_BINS - .5)
        hInverted.SetFillStyle(3002)
        hInverted.SetFillColor(colorRwthOrange)
        hInverted.SetLineColor(colorRwthOrange)
        hInverted.SetLineStyle(3)

        hL13x3Alone = TH1D('hL1And3x3Alone', '', 1, 1.5, 2.5)
        hL13x3Alone.SetBinContent(1, nL1RecoHo / nL1Reco)
        hL13x3Alone.SetBinError(1, calcSigma(nL1RecoHo, nL1Reco))
        hL13x3Alone.SetLineColor(colorRwthMagenta)

        hTightL13x3Alone = TH1D('hTightL1And3x3Alone', '', 1, 2.5, 3.5)
        hTightL13x3Alone.SetBinContent(1, nL1RecoHoTight / nL1RecoHo)
        hTightL13x3Alone.SetBinError(1, calcSigma(nL1RecoHoTight, nL1RecoHo))
        hTightL13x3Alone.SetLineColor(colorRwthTuerkis)

        for i in range(2, N_BINS + 1):
            h.SetBinContent(i, binContents[i - 1] / binContents[1])
            h.GetXaxis().SetBinLabel(i, binLabels[i - 1])
            hInverted.SetBinContent(
                i, binContentsInverted[i - 1] / binContentsInverted[1])
            hInverted.GetXaxis().SetBinLabel(i, binLabelsInverted[i - 1])

        h.GetXaxis().SetBinLabel(1, 'L1')
        h.SetBinContent(1, 1)
        hInverted.GetXaxis().SetBinLabel(1, 'L1')
        hInverted.SetBinContent(1, 1)

        h.SetLineColor(colorRwthDarkBlue)
        h.SetStats(0)
        h.GetYaxis().SetTitle('rel. fraction')
        h.Draw()
        #		hL13x3Alone.Draw('same e')
        #		hTightL13x3Alone.Draw('same e')
        hInverted.Draw('same')
        hInverted.GetXaxis().Draw('same')

        setupAxes(h)

        legend = getLegend(y2=.9, x1=.55)
        legend.AddEntry(h, 'First match HO then use tight', 'l')
        #		legend.AddEntry(hL13x3Alone,'3x3 matching normed to # L1 + R','le')
        #		legend.AddEntry(hTightL13x3Alone,'Normed to # L1 + R + HO','l')
        legend.AddEntry(hInverted, 'Inverted order for HO and tight', 'f')
        legend.Draw()

        label = self.drawLabel()

        textObjects = []

        #for (Int_t i=1;i<=30;i++) t.DrawText(h->GetBinCenter(i),yt,Form("%d",i%10));
        for i in range(1, 4):
            t = TText()
            t.SetTextSize(0.025)
            t.SetTextAlign(22)
            t.SetTextColor(colorRwthOrange)
            t.DrawTextNDC(getXinNDC(hInverted.GetBinCenter(i + 1)), 0.05,
                          binLabelsInverted[i])
            #			Double_t yt = - h->GetMaximum()/15.;
            textObjects.append(t)
        c.Update()
        self.storeCanvas(c, 'l1AndTightL1Counters')

        return h, c, hL13x3Alone, hTightL13x3Alone, label, legend, hInverted, textObjects
예제 #8
0
def drawColorTable(clist=range(0, 50),
                   nrow=None,
                   ncol=None,
                   cmax=10,
                   tag="",
                   label=False,
                   RBG=False,
                   newRBG=True,
                   div=2):
    # https://root.cern.ch/doc/master/src_2TPad_8cxx_source.html#l01611

    if not ncol:
        ncol = min(cmax, len(clist))
    if not nrow:
        nrow = 1 if len(clist) <= cmax else int(ceil(len(clist) / float(cmax)))
    x1 = y1 = 0.
    x2 = y2 = 20.
    hs = (y2 - y1) / nrow
    ws = (x2 - x1) / ncol
    if label or RBG:
        width = 170 * ncol
        height = 80 * nrow
    else:
        width = 110 * ncol
        height = 80 * nrow
    scale = 400. / height
    if 400. < height: scale = sqrt(scale)
    canvas = TCanvas("c", "Fill Area colors", 0, 0, width, height)
    canvas.SetFillColor(0)
    canvas.Clear()
    canvas.Range(x1, y1, x2, y2)

    text = TText(0, 0, "")
    text.SetTextFont(61)
    text.SetTextSize(0.07 * scale)
    text.SetTextAlign(22)
    box = TBox()

    for r in range(0, nrow):
        ylow = y2 - hs * (r + 0.1)
        yup = y2 - hs * (r + 0.9)
        for c in range(0, ncol):
            i = ncol * r + c
            if i >= len(clist): break
            xlow = x1 + ws * (c + 0.1)
            xup = x1 + ws * (c + 0.9)
            color = clist[ncol * r + c]
            box.SetFillStyle(1001)
            box.SetFillColor(color)
            box.DrawBox(xlow, ylow, xup, yup)
            box.SetFillStyle(0)
            box.SetLineColor(1)
            box.DrawBox(xlow, ylow, xup, yup)
            if color == 1: text.SetTextColor(0)
            else: text.SetTextColor(1)
            name = "%d" % color
            if (isinstance(label, int) and i % div == label) or label:
                name = getColorString(color)
            if (not isinstance(RBG, bool) and isinstance(RBG, int)
                    and i % div == RBG) or (RBG
                                            and not isinstance(label, int)):
                name = getRGBString(color)
            elif newRBG and color >= 924:
                name = getRGBString(color)
            text.DrawText(0.5 * (xlow + xup), 0.5 * (ylow + yup), name)
        if i >= len(clist): break

    canvas.SaveAs("TColorTable%s.png" % tag)
    canvas.SaveAs("TColorTable%s.pdf" % tag)
예제 #9
0
def main():

    if True:
        mf=TGMainFrame(gClient.GetRoot(),1500,475)
        gvf=TGVerticalFrame(mf,1500,475)
        rec=TRootEmbeddedCanvas("ccc",gvf,1500,450)
        rec2=TRootEmbeddedCanvas("ccc2",gvf,1500,25)
        gvf.AddFrame(rec,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsTop))
        gvf.AddFrame(rec2,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsBottom))
        mf.AddFrame(gvf,TGLayoutHints(ROOT.kLHintsExpandX))
        cc=rec.GetCanvas()
        cc2=rec2.GetCanvas()
        mf.SetEditable(0)
        mf.SetWindowName('HPS ECAL FADC SCALERS')
        mf.MapSubwindows()
        mf.Resize(1501,476)# resize to get proper frame placement
        mf.MapWindow()
    else:
        cc=TCanvas('cc','',1500,450)
   
    cc.cd()
    cc.SetBorderMode(0)
    cc.SetFixedAspectRatio(1)
    cc.FeedbackMode(1)
    
    gStyle.SetOptStat(0)
    gStyle.SetGridStyle(1)
    gStyle.SetGridColor(11)

    hh=TH2D('hh',';X;Y',46,-22,24,11,-5,6)
    hi=TH2I('hi',';X;Y',46,-22,24,11,-5,6)
    setupHists([hh,hi])
    xax,yax=hh.GetXaxis(),hh.GetYaxis()
    hh.Draw('COLZ')
    hi.Draw('TEXTSAME')
    
    gPad.SetLogz()
    gPad.SetGrid(1,1)
    gPad.SetLeftMargin(0.05)
    
    tt1=TPaveText(0.1,0.9,0.3,1.0,'NDC')
    tt2=TPaveText(0.7,0.91,0.9,0.99,'NDC')
    ttT=TPaveText(-22+13+0.05,6-5,-22+22,7-5-0.05)
    ttB=TPaveText(-22+13+0.05,4-5+0.05,-22+22,5-5)
    ttM=TPaveText(-22+0+0.05,5-5+0.05,-22+13,6-5.01)
    ttime=TPaveText(-10,-6.5,10,-5.8)
    tchan=TPaveText(0,0,0.9,1)
    setupPaveTexts([tt1,tt2,ttT,ttB,ttM,ttime,tchan])
    ttM.SetTextColor(2)
    
    bb=TBox()
    bb.SetFillStyle(1001)
    bb.SetFillColor(0)
    bb.SetLineWidth(1)
    bb.SetLineColor(1)
    bb.DrawBox(-9+0.05,-1,0,1.97)
    bb.DrawBox(-24,0,24.05,0.97)
    
    tarrow=TText(14.5,0.3,'Beam Left')
    arrow=TArrow(19,0.5,23,0.5,0.02,'|>')
    arrow.SetAngle(40)
    arrow.SetFillColor(1)
    arrow.SetLineWidth(2)
    
    tt=TText()
    tt.SetTextColor(1)
    tt.SetTextAngle(90)
    tt.SetTextSize(0.08)
    tt.DrawText(25.4,0,'kHz')
    tt.SetTextAngle(0)
    tt.SetTextColor(2)
    tt.DrawTextNDC(0.3,0.92,'ECAL FADC SCALERS')
   
    cc.cd()
    for xx in [tt2,ttT,ttB,ttM,arrow,tarrow,ttime]: xx.Draw()
    cc2.cd()
    tchan.Draw('NDC')
    cc.cd()
    
    ll=TLine()
    ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmax(),yax.GetXmin())
    ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmax(),yax.GetXmax())
    ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmin(),0)
    ll.DrawLine(xax.GetXmax(),yax.GetXmin(),xax.GetXmax(),0)
    ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmin(),1)
    ll.DrawLine(xax.GetXmax(),yax.GetXmax(),xax.GetXmax(),1)
    ll.DrawLine(xax.GetXmax(),0,0,0)
    ll.DrawLine(xax.GetXmax(),1,0,1)
    ll.DrawLine(xax.GetXmin(),0,-9,0)
    ll.DrawLine(xax.GetXmin(),1,-9,1)
    ll.DrawLine(-9,-1,0,-1)
    ll.DrawLine(-9,2,0,2)
    ll.DrawLine(-9,1,-9,2)
    ll.DrawLine(-9,-1,-9,0)
    ll.DrawLine(0,-1,0,0)
    ll.DrawLine(0,1,0,2)
   
    gPad.SetEditable(0)

    while True:

#        try:

            zvals=getPVS()
            for ii in range(len(zvals)):
                hh.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii])
                hi.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii])
            
            for xx in [ttime,tt2,ttT,ttB,ttM]: xx.Clear()
            [top,bottom,maximum]=calcRates(zvals)
            tt2.AddText('Total:  %.1f MHz'%((top+bottom)/1000))
            ttT.AddText('%.1f MHz'%(top/1000))
            ttB.AddText('%.1f MHz'%(bottom/1000))
            ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz'%(maximum))
            ttime.AddText(makeTime())
          
            if gPad.GetEvent()==11:
                xy=pix2xy(gPad)
                ee=ECAL.findChannelXY(xy[0],xy[1])
                if ee:
                    tchan.Clear()
                    tchan.AddText(printChannel(ee))
                    cc2.Modified()
                    cc2.Update()
            elif gPad.GetEvent()==12:
                tchan.Clear()
                cc2.Modified()
                cc2.Update()
    
    
            cc.Modified()
            cc.Update()
        
            time.sleep(1)
예제 #10
0
def main():

    cc.cd()
    cc.SetBorderMode(0)
    cc.SetFixedAspectRatio(1)
    cc.FeedbackMode(1)

    gStyle.SetOptStat(0)
    gStyle.SetGridStyle(1)
    gStyle.SetGridColor(11)

    hh=TH2D('hh',';X;Y',22,-10.5,11.5,22,-10.5,11.5)
    hi=TH2I('hi',';X;Y',22,-10.5,11.5,22,-10.5,11.5)
    setupHists([hh,hi])
    xax,yax=hh.GetXaxis(),hh.GetYaxis()
    hh.Draw('COLZ')
    hi.Draw('TEXTSAME')

    gPad.SetLogz()
    gPad.SetGrid(1,1)
    gPad.SetLeftMargin(0.09)
    gPad.SetRightMargin(0.11)

    #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC')
    ttM=TPaveText(-3+0.05, 7-4.45, 4.0, 8-4.51)
    tt2=TPaveText(-3+0.05, 7-5.45, 4.0, 8-5.51)

    ttX=TPaveText(-2, 7-8.00, 3, 8-8.00)
    ttY=TPaveText(-2, 7-9.00, 3, 8-9.00)
    ttZ=TPaveText(-2, 6-8.80, 3, 8-9.30)
    ttZ.AddText("positive = beam top/right")

    ttime=TPaveText(-10,-12.5,10,-11.8)
    tchan=TPaveText(0,0,0.9,1)
    setupPaveTexts([tt2,ttM,ttime,tchan,ttX,ttY,ttZ])
    ttM.SetTextColor(2)
    ttM.SetFillStyle(0)
    ttZ.SetFillStyle(0)
    tt2.SetFillStyle(0)

    tarrow=TText(-0.9,0.7,'Beam Right')
    tarrow.SetTextSizePixels(15)
    arrow=TArrow(-1.4,0.5,2.4,0.5,0.02,'|>')
    arrow.SetAngle(40)
    arrow.SetFillColor(1)
    arrow.SetLineWidth(2)

    tt=TText()
    tt.SetTextColor(1)
    tt.SetTextAngle(90)
    tt.SetTextSize(0.04)
    tt.DrawText(12.4,0,'kHz')
    tt.SetTextAngle(0)
    tt.SetTextColor(1)
    tt.DrawTextNDC(0.3,0.92,'FTC FADC SCALERS')

    bb=TBox()
    bb.SetFillStyle(1001)
    bb.SetFillColor(0)
    bb.SetLineWidth(1)
    bb.SetLineColor(1)
    bb.DrawBox(-3.47,-1.47,4.47,2.46)
    bb.DrawBox(-1.47,-3.47,2.49,4.47)
    bb.DrawBox(-2.47,-2.47,3.49,3.47)

    cc.cd()
    for xx in [ttM,tt2,ttime,arrow,tarrow,ttX,ttY,ttZ]: xx.Draw()
    cc2.cd()
    tchan.Draw('NDC')
    cc.cd()

    gPad.SetEditable(0)

    while True:

            for ch in ECAL.chans:
              loadPV(ch)
              ch=ch.vals
              xx,yy=ch['X'],ch['Y']
              #if (ch['PVVAL']>10):
               # print xx,yy,ch['PVVAL']

              # swap x to make it downstream view:
              xx=-xx

              #after, fix the fact x=0 / y=0 don't exists
              if xx<0: xx+=1
              if yy<0: yy+=1
              hh.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL'])
              hi.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL'])

            for xx in [ttime,tt2,ttM,ttX,ttY]: xx.Clear()
            [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans)

            tt2.AddText('Total:  %.1f MHz'%(total/1000))
            ttM.AddText('Max:  %.0f kHz'%(maximum))

            if total>1e2:
              xasy = (right-left)/total
              yasy = (top-bottom)/total
              ttX.AddText('X-Asy:  %+.1f%%'%(100*xasy))
              ttY.AddText('Y-Asy:  %+.1f%%'%(100*yasy))
            else:
              ttX.AddText('X-Asy:  N/A')
              ttY.AddText('Y-Asy:  N/A')

            ttime.AddText(makeTime())

            if not gPad: sys.exit()

            if gPad.GetEvent()==11:
                xy=pix2xy(gPad)
                ee=ECAL.findChannelXY(xy[0],xy[1])
                if ee:
                    tchan.Clear()
                    tchan.AddText(printChannel(ee))
                    cc2.Modified()
                    cc2.Update()
            elif gPad.GetEvent()==12:
                tchan.Clear()
                cc2.Modified()
                cc2.Update()


            cc.Modified()
            cc.Update()

            time.sleep(2)
예제 #11
0
    leg1 = TLegend(0.1, 0.65, 0.6, 0.9)
    leg1.SetFillColor(0)
    leg1.SetFillStyle(0)
    leg1.SetTextSize(0.05)
    leg1.SetBorderSize(0)
    leg1.SetTextFont(22)
    leg1.AddEntry(G1, "M(Z')=5TeV", "l")
    leg1.AddEntry(G2, "M(Z')=10TeV", "l")
    leg1.AddEntry(G3, "M(Z')=20TeV", "l")
    leg1.AddEntry(G4, "M(Z')=40TeV", "l")

    t = TText()
    t.SetTextAlign(20)
    t.SetTextSize(0.03)
    t.SetTextFont(22)
    t.SetTextColor(1)
    label = ["20*20", "5*5", "1*1"]
    for i in range(3):
        t.DrawText(i + 1, -0.03, label[i])
    c.Draw()
    mg.Draw()
    leg.Draw()
    leg1.Draw()

    #    c.Print("raw_"+str(cut_value)+"_tau21_summary_U_after_cut_25bins_no_UOF.pdf")
    c.Print("raw_" + str(cut_value) +
            "_tau21_summary_U_after_cut_25bins_no_UOF_new_75pa.eps")

if (variable[k + 1] == "tau32"):
    f1 = ROOT.TFile.Open(
        "/Users/ms08962476/github/MannWhitneyUrawhit/codes/raw_" +
예제 #12
0
def main():

    cc.cd()
    cc.SetBorderMode(0)
    cc.SetFixedAspectRatio(1)
    cc.FeedbackMode(1)

    gStyle.SetOptStat(0)
    gStyle.SetGridStyle(1)
    gStyle.SetGridColor(18)

    hh = TH2D('hh', ';X;Y', 8 * 28, 0, 28, 8 * 23, 0, 23)
    hi = TH2I('hi', ';X;Y', 8 * 28, 0, 28, 8 * 23, 0, 23)
    setupHists([hh, hi])
    xax, yax = hh.GetXaxis(), hh.GetYaxis()
    hh.Draw('COLZ')
    hh.SetMinimum(1)
    hh.SetMaximum(1.5e3)
    #hi.Draw('TEXTSAME')

    gPad.SetLogz()
    gPad.SetGrid(1, 1)
    gPad.SetLeftMargin(0.09)
    gPad.SetRightMargin(0.11)

    #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC')
    ttM = TPaveText(-3 + 0.05, 7 - 4.45, 4.0, 8 - 4.51)
    tt2 = TPaveText(-3 + 0.05, 7 - 5.45, 4.0, 8 - 5.51)

    ttX = TPaveText(-2, 7 - 8.00, 3, 8 - 8.00)
    ttY = TPaveText(-2, 7 - 9.00, 3, 8 - 9.00)

    ttime = TPaveText(8, -2, 20, -1)
    tchan = TPaveText(0, 0, 0.9, 1)
    setupPaveTexts([tt2, ttM, ttime, tchan, ttX, ttY])
    ttM.SetTextColor(2)
    ttM.SetFillStyle(0)
    tt2.SetFillStyle(0)

    tt = TText()
    tt.SetTextColor(1)
    tt.SetTextAngle(90)
    tt.SetTextSize(0.04)
    tt.DrawText(29.5, 10, 'kHz')
    tt.SetTextAngle(0)
    tt.SetTextColor(1)
    tt.DrawTextNDC(0.3, 0.92, 'RICH SSP Scalers')

    #    bb=TBox()
    #    bb.SetFillStyle(1001)
    #    bb.SetFillColor(0)
    #    bb.SetLineWidth(1)
    #    bb.SetLineColor(1)
    #    bb.DrawBox(-3.47,-1.47,4.47,2.46)
    #    bb.DrawBox(-1.47,-3.47,2.49,4.47)
    #    bb.DrawBox(-2.47,-2.47,3.49,3.47)

    cc.cd()
    for xx in [ttime]:
        xx.Draw()  #ttM,tt2,ttime,ttX,ttY]: xx.Draw()
    cc2.cd()
    tchan.Draw('NDC')
    cc.cd()

    gPad.SetEditable(0)

    while True:

        for ch in ECAL.chans:
            loadPV(ch)
            ch = ch.vals
            xx, yy = ch['X'], ch['Y']
            data = ch['PVVAL']

            for ix in range(8):
                for iy in range(8):
                    ii = ix * 8 + iy
                    #print ch['PVNAME'],data[ii]
                    xoff = float(ix) / 8
                    yoff = float(iy) / 8

                    hh.SetBinContent(xax.FindBin(xx + xoff),
                                     yax.FindBin(yy + yoff), data[ii])


#                  hi.SetBinContent(xax.FindBin(xx+xoff),yax.FindBin(yy+yoff),data[ii])
#
        for xx in [ttime]:
            ttime.Clear()  # xx.,tt2,ttM,ttX,ttY]: xx.Clear()
        #            [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans)

        #            tt2.AddText('Total:  %.1f MHz'%(total/1000))
        #            ttM.AddText('Max:  %.0f kHz'%(maximum))

        #            if total>1e2:
        #              xasy = (right-left)/total
        #              yasy = (top-bottom)/total
        #              ttX.AddText('X-Asy:  %+.1f%%'%(100*xasy))
        #              ttY.AddText('Y-Asy:  %+.1f%%'%(100*yasy))
        #            else:
        #              ttX.AddText('X-Asy:  N/A')
        #              ttY.AddText('Y-Asy:  N/A')

        ttime.AddText(makeTime())

        if not gPad: sys.exit()

        #            if gPad.GetEvent()==11:
        #                xy=pix2xy(gPad)
        #                ee=ECAL.findChannelXY(xy[0],xy[1])
        #                if ee:
        #                    tchan.Clear()
        #                    tchan.AddText(printChannel(ee))
        #                    cc2.Modified()
        #                    cc2.Update()
        #            elif gPad.GetEvent()==12:
        #                tchan.Clear()
        #                cc2.Modified()
        #                cc2.Update()

        cc.Modified()
        cc.Update()

        time.sleep(1)