Two datasets on the same frame using RooFit?

Hi all,

(reposting what I posted in Root Support)

I am using RooFIT to do unbinned fit the following way:

(1) I have two datasets (the variable is the Z mass):
one from real data and the other from simulated data
each having different total number of events.

(2) I want to fit each of the datasets with a PDF (crystal ball) separately
and want to plot it on the same frame so that I can compare both the fits
and see if there is any shift in the Z peak.

I know how to plot and fit one dataset.
is it possible to plot both the dataset points (which have different number of entries)
and there fits on the same frame so that i can compare the Z peak?

Thanks for help,


I don’t think you can plot both datasets on the same plot (but I might be wrong). However it is possible to plot both PDFs on the same plot. If you plot PDF on a frame without data present the PDF is normalized to unity; if it’s on a frame with data plotted the PDF normalized to that data. If you create an empty frame and plot both PDFs you can compare them. If you plot one of the datasets first both PDFs will normalize to that data.

I’d suggest:

  • for each of the 2 datasets make a plot of data and fitted function
  • and the make a plot comparing the shapes of the 2 fitted functions (with no data).

You might want to keep searching for a 2-datasets plots but there would be otherwise workarounds like:

  • using RooAbsData::tree() to get a TTree you can plot in ROOT. There is also a way of converting a RooAbsPdf into a TF1 so you can definitely get the plot you want this way
  • transforming the datasets in RooDataHist and RooHistPdf and this way the shapes of these PDFs representing the data can be compared (but that’s a quite nasty solution: esp. the bin errors will not be displayed and you may need to enforce somehow the data normalizations).


– Gregory

Hello Gregory,

Many thanks.
I will try your suggestions.