Home | News | Documentation | Download

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

rdataframe

#1

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?


Use RDataFrame to skim a tree
#2

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


#3

@dpiparo 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).


#4

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();

#5

@dpiparo 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”).


#6

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