Print Chi2 from RooMCstudy

I would like to get the chi2 of the fit of the single toy of a MCstudy.
I can get the fitted parameters and their uncertanties, but I can’t seem able to find a way to print the Chi2, or anyway something that could tell me if the fit was good or bad.
What I have for now is:

for j in range(len(PDFdecays)):
        df_fit[f"n_{PDFdecays[j]}_val"] = [mcstudy.fitResult(i).floatParsFinal().find(f"n_{PDFdecays[j]}").getVal() for i in range(nMCevents)]
        df_fit[f"n_{PDFdecays[j]}_err"] = [mcstudy.fitResult(i).floatParsFinal().find(f"n_{PDFdecays[j]}").getError() for i in range(nMCevents)]
        df_fit[f"n_{PDFdecays[j]}_minNll"] = [mcstudy.fitResult(i).minNll() for i in range(nMCevents)]

I printed the min-log Likelihood but I don’t find it helpful.
Any idea?

Hi @mdgalati,
thanks for reaching out!
Can you include a complete code snippet so we’re able to reproduce your situation?

Cheers,
Monica

Hi Monica,
the code is quite long, but basically I do a mcstudy like so:

 mcstudy = R.RooMCStudy(
        pdf_model,
        vars,
        Binned=True,
        Silence=True,
        Extended=True,
        FitOptions=dict(Save=True, Strategy=2, PrintEvalErrors=0),
    )
    mcstudy.generateAndFit(nMCevents, sum(yields))

where pdf_model is a list of R.RooHistPdf.

Then I want to know the fit results for every toy, and I do that like:

df_fit= pd.DataFrame()
    df_fit[f"fit_minNll"] = [mcstudy.fitResult(i).minNll() for i in range(nMCevents)]
    print(mcstudy.fitResult(i).numInvalidNLL() for i in range(nMCevents))
    for j in range(len(PDFdecays)):
        df_fit[f"n_{PDFdecays[j]}_val"] = [mcstudy.fitResult(i).floatParsFinal().find(f"n_{PDFdecays[j]}").getVal() for i in range(nMCevents)]
        df_fit[f"n_{PDFdecays[j]}_err"] = [mcstudy.fitResult(i).floatParsFinal().find(f"n_{PDFdecays[j]}").getError() for i in range(nMCevents)]

I think @jonas can help you on this.

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