Best way to read branches with a cut

Ok, this is like the simplest question, but I am confused.

What is the recommended way to read few branches in a tree with a cut? I can call Draw with a cut and do GetV1, etc, but I assume the proper way would be to use SetBranchAddress, but not sure how to use a selection with that, is there a good example I can use?

I am somewhat confused about the usage of Selections

Hi xcorat,
please take a look at this answer for an overview of the different methods that can be used to read data from a TTree. All of these techniques are proper.
The recommended way depends on what you need. As a rule of thumb, start with the higher-level (more abstract) interfaces and work down the list if those do not satisfy your needs.

Concretely, for your case (cut and fill), TDataFrame is a good match (if you can use ROOT v6.12 or later):

using namespace ROOT::Experimental; // TDF lives here (until v6.14)
TDataFrame d("treename", "filename.root");
auto v1histo = d.Filter("v1 > 0").Histo1D("v1");

Hope this helps!

1 Like

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