Replies: 1 comment 1 reply
-
The proper way to read from a single branch in import uproot
with uproot.open("output.root:T") as tree:
ev_pmt = tree["ds/ev/ev.pmt"].array() In ---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In [7], line 2
1 with uproot.open("/home/angus/Downloads/output.root:T") as tree:
----> 2 ev_pmt = tree["ds/ev/ev.pmt"].array()
File ~/Git/uproot5/src/uproot/behaviors/TBranch.py:1818, in TBranch.array(self, interpretation, entry_start, entry_stop, decompression_executor, interpretation_executor, array_cache, library, ak_add_doc)
1815 ranges_or_baskets.append((branch, basket_num, range_or_basket))
1817 interp_options = {"ak_add_doc": ak_add_doc}
-> 1818 _ranges_or_baskets_to_arrays(
1819 self,
1820 ranges_or_baskets,
1821 branchid_interpretation,
1822 entry_start,
1823 entry_stop,
1824 decompression_executor,
1825 interpretation_executor,
1826 library,
1827 arrays,
1828 False,
1829 interp_options,
1830 )
1832 _fix_asgrouped(
1833 arrays,
1834 expression_context,
(...)
1838 ak_add_doc,
1839 )
1841 if array_cache is not None:
File ~/Git/uproot5/src/uproot/behaviors/TBranch.py:3124, in _ranges_or_baskets_to_arrays(hasbranches, ranges_or_baskets, branchid_interpretation, entry_start, entry_stop, decompression_executor, interpretation_executor, library, arrays, update_ranges_or_baskets, interp_options)
3121 pass
3123 elif isinstance(obj, tuple) and len(obj) == 3:
-> 3124 uproot.source.futures.delayed_raise(*obj)
3126 else:
3127 raise AssertionError(obj)
File ~/Git/uproot5/src/uproot/source/futures.py:36, in delayed_raise(exception_class, exception_value, traceback)
32 def delayed_raise(exception_class, exception_value, traceback):
33 """
34 Raise an exception from a background thread on the main thread.
35 """
---> 36 raise exception_value.with_traceback(traceback)
File ~/Git/uproot5/src/uproot/behaviors/TBranch.py:3066, in _ranges_or_baskets_to_arrays.<locals>.basket_to_array(basket)
3063 context = dict(branch.context)
3064 context["forth"] = forth_context[branch.cache_key]
-> 3066 basket_arrays[basket.basket_num] = interpretation.basket_array(
3067 basket.data,
3068 basket.byte_offsets,
3069 basket,
3070 branch,
3071 context,
3072 basket.member("fKeylen"),
3073 library,
3074 interp_options,
3075 )
3076 if basket.num_entries != len(basket_arrays[basket.basket_num]):
3077 raise ValueError(
3078 """basket {} in tree/branch {} has the wrong number of entries """
3079 """(expected {}, obtained {}) when interpreted as {}
(...)
3087 )
3088 )
File ~/Git/uproot5/src/uproot/interpretation/objects.py:139, in AsObjects.basket_array(self, data, byte_offsets, basket, branch, context, cursor_offset, library, options)
136 assert basket.byte_offsets is not None
138 if self._forth and isinstance(library, uproot.interpretation.library.Awkward):
--> 139 output = self.basket_array_forth(
140 data,
141 byte_offsets,
142 basket,
143 branch,
144 context,
145 cursor_offset,
146 library,
147 options,
148 )
149 else:
150 output = ObjectArray(
151 self._model, branch, context, byte_offsets, data, cursor_offset
152 ).to_numpy()
File ~/Git/uproot5/src/uproot/interpretation/objects.py:206, in AsObjects.basket_array_forth(self, data, byte_offsets, basket, branch, context, cursor_offset, library, options)
200 with self._forth_lock:
201 # all threads have to wait until complete_forth_code is ready
203 if self._complete_forth_code is None:
204 # another thread didn't make it while this thread waited
205 # this thread tries to make it now
--> 206 output = self._discover_forth(
207 data, byte_offsets, branch, context, cursor_offset
208 )
210 if output is not None:
211 # Forth discovery was unsuccessful; return Python-derived
212 # output and maybe another basket will be more fruitful
213 self.hook_after_basket_array(
214 data=data,
215 byte_offsets=byte_offsets,
(...)
222 options=options,
223 )
File ~/Git/uproot5/src/uproot/interpretation/objects.py:286, in AsObjects._discover_forth(self, data, byte_offsets, branch, context, cursor_offset)
284 if "forth" in context.keys():
285 context["forth"].gen.var_set = False
--> 286 output[i] = self._model.read(
287 chunk,
288 cursor,
289 context,
290 branch.file,
291 branch.file.detached,
292 branch,
293 )
294 if context["cancel_forth"] and "forth" in context.keys():
295 del context["forth"]
File ~/Git/uproot5/src/uproot/containers.py:716, in AsArray.read(self, chunk, cursor, context, file, selffile, parent, header)
714 forth_stash.add_to_pre(f"{temp_jump} stream skip\n")
715 if is_memberwise:
--> 716 raise NotImplementedError(
717 """memberwise serialization of {}
718 in file {}""".format(
719 type(self).__name__, selffile.file_path
720 )
721 )
723 if isinstance(self._values, numpy.dtype):
724 remainder = chunk.get(
725 cursor.index, cursor.index + num_bytes, cursor, context
726 )
NotImplementedError: memberwise serialization of AsArray
in file /home/angus/Downloads/output.root If we inspect the interpretation of the data, we see >>> with uproot.open("output.root:T") as tree:
>>> ev_pmt = tree["ds/ev/ev.pmt"]
>>> print(ev_pmt.interpretation)
AsObjects(AsArray(True, False, AsVector(False, Model_RAT_3a3a_DS_3a3a_PMT), ())) It looks like you're reading a structure, and uproot needs to deserialise it memberwise. We don't support all of the various peculiar ways that ROOT can serialise an object, though @ioanaif and @jpivarski can pick this up and tell you more, such as where to go next. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm new to Uproot, and ROOT in general, with a very lacking foundation of the data structures of ROOT. I originally used ROOT directly to access and plot for example ev.pmt.charge, with no issue. I wanted to use Uproot due to its ease of use compared to the conventional ROOT. Anyway, I wanted to ask how to access the ev.pmt in the TTree, and plot something like ev.pmt.charge (or time ,dTime, dCharge).
I did the following to plot the data, but I get an empty plot (most likely due to me missing or misusing something):
`file = uproot.open("output.root")
tree = file["T"]
ev_pmt = uproot.containers.STLVector(tree["ds/ev/ev.pmt"])
charge_data = np.array([x.charge for x in ev_pmt])
charge_df = pd.DataFrame(charge_data, columns=["charge"])
Create a histogram of the charge data
charge_df.plot(kind='hist', y='charge', bins = 100)
plt.xlabel("Charge")
plt.ylabel("Frequency")
plt.title("Histogram of Charge")
plt.show()
Summary of charge data:
print(charge_df.describe())`
I hope to have some updated code to help me with this as I've been stuck on this for quite a while now, and I have a deadline coming up for thesis work. Any help would be much appreciated.
Also, if possible, could you show how to apply cuts aswell? I posted the root file as a zip file for anyone to help. Thanks in advance to everybody who helps.
output.zip
P.S. Forgive me if someone asked a similar question, I could not find one if there was.
Beta Was this translation helpful? Give feedback.
All reactions