Plotting difference between data and fit on the same plot for Cs-137 spectrum


I am trying to plot on the existing plot the difference between the fitted function and the histogram. I thought it was as simple as including the line h->Add(g,-1); but then my existing plot gets distorted. The macro works fine up until that line. I am very confused and any help would be greatly appreciated.
comp.cxx (1013 Bytes) Compton.txt (329.3 KB)
_ROOT Version: 6.23/01

Maybe @couet or @moneta cang give an advice, but why not using a ratio plot for this? Something like:

   auto rp1 = new TRatioPlot(h);

Yes, using the TRatioPlot as shown above it is the correct way for plotting the fit residuals.
If you have any issues using TRatioPlot please let us know

Best regards


1 Like

Thank you very much!