Merging two datasets with different selections

Hi @Clara_Landesa_Gomez ,

and welcome to the ROOT forum!

In the following I will assume that the two trees have the same schema (same branches with same names and types) and you want to concatenate the datasets vertically (i.e. make a dataset that has the same columns as the two original datasets and the union of their rows). If that’s not the case, please clarify what you mean with merging here.

That will require storage for the skimmed versions of the two datasets, but if that’s not a problem, depending on your analysis workflow, this might be a one-time operation (or a rare operation anyway) and it might prove to be the simplest solution.

Otherwise you can read both datasets into the same RDataFrame object (e.g. with RDataFrame("Events", {"f1.root", "f2.root"}), which will concatenate them vertically, or by first building a TChain and them passing that to the RDataFrame constructor) and then change the behavior of your Filters based on which file is being processed by using DefinePerSample, e.g.:

df.DefinePerSample("isMC", "rdfsampleinfo_.Contains("f1") ? true : false")
  .Filter("isMC ? x > 1.5 : x > 2.")

I hope this helps!
Cheers,
Enrico