Read Multiple trees using RDFs

Hi,
I have two trees in two different files that I am trying to read. Both the trees have equal entries because they were created together. Both the trees have some similar branches but some different as well. I load both of them:

  auto df_lam =
      ROOT::RDataFrame("v0", "./xi_lambda.root");
  auto df_xi =
      ROOT::RDataFrame("xi", "./xi.root");

// define cuts
  auto ev_cuts = [](float primVx, float primVy, float primVz, int ntofMatch) {
    return (fabs(primVz) < 40 && ntofMatch > 2.0 &&
            fabs(primVx * primVx + primVy * primVy) < 4.0);
  };

  auto df_lam_cut = df_lam.Filter(
      ev_cuts, {"primvertexX", "primvertexY", "primvertexZ", "ntofmatched"});
  auto nentries = df_lam_cut.Count();
  // do all the takes for event branches
  auto primVX = df_lam_cut.Take<Float_t>("primvertexX");
  auto primVY = df_lam_cut.Take<Float_t>("primvertexY");
  auto primVZ = df_lam_cut.Take<Float_t>("primvertexZ");

and then I do, for example this:

  auto nmcXi = *df_xi.Take<Int_t>("nmcxi");

 for (ULong64_t n = 0; n < *nentries; ++n) {
    Int_t nmcXi = nmcXi;
    cout << "nmcXi = " << nmcXi << endl;
  }

seems to cout wrong values. I tried to do this as well:

  auto nmcXi = df_xi.Take<Int_t>("nmcxi");

 for (ULong64_t n = 0; n < *nentries; ++n) {
    Int_t nmcXi = nmcXi;
    cout << "nmcXi = " << nmcXi << endl;
  }

but it just prints 0.

ROOT Version: 6.30/02
Compiler: gcc version 13.2.1


Hi Marooz,

Nice snippets.
I am a bit puzzled by this snippet:

  auto nmcXi = *df_xi.Take<Int_t>("nmcxi");

 for (ULong64_t n = 0; n < *nentries; ++n) {
    Int_t nmcXi = nmcXi;
    cout << "nmcXi = " << nmcXi << endl;
  }

I assume nmcxi is a column of int values. Therefore, the type of nmcXi is <std::vector<int> as per the behaviour of Take.
Therefore, I would expect that to print the content of that column one would write

for (auto i_nmcXi : nmcXi) cout << "i_nmcXi = " << i_nmcXi << endl;

Please let me know if I am not understood something correctly!

Cheers,
D

Thank you.
nmcXi is indeed is a column of int values. But would this:

for (auto i_nmcXi : nmcXi) cout << "i_nmcXi = " << i_nmcXi << endl;

give me right event by event values, i mean when i put this in the *nenetries loop, because nmcXi is from a different DF

Hi Marooz,

If the content of the two datasets is identical, modulo a few details, and the initial number of entries is identical, why not?
It all depends on the content of the datasets, no?

I hope this helps.

Cheers,
D

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.