Fill RVecs with Branch Values (as Array)

Hi,
please check out this post about embedding code in your posts.

The problem is that the function reco_zz_to_4l, the body of which you copied, is not meant to be executed standalone. It needs to be passed to RDataFrame so RDataFrame will execute it during the event loop. Example:

int always_two() { return 2; }

int main() {
  ROOT::RDataFrame df("tree", "file.root");
  auto df2 = df.Define("two", always_two);
  return 0;
}

Here always_two is a standalone function, just like reco_zz_to_4l in the tutorial you linked. And just like in the tutorial, we pass the function to RDF’s Define, so RDataFrame knows that whenever it needs the column called "two" it can produce it by invoking that function.

In the tutorial, reco_zz_to_4l is passed to RDataFrame like this:

   auto df_z_idx = df_base.Define("Z_idx", reco_zz_to_4l, {"Muon_pt", "Muon_eta", "Muon_phi", "Muon_mass", "Muon_charge"});

where the third argument to Define is a list of column names that reco_zz_to_4l must be applied to in order to produce column Z_idx.

In summary: you must not work with RVec’s yourself, you have to define functions that work with RVec’s and tell RDataFrame what to use them for. The RDataFrame crash course might help further.

Cheers,
Enrico