All Projects → tamasgal → UnROOT.jl

tamasgal / UnROOT.jl

Licence: MIT license
Native Julia I/O package to work with CERN ROOT files

Programming Languages

julia
2034 projects
TeX
3793 projects

Projects that are alternatives of or similar to UnROOT.jl

decaylanguage
Package to parse decay files, describe and convert particle decays between digital representations.
Stars: ✭ 34 (-34.62%)
Mutual labels:  analysis, high-energy-physics, hep, particle-physics, hep-ex
Corpuscles.jl
Julia package for particle physics
Stars: ✭ 25 (-51.92%)
Mutual labels:  analysis, high-energy-physics, hep, particle-physics, hep-ex
particle
Package to deal with particles, the PDG particle data table, PDGIDs, etc.
Stars: ✭ 113 (+117.31%)
Mutual labels:  analysis, high-energy-physics, hep, particle-physics
Uproot3
ROOT I/O in pure Python and NumPy.
Stars: ✭ 312 (+500%)
Mutual labels:  analysis, bigdata, hep
Uproot4
ROOT I/O in pure Python and NumPy.
Stars: ✭ 80 (+53.85%)
Mutual labels:  analysis, bigdata, hep
ml-lpi
Materials for ML course at Lebedev Physical Institute
Stars: ✭ 31 (-40.38%)
Mutual labels:  hep, particle-physics, hep-ex
alice-rs
Analyze the public data from the CERN base ALICE collaboration with Rust
Stars: ✭ 81 (+55.77%)
Mutual labels:  hep, particle-physics
root pandas
A Python module for conveniently loading/saving ROOT files as pandas DataFrames
Stars: ✭ 108 (+107.69%)
Mutual labels:  analysis, hep
Scikit Hep
Metapackage of Scikit-HEP project data analysis packages for Particle Physics.
Stars: ✭ 131 (+151.92%)
Mutual labels:  analysis, hep
Statistics-Notes
Personal notes on statistics with a focus on applications to experimental high energy physics
Stars: ✭ 19 (-63.46%)
Mutual labels:  high-energy-physics, hep
pylhe
Lightweight Python interface to read Les Houches Event (LHE) files
Stars: ✭ 29 (-44.23%)
Mutual labels:  hep, particle-physics
weaver
Streamlined neural network training.
Stars: ✭ 22 (-57.69%)
Mutual labels:  hep, hep-ex
LatticeQCD.jl
A native Julia code for lattice QCD with dynamical fermions in 4 dimension.
Stars: ✭ 85 (+63.46%)
Mutual labels:  hep, particle-physics
lumin
LUMIN - a deep learning and data science ecosystem for high-energy physics.
Stars: ✭ 45 (-13.46%)
Mutual labels:  hep
amazon-transcribe-news-media-analysis
Transcribe news audio in realtime
Stars: ✭ 21 (-59.62%)
Mutual labels:  analysis
zAnalysis
zAnalysis是基于Pascal语言编写的大型统计学开源库
Stars: ✭ 52 (+0%)
Mutual labels:  analysis
Cpp2IL
Work-in-progress tool to reverse unity's IL2CPP toolchain.
Stars: ✭ 689 (+1225%)
Mutual labels:  analysis
GymWorkoutManager
💪A functional Gym workout timer ❤️
Stars: ✭ 16 (-69.23%)
Mutual labels:  analysis
paStash
pastaʃ'ʃ = Spaghetti I/O Event Data Processing, Interpolation, Correlation and beyond 🍝
Stars: ✭ 89 (+71.15%)
Mutual labels:  hep
humble
A humble, and fast, security-oriented HTTP headers analyzer
Stars: ✭ 17 (-67.31%)
Mutual labels:  analysis

UnROOT.jl

All Contributors

status Dev Build Status Codecov status

UnROOT.jl is a reader for the CERN ROOT file format written entirely in Julia, without any dependence on ROOT or Python.

Installation Guide

  1. Download the latest Julia release
  2. Open up Julia REPL (hit ] once to enter Pkg mode, hit backspace to exit it)
julia>]
(v1.8) pkg> add UnROOT

Quick Start (see docs for more)

julia> using UnROOT

julia> f = ROOTFile("test/samples/NanoAODv5_sample.root")
ROOTFile with 2 entries and 21 streamers.
test/samples/NanoAODv5_sample.root
└─ Events
   ├─ "run"
   ├─ "luminosityBlock"
   ├─ "event"
   ├─ "HTXS_Higgs_pt"
   ├─ "HTXS_Higgs_y"
   └─ ""

julia> mytree = LazyTree(f, "Events", ["Electron_dxy", "nMuon", r"Muon_(pt|eta)$"])
 Row │ Electron_dxy     nMuon   Muon_eta         Muon_pt
     │ Vector{Float32}  UInt32  Vector{Float32}  Vector{Float32}
─────┼───────────────────────────────────────────────────────────
 1   │ [0.000371]       0       []               []
 2   │ [-0.00982]       2       [0.53, 0.229]    [19.9, 15.3]
 3   │ []               0       []               []
 4   │ [-0.00157]       0       []               []
 ⋮   │     ⋮            ⋮             ⋮                ⋮
 

You can iterate through a LazyTree:

julia> for event in mytree
           @show event.Electron_dxy
           break
       end
event.Electron_dxy = Float32[0.00037050247]

julia> Threads.@threads for event in mytree # multi-threading
           ...
       end

Only one basket per branch will be cached so you don't have to worry about running out of RAM. At the same time, event inside the for-loop is not materialized until a field is accessed. If your event is fairly small or you need all of them anyway, you can collect(event) first inside the loop.

XRootD is also supported, depending on the protocol:

  • the "url" has to start with http:// or https://:
  • (1.6+ only) or the "url" has to start with root:// and have another // to separate server and file path
julia> r = @time ROOTFile("https://scikit-hep.org/uproot3/examples/Zmumu.root")
  0.034877 seconds (5.13 k allocations: 533.125 KiB)
ROOTFile with 1 entry and 18 streamers.

julia> r = ROOTFile("root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root")
ROOTFile with 1 entry and 19 streamers.

Branch of custom struct

We provide an experimental interface for hooking up UnROOT with your custom types that only takes 2 steps, as explained in the docs. As a show case for this functionality, the TLorentzVector support in UnROOT is implemented with the said plug-in system.

Support & Contributiing

  • Use Github issues for any bug reporting or feature request; feel free to make PRs, bug fixing, feature tuning, quality of life, docs, examples etc.
  • See CONTRIBUTING.md for more information and recommended workflows in contributing to this package.

TODOs

  • Parsing the file header
  • Read the TKeys of the top level dictionary
  • Reading the available trees
  • Reading the available streamers
  • Reading a simple dataset with primitive streamers
  • Reading of raw basket bytes for debugging
  • Automatically generate streamer logic
  • Prettier show for Lazy*s
  • Clean up Cursor use
  • Reading TNtuple #27
  • Reading histograms (TH1D, TH1F, TH2D, TH2F, etc.) #48
  • Clean up the readtype, unpack, stream! and readobjany construct
  • Refactor the code and add more docs
  • Class name detection of sub-branches
  • High-level histogram interface

Acknowledgements

Special thanks to Jim Pivarski (@jpivarski) from the Scikit-HEP project, who is the main author of uproot, a native Python library to read and write ROOT files, which was and is a great source of inspiration and information for reverse engineering the ROOT binary structures.

Behind the scene

Some additional debug output:

julia> using UnROOT

julia> f = ROOTFile("test/samples/tree_with_histos.root")
Compressed stream at 1509
ROOTFile("test/samples/tree_with_histos.root") with 1 entry and 4 streamers.

julia> keys(f)
1-element Array{String,1}:
 "t1"

julia> keys(f["t1"])
Compressed datastream of 1317 bytes at 1509 (TKey 't1' (TTree))
2-element Array{String,1}:
 "mynum"
 "myval"

julia> f["t1"]["mynum"]
Compressed datastream of 1317 bytes at 6180 (TKey 't1' (TTree))
UnROOT.TBranch
  cursor: UnROOT.Cursor
  fName: String "mynum"
  fTitle: String "mynum/I"
  fFillColor: Int16 0
  fFillStyle: Int16 1001
  fCompress: Int32 101
  fBasketSize: Int32 32000
  fEntryOffsetLen: Int32 0
  fWriteBasket: Int32 1
  fEntryNumber: Int64 25
  fIOFeatures: UnROOT.ROOT_3a3a_TIOFeatures
  fOffset: Int32 0
  fMaxBaskets: UInt32 0x0000000a
  fSplitLevel: Int32 0
  fEntries: Int64 25
  fFirstEntry: Int64 0
  fTotBytes: Int64 170
  fZipBytes: Int64 116
  fBranches: UnROOT.TObjArray
  fLeaves: UnROOT.TObjArray
  fBaskets: UnROOT.TObjArray
  fBasketBytes: Array{Int32}((10,)) Int32[116, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  fBasketEntry: Array{Int64}((10,)) [0, 25, 0, 0, 0, 0, 0, 0, 0, 0]
  fBasketSeek: Array{Int64}((10,)) [238, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  fFileName: String ""


julia> seek(f.fobj, 238)
IOStream(<file test/samples/tree_with_histos.root>)

julia> basketkey = UnROOT.unpack(f.fobj, UnROOT.TKey)
UnROOT.TKey64(116, 1004, 100, 0x6526eafb, 70, 0, 238, 100, "TBasket", "mynum", "t1")

julia> s = UnROOT.datastream(f.fobj, basketkey)
Compressed datastream of 100 bytes at 289 (TKey 'mynum' (TBasket))
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=100, maxsize=Inf, ptr=1, mark=-1)

julia> [UnROOT.readtype(s, Int32) for _ in 1:f["t1"]["mynum"].fEntries]
Compressed datastream of 1317 bytes at 6180 (TKey 't1' (TTree))
25-element Array{Int32,1}:
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 10
 10
 10
 10

Contributors

Thanks goes to these wonderful people (emoji key):


Tamas Gal

💻 📖 🚇 🔣 ⚠️

Jerry Ling

💻 ⚠️ 🔣 📖

Johannes Schumann

💻 ⚠️ 🔣

Nick Amin

💻 ⚠️ 🔣

Mosè Giordano

🚇

Oliver Schulz

🤔

Misha Mikhasenko

🔣

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].