Example #1
0
def test_BinnedDataframe_user_var_run(config_3, tmpdir, full_wrapped_tree):
    config_4 = copy.deepcopy(config_3)
    config_4["binning"][0]["in"] = "Electron_Pt"
    binned_df_4 = bdf.BinnedDataframe("binned_df_4", out_dir="somewhere", **config_4)

    chunk = FakeBEEvent(full_wrapped_tree, "mc")
    px, py = chunk.tree.arrays(["Electron_Px", "Electron_Py"], outputtype=tuple)
    pt = np.hypot(px, py)
    chunk.tree.new_variable("Electron_Pt", pt)
    collector = binned_df_4.collector()

    binned_df_4.event(chunk)
    dataset_readers_list = (("test_dataset", (binned_df_4,)),)
    results = collector._prepare_output(dataset_readers_list)

    bin_centers = pd.IntervalIndex(results.index.get_level_values('electron_pT')).mid
    mean = np.sum((bin_centers[1:-1] * results['n'][1:-1]) / results['n'][1:-1].sum())
    assert mean == pytest.approx(44.32584)
Example #2
0
def binned_df_2(tmpdir, config_2):
    return bdf.BinnedDataframe("binned_df_2", out_dir="somewhere", **config_2)
Example #3
0
def make_binned_df_1(config_1):
    return bdf.BinnedDataframe("binned_df_1", out_dir="somewhere", **config_1)
Example #4
0
def binned_df_2_weightData(tmpdir, config_2):
    return bdf.BinnedDataframe("binned_df_2_weightData", out_dir="somewhere",
                               weight_data=True, **config_2)