Ejemplo n.º 1
0
def rootSetup():
    from ROOT import gStyle
    gStyle.SetStatColor(0)
    gStyle.SetFillColor(38)
    gStyle.SetCanvasColor(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetOptStat(1110)
    gStyle.SetStatH(0.3)
    gStyle.SetStatW(0.3)

    gStyle.SetTitleFillColor(0)
    #gStyle.SetTitleY(1.)
    #gStyle.SetTitleX(.1)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetHistLineWidth(2)
    gStyle.SetFrameFillColor(0)
    #gStyle.SetLineWidth(2)
    #gStyle.SetTitleColor(0)
    #gStyle.SetTitleColor(1)
    gStyle.SetLabelSize(0.05, "x")
    gStyle.SetLabelSize(0.05, "y")
    gStyle.SetLabelOffset(0.02, "y")
    gStyle.SetTitleOffset(1.8, "y")
    gStyle.SetTitleSize(0.04, "y")
    gStyle.SetPadRightMargin(0.02)
    gStyle.SetPadLeftMargin(0.14)  # Used to be 0.20 --> Salva
    gStyle.SetPadBottomMargin(0.14)
Ejemplo n.º 2
0
 def DefaultPlotStyle(self):
     gStyle.SetPalette(55)  # 55 is kRainBow. 53 is kDarkBodyRadiator
     gStyle.SetOptStat(self.optStat1D)
     gStyle.SetOptFit(11111)
     gStyle.SetStatH(0.12)
     gStyle.SetStatW(0.15)
     gStyle.SetPadBottomMargin(0.15)
     gStyle.SetPadTopMargin(0.15)
Ejemplo n.º 3
0
def setstatsize(canvas, plot, config):
    # statistics size
    gStyle.SetStatW(0.3)
    gStyle.SetStatH(0.3)
    plot.Draw()
    canvas.Update()

    # set the size of the statistics box
    stat = plot.FindObject("stats")
    stat.SetX1NDC(1 - config.statboxsize)
    stat.SetY1NDC(1 - config.statboxsize)
Ejemplo n.º 4
0
def set_statbox(x=.95,
                y=.88,
                w=.16,
                entries=3,
                only_fit=False,
                opt=None,
                form=None):
    if only_fit:
        gStyle.SetOptStat(0011)
        gStyle.SetOptFit(1)
    gStyle.SetOptStat(opt) if opt is not None else do_nothing()
    gStyle.SetFitFormat(form) if form is not None else do_nothing()
    gStyle.SetStatX(x)
    gStyle.SetStatY(y)
    gStyle.SetStatW(w)
    gStyle.SetStatH(.04 * entries)
    def __init__(self):
        # ROOT
        gROOT.LoadMacro("tdrstyle.C")
        gROOT.LoadMacro("../interface/HelperMath.h")
        gROOT.LoadMacro("../../AMSimulationIO/src/AMSimulationIOLinkDef.h")
        gROOT.ProcessLine("setTDRStyle()")

        gStyle.SetEndErrorSize(2)
        gStyle.SetPadRightMargin(0.05)
        gStyle.SetTitleOffset(1.1, "Y")
        gStyle.SetLabelSize(0.04, "Y")
        gStyle.SetLabelSize(0.04, "Z")
        gStyle.SetNdivisions(505, "XY")

        gStyle.SetPalette(55)  # rainbow color map
        gStyle.SetNumberContours(100)

        gStyle.SetOptStat(111110)
        gStyle.SetStatX(0.94)
        gStyle.SetStatY(0.93)
        gStyle.SetStatH(0.30)
        gStyle.SetStatW(0.28)

        TH1.SetDefaultSumw2()
Ejemplo n.º 6
0
def setStyle():
    TColor.InitializeColors()
    stops = array('d', [
        0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000
    ])
    red = array('d', [
        0.9764, 0.9956, 0.8186, 0.5301, 0.1802, 0.0232, 0.0780, 0.0592, 0.2082
    ])
    green = array('d', [
        0.9832, 0.7862, 0.7328, 0.7492, 0.7178, 0.6419, 0.5041, 0.3599, 0.1664
    ])
    blue = array('d', [
        0.0539, 0.1968, 0.3499, 0.4662, 0.6425, 0.7914, 0.8385, 0.8684, 0.5293
    ])
    TColor.CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0)
    gStyle.SetHatchesLineWidth(1)
    gStyle.SetNumberContours(255)
    gStyle.SetNdivisions(505, "xyz")
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleColor(1)
    gStyle.SetTitleStyle(3013)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleX(0.05)
    gStyle.SetTitleW(0.4)
    gStyle.SetTitleY(0.965)
    gStyle.SetTitleH(0.065)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasBorderSize(3)
    gStyle.SetCanvasColor(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetFuncWidth(3)
    gStyle.SetPadGridY(False)
    gStyle.SetPadGridX(False)
    gStyle.SetFrameLineWidth(1)
    gStyle.SetMarkerSize(5)
    gStyle.SetPadTickX(True)
    gStyle.SetPadTickY(True)
    #gStyle.SetPalette(1)
    gStyle.SetHistLineWidth(3)
    gStyle.SetHistLineColor(1)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetStatW(0.25)
    gStyle.SetStatH(0.25)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatColor(0)
    gStyle.SetStatFormat("6.4g")
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadRightMargin(0.05)
    gStyle.SetPadBottomMargin(0.16)
    gStyle.SetPadLeftMargin(0.12)
    font = 42
    gStyle.SetTextSize(.055)

    gStyle.SetTextFont(font)
    gStyle.SetLabelFont(font, "x")
    gStyle.SetTitleFont(font, "x")
    gStyle.SetLabelFont(font, "y")
    gStyle.SetTitleFont(font, "y")
    gStyle.SetLabelFont(font, "z")
    gStyle.SetTitleFont(font, "z")

    gStyle.SetTitleSize(.055, "x")
    gStyle.SetTitleSize(.055, "y")
    gStyle.SetTitleSize(.05, "z")
    gStyle.SetLabelSize(.05, "x")
    gStyle.SetLabelSize(.05, "y")
    gStyle.SetLabelSize(.05, "z")
    gStyle.SetLabelOffset(0.014, "x")
    gStyle.SetLabelOffset(0.006, "y")
    gStyle.SetLabelOffset(0.008, "z")
    gStyle.SetTitleOffset(1, "y")
    gStyle.SetTitleXOffset(1.2)

    # use bold lines and markers
    gStyle.SetMarkerStyle(20)
    gStyle.SetMarkerColor(1)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetLineStyleString(2, "[12 12]")
    # postscript dashes

    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
Ejemplo n.º 7
0
def closureTest_plots(filename):
    f = BareRootFile(filename)
    tree = f.Get('closureTest')

    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(0.2)
    gStyle.SetStatH(0.14)

    hist1 = TH1F('hist1', '', 55, 0.9, 2.0)
    hist2 = TH1F('hist2', '', 55, 0.9, 2.0)
    condition = ('fit_overlapDiff>=0 && temp_overlapDiff>=0 && '
                 'fit_chisq/fit_dof<=2 && temp_chisq/temp_dof<=2')
    tree.Draw('temp_chisq/temp_dof>>hist1', condition)
    tree.Draw('fit_chisq/fit_dof>>hist2', condition)
    for i, hist in [(0, hist1), (1, hist2)]:
        hist.SetLineColor(colors[i])
        hist.SetLineWidth(3)
    maxi = max(hist1.GetMaximum(), hist2.GetMaximum()) * 1.1
    plot = SingleHistBase(hist1,
                          'hist_numberPerChisq',
                          fill=None,
                          workinprogress=wip)
    gStyle.SetOptStat(10)
    plot._xtitle = '#chi^{2}/d.o.f.'
    plot._ytitle = 'number of toys'
    plot.yrange(0.0, maxi)
    leg = TLegend(0.65, 0.75, 0.89, 0.85)
    leg.SetBorderSize(0)
    leg.AddEntry(hist1, 'DG fit', 'L')
    leg.AddEntry(hist2, 'SupDG fit', 'L')
    plot.draw()
    hist2.Draw('SAMEH')
    leg.Draw()
    plot.save_pdf()
    plot.Close()

    hist3 = TH2F('hist3', '', 31, -0.05, 3.05, 31, -0.05, 3.05)
    tree.Draw('100*temp_overlapDiff:100*fit_overlapDiff>>hist3', condition)
    one = TF1('one', 'x', -10.0, 10.0)
    one.SetLineColor(1)
    plot = SingleHistBase(hist3,
                          'correctionDGvsSupDG',
                          fill=None,
                          workinprogress=wip)
    plot.add(one)
    plot._drawoption = 'BOX'
    plot._xtitle = 'correction [%] from SupDG fit'
    plot._ytitle = 'correction [%] from DG fit'
    plot._above = True
    plot.draw()
    plot.save_pdf()
    plot.Close()

    hist4 = TH2F('hist4', '', 22, 0.95, 1.5, 22, 0.95, 1.5)
    tree.Draw('temp_chisq/temp_dof:fit_chisq/fit_dof>>hist4', condition)
    plot = SingleHistBase(hist4,
                          'chisqDGvsSupDG',
                          fill=None,
                          workinprogress=wip)
    plot.add(one)
    plot._drawoption = 'BOX'
    plot._xtitle = '#chi^{2}/d.o.f. of SupDG fit'
    plot._ytitle = '#chi^{2}/d.o.f. of DG fit'
    plot._above = True
    plot.draw()
    plot.save_pdf()
    plot.Close()

    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.83)
    gStyle.SetStatW(0.3)
    gStyle.SetStatH(0.08)

    #bins_csq = [(0.0, 1.1), (1.1, 1.3), (1.3, 1.6), (1.6, 2.0)]
    #bins_cor = [(0.0, 0.5), (0.5, 1.0), (1.0, 1.5), (1.5, 2.0), (2.0, 2.5)]
    #bins_csq = [(1.07, 1.13), (1.06, 1.11), (1.3, 1.5), (1.08, 1.17), (1.1, 1.2)]
    #bins_cor = [(0.3, 0.8), (0.9, 1.2), (0.1, 0.5), (0.4, 0.7), (0.3, 1.1)]
    bins_csq = [(0.99, 1.06), (0.98, 1.07), (0.99, 1.10), (1.02, 1.06),
                (1.00, 1.06), (1.00, 1.04)]
    bins_cor = [(0.9, 1.9), (0.4, 1.6), (0.6, 1.5), (0.6, 1.9), (1.0, 1.3),
                (0.3, 1.5)]

    means = {
        mod: [[0.0 for __ in bins_cor] for __ in bins_csq]
        for mod in ('DG', 'SupDG')
    }
    meane = {
        mod: [[0.0 for __ in bins_cor] for __ in bins_csq]
        for mod in ('DG', 'SupDG')
    }
    rmses = {
        mod: [[0.0 for __ in bins_cor] for __ in bins_csq]
        for mod in ('DG', 'SupDG')
    }
    rmser = {
        mod: [[0.0 for __ in bins_cor] for __ in bins_csq]
        for mod in ('DG', 'SupDG')
    }

    #for i, (csq_lo, csq_hi) in enumerate(bins_csq):
    #    for j, (cor_lo, cor_hi) in enumerate(bins_cor):
    for i, ((csq_lo, csq_hi), (cor_lo,
                               cor_hi)) in enumerate(zip(bins_csq, bins_cor)):
        j = i
        name = 'hist_{{0}}_{0}csq{1}_{2}cor{3}' \
               .format(csq_lo, csq_hi, cor_lo, cor_hi)
        fields = '100*({0}_overlapDiff-toy_overlapDiff)>>hist'
        condition = (
            '100*{{0}}_overlapDiff>={0} && 100*{{0}}_overlapDiff<{1} && '
            '{{0}}_chisq/{{0}}_dof>={2} && {{0}}_chisq/{{0}}_dof<{3} && '
            'fit_overlapDiff>=0 && temp_overlapDiff>=0 && '
            'fit_chisq/fit_dof<=2 && temp_chisq/temp_dof<=2').format(
                cor_lo, cor_hi, csq_lo, csq_hi)
        xtitle = 'correction [%] from {0} fit #minus true correction [%]'
        line1 = '{0} < correction < {1}'.format(cor_lo, cor_hi)
        line2 = '{0} < #chi^{{2}}/d.o.f. < {1}'.format(csq_lo, csq_hi)
        gStyle.SetOptStat(2210)
        for prefix, modname in (('temp', 'DG'), ('fit', 'SupDG')):
            hist = TH1F('hist', '', 41, -2.05, 2.05)
            hist.StatOverflows()
            tree.Draw(fields.format(prefix), condition.format(prefix))
            plot = SingleHistBase(hist,
                                  name.format(modname),
                                  fill=None,
                                  workinprogress=wip)
            gStyle.SetOptStat(2210)
            plot._xtitle = xtitle.format(modname)
            plot._ytitle = 'number of toys'
            plot.xrange(-2.05, 2.05)
            plot.yrange(0.0, plot._graph.GetMaximum() * 1.2)
            pave = plot.add_pave(0.6, 0.83, 0.9, 0.9, border=True)
            pave(line1)
            pave(line2)
            plot.draw()
            plot.save_pdf()
            means[modname][i][j] = plot._graph.GetMean()
            meane[modname][i][j] = plot._graph.GetMeanError()
            rmses[modname][i][j] = plot._graph.GetRMS()
            rmser[modname][i][j] = plot._graph.GetRMSError()
            plot.Close()

    multi = TMultiGraph('multi', '')
    for k, modname in enumerate(('DG', 'SupDG')):
        for i, (csq_lo, csq_hi) in enumerate(bins_csq):
            xval = array(
                'd',
                [j - 0.35 + k * 0.4 + i * 0.1 for j in range(len(bins_cor))])
            xerr = array('d', [0.0] * len(bins_cor))
            yval = array('d', means[modname][i])
            yerr = array('d', rmses[modname][i])
            graph = TGraphErrors(len(bins_cor), xval, yval, xerr, yerr)
            graph.SetName('graph{0}{1}'.format(k, i))
            graph.SetMarkerStyle(22 + k)
            graph.SetMarkerColor(colors[i])
            graph.SetLineColor(colors[i])
            multi.Add(graph)
    minvalues = [
        means[mod][i][j] - rmses[mod][i][j] for j in range(len(bins_cor))
        for i in range(len(bins_csq)) for mod in ('DG', 'SupDG')
    ]
    maxvalues = [
        means[mod][i][j] + rmses[mod][i][j] for j in range(len(bins_cor))
        for i in range(len(bins_csq)) for mod in ('DG', 'SupDG')
    ]
    mini, maxi = min(minvalues), max(maxvalues)
    mini, maxi = mini - 0.1 * (maxi - mini), maxi + 0.3 * (maxi - mini)
    hist = TH2F('axishist', '', len(bins_cor), -0.5,
                len(bins_cor) - 0.5, 100, mini, maxi)
    for j, (cor_lo, cor_hi) in enumerate(bins_cor):
        hist.GetXaxis().SetBinLabel(j + 1,
                                    '{0}% #minus {1}%'.format(cor_lo, cor_hi))
    leg1 = TLegend(0.53, 0.78, 0.63, 0.86)
    leg1.SetBorderSize(0)
    dgmarker = TMarker(0.0, 0.0, 22)
    supdgmarker = TMarker(0.0, 0.0, 23)
    leg1.AddEntry(dgmarker, 'DG', 'P')
    leg1.AddEntry(supdgmarker, 'SupDG', 'P')
    leg2 = TLegend(0.65, 0.75, 0.89, 0.89)
    leg2.SetBorderSize(0)
    csqmarker = TMarker(0.0, 0.0, 1)
    for i, (csq_lo, csq_hi) in enumerate(bins_csq):
        title = '{0} < #chi^{{2}}/d.o.f. < {1}'.format(csq_lo, csq_hi)
        entry = leg2.AddEntry(csqmarker, title, 'L')
        entry.SetMarkerColor(colors[i])
        entry.SetLineColor(colors[i])
    zero = TF1('zero', '0.0', -1.0, 10.0)
    zero.SetLineColor(1)
    zero.SetLineStyle(2)
    plot = SingleHistBase(hist,
                          name='differenceDoubleDifferential',
                          fill=None,
                          workinprogress=wip)
    plot._xtitle = 'correction from fit'
    plot._ytitle = 'correction [%] from fit #minus true correction [%]'
    plot.xrange(-0.5, len(bins_cor) - 0.5)
    plot.yrange(mini, maxi)
    plot._drawoption = 'AXIS'
    plot.draw()
    plot.xaxis().SetNdivisions(len(bins_cor), False)
    plot.xaxis().SetLabelSize(0.03)
    zero.Draw('SAME')
    multi.Draw('P')
    leg1.Draw()
    leg2.Draw()
    plot.save_pdf()
    plot.Close()

    bcid = (41, 281, 872, 1783, 2063)
    DGcor1 = array('d', [0.809, 0.392, 0.846, 0.731, 0.497])
    DGerr1 = array('d', [0.548, 0.567, 0.984, 0.984, 1.018])
    DGcor2 = array('d', [1.145, 0.799, 1.58, 1.465, 1.281])
    DGerr2 = array('d', [0.432, 0.395, 0.656, 0.656, 0.649])
    DGxval = array('d', [j - 0.1 for j in range(5)])
    SupDGcor1 = array('d', [0.823, 0.761, 1.458, 0.986, 1.012])
    SupDGerr1 = array('d', [0.513, 0.513, 0.499, 0.513, 0.499])
    SupDGcor2 = array('d', [0.978, 0.916, 1.532, 1.141, 1.086])
    SupDGerr2 = array('d', [0.489, 0.489, 0.493, 0.489, 0.493])
    SupDGxval = array('d', [j + 0.1 for j in range(5)])
    xerr = array('d', [0.0] * 5)

    for fill, values in [
        (4266, {
            'DGcor': [1.021, 1.057, 0.968, 1.084, 1.114],
            'DGerr': [(e**2 + 0.74**2)**0.5
                      for e in (0.118, 0.124, 0.119, 0.117, 0.119)],
            'SupDGcor': [1.402, 1.411, 1.164, 1.549, 1.589],
            'SupDGerr': [(e**2 + 0.45**2)**0.5
                         for e in (0.106, 0.110, 0.108, 0.106, 0.115)],
            'bcids': [51, 771, 1631, 2211, 2674]
        }),
        (4954, {
            'DGcor': [0.799, 0.398, 0.845, 0.724, 0.502],
            'DGerr': [(e**2 + 0.79**2)**0.5
                      for e in (0.137, 0.124, 0.122, 0.130, 0.116)],
            'SupDGcor': [0.794, 0.694, 1.642, 0.983, 0.993],
            'SupDGerr': [(e**2 + 0.50**2)**0.5
                         for e in (0.126, 0.112, 0.186, 0.102, 0.144)],
            'bcids': [41, 281, 872, 1783, 2063]
        }),
        (4937, {
            'DGcor': [0.649, 0.494, 0.575, 0.527, 0.602],
            'DGerr':
            [(e**2 + 0.85**2)**0.5 for e in (0.127, 0.115, 0.120, 0.125)],
            'SupDGcor': [0.377, 0.611, 1.137, 0.453, 1.840],
            'SupDGerr': [(e**2 + 0.56**2)**0.5
                         for e in (0.100, 0.105, 0.288, 0.161, 0.207)],
            'bcids': [81, 875, 1610, 1690, 1730]
        }),
        (6016, {
            'DGcor': [0.146, 0.394, 0.377, 0.488, 0.184],
            'DGerr': [(e**2 + 1.15**2)**0.5
                      for e in (0.110, 0.114, 0.118, 0.123, 0.109)],
            'SupDGcor': [0.760, 0.953, 1.048, 0.847, 0.373],
            'SupDGerr': [(e**2 + 0.79**2)**0.5
                         for e in (0.219, 0.094, 0.189, 0.098, 0.169)],
            'bcids': [41, 281, 872, 1783, 2063]
        })
    ]:
        bcid = values['bcids']
        DGcor = array('d', values['DGcor'])
        DGerr = array('d', values['DGerr'])
        DGxvl = array('d', [j - 0.1 for j in range(len(bcid))])
        SupDGcor = array('d', values['SupDGcor'])
        SupDGerr = array('d', values['SupDGerr'])
        SupDGxvl = array('d', [j + 0.1 for j in range(len(bcid))])
        xerr = array('d', [0.0] * len(bcid))
        maxi = max(max([v + e for v, e in zip(DGcor, DGerr)]),
                   max([v + e for v, e in zip(SupDGcor, SupDGerr)]))
        mini = min(min([v - e for v, e in zip(DGcor, DGerr)]),
                   min([v - e for v, e in zip(SupDGcor, SupDGerr)]))
        maxi, mini = maxi + 0.2 * (maxi - mini), mini - 0.1 * (maxi - mini)

        graphDG = TGraphErrors(len(bcid), DGxvl, DGcor, xerr, DGerr)
        graphDG.SetName('graphDG')
        graphSupDG = TGraphErrors(len(bcid), SupDGxvl, SupDGcor, xerr,
                                  SupDGerr)
        graphSupDG.SetName('graphSupDG')
        multi = TMultiGraph('multi', '')
        for i, graph in [(0, graphDG), (1, graphSupDG)]:
            graph.SetMarkerStyle(22 + i)
            graph.SetMarkerColor(colors[i])
            graph.SetLineColor(colors[i])
            multi.Add(graph)
        leg = TLegend(0.15, 0.80, 0.5, 0.83)
        leg.SetNColumns(2)
        leg.SetBorderSize(0)
        leg.AddEntry(graphDG, 'DG fit', 'PL')
        leg.AddEntry(graphSupDG, 'SupDG fit', 'PL')
        axishist = TH2F('axishist', '', len(bcid), -0.5,
                        len(bcid) - 0.5, 100, mini, maxi)
        for i, bx in enumerate(bcid):
            axishist.GetXaxis().SetBinLabel(i + 1, '{0}'.format(bx))

        plot = SingleHistBase(axishist,
                              name='Fill{0}biased'.format(fill),
                              fill=fill,
                              workinprogress=wip)
        plot._xtitle = 'BCID'
        plot._ytitle = 'correction [%] from fit'
        plot.xrange(-0.5, len(bcid) - 0.5)
        plot.yrange(mini, maxi)
        plot._drawoption = 'AXIS'
        plot.draw()
        plot.xaxis().SetNdivisions(len(bcid), False)
        plot.xaxis().SetLabelSize(0.03)
        multi.Draw('P')
        leg.Draw()
        plot.save_pdf()
        plot.Close()

        print
        print 'Fill', fill
        for bx, cor, err in zip(bcid, SupDGcor, SupDGerr):
            print 'BCID {0}:\t{1:.2f} +- {2:.2f}'.format(bx, cor, err)
        print
Ejemplo n.º 8
0
def applyRootStyle():

    from ROOT import gROOT, gStyle, kWhite, kBlack, TColor

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

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

    # Grid
    # gStyle.SetGridStyle(3)

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

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

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Style for 2D zcol plots
    NRGBs = 5
    NCont = 255
    from array import array
    stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00])
    red = array('d', [0.00, 0.00, 0.87, 1.00, 0.51])
    green = array('d', [0.00, 0.81, 1.00, 0.20, 0.00])
    blue = array('d', [0.51, 1.00, 0.12, 0.00, 0.00])
    TColor().CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont)
    gStyle.SetNumberContours(NCont)

    # Force the style
    gROOT.ForceStyle()
Ejemplo n.º 9
0
def tdrstyle():
    gROOT.SetStyle("Plain")
    
    gStyle.SetAxisColor(1, "XYZ")
    
    gStyle.SetCanvasColor(0)
    #gStyle.SetCanvasBorderSize(10)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasDefH(700)
    gStyle.SetCanvasDefW(700)
    gStyle.SetCanvasDefX(0)
    gStyle.SetCanvasDefY(0)
    
    gStyle.SetFitFormat("5.4g")
    gStyle.SetFuncColor(2)
    gStyle.SetFuncStyle(1)
    gStyle.SetFuncWidth(1)
    
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameBorderSize(1)
    gStyle.SetFrameFillStyle(0)
    gStyle.SetFrameFillColor(0)
    gStyle.SetFrameLineColor(1)
    gStyle.SetFrameLineStyle(1)  # 0?
    gStyle.SetFrameLineWidth(1)  # 1?
    
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)
    
    #gStyle.SetHistFillColor(1)
    #gStyle.SetHistFillStyle(0)
    gStyle.SetHistLineColor(1)
    gStyle.SetHistLineStyle(0)
    gStyle.SetHistLineWidth(1)
    
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42,"XYZ")
    gStyle.SetLabelOffset(0.007,"XYZ")  # 0.010?
    gStyle.SetLabelSize(0.05,"XYZ")  # 0.04?
    
    gStyle.SetLegendBorderSize(0)
    gStyle.SetLegendFillColor(0)
    gStyle.SetLegendFont(42)
    
    gStyle.SetMarkerSize(1.0)
    gStyle.SetMarkerStyle(20)
    
    gStyle.SetLineColor(1)
    gStyle.SetLineWidth(2)
    #gStyle.SetLineScalePS(2)
    
    gStyle.SetOptDate(0)
    gStyle.SetOptFile(0)
    gStyle.SetOptFit(1)
    gStyle.SetOptStat(0)
    gStyle.SetOptTitle(0)
    #gStyle.SetOptLogx(0)
    #gStyle.SetOptLogy(0)
    #gStyle.SetOptLogz(0)
    
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadBorderSize(10)
    gStyle.SetPadTopMargin(0.05)  # 0.08?
    gStyle.SetPadBottomMargin(0.13)
    gStyle.SetPadLeftMargin(0.16)
    gStyle.SetPadRightMargin(0.03)  # 0.05?
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    
    gStyle.SetStatColor(0)
    gStyle.SetStatFont(42)
    gStyle.SetStatFontSize(0.025)
    gStyle.SetStatTextColor(1)
    gStyle.SetStatFormat("6.4g")
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatH(0.1)
    gStyle.SetStatW(0.15)
    #gStyle.SetStatX(0)
    #gStyle.SetStatY(0)
    
    #gStyle.SetTextSize(0.055)
    gStyle.SetTextFont(42)
    
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleColor(1)
    gStyle.SetTitleFont(42)
    gStyle.SetTitleColor(1,"XYZ")
    gStyle.SetTitleFont(42,"XYZ")
    gStyle.SetTitleSize(0.06,"XYZ")  # 0.05?
    #gStyle.SetTitleOffset(1.4,"XYZ")
    gStyle.SetTitleOffset(0.9,"X")
    gStyle.SetTitleOffset(1.20,"Y")
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)
    gStyle.SetTitleTextColor(1)
    #gStyle.SetTitleH(0)
    #gStyle.SetTitleW(0)
    #gStyle.SetTitleX(0)
    #gStyle.SetTitleY(0.985)
    #gStyle.SetTitleStyle(1001)
    
    gStyle.SetPalette(1)
    #gStyle.SetNdivisions(510, "XYZ")  # 505?
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetEndErrorSize(2)  # 2?
    #gStyle.SetErrorMarker(20)
    #gStyle.SetErrorX(0.)
    #gStyle.SetPaperSize(20.,20.)
    gStyle.SetStripDecimals(1)
    gStyle.SetTickLength(0.03, "XYZ")
    return 1
Ejemplo n.º 10
0
#parser.add_option('--ML', type='string', action='store',
#                  default= 'DNN',
#                  dest='ML',
#                  help='Which ML method? DNN, BDT, MLP, or kNN')

(options, args) = parser.parse_args()
argv = []

folder = "varplots_" + str(options.n) + "_" + str(options.layers)

#ML = str(options.ML)
#eff = options.eff

gStyle.SetStatY(0.93)
gStyle.SetStatX(0.25)
gStyle.SetStatW(0.15)
gStyle.SetStatH(0.1)

xlist = ["Hit_plane0", "Hit_plane1", "Hit_plane6", "Hit_plane7"]
uvlist = ["Hit_plane2", "Hit_plane3", "Hit_plane4", "Hit_plane5"]
planes = xlist + uvlist

########### START LOOP OVER EFFICIENCIES ###########

#effs = [90,91,92,93,94,95,96,97,98,99,100]
effs = [100]

for eff in effs:

    TMVA.Tools.Instance()
    reader = ROOT.TMVA.Reader()
Ejemplo n.º 11
0
    def initStyle():
        gROOT.SetStyle("Plain")

        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(700)  #Height of canvas
        gStyle.SetCanvasDefW(700)  #Width of canvas
        gStyle.SetCanvasDefX(0)  #Position on screen
        gStyle.SetCanvasDefY(0)

        # For the line:
        gStyle.SetLineWidth(2)

        # For the Pad:
        gStyle.SetPadBorderMode(0)
        # gStyle.SetPadBorderSize(Width_t size = 1)
        gStyle.SetPadColor(kWhite)
        gStyle.SetPadGridX(True)
        gStyle.SetPadGridY(True)
        gStyle.SetGridColor(0)
        gStyle.SetGridStyle(3)
        gStyle.SetGridWidth(1)

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        gStyle.SetFrameFillColor(0)
        gStyle.SetFrameFillStyle(0)
        gStyle.SetFrameLineColor(1)
        gStyle.SetFrameLineStyle(1)
        gStyle.SetFrameLineWidth(1)

        # For the histo:
        # gStyle.SetHistFillColor(1)
        # gStyle.SetHistFillStyle(0)
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(2)
        # gStyle.SetLegoInnerR(Float_t rad = 0.5)
        # gStyle.SetNumberContours(Int_t number = 20)

        gStyle.SetEndErrorSize(2)
        #gStyle.SetErrorMarker(20)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(8)
        gStyle.SetMarkerSize(1)

        #For the fit/function:
        gStyle.SetOptFit(0)
        gStyle.SetFitFormat("5.4g")
        gStyle.SetFuncColor(2)
        gStyle.SetFuncStyle(1)
        gStyle.SetFuncWidth(1)

        #For the date:
        gStyle.SetOptDate(0)
        # gStyle.SetDateX(Float_t x = 0.01)
        # gStyle.SetDateY(Float_t y = 0.01)

        # For the statistics box:
        gStyle.SetOptFile(0)
        gStyle.SetOptStat(0)  # To display the mean and RMS:   SetOptStat("mr")
        gStyle.SetStatColor(kWhite)
        gStyle.SetStatFont(42)
        gStyle.SetStatFontSize(0.025)
        gStyle.SetStatTextColor(1)
        gStyle.SetStatFormat("6.4g")
        gStyle.SetStatBorderSize(1)
        gStyle.SetStatH(0.1)
        gStyle.SetStatW(0.15)
        # gStyle.SetStatStyle(Style_t style = 1001)
        # gStyle.SetStatX(Float_t x = 0)
        # gStyle.SetStatY(Float_t y = 0)

        # Margins:
        gStyle.SetPadTopMargin(0.11)
        gStyle.SetPadBottomMargin(0.13)
        gStyle.SetPadLeftMargin(0.17)
        gStyle.SetPadRightMargin(0.07)

        # For the Global title:
        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.04)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        #gStyle.SetTitleX(0.35) # Set the position of the title box
        #gStyle.SetTitleY(0.986) # Set the position of the title box
        # gStyle.SetTitleStyle(Style_t style = 1001)
        #gStyle.SetTitleBorderSize(0)

        # For the axis titles:
        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.05, "XYZ")
        # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
        # gStyle.SetTitleYSize(Float_t size = 0.02)
        gStyle.SetTitleXOffset(1.)
        gStyle.SetTitleYOffset(1.3)
        #gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.035, "XYZ")

        # For the axis:
        gStyle.SetAxisColor(1, "XYZ")
        gStyle.SetStripDecimals(True)
        gStyle.SetTickLength(0.03, "XYZ")
        gStyle.SetNdivisions(510, "XYZ")
        gStyle.SetPadTickX(
            1)  # To get tick marks on the opposite side of the frame
        gStyle.SetPadTickY(1)

        # Change for log plots:
        gStyle.SetOptLogx(0)
        gStyle.SetOptLogy(0)
        gStyle.SetOptLogz(0)

        gStyle.SetPalette(1)  #(1,0)

        # another top group addition
        gStyle.SetHatchesSpacing(1.0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
        #gStyle.SetPaperSize(TStyle.kA4)
        #gStyle.SetPaperSize(27., 29.7)
        #TGaxis.SetMaxDigits(3)
        # gStyle.SetLineScalePS(Float_t scale = 3)
        # gStyle.SetLineStyleString(Int_t i, const char* text)
        # gStyle.SetHeaderPS(const char* header)
        # gStyle.SetTitlePS(const char* pstitle)
        #gStyle.SetColorModelPS(1)

        # gStyle.SetBarOffset(Float_t baroff = 0.5)
        # gStyle.SetBarWidth(Float_t barwidth = 0.5)
        # gStyle.SetPaintTextFormat(const char* format = "g")
        # gStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0)
        # gStyle.SetTimeOffset(Double_t toffset)
        # gStyle.SetHistMinimumZero(kTRUE)

        #gStyle.cd()
        print "TDR Style initialized"
Ejemplo n.º 12
0
    hp1.Fill((p1Fit - p1End) / p1FitError)

    p0Fit = fitresult.Parameter(0)  # - dsMeanVal.getValV();
    p0FitError = fitresult.ParError(0)

    print 'P0FIT = ', p0Fit, '\nDSMEANVAL = ', etaAvg.getValV(
    ), '\nP0END = ', p0End, '\n'

    hp0.Fill((p0Fit - p0End) / p0FitError)
    #break;

from ROOT import gStyle, TStyle
gStyle.SetOptFit(111)
gStyle.SetOptStat(11)
gStyle.SetStatW(gStyle.GetStatW() / 1.1)
gStyle.SetStatH(gStyle.GetStatH() / 1.1)
gStyle.SetStatX(gStyle.GetStatX())
gStyle.SetStatY(gStyle.GetStatY() - 0.05)

currentTime = time.time()

theHistCanvas = TCanvas()
theHistCanvas.SetBottomMargin(0.2)
theHistCanvas.SetRightMargin(0.05)
hp1.Fit("gaus", "ILL")
hp1.Draw()

hp1.GetYaxis().SetTitleSize(0.05)
hp1.GetXaxis().SetTitleSize(0.05)
hp1.GetXaxis().SetTitleOffset(1.5)
Ejemplo n.º 13
0
def initialization(batch=True, font=default_font):
    '''-- ROOT initialization --'''

    print "Initializing ROOT ..."

    # general
    gROOT.Reset()
    gROOT.SetBatch(batch)
    gROOT.SetStyle("Plain")

    # gStyle
    gStyle.SetFillColor(0)
    gStyle.SetCanvasColor(10)
    gStyle.SetLineWidth(1)
    gStyle.SetPalette(8)
    gStyle.SetTextFont(font)
    #gStyle.SetTextSize(30)

    # Frame
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameFillColor(0)

    # Pad
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBottomMargin(0.1)
    gStyle.SetPadTopMargin(0.01)
    gStyle.SetPadLeftMargin(0.1)
    gStyle.SetPadRightMargin(0.01)
    gStyle.SetPadTickX(1)  # make ticks be on all 4 sides.
    gStyle.SetPadTickY(1)
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    # histogram
    gStyle.SetHistFillStyle(0)
    gStyle.SetOptTitle(0)
    gStyle.SetTitleSize(0.22)
    gStyle.SetTitleFontSize(10)
    gStyle.SetTitleFont(font)
    gStyle.SetTitleFont(font, "xyz")
    gStyle.SetTitleYOffset(1.0)
    gStyle.SetTitleXOffset(1.0)
    gStyle.SetTitleXSize(0.04)
    gStyle.SetTitleYSize(0.04)
    gStyle.SetTitleX(.15)
    gStyle.SetTitleY(.98)
    gStyle.SetTitleW(.70)
    gStyle.SetTitleH(.05)

    # statistics box
    gStyle.SetOptStat(0)
    gStyle.SetStatFont(font)
    gStyle.SetStatFontSize(10)
    gStyle.SetStatX(.91)
    gStyle.SetStatY(.90)
    gStyle.SetStatW(.15)
    gStyle.SetStatH(.15)

    # axis labels
    gStyle.SetLabelFont(font)
    gStyle.SetLabelFont(font, "xyz")
    gStyle.SetLabelSize(10, "xyz")
    # gStyle.SetGridColor(1)
    gStyle.SetLegendBorderSize(1)
Ejemplo n.º 14
0
    def initialize(fitresults=True, grid=False):
        gROOT.SetStyle("Plain")
        gStyle.SetOptFit()
        gStyle.SetOptStat(0)
        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(600) #Height of canvas
        gStyle.SetCanvasDefW(600) #Width of canvas
        gStyle.SetCanvasDefX(0)   #POsition on screen
        gStyle.SetCanvasDefY(0)

        # For the Pad:
        gStyle.SetPadBorderMode(0)
        gStyle.SetPadColor(kWhite)
        gStyle.SetPadGridX(False)
        gStyle.SetPadGridY(False)
        gStyle.SetGridColor(0)
        gStyle.SetGridStyle(3)
        gStyle.SetGridWidth(1)

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        gStyle.SetFrameFillColor(kWhite)
        gStyle.SetFrameFillStyle(1000)
        gStyle.SetFrameLineColor(1)
        gStyle.SetFrameLineStyle(1)
        gStyle.SetFrameLineWidth(1)

        # For the histo:
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(2)

        gStyle.SetEndErrorSize(2)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(20)

        #For the fit/function:
        gStyle.SetOptFit(1)
        gStyle.SetFitFormat("5.4g")
        gStyle.SetFuncColor(2)
        gStyle.SetFuncStyle(1)
        gStyle.SetFuncWidth(1)

        #For the date:
        gStyle.SetOptDate(0)

        # For the statistics box:
        gStyle.SetOptFile(0)
        gStyle.SetOptStat(0) # To display the mean and RMS:   SetOptStat("mr")
        gStyle.SetStatColor(kWhite)
        gStyle.SetStatFont(42)
        gStyle.SetStatFontSize(0.025)
        gStyle.SetStatTextColor(1)
        gStyle.SetStatFormat("6.4g")
        gStyle.SetStatBorderSize(1)
        gStyle.SetStatH(0.1)
        gStyle.SetStatW(0.15)

        # Margins:
        gStyle.SetPadTopMargin(0.05)
        gStyle.SetPadLeftMargin(0.16)
        gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02
        gStyle.SetPadBottomMargin(0.13)

        # For the Global title:

        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.05)

        # For the axis titles:
        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.06, "XYZ")
        gStyle.SetTitleXOffset(0.9)
        gStyle.SetTitleYOffset(1.25)

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.05, "XYZ")
        #gStyle.SetLabelSize(0.04, "XYZ")

        # For the axis:

        gStyle.SetAxisColor(1, "XYZ")
        gStyle.SetStripDecimals(True)
        gStyle.SetTickLength(0.03, "XYZ")
        gStyle.SetNdivisions(510, "XYZ")
        gStyle.SetPadTickX(1)  # To get tick marks on the opposite side of the frame
        gStyle.SetPadTickY(1)

        # Change for log plots:
        gStyle.SetOptLogx(0)
        gStyle.SetOptLogy(0)
        gStyle.SetOptLogz(0)

        gStyle.SetPalette(1) #(1,0)

        # another top group addition
        gStyle.SetHatchesSpacing(1.0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
        # For graphs
        gStyle.SetErrorX(0)  # suppress error along x

        if grid:
          gStyle.SetPadGridX(gridOn)
          gStyle.SetPadGridY(gridOn)
          gStyle.SetGridColor(kGray)
Ejemplo n.º 15
0
f1 = TFile('py-hsimple.root')

#
# Inside this canvas, we create 4 pads
pad1 = TPad('pad1', 'This is pad1', 0.02, 0.52, 0.48, 0.98, 21)
pad2 = TPad('pad2', 'This is pad2', 0.52, 0.52, 0.98, 0.98, 21)
pad3 = TPad('pad3', 'This is pad3', 0.02, 0.02, 0.48, 0.48, 21)
pad4 = TPad('pad4', 'This is pad4', 0.52, 0.02, 0.98, 0.48, 1)
pad1.Draw()
pad2.Draw()
pad3.Draw()
pad4.Draw()

#
# Change default style for the statistics box
gStyle.SetStatW(0.30)
gStyle.SetStatH(0.20)
gStyle.SetStatColor(42)

#
# Display a function of one ntuple column imposing a condition
# on another column.
pad1.cd()
pad1.SetGrid()
pad1.SetLogy()
pad1.GetFrame().SetFillColor(15)
ntuple = gROOT.FindObject('ntuple')
ntuple.SetLineColor(1)
ntuple.SetFillStyle(1001)
ntuple.SetFillColor(45)
ntuple.Draw('3*px+2', 'px**2+py**2>1')
Ejemplo n.º 16
0
#! /usr/bin/env python

from ROOT import gROOT, TFile, TCanvas, TF1, TGraph, TPaveText, TLatex, TH1F, TLegend, TLine, TColor, TIter, gStyle
from ROOT import TGaxis
from array import array
import ROOT

gROOT.SetStyle("Plain")
gStyle.SetOptStat(1110)
gStyle.SetOptFit(1)
gStyle.SetOptStat(0)
gStyle.SetStatW(0.25)
gStyle.SetStatH(0.15)

gStyle.SetCanvasDefH(150)
gStyle.SetCanvasDefW(150)

gStyle.SetAxisColor(1, "XYZ")
gStyle.SetStripDecimals(1)
gStyle.SetTickLength(0.03, "XYZ")
gStyle.SetNdivisions(510, "XYZ")
gStyle.SetPadTickX(1)
gStyle.SetPadTickY(1)

gStyle.SetPadTopMargin(0.1)
gStyle.SetPadBottomMargin(0.13)
gStyle.SetPadLeftMargin(0.13)
gStyle.SetPadRightMargin(0.1)

gStyle.SetTitleColor(1, "XYZ")
gStyle.SetTitleFont(42, "XYZ")
Ejemplo n.º 17
0
    def analyzeMeshes(self, dictOfMeshes, doCull=False, cullCut=0.90):
        """ analyzeMeshes takes a dictionary with meshes as input, and fits it to the references
        output dictionary includes a deepcopy of the input meshes
        note:
           this fits to zDiff = dictOfMeshes - interpolation of self.meshDict
           ie. the sign is defined as (other guy) - (me)
        """
        # deepcopy the meshes! no longer adjusts in place
        dictOfMeshesCopy = {}
        for key in list(dictOfMeshes.keys()):
            theMesh = copy.deepcopy(dictOfMeshes[key])
            dictOfMeshesCopy[key] = theMesh

        # then we analyze the Zernike polynomials by comparing them to stored references
        # analyzeDonuts returns a dictionary containing deltas and rotation angles for focus, astigmatism and coma
        # as well as the hexapod adjustments
        # it also makes a Canvas of plots for study

        dictOfResults = {}

        # loop over keys, fitting References
        for key in list(dictOfMeshesCopy.keys()):

            # some special cases
            resultsKeyName = "%sResultDict" % (key.replace("Mesh", ""))
            meshName = key
            if key == "z4Mesh":
                print("Python 3 debugging: %r" % self.meshDict)
                dictOfResults[resultsKeyName] = self.fitToRefMesh(
                    self.meshDict[meshName], dictOfMeshesCopy[meshName],
                    self.zangleconv)
            elif key == "rzeroMesh":
                dictOfResults[resultsKeyName] = self.analyzeRzero(
                    dictOfMeshesCopy["rzeroMesh"],
                    dictOfMeshesCopy["chi2Mesh"], dictOfMeshesCopy["neleMesh"])
            elif key == "chi2Mesh":
                continue
            elif key == "neleMesh":
                continue
            else:
                # check that meshDict has the appropriate mesh
                if meshName in self.meshDict:
                    dictOfResults[resultsKeyName] = self.fitToRefMesh(
                        self.meshDict[meshName], dictOfMeshesCopy[meshName])

        # if we want to cull, cull and refit!
        # use the fitted weight to cull - culltype="fit"
        if doCull:
            # this will take the wgt's from the fit and take their product
            # for each point, and cull at a product of cullCut
            self.cullAllMeshes(dictOfMeshesCopy, cullCut=cullCut)

            for key in list(dictOfMeshesCopy.keys()):

                # some special cases
                resultsKeyName = "%sResultDict" % (key.replace("Mesh", ""))
                meshName = key
                if key == "z4Mesh":
                    dictOfResults[resultsKeyName] = self.fitToRefMesh(
                        self.meshDict[meshName], dictOfMeshesCopy[meshName],
                        self.zangleconv)
                elif key == "rzeroMesh":
                    dictOfResults[resultsKeyName] = self.analyzeRzero(
                        dictOfMeshesCopy["rzeroMesh"],
                        dictOfMeshesCopy["chi2Mesh"],
                        dictOfMeshesCopy["neleMesh"])
                elif key == "chi2Mesh":
                    continue
                elif key == "neleMesh":
                    continue
                else:
                    # check that meshDict has the appropriate mesh
                    if meshName in self.meshDict:
                        dictOfResults[resultsKeyName] = self.fitToRefMesh(
                            self.meshDict[meshName],
                            dictOfMeshesCopy[meshName])

        # analyze this data and extract the hexapod coefficients
        donutDict = self.calcHexapod(dictOfResults)

        if len(donutDict) == 0:
            goodCalc = False
        else:
            goodCalc = True

        # add the individual fit results here too
        for key in list(dictOfResults.keys()):
            donutDict[key] = dictOfResults[key]

        # and add the meshes too
        for key in list(dictOfMeshesCopy.keys()):
            donutDict[key] = dictOfMeshesCopy[key]

        # cmr add X and Y coords
        keylist = list(dictOfResults.keys())
        key0 = keylist[0]
        dict0 = dictOfResults[key0]
        donutDict['deltaArrayX'] = dict0['deltaArrayX']
        donutDict['deltaArrayY'] = dict0['deltaArrayY']

        # make a Canvas of plots for this image
        # plot Histogram of Difference before fit, after fit, and after fit vs. X,Y position
        if self.paramDict["histFlag"] and "deltaArrayBefore" in dictOfResults[
                "z4ResultDict"] and goodCalc:

            # setup plots
            gStyle.SetStatH(0.32)
            gStyle.SetStatW(0.4)
            gStyle.SetOptStat(1111111)
            gStyle.SetMarkerStyle(20)
            gStyle.SetMarkerSize(0.5)
            gStyle.SetPalette(1)
            gROOT.ForceStyle()

            # loop over results, making plots for each
            nplots = 0
            plotDict = {}
            for key in list(dictOfResults.keys()):
                theResultDict = dictOfResults[key]

                keyId = key.replace("ResultDict", "")
                # special cases
                if keyId == "z4":
                    nWavesBefore = 200.0
                    nWavesAfter = 200.0
                else:
                    nWavesBefore = 2.0
                    nWavesAfter = 0.2

                if keyId != "rzero":
                    nplots = nplots + 1
                    hBefore = hfillhist(key + "Before",
                                        "Delta " + key + ", Before Fit",
                                        theResultDict["deltaArrayBefore"], 200,
                                        -nWavesBefore, nWavesBefore)
                    hAfter = hfillhist(key + "zAfter",
                                       "Delta " + key + ", After Fit",
                                       theResultDict["deltaArrayAfter"], 200,
                                       -nWavesAfter, nWavesAfter)
                    hBefore2D = TGraph2D(
                        key + "Before2D", "Delta " + key +
                        ", Before Fit, vs. Position;X[mm];Y[mm]",
                        theResultDict["deltaArrayBefore"].shape[0],
                        theResultDict["deltaArrayX"],
                        theResultDict["deltaArrayY"],
                        theResultDict["deltaArrayBefore"])
                    hAfter2D = TGraph2D(
                        key + "After2D", "Delta " + key +
                        ", After Fit, vs. Position;X[mm];Y[mm]",
                        theResultDict["deltaArrayAfter"].shape[0],
                        theResultDict["deltaArrayX"],
                        theResultDict["deltaArrayY"],
                        theResultDict["deltaArrayAfter"])

                    plotList = [hBefore, hAfter, hBefore2D, hAfter2D]
                    plotDict[keyId] = plotList

            # the Canvas

            # unique name for our canvas
            # might be that
            # gROOT.SetBatch(kTRUE)
            # will prevent the Canvas from appearing, but will still get made in output pickle
            tstr = "canvas" + str(time.time())

            canvas = TCanvas(tstr, tstr, 300 * nplots, 1000)
            canvas.Divide(nplots, 4)

            # plot em
            jZ = 0
            for iZ in range(4, 15 + 1):
                key = "z%d" % (iZ)
                if key in plotDict:
                    jZ = jZ + 1

                    plotList = plotDict[key]

                    icanvas = jZ + 0 * nplots
                    canvas.cd(icanvas)
                    plotList[0].Draw()
                    icanvas = jZ + 1 * nplots
                    canvas.cd(icanvas)
                    plotList[1].Draw()
                    icanvas = jZ + 2 * nplots
                    canvas.cd(icanvas)
                    plotList[2].Draw("zcolpcol")
                    icanvas = jZ + 3 * nplots
                    canvas.cd(icanvas)
                    plotList[3].Draw("zcolpcol")

            # set it so that python doesn't own these ROOT object
            for key in list(plotDict.keys()):
                for plot in plotDict[key]:
                    SetOwnership(plot, False)

            # save canvas in the output Dictionary
            donutDict["canvas"] = canvas

        # all done
        return donutDict
Ejemplo n.º 18
0
def setTDRStyle(force):

  gStyle.SetCanvasBorderMode(0)
  gStyle.SetCanvasColor(kWhite)
  gStyle.SetCanvasDefH(600)
  gStyle.SetCanvasDefW(600)
  gStyle.SetCanvasDefX(0)
  gStyle.SetCanvasDefY(0)

  gStyle.SetPadBorderMode(0)
  gStyle.SetPadColor(kWhite)
  gStyle.SetPadGridX(False)
  gStyle.SetPadGridY(False)
  gStyle.SetGridColor(0)
  gStyle.SetGridStyle(3)
  gStyle.SetGridWidth(1)

  gStyle.SetFrameBorderMode(0)
  gStyle.SetFrameBorderSize(1)
  gStyle.SetFrameFillColor(0)
  gStyle.SetFrameFillStyle(0)
  gStyle.SetFrameLineColor(1)
  gStyle.SetFrameLineStyle(1)
  gStyle.SetFrameLineWidth(1)

  if force:
      gStyle.SetHistLineColor(1)
      gStyle.SetHistLineStyle(0)
      gStyle.SetHistLineWidth(1)


  gStyle.SetEndErrorSize(2)
  gStyle.SetErrorX(0.)

  gStyle.SetMarkerStyle(20)

  gStyle.SetOptFit(1)
  gStyle.SetFitFormat("5.4g")
  gStyle.SetFuncColor(2)
  gStyle.SetFuncStyle(1)
  gStyle.SetFuncWidth(1)

  gStyle.SetOptDate(0)

  gStyle.SetOptFile(0)
  gStyle.SetOptStat(0)
  gStyle.SetStatColor(kWhite)
  gStyle.SetStatFont(42)
  gStyle.SetStatFontSize(0.04)
  gStyle.SetStatTextColor(1)
  gStyle.SetStatFormat("6.4g")
  gStyle.SetStatBorderSize(1)
  gStyle.SetStatH(0.1)
  gStyle.SetStatW(0.2)


  gStyle.SetPadTopMargin(0.05)
  gStyle.SetPadBottomMargin(0.13)
  gStyle.SetPadLeftMargin(0.16)
  gStyle.SetPadRightMargin(0.04)


  gStyle.SetOptTitle(0)
  gStyle.SetTitleFont(42)
  gStyle.SetTitleColor(1)
  gStyle.SetTitleTextColor(1)
  gStyle.SetTitleFillColor(10)
  gStyle.SetTitleFontSize(0.05)


  gStyle.SetTitleColor(1, "XYZ")
  gStyle.SetTitleFont(42, "XYZ")
  gStyle.SetTitleSize(0.06, "XYZ")
  gStyle.SetTitleXOffset(0.9)
  gStyle.SetTitleYOffset(1.25)


  gStyle.SetLabelColor(1, "XYZ")
  gStyle.SetLabelFont(42, "XYZ")
  gStyle.SetLabelOffset(0.007, "XYZ")
  gStyle.SetLabelSize(0.05, "XYZ")


  gStyle.SetAxisColor(1, "XYZ")
  gStyle.SetStripDecimals(True)
  gStyle.SetTickLength(0.03, "XYZ")
  gStyle.SetNdivisions(510, "XYZ")
  gStyle.SetPadTickX(1)
  gStyle.SetPadTickY(1)

  gStyle.SetOptLogx(0)
  gStyle.SetOptLogy(0)
  gStyle.SetOptLogz(0)

  gStyle.SetPaperSize(20.,20.)


  gROOT.ForceStyle()
Ejemplo n.º 19
0
def analysis(input_file, output_file):
    tfile = TFile.Open(input_file, "read")

    sim_data = tfile.Get("simData")
    ''' simData Branches
  gridEnergy [vector<double>]
  gridID [vector<int>]
  gridTrackID [vector<int>]
  scintXPosition [vector<double>]
  scintYPosition [vector<double>]
  scintZPosition [vector<double>]
  scintEnergy [vector<double>]
  scintTrackID [vector<int>]
  scintMass [vector<int>]
  scintCharge [vector<int>]
  beamEnergy [double]
  beamCharge [int]
  beamMass [int]
  energy [double]
  cmEnergy [double]
  vertex [double]
  lightAngleCM [double]
  lightAngleLab [double]
  lightEnergy [double]
  heavyAngleCM [double]
  heavyAngleLab [double]
  heavyEnergy [double]
  qValue [double]
  excitedEnergy [double]
  lightRecoilCharge [int]
  lightRecoilMass [int]
  heavyRecoilCharge [int]
  heavyRecoilMass [int]
  '''
    ''' Reaction Types
  0: 4He, 6/7Li or 7Be with trackID = 1 there is no reaction
  1: 8B with trackID = 3 there was (d, n)
  2: 7Be or 1H with trackID = 5, 4 there was (d, n)8B*
  '''
    ''' Scattering Types
  0: No scattering
  1: (d, d)
  2: (12C, 12C)
  3: (d, n)
  '''

    # Output Files
    output_root = TFile(output_file, "recreate")

    # Canvas Definitions
    #c1 = TCanvas('c1', 'Scint. Energy vs Grid Energy', 200, 10, 800, 600 )
    c2 = TCanvas('scintGridRT',
                 'Scint. Energy vs Grid Energy with Reaction Types', 500, 10,
                 800, 600)
    c3 = TCanvas('scintGridST',
                 'Scint. Energy vs Grid Energy with Scattering Types', 500, 10,
                 800, 600)

    gStyle.SetOptStat(10)
    gStyle.SetStatW(0.1)
    gStyle.SetStatH(0.1)

    # Histogram Definitions
    h_scint_grid = TH2F(
        'scintGrid',
        'Scint. Energy vs Grid Energy; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
        500, 0, 40, 500, 0, 4)
    h_scint_grid.GetXaxis().CenterTitle()
    h_scint_grid.GetYaxis().CenterTitle()

    h_scint_grid_rt = []
    h_scint_grid_rt.append(
        TH2F(
            'scintGridRT0',
            'Scint. Energy vs Grid Energy with Reaction Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_rt.append(
        TH2F(
            'scintGridRT1',
            'Scint. Energy vs Grid Energy with Reaction Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_rt.append(
        TH2F(
            'scintGridRT2',
            'Scint. Energy vs Grid Energy with Reaction Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    for i in range(len(h_scint_grid_rt)):
        h_scint_grid_rt[i].GetXaxis().CenterTitle()
        h_scint_grid_rt[i].GetYaxis().CenterTitle()

    h_scint_grid_st = []
    h_scint_grid_st.append(
        TH2F(
            'scintGridST0',
            'Scint. Energy vs Grid Energy with Scattering Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_st.append(
        TH2F(
            'scintGridST1',
            'Scint. Energy vs Grid Energy with Scattering Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_st.append(
        TH2F(
            'scintGridST2',
            'Scint. Energy vs Grid Energy with Scattering Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_st.append(
        TH2F(
            'scintGridST3',
            'Scint. Energy vs Grid Energy with Scattering Types; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    for i in range(len(h_scint_grid_st)):
        h_scint_grid_st[i].GetXaxis().CenterTitle()
        h_scint_grid_st[i].GetYaxis().CenterTitle()

    h_scint_grid_mp = []
    h_scint_grid_mp.append(
        TH2F(
            'scintGridMP0',
            'Scint. Energy vs Grid Energy with Multiple Particles; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    h_scint_grid_mp.append(
        TH2F(
            'scintGridMP1',
            'Scint. Energy vs Grid Energy with Multiple Particles; Scintillator Energy [MeV]; Total Grid Energy [MeV]',
            500, 0, 40, 500, 0, 4))
    for i in range(len(h_scint_grid_mp)):
        h_scint_grid_mp[i].GetXaxis().CenterTitle()
        h_scint_grid_mp[i].GetYaxis().CenterTitle()

    h_multiple_particles = TH2F(
        'multiple_particles',
        'Mass vs Charge of Events with > 1 Particles; Mass; Charge', 9, 0, 9,
        9, 0, 9)
    h_multiple_particles.GetXaxis().CenterTitle()
    h_multiple_particles.GetYaxis().CenterTitle()

    h_scint_position = TH2F(
        'scint_pos',
        'X-Y Position of Hits in the Scintillator; X [mm]; Y [mm]', 2000, -100,
        100, 2000, -100, 100)
    h_scint_position.GetXaxis().CenterTitle()
    h_scint_position.GetYaxis().CenterTitle()

    h_vertex_position = TH1F('vertex_pos',
                             'Vertex Position of Reaction; Z[mm]', 200, -20,
                             200)
    h_vertex_position.GetXaxis().CenterTitle()
    h_vertex_position.GetYaxis().CenterTitle()

    # Define variables for silhouette score
    silhouette_arr = []
    silhouette_label_2_clusters = []
    silhouette_label_3_clusters = []

    # Define variables for efficiency
    observed = [0] * 3
    generated = [0] * 3

    # Loop over all events in simData
    print("Reading All Events in TTree:")
    for event in tqdm(sim_data, total=sim_data.GetEntries()):

        grid_energy_arr = np.ndarray(event.gridEnergy_count, 'd',
                                     event.gridEnergy)
        grid_id_arr = np.ndarray(event.gridID_count, 'i', event.gridID)

        scint_x_position_arr = np.ndarray(event.scintXPosition_count, 'd',
                                          event.scintXPosition)
        scint_y_position_arr = np.ndarray(event.scintYPosition_count, 'd',
                                          event.scintYPosition)
        scint_energy_arr = np.ndarray(event.scintEnergy_count, 'd',
                                      event.scintEnergy)
        scint_trackid_arr = np.ndarray(event.scintTrackID_count, 'i',
                                       event.scintTrackID)
        scint_mass_arr = np.ndarray(event.scintMass_count, 'i',
                                    event.scintMass)
        scint_charge_arr = np.ndarray(event.scintCharge_count, 'i',
                                      event.scintCharge)

        # Get Reaction Type
        reaction_type = 0
        if (event.beamCharge == 4 and event.lightRecoilCharge == 0
                and event.lightRecoilMass == 1):
            if (event.excitedEnergy < 0.001):
                reaction_type = 1
            else:
                reaction_type = 2

        # Get Scattering Type
        scattering_type = 0
        if event.lightRecoilCharge == 1 and event.lightRecoilMass == 2:
            scattering_type = 1
        elif event.heavyRecoilCharge == 6 and event.heavyRecoilMass == 12:
            scattering_type = 2
        elif event.lightRecoilCharge == 0 and event.lightRecoilMass == 1:
            scattering_type = 3

        generated[reaction_type] += 1

        # Get events with multiple particles hitting scintillator
        multiple_particles = 0
        for i in range(len(scint_trackid_arr)):
            if i == 0:
                previous_track = scint_trackid_arr[i]
            else:
                current_track = scint_trackid_arr[i]
                if previous_track != current_track:
                    multiple_particles = 1

        if multiple_particles:
            for i in range(len(scint_trackid_arr)):
                h_multiple_particles.Fill(scint_mass_arr[i],
                                          scint_charge_arr[i])

        # Get energy in scintillator
        scintillator_energy = np.sum(scint_energy_arr)

        # Get energy in grids
        grid_energy = np.sum(grid_energy_arr)

        tmp_arr = [scintillator_energy, grid_energy]
        silhouette_arr.append(tmp_arr)
        silhouette_label_2_clusters.append(1 if reaction_type > 0 else 0)
        silhouette_label_3_clusters.append(reaction_type)

        # Fill Histograms
        if scintillator_energy > 0.001:
            h_scint_grid.Fill(scintillator_energy, grid_energy)
            h_scint_grid_rt[reaction_type].Fill(scintillator_energy,
                                                grid_energy)
            h_scint_grid_st[scattering_type].Fill(scintillator_energy,
                                                  grid_energy)
            h_scint_grid_mp[multiple_particles].Fill(scintillator_energy,
                                                     grid_energy)

            scintAvgXPos = np.mean(scint_x_position_arr)
            scintAvgYPos = np.mean(scint_y_position_arr)
            h_scint_position.Fill(scintAvgXPos, scintAvgYPos)

            observed[reaction_type] += 1

        h_vertex_position.Fill(event.vertex)

    ############################
    # Done with event by event #
    ############################

    # Write histograms to file
    h_scint_grid.Write()
    for i in range(len(h_scint_grid_rt)):
        h_scint_grid_rt[i].Write()
    for i in range(len(h_scint_grid_st)):
        h_scint_grid_st[i].Write()
    for i in range(len(h_scint_grid_mp)):
        h_scint_grid_mp[i].Write()
    h_multiple_particles.Write()
    h_scint_position.Write()
    h_vertex_position.Write()

    # # Draw histograms
    c2.cd()
    h_scint_grid_rt[0].SetMarkerStyle(20)
    h_scint_grid_rt[0].SetMarkerSize(0.3)
    h_scint_grid_rt[0].SetMarkerColor(1)
    h_scint_grid_rt[0].Draw("P")
    h_scint_grid_rt[1].SetMarkerStyle(20)
    h_scint_grid_rt[1].SetMarkerSize(0.3)
    h_scint_grid_rt[1].SetMarkerColor(2)
    h_scint_grid_rt[1].Draw("PSame")
    h_scint_grid_rt[2].SetMarkerStyle(20)
    h_scint_grid_rt[2].SetMarkerSize(0.3)
    h_scint_grid_rt[2].SetMarkerColor(3)
    h_scint_grid_rt[2].Draw("PSame")
    legend_rt = TLegend(0.6, 0.75, 0.9, 0.9)
    legend_rt.AddEntry(h_scint_grid_rt[0], "No Reaction/Other", "p")
    legend_rt.AddEntry(h_scint_grid_rt[1], "(d, n)^{8}B", "p")
    legend_rt.AddEntry(h_scint_grid_rt[2], "(d, n)^{8}B*", "p")
    legend_rt.Draw()
    c2.Update()
    c2.Write()

    # Draw Scintillator Energy vs Grid Energy for Scattering Types
    c3.cd()
    h_scint_grid_st[1].SetMarkerStyle(20)
    h_scint_grid_st[1].SetMarkerSize(0.3)
    h_scint_grid_st[1].SetMarkerColor(1)
    h_scint_grid_st[1].Draw("P")
    h_scint_grid_st[2].SetMarkerStyle(20)
    h_scint_grid_st[2].SetMarkerSize(0.3)
    h_scint_grid_st[2].SetMarkerColor(2)
    h_scint_grid_st[2].Draw("PSame")
    h_scint_grid_st[3].SetMarkerStyle(20)
    h_scint_grid_st[3].SetMarkerSize(0.3)
    h_scint_grid_st[3].SetMarkerColor(3)
    h_scint_grid_st[3].Draw("PSame")
    legend_st = TLegend(0.6, 0.75, 0.9, 0.9)
    legend_st.AddEntry(h_scint_grid_st[1], "(d, d)", "p")
    legend_st.AddEntry(h_scint_grid_st[2], "(^{12}C, ^{12}C)", "p")
    legend_st.AddEntry(h_scint_grid_st[3], "(d, n)", "p")
    legend_st.Draw()
    c3.Update()
    c3.Write()

    print()
    print("Calculating Silhouette Score")
    silhouette_avg_2_clusters = silhouette_score(silhouette_arr,
                                                 silhouette_label_2_clusters)
    print("Silhouette Score for 2 Clusters: ", silhouette_avg_2_clusters)

    # silhouette_avg_3_clusters = silhouette_score(silhouette_arr, silhouette_label_3_clusters)
    # print("Silhouette Score for 3 Clusters: ", silhouette_avg_3_clusters)

    # Efficiency Ratios
    efficiency_ratio = []
    for i in range(len(observed)):
        efficiency_ratio.append(observed[i] / generated[i])

    print()
    print("Observed/Generated Ratios:")
    for i in range(len(observed)):
        print("Reaction Type %d: %f", i, efficiency_ratio[i])
    print()

    # input('Press Enter to Exit')

    return silhouette_avg_2_clusters, efficiency_ratio[1]
Ejemplo n.º 20
0
    def initialize2(self):
        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(600)  #Height of canvas
        gStyle.SetCanvasDefW(600)  #Width of canvas
        gStyle.SetCanvasDefX(0)  #POsition on screen
        gStyle.SetCanvasDefY(0)

        # For the Pad:
        gStyle.SetPadBorderMode(0)
        # gStyle.SetPadBorderSize(Width_t size = 1)
        gStyle.SetPadColor(kWhite)
        gStyle.SetPadGridX(False)
        gStyle.SetPadGridY(False)
        gStyle.SetGridColor(0)
        gStyle.SetGridStyle(3)
        gStyle.SetGridWidth(1)

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        gStyle.SetFrameFillStyle(1000)
        gStyle.SetFrameFillColor(0)
        gStyle.SetFrameFillStyle(0)
        gStyle.SetFrameLineColor(1)
        gStyle.SetFrameLineStyle(1)
        gStyle.SetFrameLineWidth(1)

        # For the histo:
        # gStyle.SetHistFillColor(1)
        # gStyle.SetHistFillStyle(0)
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(1)
        # gStyle.SetLegoInnerR(Float_t rad = 0.5)
        # gStyle.SetNumberContours(Int_t number = 20)

        gStyle.SetEndErrorSize(2)
        # gStyle.SetErrorMarker(20)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(20)

        #For the fit/function:
        gStyle.SetOptFit(1)
        gStyle.SetFitFormat("5.4g")
        gStyle.SetFuncColor(2)
        gStyle.SetFuncStyle(1)
        gStyle.SetFuncWidth(1)

        #For the date:
        gStyle.SetOptDate(0)
        # gStyle.SetDateX(Float_t x = 0.01)
        # gStyle.SetDateY(Float_t y = 0.01)

        # For the statistics box:
        gStyle.SetOptFile(0)
        gStyle.SetOptStat(
            0)  # To display the mean and RMS:         SetOptStat("mr")
        gStyle.SetStatColor(kWhite)
        gStyle.SetStatFont(42)
        gStyle.SetStatFontSize(0.025)
        gStyle.SetStatTextColor(1)
        gStyle.SetStatFormat("6.4g")
        gStyle.SetStatBorderSize(1)
        gStyle.SetStatH(0.1)
        gStyle.SetStatW(0.15)
        # gStyle.SetStatStyle(Style_t style = 1001)
        # gStyle.SetStatX(Float_t x = 0)
        # gStyle.SetStatY(Float_t y = 0)

        # Margins:
        gStyle.SetPadTopMargin(0.05)
        gStyle.SetPadBottomMargin(0.13)
        gStyle.SetPadLeftMargin(0.16)
        gStyle.SetPadRightMargin(0.02)

        # For the Global title:

        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.05)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        # gStyle.SetTitleX(0) # Set the position of the title box
        # gStyle.SetTitleY(0.985) # Set the position of the title box
        # gStyle.SetTitleStyle(Style_t style = 1001)
        # gStyle.SetTitleBorderSize(2)

        # For the axis titles:

        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.06, "XYZ")
        # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
        # gStyle.SetTitleYSize(Float_t size = 0.02)
        gStyle.SetTitleXOffset(0.9)
        gStyle.SetTitleYOffset(1.25)
        # gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.05, "XYZ")

        # For the axis:

        gStyle.SetAxisColor(1, "XYZ")
        gStyle.SetStripDecimals(True)
        gStyle.SetTickLength(0.03, "XYZ")
        gStyle.SetNdivisions(510, "XYZ")
        gStyle.SetPadTickX(
            1)  # To get tick marks on the opposite side of the frame
        gStyle.SetPadTickY(1)

        # Change for log plots:
        gStyle.SetOptLogx(0)
        gStyle.SetOptLogy(0)
        gStyle.SetOptLogz(0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
Ejemplo n.º 21
0
def rootStyle(batchMode=True):
    from ROOT import gROOT, gStyle, kWhite, kBlack

    # No info messages
    gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;")

    # Batch mode (no TCanvas)
    gROOT.SetBatch(batchMode)

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

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

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

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

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Force the style
    gROOT.ForceStyle()