Hi, assuming you have your tree in a file on disk, since v6.10 you can solve your problem with TDataFrame, as pcanal suggested. The following code is not tested but should work about fine for branches containing a single float:
ROOT::Experimental::TDataFrame d("myTree", "file.root"); // instantiate TDF
d.Filter("sqrt(x) <= 1./y") // only consider events that fulfill this condition
.Snapshot("skimmedTree", "output.root", {"n", "x", "y"}); // write to disk
For more complicated filter expressions you can use c++11 lambdas (or normal c++ functions). Here is a filter applied to branches x
and y
containing arrays of floats:
using arr_view_f = std::array_view<Float_t>;
auto myCut = [](const arr_view_f& x, const arr_view_f& y, int n) {
/* your logic goes here, e.g. */
auto xysum = 0;
for(auto i = 0; i < n; ++i) xysum += x[i] + y[i];
return xysum > 0;
};
d.Filter(myCut, {"x", "y", "n"}).Snapshot(/*as before*/);