User-defined formula in TCut

Hello,

I would like to use my own function to specify a cut in TTree::Draw(). I read that only TFormula objects are allowed in TCut objects. But, I also read that one might have to compile this new TFormula, but I can’t figure out what the first parameter in TFormula::Compile(const char* expression = “”) is. … I don’t even know if I have to do this or not – no documentation as far as I can see.

I thought that this would work:

TFormula *uwf = new TFormula(“uwf”, “[0]+[1]*x”);
uwf->SetParameters( 1, 2 );
TCut uwc = "width < uwf( size ) ";

But, all ROOT says in return is:
*ERROR 30 :
Bad numerical expression : “uwf(size)”

I looked up error #30: it’s indeed “bad numerical expression” – not very helpful!

BTW: The documentation for TFormula (root.cern.ch/root/html/TFormula.html) is very confusing. It would be nice if someone who speaks English could rewrite this, please?

Thanks much,
Martin

TFormula *uwf = new TFormula("uwf", "[0]+[1]*x"); uwf->SetParameters(1, 2); Double_t size = 3; TCut uwc = Form("width < %g", uwf->Eval(size)); cout << uwc.GetTitle() << endl;Jan

Thanks for the reply, but this doesn’t work for my purpose. In my case “size” is a leaf on a branch on a tree, just like “width”. I want to use the evaluated expression in a

TTree::Draw(“width”, uwc)

where
TCut uwc = “A Function of a leaf in the tree that I am drawing”

How do people deal with this? Using TTree::Draw is 10x faster than looping over all events in the tree, so I was hoping to be able to do it the fast&easy way.

Cheers,
Martin

[quote=“musinsky”]TFormula *uwf = new TFormula("uwf", "[0]+[1]*x"); uwf->SetParameters(1, 2); Double_t size = 3; TCut uwc = Form("width < %g", uwf->Eval(size)); cout << uwc.GetTitle() << endl;Jan[/quote]

I assume the following would work:

Cheers,
Philippe.

PS. Altenatively you could make use of the ability of Draw to run a script (see the TTree::Draw and TTree::MakeProxy documentation).