In an effort to bypass the generate call on the top layered RooSimultaneous, I attempted to use the RooSuperCategory created by this RooSimultaneous to just access the stored pdf directly and use it to generate the events. I replaced the code in the above post below
"// try nested simul"
with the following:
// try nested simul
w->cat("cat1")->setLabel("cat1Negative");
w->cat("cat2")->setLabel("cat2Negative");
cout << "top layer pdf RooSuperCategory named: "
<< ((RooSimultaneous*)w->pdf("simulPdf"))->indexCat().GetName()
<< endl;
cout << "super category label being used: "
<< ((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel() << endl;
// generate the actual data set
RooDataSet* genNegDS =
((RooSimultaneous*)w->pdf("simulPdf"))
->getPdf(((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel())
->generate(*w->set("vars"), 10);
cout << "data generated from pdf: "
<< ((RooSimultaneous*)w->pdf("simulPdf"))
->getPdf(((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel())
->GetName() << endl;
// look at events
for(int i = 0; i < genNegDS->numEntries(); i++){
const RooArgSet* tmpSet = genNegDS->get(i);
cout << "generated x: " << tmpSet->getRealValue("x") << " "
<< "generated y: " << tmpSet->getRealValue("y")
<< endl;
}
// try nested simul
w->cat("cat1")->setLabel("cat1Negative");
w->cat("cat2")->setLabel("cat2Negative");
cout << "top layer pdf RooSuperCategory named: "
<< ((RooSimultaneous*)w->pdf("simulPdf"))->indexCat().GetName()
<< endl;
cout << "super category label being used: "
<< ((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel() << endl;
// generate the actual data set
RooDataSet* genNegDS =
((RooSimultaneous*)w->pdf("simulPdf"))
->getPdf(((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel())
->generate(*w->set("vars"), 10);
cout << "data generated from pdf: "
<< ((RooSimultaneous*)w->pdf("simulPdf"))
->getPdf(((RooSuperCategory*)w->obj("simulPdf_index"))->getLabel())
->GetName() << endl;
// look at events
for(int i = 0; i < genNegDS->numEntries(); i++){
const RooArgSet* tmpSet = genNegDS->get(i);
cout << "generated x: " << tmpSet->getRealValue("x") << " "
<< "generated y: " << tmpSet->getRealValue("y")
<< endl;
}
This yielded the following output:
cat1 negative, cat2 negative: x=-1 y=-1: 1
cat1 negative, cat2 negative: x=-0.8 y=-0.85: 1
cat1 negative, cat2 negative: x=-0.6 y=-0.7: 1
cat1 negative, cat2 negative: x=-0.4 y=-0.55: 1
cat1 negative, cat2 negative: x=-0.2 y=-0.4: 1
cat1 negative, cat2 negative: x=0 y=-0.25: 0
cat1 negative, cat2 negative: x=0.2 y=-0.1: 0
cat1 negative, cat2 negative: x=0.4 y=0.05: 0
cat1 negative, cat2 negative: x=0.6 y=0.2: 0
cat1 negative, cat2 negative: x=0.8 y=0.35: 0
generated x: -0.858381 generated y: -0.26699
generated x: -0.729474 generated y: -0.784387
generated x: -0.915259 generated y: -0.689318
generated x: -0.0609316 generated y: -0.0226334
generated x: -0.351653 generated y: -0.496254
generated x: -0.219934 generated y: 0.958981
generated x: -0.847732 generated y: 0.208973
generated x: -0.117388 generated y: 0.827671
generated x: -0.965437 generated y: 0.87946
generated x: -0.161526 generated y: 0.324706
above events generated from PDF: xNegYPosPdf
top layer pdf RooSuperCategory named: simulPdf_index
super category label being used: {cat1Negative;cat2Negative}
data generated from pdf: xNegYNegPdf
generated x: -0.5 generated y: -0.5
generated x: -0.5 generated y: 0.5
generated x: 0.5 generated y: -0.5
generated x: 0.5 generated y: 0.5
Everything works as expected until I look at the generated events from the pdf I accessed.
First, there are 4 events instead of the 10 requested.
Second, they appear to be the values stored in the 4 histograms that were used to create the RooHistPdfs earlier, not events generated from the single accessed RooHistPdf.
I am pretty confused as to what is going on here.
later edit
It turns out this problem (generating only 4 strange events rather than the number requested) turned out to be related to my RooHistPdfs, not the RooSimultaneous in any way. I needed to deactivate AutoBinned (see RooHistPdf Generate method not working as expected - #3 by SAlsum)
The following changes then worked to generate events from the stored pdfs:
// get the name of the top layer RooSimultaneous (Super)Category
string superCatName =
((RooSimultaneous*)w->pdf("simulPdf"))->indexCat().GetName();
cout << "top layer pdf RooSuperCategory named: "
<< superCatName << endl;
string thisSuperCatLabel;
w->cat("cat1")->setLabel("cat1Negative");
w->cat("cat2")->setLabel("cat2Positive");
// generate the actual data set
thisSuperCatLabel =
((RooAbsCategory*)w->obj(superCatName.c_str()))->getLabel();
cout << "super cat label is: " << thisSuperCatLabel << endl;
RooDataSet* genNegDS =
((RooSimultaneous*)w->pdf("simulPdf"))
->getPdf(thisSuperCatLabel.c_str())
->generate(*w->set("vars"), AutoBinned(0), NumEvents(5), Verbose(1));
// look at events
for(int i = 0; i < genNegDS->numEntries(); i++){
const RooArgSet* tmpSet = genNegDS->get(i);
cout << "generated x: " << tmpSet->getRealValue("x") << " "
<< "generated y: " << tmpSet->getRealValue("y")
<< endl;
}