TTree selection from txt file

Dear all.

I hope this question wasn’t posted before. Still I couldn’t find an answer
on the internet to this spending an approopriate amount of time. The
question is the following:

Suppose I have a ROOT file with a tree, say “tree”, that has 100-ish
branches. For simplicity, those branches shall be called “branch0”, …
“branch99”, etc. Suppose, there are a number of branches, branch0-4
for which every entry has a unique value (or the combination of values
in those branches is unique for every event). So, doing something like

tree->Draw("branch6", "branch0 == 0 && branch1 == 1 && branch2 == 2 && branch3 == 3 && branch4 == 4")

would draw the histogram for branch6 with exactly one entry as the
combination (0,1,2,3,4) corresponds to exactly one event. OK, anyway.
Let’s suppose this is the case.

What I want to do now is the following: I want to use a .txt file with all
the combinations of all the events that I am interested in. The text file
could look like this:

0:1:2:3:4 5:6:7:8:9 10:11:12:13:14 15:16:17:18:19 etc.

So I need to select the events (0,1,2,3,4), (5,6,7,8,9), (10,11,12,13,14), etc.
But I’m lazy and I do not want to do a TTree::Draw() or Scan or something for every
single event in order to look at their branch6 or such. I could write a code
that reads this txt file and produces the TTree::Draw selection string by combining
the values and the branches in the proper way.

However, I’d like to ask if there is something like this already in place.
Is there a built-in way to give a txt file to TTree and the branch names of
the different columns and then to use it for a selection?

Thank you and cheers,

I am not sure I fully understood your question but instead of having an ASCII file with numbers, why don’t you make a macro defining TCuts ?


You may want to investigate creating a TEntryList out of the numbers from your file and using it by calling mytree->SetEntryList(entrylist);



Thank you for your answers and sorry for the late reply.
I was traveling and didn’t find time to think about this issue again.

In both suggested solutions, I need to produce some cuts out of the
text file with the numbers. This text file is what I sometimes (or often)
get from people and then I need to check the entries in the TTree that
correspond to those numbers. I wanted to make my life easier by
using a function tree->ReadFileWithNumbers(“foo.txt”) or such that
I do not have to do the selection tree->Scan(“somebranches”, “branch0==number0 && branch1 == number1…”)

If I create TCuts first out of the txt file, I also can produce this selection
string. It doesn’t really matter what I do, I’ll still have the intermediate step.

If I use an event list, I’m making my life easier for everything that comes
AFTER the selection, which I still need to do with the string or the TCut.

My question was about simplifying this selection. But I guess it is a very special
case and something like that is not in place yet.

Thank you for your answers.