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() ;
227 _masterPdf(const_cast<
RooAbsArg *>(&pdf)),
229 _masterBranchList(
"masterBranchList"),
230 _masterLeafList(
"masterLeafList"),
231 _internalCloneBranchList(
"cloneBranchList"),
232 _cloneBranchList(&_internalCloneBranchList),
233 _cloneNodeListAll(splitLeavesAll),
234 _cloneNodeListOwned(&splitLeaves)
251 _masterPdf(const_cast<
RooAbsArg *>(&pdf)),
252 _masterBranchList(
"masterBranchList"),
253 _masterLeafList(
"masterLeafList"),
254 _internalCloneBranchList(
"cloneBranchList"),
255 _cloneBranchList(&_internalCloneBranchList)
284 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArgs(" <<
_name
285 <<
") ERROR cannot set spitting rules on this sterile customizer" << 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" << endl ;
313 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArg(" <<
_name
314 <<
") ERROR cannot set spitting rules on this sterile customizer" << endl ;
330 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer(" <<
_masterPdf->
GetName() <<
") ERROR: multiple replacement rules defined for "
331 << orig.
GetName() <<
" only using first rule" << endl ;
362 allOwned.remove(*ret) ;
366 if (!allOwned.empty()) {
386 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_name
387 <<
") ERROR cannot use leaf spitting build() on this sterile customizer" << endl ;
393 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_masterPdf->
GetName() <<
"): ERROR label '" << masterCatState
394 <<
"' not defined for master splitting category " <<
_masterCat->
GetName() << 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) {
425 <<
"): tree node " << node->GetName() <<
" is split by category " << splitCat->
GetName() << endl ;
428 TString newName(node->GetName()) ;
429 if (masterCatState) {
439 clonedMasterNodes.
add(*specNode) ;
442 <<
") Adding existing node specialization " << newName <<
" to clonedMasterNodes" << endl ;
446 TString nameAttrib(
"ORIGNAME:") ;
447 nameAttrib.
Append(node->GetName()) ;
458 if (node->isDerived()) {
460 <<
"): WARNING: branch node " << node->GetName() <<
" is split but has no pre-defined specializations" << endl ;
463 TString newTitle(node->GetTitle()) ;
470 clone->removeStringAttribute(
"factory_tag") ;
471 clone->SetTitle(newTitle) ;
474 TString nameAttrib(
"ORIGNAME:") ;
475 nameAttrib.
Append(node->GetName()) ;
476 clone->setAttribute(nameAttrib) ;
478 if (!
clone->getStringAttribute(
"origName")) {
479 clone->setStringAttribute(
"origName",node->GetName()) ;
493 masterNodesToBeSplit.
add(*node) ;
501 <<
"): tree node " << node->GetName() <<
" will be replaced by " << substArg->
GetName() << 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" << endl ;
526 if (masterNodesToBeReplaced.
find(branch->GetName())) {
528 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->
GetName() <<
") Branch node " << branch->GetName() <<
" is already replaced" << endl ;
533 if (branch->dependsOn(masterNodesToBeSplit)) {
536 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a split parameter" << endl ;
538 masterBranchesToBeCloned.
add(*branch) ;
539 }
else if (branch->dependsOn(masterNodesToBeReplaced)) {
542 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a replaced parameter" << 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) ;
561 clone->removeStringAttribute(
"factory_tag") ;
562 TString nameAttrib(
"ORIGNAME:") ;
563 nameAttrib.
Append(branch->GetName()) ;
564 clone->setAttribute(nameAttrib) ;
566 if (!
clone->getStringAttribute(
"origName")) {
567 clone->setStringAttribute(
"origName",branch->GetName()) ;
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 ;
617 os <<
indent <<
" Splitting rules:" << endl ;
618 for (i=0 ; i<nsplit ; i++) {
625 os <<
indent <<
" Replacement rules:" << 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)) ;
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 ;
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())) ;
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"<< endl ;
732 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR in customizer build, object %snot created",instanceName)) ;
745 return string(instanceName?instanceName:targ->GetName()) ;
TObject * clone(const char *newname) const override
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.
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node.
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
virtual bool setLabel(const char *label, bool printError=true)=0
Change category state by specifying a state name.
A space to attach TBranches.
virtual const char * getCurrentLabel() const
Return label string of current state.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
void useHashMapForFind(bool flag) const
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
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.
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.
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)
void(off) SmallVectorTemplateBase< T