Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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 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
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()
c1.Update()

# optional wait for keypress
input = raw_input('Press Enter to continue, E to exit')
if 'E' in input:
    c1.Close()


h_2.SetFillColor(37)
h_2.GetYaxis().SetTitleOffset(1.2)
Ejemplo n.º 7
0
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 )
hori.SetTextSize( 0.035 )
Ejemplo n.º 8
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
Ejemplo n.º 9
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 )')
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    hs= THStack("hs","")
    hs.Add(h1)
    hs.Add(h2)
    
    h1.SetLineColor(ROOT.kBlue)
    h2.SetLineColor(ROOT.kRed)
    h1.SetTitle(file1Name.replace(".root",""))
    h2.SetTitle(file2Name.replace(".root",""))
    
    #h1.Draw()
    #h2.Draw("same")
    hs.Draw()
    
    T = TText()
    T.SetTextFont(42)
    T.SetTextAlign(21)
    T.DrawTextNDC(.5,.95,var)

    c1.BuildLegend(0.66, 0.87, 0.93, 0.77, "")
    c1.SetTitle(var)
    #c.cd()
    #Tl = ROOT.TLatex(0.5,0.9,var)
    #Tl.SetTextSize(0.04)
    #Tl.SetTextAlign(13)
    #Tl.Draw()

    pdfName=var+"_"+file1Name.replace(".root","")+"_vs_"+file2Name.replace(".root","")
    c1.SaveAs("plots/"+pdfName+".pdf")

#/lstore/cms/cbeiraod/Stop4Body/puWeights
#/lstore/cms/dbastos/Stop4Body/nTuples_v2018-04-03/
Ejemplo n.º 12
0
    mg.GetXaxis().SetTitleSize(0.05)
    mg.GetYaxis().SetTitleSize(0.05)

    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")
Ejemplo n.º 13
0
class photon_detector(object):
    #_____________________________________________________________________________
    def __init__(self):
        #length, height and distance of the front side from the origin, all in m
        self.length = 8.
        self.height = 0.15
        self.dist = 23.2
        self.angle = -0.025  # rotation to be on electron beam axis

    #_____________________________________________________________________________
    def rotate(self, theta):
        #rotate by angle theta about the origin
        self.angle += theta

    #_____________________________________________________________________________
    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")
Ejemplo n.º 14
0
class vmagnet(object):
    #_____________________________________________________________________________
    def __init__(self):
        #set magnet from configuration dictionary
        self.name = ""
        self.center_z = 0.
        self.center_x = 0.
        self.length = 0.
        self.rad1 = 0.
        self.rad2 = 0.
        self.field = 0.
        #electron or hadron
        self.is_electron = True
        #initial angle
        self.theta_0 = 0.
        #parameters from MAD-X survey
        self.S = 0.
        self.L = 0.
        self.X = 0.
        self.Z = 0.
        self.THETA = 0.
        self.has_survey = False
        #drawing configuration
        self.fill_style = 1000
        self.label_down = False
        self.label = ""
        self.no_label = False
        self.line_col = rt.kBlue
        self.fill_col = rt.kGreen - 2

    #_____________________________________________________________________________
    def read_survey(self, lin):
        #values from MAD-X survey

        self.S = float(lin["S"])
        self.L = float(lin["L"])
        self.X = float(lin["X"])
        self.Z = float(lin["Z"])
        self.THETA = float(lin["THETA"]) + self.theta_0
        self.has_survey = True

    #_____________________________________________________________________________
    def rotate_translateX(self, theta, xt):

        #combined rotation and translation
        self.rotate(theta)
        self.translateX(xt)

    #_____________________________________________________________________________
    def translateX(self, xt):

        #translate the magnet along x

        self.center_x += xt

    #_____________________________________________________________________________
    def rotate(self, theta):
        #rotate by angle theta about the origin

        #get new center_z and center_x by TVector2 rotation
        vec = TVector2(self.center_z, self.center_x).Rotate(theta)
        self.center_z = vec.X()
        self.center_x = vec.Y()

        #rotate along magnet center
        self.THETA = self.THETA - theta

    #_____________________________________________________________________________
    def draw_2d(self):

        #draw only magnets with survey defined
        if not self.has_survey: return

        #self.draw_box()
        self.draw_graph()

    #_____________________________________________________________________________
    def draw_graph(self):

        #inner and outer radius
        if self.center_z < 0:
            rad_right = self.rad1
            rad_left = self.rad2
        else:
            rad_right = self.rad2
            rad_left = self.rad1

        #edge points of the magnet
        vec = []
        vec.append(TVector2(self.length / 2, rad_right))
        vec.append(TVector2(self.length / 2, -rad_right))
        vec.append(TVector2(-self.length / 2, -rad_left))
        vec.append(TVector2(-self.length / 2, rad_left))

        #rotate along magnet axis and move to magnet center
        vpos = TVector2(self.center_z, self.center_x)
        for i in xrange(len(vec)):
            vec[i] = vec[i].Rotate(-self.THETA) + vpos

        #export points to the graph
        self.gbox = TGraph(len(vec) + 1)
        self.gbox.SetLineColor(self.line_col)
        self.gbox.SetLineWidth(2)
        self.gbox.SetFillStyle(self.fill_style)
        self.gbox.SetFillColor(self.fill_col)

        for i in xrange(len(vec)):
            self.gbox.SetPoint(i, vec[i].X(), 100 * vec[i].Y())

        #last point same as the first
        self.gbox.SetPoint(len(vec), vec[0].X(), 100 * vec[0].Y())

        self.gbox.Draw("lfsame")

        #label
        if self.no_label: return
        #lx = (self.center_x + self.rad2)*100 + 4
        lx = (self.center_x + (self.rad1 + self.rad2) / 2) * 100 + 4
        if lx < 30: lx = 30
        align = 12
        #left down
        if (self.center_z < 0 and not self.is_electron) or self.label_down:
            lx = (self.center_x - self.rad2) * 100 - 4
            align = 32
        #right down
        if self.center_z > 0 and self.is_electron:
            lx = (self.center_x - self.rad2) * 100 - 4
            if lx > -25: lx = -25
            align = 32
            #label above the magnet
            if self.center_x < -0.4:
                lx = (self.center_x + self.rad2) * 100 + 4
                align = 12
        if self.label == "":
            self.label = self.name
        #self.glabel = TText(self.center_z, lx, self.label)
        self.glabel = TLatex(self.center_z, lx, self.label)
        self.glabel.SetTextSize(0.03)
        #self.glabel.SetTextSize(0.02)
        self.glabel.SetTextAngle(90)
        self.glabel.SetTextAlign(align)
        self.glabel.Draw("same")

    #_____________________________________________________________________________
    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)
Ejemplo n.º 15
0
class exit_window(object):
    #photon exit window, part of electron beam pipe, rear side
    #_____________________________________________________________________________
    def __init__(self, geom):

        #input points, in electron beamline frame
        if geom == "flat":
            self.pos = [(-21.7, -5), (-21.7, 5)]  # flat geometry
        if geom == "tilt":
            self.pos = [(-18.8, -5), (-21.7, 5)]  # tilted geometry

        #print the geometry
        self.print_position()

        #points in z and x, both in m
        self.zx_pos = []
        for i in self.pos:
            # z at 0 and x at 1, converted to cm
            self.zx_pos.append(TVector2(i[0], 0.01 * i[1]))

        #angle of initial rotation
        self.rotate(-0.008)

    #_____________________________________________________________________________
    def rotate(self, theta):
        #rotate by angle theta about the origin
        for i in xrange(len(self.zx_pos)):
            self.zx_pos[i] = self.zx_pos[i].Rotate(theta)

    #_____________________________________________________________________________
    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)
        #self.label.Draw("same")

    #_____________________________________________________________________________
    def print_position(self):

        #show position and angle of the exit window
        z1 = self.pos[0][0] * 1e3  # to mm
        z2 = self.pos[1][0] * 1e3

        x1 = self.pos[0][1] * 10.  # to mm
        x2 = self.pos[1][1] * 10.
        print "z_mid:", (z1 + z2) / 2., "mm"
        print "x_mid:", (x1 + x2) / 2., "mm"

        #length in x-z plane
        dl = math.sqrt((z1 - z2)**2 + (x1 - x2)**2)
        print "len:", dl, "mm"

        #angle in x-z plane
        dz = abs(z2 - z1)
        dx = abs(x2 - x1)
        #theta = math.atan( dx/dz )
        theta = math.asin(dx / dl)
        print "dz:", dz, "mm"
        print "dx:", dx, "mm"
        print "theta:", theta, "rad"
        print "pi/2 - theta:", math.pi / 2. - theta, "rad"