Question about TMVA::DataLoader::AddVariable()

Can TMVA::DataLoader::AddVariable() method deal with more sophiscated input variable rather than, for exmple, dataloader->AddVariable(“myvar1 := var1+var2”, ‘F’);

For example,
//////////////////////////////////////////////////////////////////////////
Float_t minNonZero=2.0;
for (int i = 0; i < 7; i++) {
if ((fE.rata[i] != 0) && (fE.rata[i] < minNonZero)) {
minNonZero = fE.rata[i] ;
}
}
fE.minrata=minNonZero;
////////////////////////////////////////////////////////////////////////////
dataloader->AddVariable( “minrata”, ‘F’ );
////////////////////////////////////////////////////////////////////////////

How could I combine the two scrips in Classification.cxx, instead of doing the loop adding new branch in original tree then dataloader->AddVariable()?

Hello @TField, thanks for the question.
I think @moneta will be able to help you with this.

Hello,
You can use in AddVariable any expression supported by TTreeFormula, i.e. an expression written as a string. It is the same syntax used also in TTree::Draw.

Lorenzo

So only simple expression can be used in AddVariable(), rather than, for example, “for loop”, etc.:upside_down_face:
However, I am wondering whether there is a way, for example, select the second smallest array element putting in the AddVariable() methods without doing the selection in another script:
//////////////////////////////////////////////////////////////////////////////////
“THIS IS FOR DEMONSTRATION”
Float_t a=0,k1,k2;
tr->SetBranchAddress(“evt.r1”, &k1);
tr->SetBranchAddress(“evt.r2”, &k2);
a=k1+k2;
dataloader->AddVariable( “a”, ‘F’ );
//////////////////////////////////////////////////////////////////////////////////
So is there any way to process the variable before dataloader::AddVariable(), then put it in, in the same scope.
Thanks