Created
December 18, 2019 22:46
-
-
Save kratsg/db184f6be63afb6bf8b8690a15abe31b to your computer and use it in GitHub Desktop.
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
import uproot | |
from pathlib import Path | |
import numpy as np | |
cwd = Path('.') | |
out_branches = ['bjets_n'] | |
for input_fname in cwd.glob('*.root*'): | |
output_fname = Path(f'out_{input_fname.parts[-1]}') | |
with uproot.recreate(output_fname) as out_file: | |
in_file = uproot.open(input_fname) | |
print(f"Opening {input_fname} and writing to {output_fname}") | |
for tree_name, tree in in_file.items(): | |
print(f" ... processing {tree_name}") | |
branches = {b:tree[b].interpretation.todtype for b in out_branches} | |
out_treename = tree_name.split(b';')[0] | |
out_file[out_treename] = uproot.newtree(branches) | |
for events in tree.iterate(branches=out_branches, namedecode='utf-8'): | |
out_file[out_treename].extend(events) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment