#include "Rtypes.h"
#if !defined(R__ALPHA) && !defined(R__SOLARIS) && !defined(R__ACC) && !defined(R__FBSD)
NamespaceImp(RooStats)
#endif
#include "RooProdPdf.h"
#include "RooSimultaneous.h"
#include "RooStats/ModelConfig.h"
#include "RooStats/RooStatsUtils.h"
#include <typeinfo>
namespace RooStats {
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints) {
const std::type_info & id = typeid(pdf);
if (id == typeid(RooProdPdf)) {
RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
RooArgList list(prod->pdfList());
for (int i = 0, n = list.getSize(); i < n; ++i) {
RooAbsPdf *pdfi = (RooAbsPdf *) list.at(i);
FactorizePdf(observables, *pdfi, obsTerms, constraints);
}
} else if (id == typeid(RooSimultaneous) ) {
RooSimultaneous *sim = dynamic_cast<RooSimultaneous *>(&pdf);
RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
for (int ic = 0, nc = cat->numBins((const char *)0); ic < nc; ++ic) {
cat->setBin(ic);
FactorizePdf(observables, *sim->getPdf(cat->getLabel()), obsTerms, constraints);
}
delete cat;
} else if (pdf.dependsOn(observables)) {
if (!obsTerms.contains(pdf)) obsTerms.add(pdf);
} else {
if (!constraints.contains(pdf)) constraints.add(pdf);
}
}
void FactorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints) {
return FactorizePdf(*model.GetObservables(), pdf, obsTerms, constraints);
}
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name) {
RooArgList obsTerms, constraints;
FactorizePdf(observables, pdf, obsTerms, constraints);
return new RooProdPdf(name,"", constraints);
}
RooAbsPdf * MakeNuisancePdf(const RooStats::ModelConfig &model, const char *name) {
return MakeNuisancePdf(*model.GetPdf(), *model.GetObservables(), name);
}
}