118using std::string, std::endl, std::map, std::list, std::pair, std::cout, std::vector;
124 std::string
create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
override ;
129Int_t dummy = init() ;
133 static SimWSIFace iface{};
176 BuildConfig bc(protoPdfName,arg1,arg2,arg3,arg4,arg5,arg6) ;
177 return build(simPdfName,bc) ;
189 if (!obc)
return nullptr;
209 auto obc = std::make_unique<ObjBuildConfig>();
213 if (!obc->_masterCat) {
214 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
216 <<
" that was designated as master index category in the build configuration" << endl ;
220 obc->_masterCat = nullptr ;
223 map<string,SplitRule>::iterator pdfiter ;
225 for (pdfiter = bc.
_pdfmap.begin() ; pdfiter != bc.
_pdfmap.end() ; ++pdfiter) {
230 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
231 <<
" does not contain a pdf named " << pdfiter->second.GetName() << endl ;
241 map<string, pair<list<string>,
string> >::iterator pariter ;
247 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
248 <<
" does not contain a variable named " << pariter->first.c_str()
249 <<
" as specified in splitting rule of parameter " << pariter->first <<
" of p.d.f " << pdf << endl ;
255 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: specified parameter " << pariter->first
256 <<
" in split is not function of p.d.f " << pdf->
GetName() << endl ;
262 list<string>::iterator catiter ;
263 for (catiter = pariter->second.first.begin() ; catiter!=pariter->second.first.end() ; ++catiter) {
266 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
267 <<
" does not contain a category named " << catiter->c_str()
268 <<
" as specified in splitting rule of parameter " << pariter->first <<
" of p.d.f " << pdf << endl ;
271 splitCatSet.
add(*cat) ;
278 if (arg->dependsOnValue(tmp)) {
279 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::build() ERROR: Ill defined split: splitting category function " << arg->GetName()
280 <<
" used in composite split " << splitCatSet <<
" of parameter " << farg->
GetName() <<
" of pdf " << pdf->
GetName()
281 <<
" depends on one or more of the other splitting categories in the composite split" << endl ;
287 if (!pariter->second.second.empty()) {
289 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::build() ERROR: Constrained split specified in non real-valued parameter " << farg->
GetName() << endl ;
299 if (obc->_masterCat) {
300 list<string>::iterator misi ;
302 const RooCatType* ctype = obc->_masterCat->lookupType(misi->c_str(),
false) ;
303 if (ctype==
nullptr) {
304 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: master index category " << obc->_masterCat->
GetName()
305 <<
" does not have a state named " << *misi <<
" which was specified as state associated with p.d.f "
314 obc->_usedSplitCats.add(splitCatSet,
true) ;
320 if (obc->_masterCat) {
321 list<string>::iterator misi ;
323 const RooCatType* ctype = obc->_masterCat->lookupType(misi->c_str(),
false) ;
324 if (ctype==
nullptr) {
325 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: master index category " << obc->_masterCat->
GetName()
326 <<
" does not have a state named " << *misi <<
" which was specified as state associated with p.d.f "
335 obc->_pdfmap[pdf] = osr ;
340 map<string,string>::iterator riter ;
341 for (riter=bc.
_restr.begin() ; riter!=bc.
_restr.end() ; ++riter) {
344 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
345 <<
" does not contain a category named " << riter->first
346 <<
" for which build was requested to be restricted to states " << riter->second << endl ;
351 list<const RooCatType*> rlist ;
352 strlcpy(buf,riter->second.c_str(),4096) ;
354 char* tok = strtok(buf,
"{,}") ;
358 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: restricted build category " << cat->
GetName()
359 <<
" does not have state " << tok <<
" as specified in restriction list" << endl ;
362 rlist.push_back(ctype) ;
363 tok = strtok(
nullptr,
"{,}") ;
366 obc->_restr[cat] = rlist ;
385 map<string,RooAbsPdf*> stateMap ;
387 map<RooAbsPdf*,ObjSplitRule>::iterator physIter = obc.
_pdfmap.begin() ;
388 while(physIter!=obc.
_pdfmap.end()) {
392 physModelSet.
add(*physModel,
true) ;
394 list<const RooCatType*>::iterator stiter ;
395 for (stiter=physIter->second._miStateList.begin() ; stiter!=physIter->second._miStateList.end() ; ++stiter) {
396 stateMap[(*stiter)->GetName()] = physModel ;
403 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: list of prototype pdfs " << physModelSet << endl ;
407 if (physCat) splitCatSet.
add(*physCat) ;
410 for(
auto * scat : static_range_cast<RooAbsCategory*>(splitCatSet)) {
411 if (scat->isFundamental()) {
412 splitCatSetFund.
add(*scat) ;
414 std::unique_ptr<RooArgSet> scatvars{scat->getVariables()};
415 splitCatSetFund.
add(*scatvars) ;
421 if (splitCatSetFund.
size()>1) {
422 auto masterSplitCatOwner = std::make_unique<RooSuperCategory>(
"masterSplitCat",
"Master splitting category",splitCatSetFund);
423 masterSplitCat = masterSplitCatOwner.get();
424 cleanupList.
addOwned(std::move(masterSplitCatOwner));
429 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: list of splitting categories " << splitCatSet << endl ;
434 std::vector<std::unique_ptr<RooCustomizer>> customizerList ;
437 for(
auto * physModel : static_range_cast<RooAbsPdf*>(physModelSet)) {
439 oocoutI(
nullptr, ObjectHandling) <<
"RooSimPdfBuilder::executeBuild: processing prototype pdf " << physModel->
GetName() << endl ;
442 customizerList.push_back(std::make_unique<RooCustomizer>(*physModel,*masterSplitCat,splitNodeListOwned,&splitNodeListAll));
445 map<RooAbsArg*, pair<RooArgSet,string> >::iterator splitIter ;
446 for (splitIter = obc.
_pdfmap[physModel]._paramSplitMap.begin() ; splitIter != obc.
_pdfmap[physModel]._paramSplitMap.end() ; ++splitIter) {
457 auto splitCatOwner = std::make_unique<RooMultiCategory>(splitName.c_str(),splitName.c_str(),splitCatSetTmp);
458 splitCat = splitCatOwner.get();
460 cleanupList.
addOwned(std::move(splitCatOwner)) ;
464 if(!splitIter->second.second.empty()) {
467 if (!splitCat->
hasLabel(splitIter->second.second)) {
468 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::executeBuild() ERROR: name of remainder state for constrained split, '"
469 << splitIter->second.second <<
"' , does not match any state name of (composite) split category " << splitCat->
GetName() << endl ;
475 for(
auto const&
type : *splitCat) {
477 std::string
const& typeName =
type.first;
480 if (splitIter->second.second == typeName) continue ;
483 std::string splitLeafName = std::string{splitIter->first->GetName()} +
"_" + typeName;
489 splitLeaf =
static_cast<RooAbsArg*
>(splitIter->first->clone(splitLeafName.c_str()));
492 fracLeafList.
add(*splitLeaf) ;
497 auto fracRem = std::make_unique<RooFracRemainder>(
Form(
"%s_%s",splitIter->first->GetName(),splitIter->second.second.c_str()),
"Remainder fraction",fracLeafList);
499 cleanupList.
addOwned(std::move(fracRem));
505 physCustomizer->
splitArgs(*splitIter->first,*splitCat) ;
513 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: configured customizers for all prototype pdfs" << endl ;
518 if (physCat) fitCatList.
add(*physCat) ;
522 for(
auto * scat : static_range_cast<RooAbsCategory*>(splitCatSet)) {
523 if (scat->isFundamental()) {
524 fitCatList.
add(*scat) ;
526 fitCatList.
add(*std::unique_ptr<RooArgSet>{scat->getVariables()}) ;
531 string mcatname = string(simPdfName) +
"_index" ;
533 if (fitCatList.
size()>1) {
534 auto fitCatOwner = std::make_unique<RooSuperCategory>(mcatname.c_str(),mcatname.c_str(),fitCatList);
535 fitCat = fitCatOwner.get();
536 cleanupList.
addOwned(std::move(fitCatOwner));
542 auto simPdfOwner = std::make_unique<RooSimultaneous>(simPdfName,simPdfName,*fitCat);
544 cleanupList.
addOwned(std::move(simPdfOwner));
547 for (
auto const& fcState : *fitCat) {
548 const std::string fcStateName = fcState.first;
551 fitCat->
setLabel(fcStateName.c_str());
555 if (!obc.
_restr.empty()) {
556 for(
auto * splitCat : static_range_cast<RooAbsCategory*>(fitCatList)) {
559 list<const RooCatType*> slist = obc.
_restr[splitCat] ;
564 list<const RooCatType*>::iterator sli ;
565 for (sli=slist.begin() ; sli!=slist.end() ; ++sli) {
566 if (
string(splitCat->getCurrentLabel())==(*sli)->GetName()) {
571 if (!select) continue ;
583 const std::string pdfName = pdf->
GetName();
584 auto found = std::find_if(customizerList.begin(), customizerList.end(),
585 [&](
auto const&
c){ return pdfName == c->pdf().GetName(); });
586 physCustomizer = found != customizerList.end() ? found->get() :
nullptr;
588 physCustomizer = customizerList.front().get();
592 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: Customizing prototype pdf " << physCustomizer->
pdf().
GetName()
593 <<
" for mode " << fcStateName << endl ;
598 simPdf->
addPdf(*fcPdf,fcStateName.c_str()) ;
623 name += arg->GetName() ;
638 char paramBuf[4096] ;
640 strlcpy(paramBuf,paramNameList,4096) ;
641 strlcpy(catBuf,categoryNameList,4096) ;
644 list<string> catList ;
645 char* cat = strtok(catBuf,
"{,}") ;
647 catList.push_back(cat) ;
648 cat = strtok(
nullptr,
"{,}") ;
652 char* param = strtok(paramBuf,
"{,}") ;
655 param = strtok(
nullptr,
"{,}") ;
666 char paramBuf[4096] ;
668 strlcpy(paramBuf,paramNameList,4096) ;
669 strlcpy(catBuf,categoryNameList,4096) ;
672 list<string> catList ;
673 char* cat = strtok(catBuf,
"{,}") ;
675 catList.push_back(cat) ;
676 cat = strtok(
nullptr,
"{,}") ;
680 char* param = strtok(paramBuf,
"{,}") ;
682 _paramSplitMap[param] = pair<list<string>,
string>(catList,remainderStateName) ;
683 param = strtok(
nullptr,
"{,}") ;
695 list<const RooCmdArg*> cmdList ;
696 cmdList.push_back(&arg1) ; cmdList.push_back(&arg2) ;
697 cmdList.push_back(&arg3) ; cmdList.push_back(&arg4) ;
698 cmdList.push_back(&arg5) ; cmdList.push_back(&arg6) ;
700 list<const RooCmdArg*>::iterator iter ;
701 for (iter=cmdList.begin() ; iter!=cmdList.end() ; ++iter) {
703 if ((*iter)->opcode()==
nullptr)
continue ;
705 string name = (*iter)->opcode() ;
707 if (
name==
"SplitParam") {
708 splitParameter((*iter)->getString(0),(*iter)->getString(1)) ;
709 }
else if (
name==
"SplitParamConstrained") {
710 splitParameterConstrained((*iter)->getString(0),(*iter)->getString(1),(*iter)->getString(2)) ;
723 internalAddPdf(pdfName,
"",sr) ;
736 sr.
configure(arg1,arg2,arg3,arg4,arg5,arg6) ;
737 internalAddPdf(pdfName,
"",sr) ;
740 list<const RooCmdArg*> cmdList ;
741 cmdList.push_back(&arg1) ; cmdList.push_back(&arg2) ;
742 cmdList.push_back(&arg3) ; cmdList.push_back(&arg4) ;
743 cmdList.push_back(&arg5) ; cmdList.push_back(&arg6) ;
745 list<const RooCmdArg*>::iterator iter ;
746 for (iter=cmdList.begin() ; iter!=cmdList.end() ; ++iter) {
747 if ((*iter)->opcode()==
nullptr)
continue ;
748 string name = (*iter)->opcode() ;
749 if (
name==
"Restrict") {
750 restrictBuild((*iter)->getString(0),(*iter)->getString(1)) ;
752 if (
name==
"RenameConflictNodes") {
753 _conflProtocol = *(*iter) ;
775 strlcpy(buf,miStateNameList,4096) ;
777 char* tok = strtok(buf,
",") ;
780 tok = strtok(
nullptr,
",") ;
783 _pdfmap[pdfName] = sr ;
792 _restr[catName] = stateList ;
805 _masterCatName = masterIndexCat ;
818 sr.
configure(arg1,arg2,arg3,arg4,arg5,arg6) ;
819 internalAddPdf(pdfName,miStateList,sr) ;
829 internalAddPdf(pdfName,miStateList,sr) ;
851 map<RooAbsPdf*,ObjSplitRule>::iterator ri ;
852 for (ri = _pdfmap.begin() ; ri != _pdfmap.end() ; ++ri ) {
853 cout <<
"Splitrule for p.d.f " << ri->first->GetName() <<
" with state list " ;
854 for (std::list<const RooCatType*>::iterator misi= ri->second._miStateList.begin() ; misi!=ri->second._miStateList.end() ; ++misi) {
855 cout << (*misi)->GetName() <<
" " ;
859 map<RooAbsArg*,pair<RooArgSet,string> >::iterator csi ;
860 for (csi = ri->second._paramSplitMap.begin() ; csi != ri->second._paramSplitMap.end() ; ++csi ) {
861 if (csi->second.second.length()>0) {
862 cout <<
" parameter " << csi->first->GetName() <<
" is split with constraint in categories " << csi->second.first
863 <<
" with remainder in state " << csi->second.second << endl ;
865 cout <<
" parameter " << csi->first->GetName() <<
" is split with constraint in categories " << csi->second.first << endl ;
870 map<RooAbsCategory*,list<const RooCatType*> >::iterator riter ;
871 for (riter=_restr.begin() ; riter!=_restr.end() ; ++riter) {
872 cout <<
"Restricting build in category " << riter->first->GetName() <<
" to states " ;
873 list<const RooCatType*>::iterator i ;
874 for (i=riter->second.begin() ; i!=riter->second.end() ; ++i) {
875 if (i!=riter->second.begin()) cout <<
"," ;
876 cout << (*i)->GetName() ;
888std::string SimWSIFace::create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
890 string tn(typeName) ;
891 if (tn==
"SIMCLONE") {
894 for (
unsigned int i=1 ; i<args.size() ; i++) {
895 if (args[i].find(
"$SplitParam(")!=0 &&
896 args[i].find(
"$SplitParamConstrained(")!=0 &&
897 args[i].find(
"$SplitRestrict(")!=0 &&
898 args[i].find(
"$Verbose(")!=0) {
899 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: unknown token %s encountered",args[i].c_str())) ;
905 for (
unsigned int i=1 ; i<args.size() ; i++) {
906 if (args[i].find(
"$SplitParam(")==0) {
908 if (subargs.size()!=2) {
909 throw string(
Form(
"Incorrect number of arguments in $SplitParam, have %d, expect 2",(
Int_t)subargs.size())) ;
911 sr.splitParameter(subargs[0].c_str(),subargs[1].c_str()) ;
912 }
else if (args[i].find(
"$SplitParamConstrained(")==0) {
914 if (subargs.size()!=3) {
915 throw string(
Form(
"Incorrect number of arguments in $SplitParamConstrained, have %d, expect 3",(
Int_t)subargs.size())) ;
917 sr.splitParameterConstrained(subargs[0].c_str(), subargs[1].c_str(), subargs[2].c_str()) ;
923 for (
unsigned int i=1 ; i<args.size() ; i++) {
924 if (args[i].find(
"$Restrict(")==0) {
926 if (subargs.size()!=2) {
927 throw string(
Form(
"Incorrect number of arguments in $Restrict, have %d, expect 2",(
Int_t)subargs.size())) ;
929 bc.restrictBuild(subargs[0].c_str(),subargs[1].c_str()) ;
935 for (
unsigned int i=1 ; i<args.size() ; i++) {
936 if (args[i].find(
"$Verbose(")==0) {
938 if (!subargs.empty()) {
939 verbose = atoi(subargs[0].c_str()) ;
946 RooAbsPdf* pdf = sct.build(instanceName,bc,verbose) ;
948 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() error in RooSimWSTool::build() for %s",instanceName)) ;
954 }
else if (tn==
"MSIMCLONE") {
959 for (
unsigned int i=1 ; i<args.size() ; i++) {
960 if (args[i].find(
"$AddPdf(")==0) {
966 for (
unsigned int j=2 ; j<subargs.size() ; j++) {
967 if (subargs[j].find(
"$SplitParam(")==0) {
969 if (subsubargs.size()!=2) {
970 throw string(
Form(
"Incorrect number of arguments in $SplitParam, have %d, expect 2",(
Int_t)subsubargs.size())) ;
972 sr.splitParameter(subsubargs[0].c_str(),subsubargs[1].c_str()) ;
973 }
else if (subargs[j].find(
"$SplitParamConstrained(")==0) {
975 if (subsubargs.size()!=3) {
976 throw string(
Form(
"Incorrect number of arguments in $SplitParamConstrained, have %d, expect 3",(
Int_t)subsubargs.size())) ;
978 sr.splitParameterConstrained(subsubargs[0].c_str(), subsubargs[1].c_str(), subsubargs[2].c_str()) ;
981 mbc.addPdf(subargs[0].c_str(),subargs[1].c_str(),sr) ;
983 }
else if (args[i].find(
"$Restrict(")==0) {
987 if (subargs.size()!=2) {
988 throw string(
Form(
"Incorrect number of arguments in $Restrict, have %d, expect 2",(
Int_t)subargs.size())) ;
990 mbc.restrictBuild(subargs[0].c_str(),subargs[1].c_str()) ;
993 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: unknown token in MSIMCLONE: %s",args[i].c_str())) ;
999 RooAbsPdf* pdf = sct.build(instanceName,mbc,
false) ;
1001 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() error in RooSimWSTool::build() for %s",instanceName)) ;
1009 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
1012 return string(instanceName) ;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
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.
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
virtual const char * getCurrentLabel() const
Return label string of current state.
const RooCatType * lookupType(value_type index, bool printError=false) const
Find our type corresponding to the specified index, or return nullptr for no match.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * first() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCatType is an auxiliary class for RooAbsCategory and defines a a single category state.
const Text_t * GetName() const override
Returns name of object.
Object to represent discrete states.
Named container for two doubles, two integers two object points and three string pointers that can be...
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
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...
void splitArgs(const RooArgSet &argSet, const RooAbsCategory &splitCat)
Split all arguments in 'set' into individualized clones for each defined state of 'splitCat'.
RooAbsPdf const & pdf() const
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
bool addPdf(const RooAbsPdf &pdf, const char *catLabel)
Associate given PDF with index category state label 'catLabel'.
Persistable container for RooFit projects.
RooAbsCategory * catfunc(RooStringView name) const
Retrieve discrete function (RooAbsCategory) with given name. A null pointer is returned if not found.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
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 RooArgSet & components() const
const char * GetName() const override
Returns name of object.
RooCmdArg Silence(bool flag=true)
RooCmdArg RenameConflictNodes(const char *suffix, bool renameOrigNodes=false)
void(off) SmallVectorTemplateBase< T