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
2
votes
1 answer

Loop over pandas.dataframe's entries or sub-entries

I am using uproot to convert a ROOT.TTree into a pandas.dataframe. The structure of the dataframe can be seen below. Note that ‘met’ is an entry level variable, while ‘mu_cells_*’ is a subentry level variable. Now I want to create a ROOT.TH1…
2
votes
1 answer

Combine awkward-array JaggedArray contents and offsets into nested JaggedArray

I'm trying to use the excellent uproot and awkward-array to read some analysis data stored in a TTree. I understand that ROOT doesn't write nested vectors (ie. std::vector>) in a columnar format, but following this discussion, I…
2
votes
1 answer

Get data from Pandas multiIndex

I am using pandas and uproot to read data from a .root file, and I get a table like the following one: table So, from my .root file I have got some branches of a tree. fname = 'ZZ4lAnalysis_VBFH.root' key = 'ZZTree/candTree' ttree =…
aleolomorfo
  • 133
  • 1
  • 5
2
votes
1 answer

Reindex Panda Multiindex

I am trying to create a new index for a dataframe from created from a root file. I'm using uproot to bring in the file using the command upfile_muon = uproot.open(file_prefix_muon + '.root') tree_muon = upfile_muon['ntupler']['tree'] df_muon =…
2
votes
1 answer

How to read large set of data as lazyarrays

I am trying to read a large set of data as lazyarrays doing the following: import uproot import numpy as np file_path = "~/data.root" data = uproot.lazyarrays(file_path, "E") hits = data['hits'] >>>
zineb a
  • 53
  • 3
2
votes
0 answers

Using Chunked array (Akwkard lib) for fancy indexing or masking

I am loading a root file with uproot.lazyarrays() which produces a Table. I compute a function of this table which returns a JaggedArray whose length is equal to the length of the table. This is in the form of a ChunkedArray, and I would like to use…
2
votes
1 answer

How to get uproot.iterate() output like the root_numpy root2array() output fast

array2root returns a list of tuples with a dtype containing the branch names. Is there a way to return the same type of format from uproot.iterate() without costly reshaping it afterwards? Output should be the same as from array =…
Andrzej Novák
  • 136
  • 1
  • 8
2
votes
0 answers

uproot.lazyarrays not reading what uproot.open shows

back with another quick question in learning how to use uproot correctly. I am trying to load a Delphes output .root file and I am trying to transition from using uproot.open to using uproot.lazyarrays in order to use split MC files, and when I…
John Karkas
  • 113
  • 1
  • 7
2
votes
1 answer

How to use uproot to load referenced values (TRefArray)

I am trying to use uproot to do some basic selection from a Delphes .root output file. Delphes's c++ code examples are looping over events and accessing reconstructed BranchElements, which have methods to access the branch elements belonging to…
John Karkas
  • 113
  • 1
  • 7
1
vote
1 answer

How can I "dump" / get the content of objects of "experiment specific" / "custom" classes (from a TTree)

I am trying to use Uproot to read some existing trees. I can open the ROOT file with trees, I can "get" the trees and "show" their branches. I've met branches for which I don't know how to "dump" them and/or get their content. Some branches contain…
1
vote
1 answer

Getting i-th element of branch with uproot

I am using uproot to read root files in Python. My files are such that I am doing this: ifile = uproot.open(path_to_root_file) metadata = ifile['Metadata'] waveforms = ifile['Waveforms'] waveforms.show() waveforms_of_event_50 =…
user171780
  • 2,243
  • 1
  • 20
  • 43
1
vote
1 answer

How can I resolve the 'Basket data should be added to all branches' exception when writing to a TTree with Uproot?

Reading from an ntuple and saving into a new ntuple, after many iterations over events, getting the following: utils.writeTree(outf, ltree, outtreename, brs) File "/srv01/agrp/roybr/zprimeplusxntr/UprootFramework/utils.py", line 273, in…
Roy Brener
  • 11
  • 2
1
vote
0 answers

Not reading / opening of root file from uproot

I am trying to read a file.root using ** uproot** but it's throwing back this error :- File "/Users/siddharthkeshar/opt/anaconda3/lib/python3.9/site-packages/uproot/source/chunk.py", line 370, in wait raise OSError( OSError: expected Chunk of length…
1
vote
1 answer

how to add new field in a 'zip' jagged array

I want to add a new field in an already zipped jagged array. For example, if I zip 4D info into a muons object, then I can call pt,eta,phi,charge like this: muons.Muon.pt. However, if I want to add a new field such as 2*pt into this muons object,…
Zhenxuan
  • 11
  • 1
1
vote
1 answer

Copy TTree to Other File

I'm trying to extract cycles/revisions ("TreeName;3" etc) from one root file and make them their own trees in a new one. I tried doing it by creating a new file and assigning it to a new name, but I get an error telling me that TTree is not…
Chalky
  • 13
  • 5