Reading and writing in different formats¶
Heppy histograms can be written to and read from the native text-based format
using heppy.basehistogram.to_file()
and heppy.from_file()
.
ROOT¶
Reading from a ROOT file:
-
heppy.
readroot
(rootfile, histpath, variation_paths={}, ignore_missing_variations=False, **kwargs)¶ Reads a histogram (possibly with systematic variations) from a ROOT file.
Parameters: - rootfile (
str
) – path to ROOT file - histopath (
str
) – path of the histogram inside the file - variation_paths (
dict
ofstr : str
) – optional dictionary of variation names (keys) and paths to the variation histograms inside the same ROOT file (values). NOTE: we can easily add the ability to read variation histograms also from other ROOT files than the nominal, get in touch if you want that. - **kwargs –
get passed on to histogram constructor. An important one is
areas=False
if retrieving ratios (e.g. efficiencies).
- rootfile (
Converting to ROOT histograms and writing to ROOT files can be done using
heppy.histogram1d.to_root()
and
heppy.histogram1d.to_root_file()
(for 1D histograms) and
heppy.histogram2d.to_root()
and
heppy.histogram2d.to_root_file()
(for 2D histograms).
Rivet (YODA)¶
One-dimensional histograms can be written to the Rivet YODA format using
heppy.histogram1d.to_yoda()
or its synonym
heppy.histogram1d.to_rivet()
.
TRExFitter (YAML)¶
Reading TRExFitter YAML format:
-
heppy.
readtrex
(trexfile, unfolded_format=False)¶ Reads Heppy histogram from TRExFitter YAML format.
Requires PyYAML.
IMPORTANT: the uncertainties are treated as correlated uncertainties, since their actual correlations cannot be inferred from the histogram. So treat them with care: they’re fine for plotting and looking at individual bins, but do not rebin the histogram or do statistical testing involving its shape and assume that you will find correct results.
Parameters: - trexfile (
str
) – path to input file. - unfolded_format (
bool
) – set this to True if reading the YAML format that TRExFitter uses for unfolded cross sections.
- trexfile (