TTree::Draw control like "nentries" but for the output?

The “nentries” optional parameter for TTree::Draw is the number of entries from the tree which will be read, compared against the selection, and if passing, drawn.

Is there a way to select the number of entries that will be drawn post-selection? E.g. if I have a TTree with 1000 entries, a selection argument, and I want the first 100 entries which pass the selection, can I get that via TTree::Draw? I can’t think of how to do it even with TEntryLists and such.

More useful than an optional parameter like “nentries” would be a special variable in the draw/selection expressions. Like Entry$ but for the number of entries in the output. Does anything like that exist?

Hi,

this can be achieved with RDataFrame. For example, let’s assume a dataset which contains two columns, x and y:

ROOT::RDataFrame rdf("myTree", "myFile.root");
auto filtered_rdf = rdf.Filter("x > 50");
auto h = filtered_rdf.Histo1D("x");
auto c = filtered_rdf.Count;
cout << "Entries passing the filter " < *c << endl;
h->Draw();

Cheers,
D

@Danilo I fail to see how / where you set a limit on entries that passed the “Filter” (e.g. only the first 100, as in the original question).

Hi,

right. You do this with Range.

ROOT::RDataFrame rdf("myTree", "myFile.root");
auto filtered_rdf = rdf.Filter("x > 50").Range(0,100);
auto h = filtered_rdf.Histo1D("x");
auto c = filtered_rdf.Count;
cout << "Entries passing the filter " < *c << endl;
h->Draw();

@Danilo Just for “completeness” of this thread … maybe you could also show how / where one can set the limit on the “number of entries from the tree which will be read” (e.g. read the first 1000 entries, accept at most 100 “Filtered”).

Sure, it’s very intuitive.
If you want to limit the total number of entries to 1000 and the filtered to 100, just another Range will do the job:

ROOT::RDataFrame rdf("myTree", "myFile.root");
auto filtered_rdf = rdf.Range(0,1000).Filter("x > 50").Range(0,100);
auto h = filtered_rdf.Histo1D("x");
auto c = filtered_rdf.Count;
cout << "Entries passing the filter " < *c << endl;
h->Draw();

Cheers,
D

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