63using std::string, std::map, std::list, std::pair, std::endl, std::vector;
65#define BUFFER_SIZE 64000
124 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createFactory() ERROR: variable with name '" <<
name <<
"' already exists" << std::endl ;
151 const size_t tmpSize = strlen(stateNameList)+1;
152 std::vector<char> tmp(tmpSize);
153 strlcpy(tmp.data(),stateNameList,tmpSize) ;
155 char* tok = R__STRTOK_R(tmp.data(),
",",&save) ;
157 char* sep = strchr(tok,
'=') ;
160 Int_t id = atoi(sep+1) ;
166 tok = R__STRTOK_R(
nullptr,
",",&save) ;
179 bool isEnum(
const char* classname) {
181 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
188 bool isValidEnumValue(
const char* enumName,
const char* enumConstantName) {
191 if (!enumName)
return false;
194 if (!enumName)
return false;
197 if (theEnum->GetConstant(enumConstantName))
return true;
199 auto tmp = strstr(enumConstantName,
"::");
201 auto enumConstantNameNoScope = tmp+2;
202 if (theEnum->GetConstant(enumConstantNameNoScope))
return true;
208 pair<list<string>,
unsigned int> ctorArgsImpl(
const char* classname, std::size_t nPassedArgs) {
216 ClassInfo_t* cls =
gInterpreter->ClassInfo_Factory(classname);
217 MethodInfo_t* func =
gInterpreter->MethodInfo_Factory(cls);
230 if (
string(classname) !=
gInterpreter->MethodInfo_TypeName(func)) {
236 int nDefaultArgs =
gInterpreter->MethodInfo_NDefaultArg(func);
237 if (nargs == nDefaultArgs) {
241 MethodArgInfo_t* arg =
gInterpreter->MethodArgInfo_Factory(func);
244 const char* argTypeName =
gInterpreter->MethodArgInfo_TypeName(arg);
245 if (nreq<2 && ((
string(
"char*") != argTypeName
247 &&
string(
"const char*") != argTypeName)) {
250 ret.push_back(argTypeName) ;
251 if(!
gInterpreter->MethodArgInfo_DefaultValue(arg)) nreq++;
258 if(
static_cast<int>(nPassedArgs) >= nargs - nDefaultArgs &&
static_cast<int>(nPassedArgs) <= nargs) {
264 return pair<list<string>,
unsigned int>(ret,nreq);
267 pair<list<string>,
unsigned int>
const & ctorArgs(
const char* classname, std::size_t nPassedArgs) {
274 static std::map<pair<string, std::size_t>, pair<list<string>,
unsigned int>> cache;
275 auto key = std::make_pair(
string(classname), nPassedArgs);
276 auto it = cache.find(key);
277 if (it == cache.end()) {
278 it = cache.emplace(std::move(key), ctorArgsImpl(classname, nPassedArgs)).first;
295 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " <<
className <<
" not found in factory alias table, nor in ROOT class table" << std::endl;
313 size_t start_tok = 0;
314 bool litmode =
false;
315 for (end_tok = 0; end_tok < tmp.length(); end_tok++) {
317 if (tmp[end_tok]==
'{' || tmp[end_tok]==
'(' || tmp[end_tok]==
'[') blevel++;
318 if (tmp[end_tok]==
'}' || tmp[end_tok]==
')' || tmp[end_tok]==
']') blevel--;
321 if (tmp[end_tok]==
'"' || tmp[end_tok]==
'\'') litmode = !litmode;
326 if (litmode ==
false && blevel == 0 && tmp[end_tok] ==
',') {
327 _args.push_back(tmp.substr(start_tok, end_tok - start_tok));
328 start_tok = end_tok+1;
331 _args.push_back(tmp.substr(start_tok, end_tok));
334 pair<list<string>,
unsigned int>
const & ca = ctorArgs(
className,
_args.size()+2) ;
335 if (ca.first.empty()) {
343 if (
_args.size()+2<ca.second ||
_args.size()+2>ca.first.size()) {
344 if (ca.second==ca.first.size()) {
346 <<
" expects " << ca.first.size()-2 << std::endl ;
350 <<
" expect number between " << ca.second-2 <<
" and " << ca.first.size()-2 << std::endl ;
357 string cintExpr(
Form(
"new %s(\"%s\",\"%s\"",
className,objName,objName)) ;
365 list<string>::const_iterator ti = ca.first.begin() ; ++ti ; ++ti ;
366 for (vector<string>::iterator ai =
_args.begin() ; ai !=
_args.end() ; ++ai,++ti,++i) {
367 if ((*ti)==
"RooAbsReal&" || (*ti)==
"const RooAbsReal&" || (*ti)==
"RooAbsReal::Ref") {
369 cintExpr +=
Form(
",RooFactoryWSTool::as_FUNC(%d)",i) ;
370 }
else if ((*ti)==
"RooAbsArg&" || (*ti)==
"const RooAbsArg&") {
372 cintExpr +=
Form(
",RooFactoryWSTool::as_ARG(%d)",i) ;
373 }
else if ((*ti)==
"RooRealVar&" || (*ti)==
"const RooRealVar&") {
375 cintExpr +=
Form(
",RooFactoryWSTool::as_VAR(%d)",i) ;
376 }
else if ((*ti)==
"RooAbsRealLValue&" || (*ti)==
"const RooAbsRealLValue&") {
378 cintExpr +=
Form(
",RooFactoryWSTool::as_VARLV(%d)",i) ;
379 }
else if ((*ti)==
"RooCategory&" || (*ti)==
"const RooCategory&") {
381 cintExpr +=
Form(
",RooFactoryWSTool::as_CAT(%d)",i) ;
382 }
else if ((*ti)==
"RooAbsCategory&" || (*ti)==
"const RooAbsCategory&") {
384 cintExpr +=
Form(
",RooFactoryWSTool::as_CATFUNC(%d)",i) ;
385 }
else if ((*ti)==
"RooAbsCategoryLValue&" || (*ti)==
"const RooAbsCategoryLValue&") {
387 cintExpr +=
Form(
",RooFactoryWSTool::as_CATLV(%d)",i) ;
388 }
else if ((*ti)==
"RooAbsPdf&" || (*ti)==
"const RooAbsPdf&") {
390 cintExpr +=
Form(
",RooFactoryWSTool::as_PDF(%d)",i) ;
391 }
else if ((*ti)==
"RooResolutionModel&" || (*ti)==
"const RooResolutionModel&") {
393 cintExpr +=
Form(
",RooFactoryWSTool::as_RMODEL(%d)",i) ;
394 }
else if ((*ti)==
"RooAbsData&" || (*ti)==
"const RooAbsData&") {
396 cintExpr +=
Form(
",RooFactoryWSTool::as_DATA(%d)",i) ;
397 }
else if ((*ti)==
"RooDataSet&" || (*ti)==
"const RooDataSet&") {
399 cintExpr +=
Form(
",RooFactoryWSTool::as_DSET(%d)",i) ;
400 }
else if ((*ti)==
"RooDataHist&" || (*ti)==
"const RooDataHist&") {
402 cintExpr +=
Form(
",RooFactoryWSTool::as_DHIST(%d)",i) ;
403 }
else if ((*ti)==
"const RooArgSet&") {
405 cintExpr +=
Form(
",RooFactoryWSTool::as_SET(%d)",i) ;
406 }
else if ((*ti)==
"const RooArgList&") {
408 cintExpr +=
Form(
",RooFactoryWSTool::as_LIST(%d)",i) ;
409 }
else if ((*ti)==
"const char*") {
411 cintExpr +=
Form(
",RooFactoryWSTool::as_STRING(%d)",i) ;
412 }
else if ((*ti)==
"Int_t" || (*ti)==
"int" || (*ti)==
"bool" || (*ti)==
"bool") {
414 cintExpr +=
Form(
",RooFactoryWSTool::as_INT(%d)",i) ;
415 }
else if ((*ti)==
"double") {
417 cintExpr +=
Form(
",RooFactoryWSTool::as_DOUBLE(%d)",i) ;
418 }
else if (isEnum(ti->c_str())) {
422 qualvalue =
_args[i] ;
426 if (isValidEnumValue(ti->c_str(),qualvalue.c_str())) {
427 cintExpr +=
Form(
",(%s)%s",ti->c_str(),qualvalue.c_str()) ;
429 throw string(
Form(
"Supplied argument %s does not represent a valid state of enum %s",
_args[i].c_str(),ti->c_str())) ;
437 if (ti->find(
"const ")==0) {
438 btype = ti->c_str()+6 ;
442 if (btype.find(
'&')) {
443 btype.erase(btype.size()-1,btype.size()) ;
450 cintExpr +=
Form(
",(%s&)RooFactoryWSTool::as_OBJ(%d)",ti->c_str(),i) ;
452 throw string(
Form(
"Required argument with name %s of type '%s' is not in the workspace",
_args[i].c_str(),ti->c_str())) ;
457 }
catch (
const string &err) {
458 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR constructing " <<
className <<
"::" << objName <<
": " << err << std::endl ;
463 cxcoutD(
ObjectHandling) <<
"RooFactoryWSTool::createArg() Construct expression is " << cintExpr << std::endl ;
466 if (std::unique_ptr<RooAbsArg> arg{
reinterpret_cast<RooAbsArg*
>(
gROOT->ProcessLineFast(cintExpr.c_str()))}) {
467 if (
string(
className)==
"RooGenericPdf") {
468 arg->setStringAttribute(
"factory_tag",
Form(
"EXPR::%s(%s)",objName,varList)) ;
469 }
else if (
string(
className)==
"RooFormulaVar") {
470 arg->setStringAttribute(
"factory_tag",
Form(
"expr::%s(%s)",objName,varList)) ;
472 arg->setStringAttribute(
"factory_tag",
Form(
"%s::%s(%s)",
className,objName,varList)) ;
478 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR in Cling constructor call to create object" << std::endl ;
499 char* tok = R__STRTOK_R(buf,
",",&save) ;
501 char* star=strchr(tok,
'*') ;
507 pdfList2.add(
asPDF(tok)) ;
509 tok = R__STRTOK_R(
nullptr,
",",&save) ;
511 pdfList.
add(pdfList2) ;
513 }
catch (
const string &err) {
514 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooAddPdf: " << err << std::endl ;
519 RooAddPdf pdf{objName,objName,pdfList,coefList,recursiveCoefs};
520 pdf.setStringAttribute(
"factory_tag",
Form(
"SUM::%s(%s)",objName,specList)) ;
541 char* tok = R__STRTOK_R(buf,
",",&save) ;
543 char* star=strchr(tok,
'*') ;
546 amplList.add(
asFUNC(star+1)) ;
549 amplList2.add(
asFUNC(tok)) ;
551 tok = R__STRTOK_R(
nullptr,
",",&save) ;
553 amplList.add(amplList2) ;
555 }
catch (
const string &err) {
556 coutE(
ObjectHandling) <<
"RooFactoryWSTool::add(" << objName <<
") ERROR creating RooRealSumPdf: " << err << std::endl ;
561 RooRealSumPdf pdf(objName,objName,amplList,coefList,(amplList.size()==coefList.
size())) ;
576 string regPdfList=
"{" ;
580 char* tok = R__STRTOK_R(buf,
",",&save) ;
582 char *sep = strchr(tok,
'|') ;
589 bool invCond(
false) ;
597 }
catch (
const string &err) {
598 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf Conditional argument: " << err << std::endl ;
605 if (regPdfList.size()>1) {
610 tok = R__STRTOK_R(
nullptr,
",",&save) ;
614 std::unique_ptr<RooProdPdf> pdf;
616 pdf = std::make_unique<RooProdPdf>(objName,objName,
asSET(regPdfList.c_str()),cmdList);
617 }
catch (
const string &err) {
618 coutE(
ObjectHandling) <<
"RooFactoryWSTool::prod(" << objName <<
") ERROR creating RooProdPdf input set of regular pdfs: " << err << std::endl ;
624 pdf->setStringAttribute(
"factory_tag",
Form(
"PROD::%s(%s)",objName,pdfList)) ;
638 map<string,RooAbsPdf*> theMap ;
643 char* tok = R__STRTOK_R(buf,
",",&save) ;
645 char* eq = strchr(tok,
'=') ;
647 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName
648 <<
" expect mapping token of form 'state=pdfName', but found '" << tok <<
"'" << std::endl ;
655 theMap[tok] = &
asPDF(eq+1) ;
656 }
catch (
const string &err ) {
657 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous: " << err << std::endl ;
661 tok = R__STRTOK_R(
nullptr,
",",&save) ;
666 std::unique_ptr<RooSimultaneous> pdf;
668 pdf = std::make_unique<RooSimultaneous>(objName,objName,theMap,
asCATLV(indexCat)) ;
669 }
catch (
const string &err) {
670 coutE(
ObjectHandling) <<
"RooFactoryWSTool::simul(" << objName <<
") ERROR creating RooSimultaneous::" << objName <<
" " << err << std::endl ;
676 pdf->setStringAttribute(
"factory_tag",
Form(
"SIMUL::%s(%s,%s)",objName,indexCat,pdfMap)) ;
696 char* tok = R__STRTOK_R(buf,
",",&save) ;
698 char* star=strchr(tok,
'*') ;
701 sumlist2.add(
asFUNC(star+1)) ;
702 sumlist1.add(
asFUNC(tok)) ;
704 sumlist1.add(
asFUNC(tok)) ;
706 tok = R__STRTOK_R(
nullptr,
",",&save) ;
709 }
catch (
const string &err) {
710 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: " << err << std::endl ;
715 if (!sumlist2.empty() && (sumlist1.size()!=sumlist2.size())) {
716 coutE(
ObjectHandling) <<
"RooFactoryWSTool::addfunc(" << objName <<
") ERROR creating RooAddition: syntax error: either all sum terms must be products or none" << std::endl ;
722 auto sum = sumlist2.empty() ? std::make_unique<RooAddition>(objName,objName,sumlist1)
723 : std::make_unique<RooAddition>(objName,objName,sumlist1,sumlist2);
725 sum->setStringAttribute(
"factory_tag",
Form(
"sum::%s(%s)",objName,specList)) ;
842 std::vector<char> buf(strlen(expr)+1);
845 char* buftmp = buf.data();
847 if (!isspace(*expr)) {
864 }
catch (
const string &error) {
865 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERROR in parsing: " << error << std::endl ;
871 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed" << std::endl ;
877 return !out.empty() ?
ws().
arg(out) : nullptr ;
896 if (
string(token).find(
"$Alias(")==0) {
922 const size_t bufBaseSize = strlen(token)+1;
923 std::vector<char> buf_base(bufBaseSize);
924 char* buf = buf_base.data();
925 strlcpy(buf,token,bufBaseSize) ;
928 list<string> singleExpr ;
929 list<char> separator ;
931 bool litmode(
false) ;
935 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
936 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
939 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
943 if (!litmode && blevel==0 && ( (*
p)==
'=' || (*
p) ==
'|' || (*
p) ==
'*')) {
944 separator.push_back(*
p) ;
946 singleExpr.push_back(buf) ;
952 singleExpr.push_back(buf) ;
954 if (singleExpr.size()==1) {
960 list<char>::iterator ic = separator.begin() ;
961 for (list<string>::iterator ii = singleExpr.begin() ; ii!=singleExpr.end() ; ++ii) {
963 if (ic != separator.end()) {
985 if (strlen(arg)==0) {
990 if (arg[0]==
'\'' || arg[0]==
'"') {
995 const size_t bufSize = strlen(arg)+1;
996 std::vector<char> buf(bufSize);
997 strlcpy(buf.data(),arg,bufSize) ;
998 char* bufptr = buf.data();
1001 vector<string> args ;
1005 char* tmpx = R__STRTOK_R(buf.data(),
"([",&save) ;
1006 func = tmpx ? tmpx :
"" ;
1007 char*
p = R__STRTOK_R(
nullptr,
"",&save) ;
1017 bool litmode(
false) ;
1021 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
1022 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
1025 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
1031 if (!litmode && blevel==0 && ((*
p)==
',')) {
1033 args.push_back(tok) ;
1042 if (
p>bufptr && (*(
p-1)==
')'||*(
p-1)==
']')) {
1051 p = R__STRTOK_R(
nullptr,
"",&save) ;
1053 args.push_back(tmp) ;
1061 for(
const char* pp=arg ; *pp!=0 ; pp++) {
1062 if (*pp==
'(' || *pp==
'[' || *pp==
'{') {
1068 if (strstr(func.c_str(),
"::")) {
1073 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: Class::Instance must be followed by (...)" << std::endl ;
1076 }
else if (func[0]!=
'$'){
1080 }
else if (lb==
'(') {
1090 static Int_t globCounter = 0 ;
1092 autoname =
Form(
"gobj%d",globCounter) ;
1094 if (!
ws().arg(autoname)) {
1098 autoname =
Form(
"%s::%s",func.c_str(),autoname.c_str()) ;
1102 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: expect either Class(...) or Instance[...]" << std::endl ;
1110 coutE(
ObjectHandling) <<
"RooFactoryWSTool::processSingleExpression(" << arg <<
"): ERROR: Syntax error: $MetaClass must be followed by (...)" << std::endl ;
1130 const size_t bufSize = strlen(arg)+1;
1131 std::vector<char> buf(bufSize);
1132 strlcpy(buf.data(),arg,bufSize) ;
1134 std::vector<string> args ;
1137 char* tok = buf.data()+1 ;
1138 char*
p = buf.data()+1 ;
1145 if (*
p==
'{' || *
p==
'(' || *
p==
'[') level++ ;
1146 if (*
p==
'}' || *
p==
')' || *
p==
']') level-- ;
1152 if (level==0 && ((*
p)==
',')) {
1154 args.push_back(tok) ;
1162 if (
p>buf.data() && *(
p-1)==
'}') {
1165 args.push_back(tok) ;
1170 vector<string>::iterator iter = args.begin() ;
1172 while(iter!= args.end()) {
1173 if (strlen(ret.c_str())>1) ret +=
"," ;
1197 if (args.size()!=2) {
1198 coutE(
ObjectHandling) <<
"RooFactorWSTool::processAliasExpression() ERROR $Alias() takes exactly two arguments, " << args.size() <<
" args found" << std::endl ;
1235 coutE(
ObjectHandling) <<
"RooFactoryWSTool::createArg() ERROR class " <<
className <<
" not defined in ROOT class table" << std::endl ;
1252 for (vector<string>::iterator iter = args.begin() ; iter!=args.end() ; ++iter) {
1253 if (iter!=args.begin()) {
1279 string first = *(args.begin());
1280 bool isNumeric = isdigit(first[0]) || first[0] ==
'.' || first[0] ==
'+' || first[0] ==
'-';
1285 for (
auto const &ai : args) {
1286 if (!allStates.empty()) {
1295 std::unique_ptr<RooRealVar> tmp;
1297 if (args.size() == 1) {
1299 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit);
1301 }
else if (args.size() == 2) {
1304 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xlo, xhi);
1306 }
else if (args.size() == 3) {
1310 tmp = std::make_unique<RooRealVar>(func.c_str(), func.c_str(), xinit, xlo, xhi);
1314 tmp->setStringAttribute(
"factory_tag",
varTag(func, args).c_str());
1339 const char *
className = R__STRTOK_R(buf,
":",&save) ;
1340 const char *instName = R__STRTOK_R(
nullptr,
":",&save) ;
1342 if (!instName) instName =
"" ;
1347 vector<string>::iterator iter = args.begin() ;
1348 vector<string> pargv ;
1350 while(iter!=args.end()) {
1351 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1356 pargv.push_back(tmp) ;
1362 for (map<string,IFace*>::iterator ii=
hooks().begin() ; ii!=
hooks().end() ; ++ii) {
1366 return iface->create(*
this,
className,instName,pargv) ;
1371 return string(instName) ;
1383 vector<string>::iterator iter = args.begin() ;
1384 vector<string> pargv ;
1385 while(iter!=args.end()) {
1386 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1389 pargv.push_back(tmp) ;
1393 string ret = func+
"("+pargs+
")" ;
1405 const size_t bufSize = strlen(funcExpr)+1;
1406 std::vector<char> buf(bufSize);
1407 strlcpy(buf.data(),funcExpr,bufSize) ;
1408 char* bufptr = buf.data();
1411 vector<string> args ;
1415 char* tmpx = R__STRTOK_R(buf.data(),
"(",&save) ;
1416 func = tmpx ? tmpx :
"" ;
1417 char*
p = R__STRTOK_R(
nullptr,
"",&save) ;
1426 bool litmode(
false) ;
1430 if (*
p==
'{' || *
p==
'(' || *
p==
'[') blevel++ ;
1431 if (*
p==
'}' || *
p==
')' || *
p==
']') blevel-- ;
1434 if (*
p==
'"' || *
p==
'\'') litmode = !litmode ;
1440 if (!litmode && blevel==0 && ((*
p)==
',')) {
1442 args.push_back(tok) ;
1451 if (
p>bufptr && *(
p-1)==
')') {
1460 p = R__STRTOK_R(
nullptr,
"",&save) ;
1462 args.push_back(tmp) ;
1478 Int_t nParentheses(0);
1481 const char* ptr = arg ;
1483 if (*ptr==
'(') nParentheses++ ;
1484 if (*ptr==
')') nParentheses-- ;
1485 if (*ptr==
'[') nBracket++ ;
1486 if (*ptr==
']') nBracket-- ;
1487 if (*ptr==
'{') nAccolade++ ;
1488 if (*ptr==
'}') nAccolade-- ;
1491 if (nParentheses!=0) {
1492 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nParentheses>0?
"(":
")") <<
"' in expression" << std::endl ;
1496 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nBracket>0?
"[":
"]") <<
"' in expression" << std::endl ;
1500 coutE(
ObjectHandling) <<
"RooFactoryWSTool::checkSyntax ERROR non-matching '" << (nAccolade>0?
"{":
"}") <<
"' in expression" << std::endl ;
1512 if (idx>
_of->_args.size()-1) {
1513 throw string(
Form(
"Need argument number %d, but only %d args are provided",idx,(
Int_t)
_of->_args.size())) ;
1525 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1532 throw string(
Form(
"RooAbsArg named %s not found",arg)) ;
1545 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1551 throw string(
Form(
"RooAbsReal named %s not found",arg)) ;
1555 throw string(
Form(
"Object named %s is not of type RooAbsReal",arg)) ;
1568 if (arg[0]==
'.' || arg[0]==
'+' || arg[0] ==
'-' || isdigit(arg[0])) {
1569 throw string(
Form(
"Numeric literal provided for argument (%s), but lvalue is required",arg)) ;
1574 throw string(
Form(
"RooAbsRealLValue named %s not found",arg)) ;
1578 throw string(
Form(
"Object named %s is not of type RooAbsRealLValue",arg)) ;
1592 throw string(
Form(
"RooRealVar named %s not found",arg)) ;
1607 throw string(
Form(
"RooAbsPdf named %s not found",arg)) ;
1622 throw string(
Form(
"RooResolutionModel named %s not found",arg)) ;
1626 throw string(
Form(
"Object named %s is not of type RooResolutionModel",arg)) ;
1641 throw string(
Form(
"RooAbsCategory named %s not found",arg)) ;
1645 throw string(
Form(
"Object named %s is not of type RooAbsCategory",arg)) ;
1659 throw string(
Form(
"RooAbsCategoryLValue named %s not found",arg)) ;
1664 throw string(
Form(
"Object named %s is not of type RooAbsCategoryLValue",arg)) ;
1678 throw string(
Form(
"RooCategory named %s not found",arg)) ;
1709 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1714 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1716 }
else if (tok[0] ==
'\'') {
1717 tok[strlen(tok) - 1] = 0;
1725 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1728 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1746 char* tok = R__STRTOK_R(tmp,
",{}",&save) ;
1750 if (tok[0]==
'.' || tok[0]==
'+' || tok[0] ==
'-' || isdigit(tok[0])) {
1752 }
else if (tok[0] ==
'\'') {
1753 tok[strlen(tok) - 1] = 0;
1761 throw string(
Form(
"RooAbsArg named %s not found",tok)) ;
1764 tok = R__STRTOK_R(
nullptr,
",{}",&save) ;
1779 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1793 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1797 throw string(
Form(
"Dataset named %s is not of type RooDataHist",arg)) ;
1810 throw string(
Form(
"RooAbsData named %s not found",arg)) ;
1814 throw string(
Form(
"Dataset named %s is not of type RooDataSet",arg)) ;
1827 throw string(
Form(
"Object named %s not found",arg)) ;
1839 static vector<string> cbuf(10) ;
1840 static unsigned int cbuf_idx = 0 ;
1843 if (arg==
nullptr || strlen(arg)==0) {
1849 cbuf[cbuf_idx].clear() ;
1850 const char*
p = arg+1 ;
1851 while(*
p && (*
p) !=
'"' && (*
p) !=
'\'' ) {
1852 cbuf[cbuf_idx] += *(
p++) ;
1854 const char* ret = cbuf[cbuf_idx].c_str() ;
1858 if (cbuf_idx==cbuf.size()) cbuf_idx=0 ;
1871 const std::string s{arg};
1894 hooks()[typeName] = iface ;
1904 _hooks =
new map<string,IFace*> ;
1917 vector<string>::iterator iter = args.begin() ;
1918 vector<string> pargv ;
1919 while(iter!=args.end()) {
1920 if (strlen(pargs)>0) strlcat(pargs,
",",
BUFFER_SIZE) ;
1921 string tmp = ft.processExpression(iter->c_str()) ;
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") {
1942 ft.amplAdd(instName,pargs) ;
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") {
1988 ft.addfunc(instName,pargs) ;
1990 }
else if (cl==
"prod") {
1993 ft.prodfunc(instName,pargs) ;
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()));
2023 RooAbsReal &func = ft.asFUNC(pargv[0].c_str());
2024 RooArgList observables = ft.asLIST(pargv[1].c_str());
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()));
2050 if (ft.ws().import(*taylor,
Silence())) ft.logError();
2052 }
else if (cl==
"nconv") {
2055 ft.createArg(
"RooNumConvolution",instName,pargs) ;
2057 }
else if (cl==
"profile") {
2060 ft.createArg(
"RooProfileLL",instName,pargs) ;
2062 }
else if (cl==
"dataobs") {
2065 std::unique_ptr<RooAbsArg> funcClone{
static_cast<RooAbsArg*
>(ft.asARG(pargv[1].c_str()).clone(instName))};
2066 RooAbsArg* arg = ft.asDSET(pargv[0].c_str()).addColumn(*funcClone) ;
2067 if (!ft.ws().fundArg(arg->
GetName())) {
2068 if (ft.ws().import(*arg,
Silence())) ft.logError() ;
2071 }
else if (cl==
"int") {
2078 if (pargv.size()<2 || pargv.size()>3) {
2079 throw string(
Form(
"int::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2082 RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2085 strlcpy(buf,pargv[1].c_str(),256) ;
2087 const char* intobs = R__STRTOK_R(buf,
"|",&save) ;
2088 if (!intobs) intobs=
"" ;
2090 const char* range = R__STRTOK_R(
nullptr,
"",&save) ;
2091 if (!range) range=
"" ;
2093 std::unique_ptr<RooAbsReal> integral;
2094 if (pargv.size()==2) {
2095 if (range && strlen(range)) {
2096 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
Range(range))};
2098 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs))};
2101 if (range && strlen(range)) {
2102 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
Range(range),
NormSet(ft.asSET(pargv[2].c_str())))};
2104 integral = std::unique_ptr<RooAbsReal>{func.
createIntegral(ft.asSET(intobs),
NormSet(ft.asSET(pargv[2].c_str())))};
2108 integral->SetName(instName) ;
2109 if (ft.ws().import(*integral,
Silence())) ft.logError() ;
2111 }
else if (cl==
"deriv") {
2115 if (pargv.size()<2 || pargv.size()>3) {
2116 throw string(
Form(
"deriv::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2119 RooAbsReal& func = ft.asFUNC(pargv[0].c_str()) ;
2121 std::unique_ptr<RooAbsReal> derivative;
2122 if (pargv.size()==2) {
2123 derivative.reset(func.
derivative(ft.asVAR(pargv[1].c_str()),1));
2125 derivative.reset(func.
derivative(ft.asVAR(pargv[1].c_str()),ft.asINT(pargv[2].c_str())));
2128 derivative->SetName(instName) ;
2129 if (ft.ws().import(*derivative,
Silence())) ft.logError() ;
2131 }
else if (cl==
"cdf") {
2135 if (pargv.size()<2 || pargv.size()>3) {
2136 throw string(
Form(
"cdf::%s, requires 2 or 3 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2139 RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2141 std::unique_ptr<RooAbsReal> cdf;
2142 if (pargv.size()==2) {
2143 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.asSET(pargv[1].c_str()))};
2145 cdf = std::unique_ptr<RooAbsReal>{pdf.
createCdf(ft.asSET(pargv[1].c_str()),ft.asSET(pargv[2].c_str()))};
2148 cdf->SetName(instName) ;
2149 if (ft.ws().import(*cdf,
Silence())) ft.logError() ;
2152 }
else if (cl==
"PROJ") {
2155 if (pargv.size()!=2) {
2156 throw string(
Form(
"PROJ::%s, requires 2 arguments, have %d arguments",instName,(
Int_t)pargv.size())) ;
2159 RooAbsPdf& pdf = ft.asPDF(pargv[0].c_str()) ;
2160 std::unique_ptr<RooAbsPdf> projection{pdf.
createProjection(ft.asSET(pargv[1].c_str()))};
2161 projection->SetName(instName) ;
2163 if (ft.ws().import(*projection,
Silence())) ft.logError() ;
2165 }
else if (cl==
"set") {
2168 if (ft.ws().defineSet(instName,pargs)) {
2170 return string(instName) ;
2175 throw string(
Form(
"RooFactoryWSTool::SpecialsIFace::create() ERROR: Unknown meta-type %s",typeName)) ;
2178 return string(instName) ;
double toDouble(const char *s)
int Int_t
Signed integer 4 bytes (int)
winID h TVirtualViewer3D TVirtualGLPainter p
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'.
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.
Collection class for internal use, storing a collection of TObject pointers in a vector.
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...
bool commitTransaction()
Commit an ongoing import transaction.
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
RooAbsReal * function(RooStringView name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
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 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.
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.
Mother of all ROOT objects.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
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)