This is actually a question about Uproot. In this line:

>>> jet_data=events.arrays(filter_name=["Jet_nFirstTrack","Jet_nLastTrack","Jet_pt","Jet_phi","Jet_eta"],library="ak")

the filter_name is just a filter, accepting or rejecting branches from the ROOT file. Those branches have a natural order in the file, and the output is probably that order (and therefore stable upon repeated attempts, unless a dict is involved at some point and you're using Python <= 3.5).

If you want to enforce an order, pass your list of branch names as expressions, rather than filter_name. That argument has different meaning: expressions can be simple formulas; filter_name can have wildcards—therefore, a character like * has very different meanings in each!

Alternatively, you can reorder the fields after reading the array by slicing with a list of strings. There's no performance penalty for doing so—it's just rearranging metadata (time to completion does not scale with the length of the array). This documentation has some examples (including more complex cases where you're selecting fields within fields, but the simple case is enough for your issue).

Edit: I should add that fields of records in Awkward Arrays have a reproducible order. They're not unstable hashmaps like dicts in Python <= 3.5. They're actually two equal length lists: the ordered fields (which is what ak.unzip returns) and ordered fields names (which ak.fields returns). The names are optional—without field names, records become tuples.

Answer from Jim Pivarski on Stack Overflow
🌐
Awkward-array
awkward-array.org › how-to-convert-uproot.html
Getting started guide — Uproot documentation - Read the Docs
By default, Uproot 4 delivers data from ROOT files as Awkward 1 arrays, even though the Awkward library isn’t one of Uproot’s formal dependencies.
🌐
CERN
indico.cern.ch › event › 1019958 › contributions › 4430420
PyHEP 2021 (virtual) Workshop (5-July 9, 2021): Uproot and Awkward Array tutorial · Indico
July 6, 2021 - Uproot provides an easy way to get data from ROOT files into arrays and DataFrames, and Awkward Array lets you manipulate arrays of complex data types.
🌐
Masonproffitt
masonproffitt.github.io › uproot-tutorial › aio › index.html
Uproot Tutorial
March 21, 2022 - Awkward Array is a package used to deal with jagged arrays so that they can be manipulated in ways almost identical to standard rectangular NumPy arrays. Other Python packages for reading ROOT files usually do not support jagged arrays, which means that you cannot do operations on multiple ...
🌐
Awkward-array
awkward-array.org › doc › main › getting-started › uproot-awkward-columnar-hats.html
Uproot Awkward Columnar HATS — Awkward Array 2.10.0 documentation
array2 = uproot.open( "https://github.com/jpivarski-talks/2023-12-18-hsf-india-tutorial-bhubaneswar/raw/main/data/SMHiggsToZZTo4L.root:Events" ).arrays(["Muon_pt", "Muon_eta", "Muon_phi", "Muon_charge"], entry_stop=100000)
🌐
Indico
indico.bnl.gov › event › 8242
EIC Software Tutorial: Uproot and awkward array (April 8, 2020) · Indico
Jim Pivarski, known for innovative software in DIANA/HEP, IRIS-HEP and other projects, will give tutorials on how to process and analyze Root files with pure Python libraries: uproot and awkward array The tutorials are aimed for anyone who would like to develop the EIC Science and detectors ...
Top answer
1 of 1
1

This is actually a question about Uproot. In this line:

>>> jet_data=events.arrays(filter_name=["Jet_nFirstTrack","Jet_nLastTrack","Jet_pt","Jet_phi","Jet_eta"],library="ak")

the filter_name is just a filter, accepting or rejecting branches from the ROOT file. Those branches have a natural order in the file, and the output is probably that order (and therefore stable upon repeated attempts, unless a dict is involved at some point and you're using Python <= 3.5).

If you want to enforce an order, pass your list of branch names as expressions, rather than filter_name. That argument has different meaning: expressions can be simple formulas; filter_name can have wildcards—therefore, a character like * has very different meanings in each!

Alternatively, you can reorder the fields after reading the array by slicing with a list of strings. There's no performance penalty for doing so—it's just rearranging metadata (time to completion does not scale with the length of the array). This documentation has some examples (including more complex cases where you're selecting fields within fields, but the simple case is enough for your issue).

Edit: I should add that fields of records in Awkward Arrays have a reproducible order. They're not unstable hashmaps like dicts in Python <= 3.5. They're actually two equal length lists: the ordered fields (which is what ak.unzip returns) and ordered fields names (which ak.fields returns). The names are optional—without field names, records become tuples.

🌐
Readthedocs
uproot.readthedocs.io › en › latest › basic.html
Getting started guide — Uproot documentation - Read the Docs
If basket_array does not return an awkward, numpy array or pandas dataframe, you need to reimplement the final_array method to concatenate the results. To use your custom interpretation, register it with Uproot like:
🌐
CERN
indico.cern.ch › event › 960587 › contributions › 4070318 › attachments › 2129252 › 3585426 › pivarski-as-blueprint.pdf pdf
Access and manipulation of complex data structures: Uproot and Awkward Array
December 1, 2020 - Uproot · 7 / 15 · Both libraries rewritten in 2020: new interface, better architecture · Femtocode · (from Oct 2016) OAMap · (also unreleased) Awkward Array 0.x · Awkward Array 1.x · Uproot 2.x · Uproot 1.x · Uproot 3.x · Uproot 4.x · Deprecated ·
Find elsewhere
🌐
Zenodo
zenodo.org › records › 6798671
Uproot and Awkward Array tutorial | Zenodo
July 6, 2022 - Uproot provides an easy way to get data from ROOT files into arrays and DataFrames, and Awkward Array lets you manipulate arrays of complex data types. This tutorial starts at the beginning, showing how an Uproot + Awkward Array (+ Hist + Vector) workflow differs from ROOT based workflows, ...
🌐
GitHub
github.com › scikit-hep › uproot3
GitHub - scikit-hep/uproot3: ROOT I/O in pure Python and NumPy. · GitHub
For this, Uproot fills a new JaggedArray data structure (from the Awkward Array library, like ChunkedArray and VirtualArray).
Author: scikit-hep
🌐
Stack Overflow
stackoverflow.com › questions › 58503117 › may-i-see-a-short-example-of-cutting-on-data-to-prepare-it-for-histogramming-in
awkward array - May I see a short example of cutting on data to prepare it for histogramming in uproot? - Stack Overflow
That also makes it easier to write an answer, because I can create simple artificial cases without having to put them in a ROOT file and read them back with uproot. Here are some artificial jetpt and jeteta jagged arrays: >>> import awkward >>> jetpt = awkward.fromiter([[0.0, 1.1, 2.2], [3.3], [4.4, 5.5], [6.6, 7.7, 8.8, 9.9]]) >>> jeteta = awkward.fromiter([[0.1, -1.2, 0.8], [1.2], [-0.8, 0.8], [0.2, -0.3, 0.9, 0.0]]) >>> jetpt, jeteta
🌐
PyPI
pypi.org › project › uproot
uproot · PyPI
git clone https://github.com/scikit-hep/uproot5.git · and install it locally by calling pip install -e . in the repository directory. If you need to develop Awkward Array as well, see its installation for developers.
🌐
Readthedocs
uproot.readthedocs.io › en › latest › uproot._dask.dask.html
uproot.dask — Uproot documentation
Returns dask equivalents of the backends supported by uproot. If library='np', the function returns a Python dict of dask arrays. If library='ak', the function returns a single dask-awkward array.
🌐
Stack Overflow
stackoverflow.com › questions › 58922824 › arrays-of-strings-from-uproot
python - Arrays of strings from uproot - Stack Overflow
This Python list is not good for array-at-a-time operations, so we then construct a NumPy array, which is (at a cost of padding). ... While writing this, I remembered that uproot's ObjectArray is implemented using an awkward JaggedArray, so the transformation above can be performed with JaggedArray's regular method, which is probably much faster (no intermediate Python bytes objects, no Python for loop).
🌐
Notebook Community
notebook.community › scikit-hep › uproot › binder › tutorial
This tutorial is designed to help you start using uproot. ...
The ChunkedArray and VirtualArray classes are defined in the awkward-array library installed with uproot.