185 std::string
create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
override ;
231 _masterBranchList(
"masterBranchList"),
232 _masterLeafList(
"masterLeafList"),
233 _internalCloneBranchList(
"cloneBranchList"),
234 _cloneNodeListAll(splitLeafsAll),
235 _cloneNodeListOwned(&splitLeafs)
254 _masterBranchList(
"masterBranchList"),
255 _masterLeafList(
"masterLeafList"),
256 _internalCloneBranchList(
"cloneBranchList")
286 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArgs(" <<
_name
287 <<
") ERROR cannot set spitting rules on this sterile customizer" << endl ;
291 for (
auto arg : set) {
309 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer(" <<
_masterPdf->
GetName() <<
") ERROR: multiple splitting rules defined for "
310 << arg.
GetName() <<
" only using first rule" << endl ;
315 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::splitArg(" <<
_name
316 <<
") ERROR cannot set spitting rules on this sterile customizer" << endl ;
332 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer(" <<
_masterPdf->
GetName() <<
") ERROR: multiple replacement rules defined for "
333 << orig.
GetName() <<
" only using first rule" << endl ;
364 allOwned.remove(*ret) ;
368 if (allOwned.getSize()>0) {
388 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_name
389 <<
") ERROR cannot use leaf spitting build() on this sterile customizer" << endl ;
395 oocoutE(
nullptr, InputArguments) <<
"RooCustomizer::build(" <<
_masterPdf->
GetName() <<
"): ERROR label '" << masterCatState
396 <<
"' not defined for master splitting category " <<
_masterCat->
GetName() << endl ;
400 return doBuild(masterCatState,verbose) ;
411 RooArgSet masterNodesToBeSplit(
"masterNodesToBeSplit") ;
412 RooArgSet masterNodesToBeReplaced(
"masterNodesToBeReplaced") ;
413 RooArgSet masterReplacementNodes(
"masterReplacementNodes") ;
414 RooArgSet clonedMasterNodes(
"clonedMasterNodes") ;
421 for (
auto node : nodeList) {
427 <<
"): tree node " << node->GetName() <<
" is split by category " << splitCat->
GetName() << endl ;
430 TString newName(node->GetName()) ;
431 if (masterCatState) {
441 clonedMasterNodes.
add(*specNode) ;
444 <<
") Adding existing node specialization " << newName <<
" to clonedMasterNodes" << endl ;
448 TString nameAttrib(
"ORIGNAME:") ;
449 nameAttrib.
Append(node->GetName()) ;
460 if (node->isDerived()) {
462 <<
"): WARNING: branch node " << node->GetName() <<
" is split but has no pre-defined specializations" << endl ;
465 TString newTitle(node->GetTitle()) ;
472 clone->removeStringAttribute(
"factory_tag") ;
473 clone->SetTitle(newTitle) ;
476 TString nameAttrib(
"ORIGNAME:") ;
477 nameAttrib.
Append(node->GetName()) ;
478 clone->setAttribute(nameAttrib) ;
480 if (!
clone->getStringAttribute(
"origName")) {
481 clone->setStringAttribute(
"origName",node->GetName()) ;
495 masterNodesToBeSplit.
add(*node) ;
503 <<
"): tree node " << node->GetName() <<
" will be replaced by " << substArg->
GetName() << endl ;
507 TString nameAttrib(
"ORIGNAME:") ;
508 nameAttrib.
Append(node->GetName()) ;
512 masterNodesToBeReplaced.
add(*node) ;
513 masterReplacementNodes.
add(*substArg) ;
518 RooArgSet masterBranchesToBeCloned(
"masterBranchesToBeCloned") ;
522 if (masterNodesToBeSplit.
find(branch->GetName())) {
524 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->
GetName() <<
") Branch node " << branch->GetName() <<
" is already split" << endl ;
528 if (masterNodesToBeReplaced.
find(branch->GetName())) {
530 oocoutI(
nullptr, ObjectHandling) <<
"RooCustomizer::build(" <<
_masterPdf->
GetName() <<
") Branch node " << branch->GetName() <<
" is already replaced" << endl ;
535 if (branch->dependsOn(masterNodesToBeSplit)) {
538 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a split parameter" << endl ;
540 masterBranchesToBeCloned.
add(*branch) ;
541 }
else if (branch->dependsOn(masterNodesToBeReplaced)) {
544 << branch->ClassName() <<
"::" << branch->GetName() <<
" cloned: depends on a replaced parameter" << endl ;
546 masterBranchesToBeCloned.
add(*branch) ;
552 RooArgSet clonedMasterBranches(
"clonedMasterBranches") ;
554 for (
auto branch : masterBranchesToBeCloned) {
555 TString newName(branch->GetName()) ;
556 if (masterCatState) {
558 newName.
Append(masterCatState) ;
563 clone->removeStringAttribute(
"factory_tag") ;
564 TString nameAttrib(
"ORIGNAME:") ;
565 nameAttrib.
Append(branch->GetName()) ;
566 clone->setAttribute(nameAttrib) ;
568 if (!
clone->getStringAttribute(
"origName")) {
569 clone->setStringAttribute(
"origName",branch->GetName()) ;
585 for (
auto branch : clonedMasterBranches) {
586 branch->redirectServers(clonedMasterBranches,
false,
true) ;
587 branch->redirectServers(clonedMasterNodes,
false,
true) ;
588 branch->redirectServers(masterReplacementNodes,
false,
true) ;
591 return cloneTopPdf ? cloneTopPdf :
_masterPdf ;
618 os <<
indent <<
" Splitting rules:" << endl ;
619 for (i=0 ; i<nsplit ; i++) {
626 os <<
indent <<
" Replacement rules:" << endl ;
627 for (i=0 ; i<nrepl ; i++) {
649 return static_cast<RooAbsPdf&
>(*_masterPdf);
657std::string CustIFace::create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
661 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: expect at least 2 arguments for EDIT: the input object and at least one $Replace() rule")) ;
664 if (
string(typeName)!=
"EDIT") {
665 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: unknown type requested: %s",typeName)) ;
671 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: input RooAbsArg %s does not exist",args[0].c_str())) ;
675 if (args[0]==instanceName) {
676 instanceName=nullptr ;
682 for (
unsigned int i=1 ; i<args.size() ; i++) {
684 strlcpy(buf,args[i].c_str(),1024) ;
685 char*
sep = strchr(buf,
'=') ;
687 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR: unknown argument: %s, expect form orig=subst",args[i].c_str())) ;
692 if (
string(sep+1).find(
"$REMOVE")==0) {
698 char* sep2 = strchr(sep+1,
'(') ;
701 strlcpy(buf2,sep2+1,1024) ;
703 char* tok = R__STRTOK_R(buf2,
",)",&saveptr) ;
706 subst->setAttribute(
Form(
"REMOVE_FROM_%s",tok)) ;
707 tok = R__STRTOK_R(
nullptr,
",)",&saveptr) ;
711 subst->setAttribute(
"REMOVE_ALL") ;
715 subst = ft.
ws().
arg(sep+1) ;
724 cust.replaceArg(*orig,*subst) ;
726 oocoutW(
nullptr,ObjectHandling) <<
"RooCustomizer::CustIFace::create() WARNING: input or replacement of a replacement operation not found, operation ignored"<< endl ;
733 throw string(
Form(
"RooCustomizer::CustIFace::create() ERROR in customizer build, object %snot created",instanceName)) ;
746 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.
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.
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.
TList _splitArgList
List of RooAbsArgs to be split.
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.
TList _replaceSubList
List of replacement RooAbsArgs.
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...
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.
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.
TList _replaceArgList
List of RooAbsArgs to be replaced.
bool _sterile
If true we do not have as associated master category.
RooAbsPdf const & pdf() const
TList _splitCatList
List of categories to be used for above splits.
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 Int_t GetSize() const
Return the capacity of the collection, i.e.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
const char * GetName() const override
Returns name of object.
virtual const char * GetName() const
Returns name of object.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
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
void init()
Inspect hardware capabilities, and load the optimal library for RooFit computations.