#include "fct1dfit.h" // ... // Read from ppf file NTuple nt; { PInPersist pis("myfile.ppf"); string tag = "NT"; pis.GetObject(nt,tag); } // Fill GeneralData GeneralData mGdata(nt.NEntry()); for(int i=0; i<nt.NEntry(); i++) mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y mGData.PrintStatus(); // Function for fitting : y = f(x) + noise Gauss1DPol mFunction; // gaussian + constant // Prepare for fit GeneralFit mFit(&mFunction); // create a fitter for the choosen function mFit.SetData(&mGData); // connect data to the fitter // Set and initialise the parameters (that's non-linear fitting!) // (num par, name, guess start, step, [limits min and max]) mFit.SetParam(0,"high",90.,1..); mFit.SetParam(1,"xcenter",0.05,0.01); mFit.SetParam(2,"sigma",sig,0.05,0.01,10.); // Give limits to avoid division by zero mFit.SetParam(3,"constant",0.,1.); // Fit and print result int rcfit = mFit.Fit(); mFit.PrintFit(); if(rcfit>0) {) cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red() <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl; } else { cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl; mFit.PrintFitErr(rcfit); } // Get the result for further use TVector<r_8> ParResult = mFit.GetParm(); cout<<ParResult;
Much more usefull possibilities and detailed informations might be found in the HTML pages of the Sophya manual.