A small collection of utilities for handling ROOT TTrees with uproot.
Project description
uproot_tree_utils
A small collection of utilities for handling ROOT TTrees with uproot.
Usage
There are two functions currently in the package. The first is clone_tree
:
clone_tree(tree, new_filename, new_treename=None, branches=None, selection=None, new_branches=None)
The required arguments tree
and new_filename
are the TTree object to copy from (as retrieved by uproot) and the file to copy to, respectively. The simplest usage looks like
import uproot
from uproot_tree_utils import clone_tree
file = uproot.open('some_root_file.root')
clone_tree(file['the_treename'], 'a_new_filename.root')
This will simply copy the entire tree from the original file to a new file (with no other objects).
new_treename
can be used to give the new tree a different name. The default is the original tree's name.branches
can be a list of strings representing the branches to copy. Only the selected branches will be in the new file.selection
is an optional array determining which events to copy. This can be a boolean mask or integers corresponding to the desired event indices.new_branches
allows the user to pass a dictionary of new branches to insert into the tree. The format for the dictionary should be{'new_branchname': array_with_branch_data}
.
The other function available is write_tree
:
write_tree(branches, filename, treename)
This function will create a new tree entirely composed of arrays passed to it.
branches
is a dictionary with items of the form'branchname': array_with_branch_data
filename
is the name of a new file to put the tree intreename
is the name of the new tree
Limitations
Not all branch types can be written by uproot.
Currently supported branch types:
Char_t
/char
Short_t
/short
Int_t
/int
Float_t
/float
Double_t
/double
Long64_t
/long long
Bool_t
/bool
std::vector<short>
std::vector<int>
std::vector<float>
std::vector<double>
Character strings, unsigned integers, vector<char>
, and vector<bool>
are not yet supported. There are also some known bugs with vector<long>
and vector<long long>
. Further nesting of vectors (e.g. vector<vector<int> >
) is not supported by uproot's tree writing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uproot_tree_utils-0.2.tar.gz
.
File metadata
- Download URL: uproot_tree_utils-0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77dc186b826f7e9f73c1197b99b0bc81d82fed87072164b5ab63f4f341e0dbbd |
|
MD5 | 171174c186fb652260a702c76e93294e |
|
BLAKE2b-256 | 374bde13ac67fa344b5acb30825b0b7610a1d06a2299bd8a3cb18ebeeb847359 |
File details
Details for the file uproot_tree_utils-0.2-py3-none-any.whl
.
File metadata
- Download URL: uproot_tree_utils-0.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ee58a3c2a04da89ed500375682d51ad1d837d8179762f805ef11ba432a75fb8 |
|
MD5 | f4f1da52f9911a3ecb5f9b77cf5d087a |
|
BLAKE2b-256 | 941d4c32fe7ba99ad149aa906273a1985da40f4fa66034438c41ec804aab6460 |