77 ClassImp(RooSimultaneous);
92 RooSimultaneous::RooSimultaneous(
const char *name,
const char *title,
93 RooAbsCategoryLValue& inIndexCat) :
94 RooAbsPdf(name,title),
95 _plotCoefNormSet(
"!plotCoefNormSet",
"plotCoefNormSet",this,kFALSE,kFALSE),
96 _plotCoefNormRange(0),
98 _indexCat(
"indexCat",
"Index category",this,inIndexCat),
113 RooSimultaneous::RooSimultaneous(
const char *name,
const char *title,
114 const RooArgList& inPdfList, RooAbsCategoryLValue& inIndexCat) :
115 RooAbsPdf(name,title),
116 _plotCoefNormSet(
"!plotCoefNormSet",
"plotCoefNormSet",this,kFALSE,kFALSE),
117 _plotCoefNormRange(0),
118 _partIntMgr(this,10),
119 _indexCat(
"indexCat",
"Index category",this,inIndexCat),
122 if (inPdfList.getSize() != inIndexCat.numTypes()) {
123 coutE(InputArguments) <<
"RooSimultaneous::ctor(" << GetName()
124 <<
" ERROR: Number PDF list entries must match number of index category states, no PDFs added" << endl ;
128 map<string,RooAbsPdf*> pdfMap ;
130 TIterator* pIter = inPdfList.createIterator() ;
131 TIterator* cIter = inIndexCat.typeIterator() ;
133 RooCatType* type(0) ;
134 while ((pdf=(RooAbsPdf*)pIter->Next())) {
135 type = (RooCatType*) cIter->Next() ;
136 pdfMap[string(type->GetName())] = pdf ;
141 initialize(inIndexCat,pdfMap) ;
147 RooSimultaneous::RooSimultaneous(
const char *name,
const char *title,
148 map<string,RooAbsPdf*> pdfMap, RooAbsCategoryLValue& inIndexCat) :
149 RooAbsPdf(name,title),
150 _plotCoefNormSet(
"!plotCoefNormSet",
"plotCoefNormSet",this,kFALSE,kFALSE),
151 _plotCoefNormRange(0),
152 _partIntMgr(this,10),
153 _indexCat(
"indexCat",
"Index category",this,inIndexCat),
156 initialize(inIndexCat,pdfMap) ;
164 namespace RooSimultaneousAux {
167 RooSimultaneous* simPdf ;
168 const RooAbsCategoryLValue* subIndex ;
169 RooArgSet* subIndexComps ;
173 void RooSimultaneous::initialize(RooAbsCategoryLValue& inIndexCat, std::map<std::string,RooAbsPdf*> pdfMap)
176 Bool_t simComps(kFALSE) ;
177 for (map<string,RooAbsPdf*>::iterator iter=pdfMap.begin() ; iter!=pdfMap.end() ; ++iter) {
178 if (dynamic_cast<RooSimultaneous*>(iter->second)) {
186 bool failure =
false;
187 for (map<string,RooAbsPdf*>::iterator iter=pdfMap.begin() ; iter!=pdfMap.end() ; ++iter) {
188 failure |= addPdf(*iter->second,iter->first.c_str()) ;
192 throw std::invalid_argument(std::string(
"At least one of the PDFs of the RooSimultaneous ")
193 + GetName() +
" is invalid.");
199 coutI(InputArguments) <<
"RooSimultaneous::initialize(" << GetName() <<
") INFO: one or more input component of simultaneous p.d.f.s are"
200 <<
" simultaneous p.d.f.s themselves, rewriting composite expressions as one-level simultaneous p.d.f. in terms of"
201 <<
" final constituents and extended index category" << endl ;
204 RooArgSet allAuxCats ;
205 map<string,RooSimultaneousAux::CompInfo> compMap ;
206 for (map<string,RooAbsPdf*>::iterator iter=pdfMap.begin() ; iter!=pdfMap.end() ; ++iter) {
207 RooSimultaneousAux::CompInfo ci ;
208 ci.pdf = iter->second ;
209 RooSimultaneous* simComp =
dynamic_cast<RooSimultaneous*
>(iter->second) ;
211 ci.simPdf = simComp ;
212 ci.subIndex = &simComp->indexCat() ;
213 ci.subIndexComps = simComp->indexCat().isFundamental() ?
new RooArgSet(simComp->indexCat()) : simComp->indexCat().getVariables() ;
214 allAuxCats.add(*(ci.subIndexComps),kTRUE) ;
218 ci.subIndexComps = 0 ;
220 compMap[iter->first] = ci ;
224 RooArgSet allCats(inIndexCat) ;
225 allCats.add(allAuxCats) ;
226 string siname = Form(
"%s_index",GetName()) ;
227 RooSuperCategory* superIndex =
new RooSuperCategory(siname.c_str(),siname.c_str(),allCats) ;
228 bool failure =
false;
231 for (map<string,RooSimultaneousAux::CompInfo>::iterator citer = compMap.begin() ; citer != compMap.end() ; ++citer) {
233 RooArgSet repliCats(allAuxCats) ;
234 if (citer->second.subIndexComps) {
235 repliCats.remove(*citer->second.subIndexComps) ;
236 delete citer->second.subIndexComps ;
238 inIndexCat.setLabel(citer->first.c_str()) ;
240 if (!citer->second.simPdf) {
243 RooSuperCategory repliSuperCat(
"tmp",
"tmp",repliCats) ;
246 for (
const auto type : repliSuperCat) {
248 repliSuperCat.setLabel(type->GetName()) ;
250 string superLabel = superIndex->getLabel() ;
251 failure |= addPdf(*citer->second.pdf,superLabel.c_str()) ;
252 cxcoutD(InputArguments) <<
"RooSimultaneous::initialize(" << GetName()
253 <<
") assigning pdf " << citer->second.pdf->GetName() <<
" to super label " << superLabel << endl ;
259 if (repliCats.getSize()==0) {
263 for (
const RooCatType* type : *citer->second.subIndex) {
264 const_cast<RooAbsCategoryLValue*
>(citer->second.subIndex)->setLabel(type->GetName()) ;
265 string superLabel = superIndex->getLabel() ;
266 RooAbsPdf* compPdf = citer->second.simPdf->getPdf(type->GetName()) ;
268 failure |= addPdf(*compPdf,superLabel.c_str()) ;
269 cxcoutD(InputArguments) <<
"RooSimultaneous::initialize(" << GetName()
270 <<
") assigning pdf " << compPdf->GetName() <<
"(member of " << citer->second.pdf->GetName()
271 <<
") to super label " << superLabel << endl ;
273 coutW(InputArguments) <<
"RooSimultaneous::initialize(" << GetName() <<
") WARNING: No p.d.f. associated with label "
274 << type->GetName() <<
" for component RooSimultaneous p.d.f " << citer->second.pdf->GetName()
275 <<
"which is associated with master index label " << citer->first << endl ;
284 RooSuperCategory repliSuperCat(
"tmp",
"tmp",repliCats) ;
286 for (
const RooCatType* stype : *citer->second.subIndex) {
287 const_cast<RooAbsCategoryLValue*
>(citer->second.subIndex)->setLabel(stype->GetName()) ;
289 for (
const RooCatType* rtype : repliSuperCat) {
290 repliSuperCat.setLabel(rtype->GetName()) ;
291 string superLabel = superIndex->getLabel() ;
292 RooAbsPdf* compPdf = citer->second.simPdf->getPdf(stype->GetName()) ;
294 failure |= addPdf(*compPdf,superLabel.c_str()) ;
295 cxcoutD(InputArguments) <<
"RooSimultaneous::initialize(" << GetName()
296 <<
") assigning pdf " << compPdf->GetName() <<
"(member of " << citer->second.pdf->GetName()
297 <<
") to super label " << superLabel << endl ;
299 coutW(InputArguments) <<
"RooSimultaneous::initialize(" << GetName() <<
") WARNING: No p.d.f. associated with label "
300 << stype->GetName() <<
" for component RooSimultaneous p.d.f " << citer->second.pdf->GetName()
301 <<
"which is associated with master index label " << citer->first << endl ;
310 throw std::invalid_argument(std::string(
"Failed to initialise RooSimultaneous ") + GetName());
314 _indexCat.setArg(*superIndex) ;
315 addOwnedComponents(*superIndex) ;
324 RooSimultaneous::RooSimultaneous(
const RooSimultaneous& other,
const char* name) :
325 RooAbsPdf(other,name),
326 _plotCoefNormSet(
"!plotCoefNormSet",this,other._plotCoefNormSet),
327 _plotCoefNormRange(other._plotCoefNormRange),
328 _partIntMgr(other._partIntMgr,this),
329 _indexCat(
"indexCat",this,other._indexCat),
330 _numPdf(other._numPdf)
333 TIterator* pIter = other._pdfProxyList.MakeIterator() ;
334 RooRealProxy* proxy ;
335 while ((proxy=(RooRealProxy*)pIter->Next())) {
336 _pdfProxyList.Add(
new RooRealProxy(proxy->GetName(),
this,*proxy)) ;
346 RooSimultaneous::~RooSimultaneous()
348 _pdfProxyList.Delete() ;
356 RooAbsPdf* RooSimultaneous::getPdf(
const char* catName)
const
358 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(catName) ;
359 return proxy ? ((RooAbsPdf*)proxy->absArg()) : 0 ;
378 Bool_t RooSimultaneous::addPdf(
const RooAbsPdf& pdf,
const char* catLabel)
381 if (pdf.dependsOn(_indexCat.arg())) {
382 coutE(InputArguments) <<
"RooSimultaneous::addPdf(" << GetName() <<
"): PDF '" << pdf.GetName()
383 <<
"' overlaps with index category '" << _indexCat.arg().GetName() <<
"'."<< endl ;
388 if (_pdfProxyList.FindObject(catLabel)) {
389 coutE(InputArguments) <<
"RooSimultaneous::addPdf(" << GetName() <<
"): index state '"
390 << catLabel <<
"' has already an associated PDF." << endl ;
394 const RooSimultaneous* simPdf =
dynamic_cast<const RooSimultaneous*
>(&pdf) ;
397 coutE(InputArguments) <<
"RooSimultaneous::addPdf(" << GetName()
398 <<
") ERROR: you cannot add a RooSimultaneous component to a RooSimultaneous using addPdf()."
399 <<
" Use the constructor with RooArgList if input p.d.f.s or the map<string,RooAbsPdf&> instead." << endl ;
405 TObject* proxy =
new RooRealProxy(catLabel,catLabel,
this,(RooAbsPdf&)pdf) ;
406 _pdfProxyList.Add(proxy) ;
420 RooAbsPdf::ExtendMode RooSimultaneous::extendMode()
const
422 Bool_t allCanExtend(kTRUE) ;
423 Bool_t anyMustExtend(kFALSE) ;
425 for (Int_t i=0 ; i<_numPdf ; i++) {
426 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(_indexCat.label()) ;
429 RooAbsPdf* pdf = (RooAbsPdf*) proxy->absArg() ;
430 if (!pdf->canBeExtended()) {
432 allCanExtend=kFALSE ;
434 if (pdf->mustBeExtended()) {
441 return MustBeExtended ;
445 return CanBeExtended ;
448 return CanNotBeExtended ;
458 Double_t RooSimultaneous::evaluate()
const
461 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(_indexCat.label()) ;
464 if (proxy==0)
return 0 ;
467 Double_t catFrac(1) ;
468 if (canBeExtended()) {
469 Double_t nEvtCat = ((RooAbsPdf*)(proxy->absArg()))->expectedEvents(_normSet) ;
471 Double_t nEvtTot(0) ;
472 TIterator* iter = _pdfProxyList.MakeIterator() ;
473 RooRealProxy* proxy2 ;
474 while((proxy2=(RooRealProxy*)iter->Next())) {
475 nEvtTot += ((RooAbsPdf*)(proxy2->absArg()))->expectedEvents(_normSet) ;
478 catFrac=nEvtCat/nEvtTot ;
482 return ((RooAbsPdf*)(proxy->absArg()))->getVal(_normSet)*catFrac ;
493 Double_t RooSimultaneous::expectedEvents(
const RooArgSet* nset)
const
495 if (nset->contains(_indexCat.arg())) {
499 TIterator* iter = _pdfProxyList.MakeIterator() ;
500 RooRealProxy* proxy ;
501 while((proxy=(RooRealProxy*)iter->Next())) {
502 sum += ((RooAbsPdf*)(proxy->absArg()))->expectedEvents(nset) ;
511 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(_indexCat.label()) ;
514 if (proxy==0)
return 0 ;
517 return ((RooAbsPdf*)(proxy->absArg()))->expectedEvents(nset);
528 Int_t RooSimultaneous::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars,
529 const RooArgSet* normSet,
const char* rangeName)
const
532 analVars.add(allVars) ;
538 CacheElem* cache = (CacheElem*) _partIntMgr.getObj(normSet,&analVars,0,RooNameReg::ptr(rangeName)) ;
540 code = _partIntMgr.lastIndex() ;
543 cache =
new CacheElem ;
546 TIterator* iter = _pdfProxyList.MakeIterator() ;
547 RooRealProxy* proxy ;
548 while((proxy=(RooRealProxy*)iter->Next())) {
549 RooAbsReal* pdfInt = proxy->arg().createIntegral(analVars,normSet,0,rangeName) ;
550 cache->_partIntList.addOwned(*pdfInt) ;
555 code = _partIntMgr.setObj(normSet,&analVars,cache,RooNameReg::ptr(rangeName)) ;
565 Double_t RooSimultaneous::analyticalIntegralWN(Int_t code,
const RooArgSet* normSet,
const char* )
const
569 return getVal(normSet) ;
573 CacheElem* cache = (CacheElem*) _partIntMgr.getObjByIndex(code-1) ;
575 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(_indexCat.label()) ;
576 Int_t idx = _pdfProxyList.IndexOf(proxy) ;
577 return ((RooAbsReal*)cache->_partIntList.at(idx))->getVal(normSet) ;
591 RooPlot* RooSimultaneous::plotOn(RooPlot *frame, RooLinkedList& cmdList)
const
594 if (plotSanityChecks(frame))
return frame ;
597 RooCmdConfig pc(Form(
"RooSimultaneous::plotOn(%s)",GetName())) ;
598 pc.defineString(
"sliceCatState",
"SliceCat",0,
"",kTRUE) ;
599 pc.defineDouble(
"scaleFactor",
"Normalization",0,1.0) ;
600 pc.defineInt(
"scaleType",
"Normalization",0,RooAbsPdf::Relative) ;
601 pc.defineObject(
"sliceCatList",
"SliceCat",0,0,kTRUE) ;
602 pc.defineObject(
"projSet",
"Project",0) ;
603 pc.defineObject(
"sliceSet",
"SliceVars",0) ;
604 pc.defineObject(
"projDataSet",
"ProjData",0) ;
605 pc.defineObject(
"projData",
"ProjData",1) ;
606 pc.defineMutex(
"Project",
"SliceVars") ;
607 pc.allowUndefined() ;
610 pc.process(cmdList) ;
615 const RooAbsData* projData = (
const RooAbsData*) pc.getObject(
"projData") ;
616 const RooArgSet* projDataSet = (
const RooArgSet*) pc.getObject(
"projDataSet") ;
617 const RooArgSet* sliceSetTmp = (
const RooArgSet*) pc.getObject(
"sliceSet") ;
618 RooArgSet* sliceSet = sliceSetTmp ? ((RooArgSet*) sliceSetTmp->Clone()) : 0 ;
619 const RooArgSet* projSet = (
const RooArgSet*) pc.getObject(
"projSet") ;
620 Double_t scaleFactor = pc.getDouble(
"scaleFactor") ;
621 ScaleType stype = (ScaleType) pc.getInt(
"scaleType") ;
625 const char* sliceCatState = pc.getString(
"sliceCatState",0,kTRUE) ;
626 const RooLinkedList& sliceCatList = pc.getObjectList(
"sliceCatList") ;
631 sliceSet =
new RooArgSet ;
636 strlcpy(buf,sliceCatState,1024) ;
637 const char* slabel = strtok(buf,
",") ;
640 TIterator* iter = sliceCatList.MakeIterator() ;
642 while((scat=(RooCategory*)iter->Next())) {
645 scat->setLabel(slabel) ;
647 sliceSet->add(*scat,kFALSE) ;
649 slabel = strtok(0,
",") ;
656 coutE(InputArguments) <<
"RooSimultaneous::plotOn(" << GetName() <<
") ERROR: must have a projection dataset for index category" << endl ;
661 RooArgSet projectedVars ;
665 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
668 TIterator* iter = sliceSet->createIterator() ;
669 RooAbsArg* sliceArg ;
670 while((sliceArg=(RooAbsArg*)iter->Next())) {
671 RooAbsArg* arg = projectedVars.find(sliceArg->GetName()) ;
673 projectedVars.remove(*arg) ;
675 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") slice variable "
676 << sliceArg->GetName() <<
" was not projected anyway" << endl ;
680 }
else if (projSet) {
681 makeProjectionSet(frame->getPlotVar(),projSet,projectedVars,kFALSE) ;
683 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
686 Bool_t projIndex(kFALSE) ;
688 if (!_indexCat.arg().isDerived()) {
693 if (!projData->get()->find(_indexCat.arg().GetName())) {
694 coutE(Plotting) <<
"RooSimultaneous::plotOn(" << GetName() <<
") ERROR: Projection over index category "
695 <<
"requested, but projection data set doesn't contain index category" << endl ;
699 if (projectedVars.find(_indexCat.arg().GetName())) {
707 TIterator* sIter = _indexCat.arg().serverIterator() ;
709 RooArgSet projIdxServers ;
710 Bool_t anyServers(kFALSE) ;
711 while((server=(RooAbsArg*)sIter->Next())) {
712 if (projectedVars.find(server->GetName())) {
714 projIdxServers.add(*server) ;
723 sIter = projIdxServers.createIterator() ;
724 Bool_t allServers(kTRUE) ;
725 while((server=(RooAbsArg*)sIter->Next())) {
726 if (!projData->get()->find(server->GetName())) {
733 coutE(Plotting) <<
"RooSimultaneous::plotOn(" << GetName()
734 <<
") ERROR: Projection dataset doesn't contain complete set of index category dependents" << endl ;
744 Roo1DTable* wTable = projData->table(_indexCat.arg()) ;
749 coutI(Plotting) <<
"RooSimultaneous::plotOn(" << GetName() <<
") plot on " << frame->getPlotVar()->GetName()
750 <<
" represents a slice in the index category (" << _indexCat.arg().GetName() <<
")" << endl ;
755 const RooAbsData* projDataTmp(projData) ;
758 RooArgSet* indexCatComps = _indexCat.arg().getObservables(frame->getNormVars());
762 TIterator* compIter = indexCatComps->createIterator();
763 RooAbsCategory* idxComp ;
764 Bool_t first(kTRUE) ;
765 while((idxComp=(RooAbsCategory*)compIter->Next())) {
766 RooAbsArg* slicedComponent =
nullptr;
767 if (sliceSet && (slicedComponent = sliceSet->find(*idxComp)) !=
nullptr) {
768 auto theCat =
static_cast<const RooAbsCategory*
>(slicedComponent);
769 auto idxCompLV =
dynamic_cast<RooAbsCategoryLValue*
>(idxComp);
771 idxCompLV->setIndex(theCat->getIndex(),
false);
775 cutString.Append(
"&&") ;
779 cutString.Append(Form(
"%s==%d",idxComp->GetName(),idxComp->getIndex())) ;
784 RooArgSet projDataVars(*projData->get()) ;
785 projDataVars.remove(*indexCatComps,kTRUE,kTRUE) ;
787 projDataTmp = ((RooAbsData*)projData)->reduce(projDataVars,cutString) ;
788 delete indexCatComps ;
797 RooCmdArg tmp1 = RooFit::Normalization(scaleFactor*wTable->getFrac(_indexCat.arg().getLabel()),stype) ;
798 RooCmdArg tmp2 = RooFit::ProjWData(*projDataSet,*projDataTmp) ;
801 RooLinkedList cmdList2(cmdList) ;
802 if (!cmdList.find(
"Asymmetry")) {
803 cmdList2.Add(&tmp1) ;
805 cmdList2.Add(&tmp2) ;
808 RooPlot* retFrame = getPdf(_indexCat.arg().getLabel())->plotOn(frame,cmdList2) ;
822 RooArgSet* idxCloneSet = (RooArgSet*) RooArgSet(_indexCat.arg()).snapshot(kTRUE) ;
823 RooAbsCategoryLValue* idxCatClone = (RooAbsCategoryLValue*) idxCloneSet->find(_indexCat.arg().GetName()) ;
826 RooArgSet* idxCompSliceSet = _indexCat.arg().getObservables(frame->getNormVars()) ;
827 idxCompSliceSet->remove(projectedVars,kTRUE,kTRUE) ;
828 TIterator* idxCompSliceIter = idxCompSliceSet->createIterator() ;
831 RooArgList pdfCompList ;
832 RooArgList wgtCompList ;
834 RooRealProxy* proxy ;
835 TIterator* pIter = _pdfProxyList.MakeIterator() ;
836 Double_t sumWeight(0) ;
837 while((proxy=(RooRealProxy*)pIter->Next())) {
839 idxCatClone->setLabel(proxy->name()) ;
842 Bool_t skip(kFALSE) ;
843 idxCompSliceIter->Reset() ;
844 RooAbsCategory* idxSliceComp ;
845 while((idxSliceComp=(RooAbsCategory*)idxCompSliceIter->Next())) {
846 RooAbsCategory* idxComp = (RooAbsCategory*) idxCloneSet->find(idxSliceComp->GetName()) ;
847 if (idxComp->getIndex()!=idxSliceComp->getIndex()) {
855 RooRealVar *wgtVar =
new RooRealVar(proxy->name(),
"coef",wTable->getFrac(proxy->name())) ;
856 wgtCompList.addOwned(*wgtVar) ;
857 sumWeight += wTable->getFrac(proxy->name()) ;
860 pdfCompList.add(proxy->arg()) ;
863 TString plotVarName(GetName()) ;
864 RooAddPdf *plotVar =
new RooAddPdf(plotVarName,
"weighted sum of RS components",pdfCompList,wgtCompList) ;
867 if (_plotCoefNormSet.getSize()>0) {
868 plotVar->fixAddCoefNormalization(_plotCoefNormSet) ;
871 RooAbsData* projDataTmp(0) ;
872 RooArgSet projSetTmp ;
877 if (idxCompSliceSet->getSize()>0) {
878 idxCompSliceIter->Reset() ;
879 RooAbsCategory* idxSliceComp ;
880 Bool_t first(kTRUE) ;
881 while((idxSliceComp=(RooAbsCategory*)idxCompSliceIter->Next())) {
883 cutString.Append(
"&&") ;
887 cutString.Append(Form(
"%s==%d",idxSliceComp->GetName(),idxSliceComp->getIndex())) ;
892 RooArgSet projDataVars(*projData->get()) ;
893 RooArgSet* idxCatServers = _indexCat.arg().getObservables(frame->getNormVars()) ;
895 projDataVars.remove(*idxCatServers,kTRUE,kTRUE) ;
897 if (idxCompSliceSet->getSize()>0) {
898 projDataTmp = ((RooAbsData*)projData)->reduce(projDataVars,cutString) ;
900 projDataTmp = ((RooAbsData*)projData)->reduce(projDataVars) ;
906 projSetTmp.add(*projSet) ;
907 projSetTmp.remove(*idxCatServers,kTRUE,kTRUE);
911 delete idxCatServers ;
915 if (_indexCat.arg().isDerived() && idxCompSliceSet->getSize()>0) {
916 coutI(Plotting) <<
"RooSimultaneous::plotOn(" << GetName() <<
") plot on " << frame->getPlotVar()->GetName()
917 <<
" represents a slice in index category components " << *idxCompSliceSet << endl ;
919 RooArgSet* idxCompProjSet = _indexCat.arg().getObservables(frame->getNormVars()) ;
920 idxCompProjSet->remove(*idxCompSliceSet,kTRUE,kTRUE) ;
921 if (idxCompProjSet->getSize()>0) {
922 coutI(Plotting) <<
"RooSimultaneous::plotOn(" << GetName() <<
") plot on " << frame->getPlotVar()->GetName()
923 <<
" averages with data index category components " << *idxCompProjSet << endl ;
925 delete idxCompProjSet ;
927 coutI(Plotting) <<
"RooSimultaneous::plotOn(" << GetName() <<
") plot on " << frame->getPlotVar()->GetName()
928 <<
" averages with data index category (" << _indexCat.arg().GetName() <<
")" << endl ;
933 RooLinkedList cmdList2(cmdList) ;
935 RooCmdArg tmp1 = RooFit::Normalization(scaleFactor*sumWeight,stype) ;
936 RooCmdArg tmp2 = RooFit::ProjWData(*projDataSet,*projDataTmp) ;
938 if (!cmdList.find(
"Asymmetry")) {
939 cmdList2.Add(&tmp1) ;
941 cmdList2.Add(&tmp2) ;
944 if (projSetTmp.getSize()>0) {
946 RooCmdArg tmp3 = RooFit::Project(projSetTmp) ;
947 cmdList2.Add(&tmp3) ;
948 frame2 = plotVar->plotOn(frame,cmdList2) ;
951 frame2 = plotVar->plotOn(frame,cmdList2) ;
959 delete idxCompSliceIter ;
960 delete idxCompSliceSet ;
963 if (projDataTmp)
delete projDataTmp ;
973 RooPlot* RooSimultaneous::plotOn(RooPlot *frame, Option_t* drawOptions, Double_t scaleFactor,
974 ScaleType stype,
const RooAbsData* projData,
const RooArgSet* projSet,
975 Double_t , Bool_t ,
const RooArgSet* ,
976 Double_t , Double_t , RooCurve::WingMode )
const
979 RooLinkedList cmdList ;
980 cmdList.Add(
new RooCmdArg(RooFit::DrawOption(drawOptions))) ;
981 cmdList.Add(
new RooCmdArg(RooFit::Normalization(scaleFactor,stype))) ;
982 if (projData) cmdList.Add(
new RooCmdArg(RooFit::ProjWData(*projData))) ;
983 if (projSet) cmdList.Add(
new RooCmdArg(RooFit::Project(*projSet))) ;
986 RooPlot* ret = plotOn(frame,cmdList) ;
1000 void RooSimultaneous::selectNormalization(
const RooArgSet* normSet, Bool_t )
1002 _plotCoefNormSet.removeAll() ;
1003 if (normSet) _plotCoefNormSet.add(*normSet) ;
1012 void RooSimultaneous::selectNormalizationRange(
const char* normRange2, Bool_t )
1014 _plotCoefNormRange = RooNameReg::ptr(normRange2) ;
1022 RooAbsGenContext* RooSimultaneous::autoGenContext(
const RooArgSet &vars,
const RooDataSet* prototype,
1023 const RooArgSet* auxProto, Bool_t verbose, Bool_t autoBinned,
const char* binnedTag)
const
1025 const char* idxCatName = _indexCat.arg().GetName() ;
1027 if (vars.find(idxCatName) && prototype==0
1028 && (auxProto==0 || auxProto->getSize()==0)
1029 && (autoBinned || (binnedTag && strlen(binnedTag)))) {
1032 return new RooSimSplitGenContext(*
this,vars,verbose,autoBinned,binnedTag) ;
1037 return genContext(vars,prototype,auxProto,verbose) ;
1046 RooAbsGenContext* RooSimultaneous::genContext(
const RooArgSet &vars,
const RooDataSet *prototype,
1047 const RooArgSet* auxProto, Bool_t verbose)
const
1049 const char* idxCatName = _indexCat.arg().GetName() ;
1050 const RooArgSet* protoVars = prototype ? prototype->get() : 0 ;
1052 if (vars.find(idxCatName) || (protoVars && protoVars->find(idxCatName))) {
1055 return new RooSimGenContext(*
this,vars,prototype,auxProto,verbose) ;
1057 }
else if (_indexCat.arg().isDerived()) {
1061 Bool_t anyServer(kFALSE), allServers(kTRUE) ;
1063 TIterator* sIter = _indexCat.arg().serverIterator() ;
1065 while((server=(RooAbsArg*)sIter->Next())) {
1066 if (prototype->get()->find(server->GetName())) {
1080 return new RooSimGenContext(*
this,vars,prototype,auxProto,verbose) ;
1081 }
else if (!allServers && anyServer) {
1083 coutE(Plotting) <<
"RooSimultaneous::genContext: ERROR: prototype must include either all "
1084 <<
" components of the RooSimultaneous index category or none " << endl ;
1091 RooRealProxy* proxy = (RooRealProxy*) _pdfProxyList.FindObject(_indexCat.arg().getLabel()) ;
1093 coutE(InputArguments) <<
"RooSimultaneous::genContext(" << GetName()
1094 <<
") ERROR: no PDF associated with current state ("
1095 << _indexCat.arg().GetName() <<
"=" << _indexCat.arg().getLabel() <<
")" << endl ;
1098 return ((RooAbsPdf*)proxy->absArg())->genContext(vars,prototype,auxProto,verbose) ;
1106 RooDataHist* RooSimultaneous::fillDataHist(RooDataHist *hist,
1107 const RooArgSet* nset,
1108 Double_t scaleFactor,
1109 Bool_t correctForBinVolume,
1110 Bool_t showProgress)
const
1112 if (RooAbsReal::fillDataHist (hist, nset, scaleFactor,
1113 correctForBinVolume, showProgress) == 0)
1117 for (
int i=0 ; i<hist->numEntries() ; i++) {
1119 sum += hist->weight();
1122 for (
int i=0 ; i<hist->numEntries() ; i++) {
1124 hist->set (hist->weight() / sum);
1137 RooDataSet* RooSimultaneous::generateSimGlobal(
const RooArgSet& whatVars, Int_t nEvents)
1140 RooArgSet* globClone = (RooArgSet*) whatVars.snapshot() ;
1142 RooDataSet* data =
new RooDataSet(
"gensimglobal",
"gensimglobal",whatVars) ;
1145 TIterator* iter = indexCat().typeIterator() ;
1147 for (Int_t i=0 ; i<nEvents ; i++) {
1150 while((tt=(RooCatType*) iter->Next())) {
1153 RooAbsPdf* pdftmp = getPdf(tt->GetName()) ;
1156 RooArgSet* globtmp = pdftmp->getObservables(whatVars) ;
1157 RooDataSet* tmp = pdftmp->generate(*globtmp,1) ;
1160 *globClone = *tmp->get(0) ;
1166 data->add(*globClone) ;