Read 2-dimensional c-array branch with RDataFrame

I created a RDataFrame reading a TTree. The Tree has branches:

const int kNPmax = 250;
int         brStdHepN;                  // Number of particles in particle array 
double      brStdHepP4    [kNPmax][4];  // 4-p (px,py,pz,E) of particle in LAB frame (GeV)
rootracker_tree->Branch("StdHepN",         &brStdHepN,         "StdHepN/I"); 
rootracker_tree->Branch("StdHepP4",         brStdHepP4,        "StdHepP4[StdHepN][4]/D");

The question is which type should I use to read the RDataFrame column “StdHepP4” and define a new one starting from it?

My guess was:

ROOT::RDataFrame gDF("rootracker_tree","gFile.root");
auto gDFExpanded = gDF.Define("nuE",[](const ROOT::VecOps::RVec<double[4]>& v) { return v[0][3]; },{"StdHepP4"});

but it doesn’t work.


Hi @mtROOT ,
welcome to the ROOT forum and sorry for the high latency! (I was off last week)

C-style multi-dimensional arrays are now well supported in RDF because they are not well supported in TTreeReader (the ROOT machinery that RDF uses for reading data). If you use a custom class or a std::vector of size kNPmax*4 which you then access appropriately, that should work out of the box.

I’ll check what the current state is with 2-dimensional C-arrays and get back to you as soon as possible.

Hi again,
this is the relevant jira ticket: [ROOT-9509] [DF] Add proper support for multidimensional arrays - SFTJIRA .

It mentions that reading the 2-dim array as a 1-dim array (i.e. as a RVec<double>) should work, can you please try? I’m afraid proper support of C-style 2-dim array is not yet available.


Thank you Enrico, the solution you propose works