87 string realArgNames,catArgNames ;
91 if (dynamic_cast<RooAbsReal*>(arg)) {
92 if (realArgNames.size()>0) realArgNames +=
"," ;
93 realArgNames += arg->
GetName() ;
94 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
95 if (catArgNames.size()>0) catArgNames +=
"," ;
99 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
104 Bool_t ret = makePdf(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,
kFALSE,intExpression) ;
135 string realArgNames,catArgNames ;
139 if (dynamic_cast<RooAbsReal*>(arg)) {
140 if (realArgNames.size()>0) realArgNames +=
"," ;
141 realArgNames += arg->
GetName() ;
142 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
143 if (catArgNames.size()>0) catArgNames +=
"," ;
144 catArgNames += arg->
GetName() ;
147 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
152 Bool_t ret = makeFunction(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,intExpression) ;
190 string tmpName(name) ;
191 tmpName[0] = toupper(tmpName[0]) ;
192 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
194 return makeFunctionInstance(className.c_str(),
name,expression,vars,intExpression) ;
224 Bool_t error = makeAndCompileFunction(className,expression,vars,intExpression) ;
232 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
243 if (dynamic_cast<RooAbsReal*>(var)) {
244 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
250 if (dynamic_cast<RooAbsCategory*>(var)) {
251 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
256 line += argList +
") ;" ;
286 const RooArgList& vars,
const char* intExpression)
289 string tmpName(name) ;
290 tmpName[0] = toupper(tmpName[0]) ;
291 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
293 return makePdfInstance(className.c_str(),
name,expression,vars,intExpression) ;
317 const RooArgList& vars,
const char* intExpression)
324 Bool_t error = makeAndCompilePdf(className,expression,vars,intExpression) ;
332 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
343 if (dynamic_cast<RooAbsReal*>(var)) {
344 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
350 if (dynamic_cast<RooAbsCategory*>(var)) {
351 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
356 line += argList +
") ;" ;
383 Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
385 return makeClass(
"RooAbsPdf",name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
407 return makeClass(
"RooAbsReal",name,argNames,catArgNames,expression,hasAnaInt,
kFALSE,intExpression) ;
430 const char* expression,
Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
443 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
448 if (intExpression && !hasAnaInt) {
449 oocoutE((
TObject*)0,
InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
454 vector<string> alist ;
457 if (realArgNames && *realArgNames) {
458 const size_t bufSize = strlen(realArgNames)+1;
459 char* buf =
new char[bufSize] ;
460 strlcpy(buf,realArgNames,bufSize) ;
461 char* token = strtok(buf,
",") ;
463 alist.push_back(token) ;
464 isCat.push_back(
false) ;
465 token = strtok(0,
",") ;
469 if (catArgNames && *catArgNames) {
470 const size_t bufSize = strlen(catArgNames)+1;
471 char* buf =
new char[bufSize] ;
472 strlcpy(buf,catArgNames,bufSize) ;
473 char* token = strtok(buf,
",") ;
475 alist.push_back(token) ;
476 isCat.push_back(
true) ;
477 token = strtok(0,
",") ;
482 TString impFileName(className), hdrFileName(className) ;
483 impFileName +=
".cxx" ;
484 hdrFileName +=
".h" ;
489 ofstream hf(hdrFileName) ;
490 hf <<
"/*****************************************************************************" << endl
491 <<
" * Project: RooFit *" << endl
493 <<
" * This code was autogenerated by RooClassFactory * " << endl
494 <<
" *****************************************************************************/" << endl
496 <<
"#ifndef " << ifdefName << endl
497 <<
"#define " << ifdefName << endl
499 <<
"#include \"" << baseName <<
".h\"" << endl
500 <<
"#include \"RooRealProxy.h\"" << endl
501 <<
"#include \"RooCategoryProxy.h\"" << endl
502 <<
"#include \"RooAbsReal.h\"" << endl
503 <<
"#include \"RooAbsCategory.h\"" << endl
505 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
507 <<
" " << className <<
"() {} ; " << endl
508 <<
" " << className <<
"(const char *name, const char *title," << endl ;
512 for (i=0 ; i<alist.size() ; i++) {
514 hf <<
" RooAbsReal& _" ;
516 hf <<
" RooAbsCategory& _" ;
519 if (i==alist.size()-1) {
526 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
527 <<
" virtual TObject* clone(const char* newname) const { return new " << className <<
"(*this,newname); }" << endl
528 <<
" inline virtual ~" << className <<
"() { }" << endl
532 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;" << endl
533 <<
" Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;" << endl
538 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;" << endl
539 <<
" void initGenerator(Int_t code) {} ; // optional pre-generation initialization" << endl
540 <<
" void generateEvent(Int_t code);" << endl
544 hf <<
"protected:" << endl
548 for (i=0 ; i<alist.size() ; i++) {
550 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
552 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
557 <<
" Double_t evaluate() const ;" << endl
559 <<
"private:" << endl
561 <<
" ClassDef(" << className <<
",1) // Your description goes here..." << endl
564 <<
"#endif" << endl ;
567 ofstream cf(impFileName) ;
569 cf <<
"/***************************************************************************** " << endl
570 <<
" * Project: RooFit * " << endl
572 <<
" * This code was autogenerated by RooClassFactory * " << endl
573 <<
" *****************************************************************************/ " << endl
575 <<
"// Your description goes here... " << endl
578 <<
"#include \"Riostream.h\" " << endl
581 <<
"#include \"" << className <<
".h\" " << endl
582 <<
"#include \"RooAbsReal.h\" " << endl
583 <<
"#include \"RooAbsCategory.h\" " << endl
584 <<
"#include <math.h> " << endl
585 <<
"#include \"TMath.h\" " << endl
588 <<
"ClassImp(" << className <<
") " << endl
591 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
594 for (i=0 ; i<alist.size() ; i++) {
596 cf <<
" RooAbsReal& _" << alist[i] ;
598 cf <<
" RooAbsCategory& _" << alist[i] ;
600 if (i<alist.size()-1) {
609 cf <<
" " << baseName <<
"(name,title), " << endl ;
612 for (i=0 ; i<alist.size() ; i++) {
613 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
614 if (i<alist.size()-1) {
625 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
626 <<
" " << baseName <<
"(other,name), " << endl ;
628 for (i=0 ; i<alist.size() ; i++) {
629 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
630 if (i<alist.size()-1) {
642 <<
" Double_t " << className <<
"::evaluate() const " << endl
644 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
645 <<
" return " << expression <<
" ; " << endl
653 vector<string> intObs ;
654 vector<string> intExpr ;
657 if (intExpression && *intExpression) {
658 const size_t bufSize = strlen(intExpression)+1;
659 char* buf =
new char[bufSize] ;
660 strlcpy(buf,intExpression,bufSize) ;
661 char* ptr = strtok(buf,
":") ;
663 intObs.push_back(ptr) ;
664 intExpr.push_back(strtok(0,
";")) ;
665 ptr = strtok(0,
":") ;
670 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
672 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
673 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
674 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
675 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
676 <<
" // EXPRESSION MULTIPLE TIMES" << endl
679 if (intObs.size()>0) {
680 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
681 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
684 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
687 cf <<
" return 0 ; " << endl
693 <<
" Double_t " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
695 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
696 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
697 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
700 if (intObs.size()>0) {
701 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
702 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
705 cf <<
" // assert(code==1) ; " << endl
706 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
709 cf <<
" return 0 ; " << endl
717 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const " << endl
719 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
720 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
721 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
722 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
723 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
724 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
725 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
727 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
728 <<
" return 0 ; " << endl
734 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
736 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
737 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
738 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
740 <<
" // assert(code==1) ; " << endl
741 <<
" // x = 0 ; " << endl
742 <<
" return; " << endl
757 static int classCounter = 0 ;
759 string tn(typeName) ;
760 if (tn==
"CEXPR" || tn==
"cexpr") {
763 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
770 strncpy(expr,args[0].c_str()+1,args[0].size()-2) ;
771 expr[args[0].size()-2]=0 ;
777 if (args.size()==2) {
779 varList.
add(ft.
asLIST(args[1].c_str())) ;
781 for (
unsigned int i=1 ; i<args.size() ; i++) {
782 varList.
add(ft.
asARG(args[i].c_str())) ;
785 }
catch (
string err) {
786 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
800 ret = makePdfInstance(className.c_str(),instanceName,expr,varList) ;
802 ret = makeFunctionInstance(className.c_str(),instanceName,expr,varList) ;
805 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
817 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
820 return string(instanceName) ;
static RooAbsPdf * makePdfInstance(const char *className, const char *name, const char *expression, const RooArgList &vars, const char *intExpression=0)
Write, compile and load code and instantiate object for a RooAbsPdf implementation with class name 'n...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void ToUpper()
Change string to upper case.
Iterator abstract base class.
Bool_t importClassCode(const char *pat="*", Bool_t doReplace=kFALSE)
Inport code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
static RooAbsReal * makeFunctionInstance(const char *className, const char *name, const char *expression, const RooArgList &vars, const char *intExpression=0)
Write, compile and load code and instantiate object for a RooAbsReal implementation with class name '...
std::map< std::string, std::string >::const_iterator iter
TIterator * createIterator(Bool_t dir=kIterForward) const
RooCmdArg Silence(Bool_t flag=kTRUE)
static Bool_t makePdf(const char *name, const char *realArgNames=0, const char *catArgNames=0, const char *expression="1.0", Bool_t hasAnaInt=kFALSE, Bool_t hasIntGen=kFALSE, const char *intExpression=0)
Write code for a RooAbsPdf implementation with class name 'name', taking RooAbsReal arguments with na...
static Bool_t makeFunction(const char *name, const char *realArgNames=0, const char *catArgNames=0, const char *expression="1.0", Bool_t hasAnaInt=kFALSE, const char *intExpression=0)
Write code for a RooAbsReal implementation with class name 'name', taking RooAbsReal arguments with n...
char * Form(const char *fmt,...)
RooClassFactory()
Default constructor.
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
static Bool_t makeAndCompilePdf(const char *name, const char *expression, const RooArgList &vars, const char *intExpression=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.
ClassImp(RooClassFactory)
Mother of all ROOT objects.
typedef void((*Func_t)())
std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Bool_t 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.
virtual TObject * Next()=0
virtual ~RooClassFactory()
Destructor.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
static Bool_t makeClass(const char *className, const char *name, const char *realArgNames=0, const char *catArgNames=0, const char *expression="1.0", Bool_t hasAnaInt=kFALSE, Bool_t hasIntGen=kFALSE, const char *intExpression=0)
Write code for a 'baseName' implementation with class name 'className', taking RooAbsReal arguments w...
static Bool_t makeAndCompileFunction(const char *name, const char *expression, const RooArgList &args, const char *intExpression=0)
Write, compile and load code for a RooAbsReal implementation with class name 'name', taking all elements of 'vars' as constructor arguments.