Best way to read branches with a cut

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");
v1histo->Draw();

Hope this helps!
Enrico

1 Like