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)
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);
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 );
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 map<TString,Int_t> functionsNumbers;
924 functionsNumbers[
"gaus"] = 100;
925 functionsNumbers[
"landau"] = 400;
926 functionsNumbers[
"expo"] = 200;
927 functionsNumbers[
"crystalball"] = 500;
934 for(map<pair<TString,Int_t>,pair<TString,TString> >::iterator it = functions.begin(); it != functions.end(); ++it)
937 TString funName = it->first.first;
943 while(funPos !=
kNPOS)
950 Int_t iposBefore = funPos - 1;
952 if (iposBefore >= 0) {
954 if (isalpha(formula[iposBefore] ) ) {
960 Bool_t isNormalized =
false;
961 if (lastFunPos < formula.
Length() ) {
963 isNormalized = (formula[lastFunPos] ==
'n');
964 if (isNormalized) lastFunPos += 1;
965 if (lastFunPos < formula.
Length() ) {
967 if (isalnum(formula[lastFunPos] ) )
break;
968 if (formula[lastFunPos] !=
'[' && formula[lastFunPos] !=
'(' && !
IsOperator(formula[lastFunPos] ) ) {
969 funPos = formula.
Index(funName,lastFunPos);
982 Bool_t defaultVariable =
false;
985 Int_t openingBracketPos = funPos + funName.
Length() + (isNormalized ? 1 : 0);
987 if(openingBracketPos > formula.
Length() || formula[openingBracketPos] !=
'[')
990 variables.resize(dim);
992 defaultVariable =
true;
997 closingBracketPos = formula.
Index(
']',openingBracketPos);
998 varList = formula(openingBracketPos+1,closingBracketPos - openingBracketPos - 1);
1000 variables.resize(dim);
1007 varName.
Append(varList[i]);
1009 if(varList[i] ==
',')
1011 variables[Nvar] = varName;
1018 variables[Nvar] = varName;
1022 if(dim != it->first.second)
1024 pair<TString,Int_t> key = make_pair(funName,dim);
1025 if(functions.find(key) == functions.end())
1027 Error(
"PreProcessFormula",
"%d dimension function %s is not defined as parametrized function.",dim,funName.
Data());
1034 Int_t openingParenthesisPos = (closingBracketPos ==
kNPOS) ? openingBracketPos : closingBracketPos + 1;
1035 bool defaultCounter = (openingParenthesisPos > formula.
Length() || formula[openingParenthesisPos] !=
'(');
1046 counter =
TString(formula(openingParenthesisPos+1,formula.
Index(
')',funPos) - openingParenthesisPos -1)).
Atoi();
1050 TString body = (isNormalized ? it->second.second : it->second.first);
1051 if(isNormalized && body ==
"")
1053 Error(
"PreprocessFormula",
"%d dimension function %s has no normalized form.",it->first.second,funName.
Data());
1056 for(
int i = 0 ; i < body.
Length() ; ++i)
1063 TString variable = variables[num];
1067 i += variable.
Length()-1;
1069 else if(body[i] ==
'[')
1073 while(tmp < body.
Length() && body[tmp] !=
']')
1081 body.
Replace(i+1,tmp - 1 - i,replacement,replacement.
Length());
1082 i += replacement.
Length() + 1;
1086 if(defaultCounter && defaultVariable)
1090 (isNormalized ?
"n" :
""));
1092 if(!defaultCounter && defaultVariable)
1096 (isNormalized ?
"n" :
""),
1099 if(defaultCounter && !defaultVariable)
1103 (isNormalized ?
"n":
""),
1106 if(!defaultCounter && !defaultVariable)
1110 (isNormalized ?
"n" :
""),
1118 fNumber = functionsNumbers[funName] + 10*(dim-1);
1121 formula.
Replace(funPos,pattern.
Length(),replacement,replacement.Length());
1123 funPos = formula.
Index(funName);
1137 while(caretPos !=
kNPOS)
1141 Int_t temp = caretPos;
1144 if(formula[temp] ==
')')
1148 while(depth != 0 && temp > 0)
1150 if(formula[temp] ==
')')
1152 if(formula[temp] ==
'(')
1156 if (depth == 0) temp++;
1167 Int_t leftPos = temp+1;
1168 left = formula(leftPos, caretPos - leftPos);
1174 if (temp >= formula.
Length() ) {
1175 Error(
"HandleExponentiation",
"Invalid position of operator ^");
1178 if(formula[temp] ==
'(')
1182 while(depth != 0 && temp < formula.
Length())
1184 if(formula[temp] ==
')')
1186 if(formula[temp] ==
'(')
1194 if (formula[temp] ==
'-' || formula[temp] ==
'+' ) temp++;
1199 while(temp < formula.
Length() && ( (depth > 0) || !
IsOperator(formula[temp]) ) )
1205 if (temp < formula.
Length() && formula[temp] ==
'(') depth++;
1206 if (temp < formula.
Length() && formula[temp] ==
')') {
1214 right = formula(caretPos + 1, (temp - 1) - caretPos );
1222 formula.
Replace(leftPos,pattern.
Length(),replacement,replacement.Length());
1224 caretPos = formula.
Last(
'^');
1233 if (linPos ==
kNPOS )
return;
1239 while(linPos !=
kNPOS)
1247 while(temp >= 0 && formula[temp] !=
'@')
1251 left = formula(temp+1,linPos - (temp +1));
1254 while(temp < formula.
Length() && formula[temp] !=
'@')
1258 TString right = formula(linPos+1,temp - (linPos+1));
1262 Nlinear += (first) ? 2 : 1;
1272 linPos = formula.
Index(
"@");
1350 if(formula[i] ==
'[')
1355 while(formula[i] !=
']' && i < formula.
Length())
1357 param.
Append(formula[i++]);
1366 formula.
Replace(tmp,i - tmp, replacement,replacement.
Length());
1372 if (formula[i] ==
'\"') {
1376 }
while(formula[i] !=
'\"');
1394 if(isalpha(formula[i]) && !
IsOperator(formula[i]))
1401 if (formula[i] ==
':' && ( (i+1) < formula.
Length() ) ) {
1402 if ( formula[i+1] ==
':' ) {
1412 name.
Append(formula[i++]);
1415 if(formula[i] ==
'(')
1418 if(formula[i] ==
')')
1426 while(depth != 0 && i < formula.
Length())
1430 case '(': depth++;
break;
1431 case ')': depth--;
break;
1432 case ',':
if(depth == 1) args++;
break;
1436 body.
Append(formula[i++]);
1441 formula.
Replace(i-originalBodyLen,originalBodyLen,body,body.
Length());
1442 i += body.
Length() - originalBodyLen;
1454 obj =
gROOT->GetListOfFunctions()->FindObject(name);
1459 TF1 *
f1 =
dynamic_cast<TF1*
> (obj);
1474 std::vector<TString> newNames;
1477 newNames.resize(f->
GetNpar() );
1479 for (
int jpar = f->
GetNpar()-1; jpar >= 0; --jpar ) {
1486 replacementFormula.
ReplaceAll(oldName,newName);
1487 newNames[jpar] = newName;
1498 for (
int jpar = 0; jpar < f->
GetNpar(); ++jpar) {
1499 if (nparOffset> 0) {
1509 replacementFormula.
Insert(0,
'(');
1510 replacementFormula.
Insert(replacementFormula.
Length(),
')');
1557 for(list<TFormulaFunction>::iterator funcsIt =
fFuncs.begin(); funcsIt !=
fFuncs.end(); ++funcsIt)
1575 while ( index !=
kNPOS) {
1579 if ( (index > 0) && (isalpha( formula[index-1] ) || formula[index-1] ==
':' )) {
1580 index = formula.
Index(shortcut,i2);
1583 if (i2 < formula.
Length() && formula[i2] !=
'(') {
1584 index = formula.
Index(shortcut,i2);
1590 index = formula.
Index(shortcut,inext);
1598 size_t index = name.rfind(
"::");
1599 assert(index != std::string::npos);
1607 TIter next(methodList);
1609 while ((p = (
TMethod*) next()))
1611 if (strcmp(p->
GetName(),functionName.
Data()) == 0 &&
1638 Info(
"TFormula",
"Could not find %s function with %d argument(s)",fun.
GetName(),fun.
GetNargs());
1663 map<TString,TFormulaVariable>::iterator varsIt =
fVars.find(fun.
GetName());
1664 if(varsIt!=
fVars.end())
1672 if(!
fVars[name].fFound)
1677 int varDim = (*varsIt).second.fArrayPos;
1678 if (varDim >=
fNdim) {
1683 if (
v.second.fArrayPos < varDim && !
v.second.fFound ) {
1685 v.second.fFound =
true;
1706 int digit = sdigit.
Atoi();
1707 if (digit >=
fNdim) {
1710 for (
int j = 0; j <
fNdim; ++j) {
1714 fVars[vname].fFound =
true;
1750 map<TString,Double_t>::iterator constIt =
fConsts.find(fun.
GetName());
1778 if (hasParameters && ! hasVariables) {
1781 hasVariables =
true;
1783 Bool_t hasBoth = hasVariables && hasParameters;
1785 if (inputIntoCling) {
1789 std::string inputFormula = std::string(formula);
1794 TString::Format(
"%s%s%s",(hasVariables ?
"Double_t *x" :
""), (hasBoth ?
"," :
""),
1795 (hasParameters ?
"Double_t *p" :
""));
1809 inputIntoCling =
false;
1828 if(inputIntoCling) {
1849 Bool_t allFunctorsMatched =
true;
1850 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); it++)
1854 allFunctorsMatched =
false;
1855 if (it->GetNargs() == 0)
1856 Error(
"ProcessFormula",
"\"%s\" has not been matched in the formula expression",it->GetName() );
1858 Error(
"ProcessFormula",
"Could not find %s function with %d argument(s)",it->GetName(),it->GetNargs());
1861 if (!allFunctorsMatched) {
1869 auto itvar =
fVars.begin();
1872 if ( ! itvar->second.fFound ) {
1874 itvar =
fVars.erase(itvar);
1879 while( itvar !=
fVars.end() );
1949 if (i < 0 || i >= n ) {
1950 Error(
"GetLinearPart",
"Formula %s has only %d linear parts - requested %d",
GetName(),n,i);
2002 Bool_t anyNewVar =
false;
2003 for(
Int_t i = 0 ; i < size; ++i)
2006 const TString & vname = vars[i];
2018 Int_t multiplier = 2;
2045 Error(
"SetName",
"The name \'%s\' is reserved as a TFormula variable name.\n" 2046 "\tThis function will not be renamed.",name);
2050 auto listOfFunctions =
gROOT->GetListOfFunctions();
2051 TObject* thisAsFunctionInList =
nullptr;
2053 if (listOfFunctions){
2054 thisAsFunctionInList = listOfFunctions->
FindObject(
this);
2055 if (thisAsFunctionInList) listOfFunctions->Remove(thisAsFunctionInList);
2058 if (thisAsFunctionInList) listOfFunctions->Add(thisAsFunctionInList);
2071 for(
Int_t i = 0; i < size; ++i)
2073 pair<TString,Double_t>
v = vars[i];
2076 fVars[v.first].fValue = v.second;
2081 Error(
"SetVariables",
"Variable %s is not defined.",v.first.Data());
2094 Error(
"GetVariable",
"Variable %s is not defined.",sname.
Data());
2097 return fVars.find(sname)->second.fValue;
2107 Error(
"GetVarNumber",
"Variable %s is not defined.",sname.
Data());
2110 return fVars.find(sname)->second.fArrayPos;
2119 if (ivar < 0 || ivar >=
fNdim)
return "";
2122 for (
auto &
v :
fVars) {
2123 if (
v.second.fArrayPos == ivar)
return v.first;
2125 Error(
"GetVarName",
"Variable with index %d not found !!",ivar);
2137 Error(
"SetVariable",
"Variable %s is not defined.",name.
Data());
2181 auto ret =
fParams.insert(std::make_pair(name,pos));
2187 if (ret.first ==
fParams.begin() )
2190 auto previous = (ret.first);
2192 pos = previous->second + 1;
2210 for (
auto it = ret.first; it !=
fParams.end(); ++it ) {
2218 if (processFormula) {
2245 Error(
"GetParameter",
"Parameter %s is not defined.",name);
2260 Error(
"GetParameter",
"wrong index used - use GetParameter(name)");
2268 if (ipar < 0 || ipar >=
fNpar)
return "";
2272 if (p.second == ipar)
return p.first.Data();
2274 Error(
"GetParName",
"Parameter with index %d not found !!",ipar);
2308 Error(
"SetParameter",
"Parameter %s is not defined.",name.Data());
2315 for(map<TString,TFormulaVariable>::iterator it = fParams.begin(); it != fParams.end(); it++)
2317 if(!it->second.fFound)
2335 for(
Int_t i = 0 ; i < size ; ++i)
2337 pair<TString,Double_t> p = params[i];
2340 Error(
"SetParameters",
"Parameter %s is not defined",p.first.Data());
2343 fParams[p.first].fValue = p.second;
2344 fParams[p.first].fFound =
true;
2348 for(map<TString,TFormulaVariable>::iterator it =
fParams.begin(); it !=
fParams.end(); it++)
2350 if(!it->second.fFound)
2361 if(!params || size < 0 || size >
fNpar)
return;
2364 Warning(
"SetParameters",
"size is not same of cling parameter size %d - %d",size,
int(
fClingParameters.size()) );
2365 for(
Int_t i = 0; i < size; ++i)
2407 if (param < 0 || param >=
fNpar)
return;
2414 const char *name4,
const char *name5,
const char *name6,
const char *name7,
2415 const char *name8,
const char *name9,
const char *name10)
2432 if (ipar < 0 || ipar >
fNpar) {
2433 Error(
"SetParName",
"Wrong Parameter index %d ",ipar);
2439 if (it.second == ipar) {
2441 fParams.erase(oldName);
2442 fParams.insert(std::make_pair(name, ipar) );
2447 Error(
"SetParName",
"Parameter %d is not existing.",ipar);
2458 if (!formula.
IsNull() ) {
2460 for(list<TFormulaFunction>::iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2462 if(oldName == it->GetName())
2471 Error(
"SetParName",
"Parameter %s is not defined.",oldName.
Data());
2487 return DoEval(x, params);
2494 double xxx[4] = {
x,
y,z,t};
2502 double xxx[3] = {
x,
y,z};
2510 double xxx[2] = {
x,y};
2533 Error(
"Eval",
"Formula is invalid and not ready to execute ");
2534 for(
auto it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2539 printf(
"%s is unknown.\n",fun.
GetName());
2545 std::function<double(double *, double *)> & fptr = * ( (std::function<double(double *, double *)> *)
fLambdaPtr);
2548 double *
v =
const_cast<double*
>(
x);
2549 double * p = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2554 Error(
"Eval",
"Formula is invalid or not properly initialized - try calling TFormula::Compile");
2556 #ifdef EVAL_IS_NOT_CONST 2567 double * vars = (
x) ? const_cast<double*>(x) :
const_cast<double*
>(
fClingVariables.data());
2570 (*fFuncPtr)(0, 1, args, &
result);
2572 double * pars = (params) ? const_cast<double*>(params) :
const_cast<double*
>(
fClingParameters.data());
2574 (*fFuncPtr)(0, 2, args, &
result);
2598 std::size_t found = clingFunc.find(
"return");
2599 std::size_t found2 = clingFunc.rfind(
";");
2600 if (found == std::string::npos || found2 == std::string::npos) {
2601 Error(
"GetExpFormula",
"Invalid Cling expression - return default formula expression");
2606 if (!opt.
Contains(
"P"))
return clingFormula;
2609 while (i < clingFormula.
Length()-2 ) {
2611 if (clingFormula[i] ==
'p' && clingFormula[i+1] ==
'[' && isdigit(clingFormula[i+2]) ) {
2613 while ( isdigit(clingFormula[j]) ) { j++;}
2614 if (clingFormula[j] !=
']') {
2615 Error(
"GetExpFormula",
"Parameters not found - invalid expression - return default cling formula");
2616 return clingFormula;
2618 TString parNumbName = clingFormula(i+2,j-i-2);
2619 int parNumber = parNumbName.
Atoi();
2622 clingFormula.
Replace(i,j-i+1, replacement );
2623 i += replacement.
Length();
2627 return clingFormula;
2633 while (i < expFormula.
Length()-2 ) {
2635 if (expFormula[i] ==
'[') {
2637 while ( expFormula[j] !=
']' ) { j++;}
2638 if (expFormula[j] !=
']') {
2639 Error(
"GetExpFormula",
"Parameter names not found - invalid expression - return default formula");
2642 TString parName = expFormula(i+1,j-i-1);
2644 expFormula.
Replace(i,j-i+1, replacement );
2645 i += replacement.
Length();
2651 Warning(
"GetExpFormula",
"Invalid option - return defult formula expression");
2660 printf(
" Formula expression: \n");
2667 if (opt.Contains(
"V") ) {
2669 printf(
"List of Variables: \n");
2671 for (
int ivar = 0; ivar <
fNdim ; ++ivar) {
2676 printf(
"List of Parameters: \n");
2681 for (
int ipar = 0; ipar <
fNpar ; ++ipar) {
2685 printf(
"Expression passed to Cling:\n");
2690 Warning(
"Print",
"Formula is not ready to execute. Missing parameters/variables");
2691 for(list<TFormulaFunction>::const_iterator it =
fFuncs.begin(); it !=
fFuncs.end(); ++it)
2696 printf(
"%s is unknown.\n",fun.
GetName());
2720 void TFormula::Streamer(
TBuffer &b)
2726 if (v <= 8 && v > 3 && v != 6) {
2739 Error(
"Streamer",
"Old formula read from file is NOT valid");
2785 if (
fNpar != (
int) parValues.size() ) {
2786 Error(
"Streamer",
"number of parameters computed (%d) is not same as the stored parameters (%d)",
fNpar,
int(parValues.size()) );
2801 if (
fParams.size() != paramMap.size() ) {
2802 Warning(
"Streamer",
"number of parameters list found (%lu) is not same as the stored one (%lu) - use re-created list",
fParams.size(),paramMap.size()) ;
2820 gROOT->GetListOfFunctions()->Add(
this);
2823 Error(
"Streamer",
"Formula read from file is NOT ready to execute");
2831 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)
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.
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.
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.