Plot chi-square distribution on a histogram

Hi, rooters,

I have a histogram obtained from likelihood analysis.
I wanna plot chi-square distributions with a few degree of freedoms(for instance, 1, 2, … ) on this histogram to demonstrate the histogram follows a specific chi-square distribution well.

After looking for around here, I can’t find a solution.
Could you please tell me how to do it ?

Thanks in advance !

Best,
Junhui

Hi Junhui,

    TF1 chi2_1dofF("chi2_1dofF","ROOT::Math::chisquared_pdf(x,1,0)",0,10);
    TF1 chi2_2dofF("chi2_1dofF","ROOT::Math::chisquared_pdf(x,2,0)",0,10);
    chi2_2dofF.SetLineColor(kBlue);
    TF1 chi2_3dofF("chi2_1dofF","ROOT::Math::chisquared_pdf(x,3,0)",0,10);
    chi2_3dofF.SetLineColor(kOrange);
    
    chi2_1dofF.Draw();
    chi2_2dofF.Draw("same");
    chi2_3dofF.Draw("same");

Cheers,
Danilo

Hi, Danilo,

Thanks for help !

Due to unknown reason(Root version ?), I have to define a TF1 like the following. Otherwise, it doesn’t work …

    TF1* chi2_1dofF = new TF1("chi2_1dofF","ROOT::Math::chisquared_pdf(x,1,0)",0,10);

Anyway, thanks !

Best,
Junhui