Ejemplo n.º 1
0
 def test_rebin_1d(self):
     hist = _get_hist(1)
     # only checking the basic case here, since basically only the return
     # statement is different from the 3d case
     re_hist = hu.rebin(hist, [('x', 2)])
     self.assertEqual(hu._get_nbins(hist), (10,))
     self.assertEqual(hu._get_nbins(re_hist), (2,))
Ejemplo n.º 2
0
    def test_uniform_rebinning(self):
        hist = _get_hist(1)
        targ_bin = np.linspace(0, 1, 6)

        # since hist has 10 bin, rebin(hist, 5) should return the same histogram
        # as the one when we rebin it according to a custom binning
        npt.assert_allclose(hu.get_array(hu.rebin_1d_binning(hist, targ_bin)),
                            hu.get_array(hu.rebin(hist, [(0, 5)])))
Ejemplo n.º 3
0
    def test_rebin_3d(self):
        hist = _get_hist(3)
        # some more possibilities here
        re_hist = hu.rebin(hist, [(0, 2), (1, 5), (2, 6)])

        self.assertEqual(hu._get_nbins(hist), (10, 20, 30))
        self.assertEqual(hu._get_nbins(re_hist), (2, 5, 6))

        # check that char indices work
        re_hist = hu.rebin(hist, [('x', 5), ('Y', 2), ('z', 3)])
        self.assertEqual(hu._get_nbins(hist), (10, 20, 30))
        self.assertEqual(hu._get_nbins(re_hist), (5, 2, 3))

        # check that in principle also mixed indices work
        re_hist = hu.rebin(hist, [('x', 5), ('Y', 2), (2, 3)])
        self.assertEqual(hu._get_nbins(hist), (10, 20, 30))
        self.assertEqual(hu._get_nbins(re_hist), (5, 2, 3))
Ejemplo n.º 4
0
 def test_rebin_4d(self):
     hist = _get_hist(4)
     # NOTE: only very limited possibilities to do an actual rebinning
     # here
     re_hist = hu.rebin(hist, [(0, 1), (2, 2)])
     # check original hist is unchanged
     self.assertEqual(hu._get_nbins(hist), (2, 3, 4, 5))
     self.assertEqual(hu._get_nbins(re_hist), (1, 3, 2, 5))
def get_scaled_ppd(hfile, var, nbins=None):
    """
    Get the ppd scaled to unity
    """
    ppd = hfile.Get('ppd_1d_{}'.format(var))
    if nbins is not None:
        ppd = rebin(ppd, [(0, nbins)])
    ppd.Scale(1 / ppd.Integral())
    return ppd
Ejemplo n.º 6
0
def make_debug_plot(comb_ppd, inputfiles, var):
    """
    Make a plot overlaying the combined ppd and the input ppds
    """
    can = PLOT_FUNCTIONS[var](rebin(comb_ppd, [(0, 200)]))
    set_color(can.pltables[1], 1)  # make the combined ppd black

    ppds = [get_scaled_ppd(f, var, 200) for f in inputfiles]
    mkplot(ppds,
           can=can,
           drawOpt='samehist',
           attr=default_attributes(linewidth=1))

    return can
def make_ppd_comp_plot(nom_file, var_files, var):
    """
    Make a plot comparing the full ppds directly (shifting all of them by the
    median of the nominal ppd).
    """
    n_bins = {'dlth': 100, 'dlph': 400, 'dkappa': 400}

    nom_ppd = get_scaled_ppd(nom_file, var)
    nom_med = get_quantiles(nom_ppd, 0.5)
    nom_ppd = shift_by_median(rebin(nom_ppd, [(0, n_bins[var])]), nom_med)
    nom_ppd.Scale(1.0 / nom_ppd.Integral())

    var_ppds = [
        get_scaled_ppd(f, var, n_bins[var]) for f in var_files.values()
    ]
    var_ppds = [shift_by_median(p, nom_med) for p in var_ppds]
    [p.Scale(1.0 / p.Integral()) for p in var_ppds]

    xran = {'dlth': [-2, 2], 'dlph': [-0.5, 0.5], 'dkappa': [-0.5, 0.5]}

    leg = create_legend(0.69, 0.88, 0.94, len(var_ppds) + 1)

    label = '{0} - #bar{0}_{{nominal}}'.format(YLABELS.get(var))

    can = mkplot(nom_ppd,
                 attr=[{
                     'color': 1,
                     'fillalpha': (1, 0.25)
                 }],
                 drawOpt='hist',
                 yLabel='PPD [a.u.]',
                 xLabel=label,
                 xRange=xran[var],
                 yRange=[0, None],
                 leg=leg,
                 legEntries=['nominal'],
                 legOpt='F')

    mkplot(var_ppds,
           can=can,
           drawOpt='histsame',
           attr=default_attributes(linewidth=2),
           leg=leg,
           legEntries=var_files.keys(),
           legOpt='L')
    return can
Ejemplo n.º 8
0
def _make_dlth_plot(hfile, shift=None):
    """
    Make the dlth plot
    """
    ppd = get_scaled_ppd(hfile, 'dlth')
    ppd = rebin(shift_by_median(ppd, shift), [(0, 200)])
    ppdmax = get_y_max(ppd)
    can = mkplot(ppd,
                 xLabel=YLABELS['dlth'],
                 xRange=[-2, 2],
                 drawOpt='hist', yLabel='PPD [a.u.]')

    mkplot([r.TLine(v, 0, v, ppdmax * 1.1) for v in [-1.6, 1.3333]], can=can,
           drawOpt='same', attr=[{'color': 12, 'line': 7, 'width': 2}])

    # ltx = setup_latex()
    # put_on_latex(ltx, [
    #     (0.65, 0.8, '+{:.2f}'.format(np.diff(get_quantiles(ppd, [0.5, 0.84]))[0])),
    #     (0.40, 0.8, '#minus{:.2f}'.format(np.diff(get_quantiles(ppd, [0.16, 0.5]))[0]))
    # ], ndc=True)

    make_nice(can)
    return can
def make_lth_plot(ppd_files):
    """Make the plots for the lth1 ppds"""
    ppds = [get_scaled_ppd(f, 'lth') for f in ppd_files.values()]
    quantiles = [get_quantiles(p, 0.1) for p in ppds]
    ppds = [rebin(p, [(0, 100)]) for p in ppds] # for plotting

    leg = setup_legend(0.18, 0.7, 0.48, 0.84)
    leg.SetTextSize(0.0425)
    leg.SetFillColor(0)
    leg.SetFillStyle(1001)

    # Draw boundaries first to not draw it over the legend in the end
    can = mkplot(r.TLine(-1./3., 0, -1./3., get_y_max(ppds) * 1.1),
                 attr=BOUND_ATTR,
                 xRange=[-1, 1], xLabel='#lambda_{#vartheta}^{#chi_{c1}}',
                 yRange=[0, get_y_max(ppds) * 1.1], yLabel='PPD [a.u.]')

    can = mkplot(ppds, drawOpt='hist same', can=can,
                 leg=leg, legOpt='L',
                 legEntries=['{} < p_{{T}} < {} GeV'.format(*p) for p in ppd_files.keys()])
    can.pltables[0].GetYaxis().SetNdivisions(505)
    can.pltables[0].GetXaxis().SetNdivisions(505)

    mkplot([r.TLine(q, 0, q, 0.01) for q in quantiles], can=can, drawOpt='same')

    arrow_attr = default_attributes(open_markers=False)
    for att in arrow_attr:
        att['fill'] = att['color']
        att['width'] = 2

    mkplot([
        r.TArrow(q, v, q + 0.125, v, 0.025, '<|') for q, v in zip(quantiles, [0.0015, 0.003, 0.0045])
    ],
           can=can, drawOpt='same <|', attr=arrow_attr)

    return add_info(can, 'left')