hepconvert.merge_root
Defined in hepconvert.merge on line 240.
- hepconvert.merge_root(destination, files, *, keep_branches=None, drop_branches=None, keep_trees=None, drop_trees=None, cut=None, expressions=None, progress_bar=None, fieldname_separator='_', title='', field_name=<function <lambda>>, initial_basket_capacity=10, resize_factor=10.0, counter_name=<function <lambda>>, step_size='100 MB', force=False, append=False, compression='zlib', compression_level=1, skip_bad_files=False)
Merges TTrees together, and adds values in histograms from local ROOT files, and writes them to a new ROOT file. Similar to ROOT’s hadd function.
- Parameters:
destination (path-like) – Name of the output file or file path.
files (str or list of str) – List of local ROOT files to merge. May contain glob patterns.
keep_branches (list of str, str, or dict, optional) – To keep only certain branches and remove all others. To remove certain branches from all TTrees in the file, pass a list of names of branches to keep, wildcarding accepted (“Jet_*”). If removing branches from one of multiple trees, pass a dict of structure: {tree: [branch1, branch2]} to keep only branch1 and branch2 in ttree “tree”. Defaults to None. Command line option:
--keep-branches
.drop_branches (list of str, str, or dict, optional) – To remove branches from all trees, pass a list of names of branches to remove. Wildcarding supported (“Jet_*”). If removing branches from one of multiple trees, pass a dict of structure: {tree: [branch1, branch2]} to remove branch1 and branch2 from TTree “tree”. Defaults to None. Command line option:
--drop-branches
.keep_trees (str or list of str, optional) – To keep only certain a TTrees in a file, pass a list of names of trees to keep. All others will be removed. Defaults to None. Command line option:
--keep-trees
.drop_trees (str or list of str, optional) – To remove a TTree from a file, pass a list of names of trees to remove. Defaults to None. Command line option:
--drop-trees
.cut (None or str) – If not None, this expression filters all of the
expressions
.expressions (None, str, or list of str) – Names of
TBranches
or aliases to convert to arrays or mathematical expressions of them. Uses thelanguage
to evaluate. If None, allTBranches
selected by the filters are included.progress_bar (Bool, tqdm.std.tqdm object) – Displays a progress bar. Can input a custom tqdm progress bar object, or set
True
for a default tqdm progress bar. Must have tqdm installed.fieldname_separator (str, optional) – Character that separates TBranch names for columns, used for grouping columns (to avoid duplicate counters in ROOT file).
field_name (callable of str → str, optional) – Function to generate TBranch names for columns of an Awkward record array or a Pandas DataFrame.
initial_basket_capacity (int, optional) – Number of TBaskets that can be written to the TTree without rewriting the TTree metadata to make room. Command line option:
--initial-basket-capacity
.resize_factor (float, optional) – When the TTree metadata needs to be rewritten, this specifies how many more TBasket slots to allocate as a multiplicative factor. Command line option:
--resize-factor
.step_size (int or str) – If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size to include. The string must be a number followed by a memory unit, such as “100 MB”. Recommended to be >100 kB. Command line option:
--step-size
.force (bool, optional) – If True, overwrites destination file if it exists. Force and append cannot both be True. Command line option:
--force
.append (bool, optional) – If True, appends data to an existing file. Force and append cannot both be True. Command line option:
--append
.compression (str, optional) – Sets compression level for root file to write to. Can be one of “ZLIB”, “LZMA”, “LZ4”, or “ZSTD”. By default the compression algorithm is “ZLIB”. Command line option:
--compression
.compression_level (int, optional) – Use a compression level particular to the chosen compressor. By default the compression level is 1. Command line option:
--compression-level
.skip_bad_files (bool, optional) – If True, skips corrupt or non-existent files without exiting. Command line option:
--skip-bad-files
.
Example:
>>> hepconvert.merge_root("destination.root", ["file1.root", "file2.root"])
Command Line Instructions:
This function can be run from the command line. Use command
hepconvert merge [options] [OUT_FILE] [IN_FILES]