Beispiel #1
0
    def draw_box(self):

        z1 = self.center_z - self.length / 2
        z2 = z1 + self.length
        x1 = self.center_x - self.rad2
        x2 = x1 + 2 * self.rad2

        #to cm
        x1 *= 100
        x2 *= 100

        #representation as a box
        self.box = TFrame(z1, x1, z2, x2)
        self.box.SetBorderMode(0)
        self.box.SetFillColor(rt.kGray + 1)
        col = rt.kRed
        if self.is_electron == True: col = rt.kBlue
        self.box.SetLineColor(col)
        self.box.SetLineWidth(2)
        #self.box.Draw("same")

        #label
        lx = x2 + 2
        align = 11
        if lx < 0 and lx > -62:
            lx = x1 - 5  # negative lx
            align = 31
        if self.center_z < 0 and self.center_x < 0.1:
            lx = x1 - 2  # negative z and x
            align = 31
        if lx > 0 and lx < 22: lx = 22  # small positive lx
        self.label = TText(z2, lx, self.name)
        self.label.SetTextSize(0.03)
        self.label.SetTextAngle(90)
        self.label.SetTextAlign(align)
Beispiel #2
0
def drawTitle(text):
    '''Takes in the title text and draws it to the top of the current pad'''
    headerText = TText(.5, .95, text)
    headerText.SetTextAlign(22)
    headerText.Draw()

    return headerText
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")
Beispiel #4
0
def timeStampCanvas(canvas):
    import rootpy
    from rootpy.plotting import Canvas
    from ROOT import TText
    import datetime
    # apply time stamp:
    text = TText()
    canvas.cd(0)  #select canvas
    text.SetTextSize(0.015)
    text.DrawTextNDC(.7, 0.008,
                     datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p"))
Beispiel #5
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)
def D1H_txt_to_root(filename, outputpath=''):
    from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText
    from inspect import currentframe, getframeinfo

    #gStyle.SetOptStat(0)
    can = TCanvas("can", "can", 200, 10, 500, 500)
    fileroot = filename.replace(".txt", "")
    fileroot = fileroot + "_F.root"
    f = open(filename, "r")

    lineList = f.readlines()
    Nbin = (len(lineList))  # get number of bins
    Line_string = str(lineList[0])
    _, bin_init, _, _ = Line_string.split()
    bin_init = float(bin_init)  # get initial bin
    Line_string = str(lineList[len(lineList) - 1])
    _, _, bin_final, _ = Line_string.split()
    bin_final = float(bin_final)  # get final bin
    f.seek(0)  # reset python read line

    hist = TH1D("h1f", "h1f", Nbin, bin_init, bin_final)
    total_e = 0
    for i in range(1, Nbin + 1):
        Line_string = str(f.readline())
        _, _, _, bin_c = Line_string.split()
        bin_c = float(bin_c)
        hist.SetBinContent(i, bin_c)
        total_e = total_e + bin_c
    total_e = int(total_e)
    hist.Draw()
    text = TText(hist.GetXaxis().GetBinCenter(2),
                 hist.GetYaxis().GetBinCenter(1),
                 "Recycled. Total Entry : %i" % total_e)
    text.SetTextFont(10)
    text.Draw()
    gPad.Update()
    can.Update()

    if (outputpath == ''):
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    else:
        fileroot = outputpath + "/_processed.root"
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    hist.Write()
    wf.Close()
    return fileroot
Beispiel #7
0
    def draw_2d(self):

        #make corner points
        vec = []
        vec.append(TVector2(self.length / 2, -self.height / 2))
        vec.append(TVector2(-self.length / 2, -self.height / 2))
        vec.append(TVector2(-self.length / 2, self.height / 2))
        vec.append(TVector2(self.length / 2, self.height / 2))

        #rotate and translate along electron beam
        vtrans = TVector2(-1, 0).Rotate(self.angle)
        vtrans.SetMagPhi(self.dist + self.length / 2, vtrans.Phi())
        for i in xrange(len(vec)):
            vec[i] = vec[i].Rotate(self.angle)
            vec[i] += vtrans

        #last point same as the first
        vec.append(vec[0])

        self.geom = TGraph(len(vec))
        self.geom.SetLineWidth(2)
        self.geom.SetLineColor(rt.kYellow + 1)
        self.geom.SetFillColor(rt.kYellow)
        for i in xrange(len(vec)):
            self.geom.SetPoint(i, vec[i].X(), vec[i].Y() * 100)

        self.geom.Draw("lfsame")

        #label
        self.label = TText(vtrans.X(),
                           (vtrans.Y() - self.height / 2 - 0.11) * 100 - 3,
                           "Lumi detector")
        self.label.SetTextSize(0.03)
        #self.label.SetTextAngle(90)
        #self.label.SetTextAlign(32)
        self.label.SetTextAlign(23)
        self.label.Draw("same")

        #label for low Q^2 tagger
        self.label_tag = TText(vtrans.X() + 2, (vtrans.Y() + 0.6) * 100 - 3,
                               "Place for low-Q2 tagger")
        self.label_tag.SetTextSize(0.03)
        #self.label.SetTextAngle(90)
        #self.label.SetTextAlign(32)
        self.label_tag.SetTextAlign(23)
        self.label_tag.Draw("same")
Beispiel #8
0
def prepare_canvas(c, channels, pad_label=None, x_label=None, y_label=None):
    pads = dict()
    # for axis labels
    c.Divide(1, 1, 0.03, 0.03)
    c.cd(1).Divide(*divide_square(len(channels)))
    for i, chans in enumerate(channels):
        ncol, nrow = divide_square(len(chans))
        c.cd(1).cd(i + 1).Divide(nrow, ncol, 0., 0.)
        # share y axis in the sub-group
        ymax = 0
        for j, ch in enumerate(chans):
            pads[ch] = c.cd(1).cd(i + 1).cd(j + 1)
    # labels
    c.cd(0)
    htext, vtext = TText(), TText()
    htext.SetTextSize(0.03)
    htext.SetTextAlign(22)
    vtext.SetTextSize(0.03)
    vtext.SetTextAlign(22)
    vtext.SetTextAngle(90)

    if pad_label:
        htext.DrawText(0.5, 0.982, pad_label)
    if x_label:
        htext.DrawText(0.5, 0.015, x_label)
    if y_label:
        vtext.DrawText(0.015, 0.5, y_label)
    return pads
Beispiel #9
0
def drawSignature(signature):
    """Write an unique identifier in the lower left canvas corner"""
    l = TText()
    l.SetTextAlign(11)
    l.SetTextSize(0.02)
    l.SetTextFont(82)
    l.DrawTextNDC(0.01, 0.01, signature)
Beispiel #10
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)
Beispiel #11
0
def writeCurrentFile(rootFile):
    ''' Save a copy of the current script, as a TText, in the current ROOT file
        nothing happens if a ROOT file is not currently open!
    '''
    import sys, os.path
    from ROOT import TString, TText, TFile
    filename = sys.argv[0]
    if (not os.path.exists(filename)):
        m_log.error("Could not open file " + filename + "!")
        return
    s = TString()
    t = TText()
    # Too fresh
    #with open(filename) as input:
    input = open(filename)
    if input:
        for line in input:
            s += line
    t.SetName(os.path.basename(filename))
    t.SetText(0, 0, s.Data())
    f = TFile(rootFile, 'UPDATE')
    t.Write()
    f.Close()
Beispiel #12
0
    def draw_2d(self):

        #draw the exit window

        self.geom = TGraph(len(self.zx_pos))
        self.geom.SetLineColor(rt.kGreen + 1)
        self.geom.SetLineWidth(4)

        ipoint = 0
        for i in self.zx_pos:
            self.geom.SetPoint(ipoint, i.X(), 100 * i.Y())
            ipoint += 1

        self.geom.Draw("lsame")

        #label

        zpos = (self.zx_pos[0].X() + self.zx_pos[1].X()) / 2.
        self.label = TText(zpos, (self.zx_pos[0].Y()) * 100 - 6, "Exit window")
        self.label.SetTextSize(0.03)
        #self.label.SetTextAngle(90)
        #self.label.SetTextAlign(32)
        self.label.SetTextAlign(23)
Beispiel #13
0
    def invert_col(self, pad):

        bgcol = rt.kBlack
        fgcol = rt.kOrange - 3

        pad.SetFillColor(bgcol)
        pad.SetFrameLineColor(fgcol)

        next = TIter(pad.GetListOfPrimitives())
        obj = next()
        while obj != None:

            #TText
            if obj.InheritsFrom(TText.Class()) == True:
                if obj.GetTextColor() == rt.kBlack:
                    obj.SetTextColor(fgcol)

            #H1
            if obj.InheritsFrom(TH1.Class()) == True:
                if obj.GetLineColor() == rt.kBlack:
                    obj.SetLineColor(fgcol)
                    obj.SetFillColor(bgcol)
                if obj.GetMarkerColor() == rt.kBlack: obj.SetMarkerColor(fgcol)
                obj.SetAxisColor(fgcol, "X")
                obj.SetAxisColor(fgcol, "Y")
                obj.SetLabelColor(fgcol, "X")
                obj.SetLabelColor(fgcol, "Y")
                obj.GetXaxis().SetTitleColor(fgcol)
                obj.GetYaxis().SetTitleColor(fgcol)

            #TFrame
            if obj.InheritsFrom(TFrame.Class()) == True:
                if obj.GetLineColor() == rt.kBlack:
                    obj.SetLineColor(fgcol)
                    obj.SetFillColor(bgcol)

            #print obj.GetName(), obj.ClassName()

            #move to the next item
            obj = next()
Beispiel #14
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
Beispiel #15
0
from ROOT import TCanvas, TF1, TPaveLabel, TPad, TText
from ROOT import gROOT

nut = TCanvas('nut', 'FirstSession', 100, 10, 700, 900)
nut.Range(0, 0, 20, 24)
nut.SetFillColor(10)
nut.SetBorderSize(2)

pl = TPaveLabel(3, 22, 17, 23.7, 'My first PyROOT interactive session', 'br')
pl.SetFillColor(18)
pl.Draw()

t = TText(0, 0, 'a')
t.SetTextFont(62)
t.SetTextSize(0.025)
t.SetTextAlign(12)
t.DrawText(
    2, 20.3,
    'PyROOT provides ROOT bindings for Python, a powerful interpreter.')
t.DrawText(2, 19.3, 'Blocks of lines can be entered typographically.')
t.DrawText(2, 18.3, 'Previous typed lines can be recalled.')

t.SetTextFont(72)
t.SetTextSize(0.026)
t.DrawText(3, 17, r'>>>  x, y = 5, 7')
t.DrawText(3, 16, r'>>>  import math; x*math.sqrt(y)')
t.DrawText(
    3, 14,
    r'>>>  for i in range(2,7): print "sqrt(%d) = %f" % (i,math.sqrt(i))')
t.DrawText(3, 10,
           r'>>>  import ROOT; f1 = ROOT.TF1( "f1", "sin(x)/x", 0, 10 )')
Beispiel #16
0
line = TLine( 2.6, 11, 2.6, 11.5 )
line.Draw()
line.DrawLine( 2.6, 11.5, 7, 11.5 )
arrow = TArrow( 7, 11.5, 7, 11.1, 0.01, '|>' )
arrow.SetFillStyle( 1001 )
arrow.Draw()
line.DrawLine( 7, 8.5, 7, 8.0 )
line.DrawLine( 7, 8.0, 10.6, 8 )
arrow.DrawArrow( 10.6,8, 10.6, 8.4, 0.01, '|>' )
line.DrawLine( 10.6, 11, 10.6, 11.5 )
line.DrawLine( 10.6, 11.5, 14.6, 11.5 )
arrow.DrawArrow( 14.6, 11.5, 14.6, 11.1, 0.01, '|>' )
line.DrawLine( 14.6, 8.5, 14.6, 8.0 )
line.DrawLine( 14.6, 8.0, 16, 8 )
ldot.DrawLine( 16, 8, 19, 8 )
vert = TText( 1.5, 9.75, 'File' )
vert.SetTextAlign( 21 )
vert.SetTextAngle( 90 )
vert.SetTextSize( 0.025 )
vert.Draw()
vert.DrawText(  2.0, 9.75, 'Header' )
vert.DrawText(  2.9, 9.75, 'Logical Record' )
vert.DrawText(  3.2, 9.75, 'Header' )
vert.DrawText(  7.3, 9.75, 'Logical Record' )
vert.DrawText(  7.6, 9.75, 'Header' )
vert.DrawText( 10.9, 9.75, 'Logical Record' )
vert.DrawText( 11.2, 9.75, 'Header' )
vert.DrawText( 14.9, 9.75, 'Logical Record' )
vert.DrawText( 15.2, 9.75, 'Header' )
hori = TText( 4.75, 10, 'Object' )
hori.SetTextAlign( 22 )
        if cpu_type == '2376':
            h_2_6.Fill(float(t_run)/60.)

c1 = TCanvas("c1","Root Canvas",40,20,800,600)

gStyle.SetOptStat(111111)

h_1.SetFillColor(36)
h_1.GetYaxis().SetTitleOffset(1.2)
h_1.SetYTitle('Entries')
h_1.SetXTitle('Time, s')
c1.SetLogy()
h_1.Draw()

t_task = TText(0.35,0.8,'Task '+ task + " SIGNET" )
t_task.SetNDC()
t_task.Draw()

#print time stamp
t_time = datetime.now()
t_label = 'SP ' + t_time.strftime("%Y-%m-%d")

t = TText(0.905,0.6,t_label)
t.SetNDC()
t.SetTextAlign(21) # middle, bottom
t.SetTextAngle(-90)
t.SetTextSize(0.017)
t.Draw()

c1.Modified()
Beispiel #18
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)
Beispiel #19
0
        gtexts = []
        dlines = []
        boxes = []
        xmin = 0

        for d_i, daughter in enumerate(daughters):
            lines = []
            levels = daughter['Levels']
            gamma = []
            if 'Gamma' in daughter:
                gamma = daughter['Gamma']
            ngamma = len(gamma)
            x_width = 2.0 * param['TextOffset'] + 2.0 * param['TextWidth'] + (
                ngamma + 1) * param['width']
            ttexts.append(
                TText(xmin + (ngamma + 1) * param['width'] / 2.0,
                      param['TitleTextOffset'], str(daughter['Name'])))

            lstyles = {}
            lcolors = {}
            for level in levels:
                xmax = xmin + (ngamma + 1) * param['width']
                lines.append(
                    TLine(xmin, level['energy'], xmax, level['energy']))
                texts.append(
                    TText(xmin - param['TextOffset'],
                          level['energy'] + param['TextFloat'],
                          str(level['level'])))
                texts[-1].SetTextAlign(31)
                texts.append(
                    TText(xmax + param['TextOffset'],
                          level['energy'] + param['TextFloat'],
Beispiel #20
0
    infile_T1t1t_1200_275_100 = TFile.Open(inputfile_T1t1t_1200_275_100)

    # Integrated luminosity in fb-1s
    intlumi = 19.712  # ABCD

    # set root styles
    plotTools.SetBoostStyle()
    tdrstyle.setTDRStyle()

    ########################################################
    # Make comparison of gen level W pt
    hname = "h_MR_jet1ptg200"
    htitle = ""
    xt = "M_{R} (GeV)"
    legd4 = plotTools.ConstructLDict(0.35, 0.9, 0.6, 0.87)
    text1 = TText(0.73, 0.55, "T1t1t model")
    text1.SetNDC()
    text1.SetTextSize(0.04)
    hdict_bg = plotTools.ConstructHDict(infile_bg.Get(hname),
                                        name="Total background",
                                        color=rt.kCyan - 8,
                                        fillstyle=3003,
                                        linewidth=0,
                                        title=htitle,
                                        xtitle=xt)
    hdict_T1t1t_600_225_50 = plotTools.ConstructHDict(
        infile_T1t1t_600_225_50.Get(hname),
        name=
        "m_{#tilde{g}} = 600 GeV, m_{#tilde{t}_{1}} = 225 GeV, m_{#tilde{#chi}_{1}^{0}} = 50 GeV",
        #name="#splitline{m_{#tilde{g}} = 600 GeV, m_{#tilde{t}_{1}} = 225 GeV,}{m_{#tilde{#chi}_{1}^{0}} = 50 GeV}",
        color=rt.kCyan + 2,
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)
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
Beispiel #23
0
texts = []
gamma = []
if 'Gamma' in data:
    gamma = data['Gamma']
arrows = []
gtexts = []
dlines = []

for i, band in enumerate(bands):
    xmin = i * (param['width'] + param['space'])
    xmax = xmin + param['width']
    xcenter = xmin + param['width'] / 2.
    levels = band['levels']
    texts.append(
        TText(
            xcenter, plot_range['ymin'] + 0.01 *
            (plot_range['ymax'] - plot_range['ymin']) + param['TextFloat'],
            band['name']))
    texts[-1].SetTextAlign(21)
    if 'color' in band:
        texts[-1].SetTextColor(band['color'])
    for level in levels:
        lines.append(TLine(xmin, level['energy'], xmax, level['energy']))
        texts.append(
            TText(xmin, level['energy'] + param['TextFloat'],
                  str(level['level'])))
        texts[-1].SetTextAlign(11)
        texts.append(
            TText(xmax, level['energy'] + param['TextFloat'],
                  str(level['energy'])))
        texts[-1].SetTextAlign(31)
        if 'noenergy' in band:
Beispiel #24
0
ar1.DrawArrow(.25, .775, .39, .775, 0.015, '|>')
ar1.DrawArrow(.50, .775, .59, .775, 0.015, '|>')
ar1.DrawArrow(.70, .775, .79, .775, 0.015, '|>')
ar1.DrawArrow(.50, .275, .59, .275, 0.015, '|>')
ar1.DrawArrow(.70, .275, .79, .275, 0.015, '|>')
ar1.DrawArrow(.45, .175, .54, .175, 0.015, '|>')
ar1.DrawArrow(.43, .075, .54, .075, 0.015, '|>')
ar1.DrawArrow(.41, -.025, .54, -.025, 0.015, '|>')
ldot = TLine(.95, .92, .99, .92)
ldot.SetLineStyle(3)
ldot.Draw()
ldot.DrawLine(.9, .775, .99, .775)
ldot.DrawLine(.9, .275, .99, .275)
ldot.DrawLine(.55, .05, .55, 0)
ldot.DrawLine(.9, .05, .75, 0)
pname = TText(.46, .21, 'fEventOffset')
pname.SetTextFont(72)
pname.SetTextSize(0.018)
pname.Draw()
pname.DrawText(.44, .11, 'fBuffer')
pname.DrawText(.42, .01, 'fZipBuffer')
pname.DrawText(.26, .81, 'fLeaves = TObjArray of TLeaf')
pname.DrawText(.24, .40, 'fBasketEvent')
pname.DrawText(.22, .31, 'fBaskets = TObjArray of TBasket')
pname.DrawText(.20, 1.0, 'fBranches = TObjArray of TBranch')
ntleaf = TPaveText(0.30, .42, .62, .7)
ntleaf.SetTextSize(0.014)
ntleaf.SetFillColor(leafcolor)
ntleaf.SetTextAlign(12)
ntleaf.AddText('fLen: number of fixed elements')
ntleaf.AddText('fLenType: number of bytes of data type')
Beispiel #25
0
file.SetTextSize(0.04)
file.AddText('TFile')
file.AddText('Header')
arrow = TArrow(6, 20.5, 17, 20.5, 0.02, '|>')
arrow.SetFillStyle(1001)
arrow.SetLineWidth(2)
arrow.Draw()
free = TPaveText(8, 20, 11, 21)
free.SetFillColor(18)
free.Draw()
free.AddText('First:Last')
free2 = TPaveText(12, 20, 15, 21)
free2.SetFillColor(18)
free2.Draw()
free2.AddText('First:Last')
tfree = TText(6.2, 21.2, 'fFree = TList of free blocks')
tfree.SetTextSize(0.02)
tfree.Draw()
tkeys = TText(5.2, 18.2, 'fKeys = TList of Keys')
tkeys.SetTextSize(0.02)
tkeys.Draw()
tmemory = TText(3.2, 15.2, 'fListHead = TList of Objects in memory')
tmemory.SetTextSize(0.02)
tmemory.Draw()

arrow.DrawArrow(5, 17, 17, 17, 0.02, '|>')
line = TLine(5, 19, 5, 17)
line.SetLineWidth(2)
line.Draw()
key0 = TPaveText(7, 16, 10, 18)
key0.SetTextSize(0.04)
Beispiel #26
0
class Calorimeter:
    '''class for calorimeter plotting'''
    #class members
    name = 'n'  #ClassVar[TString]
    range_min = 0  #ClassVar[float]
    range_max = 0  #ClassVar[float]
    content = []  #ClassVar[list[float]] #of float
    ombox = []  #ClassVar[list[TBox]] #of TBox
    omtext = []  #ClassVar[list[TText]] #of TText
    source_foil = TLine()  #ClassVar[TLine]
    it_label = ''  #ClassVar[TText]
    fr_label = ''  #ClassVar[TText]
    canvas = None  #ClassVar[TCanvas]
    palette_index = 0  #ClassVar[int]
    fiber_map_lines = np.array([TLine])
    ncalo = 712  #ClassVar[int]
    nmwall = 520
    nxwall = 128
    ngveto = 64

    #constructor of calorimeter
    for calo in range(ncalo):
        content.append(0)

    range_min = range_max = -1

    spacerx = 0.0125
    spacery = 0.0250

    mw_sizey = (1 - 4 * spacery) / (13 + 2)
    gv_sizey = mw_sizey
    xw_sizey = mw_sizey * 13. / 16.

    mw_sizex = (0.5 - 4 * spacerx) / (20 + 4)
    gv_sizex = mw_sizex * 20. / 16.
    xw_sizex = mw_sizex

    for mw0 in range(2):
        for mw1 in range(20):
            for mw2 in range(13):
                id = mw0 * 20 * 13 + mw1 * 13 + mw2
                x1 = spacerx + 2 * xw_sizex + spacerx + 0.5 * mw0 + mw_sizex * (
                    mw1)
                if (mw0 == 1):
                    #swap french in case of internal view
                    x1 = spacerx + 2 * xw_sizex + spacerx + 0.5 * mw0 + mw_sizex * (
                        19 - mw1)
                y1 = spacery + gv_sizey + spacery + mw_sizey * mw2
                x2 = x1 + mw_sizex
                y2 = y1 + mw_sizey
                box = TBox(x1, y1, x2, y2)
                box.SetFillColor(0)
                box.SetLineWidth(1)
                ombox.append(box)

                text = TText(
                    x1 + 0.33 * mw_sizex, y1 + 0.33 * mw_sizey,
                    str(id).zfill(3)
                )  # "{:10.4f}".format(xid))#, TString::Form("%03d",id))
                text.SetTextSize(0.02)
                omtext.append(text)

    for xw0 in range(2):
        for xw1 in range(2):
            for xw2 in range(2):
                for xw3 in range(16):
                    id = 520 + xw0 * 2 * 2 * 16 + xw1 * 2 * 16 + xw2 * 16 + xw3
                    # x1 = 0
                    if xw0 == 0:
                        if xw1 == 0:
                            x1 = spacerx + xw_sizex * xw2
                        elif xw1 == 1:
                            x1 = spacerx + 2 * xw_sizex + spacerx + 20 * mw_sizex + spacerx + (
                                1 - xw2) * xw_sizex

                    elif xw0 == 1:  #wall ID
                        if xw1 == 0:  #side ID
                            x1 = 0.5 + spacerx + 2 * xw_sizex + spacerx + 20 * mw_sizex + spacerx + (
                                1 - xw2) * xw_sizex
                        elif xw1 == 1:
                            x1 = 0.5 + spacerx + xw_sizex * xw2

                    x2 = x1 + xw_sizex

                    y1 = spacery + gv_sizey + spacery + xw_sizey * (xw3)
                    y2 = spacery + gv_sizey + spacery + xw_sizey * (xw3 + 1)

                    box = TBox(x1, y1, x2, y2)
                    box.SetFillColor(0)
                    box.SetLineWidth(1)
                    ombox.append(box)

                    text = TText(x1 + 0.33 * mw_sizex, y1 + 0.33 * mw_sizey,
                                 str(id).zfill(3))
                    text.SetTextSize(0.02)
                    omtext.append(text)

    for gv0 in range(2):
        for gv1 in range(2):
            for gv2 in range(16):
                id = 520 + 128 + gv0 * 2 * 16 + gv1 * 16 + gv2
                # x1 = 0
                if gv0 == 0:  #side ID 1
                    x1 = spacerx + 2 * xw_sizex + spacerx + gv_sizex * gv2

                elif gv0 == 1:  #wall ID 0
                    x1 = 0.5 + spacerx + 2 * xw_sizex + spacerx + gv_sizex * (
                        16 - 1 - gv2)

                x2 = x1 + gv_sizex
                y1 = spacery + gv1 * (gv_sizey + spacery + 13 * mw_sizey +
                                      spacery)
                y2 = y1 + gv_sizey
                box = TBox(x1, y1, x2, y2)
                box.SetFillColor(0)
                box.SetLineWidth(1)
                ombox.append(box)

                text = TText(x1 + 0.33 * gv_sizex, y1 + 0.33 * gv_sizey,
                             str(id).zfill(3))
                text.SetTextSize(0.02)
                omtext.append(text)

    source_foil = TLine(0.5, spacery, 0.5, 1 - spacery)
    source_foil.SetLineWidth(2)

    it_label = TText(
        spacerx, spacery + gv_sizey + spacery + 13 * mw_sizey + spacery +
        0.25 * gv_sizey, "ITALY")
    fr_label = TText(
        0.5 + spacerx, spacery + gv_sizey + spacery + 13 * mw_sizey + spacery +
        0.25 * gv_sizey, "FRANCE")

    it_label.SetTextSize(0.036)
    fr_label.SetTextSize(0.036)

    #fiber map
    line_h_IT = TLine(0.25 - 10 * mw_sizex, 2 * spacery + 9 * mw_sizey,
                      0.25 + 10 * mw_sizex, 2 * spacery + 9 * mw_sizey)
    line_v_A1A2_IT = TLine(0.25, 2 * spacery + 9 * mw_sizey, 0.25,
                           2 * spacery + 14 * mw_sizey)
    line_v_A3A4_IT = TLine(0.25 - 4 * mw_sizex, 2 * 0.025 + mw_sizey,
                           0.25 - 4 * mw_sizex, 2 * spacery + 9 * mw_sizey)
    line_v_A4A5_IT = TLine(0.25 + 4 * mw_sizex, 2 * 0.025 + mw_sizey,
                           0.25 + 4 * mw_sizex, 2 * spacery + 9 * mw_sizey)

    line_h_FR = TLine(0.75 - 10 * mw_sizex, 2 * spacery + 9 * mw_sizey,
                      0.75 + 10 * mw_sizex, 2 * spacery + 9 * mw_sizey)
    line_v_A1A2_FR = TLine(0.75, 2 * 0.025 + 9 * mw_sizey, 0.75,
                           2 * spacery + 14 * mw_sizey)
    line_v_A3A4_FR = TLine(0.75 - 4 * mw_sizex, 2 * spacery + mw_sizey,
                           0.75 - 4 * mw_sizex, 2 * spacery + 9 * mw_sizey)
    line_v_A4A5_FR = TLine(0.75 + 4 * mw_sizex, 2 * spacery + mw_sizey,
                           0.75 + 4 * mw_sizex, 2 * spacery + 9 * mw_sizey)

    line_veto_top_IT = TLine(0.25, 3 * spacery + 14 * mw_sizey, 0.25,
                             3 * spacery + 15 * mw_sizey)
    line_veto_bottom_left_IT = TLine(0.25 - 4 * gv_sizex, spacery,
                                     0.25 - 4 * gv_sizex, spacery + mw_sizey)
    line_veto_bottom_right_IT = TLine(0.25 + 4 * gv_sizex, spacery,
                                      0.25 + 4 * gv_sizex, spacery + mw_sizey)
    line_veto_top_FR = TLine(0.75, 3 * spacery + 14 * mw_sizey, 0.75,
                             3 * spacery + 15 * mw_sizey)
    line_veto_bottom_left_FR = TLine(0.75 - 4 * gv_sizex, spacery,
                                     0.75 - 4 * gv_sizex, spacery + mw_sizey)
    line_veto_bottom_right_FR = TLine(0.75 + 4 * gv_sizex, spacery,
                                      0.75 + 4 * gv_sizex, spacery + mw_sizey)

    line_xw_left_IT = TLine(spacerx, 0.5 + 2 * xw_sizey,
                            spacerx + 2 * xw_sizex, 0.5 + 2 * xw_sizey)
    line_xw_right_IT = TLine(0.5 - spacerx - 2 * xw_sizex, 0.5 + 2 * xw_sizey,
                             0.5 - spacerx, 0.5 + 2 * xw_sizey)
    line_xw_left_FR = TLine(0.5 + spacerx, 0.5 + 2 * xw_sizey,
                            0.5 + spacerx + 2 * xw_sizex, 0.5 + 2 * xw_sizey)
    line_xw_right_FR = TLine(1 - spacerx - 2 * xw_sizex, 0.5 + 2 * xw_sizey,
                             1 - spacerx, 0.5 + 2 * xw_sizey)

    fiber_map_lines = np.array([line_h_IT, line_v_A1A2_IT, line_v_A3A4_IT, line_v_A4A5_IT, \
                                     line_h_FR, line_v_A1A2_FR, line_v_A3A4_FR, line_v_A4A5_FR, \
                                     line_veto_top_IT, line_veto_bottom_left_IT, line_veto_bottom_right_IT, \
                                     line_veto_top_FR, line_veto_bottom_left_FR, line_veto_bottom_right_FR, \
                                     line_xw_right_IT, line_xw_left_IT, \
                                     line_xw_right_FR, line_xw_left_FR])

    nRGBs = 6
    stops = np.array([0.00, 0.20, 0.40, 0.60, 0.80, 1.00])
    red = np.array([0.25, 0.00, 0.20, 1.00, 1.00, 0.90])
    green = np.array([0.25, 0.80, 1.00, 1.00, 0.80, 0.00])
    blue = np.array([1.00, 1.00, 0.20, 0.00, 0.00, 0.00])

    palette_index = TColor.CreateGradientColorTable(nRGBs, stops, red, green,
                                                    blue, 100)

    def setrange(self, xmin, xmax):
        self.range_min = xmin
        self.range_max = xmax
        return 0

    def draw(self, fiber_map=False):
        if (self.canvas == None):
            self.canvas = TCanvas(self.name, "SuperNEMO calorimeter", 1750,
                                  500)
            self.canvas.SetEditable(True)
            self.canvas.cd()

        for mw0 in range(2):
            for mw1 in range(20):
                for mw2 in range(13):
                    id = mw0 * 20 * 13 + mw1 * 13 + mw2

                    self.ombox[id].Draw("l")
                    self.omtext[id].Draw()

        for xw0 in range(2):
            for xw1 in range(2):
                for xw2 in range(2):
                    for xw3 in range(16):
                        id = 520 + xw0 * 2 * 2 * 16 + xw1 * 2 * 16 + xw2 * 16 + xw3
                        self.ombox[id].Draw("l")
                        self.omtext[id].Draw()

        for gv0 in range(2):
            for gv1 in range(2):
                for gv2 in range(16):
                    id = 520 + 128 + gv0 * 2 * 16 + gv1 * 16 + gv2
                    self.ombox[id].Draw("l")
                    self.omtext[id].Draw()

        self.source_foil.Draw()
        self.it_label.Draw()
        self.fr_label.Draw()

        if fiber_map == True:
            for line in self.fiber_map_lines:
                line.SetLineColor(kBlack)
                line.SetLineStyle(9)
                line.SetLineWidth(3)
                line.Draw()

        self.canvas.SetEditable(False)
        gSystem.ProcessEvents()
        return 0

    def reset(self):
        for calo in range(self.ncalo):
            self.content[calo] = 0
            # for calo=0; calo<self.ncalo; ++calo)
            self.ombox[calo].SetFillColor(0)

        self.canvas.Modified()
        self.canvas.Update()
        gSystem.ProcessEvents()

        return 0

    def setcontent(self, pmt, value):
        self.content[pmt] = value
        return 0

    def update(self):
        content_min = self.content[0]
        content_max = self.content[0]

        if (self.range_min == -1):
            for calo in range(1, self.ncalo):
                if (self.content[calo] < content_min):
                    content_min = self.content[calo]
                if (self.content[calo] > content_max):
                    content_max = self.content[calo]
        else:
            self.range_min = 0
            content_max = self.range_max

        for calo in range(self.ncalo):
            if (self.content[calo] != 0):
                self.ombox[calo].SetFillColor(self.palette_index + (
                    int)(99 * (self.content[calo] - content_min) /
                         (content_max - content_min)))
            else:
                self.ombox[calo].SetFillColor(0)

        self.canvas.Modified()
        self.canvas.Update()
        gSystem.ProcessEvents()
        return 0

    def save_canvas(self):
        self.canvas.SaveAs('sncalorimeter.png')
        return 0
Beispiel #27
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 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)
Beispiel #29
0
def D1H_txt_to_roothist(filename, outputpath=''):
    from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText
    from inspect import currentframe, getframeinfo
    import os

    #gStyle.SetOptStat(0)
    can = TCanvas("can", "can", 200, 10, 500, 500)

    if (filename[0] == "/"):
        filename = filename
    else:
        filename = os.getcwd(
        ) + "/" + filename  # get the path included filename
    loca = len(filename)
    for i in range(1, len(filename) + 1):  # find the "/" location
        if (filename[-i] == "/"):
            loca = i - 1
            break

    FILENAME = filename.replace(filename[:-loca],
                                "")  # this is the shorten filename
    #    print(FILENAME, "******")

    fileroot = filename.replace(".txt", "_F.root")
    fileroot = fileroot.replace("//", "/")
    f = open(filename, "r")

    lineList = f.readlines()
    Nbin = (len(lineList))  # get number of bins
    Line_string = str(lineList[0])
    _, bin_init, _, _ = Line_string.split()
    bin_init = float(bin_init)  # get initial bin
    Line_string = str(lineList[len(lineList) - 1])
    _, _, bin_final, _ = Line_string.split()
    bin_final = float(bin_final)  # get final bin
    f.seek(0)  # reset python read line

    hist = TH1D("hist", "hist", Nbin, bin_init, bin_final)
    total_e = 0
    for i in range(1, Nbin + 1):
        Line_string = str(f.readline())
        _, _, _, bin_c = Line_string.split()
        bin_c = float(bin_c)
        hist.SetBinContent(i, bin_c)
        total_e = total_e + bin_c
    total_e = int(total_e)
    hist.Draw()
    text = TText(hist.GetXaxis().GetBinCenter(2),
                 hist.GetYaxis().GetBinCenter(1),
                 "Recycled. Total Entry : %i" % total_e)
    text.SetTextFont(10)
    text.Draw()
    gPad.Update()
    can.Update()

    if (outputpath == ''):
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    else:
        if (outputpath[0] == "/"):
            fileroot = outputpath + "/" + FILENAME.replace(".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        elif (outputpath[0] == "~"):
            fileroot = outputpath.replace(
                "~", os.environ['HOME']) + "/" + FILENAME.replace(
                    ".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        else:
            fileroot = os.getcwd() + "/" + outputpath + "/" + FILENAME.replace(
                ".txt", "_F.root")
            fileroot = fileroot.replace("//", "/")
        wf = TFile(fileroot, "RECREATE")
        print(fileroot, " root file is generated !!!")
    hist.Write()
    wf.Close()
    fileroot = fileroot.replace("//", "/")
    #    print(fileroot)
    return fileroot
Beispiel #30
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)