RooFit: fitting 2 identical? histograms - different results?

I wanted (for my own reasons) to save in the histogram format the data created by

RooDataSet* tmodel_data=tmodel.generate(t,nevtot) ;

so I came with following (a snippet from a larger code):

int iseed=6676 ;
tbin=280 ;
RooRandom::randomGenerator()->SetSeed(iseed) ;
RooDataSet* tmodel_data=tmodel.generate(t,nevtot) ;
TFile ft = new TFile(“tmodel_hist.root”,“RECREATE”);
TH1
ht280=tmodel_data->createHistogram(“ht280”,t,Binning(tbin,-80,200)) ;
ft->Write() ; ft->Close() ;

Now I can read in and fit that histogram (it took me some time to realize that, for some reason,
the saved histogram name is not “h280”, but has appended “__t”, namely “h280__t” ;8-):

TFile ft = new TFile(“tmodel_hist.root”);
TH1
ht = (TH1*) gDirectory->Get(“ht280__t”);
RooDataHist* tmodel_hist= new RooDataHist(“tmodel_hist”,“tmodel_hist”,t,Import(*ht)) ;
tmodel.fitTo(*tmodel_hist) ;

So, what is my problem? Well, when I do just (without creating a histogram, writing it
to a file, and reading it back):

tbin=280 ;
RooDataHist* tmodel_hist = tmodel.generateBinned(t,nevtot) ;
tmodel.fitTo(*tmodel_hist) ;

with the same limits in variable “t” and the same number of bins as above,
my fit result is different!

I thought that:

RooDataHist* tmodel_hist = tmodel.generateBinned(t,nevtot) ;

and

RooDataSet* tmodel_data=tmodel.generate(t,nevtot) ;
TH1* ht280=tmodel_data->createHistogram(“ht280”,t,Binning(tbin,-80,200))

will generate the absolutely the same histogram, with the same binning, limits, and
the number of events and that, naturally, the fit results will be the same?

I don’t understand that, I must be missing some detail …
I set the same random seed and I am using a large statistics (1E8 events) in case
that the random seed is somehow reset. But the parameter fit results differ by 2 percent
in two cases …?

Hi,

You not should expect the binned output of generate() and generateBinned() to be identical when starting from a given random seed, although they do both represent samples from the same distribution.

In the first case, a one or more random seeds is/are used to generate each individual event, which you then convert in a histogram afterwards. GenerateBinned() follows a much more efficienct approach (for cases wheere nbin<nevent) where a Poisson is randomly drawn for each bin, so random numbers are used in a different way.

Wouter