I already know how to get the chiSquare with the equal binning. But you know, for the purpose of Goodness test of unbinned maximum likelihood method, it is required that each bin should have at least ~10 events. So I am trying find a way to do this. Just several questions.

I think we could draw the RooDataSet with unequal binning by the option Binning(const RooAbsBinning&). But I don’t know after we draw the RooDataSet, the RooAbsPdf::plotOn would aware that one is using unequal binning? I would expect RooAbsPdf::plotOn should be independent of the binning, right? I think it just needs the x range and the total events.

If we could combine 2) and 3), then we could use them to calculate a meaningful chiSquare and do the goodness test of unbinned maximum likelihood method? So my last question is how could I pass an array to RooAbsBinning?

And it seems to me that RooAbsBinning could do an adapvtive binning, from the members in RooAbsBinning, e.g. , lowBound(), and so on. So I don’t know whether there is already a easy way.

If you want to calculate a chi^2/ndof of a curve w.r.t a histogram in a RooPlot one can simply call

frame->chiSquare(Int_t nfitParam) ;

where nFitParam is the number of floating fit parameters needed to adjust ndof. This example takes the chi^2 of last added dataset w.r.t the last added curve. If you have multiple curves or datasets in a RooPlot you can also specify the names

where the names of curve and histogram can be set by adding a Name(“blah”) argument to the RooAbsReal::plotOn() and RooAbsData::plotOn() calls respectively.

The above chi^2 calculated works for any binning, including non-uniform binning if a histogram involved in the calculation happens to have that.

To make a histogram with non-uniform binning, you can do the following

data->plotOn(frame,Binning(MyBinning))

where MyBinning is a RooAbsBinning implementation. For non-uniform binnings create e.g. a RooBinning object which allows each bin boundary to be set individually. When
the histogram is created the chosen binning will be used.

As you observed correctly, RooAbsPdf::plotOn() does not need to know the binning when plotted. In general the points that make the curve of a p.d.f projection do not match the bin boundaries of histograms as RooAbsPdf::plotOn() using an adaptive scheme to calculate which (x,y) points need to be added to achieve a given precision target. This is (by default) that the distance between the p.d.f value and the curve at any mid-point between two curve points cannot be larger than 1/1000 of the y-range of the frame. If the precision target is not met between any two points a new point is added between the existing points.

The chiSquare is independent of the choice of curve points because it can the curve value at any x value through interpolation if not curve point exists at the given value.

Thank you very much for your reply and for all your kind help recently.

There is still something I don’t understand. I have quoted them in the following.

What would it do if the RooHist binning is unequal? And what would hist.getNominalBinWidth() return if the bining is not equal, by implementation? I would guess that for some bin, the range (x-hbinw2,x+hbinw2) would be bigger than the bin range or smaller than it. Then the integral returned would be not equal to the bin content, even if the pdf fits the data perfectly? Please correct me if I misunderstood something here. For me, we need to do something like the following for the unequal bining:

[quote]// binbh[i]: high boundary of bin i; binbl[i]: low boundary of bin i.
Double_t hinbw[i] = (hist.binbh[i] – hist.binbl[i]) / 2.0 ;
//
Double_t avg[i] = average(x-hbinw[i], x+hbinw[i]) ;
…[/quote]

right? And it would be great if RooFit could implement an adaptive binning so that the user could just set the lowest bin content for the binning, like 10 entries at least, then RooFit could return a unequal binning hist and the curve (or also RooHist now), and the chi2. -

I just realized I pressed send to quickly. Concerning your second question: the need for adaptive binning also came up in a different context recently (data-weighted projections). I’ll put this on my to do list. I think I can make this available in the next 1-2 weeks or so (so it will be in 5.19/04 due early May)