Useful tools for root in python
Project description
JusflPyRoot
a library to ease the life with powerfull python numpy and powerfull ROOT classes.
in progress, very early stage
Installation
Use uv{.verbatim} from astral to handle the environment.
uv tool install jusflpyroot
# OR classically
pip install jusflpyroot
Use examples
Basic histo creation, save, load
Self-explanatory, create TH1F, induce NumpyTH1, save, destoy, repeat, etc...
if __name__ == "__main__":
NumpyTH1.list_file("bobes.root") # list the file content if exists
# create one ROOT histogram
h = ROOT.TH1F("namea", "histogram that goes to file", 100, 0, 100)
print("i... filling-in with a binary pattern to distinguish under/ovrflow and the content")
h.Fill(- 1 ) # underflow
h.Fill(0, 2) # 2x inside
h.Fill(100 - 0.0001, 4) # 4x inside
h.Fill(100 , 8) # 8x overflow
# create THE OBJECT
nh = NumpyTH1.from_th1(h)
nh.save("bobes.root", save_format="root")
nh.force_del() # brutally remove the object from instances
# once more, but empty, I dont care about 'h'
h = ROOT.TH1F("nameb", "histogram that also goes to file", 100, 0, 100)
nh = NumpyTH1.from_th1(h)
nh.save("bobes.root", save_format="root")
nh.force_del()
# last time, but dont delete this time
h = ROOT.TH1F("namec", "histogram just here", 100, 0, 100)
nh = NumpyTH1.from_th1(h)
nh2 = NumpyTH1.load("bobes.root", "namea", load_format="root")
print(" ... _______ I expect to see 'namec' (still in memory) and 'namea' from disk")
NumpyTH1.list()
print(" ... _______ on disk:")
NumpyTH1.list_file("bobes.root")
# get three vectors for the model Fit
x, y, dy = nh.get_xy()
The output should look like this:
i... filling-in with a binary pattern to distinguish under/ovrflow and the content
i... saving histo 'namea' into 'bobes.root'
D... deleting histo 'namea' #instances 1 => 0
i... saving histo 'nameb' into 'bobes.root'
D... deleting histo 'nameb' #instances 1 => 0
i... loading 'namea' from bobes.root
i... there is 2 histograms total in the file
... _______ I expect to see 'namec' (still in memory) and 'namea' from disk
0. namec 'histogram just here ' 2025-07-09 14:21:17.876 100 <0.0 - 100.0) [ 0.0 / 0.0 / 0.0 ]
1. namea 'histogram that goes to file ' 2025-07-09 14:21:17.876 100 <0.0 - 100.0) [ 1.0 / 6.0 / 8.0 ]
... _______ on disk:
f... ... namea (TH1 in bobes.root)
f... ... nameb (TH1 in bobes.root)
Minuit fit
h = ROOT.TH1F("namec", "histogram just here", 10, 0, 10)
for i in range(10): # for range(11) .... 10 will already go to overflows
h.Fill(i, i)
for i in range(10): # make some mess
h.Fill(2)
h.Fill(3)
h.Fill(4)
h.Fill(5)
NumpyTH1.by_name("namec").Draw("numpy") # Draw using matplotlib
print("... ========================= fitting ==========================")
x, y, dy = nh.get_xy() # Get data for fit (from histogram)
print(x)
print(y)
print(dy)
A = PrepareLSQFit(x, y, dy ) # provide data to FITTER
A.set_model("p2") # select mode name and function
A.FIT( a= -0.1, b=1, c=1) # initial values + constant names; paramater names must match
A.conclude() # prints and plots using matplotlib
# NumpyTH1.wait_loop() # not needed with matplotlib plt
Delete all
Can be useful in emacs codeblocks
print("i... LIST")
NumpyTH1.list()
print("X... DELETEING")
NumpyTH1.reset_all()
print("X... DELETED")
print("i... LIST EMPTY START")
NumpyTH1.list()
print("i... LIST EMPTY END")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jusflpyroot-0.1.8.tar.gz.
File metadata
- Download URL: jusflpyroot-0.1.8.tar.gz
- Upload date:
- Size: 53.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90147b9d2c7022ef97789a6185faf486a7fe23834513d16d4fb1d7fdeff7f8b1
|
|
| MD5 |
c3073ba7707035923a6b8ca406788e95
|
|
| BLAKE2b-256 |
5bbdb899b22d26785120a7f7801aa4e3c54eca3e17e8106b8a4dbd37aeeee888
|
File details
Details for the file jusflpyroot-0.1.8-py3-none-any.whl.
File metadata
- Download URL: jusflpyroot-0.1.8-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f0717ff4de8d0c3fcd8bc681e62ebee8d495c1bf8ebf87d87002af3795ddb5d
|
|
| MD5 |
56d618bab05d586e7869acb40549be63
|
|
| BLAKE2b-256 |
78473856ec6d571b503b7362ea0bd3ada34d266bb7b3990bb12845b1ad084e27
|