Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null poissonian #67

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions fast_plotter/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,12 @@ def plot_1d_many(df, prefix="", data="data", signal=None, dataset_col="dataset",
(in_df_data, plot_data, kind_data, data_legend, "plot_data"),
(in_df_signal, plot_signal, kind_signal, "Signal", "plot_signal"),
]
kwargs.setdefault("is_null_poissonian", False)
for df, combine, style, label, var_name in config:
if df is None or len(df) == 0:
continue
merged = _merge_datasets(df, combine, dataset_col, param_name=var_name, err_from_sumw2=err_from_sumw2)
merged = _merge_datasets(df, combine, dataset_col, param_name=var_name, err_from_sumw2=err_from_sumw2,
is_null_poissonian=kwargs['is_null_poissonian'])
actually_plot(merged, x_axis=x_axis, y=y, yerr=yerr, kind=style,
label=label, ax=main_ax, dataset_col=dataset_col,
dataset_colours=dataset_colours,
Expand All @@ -392,9 +394,11 @@ def plot_1d_many(df, prefix="", data="data", signal=None, dataset_col="dataset",
if summary.startswith("ratio"):
main_ax.set_xlabel("")
summed_data = _merge_datasets(
in_df_data, "sum", dataset_col=dataset_col, err_from_sumw2=err_from_sumw2)
in_df_data, "sum", dataset_col=dataset_col, err_from_sumw2=err_from_sumw2,
is_null_poissonian=kwargs['is_null_poissonian'])
summed_sims = _merge_datasets(
in_df_sims, "sum", dataset_col=dataset_col, err_from_sumw2=err_from_sumw2)
in_df_sims, "sum", dataset_col=dataset_col, err_from_sumw2=err_from_sumw2,
is_null_poissonian=kwargs['is_null_poissonian'])
if summary == "ratio-error-both":
error = "both"
elif summary == "ratio-error-markers":
Expand All @@ -411,15 +415,16 @@ def plot_1d_many(df, prefix="", data="data", signal=None, dataset_col="dataset",
return main_ax, summary_ax


def _merge_datasets(df, style, dataset_col, param_name="_merge_datasets", err_from_sumw2=False):
def _merge_datasets(df, style, dataset_col, param_name="_merge_datasets", err_from_sumw2=False,
is_null_poissonian=False):
if style == "stack":
df = utils.stack_datasets(df, dataset_level=dataset_col)
elif style == "sum":
df = utils.sum_over_datasets(df, dataset_level=dataset_col)
elif style:
msg = "'{}' must be either 'sum', 'stack' or None. Got {}"
raise RuntimeError(msg.format(param_name, style))
utils.calculate_error(df, do_rel_err=not err_from_sumw2)
utils.calculate_error(df, do_rel_err=not err_from_sumw2, is_null_poissonian=is_null_poissonian)
return df


Expand Down
6 changes: 5 additions & 1 deletion fast_plotter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def split_data_sims(df, data_labels=["data"], dataset_level="dataset"):
return split_df(df, first_values=data_labels, level=dataset_level)


def calculate_error(df, sumw2_label="sumw2", err_label="err", inplace=True, do_rel_err=True):
def calculate_error(df, sumw2_label="sumw2", err_label="err", inplace=True, do_rel_err=True, is_null_poissonian=False):
if not inplace:
df = df.copy()
if do_rel_err:
Expand All @@ -105,6 +105,10 @@ def calculate_error(df, sumw2_label="sumw2", err_label="err", inplace=True, do_r
elif not do_rel_err and sumw2_label in column:
err_name = column.replace(sumw2_label, err_label)
df[err_name] = np.sqrt(df[column])
else:
continue
if is_null_poissonian:
df[err_name] = df[err_name].apply(lambda x: x if x > 1.15 else np.sqrt(1.15**2+x**2))
if not inplace:
return df

Expand Down