86 string realArgNames,catArgNames ;
90 if (dynamic_cast<RooAbsReal*>(arg)) {
91 if (realArgNames.size()>0) realArgNames +=
"," ;
92 realArgNames += arg->
GetName() ;
93 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
94 if (catArgNames.size()>0) catArgNames +=
"," ;
98 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
103 Bool_t ret = makePdf(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,
kFALSE,intExpression) ;
134 string realArgNames,catArgNames ;
138 if (dynamic_cast<RooAbsReal*>(arg)) {
139 if (realArgNames.size()>0) realArgNames +=
"," ;
140 realArgNames += arg->
GetName() ;
141 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
142 if (catArgNames.size()>0) catArgNames +=
"," ;
143 catArgNames += arg->
GetName() ;
146 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
151 Bool_t ret = makeFunction(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,intExpression) ;
189 string tmpName(name) ;
190 tmpName[0] = toupper(tmpName[0]) ;
191 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
193 return makeFunctionInstance(className.c_str(),
name,expression,vars,intExpression) ;
223 Bool_t error = makeAndCompileFunction(className,expression,vars,intExpression) ;
231 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
242 if (dynamic_cast<RooAbsReal*>(var)) {
243 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
249 if (dynamic_cast<RooAbsCategory*>(var)) {
250 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
255 line += argList +
") ;" ;
285 const RooArgList& vars,
const char* intExpression)
288 string tmpName(name) ;
289 tmpName[0] = toupper(tmpName[0]) ;
290 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
292 return makePdfInstance(className.c_str(),
name,expression,vars,intExpression) ;
316 const RooArgList& vars,
const char* intExpression)
323 Bool_t error = makeAndCompilePdf(className,expression,vars,intExpression) ;
331 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
342 if (dynamic_cast<RooAbsReal*>(var)) {
343 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
349 if (dynamic_cast<RooAbsCategory*>(var)) {
350 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
355 line += argList +
") ;" ;
382 Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
384 return makeClass(
"RooAbsPdf",name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
406 return makeClass(
"RooAbsReal",name,argNames,catArgNames,expression,hasAnaInt,
kFALSE,intExpression) ;
429 const char* expression,
Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
442 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
447 if (intExpression && !hasAnaInt) {
448 oocoutE((
TObject*)0,
InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
453 vector<string> alist ;
456 if (realArgNames && *realArgNames) {
457 const size_t bufSize = strlen(realArgNames)+1;
458 char* buf =
new char[bufSize] ;
459 strlcpy(buf,realArgNames,bufSize) ;
460 char* token = strtok(buf,
",") ;
462 alist.push_back(token) ;
463 isCat.push_back(
false) ;
464 token = strtok(0,
",") ;
468 if (catArgNames && *catArgNames) {
469 const size_t bufSize = strlen(catArgNames)+1;
470 char* buf =
new char[bufSize] ;
471 strlcpy(buf,catArgNames,bufSize) ;
472 char* token = strtok(buf,
",") ;
474 alist.push_back(token) ;
475 isCat.push_back(
true) ;
476 token = strtok(0,
",") ;
481 TString impFileName(className), hdrFileName(className) ;
482 impFileName +=
".cxx" ;
483 hdrFileName +=
".h" ;
485 TString ifdefName(className) ;
486 ifdefName.ToUpper() ;
488 ofstream hf(hdrFileName) ;
489 hf <<
"/*****************************************************************************" << endl
490 <<
" * Project: RooFit *" << endl
492 <<
" * This code was autogenerated by RooClassFactory * " << endl
493 <<
" *****************************************************************************/" << endl
495 <<
"#ifndef " << ifdefName << endl
496 <<
"#define " << ifdefName << endl
498 <<
"#include \"" << baseName <<
".h\"" << endl
499 <<
"#include \"RooRealProxy.h\"" << endl
500 <<
"#include \"RooCategoryProxy.h\"" << endl
501 <<
"#include \"RooAbsReal.h\"" << endl
502 <<
"#include \"RooAbsCategory.h\"" << endl
504 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
506 <<
" " << className <<
"() {} ; " << endl
507 <<
" " << className <<
"(const char *name, const char *title," << endl ;
511 for (i=0 ; i<alist.size() ; i++) {
513 hf <<
" RooAbsReal& _" ;
515 hf <<
" RooAbsCategory& _" ;
518 if (i==alist.size()-1) {
525 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
526 <<
" virtual TObject* clone(const char* newname) const { return new " << className <<
"(*this,newname); }" << endl
527 <<
" inline virtual ~" << className <<
"() { }" << endl
531 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;" << endl
532 <<
" Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;" << endl
537 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;" << endl
538 <<
" void initGenerator(Int_t code) {} ; // optional pre-generation initialization" << endl
539 <<
" void generateEvent(Int_t code);" << endl
543 hf <<
"protected:" << endl
547 for (i=0 ; i<alist.size() ; i++) {
549 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
551 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
556 <<
" Double_t evaluate() const ;" << endl
558 <<
"private:" << endl
560 <<
" ClassDef(" << className <<
",1) // Your description goes here..." << endl
563 <<
"#endif" << endl ;
566 ofstream cf(impFileName) ;
568 cf <<
"/***************************************************************************** " << endl
569 <<
" * Project: RooFit * " << endl
571 <<
" * This code was autogenerated by RooClassFactory * " << endl
572 <<
" *****************************************************************************/ " << endl
574 <<
"// Your description goes here... " << endl
577 <<
"#include \"Riostream.h\" " << endl
580 <<
"#include \"" << className <<
".h\" " << endl
581 <<
"#include \"RooAbsReal.h\" " << endl
582 <<
"#include \"RooAbsCategory.h\" " << endl
583 <<
"#include <math.h> " << endl
584 <<
"#include \"TMath.h\" " << endl
587 <<
"ClassImp(" << className <<
"); " << endl
590 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
593 for (i=0 ; i<alist.size() ; i++) {
595 cf <<
" RooAbsReal& _" << alist[i] ;
597 cf <<
" RooAbsCategory& _" << alist[i] ;
599 if (i<alist.size()-1) {
608 cf <<
" " << baseName <<
"(name,title), " << endl ;
611 for (i=0 ; i<alist.size() ; i++) {
612 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
613 if (i<alist.size()-1) {
624 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
625 <<
" " << baseName <<
"(other,name), " << endl ;
627 for (i=0 ; i<alist.size() ; i++) {
628 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
629 if (i<alist.size()-1) {
641 <<
" Double_t " << className <<
"::evaluate() const " << endl
643 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
644 <<
" return " << expression <<
" ; " << endl
652 vector<string> intObs ;
653 vector<string> intExpr ;
656 if (intExpression && *intExpression) {
657 const size_t bufSize = strlen(intExpression)+1;
658 char* buf =
new char[bufSize] ;
659 strlcpy(buf,intExpression,bufSize) ;
660 char* ptr = strtok(buf,
":") ;
662 intObs.push_back(ptr) ;
663 intExpr.push_back(strtok(0,
";")) ;
664 ptr = strtok(0,
":") ;
669 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
671 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
672 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
673 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
674 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
675 <<
" // EXPRESSION MULTIPLE TIMES" << endl
678 if (intObs.size()>0) {
679 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
680 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
683 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
686 cf <<
" return 0 ; " << endl
692 <<
" Double_t " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
694 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
695 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
696 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
699 if (intObs.size()>0) {
700 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
701 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
704 cf <<
" // assert(code==1) ; " << endl
705 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
708 cf <<
" return 0 ; " << endl
716 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const " << endl
718 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
719 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
720 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
721 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
722 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
723 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
724 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
726 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
727 <<
" return 0 ; " << endl
733 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
735 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
736 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
737 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
739 <<
" // assert(code==1) ; " << endl
740 <<
" // x = 0 ; " << endl
741 <<
" return; " << endl
756 static int classCounter = 0 ;
758 string tn(typeName) ;
759 if (tn==
"CEXPR" || tn==
"cexpr") {
762 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
769 strncpy(expr,args[0].c_str()+1,args[0].size()-2) ;
770 expr[args[0].size()-2]=0 ;
776 if (args.size()==2) {
778 varList.
add(ft.
asLIST(args[1].c_str())) ;
780 for (
unsigned int i=1 ; i<args.size() ; i++) {
781 varList.
add(ft.
asARG(args[i].c_str())) ;
784 }
catch (
const string &err) {
785 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
799 ret = makePdfInstance(className.c_str(),instanceName,expr,varList) ;
801 ret = makeFunctionInstance(className.c_str(),instanceName,expr,varList) ;
804 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
816 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
819 return string(instanceName) ;
virtual const char * GetName() const
Returns name of object.
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...
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
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 '...
RooClassFactory is a clase like TTree::MakeClass() that generates skeleton code for RooAbsPdf and Roo...
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.
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.
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.