Hi,
I might be wrong (@pcanal can confirm/deny) but I don’t think TTreeFormula supports variable definitions like that? I think that’s what the error complains about.
I suggest you don’t pass your code as a TTreeFormula but actually read and process data with full C++ so you have no limitations in terms of the syntax/types/language features you can use (see e.g. this post for a list of interfaces ROOT offers to read and process TTree data.
Cheers,
Enrico