I've made root files with histograms through another program, and I'm trying to extract this histograms in a Jupyter notebook using Python3 to do various bits of analysis on these histograms.
In the past, this has been a non-issue, but I'm on a new device and things have been wonky.
I have a root file named root_file.root located at /location and inside this root file are a number of TDirectories. If numbers are important, the histograms I'm trying to access are 5 layers of TDirectories in, which I'll label as tdir, and the histogram as root_hist
My imports:
import numpy as np import matplotlib.pyplot as plt import math import pandas as pd import uproot To open this file I've been using
file = uproot.open("/location/root_file.root") I can then use file.keys() to see all the various histograms and TDirectories within the root file. I can get myself all the way to the point where I can see the histogram I want to access through file['tdir'].keys() and one of the keys is 'root_hist'. I can even run file['tdir'].classnames() and see that 'root_hist' is a TH2F.
The issue is that then when I try to actually access the histogram thought hist = file['tdir']['root_hist'] I get a Recursion Error (note that test[key0] is the same thing as file['tdir']['root_hist'] where test=file['tdir'] and key0='root_hist'):
RecursionError Traceback (most recent call last) Input In [27], in <cell line: 7>() 5 print(test.keys()) 6 print(key0) ----> 7 test[key0].all_members File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:2089, in ReadOnlyDirectory.__getitem__(self, where) 2087 else: 2088 last = step -> 2089 step = step[item] 2091 elif isinstance(step, uproot.behaviors.TBranch.HasBranches): 2092 return step["/".join(items[i:])] File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:2089, in ReadOnlyDirectory.__getitem__(self, where) 2087 else: 2088 last = step -> 2089 step = step[item] 2091 elif isinstance(step, uproot.behaviors.TBranch.HasBranches): 2092 return step["/".join(items[i:])] [... skipping similar frames: ReadOnlyDirectory.__getitem__ at line 2089 (2966 times)] File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:2089, in ReadOnlyDirectory.__getitem__(self, where) 2087 else: 2088 last = step -> 2089 step = step[item] 2091 elif isinstance(step, uproot.behaviors.TBranch.HasBranches): 2092 return step["/".join(items[i:])] File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:2072, in ReadOnlyDirectory.__getitem__(self, where) 2070 if item != "": 2071 if isinstance(step, ReadOnlyDirectory): -> 2072 if ":" in item and item not in step: 2073 index = item.index(":") 2074 head, tail = item[:index], item[index + 1 :] File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:1922, in ReadOnlyDirectory.__contains__(self, where) 1920 def __contains__(self, where): 1921 try: -> 1922 self.key(where) 1923 except KeyError: 1924 return False File ~/Library/Python/3.8/lib/python/site-packages/uproot/reading.py:2014, in ReadOnlyDirectory.key(self, where) 2000 def key(self, where): 2001 """ 2002 Returns a ``TKey`` (:doc:`uproot.reading.ReadOnlyKey`) for the object 2003 selected by ``where``. (...) 2012 Note that this does not read any data from the file. 2013 """ -> 2014 where = uproot._util.ensure_str(where) 2016 if "/" in where: 2017 items = where.split("/") File ~/Library/Python/3.8/lib/python/site-packages/uproot/_util.py:67, in ensure_str(x) 63 def ensure_str(x): 64 """ 65 Ensures that ``x`` is a string (decoding with 'surrogateescape' if necessary). 66 """ ---> 67 if isinstance(x, bytes): 68 return x.decode(errors="surrogateescape") 69 elif isinstance(x, str): RecursionError: maximum recursion depth exceeded while calling a Python object I don't understand myself to be doing any recursion here, but it is a consistent error that I get. I've tried upping the limit on recursion, but end up crashing my kernel before solving the problem. I can find no documentation that leads me to believe I'm trying to access the histogram in any way other than the intended method
Where am I going wrong?