-
Sorry, for the naive question.
so I have 8 branches of type float. I would like to structure my data so that I can access it as
or and I also want to be able to do I am simply doing
The problem is that now I can do |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
Are there more variables per PMT than energy? Do you have |
Beta Was this translation helpful? Give feedback.
-
If I'm understanding what you are saying with the import awkward as ak
import numpy as np
import uproot
np.random.seed(42)
events_data = {}
for i in range(1, 4):
events_data[f'PMT{i}_X'] = np.random.normal(0, 1, 1000).astype(np.float32)
events_data[f'PMT{i}_Y'] = np.random.normal(0, 1, 1000).astype(np.float32)
events_data[f'PMT{i}_Z'] = np.random.normal(0, 1, 1000).astype(np.float32)
events = ak.Array(events_data)
with uproot.recreate("mock_data.root") as f:
f["tree"] = events_data Now you probably want to stack the PMTs into different "columns". I would do something like this probably import awkward as ak
import uproot
import numpy as np
events_flat = uproot.open("mock_data.root")["tree"].arrays(how=dict)
# Restructure: stack PMT data so that events.PMT.X[:, pmt_index] gives X for that PMT
PMT_X = ak.Array(np.column_stack([events_flat['PMT1_X'], events_flat['PMT2_X'], events_flat['PMT3_X']]))
PMT_Y = ak.Array(np.column_stack([events_flat['PMT1_Y'], events_flat['PMT2_Y'], events_flat['PMT3_Y']]))
PMT_Z = ak.Array(np.column_stack([events_flat['PMT1_Z'], events_flat['PMT2_Z'], events_flat['PMT3_Z']]))
events = ak.zip({"PMT": ak.zip({"X": PMT_X, "Y": PMT_Y, "Z": PMT_Z})}) Now you get this structure
So you can get the value of
and you can sum
Does that create a good structure for you to work with? |
Beta Was this translation helpful? Give feedback.
-
As far as I'm aware, it's probably best in your problem to keep the different PMTs as "columns" and not as records that you can access with a getitem like |
Beta Was this translation helpful? Give feedback.
-
My logic here was similar to how we structure physics objects like |
Beta Was this translation helpful? Give feedback.
-
Since you are expert of coffea, do you think it makes sense to write a custom schema? |
Beta Was this translation helpful? Give feedback.
If I'm understanding what you are saying with the
ak.sum(events.PMT.E)
, you want it to sum the energies for all PMTs correct?I can probably recreate some mock data that look like what you're saying where I have 3 PMTs and they each have 3 values X,Y and Z