124 ~SimWSIFace()
override {} ;
125 std::string
create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
override ;
134 static SimWSIFace iface{};
177 BuildConfig bc(protoPdfName,arg1,arg2,arg3,arg4,arg5,arg6) ;
178 return build(simPdfName,bc) ;
190 if (!obc)
return nullptr;
210 auto obc = std::make_unique<ObjBuildConfig>();
214 if (!obc->_masterCat) {
215 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
217 <<
" that was designated as master index category in the build configuration" << endl ;
221 obc->_masterCat = 0 ;
224 map<string,SplitRule>::iterator pdfiter ;
226 for (pdfiter = bc.
_pdfmap.begin() ; pdfiter != bc.
_pdfmap.end() ; ++pdfiter) {
231 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
232 <<
" does not contain a pdf named " << pdfiter->second.GetName() << endl ;
242 map<string, pair<list<string>,
string> >::iterator pariter ;
248 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
249 <<
" does not contain a variable named " << pariter->first.c_str()
250 <<
" as specified in splitting rule of parameter " << pariter->first <<
" of p.d.f " << pdf << endl ;
256 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: specified parameter " << pariter->first
257 <<
" in split is not function of p.d.f " << pdf->
GetName() << endl ;
263 list<string>::iterator catiter ;
264 for (catiter = pariter->second.first.begin() ; catiter!=pariter->second.first.end() ; ++catiter) {
267 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
268 <<
" does not contain a category named " << catiter->c_str()
269 <<
" as specified in splitting rule of parameter " << pariter->first <<
" of p.d.f " << pdf << endl ;
272 splitCatSet.
add(*cat) ;
279 if (arg->dependsOnValue(tmp)) {
280 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::build() ERROR: Ill defined split: splitting category function " << arg->GetName()
281 <<
" used in composite split " << splitCatSet <<
" of parameter " << farg->
GetName() <<
" of pdf " << pdf->
GetName()
282 <<
" depends on one or more of the other splitting categories in the composite split" << endl ;
288 if (!pariter->second.second.empty()) {
290 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::build() ERROR: Constrained split specified in non real-valued parameter " << farg->
GetName() << endl ;
300 if (obc->_masterCat) {
301 list<string>::iterator misi ;
303 const RooCatType* ctype = obc->_masterCat->lookupType(misi->c_str(),
false) ;
305 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: master index category " << obc->_masterCat->
GetName()
306 <<
" does not have a state named " << *misi <<
" which was specified as state associated with p.d.f "
315 obc->_usedSplitCats.add(splitCatSet,
true) ;
321 if (obc->_masterCat) {
322 list<string>::iterator misi ;
324 const RooCatType* ctype = obc->_masterCat->lookupType(misi->c_str(),
false) ;
326 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: master index category " << obc->_masterCat->
GetName()
327 <<
" does not have a state named " << *misi <<
" which was specified as state associated with p.d.f "
336 obc->_pdfmap[pdf] = osr ;
341 map<string,string>::iterator riter ;
342 for (riter=bc.
_restr.begin() ; riter!=bc.
_restr.end() ; ++riter) {
345 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: associated workspace " <<
_ws->
GetName()
346 <<
" does not contain a category named " << riter->first
347 <<
" for which build was requested to be restricted to states " << riter->second << endl ;
352 list<const RooCatType*> rlist ;
353 strlcpy(buf,riter->second.c_str(),4096) ;
355 char* tok = strtok(buf,
"{,}") ;
359 oocoutE(
nullptr, ObjectHandling) <<
"RooSimWSTool::build() ERROR: restricted build category " << cat->
GetName()
360 <<
" does not have state " << tok <<
" as specified in restriction list" << endl ;
363 rlist.push_back(ctype) ;
364 tok = strtok(0,
"{,}") ;
367 obc->_restr[cat] = rlist ;
386 map<string,RooAbsPdf*> stateMap ;
388 map<RooAbsPdf*,ObjSplitRule>::iterator physIter = obc.
_pdfmap.begin() ;
389 while(physIter!=obc.
_pdfmap.end()) {
393 physModelSet.
add(*physModel,
true) ;
395 list<const RooCatType*>::iterator stiter ;
396 for (stiter=physIter->second._miStateList.begin() ; stiter!=physIter->second._miStateList.end() ; ++stiter) {
397 stateMap[(*stiter)->GetName()] = physModel ;
404 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: list of prototype pdfs " << physModelSet << endl ;
408 if (physCat) splitCatSet.
add(*physCat) ;
411 for(
auto * scat : static_range_cast<RooAbsCategory*>(splitCatSet)) {
412 if (scat->isFundamental()) {
413 splitCatSetFund.
add(*scat) ;
415 std::unique_ptr<RooArgSet> scatvars{scat->getVariables()};
416 splitCatSetFund.
add(*scatvars) ;
422 if (splitCatSetFund.
size()>1) {
423 auto masterSplitCatOwner = std::make_unique<RooSuperCategory>(
"masterSplitCat",
"Master splitting category",splitCatSetFund);
424 masterSplitCat = masterSplitCatOwner.get();
425 cleanupList.
addOwned(std::move(masterSplitCatOwner));
430 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: list of splitting categories " << splitCatSet << endl ;
435 std::vector<std::unique_ptr<RooCustomizer>> customizerList ;
438 for(
auto * physModel : static_range_cast<RooAbsPdf*>(physModelSet)) {
440 oocoutI(
nullptr, ObjectHandling) <<
"RooSimPdfBuilder::executeBuild: processing prototype pdf " << physModel->
GetName() << endl ;
443 customizerList.push_back(std::make_unique<RooCustomizer>(*physModel,*masterSplitCat,splitNodeListOwned,&splitNodeListAll));
446 map<RooAbsArg*, pair<RooArgSet,string> >::iterator splitIter ;
447 for (splitIter = obc.
_pdfmap[physModel]._paramSplitMap.begin() ; splitIter != obc.
_pdfmap[physModel]._paramSplitMap.end() ; ++splitIter) {
458 auto splitCatOwner = std::make_unique<RooMultiCategory>(splitName.c_str(),splitName.c_str(),splitCatSetTmp);
459 splitCat = splitCatOwner.get();
461 cleanupList.
addOwned(std::move(splitCatOwner)) ;
465 if(!splitIter->second.second.empty()) {
468 if (!splitCat->
hasLabel(splitIter->second.second)) {
469 oocoutE(
nullptr, InputArguments) <<
"RooSimWSTool::executeBuild() ERROR: name of remainder state for constrained split, '"
470 << splitIter->second.second <<
"' , does not match any state name of (composite) split category " << splitCat->
GetName() << endl ;
476 for(
auto const&
type : *splitCat) {
478 std::string
const& typeName =
type.first;
481 if (splitIter->second.second == typeName) continue ;
484 TString splitLeafName(splitIter->first->GetName()) ;
485 splitLeafName.
Append(
"_") ;
486 splitLeafName.
Append(typeName) ;
495 fracLeafList.
add(*splitLeaf) ;
500 auto fracRem = std::make_unique<RooFracRemainder>(
Form(
"%s_%s",splitIter->first->GetName(),splitIter->second.second.c_str()),
"Remainder fraction",fracLeafList);
502 cleanupList.
addOwned(std::move(fracRem));
508 physCustomizer->
splitArgs(*splitIter->first,*splitCat) ;
516 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: configured customizers for all prototype pdfs" << endl ;
521 if (physCat) fitCatList.
add(*physCat) ;
525 for(
auto * scat : static_range_cast<RooAbsCategory*>(splitCatSet)) {
526 if (scat->isFundamental()) {
527 fitCatList.
add(*scat) ;
529 fitCatList.
add(*std::unique_ptr<RooArgSet>{scat->getVariables()}) ;
534 string mcatname = string(simPdfName) +
"_index" ;
536 if (fitCatList.
size()>1) {
537 auto fitCatOwner = std::make_unique<RooSuperCategory>(mcatname.c_str(),mcatname.c_str(),fitCatList);
538 fitCat = fitCatOwner.get();
539 cleanupList.
addOwned(std::move(fitCatOwner));
545 auto simPdfOwner = std::make_unique<RooSimultaneous>(simPdfName,simPdfName,*fitCat);
547 cleanupList.
addOwned(std::move(simPdfOwner));
550 for (
auto const& fcState : *fitCat) {
551 const std::string fcStateName = fcState.first;
554 fitCat->
setLabel(fcStateName.c_str());
558 if (!obc.
_restr.empty()) {
559 for(
auto * splitCat : static_range_cast<RooAbsCategory*>(fitCatList)) {
562 list<const RooCatType*> slist = obc.
_restr[splitCat] ;
567 list<const RooCatType*>::iterator sli ;
568 for (sli=slist.begin() ; sli!=slist.end() ; ++sli) {
569 if (
string(splitCat->getCurrentLabel())==(*sli)->GetName()) {
574 if (!select) continue ;
586 const std::string pdfName = pdf->
GetName();
587 auto found = std::find_if(customizerList.begin(), customizerList.end(),
588 [&](
auto const&
c){ return pdfName == c->pdf().GetName(); });
589 physCustomizer = found != customizerList.end() ? found->get() :
nullptr;
591 physCustomizer = customizerList.front().get();
595 oocoutI(
nullptr, ObjectHandling) <<
"RooSimWSTool::executeBuild: Customizing prototype pdf " << physCustomizer->
pdf().
GetName()
596 <<
" for mode " << fcStateName << endl ;
601 simPdf->
addPdf(*fcPdf,fcStateName.c_str()) ;
626 name += arg->GetName() ;
641 char paramBuf[4096] ;
643 strlcpy(paramBuf,paramNameList,4096) ;
644 strlcpy(catBuf,categoryNameList,4096) ;
647 list<string> catList ;
648 char* cat = strtok(catBuf,
"{,}") ;
650 catList.push_back(cat) ;
651 cat = strtok(0,
"{,}") ;
655 char* param = strtok(paramBuf,
"{,}") ;
658 param = strtok(0,
"{,}") ;
669 char paramBuf[4096] ;
671 strlcpy(paramBuf,paramNameList,4096) ;
672 strlcpy(catBuf,categoryNameList,4096) ;
675 list<string> catList ;
676 char* cat = strtok(catBuf,
"{,}") ;
678 catList.push_back(cat) ;
679 cat = strtok(0,
"{,}") ;
683 char* param = strtok(paramBuf,
"{,}") ;
685 _paramSplitMap[param] = pair<list<string>,
string>(catList,remainderStateName) ;
686 param = strtok(0,
"{,}") ;
698 list<const RooCmdArg*> cmdList ;
699 cmdList.push_back(&arg1) ; cmdList.push_back(&arg2) ;
700 cmdList.push_back(&arg3) ; cmdList.push_back(&arg4) ;
701 cmdList.push_back(&arg5) ; cmdList.push_back(&arg6) ;
703 list<const RooCmdArg*>::iterator iter ;
704 for (iter=cmdList.begin() ; iter!=cmdList.end() ; ++iter) {
706 if ((*iter)->opcode()==0)
continue ;
708 string name = (*iter)->opcode() ;
710 if (
name==
"SplitParam") {
711 splitParameter((*iter)->getString(0),(*iter)->getString(1)) ;
712 }
else if (
name==
"SplitParamConstrained") {
713 splitParameterConstrained((*iter)->getString(0),(*iter)->getString(1),(*iter)->getString(2)) ;
726 internalAddPdf(pdfName,
"",sr) ;
739 sr.
configure(arg1,arg2,arg3,arg4,arg5,arg6) ;
740 internalAddPdf(pdfName,
"",sr) ;
743 list<const RooCmdArg*> cmdList ;
744 cmdList.push_back(&arg1) ; cmdList.push_back(&arg2) ;
745 cmdList.push_back(&arg3) ; cmdList.push_back(&arg4) ;
746 cmdList.push_back(&arg5) ; cmdList.push_back(&arg6) ;
748 list<const RooCmdArg*>::iterator iter ;
749 for (iter=cmdList.begin() ; iter!=cmdList.end() ; ++iter) {
750 if ((*iter)->opcode()==0)
continue ;
751 string name = (*iter)->opcode() ;
752 if (
name==
"Restrict") {
753 restrictBuild((*iter)->getString(0),(*iter)->getString(1)) ;
755 if (
name==
"RenameConflictNodes") {
756 _conflProtocol = *(*iter) ;
778 strlcpy(buf,miStateNameList,4096) ;
780 char* tok = strtok(buf,
",") ;
783 tok = strtok(0,
",") ;
786 _pdfmap[pdfName] = sr ;
795 _restr[catName] = stateList ;
808 _masterCatName = masterIndexCat ;
821 sr.
configure(arg1,arg2,arg3,arg4,arg5,arg6) ;
822 internalAddPdf(pdfName,miStateList,sr) ;
832 internalAddPdf(pdfName,miStateList,sr) ;
854 map<RooAbsPdf*,ObjSplitRule>::iterator ri ;
855 for (ri = _pdfmap.begin() ; ri != _pdfmap.end() ; ++ri ) {
856 cout <<
"Splitrule for p.d.f " << ri->first->GetName() <<
" with state list " ;
857 for (std::list<const RooCatType*>::iterator misi= ri->second._miStateList.begin() ; misi!=ri->second._miStateList.end() ; ++misi) {
858 cout << (*misi)->GetName() <<
" " ;
862 map<RooAbsArg*,pair<RooArgSet,string> >::iterator csi ;
863 for (csi = ri->second._paramSplitMap.begin() ; csi != ri->second._paramSplitMap.end() ; ++csi ) {
864 if (csi->second.second.length()>0) {
865 cout <<
" parameter " << csi->first->GetName() <<
" is split with constraint in categories " << csi->second.first
866 <<
" with remainder in state " << csi->second.second << endl ;
868 cout <<
" parameter " << csi->first->GetName() <<
" is split with constraint in categories " << csi->second.first << endl ;
873 map<RooAbsCategory*,list<const RooCatType*> >::iterator riter ;
874 for (riter=_restr.begin() ; riter!=_restr.end() ; ++riter) {
875 cout <<
"Restricting build in category " << riter->first->GetName() <<
" to states " ;
876 list<const RooCatType*>::iterator i ;
877 for (i=riter->second.begin() ; i!=riter->second.end() ; ++i) {
878 if (i!=riter->second.begin()) cout <<
"," ;
879 cout << (*i)->GetName() ;
891std::string SimWSIFace::create(
RooFactoryWSTool& ft,
const char* typeName,
const char* instanceName, std::vector<std::string> args)
893 string tn(typeName) ;
894 if (tn==
"SIMCLONE") {
897 for (
unsigned int i=1 ; i<args.size() ; i++) {
898 if (args[i].find(
"$SplitParam(")!=0 &&
899 args[i].find(
"$SplitParamConstrained(")!=0 &&
900 args[i].find(
"$SplitRestrict(")!=0 &&
901 args[i].find(
"$Verbose(")!=0) {
902 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: unknown token %s encountered",args[i].c_str())) ;
908 for (
unsigned int i=1 ; i<args.size() ; i++) {
909 if (args[i].find(
"$SplitParam(")==0) {
911 if (subargs.size()!=2) {
912 throw string(
Form(
"Incorrect number of arguments in $SplitParam, have %d, expect 2",(
Int_t)subargs.size())) ;
914 sr.splitParameter(subargs[0].c_str(),subargs[1].c_str()) ;
915 }
else if (args[i].find(
"$SplitParamConstrained(")==0) {
917 if (subargs.size()!=3) {
918 throw string(
Form(
"Incorrect number of arguments in $SplitParamConstrained, have %d, expect 3",(
Int_t)subargs.size())) ;
920 sr.splitParameterConstrained(subargs[0].c_str(), subargs[1].c_str(), subargs[2].c_str()) ;
926 for (
unsigned int i=1 ; i<args.size() ; i++) {
927 if (args[i].find(
"$Restrict(")==0) {
929 if (subargs.size()!=2) {
930 throw string(
Form(
"Incorrect number of arguments in $Restrict, have %d, expect 2",(
Int_t)subargs.size())) ;
932 bc.restrictBuild(subargs[0].c_str(),subargs[1].c_str()) ;
938 for (
unsigned int i=1 ; i<args.size() ; i++) {
939 if (args[i].find(
"$Verbose(")==0) {
941 if (!subargs.empty()) {
942 verbose = atoi(subargs[0].c_str()) ;
949 RooAbsPdf* pdf = sct.build(instanceName,bc,verbose) ;
951 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() error in RooSimWSTool::build() for %s",instanceName)) ;
957 }
else if (tn==
"MSIMCLONE") {
962 for (
unsigned int i=1 ; i<args.size() ; i++) {
963 if (args[i].find(
"$AddPdf(")==0) {
969 for (
unsigned int j=2 ; j<subargs.size() ; j++) {
970 if (subargs[j].find(
"$SplitParam(")==0) {
972 if (subsubargs.size()!=2) {
973 throw string(
Form(
"Incorrect number of arguments in $SplitParam, have %d, expect 2",(
Int_t)subsubargs.size())) ;
975 sr.splitParameter(subsubargs[0].c_str(),subsubargs[1].c_str()) ;
976 }
else if (subargs[j].find(
"$SplitParamConstrained(")==0) {
978 if (subsubargs.size()!=3) {
979 throw string(
Form(
"Incorrect number of arguments in $SplitParamConstrained, have %d, expect 3",(
Int_t)subsubargs.size())) ;
981 sr.splitParameterConstrained(subsubargs[0].c_str(), subsubargs[1].c_str(), subsubargs[2].c_str()) ;
984 mbc.addPdf(subargs[0].c_str(),subargs[1].c_str(),sr) ;
986 }
else if (args[i].find(
"$Restrict(")==0) {
990 if (subargs.size()!=2) {
991 throw string(
Form(
"Incorrect number of arguments in $Restrict, have %d, expect 2",(
Int_t)subargs.size())) ;
993 mbc.restrictBuild(subargs[0].c_str(),subargs[1].c_str()) ;
996 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: unknown token in MSIMCLONE: %s",args[i].c_str())) ;
1002 RooAbsPdf* pdf = sct.build(instanceName,mbc,
false) ;
1004 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() error in RooSimWSTool::build() for %s",instanceName)) ;
1012 throw string(
Form(
"RooSimWSTool::SimWSIFace::create() ERROR: Unknown meta-type %s requested",typeName)) ;
1015 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.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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.
virtual TObject * clone(const char *newname=nullptr) const =0
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
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.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
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.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
const Text_t * GetName() const override
Returns name of object.
RooCategory is an object to represent discrete states.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
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
RooSimultaneous 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'.
The RooWorkspace is a 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.
bool 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.
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
const RooArgSet & components() const
const char * GetName() const override
Returns name of object.
TString & Append(const char *cs)
RooCmdArg Silence(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.