Selecting events in a tree

Hi,

I have a tree with events. I’d like to select the events which fullfill a given condition. It is more convenient for me to give this condition as a string (à la TCut). Then, the events that fullfil the condition have to be processed further, so I tried to use a TEventList to retrieve them.

For example, I tried something like this

TNtupleD *NTuple = (TNtupleD *)file->Get("OnEventsNTuple;1");
cout << NTuple->GetEntries() << endl;

NTuple->Draw(">>event_list", "Energy > 1", "goff");
TEventList *list = (TEventList *)gDirectory->Get("event_list");
NTuple->SetEventList(list);

cout <<  NTuple->GetEntries() << endl;

The two “cout” give the same number, which means that the selection does not work…

How can I solve this problem ?
Thanks a lot !

The call "NTuple->SetEventList(list): does not change the number of entries in the Tree, it simply connects a TEventList to the Tree such that the next call eg to TTree::Draw will use the TEventlist in input.
If you want to know the number of entries in the TEventList, simply call list->GetN
Note that you can play with several liss with the same tree.

Rene

Thanks for your reply !

Now, how can I do to work with the events I selected in my TEventList ?
By using GetEntry from the TEventList or from the TTree ?

[quote]By using GetEntry from the TEventList or from the TTree ?[/quote]Yes either TEventList::GetEntry directly or indirectly via TTree::GetEntryNumber.

The main advantage to setting the event list in the TTree is that the automatic tools (TTree::Draw, TTree::Process will ‘use’ it).

Cheers,
Philippe.