/// \file /// \ingroup tutorial_fit /// \notebook /// Generate points distributed with some errors around a circle /// Fit a circle through the points and draw /// To run the script, do, eg /// /// ~~~{.cpp} /// root > .x fitCircle.C (10000 points by default) /// root > .x fitCircle.C(100); (with only 100 points /// root > .x fitCircle.C++(100000); with ACLIC /// ~~~ /// /// \macro_image /// \macro_output /// \macro_code /// /// \author Rene Brun #include "TCanvas.h" #include "TRandom3.h" #include "TGraph.h" #include "TMath.h" #include "TArc.h" #include "Fit/Fitter.h" #include //____________________________________________________________________ void fitCircle(Int_t n=10000) { //generates n points around a circle and fit them TCanvas *c1 = new TCanvas("c1","c1",600,600); c1->SetGrid(); TGraph* gr = new TGraph(n); if (n> 999) gr->SetMarkerStyle(1); else gr->SetMarkerStyle(3); TRandom3 r; Double_t x,y; for (Int_t i=0;iSetPoint(i,x,y); } c1->DrawFrame(-5,-5,5,5); gr->Draw("p"); auto chi2Function = [&](const Double_t *par) { //minimisation function computing the sum of squares of residuals // looping at the graph points Int_t np = gr->GetN(); Double_t f = 0; Double_t *x = gr->GetX(); Double_t *y = gr->GetY(); for (Int_t i=0;iSetLineColor(kRed); arc->SetLineWidth(4); arc->SetFillStyle(0); arc->Draw(); }