Hi there,
I’m trying to read a branch of a TTree into a numpy
array using an RDataFrame
. Here is a brief printout of the tree:
******************************************************************************
*Tree :vdMScanData: vdMScanData *
*Entries : 107 : Total = 195121996 bytes File Size = 84340290 *
* : : Tree compression factor = 2.31 *
******************************************************************************
*Br 0 :lucBi2PMTC12_BUNCHDATA : lucBi2PMTC12_Channel/i: *
* | lucBi2PMTC12_Valid/i:lucBi2PMTC12_AverageRawInstLum/F: *
* | lucBi2PMTC12_LuminousBunches/I *
*Entries : 107 : Total Size= 2983 bytes File Size = 912 *
*Baskets : 3 : Basket Size= 1074 bytes Compression= 2.19 *
*............................................................................*
*Br 1 :lucBi2PMTC12_BCID : *
* | lucBi2PMTC12_LuminousBCIDs[lucBi2PMTC12_LuminousBunches]/I *
*Entries : 107 : Total Size= 1529113 bytes File Size = 535014 *
*Baskets : 23 : Basket Size= 537088 bytes Compression= 2.86 *
*............................................................................*
*Br 2 :lucBi2PMTC12_BunchRawInstLum : *
* | lucBi2PMTC12_BunchRawInstLum[lucBi2PMTC12_LuminousBunches]/F *
*Entries : 107 : Total Size= 1529390 bytes File Size = 815250 *
*Baskets : 23 : Basket Size= 537088 bytes Compression= 1.87 *
*............................................................................*
I want to read the branch lucBi2PMTC12_BunchRawInstLum
, and I do so with,
>>> import ROOT
>>> df = ROOT.ROOT.RDataFrame("vdMScanData", "filename.root")
>>> df.AsNumpy(["lucBi2PMTC12_BunchRawInstLum"])
I then get the following error:
Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch called lucBi2PMTC12_LuminousBunches. You could check with TTree::Print() for available branches.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/ROOT/pythonization/_rdataframe.py", line 77, in RDataFrameAsNumpy
cpp_reference = result_ptrs[column].GetValue()
cppyy.gbl.std.runtime_error: const vector<ROOT::VecOps::RVec<float> >& ROOT::RDF::RResultPtr<vector<ROOT::VecOps::RVec<float> > >::GetValue() =>
runtime_error: An error was encountered while processing the data. TTreeReader status code is: 6
I think the problem is that lucBi2PMTC12_BunchRawInstLum
is an array of length lucBi2PMTC12_LuminousBunches
, which is itself a branch, but nested under lucBi2PMTC12_BUNCHDATA
. How can I read in the lucBi2PMTC12_BunchRawInstLum
branch into a numpy
array?
For reference, here is a Scan()
of the relevant branches:
t.Scan("lucBi2PMTC12_LuminousBunches:lucBi2PMTC12_BCID:lucBi2PMTC12_BunchRawInstLum")
***********************************************************
* Row * Instance * lucBi2PMT * lucBi2PMT * lucBi2PMT *
***********************************************************
* 0 * 0 * 3564 * 0 * 2.958e-05 *
* 0 * 1 * 3564 * 1 * 3.254e-05 *
* 0 * 2 * 3564 * 2 * 2.366e-05 *
* 0 * 3 * 3564 * 3 * 2.366e-05 *
* 0 * 4 * 3564 * 4 * 1.183e-05 *
* 0 * 5 * 3564 * 5 * 2.514e-05 *
* 0 * 6 * 3564 * 6 * 4.141e-05 *
* 0 * 7 * 3564 * 7 * 1.775e-05 *
* 0 * 8 * 3564 * 8 * 3.846e-05 *
* 0 * 9 * 3564 * 9 * 2.810e-05 *
* 0 * 10 * 3564 * 10 * 3.993e-05 *
...
Many thanks,
Joey
ROOT Version: 6.22/00
Platform: x86_64-centos7-gcc9-opt
Compiler: GCC 9; Python 3.7.6