61#ifdef ROOFIT_LEGACY_EVAL_BACKEND
67using std::string, std::map, std::list, std::pair, std::endl, std::vector;
69#define BUFFER_SIZE 64000
130 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createFactory() ERROR: variable with name '" <<
name <<
"' already exists" << std::endl ;
157 const size_t tmpSize = strlen(stateNameList)+1;
158 std::vector<char> tmp(tmpSize);
159 strlcpy(tmp.data(),stateNameList,tmpSize) ;
161 char* tok = R__STRTOK_R(tmp.data(),
",",&save) ;
163 char* sep = strchr(tok,
'=') ;
166 Int_t id = atoi(sep+1) ;
172 tok = R__STRTOK_R(
nullptr,
",",&save) ;
185 bool isEnum(
const char* classname) {
187 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
194 bool isValidEnumValue(
const char* enumName,
const char* enumConstantName) {
197 if (!enumName)
return false;
200 if (!enumName)
return false;
203 if (theEnum->GetConstant(enumConstantName))
return true;
205 auto tmp = strstr(enumConstantName,
"::");
207 auto enumConstantNameNoScope = tmp+2;
208 if (theEnum->GetConstant(enumConstantNameNoScope))
return true;
214 pair<list<string>,
unsigned int> ctorArgsImpl(
const char* classname, std::size_t nPassedArgs) {
222 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
223 MethodInfo_t* func =
gInterpreter->MethodInfo_Factory(cls);
236 if (
string(classname) !=
gInterpreter->MethodInfo_TypeName(func)) {
242 int nDefaultArgs =
gInterpreter->MethodInfo_NDefaultArg(func);
243 if (nargs == nDefaultArgs) {
247 MethodArgInfo_t* arg =
gInterpreter->MethodArgInfo_Factory(func);
250 const char* argTypeName =
gInterpreter->MethodArgInfo_TypeName(arg);
251 if (nreq<2 && ((
string(
"char*") != argTypeName
253 &&
string(
"const char*") != argTypeName)) {
256 ret.push_back(argTypeName) ;
257 if(!
gInterpreter->MethodArgInfo_DefaultValue(arg)) nreq++;
264 if(
static_cast<int>(nPassedArgs) >= nargs - nDefaultArgs &&
static_cast<int>(nPassedArgs) <= nargs) {
270 return pair<list<string>,
unsigned int>(ret,nreq);
273 pair<list<string>,
unsigned int>
const & ctorArgs(
const char* classname, std::size_t nPassedArgs) {
280 static std::map<pair<string, std::size_t>, pair<list<string>,
unsigned int>> cache;
281 auto key = std::make_pair(
string(classname), nPassedArgs);
282 auto it = cache.find(key);
283 if (it == cache.end()) {
284 it = cache.emplace(std::move(key), ctorArgsImpl(classname, nPassedArgs)).first;
301 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" not found in factory alias table, nor in ROOT class table" << std::endl;
310 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" does not inherit from RooAbsArg" << std::endl;
319 size_t start_tok = 0;
320 bool litmode =
false;
321 for (end_tok = 0; end_tok < tmp.length(); end_tok++) {
323 if (tmp[end_tok]==
'{' || tmp[end_tok]==
'(' || tmp[end_tok]==
'[') blevel++;
324 if (tmp[end_tok]==
'}' || tmp[end_tok]==
')' || tmp[end_tok]==
']') blevel--;
327 if (tmp[end_tok]==
'"' || tmp[end_tok]==
'\'') litmode = !litmode;
332 if (litmode ==
false && blevel == 0 && tmp[end_tok] ==
',') {
333 _args.push_back(tmp.substr(start_tok, end_tok - start_tok));
334 start_tok = end_tok+1;
337 _args.push_back(tmp.substr(start_tok, end_tok));
340 pair<list<string>,
unsigned int>
const & ca = ctorArgs(className,
_args.size()+2) ;
341 if (ca.first.empty()) {
342 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR no suitable constructor found for class " << className << std::endl ;
349 if (
_args.size()+2<ca.second ||
_args.size()+2>ca.first.size()) {
350 if (ca.second==ca.first.size()) {
351 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR number of arguments provided (" <<
_args.size() <<
") for class is invalid, " << className
352 <<
" expects " << ca.first.size()-2 << std::endl ;
355 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR number of arguments provided (" <<
_args.size() <<
") for class is invalid " << className
356 <<
" expect number between " << ca.second-2 <<
" and " << ca.first.size()-2 << std::endl ;
363 string cintExpr(
Form(
"new %s(\"%s\",\"%s\"",className,objName,objName)) ;
371 list<string>::const_iterator ti = ca.first.begin() ; ++ti ; ++ti ;
373 if ((*ti)==
"RooAbsReal&" || (*ti)==
"const RooAbsReal&" || (*ti)==
"RooAbsReal::Ref") {
375 cintExpr +=
Form(
",RooFactoryWSTool::as_FUNC(%d)",i) ;
376 }
else if ((*ti)==
"RooAbsArg&" || (*ti)==
"const RooAbsArg&") {
378 cintExpr +=
Form(
",RooFactoryWSTool::as_ARG(%d)",i) ;
379 }
else if ((*ti)==
"RooRealVar&" || (*ti)==
"const RooRealVar&") {
381 cintExpr +=
Form(
",RooFactoryWSTool::as_VAR(%d)",i) ;
382 }
else if ((*ti)==
"RooAbsRealLValue&" || (*ti)==
"const RooAbsRealLValue&") {
384 cintExpr +=
Form(
",RooFactoryWSTool::as_VARLV(%d)",i) ;
385 }
else if ((*ti)==
"RooCategory&" || (*ti)==
"const RooCategory&") {
387 cintExpr +=
Form(
",RooFactoryWSTool::as_CAT(%d)",i) ;
388 }
else if ((*ti)==
"RooAbsCategory&" || (*ti)==
"const RooAbsCategory&") {
390 cintExpr +=
Form(
",RooFactoryWSTool::as_CATFUNC(%d)",i) ;
391 }
else if ((*ti)==
"RooAbsCategoryLValue&" || (*ti)==
"const RooAbsCategoryLValue&") {
393 cintExpr +=
Form(
",RooFactoryWSTool::as_CATLV(%d)",i) ;
394 }
else if ((*ti)==
"RooAbsPdf&" || (*ti)==
"const RooAbsPdf&") {
396 cintExpr +=
Form(
",RooFactoryWSTool::as_PDF(%d)",i) ;
397 }
else if ((*ti)==
"RooResolutionModel&" || (*ti)==
"const RooResolutionModel&") {
399 cintExpr +=
Form(
",RooFactoryWSTool::as_RMODEL(%d)",i) ;
400 }
else if ((*ti)==
"RooAbsData&" || (*ti)==
"const RooAbsData&") {
402 cintExpr +=
Form(
",RooFactoryWSTool::as_DATA(%d)",i) ;
403 }
else if ((*ti)==
"RooDataSet&" || (*ti)==
"const RooDataSet&") {
405 cintExpr +=
Form(
",RooFactoryWSTool::as_DSET(%d)",i) ;
406 }
else if ((*ti)==
"RooDataHist&" || (*ti)==
"const RooDataHist&") {
408 cintExpr +=
Form(
",RooFactoryWSTool::as_DHIST(%d)",i) ;
409 }
else if ((*ti)==
"const RooArgSet&") {
411 cintExpr +=
Form(
",RooFactoryWSTool::as_SET(%d)",i) ;
412 }
else if ((*ti)==
"const RooArgList&") {
414 cintExpr +=
Form(
",RooFactoryWSTool::as_LIST(%d)",i) ;
415 }
else if ((*ti)==
"const char*") {
417 cintExpr +=
Form(
",RooFactoryWSTool::as_STRING(%d)",i) ;
418 }
else if ((*ti)==
"Int_t" || (*ti)==
"int" || (*ti)==
"bool" || (*ti)==
"bool") {
420 cintExpr +=
Form(
",RooFactoryWSTool::as_INT(%d)",i) ;
421 }
else if ((*ti)==
"double") {
423 cintExpr +=
Form(
",RooFactoryWSTool::as_DOUBLE(%d)",i) ;
424 }
else if (isEnum(ti->c_str())) {
427 if (
_args[i].find(
Form(
"%s::",className)) != string::npos) {
428 qualvalue =
_args[i] ;
430 qualvalue =
Form(
"%s::%s",className,
_args[i].c_str()) ;
432 if (isValidEnumValue(ti->c_str(),qualvalue.c_str())) {
433 cintExpr +=
Form(
",(%s)%s",ti->c_str(),qualvalue.c_str()) ;
435 throw string(
Form(
"Supplied argument %s does not represent a valid state of enum %s",
_args[i].c_str(),ti->c_str())) ;
443 if (ti->find(
"const ")==0) {
444 btype = ti->c_str()+6 ;
448 if (btype.find(
'&')) {
449 btype.erase(btype.size()-1,btype.size()) ;
456 cintExpr +=
Form(
",(%s&)RooFactoryWSTool::as_OBJ(%d)",ti->c_str(),i) ;
458 throw string(
Form(
"Required argument with name %s of type '%s' is not in the workspace",
_args[i].c_str(),ti->c_str())) ;
463 }
catch (
const string &err) {
464 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR constructing " << className <<
"::" << objName <<
": " << err << std::endl ;
469 cxcoutD(
ObjectHandling) <<
"RooFactoryWSTool::createArg() Construct expression is " << cintExpr << std::endl ;
472 if (std::unique_ptr<RooAbsArg> arg{
reinterpret_cast<RooAbsArg*
>(
gROOT->ProcessLineFast(cintExpr.c_str()))}) {
473 if (
string(className)==
"RooGenericPdf") {
474 arg->setStringAttribute(
"factory_tag",
Form(
"EXPR::%s(%s)",objName,varList)) ;
475 }
else if (
string(className)==
"RooFormulaVar") {
476 arg->setStringAttribute(
"factory_tag",
Form(
"expr::%s(%s)",objName,varList)) ;
478 arg->setStringAttribute(
"factory_tag",
Form(
"%s::%s(%s)",className,objName,varList)) ;
484 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR in Cling constructor call to create object" << std::endl ;
505 char* tok = R__STRTOK_R(buf,
",",&save) ;
507 char* star=strchr(tok,
'*') ;
515 tok = R__STRTOK_R(
nullptr,
",",&save) ;
517 pdfList.
add(pdfList2) ;
519 }
catch (
const string &err) {
520 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooAddPdf: " << err << std::endl ;
525 RooAddPdf pdf{objName,objName,pdfList,coefList,recursiveCoefs};
547 char* tok = R__STRTOK_R(buf,
",",&save) ;
549 char* star=strchr(tok,
'*') ;
557 tok = R__STRTOK_R(
nullptr,
",",&save) ;
559 amplList.
add(amplList2) ;
561 }
catch (
const string &err) {
562 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooRealSumPdf: " << err << std::endl ;
582 string regPdfList=
"{" ;
586 char* tok = R__STRTOK_R(buf,
",",&save) ;
588 char *sep = strchr(tok,
'|') ;
595 bool invCond(
false) ;
603 }
catch (
const string &err) {
604 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf Conditional argument: " << err << std::endl ;
611 if (regPdfList.size()>1) {
616 tok = R__STRTOK_R(
nullptr,
",",&save) ;
620 std::unique_ptr<RooProdPdf> pdf;
622 pdf = std::make_unique<RooProdPdf>(objName,objName,
asSET(regPdfList.c_str()),cmdList);
623 }
catch (
const string &err) {
624 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf input set of regular pdfs: " << err << std::endl ;
630 pdf->setStringAttribute(
"factory_tag",
Form(
"PROD::%s(%s)",objName,pdfList)) ;
644 map<string,RooAbsPdf*> theMap ;
649 char* tok = R__STRTOK_R(buf,
",",&save) ;
651 char* eq = strchr(tok,
'=') ;
653 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName
654 <<
" expect mapping token of form 'state=pdfName', but found '" << tok <<
"'" << std::endl ;
661 theMap[tok] = &
asPDF(eq+1) ;
662 }
catch (
const string &err ) {
663 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous: " << err << std::endl ;
667 tok = R__STRTOK_R(
nullptr,
",",&save) ;
672 std::unique_ptr<RooSimultaneous> pdf;
674 pdf = std::make_unique<RooSimultaneous>(objName,objName,theMap,
asCATLV(indexCat)) ;
675 }
catch (
const string &err) {
676 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName <<
" " << err << std::endl ;
682 pdf->setStringAttribute(
"factory_tag",
Form(
"SIMUL::%s(%s,%s)",objName,indexCat,pdfMap)) ;
702 char* tok = R__STRTOK_R(buf,
",",&save) ;
704 char* star=strchr(tok,
'*') ;
712 tok = R__STRTOK_R(
nullptr,
",",&save) ;
715 }
catch (
const string &err) {
716 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: " << err << std::endl ;
721 if (!sumlist2.
empty() && (sumlist1.
size()!=sumlist2.
size())) {
722 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: syntax error: either all sum terms must be products or none" << std::endl ;
728 auto sum = sumlist2.
empty() ? std::make_unique<RooAddition>(objName,objName,sumlist1)
729 : std::make_unique<RooAddition>(objName,objName,sumlist1,sumlist2);
731 sum->setStringAttribute(
"factory_tag",
Form(
"sum::%s(%s)",objName,specList)) ;
848 std::vector<char> buf(strlen(expr)+1);
851 char* buftmp = buf.data();
853 if (!isspace(*expr)) {
870 }
catch (
const string &error) {
871 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERROR in parsing: " << error << std::endl ;
877 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed" << std::endl ;
883 return !out.empty() ?
ws().
arg(out) : nullptr ;
902 if (
string(token).find(
"$Alias(")==0) {
928 const size_t bufBaseSize = strlen(token)+1;
929 std::vector<char> buf_base(bufBaseSize);
930 char* buf = buf_base.data();
931 strlcpy(buf,token,bufBaseSize) ;
934 list<string> singleExpr ;
935 list<char> separator ;
937 bool litmode(
false) ;
941 if (*p==
'{' || *p==
'(' || *p==
'[') blevel++ ;
942 if (*p==
'}' || *p==
')' || *p==
']') blevel-- ;
945 if (*p==
'"' || *p==
'\'') litmode = !litmode ;
949 if (!litmode && blevel==0 && ( (*p)==
'=' || (*p) ==
'|' || (*p) ==
'*')) {
950 separator.push_back(*p) ;
952 singleExpr.push_back(buf) ;
958 singleExpr.push_back(buf) ;
960 if (singleExpr.size()==1) {
966 list<char>::iterator ic = separator.begin() ;
967 for (list<string>::iterator ii = singleExpr.begin() ; ii!=singleExpr.end() ; ++ii) {
969 if (ic != separator.end()) {
991 if (strlen(arg)==0) {
996 if (arg[0]==
'\'' || arg[0]==
'"') {
1001 const size_t bufSize = strlen(arg)+1;
1002 std::vector<char> buf(bufSize);
1003 strlcpy(buf.data(),arg,bufSize) ;
1004 char* bufptr = buf.data();
1008 vector<string> args ;
1012 char* tmpx = R__STRTOK_R(buf.data(),
"([",&save) ;
1013 func = tmpx ? tmpx :
"" ;
1014 char* p = R__STRTOK_R(
nullptr,
"",&save) ;
1024 bool litmode(
false) ;
1028 if (*p==
'{' || *p==
'(' || *p==
'[') blevel++ ;
1029 if (*p==
'}' || *p==
')' || *p==
']') blevel-- ;
1032 if (*p==
'"' || *p==
'\'') litmode = !litmode ;
1038 if (!litmode && blevel==0 && ((*p)==
',')) {
1040 args.push_back(tok) ;
1049 if (p>bufptr && (*(p-1)==
')'||*(p-1)==
']')) {
1058 p = R__STRTOK_R(
nullptr,
"",&save) ;
1060 args.push_back(tmp) ;
1068 for(
const char* pp=arg ; *pp!=0 ; pp++) {
1069 if (*pp==
'(' || *pp==
'[' || *pp==
'{') {
1075 if (strstr(func.c_str(),
"::")) {
1080 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: Class::Instance must be followed by (...)" << std::endl ;
1083 }
else if (func[0]!=
'$'){
1087 }
else if (lb==
'(') {
1097 static Int_t globCounter = 0 ;
1099 autoname =
Form(
"gobj%d",globCounter) ;
1101 if (!
ws().arg(autoname)) {
1105 autoname =
Form(
"%s::%s",func.c_str(),autoname.c_str()) ;
1109 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: expect either Class(...) or Instance[...]" << std::endl ;
1117 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: $MetaClass must be followed by (...)" << std::endl ;
1137 const size_t bufSize = strlen(arg)+1;
1138 std::vector<char> buf(bufSize);
1139 strlcpy(buf.data(),arg,bufSize) ;
1141 std::vector<string> args ;
1144 char* tok = buf.data()+1 ;
1145 char* p = buf.data()+1 ;
1152 if (*p==
'{' || *p==
'(' || *p==
'[') level++ ;
1153 if (*p==
'}' || *p==
')' || *p==
']') level-- ;
1159 if (level==0 && ((*p)==
',')) {
1161 args.push_back(tok) ;
1169 if (p>buf.data() && *(p-1)==
'}') {
1172 args.push_back(tok) ;
1179 while(iter!= args.end()) {
1180 if (strlen(ret.c_str())>1) ret +=
"," ;
1204 if (args.size()!=2) {
1205 coutE(
ObjectHandling) <<
"RooFactorWSTool::processAliasExpression() ERROR $Alias() takes exactly two arguments, " << args.size() <<
" args found" << std::endl ;
1229 className = item->second.c_str() ;
1242 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " << className <<
" not defined in ROOT class table" << std::endl ;
1260 if (iter!=args.begin()) {
1286 string first = *(args.begin());
1287 bool isNumeric = isdigit(first[0]) || first[0] ==
'.' || first[0] ==
'+' || first[0] ==
'-';
1292 for (
auto const &ai : args) {
1293 if (!allStates.empty()) {
1302 std::unique_ptr<RooRealVar> tmp;
1304 if (args.size() == 1) {
1306 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit);
1308 }
else if (args.size() == 2) {
1311 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xlo, xhi);
1313 }
else if (args.size() == 3) {
1317 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit, xlo, xhi);
1321 tmp->setStringAttribute(
"factory_tag",
varTag(func, args).c_str());
1346 const char *className = R__STRTOK_R(buf,
":",&save) ;
1347 const char *instName = R__STRTOK_R(
nullptr,
":",&save) ;
1348 if (!className) className =
"";
1349 if (!instName) instName =
"" ;
1355 vector<string> pargv ;
1357 while(iter!=args.end()) {
1358 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1363 pargv.push_back(tmp) ;
1371 if (
hooks().find(className) !=
hooks().end()) {
1373 return iface->
create(*
this, className,instName,pargv) ;
1378 return string(instName) ;
1391 vector<string> pargv ;
1392 while(iter!=args.end()) {
1393 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1396 pargv.push_back(tmp) ;
1400 string ret = func+
"("+pargs+
")" ;
1412 const size_t bufSize = strlen(funcExpr)+1;
1413 std::vector<char> buf(bufSize);
1414 strlcpy(buf.data(),funcExpr,bufSize) ;
1415 char* bufptr = buf.data();
1418 vector<string> args ;
1422 char* tmpx = R__STRTOK_R(buf.data(),
"(",&save) ;
1423 func = tmpx ? tmpx :
"" ;
1424 char* p = R__STRTOK_R(
nullptr,
"",&save) ;
1433 bool litmode(
false) ;
1437 if (*p==
'{' || *p==
'(' || *p==
'[') blevel++ ;
1438 if (*p==
'}' || *p==
')' || *p==
']') blevel-- ;
1441 if (*p==
'"' || *p==
'\'') litmode = !litmode ;
1447 if (!litmode && blevel==0 && ((*p)==
',')) {
1449 args.push_back(tok) ;
1458 if (p>bufptr && *(p-1)==
')') {
1467 p = R__STRTOK_R(
nullptr,
"",&save) ;
1469 args.push_back(tmp) ;
1485 Int_t nParentheses(0);
1488 const char* ptr = arg ;
1490 if (*ptr==
'(') nParentheses++ ;
1491 if (*ptr==
')') nParentheses-- ;
1492 if (*ptr==
'[') nBracket++ ;
1493 if (*ptr==
']') nBracket-- ;
1494 if (*ptr==
'{') nAccolade++ ;
1495 if (*ptr==
'}') nAccolade-- ;
1498 if (nParentheses!=0) {
1499 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nParentheses>0?
"(":
")") <<
"' in expression" << std::endl ;
1503 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nBracket>0?
"[":
"]") <<
"' in expression" << std::endl ;
1507 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nAccolade>0?
"{":
"}") <<
"' in expression" << std::endl ;
1519 if (idx>
_of->_args.size()-1) {
1520 throw string(
Form(
"Need argument number %d, but only %d args are provided",idx,(
Int_t)
_of->_args.size())) ;
1532 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1539 throw string(
Form(
"RooAbsArg named %s not found",arg)) ;
1552 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1558 throw string(
Form(
"RooAbsReal named %s not found",arg)) ;
1562 throw string(
Form(
"Object named %s is not of type RooAbsReal",arg)) ;
1575 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1576 throw string(
Form(
"Numeric literal provided for argument (%s), but lvalue is required",arg)) ;
1581 throw string(
Form(
"RooAbsRealLValue named %s not found",arg)) ;
1585 throw string(
Form(
"Object named %s is not of type RooAbsRealLValue",arg)) ;
1599 throw string(
Form(
"RooRealVar named %s not found",arg)) ;
1614 throw string(
Form(
"RooAbsPdf named %s not found",arg)) ;
1629 throw string(
Form(
"RooResolutionModel named %s not found",arg)) ;
1633 throw string(
Form(
"Object named %s is not of type RooResolutionModel",arg)) ;
1648 throw string(
Form(
"RooAbsCategory named %s not found",arg)) ;
1652 throw string(
Form(
"Object named %s is not of type RooAbsCategory",arg)) ;
1666 throw string(
Form(
"RooAbsCategoryLValue named %s not found",arg)) ;
1671 throw string(
Form(
"Object named %s is not of type RooAbsCategoryLValue",arg)) ;
1685 throw string(
Form(
"RooCategory named %s not found",arg)) ;
1716 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1721 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1723 }
else if (tok[0] ==
'\'') {
1724 tok[strlen(tok) - 1] = 0;
1732 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1735 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1753 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1757 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1759 }
else if (tok[0] ==
'\'') {
1760 tok[strlen(tok) - 1] = 0;
1768 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1771 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1786 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1800 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1804 throw string(
Form(
"Dataset named %s is not of type RooDataHist",arg)) ;
1817 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1821 throw string(
Form(
"Dataset named %s is not of type RooDataSet",arg)) ;
1834 throw string(
Form(
"Object named %s not found",arg)) ;
1846 static vector<string> cbuf(10) ;
1847 static unsigned int cbuf_idx = 0 ;
1850 if (arg==
nullptr || strlen(arg)==0) {
1856 cbuf[cbuf_idx].clear() ;
1857 const char* p = arg+1 ;
1858 while(*p && (*p) !=
'"' && (*p) !=
'\'' ) {
1859 cbuf[cbuf_idx] += *(p++) ;
1861 const char* ret = cbuf[cbuf_idx].c_str() ;
1865 if (cbuf_idx==cbuf.size()) cbuf_idx=0 ;
1894 hooks()[typeName] = iface ;
1904 _hooks =
new map<string,IFace*> ;
1918 vector<string> pargv ;
1919 while(iter!=args.end()) {
1920 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1923 pargv.push_back(tmp) ;
1928 string cl(typeName) ;
1932 ft.
add(instName,pargs,
false) ;
1934 }
else if (cl==
"RSUM") {
1937 ft.
add(instName,pargs,
true) ;
1939 }
else if (cl==
"ASUM") {
1944 }
else if (cl==
"PROD") {
1947 ft.
prod(instName,pargs) ;
1949 }
else if (cl==
"SIMUL") {
1952 if (pargv.size()>1) {
1953 ft.
simul(instName,pargv[0].c_str(),strchr(pargs,
',')+1) ;
1955 throw string(
Form(
"Need at least two arguments in call to SIMUL::%s, have %d: %s",instName,(
Int_t)pargv.size(),pargs)) ;
1958 }
else if (cl==
"EXPR") {
1961 if (args.size()<=2) {
1962 ft.
createArg(
"RooGenericPdf",instName,pargs) ;
1967 for (UInt_t i=1 ; i<args.size() ; i++) {
1972 ft.
createArg(
"RooGenericPdf",instName,genargs) ;
1975 }
else if (cl==
"FCONV") {
1978 ft.
createArg(
"RooFFTConvPdf",instName,pargs) ;
1980 }
else if (cl==
"NCONV") {
1983 ft.
createArg(
"RooNumConvPdf",instName,pargs) ;
1985 }
else if (cl==
"sum") {
1990 }
else if (cl==
"prod") {
1995 }
else if (cl==
"expr") {
1998 if (args.size()<=2) {
1999 ft.
createArg(
"RooFormulaVar",instName,pargs) ;
2004 for (UInt_t i=1 ; i<args.size() ; i++) {
2009 ft.
createArg(
"RooFormulaVar",instName,genargs) ;
2012 }
else if (cl ==
"taylorexpand") {
2018 double observablesValue(0.0);
2020 if (pargv.size() < 2)
2021 throw string(
Form(
"taylorexpand::%s, requires atleast 2 arguments (function, observables) atleast, has %d arguments", instName, (
Int_t)pargv.size()));
2026 if (pargv.size() > 3)
2027 order = atoi(pargv[3].c_str());
2028 if (pargv.size() > 2) {
2029 if (pargv[2].find(
',') != string::npos) {
2031 Form(
"taylorexpand::%s, factory syntax supports expansion only around same value for all observables", instName));
2033 observablesValue =
toDouble(pargv[2]);
2037 if (pargv.size() > 3)
2038 order = atoi(pargv[3].c_str());
2039 if (pargv.size() > 4)
2041 if (pargv.size() > 5)
2044 if (pargv.size() > 6) {
2046 Form(
"taylorexpand::%s, requires max. 6 arguments, has %d arguments", instName, (
Int_t)pargv.size()));
2052 }
else if (cl==
"nconv") {
2055 ft.
createArg(
"RooNumConvolution",instName,pargs) ;
2057#ifdef ROOFIT_LEGACY_EVAL_BACKEND
2058 }
else if (cl==
"nll") {
2061 RooNLLVar nll(instName,instName,ft.
asPDF(pargv[0].c_str()),ft.
asDATA(pargv[1].c_str()),
false) ;
2064 }
else if (cl==
"chi2") {
2071 }
else if (cl==
"profile") {
2074 ft.
createArg(
"RooProfileLL",instName,pargs) ;
2076 }
else if (cl==
"dataobs") {
2079 std::unique_ptr<RooAbsArg> funcClone{
static_cast<RooAbsArg*
>(ft.
asARG(pargv[1].c_str()).clone(instName))};
2085 }
else if (cl==
"int") {
2092 if (pargv.size()<2 || pargv.size()>3) {
2093 throw string(
Form(
"int::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2099 strlcpy(buf,pargv[1].c_str(),256) ;
2101 const char* intobs = R__STRTOK_R(buf,
"|",&save) ;
2102 if (!intobs) intobs=
"" ;
2104 const char* range = R__STRTOK_R(
nullptr,
"",&save) ;
2105 if (!range) range=
"" ;
2107 std::unique_ptr<RooAbsReal> integral;
2108 if (pargv.size()==2) {
2109 if (range && strlen(range)) {
2115 if (range && strlen(range)) {
2122 integral->SetName(instName) ;
2125 }
else if (cl==
"deriv") {
2129 if (pargv.size()<2 || pargv.size()>3) {
2130 throw string(
Form(
"deriv::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2135 std::unique_ptr<RooAbsReal> derivative;
2136 if (pargv.size()==2) {
2142 derivative->SetName(instName) ;
2145 }
else if (cl==
"cdf") {
2149 if (pargv.size()<2 || pargv.size()>3) {
2150 throw string(
Form(
"cdf::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2155 std::unique_ptr<RooAbsReal> cdf;
2156 if (pargv.size()==2) {
2157 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.
asSET(pargv[1].c_str()))};
2159 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.
asSET(pargv[1].c_str()),ft.
asSET(pargv[2].c_str()))};
2162 cdf->SetName(instName) ;
2166 }
else if (cl==
"PROJ") {
2169 if (pargv.size()!=2) {
2170 throw string(
Form(
"PROJ::%s, requires 2 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2175 projection->
SetName(instName) ;
2179 }
else if (cl==
"set") {
2184 return string(instName) ;
2189 throw string(
Form(
"RooFactoryWSTool::SpecialsIFace::create() ERROR: Unknown meta-type %s",typeName)) ;
2192 return string(instName) ;
true
Register systematic variations for multiple existing columns using auto-generated tags.
double toDouble(const char *s)
int Int_t
Signed integer 4 bytes (int)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
void SetName(const char *name) override
Set the name of the TNamed.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for binned and unbinned datasets.
Abstract interface for all probability density functions.
RooFit::OwningPtr< RooAbsReal > createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset.
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
RooDerivative * derivative(RooRealVar &obs, Int_t order=1, double eps=0.001)
Return function representing first, second or third order derivative of this function.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
Efficient implementation of a sum of PDFs of the form.
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
virtual RooAbsArg * addColumn(RooAbsArg &var, bool adjustRange=true)
Add a column with the values of the given (function) argument to this dataset.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
static std::unique_ptr< RooPolyFunc > taylorExpand(const char *name, const char *title, RooAbsReal &func, const RooArgList &observables, int order=1, std::vector< double > const &observableValues={}, double eps1=1e-6, double eps2=1e-3)
Taylor expanding given function in terms of observables around observableValues.
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
A RooAbsArg implementing string values.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
const RooArgSet * set(RooStringView name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
bool commitTransaction()
Commit an ongoing import transaction.
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
bool defineSet(const char *name, const RooArgSet &aset, bool importMissing=false)
Define a named RooArgSet with given constituents.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
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.
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
const char * GetName() const override
Returns name of object.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TObject()
TObject constructor.
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)
RooConstVar & RooConst(double val)
RooCmdArg Silence(bool flag=true)
RooCmdArg NormSet(Args_t &&... argsOrArgSet)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static uint64_t sum(uint64_t i)