Plotting RooDataHist with uneven binning


There is a RooDataSet that I want to convert into a RooDataHist with particular binning.
So I create a RooDataHist with uneven binning using ::RooDataHist(name,title,vars,myBinning), and then do ::add(dataset)

I can see that the binning was set correctly and all bins have ::weight() just like I expected.
But I can’t find a way to plot it such that it shows actual number of events in each bin. Instead, as you can see in the attached snapshot, it plots something like events density.

Is there a way to do that, a plotting option or something like that?



Btw, while I typically use r5.26, I know that with 5.27 one could create a TH1 first, and then make roodatahist with Import(TH1, kFALSE), but it freezes with my root.5.27/4
roodatahist_plot.pdf (121 KB)

So, given absence of reply, it was probably something obvious to everyone, but just in case:

to plot RooDataHist with number of events, instead of event densities, I had to use option ‘DataError(RooAbsData::SumW2)’.

I see that when RooDataHist::plotOn calls RooAbsData::plotOn(RooPlot*, PlotOpt), the latter eventually converts the TH1* it created into a RooHist object on the heap. The constructor of RooHist will call either addBin(), or addBinWithError(), depending on the error type [by default Poisson, hence addBin()]
addBinWithError() will convert number of events into density given the condition:

if(binWidth > 0 && correctForBinWidth) {
scale= _nominalBinWidth/binWidth;

while addBin() uses only:

if(binWidth > 0 ) {
scale= _nominalBinWidth/binWidth;

i.e. even with correctForBinWidth=kFALSE.


1 Like

Many thanks for your question and the reply!
I was going around the source code trying to find how to instruct PlotOpt to not correct for bin size, even after having set Import(TH1 *, kFALSE).

–> First, the subtlty with
Import (TH1*, kFALSE)
should be made clearER in the documentation
–> AND the second point, i.e. the fact that the RooHist object respects your correctForBinWidth choice depending on your choice of errors is a bug. That should be fixed

Thanks again