51 std::string
create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
override ;
92 string realArgNames,catArgNames ;
95 if (realArgNames.size()>0) realArgNames +=
"," ;
96 realArgNames += arg->GetName() ;
98 if (catArgNames.size()>0) catArgNames +=
"," ;
99 catArgNames += arg->GetName() ;
101 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeAndCompilePdf ERROR input argument " << arg->GetName()
102 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
106 bool ret =
makePdf(
name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
true:
false,
false,intExpression) ;
133 string realArgNames,catArgNames ;
136 if (realArgNames.size()>0) realArgNames +=
"," ;
137 realArgNames += arg->GetName() ;
139 if (catArgNames.size()>0) catArgNames +=
"," ;
140 catArgNames += arg->GetName() ;
142 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeAndCompileFunction ERROR input argument " << arg->GetName()
143 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
147 bool ret =
makeFunction(
name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
true:
false,intExpression) ;
181 string tmpName(
name) ;
182 tmpName[0] = toupper(tmpName[0]) ;
183 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
219 std::string
line = std::string(
"new ") + className +
"(\"" +
name +
"\",\"" +
name +
"\"";
225 std::string argList ;
229 argList +=
Form(
",*((RooAbsReal*)0x%zx)",(
size_t)var) ;
235 argList +=
Form(
",*((RooAbsCategory*)0x%zx)",(
size_t)var) ;
239 line += argList +
") ;" ;
269 const RooArgList& vars,
const char* intExpression)
272 string tmpName(
name) ;
273 tmpName[0] = toupper(tmpName[0]) ;
274 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
300 const RooArgList& vars,
const char* intExpression)
311 std::string
line = std::string(
"new ") + className +
"(\"" +
name +
"\",\"" +
name +
"\"";
317 std::string argList ;
321 argList +=
Form(
",*((RooAbsReal*)0x%zx)",(
size_t)var) ;
327 argList +=
Form(
",*((RooAbsCategory*)0x%zx)",(
size_t)var) ;
331 line += argList +
") ;" ;
358 bool hasAnaInt,
bool hasIntGen,
const char* intExpression)
360 return makeClass(
"RooAbsPdf",
name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
382 return makeClass(
"RooAbsReal",
name,argNames,catArgNames,expression,hasAnaInt,
false,intExpression) ;
405 const char* expression,
bool hasAnaInt,
bool hasIntGen,
const char* intExpression)
409 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeClass: ERROR: a base class name must be given" << endl ;
414 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeClass: ERROR: a class name must be given" << endl ;
418 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
419 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeClass: ERROR: A list of input argument names must be given" << endl ;
423 if (intExpression && !hasAnaInt) {
424 oocoutE(
nullptr,InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
429 vector<string> alist ;
432 if (realArgNames && *realArgNames) {
433 const size_t bufSize = strlen(realArgNames)+1;
434 std::vector<char> buf(bufSize);
435 strlcpy(buf.data(),realArgNames,bufSize) ;
436 char* token = strtok(buf.data(),
",") ;
438 alist.push_back(token) ;
439 isCat.push_back(
false) ;
440 token = strtok(0,
",") ;
443 if (catArgNames && *catArgNames) {
444 const size_t bufSize = strlen(catArgNames)+1;
445 std::vector<char> buf(bufSize);
446 strlcpy(buf.data(),catArgNames,bufSize) ;
447 char* token = strtok(buf.data(),
",") ;
449 alist.push_back(token) ;
450 isCat.push_back(
true) ;
451 token = strtok(0,
",") ;
455 TString impFileName(className), hdrFileName(className) ;
456 impFileName +=
".cxx" ;
457 hdrFileName +=
".h" ;
462 ofstream hf(hdrFileName) ;
463 hf <<
"/*****************************************************************************" << endl
464 <<
" * Project: RooFit *" << endl
466 <<
" * This code was autogenerated by RooClassFactory * " << endl
467 <<
" *****************************************************************************/" << endl
469 <<
"#ifndef " << ifdefName << endl
470 <<
"#define " << ifdefName << endl
472 <<
"#include \"" << baseName <<
".h\"" << endl
473 <<
"#include \"RooRealProxy.h\"" << endl
474 <<
"#include \"RooCategoryProxy.h\"" << endl
475 <<
"#include \"RooAbsReal.h\"" << endl
476 <<
"#include \"RooAbsCategory.h\"" << endl
478 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
480 <<
" " << className <<
"() {} ; " << endl
481 <<
" " << className <<
"(const char *name, const char *title," << endl ;
485 for (i=0 ; i<alist.size() ; i++) {
487 hf <<
" RooAbsReal& _" ;
489 hf <<
" RooAbsCategory& _" ;
492 if (i==alist.size()-1) {
499 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
500 <<
" virtual TObject* clone(const char* newname) const override { return new " << className <<
"(*this,newname); }" << endl
501 <<
" inline virtual ~" << className <<
"() { }" << endl
505 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override;" << endl
506 <<
" double analyticalIntegral(Int_t code, const char* rangeName=0) const override;" << endl
511 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool staticInitOK=true) const override;" << endl
512 <<
" void initGenerator(Int_t code) override {} ; // optional pre-generation initialization" << endl
513 <<
" void generateEvent(Int_t code) override;" << endl
517 hf <<
"protected:" << endl
521 for (i=0 ; i<alist.size() ; i++) {
523 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
525 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
530 <<
" double evaluate() const override;" << endl
532 <<
"private:" << endl
534 <<
" ClassDefOverride(" << className <<
",1) // Your description goes here..." << endl
537 <<
"#endif" << endl ;
540 ofstream cf(impFileName) ;
542 cf <<
"/***************************************************************************** " << endl
543 <<
" * Project: RooFit * " << endl
545 <<
" * This code was autogenerated by RooClassFactory * " << endl
546 <<
" *****************************************************************************/ " << endl
548 <<
"// Your description goes here... " << endl
551 <<
"#include \"Riostream.h\" " << endl
554 <<
"#include \"" << className <<
".h\" " << endl
555 <<
"#include \"RooAbsReal.h\" " << endl
556 <<
"#include \"RooAbsCategory.h\" " << endl
557 <<
"#include <math.h> " << endl
558 <<
"#include \"TMath.h\" " << endl
561 <<
"ClassImp(" << className <<
"); " << endl
564 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
567 for (i=0 ; i<alist.size() ; i++) {
569 cf <<
" RooAbsReal& _" << alist[i] ;
571 cf <<
" RooAbsCategory& _" << alist[i] ;
573 if (i<alist.size()-1) {
582 cf <<
" " << baseName <<
"(name,title), " << endl ;
585 for (i=0 ; i<alist.size() ; i++) {
586 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
587 if (i<alist.size()-1) {
598 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
599 <<
" " << baseName <<
"(other,name), " << endl ;
601 for (i=0 ; i<alist.size() ; i++) {
602 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
603 if (i<alist.size()-1) {
615 <<
" double " << className <<
"::evaluate() const " << endl
617 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
618 <<
" return " << expression <<
" ; " << endl
626 vector<string> intObs ;
627 vector<string> intExpr ;
630 if (intExpression && *intExpression) {
631 const size_t bufSize = strlen(intExpression)+1;
632 std::vector<char> buf(bufSize);
633 strlcpy(buf.data(),intExpression,bufSize) ;
634 char* ptr = strtok(buf.data(),
":") ;
636 intObs.push_back(ptr) ;
637 intExpr.push_back(strtok(0,
";")) ;
638 ptr = strtok(0,
":") ;
642 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
644 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
645 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
646 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
647 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
648 <<
" // EXPRESSION MULTIPLE TIMES" << endl
651 if (intObs.size()>0) {
652 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
653 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
656 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
659 cf <<
" return 0 ; " << endl
665 <<
" double " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
667 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
668 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
669 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
672 if (intObs.size()>0) {
673 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
674 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
677 cf <<
" // assert(code==1) ; " << endl
678 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
681 cf <<
" return 0 ; " << endl
689 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const " << endl
691 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
692 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
693 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
694 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
695 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
696 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
697 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
699 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
700 <<
" return 0 ; " << endl
706 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
708 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
709 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
710 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
712 <<
" // assert(code==1) ; " << endl
713 <<
" // x = 0 ; " << endl
714 <<
" return; " << endl
729std::string ClassFacIFace::create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
731 static int classCounter = 0 ;
733 string tn(typeName) ;
734 if (tn==
"CEXPR" || tn==
"cexpr") {
737 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
744 strncpy(expr,args[0].c_str()+1,args[0].
size()-2) ;
745 expr[args[0].size()-2]=0 ;
751 if (args.size()==2) {
753 varList.
add(ft.
asLIST(args[1].c_str())) ;
755 for (
unsigned int i=1 ; i<args.size() ; i++) {
756 varList.
add(ft.
asARG(args[i].c_str())) ;
759 }
catch (
const string &err) {
760 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
765 className =
Form(
"RooCFAuto%03d%s%s",classCounter,(tn==
"CEXPR")?
"Pdf":
"Func",ft.autoClassNamePostFix()) ;
779 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
791 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
794 return string(instanceName) ;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
A space to attach TBranches.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgList is a container object that can hold multiple RooAbsArg objects.
static bool makePdf(const char *name, const char *realArgNames=nullptr, const char *catArgNames=nullptr, const char *expression="1.0", bool hasAnaInt=false, bool hasIntGen=false, const char *intExpression=nullptr)
Write code for a RooAbsPdf implementation with class name 'name', taking RooAbsReal arguments with na...
static RooAbsPdf * makePdfInstance(const char *className, const char *name, const char *expression, const RooArgList &vars, const char *intExpression=nullptr)
Write, compile and load code and instantiate object for a RooAbsPdf implementation with class name 'n...
RooClassFactory()
Default constructor.
~RooClassFactory()
Destructor.
static RooAbsReal * makeFunctionInstance(const char *className, const char *name, const char *expression, const RooArgList &vars, const char *intExpression=nullptr)
Write, compile and load code and instantiate object for a RooAbsReal implementation with class name '...
static bool makeClass(const char *className, const char *name, const char *realArgNames=nullptr, const char *catArgNames=nullptr, const char *expression="1.0", bool hasAnaInt=false, bool hasIntGen=false, const char *intExpression=nullptr)
Write code for a 'baseName' implementation with class name 'className', taking RooAbsReal arguments w...
static bool makeAndCompileFunction(const char *name, const char *expression, const RooArgList &args, const char *intExpression=nullptr)
Write, compile and load code for a RooAbsReal implementation with class name 'name',...
static bool makeFunction(const char *name, const char *realArgNames=nullptr, const char *catArgNames=nullptr, const char *expression="1.0", bool hasAnaInt=false, const char *intExpression=nullptr)
Write code for a RooAbsReal implementation with class name 'name', taking RooAbsReal arguments with n...
static bool makeAndCompilePdf(const char *name, const char *expression, const RooArgList &vars, const char *intExpression=nullptr)
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
bool importClassCode(const char *pat="*", bool doReplace=false)
Inport code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
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.
TClass * IsA() const override
void ToUpper()
Change string to upper case.
RooCmdArg Silence(bool flag=true)
void(off) SmallVectorTemplateBase< T
void init()
Inspect hardware capabilities, and load the optimal library for RooFit computations.