88 string realArgNames,catArgNames ;
93 if (realArgNames.size()>0) realArgNames +=
"," ;
94 realArgNames += arg->
GetName() ;
96 if (catArgNames.size()>0) catArgNames +=
"," ;
99 oocoutE((
RooAbsArg*)0,InputArguments) <<
"RooClassFactory::makeAndCompilePdf ERROR input argument " << arg->
GetName()
100 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
132 string realArgNames,catArgNames ;
137 if (realArgNames.size()>0) realArgNames +=
"," ;
138 realArgNames += arg->
GetName() ;
140 if (catArgNames.size()>0) catArgNames +=
"," ;
141 catArgNames += arg->
GetName() ;
143 oocoutE((
RooAbsArg*)0,InputArguments) <<
"RooClassFactory::makeAndCompileFunction ERROR input argument " << arg->
GetName()
144 <<
" is neither RooAbsReal nor RooAbsCategory and is ignored" << endl ;
183 string tmpName(
name) ;
184 tmpName[0] = toupper(tmpName[0]) ;
185 string className =
Form(
"Roo%sFunc",tmpName.c_str()) ;
233 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
240 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
245 line += argList +
") ;" ;
275 const RooArgList& vars,
const char* intExpression)
278 string tmpName(
name) ;
279 tmpName[0] = toupper(tmpName[0]) ;
280 string className =
Form(
"Roo%sPdf",tmpName.c_str()) ;
306 const RooArgList& vars,
const char* intExpression)
329 argList +=
Form(
",*((RooAbsReal*)0x%lx)",(
ULong_t)var) ;
336 argList +=
Form(
",*((RooAbsCategory*)0x%lx)",(
ULong_t)var) ;
341 line += argList +
") ;" ;
368 Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
370 return makeClass(
"RooAbsPdf",
name,argNames,catArgNames,expression,hasAnaInt,hasIntGen,intExpression) ;
392 return makeClass(
"RooAbsReal",
name,argNames,catArgNames,expression,hasAnaInt,
kFALSE,intExpression) ;
415 const char* expression,
Bool_t hasAnaInt,
Bool_t hasIntGen,
const char* intExpression)
419 oocoutE((
TObject*)0,InputArguments) <<
"RooClassFactory::makeClass: ERROR: a base class name must be given" << endl ;
424 oocoutE((
TObject*)0,InputArguments) <<
"RooClassFactory::makeClass: ERROR: a class name must be given" << endl ;
428 if ((!realArgNames || !*realArgNames) && (!catArgNames || !*catArgNames)) {
429 oocoutE((
TObject*)0,InputArguments) <<
"RooClassFactory::makeClass: ERROR: A list of input argument names must be given" << endl ;
433 if (intExpression && !hasAnaInt) {
434 oocoutE((
TObject*)0,InputArguments) <<
"RooClassFactory::makeClass: ERROR no analytical integration code requestion, but expression for analytical integral provided" << endl ;
439 vector<string> alist ;
442 if (realArgNames && *realArgNames) {
443 const size_t bufSize = strlen(realArgNames)+1;
444 char* buf =
new char[bufSize] ;
445 strlcpy(buf,realArgNames,bufSize) ;
446 char* token = strtok(buf,
",") ;
448 alist.push_back(token) ;
449 isCat.push_back(
false) ;
450 token = strtok(0,
",") ;
454 if (catArgNames && *catArgNames) {
455 const size_t bufSize = strlen(catArgNames)+1;
456 char* buf =
new char[bufSize] ;
457 strlcpy(buf,catArgNames,bufSize) ;
458 char* token = strtok(buf,
",") ;
460 alist.push_back(token) ;
461 isCat.push_back(
true) ;
462 token = strtok(0,
",") ;
467 TString impFileName(className), hdrFileName(className) ;
468 impFileName +=
".cxx" ;
469 hdrFileName +=
".h" ;
474 ofstream hf(hdrFileName) ;
475 hf <<
"/*****************************************************************************" << endl
476 <<
" * Project: RooFit *" << endl
478 <<
" * This code was autogenerated by RooClassFactory * " << endl
479 <<
" *****************************************************************************/" << endl
481 <<
"#ifndef " << ifdefName << endl
482 <<
"#define " << ifdefName << endl
484 <<
"#include \"" << baseName <<
".h\"" << endl
485 <<
"#include \"RooRealProxy.h\"" << endl
486 <<
"#include \"RooCategoryProxy.h\"" << endl
487 <<
"#include \"RooAbsReal.h\"" << endl
488 <<
"#include \"RooAbsCategory.h\"" << endl
490 <<
"class " << className <<
" : public " << baseName <<
" {" << endl
492 <<
" " << className <<
"() {} ; " << endl
493 <<
" " << className <<
"(const char *name, const char *title," << endl ;
497 for (i=0 ; i<alist.size() ; i++) {
499 hf <<
" RooAbsReal& _" ;
501 hf <<
" RooAbsCategory& _" ;
504 if (i==alist.size()-1) {
511 hf <<
" " << className <<
"(const " << className <<
"& other, const char* name=0) ;" << endl
512 <<
" virtual TObject* clone(const char* newname) const { return new " << className <<
"(*this,newname); }" << endl
513 <<
" inline virtual ~" << className <<
"() { }" << endl
517 hf <<
" Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;" << endl
518 <<
" Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;" << endl
523 hf <<
" Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;" << endl
524 <<
" void initGenerator(Int_t code) {} ; // optional pre-generation initialization" << endl
525 <<
" void generateEvent(Int_t code);" << endl
529 hf <<
"protected:" << endl
533 for (i=0 ; i<alist.size() ; i++) {
535 hf <<
" RooRealProxy " << alist[i] <<
" ;" << endl ;
537 hf <<
" RooCategoryProxy " << alist[i] <<
" ;" << endl ;
542 <<
" Double_t evaluate() const ;" << endl
544 <<
"private:" << endl
546 <<
" ClassDef(" << className <<
",1) // Your description goes here..." << endl
549 <<
"#endif" << endl ;
552 ofstream cf(impFileName) ;
554 cf <<
"/***************************************************************************** " << endl
555 <<
" * Project: RooFit * " << endl
557 <<
" * This code was autogenerated by RooClassFactory * " << endl
558 <<
" *****************************************************************************/ " << endl
560 <<
"// Your description goes here... " << endl
563 <<
"#include \"Riostream.h\" " << endl
566 <<
"#include \"" << className <<
".h\" " << endl
567 <<
"#include \"RooAbsReal.h\" " << endl
568 <<
"#include \"RooAbsCategory.h\" " << endl
569 <<
"#include <math.h> " << endl
570 <<
"#include \"TMath.h\" " << endl
573 <<
"ClassImp(" << className <<
"); " << endl
576 <<
" " << className <<
"::" << className <<
"(const char *name, const char *title, " << endl ;
579 for (i=0 ; i<alist.size() ; i++) {
581 cf <<
" RooAbsReal& _" << alist[i] ;
583 cf <<
" RooAbsCategory& _" << alist[i] ;
585 if (i<alist.size()-1) {
594 cf <<
" " << baseName <<
"(name,title), " << endl ;
597 for (i=0 ; i<alist.size() ; i++) {
598 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",\"" << alist[i] <<
"\",this,_" << alist[i] <<
")" ;
599 if (i<alist.size()-1) {
610 <<
" " << className <<
"::" << className <<
"(const " << className <<
"& other, const char* name) : " << endl
611 <<
" " << baseName <<
"(other,name), " << endl ;
613 for (i=0 ; i<alist.size() ; i++) {
614 cf <<
" " << alist[i] <<
"(\"" << alist[i] <<
"\",this,other." << alist[i] <<
")" ;
615 if (i<alist.size()-1) {
627 <<
" Double_t " << className <<
"::evaluate() const " << endl
629 <<
" // ENTER EXPRESSION IN TERMS OF VARIABLE ARGUMENTS HERE " << endl
630 <<
" return " << expression <<
" ; " << endl
638 vector<string> intObs ;
639 vector<string> intExpr ;
642 if (intExpression && *intExpression) {
643 const size_t bufSize = strlen(intExpression)+1;
644 char* buf =
new char[bufSize] ;
645 strlcpy(buf,intExpression,bufSize) ;
646 char* ptr = strtok(buf,
":") ;
648 intObs.push_back(ptr) ;
649 intExpr.push_back(strtok(0,
";")) ;
650 ptr = strtok(0,
":") ;
655 cf <<
" Int_t " << className <<
"::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const " << endl
657 <<
" // LIST HERE OVER WHICH VARIABLES ANALYTICAL INTEGRATION IS SUPPORTED, " << endl
658 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
659 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
660 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE ANALYTICAL INTEGRAL BY REPEATING THE matchArgs " << endl
661 <<
" // EXPRESSION MULTIPLE TIMES" << endl
664 if (intObs.size()>0) {
665 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
666 cf <<
" if (matchArgs(allVars,analVars," << intObs[ii] <<
")) return " << ii+1 <<
" ; " << endl ;
669 cf <<
" // if (matchArgs(allVars,analVars,x)) return 1 ; " << endl ;
672 cf <<
" return 0 ; " << endl
678 <<
" Double_t " << className <<
"::analyticalIntegral(Int_t code, const char* rangeName) const " << endl
680 <<
" // RETURN ANALYTICAL INTEGRAL DEFINED BY RETURN CODE ASSIGNED BY getAnalyticalIntegral" << endl
681 <<
" // THE MEMBER FUNCTION x.min(rangeName) AND x.max(rangeName) WILL RETURN THE INTEGRATION" << endl
682 <<
" // BOUNDARIES FOR EACH OBSERVABLE x" << endl
685 if (intObs.size()>0) {
686 for (
UInt_t ii=0 ; ii<intObs.size() ; ii++) {
687 cf <<
" if (code==" << ii+1 <<
") { return (" << intExpr[ii] <<
") ; } " << endl ;
690 cf <<
" // assert(code==1) ; " << endl
691 <<
" // return (x.max(rangeName)-x.min(rangeName)) ; " << endl ;
694 cf <<
" return 0 ; " << endl
702 cf <<
" Int_t " << className <<
"::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const " << endl
704 <<
" // LIST HERE OVER WHICH VARIABLES INTERNAL GENERATION IS SUPPORTED, " << endl
705 <<
" // ASSIGN A NUMERIC CODE FOR EACH SUPPORTED (SET OF) PARAMETERS " << endl
706 <<
" // THE EXAMPLE BELOW ASSIGNS CODE 1 TO INTEGRATION OVER VARIABLE X" << endl
707 <<
" // YOU CAN ALSO IMPLEMENT MORE THAN ONE GENERATOR CONFIGURATION BY REPEATING THE matchArgs " << endl
708 <<
" // EXPRESSION MULTIPLE TIMES. IF THE FLAG staticInitOK IS TRUE THEN IT IS SAFE TO PRECALCULATE " << endl
709 <<
" // INTERMEDIATE QUANTITIES IN initGenerator(), IF IT IS NOT SET THEN YOU SHOULD NOT ADVERTISE" << endl
710 <<
" // ANY GENERATOR METHOD THAT RELIES ON PRECALCULATIONS IN initGenerator()" << endl
712 <<
" // if (matchArgs(directVars,generateVars,x)) return 1 ; " << endl
713 <<
" return 0 ; " << endl
719 <<
" void " << className <<
"::generateEvent(Int_t code) " << endl
721 <<
" // GENERATE SET OF OBSERVABLES DEFINED BY RETURN CODE ASSIGNED BY getGenerator()" << endl
722 <<
" // RETURN THE GENERATED VALUES BY ASSIGNING THEM TO THE PROXY DATA MEMBERS THAT" << endl
723 <<
" // REPRESENT THE CHOSEN OBSERVABLES" << endl
725 <<
" // assert(code==1) ; " << endl
726 <<
" // x = 0 ; " << endl
727 <<
" return; " << endl
742 static int classCounter = 0 ;
744 string tn(typeName) ;
745 if (tn==
"CEXPR" || tn==
"cexpr") {
748 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: CEXPR requires at least 2 arguments (expr,var,...), but only %u args found",
755 strncpy(expr,args[0].c_str()+1,args[0].size()-2) ;
756 expr[args[0].size()-2]=0 ;
762 if (args.size()==2) {
764 varList.
add(ft.
asLIST(args[1].c_str())) ;
766 for (
unsigned int i=1 ; i<args.size() ; i++) {
767 varList.
add(ft.
asARG(args[i].c_str())) ;
770 }
catch (
const string &err) {
771 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: %s",err.c_str())) ;
790 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR creating %s %s with RooClassFactory",((tn==
"CEXPR")?
"pdf":
"function"),instanceName)) ;
802 throw string(
Form(
"RooClassFactory::ClassFacIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
805 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 and a "shape" in RooFi...
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
TIterator * createIterator(Bool_t dir=kIterForward) const
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)