Questions tagged [uproot]

A library for reading [root-framework] data into [numpy] and [awkward-array].

uproot is a narrowly-scoped Python library whose sole function is to read data from ROOT files, which are widely used in the particle physics community (see ).

Rather than reconstituting data as C++ objects, as ROOT does, uproot reads columns of data as NumPy arrays. If the data have too much structure to represent in NumPy, such as a collection of unequal-length std::vector<X>, uproot uses to return jagged arrays with NumPy-like semantics.

uproot can read most types of objects serialized by ROOT, including TTree datasets, Lorentz vectors, histograms, and other types of graphs. Custom behaviors for these objects can be defined by adding functions to uproot-methods.

uproot interfaces with , , , cachetools, Python's concurrent.futures, and xrootd.

94 questions
3
votes
1 answer

Writing Trees, number of baskets and compression (uproot)

I am trying to optimize the way trees are written in pyroot and came across uproot. In the end my application should write events (consisiting of arrays) to a tree which are continuously coming in. The first approach is the classic way: event=…
Jailbone
  • 83
  • 6
3
votes
2 answers

Retrieve data in Pandas

I am using pandas and uproot to read data from a .root file, and I get a table like the following one: The aforementioned table is made with the following code: fname = 'ZZ4lAnalysis_VBFH.root' key = 'ZZTree/candTree' ttree =…
aleolomorfo
  • 133
  • 1
  • 5
3
votes
4 answers

What the fastest, most memory-efficient way of opening a ROOT NTuple for machine learning?

I'm setting up a machine learning project with scikit learn. The input data are flat ROOT NTuples. In the past I have been using root_numpy to convert the NTuples to pandas.DataFrame saved in an h5 file. I was wondering if I could use uproot to a)…
GabrielG
  • 31
  • 3
3
votes
1 answer

how to access custom classes with uproot?

Can you please tell me why uproot doesn't interpret the trees: Evt, AAObject, TObject and t? I am probably doing something wrong here because I am not familiar with root files. My goal: open data in my root file into pandas DataFrame. When I try to…
zineb a
  • 53
  • 3
2
votes
1 answer

Casting a char* type on a Branch using mktree

I'm trying to recreate a root file that contains a char* type branch (which is interpreted by uproot as AsStrings()) When using mktree uproot doesn't recognize the np.dtype('string') and when trying np.dtype('S') I get: TypeError: cannot write NumPy…
2
votes
0 answers

Trees written with uproot, cannot be read properly

I have created a script that reads from some root files, does some processing, and creates a slimmed version of these files, using uproot3 (3.14.4). Then I use these files I created to create histograms needed for my analysis. The problem that I…
maevius3
  • 21
  • 3
2
votes
0 answers

Histogram bin edges read wrong in uproot 4

Edit: this is a version problem. Uproot 4.3.7 produces the expected result, while the error below occurred in 4.0.0 I am creating 1-D histograms in ROOT with non-uniform bin sizes, then accessing them with uproot. The bin edges are not returned…
2
votes
0 answers

How to access contents of a TLorentz vector using python code

I am using the uproot package in python to read a .root file, and I need to access the contents of pf. As you can see from the picture, I can easily access the content of vz (blue arrows). However, when accessing the contents of pf (red arrows), it…
2
votes
1 answer

Can uproot3 write TBranches containing arrays?

In uproot 3 documentation there is information, that uproot can write only branches containing 1 value per entry. On the other hand, I can see some topics on uproot Github regarding writing jagged arrays, etc. So, I would like to make sure: can…
2
votes
0 answers

Can uproot4 write TTrees?

uproot3 had some limited writing capabilities, is writing TTrees possible in uproot4? In particular, I would like to create a skim, just discarding branches and one or two simple event-level cuts.
Andrzej Novák
  • 136
  • 1
  • 8
2
votes
2 answers

Reshape Array in Array in Array

I have a root file that I open with 2000 entries, and variable amount of subentries and in each column is a different variable. Lets say I am only interested in 5 of those. I want to put them in an array with np.shape(array)=(2000,250,5). The 250 is…
2
votes
0 answers

Read parts of a tree with uproot4

I have a single file with a single ROOT tree and would like to read it with uproot4 in multiple processes, with each of them reading disjoint parts of the tree. With uproot3 this was possible by passing an iterable for entrysteps: def…
YSelf
  • 2,646
  • 1
  • 14
  • 19
2
votes
1 answer

Import dataset from a ROOT file with cut using zfit

I am trying to perform a fit to a tree. But I need to add some cut to the branches which are not the observables of the fit. Website https://zfit.readthedocs.io/en/latest/getting_started/intro/data.html tells me that I can include cuts in the…
Xuelong
  • 21
  • 1
2
votes
0 answers

Flattening of 3x3 arrays in uproot.pandas.iterate

I'm trying to modify one of my existing scripts that uses uproot to read data from a root file into a pandas dataframe using uproot.pandas.iterate. Currently it only reads branches containing simple data types (floats, ints, bools), but I would like…
DylanJaide
  • 385
  • 1
  • 3
  • 13
2
votes
1 answer

How to use np arrays as a mask for jagged arrays (python - awkward)?

I have a root file from which I would like to extract a certain candidate per event. On the other hand, I have a numpy array containing the index of the candidate I want to extract. Let's say that my root file has the following branch: branch =…
Horace
  • 62
  • 4
1
2 3 4 5 6 7