I have a root file with a single tree named “Board” with 4 branches named p1, p2, p3 and p4, all have the same structure, that is several leavws, among which I am interested in 3 of them. I want to create another root file where I want to copy only 3 branches p1, p2 and p3 from the old file with only 3 leaves, old names of those leaves are: “CT”, “BT” and “ET”. How can I achieve that?
Hi,
in your terminal, you can use rooteventselector to copy subsets of trees from a ROOT file to another.
You can check the usage with rooteventselector --help.
You can also use rooteventselector from a bash script.
If that doesn’t cut it, you can use TDataFrame to easily manipulate datasets from a C++ or python program:
#include <ROOT/TDataFrame.hxx>
using namespace ROOT::Experimental; // TDF lives here (until ROOT v6.14)
int main() {
TDataFrame df("treename", "filename.root");
df.Snapshot("newtree", "newfile.root", {"CT", "BT", "ET"});
return 0;
}
Hope this helps! Check out TDataFrame’s tutorials for more documented, working examples.
Hi, TDataFrame is a fairly recent addition to ROOT and is available since ROOT v6.10 (with many of the features actually added in v6.12, and more coming in v6.14). So it’s expected that v5.34 does not have it.
Regarding the error: TDataFrame does not find a leaf named "CT". Maybe that’s because the full name is something like "branchname.CT"?
Thanks Enrico for all the help… I really appreciate, I was exactly reading about filters just after posting the last reply, but as I rarely use c++ or root, things are not that obvious for me yet but I am trying to learn.