86 string realArgNames,catArgNames ;
91 if (realArgNames.size()>0) realArgNames +=
"," ;
92 realArgNames += arg->
GetName() ;
94 if (catArgNames.size()>0) catArgNames +=
"," ;
98 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
130 string realArgNames,catArgNames ;
135 if (realArgNames.size()>0) realArgNames +=
"," ;
136 realArgNames += arg->
GetName() ;
138 if (catArgNames.size()>0) catArgNames +=
"," ;
139 catArgNames += arg->
GetName() ;
142 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
181 string tmpName(
name) ;
182 tmpName[0] = toupper(tmpName[0]) ;
183 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
231 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
238 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
243 line += argList +
") ;" ;
273 const RooArgList& vars,
const char* intExpression)
276 string tmpName(
name) ;
277 tmpName[0] = toupper(tmpName[0]) ;
278 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
304 const RooArgList& vars,
const char* intExpression)
327 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
334 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
339 line += argList +
") ;" ;
366 Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
368 return makeClass(
"RooAbsPdf",
name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
390 return makeClass(
"RooAbsReal",
name,argNames,catArgNames,expression,hasAnaInt,
kFALSE,intExpression) ;
413 const char* expression,
Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
426 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
431 if (intExpression && !hasAnaInt) {
432 oocoutE((
TObject*)0,
InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
437 vector<string> alist ;
440 if (realArgNames && *realArgNames) {
441 const size_t bufSize = strlen(realArgNames)+1;
442 char* buf =
new char[bufSize] ;
443 strlcpy(buf,realArgNames,bufSize) ;
444 char* token = strtok(buf,
",") ;
446 alist.push_back(token) ;
447 isCat.push_back(
false) ;
448 token = strtok(0,
",") ;
452 if (catArgNames && *catArgNames) {
453 const size_t bufSize = strlen(catArgNames)+1;
454 char* buf =
new char[bufSize] ;
455 strlcpy(buf,catArgNames,bufSize) ;
456 char* token = strtok(buf,
",") ;
458 alist.push_back(token) ;
459 isCat.push_back(
true) ;
460 token = strtok(0,
",") ;
465 TString impFileName(className), hdrFileName(className) ;
466 impFileName +=
".cxx" ;
467 hdrFileName +=
".h" ;
472 ofstream hf(hdrFileName) ;
473 hf <<
"/*****************************************************************************" << endl
474 <<
" * Project: RooFit *" << endl
476 <<
" * This code was autogenerated by RooClassFactory * " << endl
477 <<
" *****************************************************************************/" << endl
479 <<
"#ifndef " << ifdefName << endl
480 <<
"#define " << ifdefName << endl
482 <<
"#include \"" << baseName <<
".h\"" << endl
483 <<
"#include \"RooRealProxy.h\"" << endl
484 <<
"#include \"RooCategoryProxy.h\"" << endl
485 <<
"#include \"RooAbsReal.h\"" << endl
486 <<
"#include \"RooAbsCategory.h\"" << endl
488 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
490 <<
" " << className <<
"() {} ; " << endl
491 <<
" " << className <<
"(const char *name, const char *title," << endl ;
495 for (i=0 ; i<alist.size() ; i++) {
497 hf <<
" RooAbsReal& _" ;
499 hf <<
" RooAbsCategory& _" ;
502 if (i==alist.size()-1) {
509 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
510 <<
" virtual TObject* clone(const char* newname) const { return new " << className <<
"(*this,newname); }" << endl
511 <<
" inline virtual ~" << className <<
"() { }" << endl
515 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;" << endl
516 <<
" Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;" << endl
521 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;" << endl
522 <<
" void initGenerator(Int_t code) {} ; // optional pre-generation initialization" << endl
523 <<
" void generateEvent(Int_t code);" << endl
527 hf <<
"protected:" << endl
531 for (i=0 ; i<alist.size() ; i++) {
533 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
535 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
540 <<
" Double_t evaluate() const ;" << endl
542 <<
"private:" << endl
544 <<
" ClassDef(" << className <<
",1) // Your description goes here..." << endl
547 <<
"#endif" << endl ;
550 ofstream cf(impFileName) ;
552 cf <<
"/***************************************************************************** " << endl
553 <<
" * Project: RooFit * " << endl
555 <<
" * This code was autogenerated by RooClassFactory * " << endl
556 <<
" *****************************************************************************/ " << endl
558 <<
"// Your description goes here... " << endl
561 <<
"#include \"Riostream.h\" " << endl
564 <<
"#include \"" << className <<
".h\" " << endl
565 <<
"#include \"RooAbsReal.h\" " << endl
566 <<
"#include \"RooAbsCategory.h\" " << endl
567 <<
"#include <math.h> " << endl
568 <<
"#include \"TMath.h\" " << endl
571 <<
"ClassImp(" << className <<
"); " << endl
574 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
577 for (i=0 ; i<alist.size() ; i++) {
579 cf <<
" RooAbsReal& _" << alist[i] ;
581 cf <<
" RooAbsCategory& _" << alist[i] ;
583 if (i<alist.size()-1) {
592 cf <<
" " << baseName <<
"(name,title), " << endl ;
595 for (i=0 ; i<alist.size() ; i++) {
596 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
597 if (i<alist.size()-1) {
608 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
609 <<
" " << baseName <<
"(other,name), " << endl ;
611 for (i=0 ; i<alist.size() ; i++) {
612 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
613 if (i<alist.size()-1) {
625 <<
" Double_t " << className <<
"::evaluate() const " << endl
627 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
628 <<
" return " << expression <<
" ; " << endl
636 vector<string> intObs ;
637 vector<string> intExpr ;
640 if (intExpression && *intExpression) {
641 const size_t bufSize = strlen(intExpression)+1;
642 char* buf =
new char[bufSize] ;
643 strlcpy(buf,intExpression,bufSize) ;
644 char* ptr = strtok(buf,
":") ;
646 intObs.push_back(ptr) ;
647 intExpr.push_back(strtok(0,
";")) ;
648 ptr = strtok(0,
":") ;
653 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
655 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
656 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
657 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
658 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
659 <<
" // EXPRESSION MULTIPLE TIMES" << endl
662 if (intObs.size()>0) {
663 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
664 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
667 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
670 cf <<
" return 0 ; " << endl
676 <<
" Double_t " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
678 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
679 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
680 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
683 if (intObs.size()>0) {
684 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
685 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
688 cf <<
" // assert(code==1) ; " << endl
689 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
692 cf <<
" return 0 ; " << endl
700 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const " << endl
702 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
703 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
704 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
705 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
706 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
707 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
708 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
710 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
711 <<
" return 0 ; " << endl
717 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
719 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
720 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
721 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
723 <<
" // assert(code==1) ; " << endl
724 <<
" // x = 0 ; " << endl
725 <<
" return; " << endl
740 static int classCounter = 0 ;
742 string tn(typeName) ;
743 if (tn==
"CEXPR" || tn==
"cexpr") {
746 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
753 strncpy(expr,args[0].c_str()+1,args[0].size()-2) ;
754 expr[args[0].size()-2]=0 ;
760 if (args.size()==2) {
762 varList.
add(ft.
asLIST(args[1].c_str())) ;
764 for (
unsigned int i=1 ; i<args.size() ; i++) {
765 varList.
add(ft.
asARG(args[i].c_str())) ;
768 }
catch (
const string &err) {
769 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
788 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
800 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
803 return string(instanceName) ;
char * Form(const char *fmt,...)
typedef void((*Func_t)())
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
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.
std::string create(RooFactoryWSTool &ft, const char *typeName, const char *instanceName, std::vector< std::string > args)
RooClassFactory is a clase like TTree::MakeClass() that generates skeleton code for RooAbsPdf and Roo...
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',...
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 '...
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...
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...
RooClassFactory()
Default constructor.
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 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...
virtual ~RooClassFactory()
Destructor.
static Bool_t makeAndCompilePdf(const char *name, const char *expression, const RooArgList &vars, const char *intExpression=0)
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...
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.
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.
Iterator abstract base class.
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
void ToUpper()
Change string to upper case.
RooCmdArg Silence(Bool_t flag=kTRUE)