{ gROOT->Reset(); // -- Open the File TFile f("Exercise3.root"); // -- Remove stats and fit box gStyle->SetOptStat(0); gStyle->SetOptFit(0); // -- Set the axis range h1->SetAxisRange(.5, 1.5); // -- Set the marker style and type h1->SetMarkerStyle(20); h1->SetMarkerSize(1.); // -- Axis labels and offsets for "x" and "y" h1->SetTitleSize(0.06, "x"); h1->SetTitleOffset(1., "x"); h1->SetXTitle("E/p"); h1->SetTitleSize(0.06, "y"); h1->SetTitleOffset(1., "y"); h1->SetYTitle("Entries/bin"); // -- Get a default canvas h1->Draw(); // -- Make sure there is enough space around the plot gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); // -- Define the function TF1 *f1 = new TF1("f1", "gaus + gaus(3)", 0.6, 1.4); f1->SetParameters(h1->GetMaximum(), 1., 0.05, h1->GetMaximum()/10., 1.0, 0.2); // -- Fit the histogram and display it with errors (very small) and markers h1->Fit("f1", "", "PE"); // -- Create a Pave to contain some fit parameters in a legible font TPaveText *pt = new TPaveText(0.2, 0.7, 0.4, 0.85, "NDC"); pt->SetTextSize(0.04); pt->SetFillColor(0); pt->SetTextAlign(12); TText *pte; Double_t meanV, meanE; char display[50]; // -- Extract the fit parameters from minuit gMinuit->GetParameter(1, meanV, meanE); sprintf(display, "mean = %6.3f", meanV); pte = pt->AddText(display); gMinuit->GetParameter(2, meanV, meanE); sprintf(display, "sigma = %6.3f", meanV); pte = pt->AddText(display); // -- Don't forget to draw the pave pt->Draw(); // -- Save it to a file c1->SaveAs("plot.eps"); }