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

Hello,

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);
   rp1->Draw();
   rp1->GetLowerRefGraph()->SetMinimum(-5);
   rp1->GetLowerRefGraph()->SetMaximum(5);

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

Lorenzo

1 Like

Thank you very much!