RooFit:RooMCStudy -> bug with Extended() option in 5.24


It seems to me that the Extended() option in RooMCStudy constructor is broken in 5.24 compared to 5.22. To see this, you can use the tutorial rf801_mcstudy.C, and modify it with:

RooMCStudy* mcstudy = new RooMCStudy(model,x,Binned(kTRUE),Extended(),FitOptions(Save(kTRUE),PrintEvalErrors(0))) ; // No option Silence() to see the output of the fits

mcstudy->generateAndFit(10) ; // Small numbers of fits
return; // We don’t care about the plots

We have the signal part with 150 events and the background part with 150 events (so sum = 300).
In 5.22, if for each fit you add nsig+nbkg after the fit (HESSE output), you obtain 270, 320, 290, etc. as you expect since a poisson fluctuation is introduced on the number of generated events (because of the Extended() option).
However, in 5.24, the exact same code will give for nsig+nbkg always a number close to 300. So the Extended() option is broken and does not work as expected.

Thanks if someone (probably Wouter) could have a look at it.


Hi Vincent,

I think I fixed this already, can you check that your application works OK in ROOT 5.25/04?


Hi Wouter,

I tried with root 5.25/04, roofit 3.11, and, no, this is not working as expected. This works correctly with 5.22, but not with 5.25/04, where the sum of nbkg+nsig is always equal to 300 in the example I give. You can try this out by running the example in attachment.


rf801_mcstudy.C (5.27 KB)


I just realize looking at your code that this bug is only present when we have the option Binned(kTRUE) in RooMCStudy constructor. So remove the Binned() option, and Extended() is working as expected ; put the Binned() option, and the Expected() option is broken.

This seems related to this part of code in RooMCStudy.cxx:

   if (_binGenData) {

	// Binned generation
	_genSample = _genModel->generateBinned(_dependents,nEvtPerSample) ;

      } else {

	// Calculate the number of (extended) events for this run
	if (_extendedGen) {
	  _nExpGen = _genModel->expectedEvents(&_dependents) ;
	  nEvt = RooRandom::randomGenerator()->Poisson(nEvtPerSample==0?_nExpGen:nEvtPerSample) ;

So if we have the binned option, there is no computation of the extended number of events following a Poisson law. I don’t think this is the expected behaviour, at least this was not like this in 5.22.



Hi Vincent,

Thanks for looking into that. I’ll fix it for ROOT 5.26
(out in a couple of weeks). I’ve filed this in Savannah