Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading rest-for-physics files #1045

Open
lobis opened this issue Nov 26, 2023 · 0 comments
Open

Reading rest-for-physics files #1045

lobis opened this issue Nov 26, 2023 · 0 comments
Assignees
Labels
feature New feature or request

Comments

@lobis
Copy link
Collaborator

lobis commented Nov 26, 2023

It would be interesting to read files written using the rest-for-physics framework. Currently this is not possible as Uproot is unable to produce a valid interpretation of many branches. In principle, even though the TTree is writen using custom classes, the relevant branches are fully split so it should be possible to read them. They were readable in the past with uproot but this stopped working at some point (most likely due to changes in rest-for-physics).

Some branches are readable as shown in the example below, while some are not. In particular I would be interested in reading the Geant4 data from branhes such as TRestGeant4EventBranch/fTracks/fTracks.fHits.fY in the EventTree.

The Geant4 data is stored in a branch named TRestGeant4EventBranch in the EventTree TTree. This branch is fully split. Using custom classes and dictionaries we replicated the hierarchical structure of a Geant4 simulation (Event > Track > Hit). Here is the source code for these classes.

This issue is related to #936.

The code snippet below uses the new fsspec url chain to open a zip file since GitHub doesn't allow uploading root files directly. It needs uproot >= 5.2.0 (currently pre-release version).

zip_urlpath = "https://github.com/scikit-hep/uproot5/files/12334414/simulation.anaylsis.zip"
root_filename = "simulation.anaylsis.root"
tree_name = "EventTree"
with uproot.open(f"zip://{root_filename}:{tree_name}::{zip_urlpath}") as tree:
    print(tree.keys())

    for key in ["TRestGeant4EventBranch/TRestEvent/TObject/fUniqueID",
                "TRestGeant4EventBranch/TRestEvent/fSubRunOrigin"]:
        branch = tree[key]
        data = branch.array()

    # other keys do not work (unknown interpretation)
    for key in ["TRestGeant4EventBranch/fPrimaryEnergies", ]:
        branch = tree[key]
        data = branch.array()

I'll tag @jgalan in case he wants to follow this up.

@lobis lobis added the feature New feature or request label Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant