Plotting fitted histograms inside a for loop

Hi all, I’m trying to fit and plot the results of a RooMCStudy.
The way I’m doing it is:

c = R.TCanvas("MCstudy", "MCstudy", 4000, 900)
c.Divide(len(N_list), 1)
histos=[]
fits=[]
for j in range(len(N_list)):
   histos.append(R.RooAbsData.createHistogram(mcstudy.fitParDataSet(), "", N_list[j], RF.AutoBinning(MCbins))) 
    #fits.append(R.TF1(f"fit_gauss_{j}","gaus"))
    #histos[j].Fit(fits[j])
    c.cd(j+1)
    histos[j].Draw("E1")
c.SaveAs(tree_path + "yields_MCstudy.pdf") 

where N_list is the list of yields that I’m fitting in the MCstudy (5 in total).

If I don’t do the fits I obtain 5 plots in a row, as expected:
yields_MCstudy.pdf (23.0 KB)

But as soon as I uncomment the two lines to fit those histograms I obtain just the last plot of the for loop.
yields_MCstudy.pdf (15.6 KB)

Anyone can help me understand what I’m doing wrong?

Move the line “c.cd(j+1)” to the beginning of your loop (or at least before the “Fit” call).

Couldn’t have been easier :sweat_smile: Thanks @Wile_E_Coyote!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.