88 string realArgNames,catArgNames ;
92 if (dynamic_cast<RooAbsReal*>(arg)) {
93 if (realArgNames.size()>0) realArgNames +=
"," ;
94 realArgNames += arg->
GetName() ;
95 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
96 if (catArgNames.size()>0) catArgNames +=
"," ;
100 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
105 Bool_t ret = makePdf(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,
kFALSE,intExpression) ;
136 string realArgNames,catArgNames ;
140 if (dynamic_cast<RooAbsReal*>(arg)) {
141 if (realArgNames.size()>0) realArgNames +=
"," ;
142 realArgNames += arg->
GetName() ;
143 }
else if (dynamic_cast<RooAbsCategory*>(arg)) {
144 if (catArgNames.size()>0) catArgNames +=
"," ;
145 catArgNames += arg->
GetName() ;
148 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
153 Bool_t ret = makeFunction(name,realArgNames.c_str(),catArgNames.c_str(),expression,intExpression?
kTRUE:
kFALSE,intExpression) ;
191 string tmpName(name) ;
192 tmpName[0] = toupper(tmpName[0]) ;
193 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
195 return makeFunctionInstance(className.c_str(),
name,expression,vars,intExpression) ;
225 Bool_t error = makeAndCompileFunction(className,expression,vars,intExpression) ;
233 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
244 if (dynamic_cast<RooAbsReal*>(var)) {
245 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
251 if (dynamic_cast<RooAbsCategory*>(var)) {
252 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
257 line += argList +
") ;" ;
287 const RooArgList& vars,
const char* intExpression)
290 string tmpName(name) ;
291 tmpName[0] = toupper(tmpName[0]) ;
292 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
294 return makePdfInstance(className.c_str(),
name,expression,vars,intExpression) ;
318 const RooArgList& vars,
const char* intExpression)
325 Bool_t error = makeAndCompilePdf(className,expression,vars,intExpression) ;
333 string line =
Form(
"new %s(\"%s\",\"%s\"",className,name,name) ;
344 if (dynamic_cast<RooAbsReal*>(var)) {
345 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
351 if (dynamic_cast<RooAbsCategory*>(var)) {
352 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
357 line += argList +
") ;" ;
384 Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
386 return makeClass(
"RooAbsPdf",name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
408 return makeClass(
"RooAbsReal",name,argNames,catArgNames,expression,hasAnaInt,
kFALSE,intExpression) ;
431 const char* expression,
Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
444 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
449 if (intExpression && !hasAnaInt) {
450 oocoutE((
TObject*)0,
InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
455 vector<string> alist ;
458 if (realArgNames && *realArgNames) {
459 const size_t bufSize = strlen(realArgNames)+1;
460 char* buf =
new char[bufSize] ;
461 strlcpy(buf,realArgNames,bufSize) ;
462 char* token = strtok(buf,
",") ;
464 alist.push_back(token) ;
465 isCat.push_back(
false) ;
466 token = strtok(0,
",") ;
470 if (catArgNames && *catArgNames) {
471 const size_t bufSize = strlen(catArgNames)+1;
472 char* buf =
new char[bufSize] ;
473 strlcpy(buf,catArgNames,bufSize) ;
474 char* token = strtok(buf,
",") ;
476 alist.push_back(token) ;
477 isCat.push_back(
true) ;
478 token = strtok(0,
",") ;
483 TString impFileName(className), hdrFileName(className) ;
484 impFileName +=
".cxx" ;
485 hdrFileName +=
".h" ;
487 TString ifdefName(className) ;
488 ifdefName.ToUpper() ;
490 ofstream hf(hdrFileName) ;
491 hf <<
"/*****************************************************************************" << endl
492 <<
" * Project: RooFit *" << endl
494 <<
" * This code was autogenerated by RooClassFactory * " << endl
495 <<
" *****************************************************************************/" << endl
497 <<
"#ifndef " << ifdefName << endl
498 <<
"#define " << ifdefName << endl
500 <<
"#include \"" << baseName <<
".h\"" << endl
501 <<
"#include \"RooRealProxy.h\"" << endl
502 <<
"#include \"RooCategoryProxy.h\"" << endl
503 <<
"#include \"RooAbsReal.h\"" << endl
504 <<
"#include \"RooAbsCategory.h\"" << endl
506 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
508 <<
" " << className <<
"() {} ; " << endl
509 <<
" " << className <<
"(const char *name, const char *title," << endl ;
513 for (i=0 ; i<alist.size() ; i++) {
515 hf <<
" RooAbsReal& _" ;
517 hf <<
" RooAbsCategory& _" ;
520 if (i==alist.size()-1) {
527 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
528 <<
" virtual TObject* clone(const char* newname) const { return new " << className <<
"(*this,newname); }" << endl
529 <<
" inline virtual ~" << className <<
"() { }" << endl
533 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;" << endl
534 <<
" Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;" << endl
539 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;" << endl
540 <<
" void initGenerator(Int_t code) {} ; // optional pre-generation initialization" << endl
541 <<
" void generateEvent(Int_t code);" << endl
545 hf <<
"protected:" << endl
549 for (i=0 ; i<alist.size() ; i++) {
551 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
553 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
558 <<
" Double_t evaluate() const ;" << endl
560 <<
"private:" << endl
562 <<
" ClassDef(" << className <<
",1) // Your description goes here..." << endl
565 <<
"#endif" << endl ;
568 ofstream cf(impFileName) ;
570 cf <<
"/***************************************************************************** " << endl
571 <<
" * Project: RooFit * " << endl
573 <<
" * This code was autogenerated by RooClassFactory * " << endl
574 <<
" *****************************************************************************/ " << endl
576 <<
"// Your description goes here... " << endl
579 <<
"#include \"Riostream.h\" " << endl
582 <<
"#include \"" << className <<
".h\" " << endl
583 <<
"#include \"RooAbsReal.h\" " << endl
584 <<
"#include \"RooAbsCategory.h\" " << endl
585 <<
"#include <math.h> " << endl
586 <<
"#include \"TMath.h\" " << endl
589 <<
"ClassImp(" << className <<
"); " << endl
592 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
595 for (i=0 ; i<alist.size() ; i++) {
597 cf <<
" RooAbsReal& _" << alist[i] ;
599 cf <<
" RooAbsCategory& _" << alist[i] ;
601 if (i<alist.size()-1) {
610 cf <<
" " << baseName <<
"(name,title), " << endl ;
613 for (i=0 ; i<alist.size() ; i++) {
614 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
615 if (i<alist.size()-1) {
626 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
627 <<
" " << baseName <<
"(other,name), " << endl ;
629 for (i=0 ; i<alist.size() ; i++) {
630 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
631 if (i<alist.size()-1) {
643 <<
" Double_t " << className <<
"::evaluate() const " << endl
645 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
646 <<
" return " << expression <<
" ; " << endl
654 vector<string> intObs ;
655 vector<string> intExpr ;
658 if (intExpression && *intExpression) {
659 const size_t bufSize = strlen(intExpression)+1;
660 char* buf =
new char[bufSize] ;
661 strlcpy(buf,intExpression,bufSize) ;
662 char* ptr = strtok(buf,
":") ;
664 intObs.push_back(ptr) ;
665 intExpr.push_back(strtok(0,
";")) ;
666 ptr = strtok(0,
":") ;
671 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
673 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
674 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
675 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
676 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
677 <<
" // EXPRESSION MULTIPLE TIMES" << endl
680 if (intObs.size()>0) {
681 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
682 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
685 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
688 cf <<
" return 0 ; " << endl
694 <<
" Double_t " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
696 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
697 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
698 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
701 if (intObs.size()>0) {
702 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
703 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
706 cf <<
" // assert(code==1) ; " << endl
707 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
710 cf <<
" return 0 ; " << endl
718 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const " << endl
720 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
721 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
722 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
723 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
724 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
725 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
726 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
728 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
729 <<
" return 0 ; " << endl
735 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
737 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
738 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
739 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
741 <<
" // assert(code==1) ; " << endl
742 <<
" // x = 0 ; " << endl
743 <<
" return; " << endl
758 static int classCounter = 0 ;
760 string tn(typeName) ;
761 if (tn==
"CEXPR" || tn==
"cexpr") {
764 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
771 strncpy(expr,args[0].c_str()+1,args[0].size()-2) ;
772 expr[args[0].size()-2]=0 ;
778 if (args.size()==2) {
780 varList.
add(ft.
asLIST(args[1].c_str())) ;
782 for (
unsigned int i=1 ; i<args.size() ; i++) {
783 varList.
add(ft.
asARG(args[i].c_str())) ;
786 }
catch (
string err) {
787 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
801 ret = makePdfInstance(className.c_str(),instanceName,expr,varList) ;
803 ret = makeFunctionInstance(className.c_str(),instanceName,expr,varList) ;
806 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
818 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
821 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.