TTree selection using variables

Hello everyone,

I’ve got a TTree with 3 branches containing numbers and I’d like to create a TEventList out of one of them, given a condition,i.e:

myTree->Draw(">>list"," branch_name > value");

my problem is that this “value” is a variable declared before which value I don’t know from the beginning, and this line is inside a loop, with “value” being different for each iteration.

I´ve benn searching the forum, and all the answers I’ve found say you can’t use a variable inside the selection; you have to use either a number or a tree branch. Is there anyway to implement this idea, even if it follows a different approach? It would save me huge amounts of time.

Thank you in advance.


Assuming that you are in a loop and you compute a variable, say “double value”, you can use the function Form in TString to convert a numerical value to a string, eg
for (i=0;i<…) {
double value = some function of i
myTree->Draw(">>list",Form( branch_name > %g),value));


Thank you very much, that’s just what I was looking for. I made some attempts and the correct sintax is

myTree->Draw(">>list",Form( “branch_name > %g” ,value));

Thanks again,