fitMultiGraph.C: fitting a parabola to a multigraph of 3 partly overlapping graphs | Fitting tutorials | fithist.C: example of fit where the model is histogram + function |
void fitcont() { // Example illustrating how to draw the n-sigma contour of a Minuit fit. // To get the n-sigma contour the ERRDEF parameter in Minuit has to set // to n^2. The fcn function has to be set before the routine is called. // // WARNING!!! This test works only with TMinuit // // The TGraph object is created via the interpreter. The user must cast it // to a TGraph* // Author: Rene Brun //be sure default is Minuit since we will use gMinuit TVirtualFitter::SetDefaultFitter("Minuit"); TCanvas *c1 = new TCanvas("c1"); TH1F *h = new TH1F("h","My histogram",100,-3,3); h->FillRandom("gaus",6000); h->Fit("gaus"); c1->Update(); TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800); c2->Divide(1,2); c2->cd(1); //get first contour for parameter 1 versus parameter 2 TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2); gr12->Draw("alp"); c2->cd(2); //Get contour for parameter 0 versus parameter 2 for ERRDEF=2 gMinuit->SetErrorDef(4); //note 4 and not 2! TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2); gr2->SetFillColor(42); gr2->Draw("alf"); //Get contour for parameter 0 versus parameter 2 for ERRDEF=1 gMinuit->SetErrorDef(1); TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2); gr1->SetFillColor(38); gr1->Draw("lf"); } fitcont.C:1 fitcont.C:2 fitcont.C:3 fitcont.C:4 fitcont.C:5 fitcont.C:6 fitcont.C:7 fitcont.C:8 fitcont.C:9 fitcont.C:10 fitcont.C:11 fitcont.C:12 fitcont.C:13 fitcont.C:14 fitcont.C:15 fitcont.C:16 fitcont.C:17 fitcont.C:18 fitcont.C:19 fitcont.C:20 fitcont.C:21 fitcont.C:22 fitcont.C:23 fitcont.C:24 fitcont.C:25 fitcont.C:26 fitcont.C:27 fitcont.C:28 fitcont.C:29 fitcont.C:30 fitcont.C:31 fitcont.C:32 fitcont.C:33 fitcont.C:34 fitcont.C:35 fitcont.C:36 fitcont.C:37 fitcont.C:38 fitcont.C:39 fitcont.C:40 |
|