175using std::endl, std::ostream, std::string;
183 std::string create(RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
override ;
189Int_t dummy = init() ;
284 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArgs(" <<
_name
285 <<
") ERROR cannot set spitting rules on this sterile customizer" << std::endl ;
289 for (
auto arg :
set) {
307 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer(" <<
_masterPdf->GetName() <<
") ERROR: multiple splitting rules defined for "
308 << arg.
GetName() <<
" only using first rule" << std::endl ;
313 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArg(" <<
_name
314 <<
") ERROR cannot set spitting rules on this sterile customizer" << std::endl ;
330 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer(" <<
_masterPdf->GetName() <<
") ERROR: multiple replacement rules defined for "
331 << orig.
GetName() <<
" only using first rule" << std::endl ;
366 if (!allOwned.
empty()) {
367 ret->addOwnedComponents(allOwned) ;
386 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_name
387 <<
") ERROR cannot use leaf spitting build() on this sterile customizer" << std::endl ;
393 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_masterPdf->GetName() <<
"): ERROR label '" << masterCatState
394 <<
"' not defined for master splitting category " <<
_masterCat->GetName() << std::endl ;
398 return doBuild(masterCatState,verbose) ;
409 RooArgSet masterNodesToBeSplit(
"masterNodesToBeSplit") ;
410 RooArgSet masterNodesToBeReplaced(
"masterNodesToBeReplaced") ;
411 RooArgSet masterReplacementNodes(
"masterReplacementNodes") ;
412 RooArgSet clonedMasterNodes(
"clonedMasterNodes") ;
419 for (
auto node : nodeList) {
424 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName()
425 <<
"): tree node " << node->GetName() <<
" is split by category " << splitCat->
GetName() << std::endl ;
428 TString newName(node->GetName()) ;
429 if (masterCatState) {
439 clonedMasterNodes.
add(*specNode) ;
441 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName()
442 <<
") Adding existing node specialization " << newName <<
" to clonedMasterNodes" << std::endl ;
446 TString nameAttrib(
"ORIGNAME:") ;
447 nameAttrib.
Append(node->GetName()) ;
458 if (node->isDerived()) {
459 oocoutW(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName()
460 <<
"): WARNING: branch node " << node->GetName() <<
" is split but has no pre-defined specializations" << std::endl ;
463 TString newTitle(node->GetTitle()) ;
474 TString nameAttrib(
"ORIGNAME:") ;
475 nameAttrib.
Append(node->GetName()) ;
483 clonedMasterNodes.
add(*clone) ;
493 masterNodesToBeSplit.
add(*node) ;
500 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName()
501 <<
"): tree node " << node->GetName() <<
" will be replaced by " << substArg->
GetName() << std::endl ;
505 TString nameAttrib(
"ORIGNAME:") ;
506 nameAttrib.
Append(node->GetName()) ;
510 masterNodesToBeReplaced.
add(*node) ;
511 masterReplacementNodes.
add(*substArg) ;
516 RooArgSet masterBranchesToBeCloned(
"masterBranchesToBeCloned") ;
520 if (masterNodesToBeSplit.
find(branch->GetName())) {
522 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName() <<
") Branch node " << branch->GetName() <<
" is already split" << std::endl ;
526 if (masterNodesToBeReplaced.
find(branch->GetName())) {
528 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName() <<
") Branch node " << branch->GetName() <<
" is already replaced" << std::endl ;
533 if (branch->dependsOn(masterNodesToBeSplit)) {
535 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName() <<
") Branch node "
536 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a split parameter" << std::endl ;
538 masterBranchesToBeCloned.
add(*branch) ;
539 }
else if (branch->dependsOn(masterNodesToBeReplaced)) {
541 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->GetName() <<
") Branch node "
542 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a replaced parameter" << std::endl ;
544 masterBranchesToBeCloned.
add(*branch) ;
550 RooArgSet clonedMasterBranches(
"clonedMasterBranches") ;
552 for (
auto branch : masterBranchesToBeCloned) {
553 TString newName(branch->GetName()) ;
554 if (masterCatState) {
556 newName.
Append(masterCatState) ;
562 TString nameAttrib(
"ORIGNAME:") ;
563 nameAttrib.
Append(branch->GetName()) ;
570 clonedMasterBranches.
add(*clone) ;
583 for (
auto branch : clonedMasterBranches) {
584 branch->redirectServers(clonedMasterBranches,
false,
true) ;
585 branch->redirectServers(clonedMasterNodes,
false,
true) ;
586 branch->redirectServers(masterReplacementNodes,
false,
true) ;
589 return cloneTopPdf ? cloneTopPdf :
_masterPdf ;
598 os <<
"[ masterPdf=" <<
_masterPdf->GetName() ;
600 os <<
" masterCat=" <<
_masterCat->GetName() ;
617 os <<
indent <<
" Splitting rules:" << std::endl ;
618 for (i=0 ; i<nsplit ; i++) {
625 os <<
indent <<
" Replacement rules:" << std::endl ;
626 for (i=0 ; i<nrepl ; i++) {
648 return static_cast<RooAbsPdf&
>(*_masterPdf);
656std::string CustIFace::create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
660 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: expect at least 2 arguments for EDIT: the input object and at least one $Replace() rule")) ;
663 if (
string(typeName)!=
"EDIT") {
664 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: unknown type requested: %s",typeName)) ;
668 RooAbsArg* arg = ft.
ws().
arg(args[0]) ;
670 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: input RooAbsArg %s does not exist",args[0].c_str())) ;
674 if (args[0]==instanceName) {
675 instanceName=nullptr ;
679 RooCustomizer cust(*arg,instanceName) ;
681 for (
unsigned int i=1 ; i<args.size() ; i++) {
683 strlcpy(buf,args[i].c_str(),1024) ;
684 char*
sep = strchr(buf,
'=') ;
686 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: unknown argument: %s, expect form orig=subst",args[i].c_str())) ;
689 RooAbsArg* orig = ft.
ws().
arg(buf) ;
690 RooAbsArg* subst(
nullptr) ;
691 if (
string(sep+1).find(
"$REMOVE")==0) {
697 char* sep2 = strchr(sep+1,
'(') ;
700 strlcpy(buf2,sep2+1,1024) ;
702 char* tok = R__STRTOK_R(buf2,
",)",&saveptr) ;
705 subst->setAttribute(
Form(
"REMOVE_FROM_%s",tok)) ;
706 tok = R__STRTOK_R(
nullptr,
",)",&saveptr) ;
710 subst->setAttribute(
"REMOVE_ALL") ;
714 subst = ft.
ws().
arg(sep+1) ;
723 cust.replaceArg(*orig,*subst) ;
725 oocoutW(
nullptr,ObjectHandling) <<
"RooCustomizer::CustIFace::create() WARNING: input or replacement of a replacement operation not found, operation ignored"<< std::endl ;
730 RooAbsArg* targ = cust.build(
false) ;
732 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR in customizer build, object %snot created",instanceName)) ;
745 return string(instanceName?instanceName:targ->
GetName()) ;
int Int_t
Signed integer 4 bytes (int).
static void indent(ostringstream &buf, int indent_level)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
void SetName(const char *name) override
Set the name of the TNamed.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
void removeStringAttribute(const Text_t *key)
Delete a string attribute with a given key.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
virtual const char * getCurrentLabel() const
Return label string of current state.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
TString _name
Name of this object.
RooArgList _replaceSubList
List of replacement RooAbsArgs.
void splitArg(const RooAbsArg &arg, const RooAbsCategory &splitCat)
Split all argument 'arg' into individualized clones for each defined state of 'splitCat'.
void setCloneBranchSet(RooArgSet &cloneBranchSet)
Releases ownership of list of cloned branch nodes.
RooArgSet * _cloneNodeListAll
List of all cloned nodes.
void replaceArg(const RooAbsArg &orig, const RooAbsArg &subst)
Replace any occurrence of arg 'orig' with arg 'subst'.
RooAbsArg * _masterPdf
Pointer to input p.d.f.
bool _owning
If true we own all created components.
RooAbsArg * build(const char *masterCatState, bool verbose=false)
Build a clone of the prototype executing all registered 'replace' rules and 'split' rules for the mas...
RooArgList _splitArgList
List of RooAbsArgs to be split.
RooArgList _splitCatList
List of categories to be used for above splits.
RooArgSet * _cloneBranchList
Pointer to list of cloned branches used.
RooCustomizer(const RooAbsArg &pdf, const RooAbsCategoryLValue &masterCat, RooArgSet &splitLeafListOwned, RooArgSet *splitLeafListAll=nullptr)
Constructor with a prototype and masterCat index category.
RooArgSet _masterBranchList
List of branch nodes.
RooArgSet _masterLeafList
List of leaf nodes.
RooArgSet _internalCloneBranchList
List of branches of internal clone.
void initialize()
Initialize the customizer.
RooAbsCategoryLValue * _masterCat
Pointer to input master category.
RooArgList _replaceArgList
List of RooAbsArgs to be replaced.
void splitArgs(const RooArgSet &argSet, const RooAbsCategory &splitCat)
Split all arguments in 'set' into individualized clones for each defined state of 'splitCat'.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const
Print customizer configuration details.
RooAbsArg * doBuild(const char *masterCatState, bool verbose)
Back-end implementation of the p.d.f building functionality.
bool _sterile
If true we do not have as associated master category.
RooAbsPdf const & pdf() const
RooArgSet * _cloneNodeListOwned
List of owned cloned nodes.
void printArgs(std::ostream &os) const
Print arguments of customizer, i.e. input p.d.f and input master category (if any).
static RooConstVar & removalDummy()
Create a dummy node used in node-removal operations.
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * Data() const
TString & Append(const char *cs)
RooCmdArg RecycleConflictNodes(bool flag=true)
RooCmdArg Silence(bool flag=true)
RooCmdArg NoRecursion(bool flag=true)
RooCmdArg RenameConflictNodes(const char *suffix, bool renameOrigNodes=false)