TMVA cannot interpret some valid RDataFrame expressions as input variables

Hi,

I am training a BDT using TMVA, and I noticed that some variables defined as RDataFrame expressions cannot be interpreted by TMVA, even though they work correctly within the RDataFrame workflow.

For example, I originally defined an alias as:

aliases['LowestQGLIdx'] = {
    'expr': 'Take(Nonzero(CleanJet_qgl >= 0), Argsort(CleanJet_qgl[CleanJet_qgl >= 0]))'
}

Since I suspected Take() might be the issue, I rewrote it as:

aliases['LowestQGLIdx'] = {
    'expr': 'Nonzero(CleanJet_qgl >= 0)[Argsort(CleanJet_qgl[CleanJet_qgl >= 0])]'
}

However, TMVA still fails with the following error:

Error in TTreeFormula::Compile: Bad numerical expression: "LowestQGLIdx"
Expression LowestQGLIdx could not be resolved to a valid formula.
***> abort program execution

I encountered a similar issue with another variable, but in that case I was able to resolve it by rewriting the expression using TTreeFormula syntax.

Originally:

aliases['bVeto'] = {
    'expr': 'Sum(CleanJet_pt > 20. && abs(CleanJet_eta) < 2.5 && Take(Jet_btag{}, CleanJet_jetIdx) > {}) == 0'.format(bAlgo, bWP)
}

Rewritten as:

aliases['bVeto'] = {
    'expr': 'Sum$(CleanJet_pt > 20. && abs(CleanJet_eta) < 2.5 && (Jet_btag{}[CleanJet_jetIdx] > {})) == 0'.format(bAlgo, bWP)
}

This version works with TMVA.

My understanding is that TMVA evaluates variables using TTreeFormula, which supports a more limited expression syntax than RDataFrame. Is that the reason why expressions involving Take(), Nonzero(), Argsort(), or vector indexing fail? If so, is there a recommended way to define such variables so they can be used as TMVA input variables?

Any suggestions would be appreciated.