How to quickly apply a TCut

Dear ROOTers,

Is there a way to “apply” a TCut on a particular “row” in a TTree? Here is what I want to do:

for (long int jentry=0; jentry<mychain->GetEntries(); jentry++) { mychain->GetEntry(jentry); TCut mycut = "x>y && z>x"; TCut mycut2 = "x<y && z<x"; bool thisentrypasses = mycut.Apply(mychain, jentry) if ( thisentrypasses ) { .... } if ( mycut2.Apply(mychain, jentry) ) { .... } }

This should somehow be doable in a nice way, since TTree::Draw() accepts such cuts. I see there is a new class called TSelectorEntries in the recent versions of ROOT, so perhaps that is the answer (a reference to an example would be useful), but I would really appreciate to hear about a solution that would work in earlier versions (say 5.12), if it exists.

(One solution would be to write a parser for TCut strings, which is able to extract all the necessary information from calls like
((TLeaf*)(myhain->GetLeaf(“x”))->GetValue(0). If someone has this sort of code and would not mind sharing it, it will be very much appreciated.)

Thanks a lot,

Erkcan

PS: I have a “hack” solution based on TROOT’s ProcessLineSync() and ProcessLineFast() calls, but I would appreciate a more elegant solution, particularly because I compile the code and prefer less dependence on CINT-like constructs.

Create a TTreeFormula object outside the loop with your cuts, then iside teh loop call formula.EvalInstance(). If it returns <=0 it means that the entry is rejected. See examples of use in TTreePlayer::Scan

Rene