Creation of TH1 from a RooAddPdf object

Dear all,

I’m trying to convert a RooAddPdf object in a TH1 histogram, but the createHistogram() function retrieves me a TH1 object with just 1 entry.

I would like to perform a chi-square test (finding the chi2 variable, its associated p-value and possibly the array of residuals), but beceause of this problem I get a nan value from the TH1 Chi2Test() method.

This is the code:

RooDataHist ResolRed ("ReducedData", "Histogram", x, resol);
RooExtendPdf epeak ("esig",  "esig", peakSig, peak_yield);

RooAddPdf pdfsig("sigall", "globalsignal", RooArgList(peakSig), RooArgList(peak_yield) );

RooExtendPdf ebkg ("ebkg",  "ebkg", bkg, bkg_yield);
RooAddPdf model("MyModel", "MyModel", shapes);//, yields);
model.fitTo( ResolRed, RooFit::Extended() );
RooPlot* frame = x.frame(RooFit::Bins(nbins), RooFit::Name("x"), RooFit::Title("Time Delay") );

TH1* uwhisto = model.createHistogram("uwhisto", x, Binning(2000) );
TH1* whisto = ResolRed.createHistogram("whisto", x, Binning(2000) );
double chi = whisto->chi2Test(uwhisto, "");
cout << "Integral of uwhisto: " << uwhisto->Integral() << endl;
cout << "Integral of whisto: " << whisto->Integral() << endl;
cout << "pvalue: " << chi << endl;

which gives this output:

Integral of uwhisto: 1
Integral of whisto: 23187
pvalue: nan

Since I’m new in using RooFit, I will appreciate if anywone would suggest me any other efficient way to reach this goal.