12 #if __cplusplus >= 201103L
13 #define ROOT_CPLUSPLUS11 1
28 #include <unordered_map>
42 #pragma optimize("",off)
145 static const
TString gNamePrefix = "TFormula__";
154 char ops[] = {
'+',
'^',
'-',
'/',
'*',
'<',
'>',
'|',
'&',
'!',
'=',
'?'};
155 Int_t opsLen =
sizeof(ops)/
sizeof(
char);
156 for(
Int_t i = 0; i < opsLen; ++i)
164 char brackets[] = {
')',
'(',
'{',
'}'};
165 Int_t bracketsLen =
sizeof(brackets)/
sizeof(
char);
166 for(
Int_t i = 0; i < bracketsLen; ++i)
174 return !IsBracket(c) && !IsOperator(c) && c !=
',' && c !=
' ';
179 return name ==
"x" || name ==
"z" || name ==
"y" || name ==
"t";
186 if ( (formula[i] ==
'e' || formula[i] ==
'E') && (i > 0 && i < formula.
Length()-1) ) {
188 if ( (isdigit(formula[i-1]) || formula[i-1] ==
'.') && ( isdigit(formula[i+1]) || formula[i+1] ==
'+' || formula[i+1] ==
'-' ) )
197 if ( (formula[i] ==
'x' || formula[i] ==
'X') && (i > 0 && i < formula.
Length()-1) && formula[i-1] ==
'0') {
198 if (isdigit(formula[i+1]) )
200 static char hex_values[12] = {
'a',
'A',
'b',
'B',
'c',
'C',
'd',
'D',
'e',
'E',
'f',
'F'};
201 for (
int jjj = 0; jjj < 12; ++jjj) {
202 if (formula[i+1] == hex_values[jjj])
220 if ( a[0] ==
'p' && a.
Length() > 1) {
221 if ( b[0] ==
'p' && b.
Length() > 1) {
225 if (lhs.
IsDigit() && rhs.IsDigit() )
226 return (lhs.
Atoi() < rhs.Atoi() );
233 if ( b[0] ==
'p' && b.
Length() > 1)
251 fReadyToExecute =
false;
252 fClingInitialized =
false;
253 fAllParametersSetted =
false;
260 fLambdaPtr =
nullptr;
266 if (strlen(name)!=1)
return false;
267 for (
auto const & specialName : {
"x",
"y",
"z",
"t"}){
268 if (strcmp(name,specialName)==0)
return true;
281 gROOT->GetListOfFunctions()->Remove(
this);
288 int nLinParts = fLinearParts.size();
290 for (
int i = 0; i < nLinParts; ++i)
delete fLinearParts[i];
296 fClingInput(formula),fFormula(formula)
309 if (addToGlobList &&
gROOT) {
312 old =
dynamic_cast<TFormula*
> (
gROOT->GetListOfFunctions()->FindObject(name) );
314 gROOT->GetListOfFunctions()->Remove(old);
316 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",name);
318 gROOT->GetListOfFunctions()->Add(
this);
336 fClingInput(formula),fFormula(formula)
345 for (
int i = 0; i < npar; ++i) {
359 if (addToGlobList &&
gROOT) {
362 old =
dynamic_cast<TFormula*
> (
gROOT->GetListOfFunctions()->FindObject(name) );
364 gROOT->GetListOfFunctions()->Remove(old);
366 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",name);
368 gROOT->GetListOfFunctions()->Add(
this);
373 Error(
"TFormula",
"Syntax error in building the lambda expression %s", formula );
378 TNamed(formula.GetName(),formula.GetTitle())
404 Error(
"TFormula",
"Syntax error in building the lambda expression %s",
fFormula.
Data() );
420 gROOT->GetListOfFunctions()->Remove(old);
423 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",formula.
GetName());
425 gROOT->GetListOfFunctions()->Add(
this);
444 std::string lambdaExpression = formula;
464 TString lineExpr =
TString::Format(
"std::function<double(double*,double*)> %s = %s ;",lambdaName.
Data(), lambdaExpression.c_str() );
493 if (formula.
IsNull() )
return -1;
505 return (ret) ? 0 : 1;
515 return (ret) ? 0 : 1;
542 for (
int i = 0; i < nLinParts; ++i)
delete fnew.
fLinearParts[i];
549 for (
int i = 0; i < nLinParts; ++i) {
553 linearOld->
Copy(*linearNew);
576 Error(
"TFormula",
"Syntax error in building the lambda expression %s",
fFormula.
Data() );
618 for (
int i = 0; i < nLinParts; ++i)
delete fLinearParts[i];
636 TString prototypeArguments =
"";
639 prototypeArguments.
Append(
"Double_t*");
641 if(hasVariables && hasParameters)
643 prototypeArguments.
Append(
",");
647 prototypeArguments.
Append(
"Double_t*");
653 Error(
"Eval",
"Can't find %s function prototype with arguments %s",
fClingName.
Data(),prototypeArguments.
Data());
697 const TString defvars[] = {
"x",
"y",
"z",
"t"};
706 const pair<TString,TString> funShortcuts[] =
707 { {
"sin",
"TMath::Sin" },
708 {
"cos",
"TMath::Cos" }, {
"exp",
"TMath::Exp"}, {
"log",
"TMath::Log"}, {
"log10",
"TMath::Log10"},
709 {
"tan",
"TMath::Tan"}, {
"sinh",
"TMath::SinH"}, {
"cosh",
"TMath::CosH"},
710 {
"tanh",
"TMath::TanH"}, {
"asin",
"TMath::ASin"}, {
"acos",
"TMath::ACos"},
711 {
"atan",
"TMath::ATan"}, {
"atan2",
"TMath::ATan2"}, {
"sqrt",
"TMath::Sqrt"},
712 {
"ceil",
"TMath::Ceil"}, {
"floor",
"TMath::Floor"}, {
"pow",
"TMath::Power"},
713 {
"binomial",
"TMath::Binomial"},{
"abs",
"TMath::Abs"},
714 {
"min",
"TMath::Min"},{
"max",
"TMath::Max"},{
"sign",
"TMath::Sign" },
718 std::vector<TString> defvars2(10);
719 for (
int i = 0; i < 9; ++i)
722 for(
auto var : defvars)
724 int pos =
fVars.size();
737 for(
auto con : defconsts)
739 fConsts[con.first] = con.second;
741 for(
auto fun : funShortcuts)
798 while(polPos !=
kNPOS)
801 Bool_t defaultVariable =
false;
803 Int_t openingBracketPos = formula.
Index(
'(',polPos);
804 Bool_t defaultCounter = openingBracketPos ==
kNPOS;
805 Bool_t defaultDegree =
true;
806 Int_t degree,counter;
812 sdegree = formula(polPos + 3,openingBracketPos - polPos - 3);
813 if (!sdegree.
IsDigit() ) defaultCounter =
true;
815 if (!defaultCounter) {
816 degree = sdegree.
Atoi();
817 counter =
TString(formula(openingBracketPos+1,formula.
Index(
')',polPos) - openingBracketPos)).
Atoi();
821 Int_t temp = polPos+3;
822 while(temp < formula.
Length() && isdigit(formula[temp]))
824 defaultDegree =
false;
827 degree =
TString(formula(polPos+3,temp - polPos - 3)).
Atoi();
832 if(polPos - 1 < 0 || !
IsFunctionNameChar(formula[polPos-1]) || formula[polPos-1] ==
':' )
835 defaultVariable =
true;
839 Int_t tmp = polPos - 1;
844 variable = formula(tmp + 1, polPos - (tmp+1));
846 Int_t param = counter + 1;
855 if(defaultCounter && !defaultDegree)
859 else if(defaultCounter && defaultDegree)
865 pattern =
TString::Format(
"%spol%d(%d)",(defaultVariable ?
"" : variable.
Data()),degree,counter);
869 Error(
"HandlePolN",
"Error handling polynomial function - expression is %s - trying to replace %s with %s ", formula.
Data(), pattern.
Data(), replacement.
Data() );
872 if (formula == pattern) {
878 polPos = formula.
Index(
"pol");
900 map< pair<TString,Int_t> ,pair<TString,TString> > functions;
901 functions.insert(make_pair(make_pair(
"gaus",1),make_pair(
"[0]*exp(-0.5*(({V0}-[1])/[2])*(({V0}-[1])/[2]))",
"[0]*exp(-0.5*(({V0}-[1])/[2])*(({V0}-[1])/[2]))/(sqrt(2*pi)*[2])")));
902 functions.insert(make_pair(make_pair(
"landau",1),make_pair(
"[0]*TMath::Landau({V0},[1],[2],false)",
"[0]*TMath::Landau({V0},[1],[2],true)")));
903 functions.insert(make_pair(make_pair(
"expo",1),make_pair(
"exp([0]+[1]*{V0})",
"")));
904 functions.insert(make_pair(make_pair(
"crystalball",1),make_pair(
"[0]*ROOT::Math::crystalball_function({V0},[3],[4],[2],[1])",
"[0]*ROOT::Math::crystalball_pdf({V0},[3],[4],[2],[1])")));
905 functions.insert(make_pair(make_pair(
"breitwigner",1),make_pair(
"[0]*ROOT::Math::breitwigner_pdf({V0},[2],[1])",
"[0]*ROOT::Math::breitwigner_pdf({V0},[2],[4],[1])")));
907 functions.insert(make_pair(make_pair(
"cheb0" ,1),make_pair(
"ROOT::Math::Chebyshev0({V0},[0])",
"")));
908 functions.insert(make_pair(make_pair(
"cheb1" ,1),make_pair(
"ROOT::Math::Chebyshev1({V0},[0],[1])",
"")));
909 functions.insert(make_pair(make_pair(
"cheb2" ,1),make_pair(
"ROOT::Math::Chebyshev2({V0},[0],[1],[2])",
"")));
910 functions.insert(make_pair(make_pair(
"cheb3" ,1),make_pair(
"ROOT::Math::Chebyshev3({V0},[0],[1],[2],[3])",
"")));
911 functions.insert(make_pair(make_pair(
"cheb4" ,1),make_pair(
"ROOT::Math::Chebyshev4({V0},[0],[1],[2],[3],[4])",
"")));
912 functions.insert(make_pair(make_pair(
"cheb5" ,1),make_pair(
"ROOT::Math::Chebyshev5({V0},[0],[1],[2],[3],[4],[5])",
"")));
913 functions.insert(make_pair(make_pair(
"cheb6" ,1),make_pair(
"ROOT::Math::Chebyshev6({V0},[0],[1],[2],[3],[4],[5],[6])",
"")));
914 functions.insert(make_pair(make_pair(
"cheb7" ,1),make_pair(
"ROOT::Math::Chebyshev7({V0},[0],[1],[2],[3],[4],[5],[6],[7])",
"")));
915 functions.insert(make_pair(make_pair(
"cheb8" ,1),make_pair(
"ROOT::Math::Chebyshev8({V0},[0],[1],[2],[3],[4],[5],[6],[7],[8])",
"")));
916 functions.insert(make_pair(make_pair(
"cheb9" ,1),make_pair(
"ROOT::Math::Chebyshev9({V0},[0],[1],[2],[3],[4],[5],[6],[7],[8],[9])",
"")));
917 functions.insert(make_pair(make_pair(
"cheb10",1),make_pair(
"ROOT::Math::Chebyshev10({V0},[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10])",
"")));
919 functions.insert(make_pair(make_pair(
"gaus",2),make_pair(
"[0]*exp(-0.5*(({V0}-[1])/[2])^2 - 0.5*(({V1}-[3])/[4])^2)",
"")));
920 functions.insert(make_pair(make_pair(
"landau",2),make_pair(
"[0]*TMath::Landau({V0},[1],[2],false)*TMath::Landau({V1},[3],[4],false)",
"")));
921 functions.insert(make_pair(make_pair(
"expo",2),make_pair(
"exp([0]+[1]*{V0})",
"exp([0]+[1]*{V0}+[2]*{V1})")));
923 functions.insert(make_pair(make_pair(
"bigaus",2),make_pair(
"[0]*ROOT::Math::bigaussian_pdf({V0},{V1},[2],[4],[5],[1],[3])",
"[0]*ROOT::Math::bigaussian_pdf({V0},{V1},[2],[4],[5],[1],[3])")));
925 map<TString,Int_t> functionsNumbers;
926 functionsNumbers[
"gaus"] = 100;
927 functionsNumbers[
"bigaus"] = 102;
928 functionsNumbers[
"landau"] = 400;
929 functionsNumbers[
"expo"] = 200;
930 functionsNumbers[
"crystalball"] = 500;
937 const char * defaultVariableNames[] = {
"x",
"y",
"z"};
939 for(map<pair<TString,Int_t>,pair<TString,TString> >::iterator it = functions.begin(); it != functions.end(); ++it)
942 TString funName = it->first.first;
943 Int_t funDim = it->first.second;
949 while(funPos !=
kNPOS)
956 Int_t iposBefore = funPos - 1;
958 if (iposBefore >= 0) {
960 if (isalpha(formula[iposBefore] ) ) {
962 funPos = formula.
Index(funName,lastFunPos);
967 Bool_t isNormalized =
false;
968 if (lastFunPos < formula.
Length() ) {
970 isNormalized = (formula[lastFunPos] ==
'n');
971 if (isNormalized) lastFunPos += 1;
972 if (lastFunPos < formula.
Length() ) {
973 char c = formula[lastFunPos];
976 if ( isalnum(c ) || ( !
IsOperator(c ) && c !=
'(' && c !=
')' && c !=
'[' && c !=
']' ) ) {
978 funPos = formula.
Index(funName,lastFunPos);
991 Bool_t defaultVariables =
false;
994 Int_t openingBracketPos = funPos + funName.
Length() + (isNormalized ? 1 : 0);
996 if(openingBracketPos > formula.
Length() || formula[openingBracketPos] !=
'[')
999 variables.resize(dim);
1000 for (
Int_t idim = 0; idim < dim; ++idim)
1001 variables[idim] = defaultVariableNames[idim];
1002 defaultVariables =
true;
1007 closingBracketPos = formula.
Index(
']',openingBracketPos);
1008 varList = formula(openingBracketPos+1,closingBracketPos - openingBracketPos - 1);
1010 variables.resize(dim);
1017 varName.
Append(varList[i]);
1019 if(varList[i] ==
',')
1021 variables[Nvar] = varName;
1028 variables[Nvar] = varName;
1034 pair<TString,Int_t> key = make_pair(funName,dim);
1035 if(functions.find(key) == functions.end())
1037 Int_t funDim = it->first.second;
1038 Error(
"PreProcessFormula",
"Dimension of function %s is detected to be of dimension %d and is not compatible with existing pre-defined function which has dim %d",
1039 funName.
Data(),dim,funDim);
1043 funPos = formula.
Index(funName,lastFunPos);
1048 Int_t openingParenthesisPos = (closingBracketPos ==
kNPOS) ? openingBracketPos : closingBracketPos + 1;
1049 bool defaultCounter = (openingParenthesisPos > formula.
Length() || formula[openingParenthesisPos] !=
'(');
1060 counter =
TString(formula(openingParenthesisPos+1,formula.
Index(
')',funPos) - openingParenthesisPos -1)).
Atoi();
1064 TString body = (isNormalized ? it->second.second : it->second.first);
1065 if(isNormalized && body ==
"")
1067 Error(
"PreprocessFormula",
"%d dimension function %s has no normalized form.",it->first.second,funName.
Data());
1070 for(
int i = 0 ; i < body.
Length() ; ++i)
1077 TString variable = variables[num];
1081 i += variable.
Length()-1;
1083 else if(body[i] ==
'[')
1087 while(tmp < body.
Length() && body[tmp] !=
']')
1095 body.
Replace(i+1,tmp - 1 - i,replacement,replacement.
Length());
1096 i += replacement.
Length() + 1;
1100 if(defaultCounter && defaultVariables)
1104 (isNormalized ?
"n" :
""));
1106 if(!defaultCounter && defaultVariables)
1110 (isNormalized ?
"n" :
""),
1113 if(defaultCounter && !defaultVariables)
1117 (isNormalized ?
"n":
""),
1120 if(!defaultCounter && !defaultVariables)
1124 (isNormalized ?
"n" :
""),
1132 fNumber = functionsNumbers[funName] + 10*(dim-1);
1139 funPos = formula.
Index(funName);
1153 while(caretPos !=
kNPOS)
1157 Int_t temp = caretPos;
1160 if(formula[temp] ==
')')
1164 while(depth != 0 && temp > 0)
1166 if(formula[temp] ==
')')
1168 if(formula[temp] ==
'(')
1172 if (depth == 0) temp++;
1183 Int_t leftPos = temp+1;
1184 left = formula(leftPos, caretPos - leftPos);
1190 if (temp >= formula.
Length() ) {
1191 Error(
"HandleExponentiation",
"Invalid position of operator ^");
1194 if(formula[temp] ==
'(')
1198 while(depth != 0 && temp < formula.
Length())
1200 if(formula[temp] ==
')')
1202 if(formula[temp] ==
'(')
1210 if (formula[temp] ==
'-' || formula[temp] ==
'+' ) temp++;
1215 while(temp < formula.
Length() && ( (depth > 0) || !
IsOperator(formula[temp]) ) )
1221 if (temp < formula.
Length() && formula[temp] ==
'(') depth++;
1222 if (temp < formula.
Length() && formula[temp] ==
')') {
1230 right = formula(caretPos + 1, (temp - 1) - caretPos );
1238 formula.
Replace(leftPos,pattern.
Length(),replacement,replacement.Length());
1240 caretPos = formula.
Last(
'^');
1249 if (linPos ==
kNPOS )
return;
1255 while(linPos !=
kNPOS)
1263 while(temp >= 0 && formula[temp] !=
'@')
1267 left = formula(temp+1,linPos - (temp +1));
1270 while(temp < formula.
Length() && formula[temp] !=
'@')
1274 TString right = formula(linPos+1,temp - (linPos+1));
1278 Nlinear += (first) ? 2 : 1;
1288 linPos = formula.
Index(
"@");
1366 if(formula[i] ==
'[')
1371 while(formula[i] !=
']' && i < formula.
Length())
1373 param.
Append(formula[i++]);
1382 formula.
Replace(tmp,i - tmp, replacement,replacement.
Length());
1388 if (formula[i] ==
'\"') {
1392 }
while(formula[i] !=
'\"');
1410 if(isalpha(formula[i]) && !
IsOperator(formula[i]))
1417 if (formula[i] ==
':' && ( (i+1) < formula.
Length() ) ) {
1418 if ( formula[i+1] ==
':' ) {
1428 name.
Append(formula[i++]);
1431 if(formula[i] ==
'(')
1434 if(formula[i] ==
')')
1442 while(depth != 0 && i < formula.
Length())
1446 case '(': depth++;
break;
1447 case ')': depth--;
break;
1448 case ',':
if(depth == 1) args++;
break;
1452 body.
Append(formula[i++]);
1457 formula.
Replace(i-originalBodyLen,originalBodyLen,body,body.
Length());
1458 i += body.
Length() - originalBodyLen;
1470 obj =
gROOT->GetListOfFunctions()->FindObject(name);
1490 std::vector<TString> newNames;
1493 newNames.resize(f->
GetNpar() );
1495 for (
int jpar = f->
GetNpar()-1; jpar >= 0; --jpar ) {
1502 replacementFormula.
ReplaceAll(oldName,newName);
1503 newNames[jpar] = newName;
1514 for (
int jpar = 0; jpar < f->
GetNpar(); ++jpar) {
1515 if (nparOffset> 0) {
1525 replacementFormula.
Insert(0,
'(');
1526 replacementFormula.
Insert(replacementFormula.
Length(),
')');
1573 for(list<TFormulaFunction>::iterator funcsIt =
fFuncs.begin(); funcsIt !=
fFuncs.end(); ++funcsIt)
1591 while ( index !=
kNPOS) {
1595 if ( (index > 0) && (isalpha( formula[index-1] ) || formula[index-1] ==
':' )) {
1596 index = formula.
Index(shortcut,i2);
1599 if (i2 < formula.
Length() && formula[i2] !=
'(') {
1600 index = formula.
Index(shortcut,i2);
1606 index = formula.
Index(shortcut,inext);
1614 size_t index = name.rfind(
"::");
1615 assert(index != std::string::npos);
1627 if (strcmp(p->
GetName(),functionName.
Data()) == 0 &&
1654 Info(
"TFormula",
"Could not find %s function with %d argument(s)",fun.
GetName(),fun.
GetNargs());
1679 map<TString,TFormulaVariable>::iterator varsIt =
fVars.find(fun.
GetName());
1680 if(varsIt!=
fVars.end())
1688 if(!
fVars[name].fFound)
1693 int varDim = (*varsIt).second.fArrayPos;
1694 if (varDim >=
fNdim) {
1698 for (
auto &v :
fVars) {
1699 if (v.second.fArrayPos < varDim && !v.second.fFound ) {
1701 v.second.fFound =
true;
1722 int digit = sdigit.
Atoi();
1723 if (digit >=
fNdim) {
1726 for (
int j = 0; j <
fNdim; ++j) {
1730 fVars[vname].fFound =
true;
1766 map<TString,Double_t>::iterator constIt =
fConsts.find(fun.
GetName());
1794 if (hasParameters && ! hasVariables) {
1797 hasVariables =
true;
1799 Bool_t hasBoth = hasVariables && hasParameters;
1801 if (inputIntoCling) {
1805 std::string inputFormula = std::string(formula);
1810 TString::Format(
"%s%s%s",(hasVariables ?
"Double_t *x" :
""), (hasBoth ?
"," :
""),
1811 (hasParameters ?
"Double_t *p" :
""));
1825 inputIntoCling =
false;
1844 if(inputIntoCling) {
1865 Bool_t allFunctorsMatched =
true;
1866 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); it++)
1870 allFunctorsMatched =
false;
1871 if (it->GetNargs() == 0)
1872 Error(
"ProcessFormula",
"\"%s\" has not been matched in the formula expression",it->GetName() );
1874 Error(
"ProcessFormula",
"Could not find %s function with %d argument(s)",it->GetName(),it->GetNargs());
1877 if (!allFunctorsMatched) {
1885 auto itvar =
fVars.begin();
1888 if ( ! itvar->second.fFound ) {
1890 itvar =
fVars.erase(itvar);
1895 while( itvar !=
fVars.end() );
1974 if (i < 0 || i >= n ) {
1975 Error(
"GetLinearPart",
"Formula %s has only %d linear parts - requested %d",
GetName(),n,i);
2027 Bool_t anyNewVar =
false;
2028 for(
Int_t i = 0 ; i < size; ++i)
2031 const TString & vname = vars[i];
2043 Int_t multiplier = 2;
2070 Error(
"SetName",
"The name \'%s\' is reserved as a TFormula variable name.\n"
2071 "\tThis function will not be renamed.",name);
2075 auto listOfFunctions =
gROOT->GetListOfFunctions();
2076 TObject* thisAsFunctionInList =
nullptr;
2078 if (listOfFunctions){
2079 thisAsFunctionInList = listOfFunctions->
FindObject(
this);
2080 if (thisAsFunctionInList) listOfFunctions->Remove(thisAsFunctionInList);
2083 if (thisAsFunctionInList) listOfFunctions->Add(thisAsFunctionInList);
2096 for(
Int_t i = 0; i < size; ++i)
2098 pair<TString,Double_t> v = vars[i];
2101 fVars[v.first].fValue = v.second;
2106 Error(
"SetVariables",
"Variable %s is not defined.",v.first.Data());
2119 Error(
"GetVariable",
"Variable %s is not defined.",sname.
Data());
2122 return fVars.find(sname)->second.fValue;
2132 Error(
"GetVarNumber",
"Variable %s is not defined.",sname.
Data());
2135 return fVars.find(sname)->second.fArrayPos;
2144 if (ivar < 0 || ivar >=
fNdim)
return "";
2147 for (
auto & v :
fVars) {
2148 if (v.second.fArrayPos == ivar)
return v.first;
2150 Error(
"GetVarName",
"Variable with index %d not found !!",ivar);
2162 Error(
"SetVariable",
"Variable %s is not defined.",name.
Data());
2206 auto ret =
fParams.insert(std::make_pair(name,pos));
2212 if (ret.first ==
fParams.begin() )
2215 auto previous = (ret.first);
2217 pos = previous->second + 1;
2235 for (
auto it = ret.first; it !=
fParams.end(); ++it ) {
2243 if (processFormula) {
2270 Error(
"GetParameter",
"Parameter %s is not defined.",name);
2285 Error(
"GetParameter",
"wrong index used - use GetParameter(name)");
2293 if (ipar < 0 || ipar >=
fNpar)
return "";
2297 if (p.second == ipar)
return p.first.Data();
2299 Error(
"GetParName",
"Parameter with index %d not found !!",ipar);
2333 Error(
"SetParameter",
"Parameter %s is not defined.",name.Data());
2340 for(map<TString,TFormulaVariable>::iterator it = fParams.begin(); it != fParams.end(); it++)
2342 if(!it->second.fFound)
2360 for(
Int_t i = 0 ; i < size ; ++i)
2362 pair<TString,Double_t> p = params[i];
2365 Error(
"SetParameters",
"Parameter %s is not defined",p.first.Data());
2368 fParams[p.first].fValue = p.second;
2369 fParams[p.first].fFound =
true;
2373 for(map<TString,TFormulaVariable>::iterator it =
fParams.begin(); it !=
fParams.end(); it++)
2375 if(!it->second.fFound)
2386 if(!params || size < 0 || size >
fNpar)
return;
2389 Warning(
"SetParameters",
"size is not same of cling parameter size %d - %d",size,
int(
fClingParameters.size()) );
2390 for(
Int_t i = 0; i < size; ++i)
2432 if (param < 0 || param >=
fNpar)
return;
2439 const char *name4,
const char *name5,
const char *name6,
const char *name7,
2440 const char *name8,
const char *name9,
const char *name10)
2457 if (ipar < 0 || ipar >
fNpar) {
2458 Error(
"SetParName",
"Wrong Parameter index %d ",ipar);
2464 if (it.second == ipar) {
2466 fParams.erase(oldName);
2467 fParams.insert(std::make_pair(name, ipar) );
2472 Error(
"SetParName",
"Parameter %d is not existing.",ipar);
2483 if (!formula.
IsNull() ) {
2485 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2487 if(oldName == it->GetName())
2496 Error(
"SetParName",
"Parameter %s is not defined.",oldName.
Data());
2512 return DoEval(x, params);
2519 double xxx[4] = {
x,
y,z,t};
2527 double xxx[3] = {
x,
y,z};
2535 double xxx[2] = {
x,y};
2558 Error(
"Eval",
"Formula is invalid and not ready to execute ");
2559 for(
auto it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2570 std::function<double(double *, double *)> & fptr = * ( (std::function<double(double *, double *)> *)
fLambdaPtr);
2573 double * v =
const_cast<double*
>(
x);
2574 double * p = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2579 Error(
"Eval",
"Formula is invalid or not properly initialized - try calling TFormula::Compile");
2581 #ifdef EVAL_IS_NOT_CONST
2592 double * vars = (
x) ? const_cast<double*>(x) :
const_cast<double*
>(
fClingVariables.data());
2595 (*fFuncPtr)(0, 1, args, &
result);
2597 double * pars = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2599 (*fFuncPtr)(0, 2, args, &
result);
2625 if (found == std::string::npos || found2 == std::string::npos) {
2626 Error(
"GetExpFormula",
"Invalid Cling expression - return default formula expression");
2631 if (!opt.
Contains(
"P"))
return clingFormula;
2634 while (i < clingFormula.
Length()-2 ) {
2636 if (clingFormula[i] ==
'p' && clingFormula[i+1] ==
'[' && isdigit(clingFormula[i+2]) ) {
2638 while ( isdigit(clingFormula[j]) ) { j++;}
2639 if (clingFormula[j] !=
']') {
2640 Error(
"GetExpFormula",
"Parameters not found - invalid expression - return default cling formula");
2641 return clingFormula;
2643 TString parNumbName = clingFormula(i+2,j-i-2);
2644 int parNumber = parNumbName.
Atoi();
2647 clingFormula.
Replace(i,j-i+1, replacement );
2648 i += replacement.
Length();
2652 return clingFormula;
2658 while (i < expFormula.
Length()-2 ) {
2660 if (expFormula[i] ==
'[') {
2662 while ( expFormula[j] !=
']' ) { j++;}
2663 if (expFormula[j] !=
']') {
2664 Error(
"GetExpFormula",
"Parameter names not found - invalid expression - return default formula");
2667 TString parName = expFormula(i+1,j-i-1);
2669 expFormula.
Replace(i,j-i+1, replacement );
2670 i += replacement.
Length();
2676 Warning(
"GetExpFormula",
"Invalid option - return defult formula expression");
2685 printf(
" Formula expression: \n");
2692 if (opt.Contains(
"V") ) {
2694 printf(
"List of Variables: \n");
2696 for (
int ivar = 0; ivar <
fNdim ; ++ivar) {
2701 printf(
"List of Parameters: \n");
2706 for (
int ipar = 0; ipar <
fNpar ; ++ipar) {
2710 printf(
"Expression passed to Cling:\n");
2715 Warning(
"Print",
"Formula is not ready to execute. Missing parameters/variables");
2716 for(list<TFormulaFunction>::const_iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2745 void TFormula::Streamer(
TBuffer &b)
2751 if (v <= 8 && v > 3 && v != 6) {
2764 Error(
"Streamer",
"Old formula read from file is NOT valid");
2810 if (
fNpar != (
int) parValues.size() ) {
2811 Error(
"Streamer",
"number of parameters computed (%d) is not same as the stored parameters (%d)",
fNpar,
int(parValues.size()) );
2826 if (
fParams.size() != paramMap.size() ) {
2827 Warning(
"Streamer",
"number of parameters list found (%lu) is not same as the stored one (%lu) - use re-created list",
fParams.size(),paramMap.size()) ;
2845 gROOT->GetListOfFunctions()->Add(
this);
2848 Error(
"Streamer",
"Formula read from file is NOT ready to execute");
2856 Error(
"Streamer",
"Reading version %d is not supported",v);
virtual const char * GetTitle() const
Returns title of object.
Ssiz_t Last(char c) const
Find last occurrence of a character c.
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *) const
Double_t Floor(Double_t x)
virtual TFormula * GetFormula()
static double p3(double t, double a, double b, double c, double d)
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void variables(TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
TString & ReplaceAll(const TString &s1, const TString &s2)
Int_t GetNargs() const
Number of function arguments.
virtual void SetName(const char *name)
Change (i.e.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void ToUpper()
Change string to upper case.
Buffer base class used for serializing objects.
CallFunc_t * GetCallFunc() const
R__EXTERN TVirtualMutex * gROOTMutex
const TList * GetListOfAllPublicMethods(Bool_t load=kTRUE)
Returns a list of all public methods of this class and its base classes.
TString & Insert(Ssiz_t pos, const char *s)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
The TNamed class is the base class for all named ROOT classes.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual void Copy(TObject &named) const
Copy this to obj.
Double_t Log10(Double_t x)
virtual Bool_t Declare(const char *code)=0
static double p2(double t, double a, double b, double c)
void(* Generic_t)(void *, int, void **, void *)
TString & Append(const char *cs)
std::vector< std::vector< double > > Data
Int_t Atoi() const
Return integer value of string.
Method or function calling interface.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
virtual void Delete(Option_t *option="")
Delete this object.
Bool_t TestBit(UInt_t f) const
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
static double p1(double t, double a, double b)
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Mother of all ROOT objects.
Global functions class (global functions are obtained from CINT).
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Short_t Max(Short_t a, Short_t b)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Each ROOT class (see TClass) has a linked list of methods.
R__EXTERN TInterpreter * gCling
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.