# Help Generating Dataset from Nested RooSimultaneous

**URL:** <https://root-forum.cern.ch/t/help-generating-dataset-from-nested-roosimultaneous/33650>\
**Category:** Roofit and RooStats\
**Created:** [April 17, 2019, 9:19pm UTC](https://root-forum.cern.ch/t/help-generating-dataset-from-nested-roosimultaneous/33650 "2019-04-17T21:19:52Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [April 23, 2019, 9:07am UTC](https://root-forum.cern.ch/t/help-generating-dataset-from-nested-roosimultaneous/33650/4 "2019-04-23T09:07:29Z")

</div>

Hi @SAlsum,

**1. Weighted vs. Unweighted Events**

> [@SAlsum](#):
>
> 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](https://root-forum.cern.ch/t/roohistpdf-generate-method-not-working-as-expected/33666/3))

indeed, that’s unrelated to the first problem. Just for completeness (if somebody else reads this thread):  
If you ask for 10 events on a binned dataset, you will get one entry per bin (four in your case), but the **sum of weights** will be 10. More details can be found in the post you linked.

**2. Number of Events in Nested Categories**  
Could you just add a short answer on how you got around the following problem?

> [@SAlsum](#):
>
> I get the error:
> 
> ```auto
> [#0] ERROR:Generation -- RooSimGenContext::ctor(simulPdf) ERROR: Need either extended mode or prototype data to calculate number of events per category
> [#0] ERROR:Generation -- RooAbsPdf::generate(simulPdf) cannot create a valid context
> 
> ```

I can at least tell you why it doesn’t work when you just ask the top-level PDF for a specific number of events. The problem is that RooFit cannot know how many events to put in which category if the top-level PDF is not extended. Let’s say you want 5 events, and you have two categories. Should the split be {3,2} or {2.5,2.5}, or something completely different? In your example it’s even a bit more complicated because the categories are nested, so if you join A and B, which each have a category 1 and 2, there are actually four categories (A1 B1, A2 B1, A1 B2, A2 B2).

There’s two options I can see how to solve this:

- The SuperCategory. It creates one category for each combination of sub-categories, so it joins them. With this, you can select each combination of categories in A and B directly. That’s why the generation succeeds, because you can say for each category how many events you want.
- You need to extend the PDFs when making the categories. When you do this, (let’s say the original A1 has 5 events and the original A2 has 10), it’s clear that the ratio of A1 to A2 is 0.5. Then, if you ask the top-level PDF for 9 events from A, there should be 3 in A1 and 6 in A2.

---

_[View the full topic](https://root-forum.cern.ch/t/help-generating-dataset-from-nested-roosimultaneous/33650)._
