Double_t CauchyDens(Double_t *x, Double_t *par) { Double_t pi = TMath::Pi(); Double_t mean = par[0]; Double_t fwhm = par[1]; Double_t arg = x[0]-mean; Double_t top = 0.5*fwhm; Double_t bot = pi*(arg*arg+top*top); Double_t func = top/bot; return func; } Double_t CauchyPeak(Double_t *x, Double_t *par) { Double_t height = par[2]; Double_t func = height*CauchyDens(x,par); return func; } void doit() { TCanvas *c1 = new TCanvas("c1","the fit canvas",500,400); // Creates a Root function based on function CauchDens above TF1 *func = new TF1("cauchy",CauchyDens,-10,10,2); // Sets initial values and parameter names Double_t par[2]; par[0] = 1.0; par[1] = 2.0; func->SetParameters(par); func->SetParNames("Mean","FWHM"); // Increase the number of points for calculating the integral of the density func->SetNpx(1000); // Create a histogram filled between its boundaries with a // Cauchy distribution TH1D *hCauchy = new TH1D("h","test",100,-5.,5.); hCauchy->Sumw2(); Int_t nrPoints = 1000; hCauchy->FillRandom("cauchy",nrPoints); hCauchy->Draw(); // Extract the Cauchy density parameters from the fit TF1 *fitfunc = new TF1("fitfunc",CauchyPeak,-10,10,3); Double_t fitpar[3]; fitpar[0] = par[0]; fitpar[1] = par[1]; fitpar[2] = Double_t(nrPoints); fitfunc->SetParameters(fitpar); hCauchy->Fit(fitfunc); }