Way around 1024 character limit in TTreeFormula?


I’ve noticed what appears to be a 1024 character-limit for TTreeFormula: https://root.cern.ch/root/html/src/TTreeFormula.cxx.html#56

Does anyone know of a way around this limit? I tried defining one TTreeFormula and referencing it from another (hoping that that would work like a regular TFormula), however that does not seem to be ok.

Any suggestions welcome. Is there any reason why the limit could not be increased in future versions?


Are you sure you need such a complex formula? You will run into all sorts of problems.

Better create some simpler variables representing some terms of the formula.

With a TDataFrame, use df.Define, otherwise just add a branch and avoid the long formula. What is the specific use case for such a long formula?

What sort of problems will I run in to?

The formula is so complex because we are building up very complex selections on generic TTrees. So far we have managed to avoid the limit because for many of our selections up to now we are requiring an AND of a bunch of selections, so we would create one TTreeFormula for each selection and then EvalInstance each of them and take the product in order to do the AND.

We’re hitting the problem now that one of our studies we require to apply this long list of selections inside a builtin MinIf$ function. So we have MinIf$(x,blah&&blah&&blah&&blah&&blah…) and this gets over the 1024 character limit.

Long story short, I think you just have to take my word for it that we would really like to have long formulas if we can. It’s not clear what technical problems we would run into with such long formulae?

Ah I think I just might have figured out a solution on my own. I think I can use tree->SetAlias(…) to store fragments of the complex formulae, and then use these aliases in the TTreeFormula

… I’ll see where I can get with this and will come back here if it doesn’t work out …

The problem I ran into some time ago originated from using an automatically generated long formula (>700 chars) in TMVA. TMVA stringifies the formula and creates a new branch with the corresponding name. Throughout the ROOT code you might come across some fixed-size char arrays. See my commit 634ad8182. There might be other places in the code where string length is limited to some arbitrary value. In addition to the patch, my solution was to simplify the formula by adding a branch where I precalculated parts of the formula which then became simple and short. I still think you should try to avoid long formulas, even if it is generic and/or automatically generated.

As for MinIf$: I didn’t even know it existed :slight_smile: Learning about new ROOT features every day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.