Generating Toys with less events

Hi
I am trying to generate toys where I have to generate very few events less than 10 events. My RooFit sometime crashes when I generate events less than 6-7 events and less than 10 (for complex shapes) when I use Poisson fluctuation (using Extended(kTRUE)). If I turn off the Poisson fluctuation, there is no crash.

The reason which I am able to think is that as events are less… there is a possibility of event going to zero and at that point RooFit crash. Is there any way to prevent this???

To prevent this, at present I am doing a trick… I get the Poisson distribution for the number (I need to generate) and write the events (100 times than the events I need to generate) corresponding to this distribution in a file and than using random events from this to generate events (with Poisson fluctuation off). This way I am artificially introducing Poisson fluctuation in my generation and if I get 0 events than I simple write some strange number which will be rejected by my fitter (as it is out of the range I specified).

My only worry is that using this, there may be chance of introducing some bias. So, I would like to know if there is some standard way to prevent my RooFit crash when I generate few events (<10) using Poisson fluctuation ON???

:::: I generate using the code below, if I need to generate 4 events::::
RooDataSet *data1=dGh.generate(RooArgSet(delte,modeh),4,Extended(kTRUE));

data1->write(“file.dat”);

Hi Vish,

I just want to remind that Poissonian distribution is only an approximation to distributions with large sample size and/or low success rate. For low stats, you might need to use Binomial variation, in which case the errors will be smaller than those in Poissonian (or sqrt(n)), this might also save your crashing problems.

Though, I don’t know how to do it directly in RooFit

regards,
Nikhil

Hello,
A workaround exists to avoid this crash. You should check that the returned pointer from the RooAbsPdf::generate method is not NULL. When is NULL, it means you have zero events.
You can see here as an example of a workaround
root.cern.ch/lxr/source/roofit/r … or.cxx#380

I agree, that RooFit should provide directly a solution for this
Best Regards

Lorenzo

:smiley: Thanks to everyone. It worked…

Hi Lorenzo,

In the current trunk, RooAbsPdf::generate() already returns an empty dataset instead of a null pointer.

Wouter