I have a root file which contains 3200 histograms, they’re named "Name/NameEvent1Ch1"
… "Name/NameEvent1Ch31"
… "Name/NameEvent2Ch0"
… "Name/NameEvent{x}Ch32"
…
Half of the histograms come from an x readout of a detector, half from y, so I split them into two, and then i want to be able to access them easily by event number, so I thought the easiest way would be to read in all of the histograms and then reshape the arrays, but I get a strange error from python.
I define the following arrays:
x_channels = [8,7,9,6,10,5,11,4,12,3,13,2,14,1,15,0]
y_channels = [27,28,26,29,25,30,24,31,23,16,22,17,21,18,20,19]
Then this works fine:
analogues_x = [(f"Target/TargetEvent{Ev}Ch{ch}") for Ev in range(100) for ch in x_channels]
analogues_y = [(f"Target/TargetEvent{Ev}Ch{ch}") for Ev in range(100) for ch in y_channels]
analogues_x=np.reshape(analogues_x,(100,16))
analogues_y=np.reshape(analogues_y,(100,16))
But this gives me an error:
analogues_x = [root_file.Get(f"Target/TargetEvent{Ev}Ch{ch}") for Ev in range(100) for ch in x_channels]
analogues_y = [root_file.Get(f"Target/TargetEvent{Ev}Ch{ch}") for Ev in range(100) for ch in y_channels]
print(len(analogues_x),len(analogues_y))
analogues_x=np.reshape(analogues_x,(100,16))
analogues_y=np.reshape(analogues_y,(100,16))
The error says:
File "/Users/bethlong/Documents/PADME/230111padme-fw/PadmeReco/AnalogueTargetStudies.py", line 43, in <module>
analogues_x=np.reshape(analogues_x,(100,16))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 285, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 45, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot reshape array of size 1641600 into shape (100,16)
Even though print(len(analogues_x),len(analogues_y))
gives 1600 1600
…
Can anyone tell me what’s going wrong?