12 #if __cplusplus >= 201103L 13 #define ROOT_CPLUSPLUS11 1 28 #include <unordered_map> 42 #pragma optimize("",off) 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)
310 if (addToGlobList &&
gROOT) {
313 old =
dynamic_cast<TFormula*
> (
gROOT->GetListOfFunctions()->FindObject(name) );
315 gROOT->GetListOfFunctions()->Remove(old);
317 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",name);
319 gROOT->GetListOfFunctions()->Add(
this);
347 for (
int i = 0; i < npar; ++i) {
351 assert (
fNpar == npar);
361 if (addToGlobList &&
gROOT) {
364 old =
dynamic_cast<TFormula*
> (
gROOT->GetListOfFunctions()->FindObject(name) );
366 gROOT->GetListOfFunctions()->Remove(old);
368 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",name);
370 gROOT->GetListOfFunctions()->Add(
this);
375 Error(
"TFormula",
"Syntax error in building the lambda expression %s", formula );
406 Error(
"TFormula",
"Syntax error in building the lambda expression %s",
fFormula.
Data() );
422 gROOT->GetListOfFunctions()->Remove(old);
425 Error(
"TFormula",
"The name %s is reserved as a TFormula variable name.\n",formula.
GetName());
427 gROOT->GetListOfFunctions()->Add(
this);
446 std::string lambdaExpression = formula;
466 TString lineExpr =
TString::Format(
"std::function<double(double*,double*)> %s = %s ;",lambdaName.
Data(), lambdaExpression.c_str() );
495 if (formula.
IsNull() )
return -1;
507 return (ret) ? 0 : 1;
517 return (ret) ? 0 : 1;
544 for (
int i = 0; i < nLinParts; ++i)
delete fnew.
fLinearParts[i];
551 for (
int i = 0; i < nLinParts; ++i) {
555 linearOld->
Copy(*linearNew);
578 Error(
"TFormula",
"Syntax error in building the lambda expression %s",
fFormula.
Data() );
620 for (
int i = 0; i < nLinParts; ++i)
delete fLinearParts[i];
638 TString prototypeArguments =
"";
641 prototypeArguments.
Append(
"Double_t*");
643 if(hasVariables && hasParameters)
645 prototypeArguments.
Append(
",");
649 prototypeArguments.
Append(
"Double_t*");
655 Error(
"Eval",
"Can't find %s function prototype with arguments %s",
fClingName.
Data(),prototypeArguments.
Data());
699 const TString defvars[] = {
"x",
"y",
"z",
"t"};
708 const pair<TString,TString> funShortcuts[] =
709 { {
"sin",
"TMath::Sin" },
710 {
"cos",
"TMath::Cos" }, {
"exp",
"TMath::Exp"}, {
"log",
"TMath::Log"}, {
"log10",
"TMath::Log10"},
711 {
"tan",
"TMath::Tan"}, {
"sinh",
"TMath::SinH"}, {
"cosh",
"TMath::CosH"},
712 {
"tanh",
"TMath::TanH"}, {
"asin",
"TMath::ASin"}, {
"acos",
"TMath::ACos"},
713 {
"atan",
"TMath::ATan"}, {
"atan2",
"TMath::ATan2"}, {
"sqrt",
"TMath::Sqrt"},
714 {
"ceil",
"TMath::Ceil"}, {
"floor",
"TMath::Floor"}, {
"pow",
"TMath::Power"},
715 {
"binomial",
"TMath::Binomial"},{
"abs",
"TMath::Abs"},
716 {
"min",
"TMath::Min"},{
"max",
"TMath::Max"},{
"sign",
"TMath::Sign" },
720 std::vector<TString> defvars2(10);
721 for (
int i = 0; i < 9; ++i)
724 for(
auto var : defvars)
726 int pos =
fVars.size();
739 for(
auto con : defconsts)
741 fConsts[con.first] = con.second;
743 for(
auto fun : funShortcuts)
800 while(polPos !=
kNPOS)
803 Bool_t defaultVariable =
false;
805 Int_t openingBracketPos = formula.
Index(
'(',polPos);
806 Bool_t defaultCounter = openingBracketPos ==
kNPOS;
807 Bool_t defaultDegree =
true;
808 Int_t degree,counter;
814 sdegree = formula(polPos + 3,openingBracketPos - polPos - 3);
815 if (!sdegree.
IsDigit() ) defaultCounter =
true;
817 if (!defaultCounter) {
818 degree = sdegree.
Atoi();
819 counter =
TString(formula(openingBracketPos+1,formula.
Index(
')',polPos) - openingBracketPos)).
Atoi();
823 Int_t temp = polPos+3;
824 while(temp < formula.
Length() && isdigit(formula[temp]))
826 defaultDegree =
false;
829 degree =
TString(formula(polPos+3,temp - polPos - 3)).
Atoi();
834 if(polPos - 1 < 0 || !
IsFunctionNameChar(formula[polPos-1]) || formula[polPos-1] ==
':' )
837 defaultVariable =
true;
841 Int_t tmp = polPos - 1;
846 variable = formula(tmp + 1, polPos - (tmp+1));
848 Int_t param = counter + 1;
857 if(defaultCounter && !defaultDegree)
861 else if(defaultCounter && defaultDegree)
867 pattern =
TString::Format(
"%spol%d(%d)",(defaultVariable ?
"" : variable.
Data()),degree,counter);
871 Error(
"HandlePolN",
"Error handling polynomial function - expression is %s - trying to replace %s with %s ", formula.
Data(), pattern.
Data(), replacement.
Data() );
874 if (formula == pattern) {
880 polPos = formula.
Index(
"pol");
902 map< pair<TString,Int_t> ,pair<TString,TString> > functions;
903 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])")));
904 functions.insert(make_pair(make_pair(
"landau",1),make_pair(
"[0]*TMath::Landau({V0},[1],[2],false)",
"[0]*TMath::Landau({V0},[1],[2],true)")));
905 functions.insert(make_pair(make_pair(
"expo",1),make_pair(
"exp([0]+[1]*{V0})",
"")));
906 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])")));
907 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])")));
909 functions.insert(make_pair(make_pair(
"cheb0" ,1),make_pair(
"ROOT::Math::Chebyshev0({V0},[0])",
"")));
910 functions.insert(make_pair(make_pair(
"cheb1" ,1),make_pair(
"ROOT::Math::Chebyshev1({V0},[0],[1])",
"")));
911 functions.insert(make_pair(make_pair(
"cheb2" ,1),make_pair(
"ROOT::Math::Chebyshev2({V0},[0],[1],[2])",
"")));
912 functions.insert(make_pair(make_pair(
"cheb3" ,1),make_pair(
"ROOT::Math::Chebyshev3({V0},[0],[1],[2],[3])",
"")));
913 functions.insert(make_pair(make_pair(
"cheb4" ,1),make_pair(
"ROOT::Math::Chebyshev4({V0},[0],[1],[2],[3],[4])",
"")));
914 functions.insert(make_pair(make_pair(
"cheb5" ,1),make_pair(
"ROOT::Math::Chebyshev5({V0},[0],[1],[2],[3],[4],[5])",
"")));
915 functions.insert(make_pair(make_pair(
"cheb6" ,1),make_pair(
"ROOT::Math::Chebyshev6({V0},[0],[1],[2],[3],[4],[5],[6])",
"")));
916 functions.insert(make_pair(make_pair(
"cheb7" ,1),make_pair(
"ROOT::Math::Chebyshev7({V0},[0],[1],[2],[3],[4],[5],[6],[7])",
"")));
917 functions.insert(make_pair(make_pair(
"cheb8" ,1),make_pair(
"ROOT::Math::Chebyshev8({V0},[0],[1],[2],[3],[4],[5],[6],[7],[8])",
"")));
918 functions.insert(make_pair(make_pair(
"cheb9" ,1),make_pair(
"ROOT::Math::Chebyshev9({V0},[0],[1],[2],[3],[4],[5],[6],[7],[8],[9])",
"")));
919 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])",
"")));
921 functions.insert(make_pair(make_pair(
"gaus",2),make_pair(
"[0]*exp(-0.5*(({V0}-[1])/[2])^2 - 0.5*(({V1}-[3])/[4])^2)",
"")));
922 functions.insert(make_pair(make_pair(
"landau",2),make_pair(
"[0]*TMath::Landau({V0},[1],[2],false)*TMath::Landau({V1},[3],[4],false)",
"")));
923 functions.insert(make_pair(make_pair(
"expo",2),make_pair(
"exp([0]+[1]*{V0})",
"exp([0]+[1]*{V0}+[2]*{V1})")));
925 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])")));
927 map<TString,Int_t> functionsNumbers;
928 functionsNumbers[
"gaus"] = 100;
929 functionsNumbers[
"bigaus"] = 102;
930 functionsNumbers[
"landau"] = 400;
931 functionsNumbers[
"expo"] = 200;
932 functionsNumbers[
"crystalball"] = 500;
945 const char * defaultVariableNames[] = {
"x",
"y",
"z"};
947 for(map<pair<TString,Int_t>,pair<TString,TString> >::iterator it = functions.begin(); it != functions.end(); ++it)
950 TString funName = it->first.first;
951 Int_t funDim = it->first.second;
957 while(funPos !=
kNPOS)
964 Int_t iposBefore = funPos - 1;
966 if (iposBefore >= 0) {
967 assert( iposBefore < formula.
Length() );
968 if (isalpha(formula[iposBefore] ) ) {
970 funPos = formula.
Index(funName,lastFunPos);
975 Bool_t isNormalized =
false;
976 if (lastFunPos < formula.
Length() ) {
978 isNormalized = (formula[lastFunPos] ==
'n');
979 if (isNormalized) lastFunPos += 1;
980 if (lastFunPos < formula.
Length() ) {
981 char c = formula[lastFunPos];
984 if ( isalnum(c ) || ( !
IsOperator(c ) && c !=
'(' && c !=
')' && c !=
'[' && c !=
']' ) ) {
986 funPos = formula.
Index(funName,lastFunPos);
999 Bool_t defaultVariables =
false;
1002 Int_t openingBracketPos = funPos + funName.
Length() + (isNormalized ? 1 : 0);
1004 if(openingBracketPos > formula.
Length() || formula[openingBracketPos] !=
'[')
1007 variables.resize(dim);
1008 for (
Int_t idim = 0; idim < dim; ++idim)
1009 variables[idim] = defaultVariableNames[idim];
1010 defaultVariables =
true;
1015 closingBracketPos = formula.
Index(
']',openingBracketPos);
1016 varList = formula(openingBracketPos+1,closingBracketPos - openingBracketPos - 1);
1018 variables.resize(dim);
1025 varName.
Append(varList[i]);
1027 if(varList[i] ==
',')
1029 variables[Nvar] = varName;
1036 variables[Nvar] = varName;
1043 pair<TString,Int_t> key = make_pair(funName,dim);
1044 if(functions.find(key) == functions.end())
1046 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",
1047 funName.
Data(),dim,funDim);
1051 funPos = formula.
Index(funName,lastFunPos);
1056 Int_t openingParenthesisPos = (closingBracketPos ==
kNPOS) ? openingBracketPos : closingBracketPos + 1;
1057 bool defaultCounter = (openingParenthesisPos > formula.
Length() || formula[openingParenthesisPos] !=
'(');
1068 counter =
TString(formula(openingParenthesisPos+1,formula.
Index(
')',funPos) - openingParenthesisPos -1)).
Atoi();
1072 TString body = (isNormalized ? it->second.second : it->second.first);
1073 if(isNormalized && body ==
"")
1075 Error(
"PreprocessFormula",
"%d dimension function %s has no normalized form.",it->first.second,funName.
Data());
1078 for(
int i = 0 ; i < body.
Length() ; ++i)
1085 TString variable = variables[num];
1089 i += variable.
Length()-1;
1091 else if(body[i] ==
'[')
1095 while(tmp < body.
Length() && body[tmp] !=
']')
1103 body.
Replace(i+1,tmp - 1 - i,replacement,replacement.
Length());
1104 i += replacement.
Length() + 1;
1108 if(defaultCounter && defaultVariables)
1112 (isNormalized ?
"n" :
""));
1114 if(!defaultCounter && defaultVariables)
1118 (isNormalized ?
"n" :
""),
1121 if(defaultCounter && !defaultVariables)
1125 (isNormalized ?
"n":
""),
1128 if(!defaultCounter && !defaultVariables)
1132 (isNormalized ?
"n" :
""),
1140 fNumber = functionsNumbers[funName] + 10*(dim-1);
1145 formula.
Replace(funPos,pattern.
Length(),replacement,replacement.Length());
1147 funPos = formula.
Index(funName);
1161 while(caretPos !=
kNPOS)
1165 Int_t temp = caretPos;
1168 if(formula[temp] ==
')')
1172 while(depth != 0 && temp > 0)
1174 if(formula[temp] ==
')')
1176 if(formula[temp] ==
'(')
1180 if (depth == 0) temp++;
1190 assert(temp+1 >= 0);
1191 Int_t leftPos = temp+1;
1192 left = formula(leftPos, caretPos - leftPos);
1198 if (temp >= formula.
Length() ) {
1199 Error(
"HandleExponentiation",
"Invalid position of operator ^");
1202 if(formula[temp] ==
'(')
1206 while(depth != 0 && temp < formula.
Length())
1208 if(formula[temp] ==
')')
1210 if(formula[temp] ==
'(')
1218 if (formula[temp] ==
'-' || formula[temp] ==
'+' ) temp++;
1223 while(temp < formula.
Length() && ( (depth > 0) || !
IsOperator(formula[temp]) ) )
1229 if (temp < formula.
Length() && formula[temp] ==
'(') depth++;
1230 if (temp < formula.
Length() && formula[temp] ==
')') {
1238 right = formula(caretPos + 1, (temp - 1) - caretPos );
1246 formula.
Replace(leftPos,pattern.
Length(),replacement,replacement.Length());
1248 caretPos = formula.
Last(
'^');
1257 if (linPos ==
kNPOS )
return;
1259 assert(NofLinParts > 0);
1263 while(linPos !=
kNPOS)
1271 while(temp >= 0 && formula[temp] !=
'@')
1275 left = formula(temp+1,linPos - (temp +1));
1278 while(temp < formula.
Length() && formula[temp] !=
'@')
1282 TString right = formula(linPos+1,temp - (linPos+1));
1286 Nlinear += (first) ? 2 : 1;
1296 linPos = formula.
Index(
"@");
1374 if(formula[i] ==
'[')
1379 while(formula[i] !=
']' && i < formula.
Length())
1381 param.
Append(formula[i++]);
1390 formula.
Replace(tmp,i - tmp, replacement,replacement.
Length());
1396 if (formula[i] ==
'\"') {
1400 }
while(formula[i] !=
'\"');
1418 if(isalpha(formula[i]) && !
IsOperator(formula[i]))
1425 if (formula[i] ==
':' && ( (i+1) < formula.
Length() ) ) {
1426 if ( formula[i+1] ==
':' ) {
1436 name.
Append(formula[i++]);
1439 if(formula[i] ==
'(')
1442 if(formula[i] ==
')')
1450 while(depth != 0 && i < formula.
Length())
1454 case '(': depth++;
break;
1455 case ')': depth--;
break;
1456 case ',':
if(depth == 1) args++;
break;
1460 body.
Append(formula[i++]);
1465 formula.
Replace(i-originalBodyLen,originalBodyLen,body,body.
Length());
1466 i += body.
Length() - originalBodyLen;
1478 obj =
gROOT->GetListOfFunctions()->FindObject(name);
1483 TF1 *
f1 =
dynamic_cast<TF1*
> (obj);
1498 std::vector<TString> newNames;
1501 newNames.resize(f->
GetNpar() );
1503 for (
int jpar = f->
GetNpar()-1; jpar >= 0; --jpar ) {
1510 replacementFormula.
ReplaceAll(oldName,newName);
1511 newNames[jpar] = newName;
1522 for (
int jpar = 0; jpar < f->
GetNpar(); ++jpar) {
1523 if (nparOffset> 0) {
1525 assert((
int) newNames.size() == f->
GetNpar() );
1533 replacementFormula.
Insert(0,
'(');
1534 replacementFormula.
Insert(replacementFormula.
Length(),
')');
1581 for(list<TFormulaFunction>::iterator funcsIt =
fFuncs.begin(); funcsIt !=
fFuncs.end(); ++funcsIt)
1599 while ( index !=
kNPOS) {
1603 if ( (index > 0) && (isalpha( formula[index-1] ) || formula[index-1] ==
':' )) {
1604 index = formula.
Index(shortcut,i2);
1607 if (i2 < formula.
Length() && formula[i2] !=
'(') {
1608 index = formula.
Index(shortcut,i2);
1614 index = formula.
Index(shortcut,inext);
1622 size_t index = name.rfind(
"::");
1623 assert(index != std::string::npos);
1631 TIter next(methodList);
1633 while ((p = (
TMethod*) next()))
1635 if (strcmp(p->
GetName(),functionName.
Data()) == 0 &&
1662 Info(
"TFormula",
"Could not find %s function with %d argument(s)",fun.
GetName(),fun.
GetNargs());
1687 map<TString,TFormulaVariable>::iterator varsIt =
fVars.find(fun.
GetName());
1688 if(varsIt!=
fVars.end())
1692 Double_t value = (*varsIt).second.fValue;
1696 if(!
fVars[name].fFound)
1701 int varDim = (*varsIt).second.fArrayPos;
1702 if (varDim >=
fNdim) {
1707 if (
v.second.fArrayPos < varDim && !
v.second.fFound ) {
1709 v.second.fFound =
true;
1730 int digit = sdigit.
Atoi();
1731 if (digit >=
fNdim) {
1734 for (
int j = 0; j <
fNdim; ++j) {
1738 fVars[vname].fFound =
true;
1774 map<TString,Double_t>::iterator constIt =
fConsts.find(fun.
GetName());
1802 if (hasParameters && ! hasVariables) {
1805 hasVariables =
true;
1807 Bool_t hasBoth = hasVariables && hasParameters;
1809 if (inputIntoCling) {
1813 std::string inputFormula = std::string(formula);
1818 TString::Format(
"%s%s%s",(hasVariables ?
"Double_t *x" :
""), (hasBoth ?
"," :
""),
1819 (hasParameters ?
"Double_t *p" :
""));
1833 inputIntoCling =
false;
1852 if(inputIntoCling) {
1873 Bool_t allFunctorsMatched =
true;
1874 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); it++)
1878 allFunctorsMatched =
false;
1879 if (it->GetNargs() == 0)
1880 Error(
"ProcessFormula",
"\"%s\" has not been matched in the formula expression",it->GetName() );
1882 Error(
"ProcessFormula",
"Could not find %s function with %d argument(s)",it->GetName(),it->GetNargs());
1885 if (!allFunctorsMatched) {
1893 auto itvar =
fVars.begin();
1896 if ( ! itvar->second.fFound ) {
1898 itvar =
fVars.erase(itvar);
1903 while( itvar !=
fVars.end() );
1982 if (i < 0 || i >= n ) {
1983 Error(
"GetLinearPart",
"Formula %s has only %d linear parts - requested %d",
GetName(),n,i);
2035 Bool_t anyNewVar =
false;
2036 for(
Int_t i = 0 ; i < size; ++i)
2039 const TString & vname = vars[i];
2051 Int_t multiplier = 2;
2078 Error(
"SetName",
"The name \'%s\' is reserved as a TFormula variable name.\n" 2079 "\tThis function will not be renamed.",name);
2083 auto listOfFunctions =
gROOT->GetListOfFunctions();
2084 TObject* thisAsFunctionInList =
nullptr;
2086 if (listOfFunctions){
2087 thisAsFunctionInList = listOfFunctions->
FindObject(
this);
2088 if (thisAsFunctionInList) listOfFunctions->Remove(thisAsFunctionInList);
2091 if (thisAsFunctionInList) listOfFunctions->Add(thisAsFunctionInList);
2104 for(
Int_t i = 0; i < size; ++i)
2106 pair<TString,Double_t>
v = vars[i];
2109 fVars[v.first].fValue = v.second;
2114 Error(
"SetVariables",
"Variable %s is not defined.",v.first.Data());
2127 Error(
"GetVariable",
"Variable %s is not defined.",sname.
Data());
2130 return fVars.find(sname)->second.fValue;
2140 Error(
"GetVarNumber",
"Variable %s is not defined.",sname.
Data());
2143 return fVars.find(sname)->second.fArrayPos;
2152 if (ivar < 0 || ivar >=
fNdim)
return "";
2155 for (
auto &
v :
fVars) {
2156 if (
v.second.fArrayPos == ivar)
return v.first;
2158 Error(
"GetVarName",
"Variable with index %d not found !!",ivar);
2170 Error(
"SetVariable",
"Variable %s is not defined.",name.
Data());
2214 auto ret =
fParams.insert(std::make_pair(name,pos));
2220 if (ret.first ==
fParams.begin() )
2223 auto previous = (ret.first);
2225 pos = previous->second + 1;
2243 for (
auto it = ret.first; it !=
fParams.end(); ++it ) {
2251 if (processFormula) {
2278 Error(
"GetParameter",
"Parameter %s is not defined.",name);
2293 Error(
"GetParameter",
"wrong index used - use GetParameter(name)");
2301 if (ipar < 0 || ipar >=
fNpar)
return "";
2305 if (p.second == ipar)
return p.first.Data();
2307 Error(
"GetParName",
"Parameter with index %d not found !!",ipar);
2341 Error(
"SetParameter",
"Parameter %s is not defined.",name.Data());
2348 for(map<TString,TFormulaVariable>::iterator it = fParams.begin(); it != fParams.end(); it++)
2350 if(!it->second.fFound)
2368 for(
Int_t i = 0 ; i < size ; ++i)
2370 pair<TString,Double_t> p = params[i];
2373 Error(
"SetParameters",
"Parameter %s is not defined",p.first.Data());
2376 fParams[p.first].fValue = p.second;
2377 fParams[p.first].fFound =
true;
2381 for(map<TString,TFormulaVariable>::iterator it =
fParams.begin(); it !=
fParams.end(); it++)
2383 if(!it->second.fFound)
2394 if(!params || size < 0 || size >
fNpar)
return;
2397 Warning(
"SetParameters",
"size is not same of cling parameter size %d - %d",size,
int(
fClingParameters.size()) );
2398 for(
Int_t i = 0; i < size; ++i)
2440 if (param < 0 || param >=
fNpar)
return;
2447 const char *name4,
const char *name5,
const char *name6,
const char *name7,
2448 const char *name8,
const char *name9,
const char *name10)
2465 if (ipar < 0 || ipar >
fNpar) {
2466 Error(
"SetParName",
"Wrong Parameter index %d ",ipar);
2472 if (it.second == ipar) {
2474 fParams.erase(oldName);
2475 fParams.insert(std::make_pair(name, ipar) );
2480 Error(
"SetParName",
"Parameter %d is not existing.",ipar);
2491 if (!formula.
IsNull() ) {
2493 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2495 if(oldName == it->GetName())
2504 Error(
"SetParName",
"Parameter %s is not defined.",oldName.
Data());
2520 return DoEval(x, params);
2527 double xxx[4] = {
x,
y,
z,t};
2535 double xxx[3] = {
x,
y,z};
2543 double xxx[2] = {
x,y};
2566 Error(
"Eval",
"Formula is invalid and not ready to execute ");
2567 for(
auto it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2572 printf(
"%s is unknown.\n",fun.
GetName());
2578 std::function<double(double *, double *)> & fptr = * ( (std::function<double(double *, double *)> *)
fLambdaPtr);
2581 double *
v =
const_cast<double*
>(
x);
2582 double * p = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2587 Error(
"Eval",
"Formula is invalid or not properly initialized - try calling TFormula::Compile");
2589 #ifdef EVAL_IS_NOT_CONST 2600 double * vars = (
x) ? const_cast<double*>(x) :
const_cast<double*
>(
fClingVariables.data());
2603 (*fFuncPtr)(0, 1, args, &
result);
2605 double * pars = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2607 (*fFuncPtr)(0, 2, args, &
result);
2631 std::size_t found = clingFunc.find(
"return");
2632 std::size_t found2 = clingFunc.rfind(
";");
2633 if (found == std::string::npos || found2 == std::string::npos) {
2634 Error(
"GetExpFormula",
"Invalid Cling expression - return default formula expression");
2639 if (!opt.
Contains(
"P"))
return clingFormula;
2642 while (i < clingFormula.
Length()-2 ) {
2644 if (clingFormula[i] ==
'p' && clingFormula[i+1] ==
'[' && isdigit(clingFormula[i+2]) ) {
2646 while ( isdigit(clingFormula[j]) ) { j++;}
2647 if (clingFormula[j] !=
']') {
2648 Error(
"GetExpFormula",
"Parameters not found - invalid expression - return default cling formula");
2649 return clingFormula;
2651 TString parNumbName = clingFormula(i+2,j-i-2);
2652 int parNumber = parNumbName.
Atoi();
2653 assert(parNumber <
fNpar);
2655 clingFormula.
Replace(i,j-i+1, replacement );
2656 i += replacement.
Length();
2660 return clingFormula;
2666 while (i < expFormula.
Length()-2 ) {
2668 if (expFormula[i] ==
'[') {
2670 while ( expFormula[j] !=
']' ) { j++;}
2671 if (expFormula[j] !=
']') {
2672 Error(
"GetExpFormula",
"Parameter names not found - invalid expression - return default formula");
2675 TString parName = expFormula(i+1,j-i-1);
2677 expFormula.
Replace(i,j-i+1, replacement );
2678 i += replacement.
Length();
2684 Warning(
"GetExpFormula",
"Invalid option - return defult formula expression");
2693 printf(
" Formula expression: \n");
2700 if (opt.Contains(
"V") ) {
2702 printf(
"List of Variables: \n");
2704 for (
int ivar = 0; ivar <
fNdim ; ++ivar) {
2709 printf(
"List of Parameters: \n");
2714 for (
int ipar = 0; ipar <
fNpar ; ++ipar) {
2718 printf(
"Expression passed to Cling:\n");
2723 Warning(
"Print",
"Formula is not ready to execute. Missing parameters/variables");
2724 for(list<TFormulaFunction>::const_iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2729 printf(
"%s is unknown.\n",fun.
GetName());
2753 void TFormula::Streamer(
TBuffer &
b)
2759 if (v <= 8 && v > 3 && v != 6) {
2772 Error(
"Streamer",
"Old formula read from file is NOT valid");
2818 if (
fNpar != (
int) parValues.size() ) {
2819 Error(
"Streamer",
"number of parameters computed (%d) is not same as the stored parameters (%d)",
fNpar,
int(parValues.size()) );
2831 assert(
fNpar == (
int) parValues.size() );
2834 if (
fParams.size() != paramMap.size() ) {
2835 Warning(
"Streamer",
"number of parameters list found (%zu) is not same as the stored one (%zu) - use re-created list",
fParams.size(),paramMap.size()) ;
2853 gROOT->GetListOfFunctions()->Add(
this);
2856 Error(
"Streamer",
"Formula read from file is NOT ready to execute");
2864 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)
TString & ReplaceAll(const TString &s1, const TString &s2)
Int_t GetNargs() const
Number of function arguments.
virtual void SetName(const char *name)
Set the name of the TNamed.
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.
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.
#define R__LOCKGUARD2(mutex)
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
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.
you should not use this method at all Int_t Int_t z
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.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
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.
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
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.