Plotting individual fits on different histograms

I am trying to scan a histogram and fit a gaussian +background function by incrementing the mean of the gaussian function (by using a loop),to my histogram and then showing the result of this combined fit

hist5->Fit("fgaus", "+", "",10.5, 30); fgaus->Draw("same");

My question is, how can I show each of the individual fits (1gaussian+backgrnd) on different histograms? I have 18 such fits so i do not want to divide the Canvas into pads.


Just plot them using option “same” …
Do you have a small example showing what you are doing right now ?

I am doing the long way of defining 18 canvases and drawing the fitted function on different histograms. This is a summary of the code, where I have set values of other parameters but am not showing it here

c1->cd(); hist5->Draw(); c2-cd(); hist5->Draw(); for (int j=0; j<18; j++){ double mean = 11+(1*j); double sigma = (mean/3.096)*0.07; fgaus->FixParameter(1,mean); fgaus->FixParameter(2,sigma); hist5->Fit("fgaus", "", "",10.5, 30); if (j=0){ c1->cd() f1->Draw("same"); } if(j=1){ c2->cd(); f1->Draw("same"); } }
so basically I am using the if statement 18 times, even then all of the canvases only show the last fitting for mean=28 and none of the other fits.

Your macro does not show how you create the canvases. If you use TCanvas::Divide() you can do
c->cd(i) where “i” is the canvas number… no need to duplicate your code many times.
Like in: … opt.C.html