-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
639 additions
and
290 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,44 @@ | ||
from matplotlib.pyplot import xlabel | ||
from FourTracks import pd, np, plt, hep | ||
from typing import Sized, Union | ||
|
||
|
||
def DrawErrorHists( | ||
def DrawErrorHist( | ||
data: list, | ||
bins: int, | ||
range: tuple, | ||
title: str, | ||
label: list, | ||
x_label: list, | ||
y_label: list, | ||
color: list, | ||
x_label: str, | ||
y_label: str, | ||
showBinWidth: bool = True, | ||
xerr: bool = True, | ||
MeV: bool = True, | ||
**histplot_kwargs, | ||
) -> pd.DataFrame: | ||
""" | ||
Function draws histogram list with errors bars. | ||
""" | ||
|
||
# if ( | ||
# pd.DataFrame([data, label, x_label, y_label, color]).count(axis=1).nunique() | ||
# != 1 | ||
# ): | ||
# raise IndexError("Input lists have different sizes") | ||
|
||
plt.style.use(hep.style.ROOT) | ||
fig = plt.figure() | ||
ax = fig.add_subplot() | ||
fig.suptitle(title) | ||
|
||
for i in np.arange(len(data)): | ||
hep.histplot( | ||
np.histogram(data[i], bins=bins, range=range), | ||
yerr=True, | ||
xerr=xerr, | ||
color=color[i], | ||
histtype="errorbar", | ||
label=label[i], | ||
) | ||
val = (range[1] - range[0]) / bins | ||
|
||
val = (range[1] - range[0]) * 1000 // bins | ||
ax.set_xlabel(x_label[i]) | ||
ylabel = y_label[i] | ||
if showBinWidth: | ||
ylabel = ylabel + " per " + f"{val:.0f} MeV/c" | ||
ax.set_ylabel(ylabel) | ||
|
||
_ = plt.legend() | ||
return pd.DataFrame(map(pd.DataFrame.describe, data), index=label) | ||
hep.histplot( | ||
[np.histogram(d, bins=bins, range=range) for d in data], | ||
yerr=True, | ||
xerr=[0, val/2][showBinWidth], | ||
**histplot_kwargs, | ||
) | ||
|
||
ax.set_xlabel(x_label) | ||
ylabel = y_label | ||
if showBinWidth: | ||
ylabel = ( | ||
ylabel + " per " + f"{[1,1000][MeV] * val:.0f} {['GeV/c','MeV/c'][MeV]}" | ||
) | ||
ax.set_ylabel(ylabel) | ||
|
||
def DrawErrorHist( | ||
data: Union[list, pd.Series, np.ndarray], | ||
bins: int, | ||
range: tuple, | ||
title: str, | ||
label: str, | ||
x_label: str, | ||
y_label: str, | ||
color: str, | ||
showBinWidth: bool = True, | ||
xerr: bool = True, | ||
): | ||
return DrawErrorHists( | ||
[data], | ||
bins=bins, | ||
range=range, | ||
title=title, | ||
label=[label], | ||
x_label=[x_label], | ||
y_label=[y_label], | ||
color=[color], | ||
showBinWidth=showBinWidth, | ||
xerr=xerr, | ||
_ = plt.legend() | ||
return pd.DataFrame( | ||
map(pd.DataFrame.describe, data), index=histplot_kwargs["label"] | ||
) | ||
|