Пример #1
0
def _integral_transformer_aux(points, comp, values=None):
    '''
    Auxiliar function to perform check of the FlatDistTransform class.
    '''
    tr = hep_spt.FlatDistTransform(points, values)

    vals = tr.transform(comp)

    # Check that the values are between 0 and 1
    assert np.all(vals >= 0) and np.all(vals <= 1)

    bins = 20
    values, edges = np.histogram(vals, bins, range=(0, 1))

    centers = hep_spt.cfe(edges)

    p, residuals, _, _, _ = np.polyfit(centers, values, 0, full=True)

    # Check the mean of the values (depends on the number of bins and on the
    # length of the samples)
    assert np.isclose(p, len(points) / float(bins))

    chi2_ndof = residuals / (len(values) - 1.)

    return chi2_ndof
Пример #2
0
def test_residual_asym():
    '''
    Test the "residual" function with asymmetric errors.
    '''
    size = 1000
    data = np.random.normal(0, 2, size)

    values, edges, ex, ey = hep_spt.errorbar_hist(data, uncert='freq')

    centers = hep_spt.cfe(edges)

    rv = norm.pdf(centers)
    ref = float(size)*rv/rv.sum()

    res, perr = hep_spt.residual(values, ey, ref)

    assert perr.shape == (2, len(values))
    assert np.allclose(res, values - ref)
Пример #3
0
def test_pull_asym():
    '''
    Test the "pull" function with asymmetric errors.
    '''
    size = 1000
    data = np.random.normal(0, 2, size)

    values, edges, ex, ey = hep_spt.errorbar_hist(data, uncert='freq')

    centers = hep_spt.cfe(edges)

    rv = norm.pdf(centers)
    ref = float(size)*rv/rv.sum()

    pull, perr = hep_spt.pull(values, ey, ref)

    assert perr.shape == (2, len(values))

    p = values - ref

    assert np.all(pull[p >= 0] >= 0)
    assert np.all(pull[p < 0] < 0)
Пример #4
0
def test_cfe():
    '''
    Test the "cfe" function.
    '''
    assert np.all(hep_spt.cfe(np.array([1, 3, 5, 7])) == [2, 4, 6])