/// \file /// \ingroup tutorial_fit /// \notebook -js /// fitting a parabola to a multigraph of 3 partly overlapping graphs /// with different errors /// /// \macro_image /// \macro_output /// \macro_code /// /// \author Anna Kreshuk #include "TMultiGraph.h" #include "TRandom.h" #include "TF1.h" #include "TGraphErrors.h" #include "TCanvas.h" #include "TMath.h" void fitMultiGraph() { Int_t n = 30; Double_t *xvalues1 = new Double_t[n]; Double_t *xvalues2 = new Double_t[n]; Double_t *xvalues3 = new Double_t[n]; Double_t *yvalues1 = new Double_t[n]; Double_t *yvalues2 = new Double_t[n]; Double_t *yvalues3 = new Double_t[n]; Double_t *evalues1 = new Double_t[n]; Double_t *evalues2 = new Double_t[n]; Double_t *evalues3 = new Double_t[n]; //generate the data for the graphs TRandom r; Int_t i; for (i=0; iSetLineColor(kRed); gr2->SetLineColor(kBlue); gr2->SetMarkerStyle(24); gr2->SetMarkerSize(0.3); gr3->SetLineColor(kGreen); gr3->SetMarkerStyle(24); gr3->SetMarkerSize(0.3); //add the graphs to the multigraph TMultiGraph *mg=new TMultiGraph("mg", "TMultiGraph of 3 TGraphErrors"); mg->Add(gr1); mg->Add(gr2); mg->Add(gr3); TCanvas *myc = new TCanvas("myc", "Fitting a MultiGraph of 3 TGraphErrors"); myc->SetGrid(); mg->Draw("ap"); //fit mg->Fit("pol2", "F"); //access to the fit function TF1 *fpol = mg->GetFunction("pol2"); fpol->SetLineWidth(1); } void fitminuit() { Int_t n = 30; Double_t *xvalues1 = new Double_t[n]; Double_t *xvalues2 = new Double_t[n]; Double_t *xvalues3 = new Double_t[n]; Double_t *yvalues1 = new Double_t[n]; Double_t *yvalues2 = new Double_t[n]; Double_t *yvalues3 = new Double_t[n]; Double_t *evalues1 = new Double_t[n]; Double_t *evalues2 = new Double_t[n]; Double_t *evalues3 = new Double_t[n]; Double_t *xtotal = new Double_t[n*3]; Double_t *ytotal = new Double_t[n*3]; Double_t *etotal = new Double_t[n*3]; TRandom r; Int_t i; for (i=0; iAdd(gr1); mg->Add(gr2); mg->Add(gr3); //mg->Draw("ap"); //TF1 *ffit = new TF1("ffit", "TMath::Gaus(x, [0], [1], [2])", -3, 3); //ffit->SetParameters(0, 1, 0); //mg->Fit(ffit); grtotal->Fit("gaus"); mg->Fit("gaus"); }