{ gROOT->Reset(); gStyle->SetOptFit(1); // Set the distribution function: TF1 func("distribution","[0]*(x^2)*exp(-(x^2)/[1])", -5., 5.); // Declare initial parameters: func.SetParameters(10., 4.); // Create the histogram: TH1D hist("hist","Plot of distribution", 100, -5, 5); // Fill random events according to func: hist.FillRandom("distribution",1000000); hist.Draw(); // Fitting the histogram: func.SetLineColor(kRed); // Setting the fit line color to red func.SetParameters(1., 1.); // Resetting the parameters to something other than real values hist.Fit("distribution","M","",-5,5); }