[root] / trunk / math / mathcore / test / fit / testFit.cxx Repository:
ViewVC logotype

Diff of /trunk/math/mathcore/test/fit/testFit.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25485, Mon Sep 22 07:52:52 2008 UTC revision 25486, Mon Sep 22 12:43:03 2008 UTC
# Line 4  Line 4 
4  #include "TF2.h"  #include "TF2.h"
5  #include "TGraphErrors.h"  #include "TGraphErrors.h"
6  #include "TGraphAsymmErrors.h"  #include "TGraphAsymmErrors.h"
7  #include "TGraph2D.h"  #include "TGraph2DErrors.h"
8  #include "TSystem.h"  #include "TSystem.h"
9  #include "TRandom3.h"  #include "TRandom3.h"
10  #include "TROOT.h"  #include "TROOT.h"
# Line 12  Line 12 
12    
13  #include "Fit/BinData.h"  #include "Fit/BinData.h"
14  #include "Fit/UnBinData.h"  #include "Fit/UnBinData.h"
15  #include "THFitInterface.h"  #include "HFitInterface.h"
 #include "TGraphFitInterface.h"  
16  #include "Fit/Fitter.h"  #include "Fit/Fitter.h"
17    
18  #include "Math/WrappedMultiTF1.h"  #include "Math/WrappedMultiTF1.h"
19  #include "Math/WrappedParamFunction.h"  #include "Math/WrappedParamFunction.h"
20  #include "Math/WrappedTF1.h"  #include "Math/WrappedTF1.h"
21  //#include "Math/Polynomial.h"  //#include "Math/Polynomial.h"
22    #include "RConfigure.h"
23    
24  #include <string>  #include <string>
25  #include <iostream>  #include <iostream>
26    #include <cmath>
27    
28  // print the data  // print the data
29  void printData(const ROOT::Fit::BinData & data) {  void printData(const ROOT::Fit::BinData & data) {
# Line 53  Line 54 
54     std::cout << "\ndata size is " << data.Size() << std::endl;     std::cout << "\ndata size is " << data.Size() << std::endl;
55  }  }
56    
57    int compareResult(double v1, double v2, std::string s = "", double tol = 0.01) {
58       // compare v1 with reference v2
59       // give 1% tolerance
60       if (std::abs(v1-v2) < tol * std::abs(v2) ) return 0;
61       std::cerr << s << " Failed comparison of fit results \t chi2 = " << v1 << "   it should be = " << v2 << std::endl;
62       return -1;
63    }
64    
65    double chi2FromFit(const TF1 * func )  {
66       // return last chi2 obtained from Fit method function
67       assert(TVirtualFitter::GetFitter() != 0 );
68       return (TVirtualFitter::GetFitter()->Chisquare(func->GetNpar(), func->GetParameters() ) );
69    }
70    
71  int testHisto1DFit() {  int testHisto1DFit() {
72    
73    
# Line 63  Line 78 
78     func->SetParameter(2,3.0);     func->SetParameter(2,3.0);
79    
80     TRandom3 rndm;     TRandom3 rndm;
81       int iret = 0;
82       double chi2ref = 0;
83    
84     // fill an histogram     // fill an histogram
85     TH1D * h1 = new TH1D("h1","h1",30,-5.,5.);     TH1D * h1 = new TH1D("h1","h1",30,-5.,5.);
# Line 101  Line 118 
118        std::cout << "Chi2 Fit Failed " << std::endl;        std::cout << "Chi2 Fit Failed " << std::endl;
119        return -1;        return -1;
120     }     }
121       chi2ref = fitter.Result().Chi2();
122    
123     // compare with TH1::Fit     // compare with TH1::Fit
124     TVirtualFitter::SetDefaultFitter("Minuit2");     TVirtualFitter::SetDefaultFitter("Minuit2");
125     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;
126     func->SetParameters(p);     func->SetParameters(p);
127     h1->Fit(func);     h1->Fit(func);
128    
129       iret |= compareResult( chi2FromFit(func), chi2ref,"1D histogram chi2 fit");
130    
131    
132     // test using binned likelihood     // test using binned likelihood
133     std::cout << "\n\nTest Binned Likelihood Fit" << std::endl;     std::cout << "\n\nTest Binned Likelihood Fit" << std::endl;
134    
# Line 118  Line 140 
140        std::cout << "Binned Likelihood Fit Failed " << std::endl;        std::cout << "Binned Likelihood Fit Failed " << std::endl;
141        return -1;        return -1;
142     }     }
143       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D histogram likelihood fit",0.2);
144    
145     // compare with TH1::Fit     // compare with TH1::Fit
146     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;
147     func->SetParameters(p);     func->SetParameters(p);
148     h1->Fit(func,"L");     h1->Fit(func,"L");
149     std::cout << "Equivalent Chi2 from TF1::Fit " << func->GetChisquare() << std::endl;  
150       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TH1::Fit likelihood ",0.001);
151       //std::cout << "Equivalent Chi2 from TF1::Fit " << func->GetChisquare() << std::endl;
152    
153     std::cout << "\n\nTest Chi2 Fit using integral option" << std::endl;     std::cout << "\n\nTest Chi2 Fit using integral option" << std::endl;
154    
# Line 140  Line 166 
166        std::cout << "Integral Chi2 Fit Failed " << std::endl;        std::cout << "Integral Chi2 Fit Failed " << std::endl;
167        return -1;        return -1;
168     }     }
169       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D histogram integral chi2 fit",0.2);
170    
171     // compare with TH1::Fit     // compare with TH1::Fit
172     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;
173     func->SetParameters(p);     func->SetParameters(p);
174     h1->Fit(func,"I");     h1->Fit(func,"I");
175       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TH1::Fit integral ",0.001);
176    
177     f.SetParameters(p);     f.SetParameters(p);
178     ret = fitter.LikelihoodFit(d2, f);     ret = fitter.LikelihoodFit(d2, f);
# Line 153  Line 182 
182        std::cout << "Integral Likelihood Fit Failed " << std::endl;        std::cout << "Integral Likelihood Fit Failed " << std::endl;
183        return -1;        return -1;
184     }     }
185       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D histogram integral likelihood fit",0.2);
186    
187     // compare with TH1::Fit     // compare with TH1::Fit
188     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit Result \n" << std::endl;
189     func->SetParameters(p);     func->SetParameters(p);
190     h1->Fit(func,"IL");     h1->Fit(func,"IL");
191     std::cout << "Equivalent Chi2 from TF1::Fit " << func->GetChisquare() << std::endl;     //std::cout << "Equivalent Chi2 from TF1::Fit " << func->GetChisquare() << std::endl;
192       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TH1::Fit likelihood integral ",0.001);
   
193    
194    
195    
# Line 173  Line 203 
203        std::cout << "Chi2 Fit Failed " << std::endl;        std::cout << "Chi2 Fit Failed " << std::endl;
204        return -1;        return -1;
205     }     }
206       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D histogram chi2 fit (2)",0.001);
207    
208    
209    
# Line 181  Line 211 
211     std::cout << "\n\nTest Same Fit from a TGraphErrors - no coord errors" << std::endl;     std::cout << "\n\nTest Same Fit from a TGraphErrors - no coord errors" << std::endl;
212     TGraphErrors gr(h1);     TGraphErrors gr(h1);
213     ROOT::Fit::BinData dg;     ROOT::Fit::BinData dg;
214       dg.Opt().fCoordErrors = false;  // do not use coordinate errors (default is using )
215     ROOT::Fit::FillData(dg,&gr);     ROOT::Fit::FillData(dg,&gr);
216    
217     f.SetParameters(p);     f.SetParameters(p);
# Line 191  Line 222 
222        std::cout << "Chi2 Graph Errors Fit Failed " << std::endl;        std::cout << "Chi2 Graph Errors Fit Failed " << std::endl;
223        return -1;        return -1;
224     }     }
225       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"TGraphErrors chi2 fit",0.001);
226    
227    
228     // fit using error on X     // fit using error on X
229     std::cout << "\n\nTest Same Fit from a TGraphErrors - use coord errors" << std::endl;     std::cout << "\n\nTest Same Fit from a TGraphErrors - use coord errors" << std::endl;
230     ROOT::Fit::BinData dger;     ROOT::Fit::BinData dger;
231     dger.Opt().fCoordErrors = true;  // use coordinate errors     // not needed since they are used by default
232       //dger.Opt().fCoordErrors = true;  // use coordinate errors
233     ROOT::Fit::FillData(dger,&gr);     ROOT::Fit::FillData(dger,&gr);
234    
235     f.SetParameters(p);     f.SetParameters(p);
# Line 206  Line 240 
240        std::cout << "Chi2 Graph Errors Fit Failed " << std::endl;        std::cout << "Chi2 Graph Errors Fit Failed " << std::endl;
241        return -1;        return -1;
242     }     }
243       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"TGraphErrors effective chi2 fit ",0.7);
244    
245     // compare with TGraphErrors::Fit     // compare with TGraphErrors::Fit
246     std::cout << "\n******************************\n\t TGraphErrors::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TGraphErrors::Fit Result \n" << std::endl;
247     func->SetParameters(p);     func->SetParameters(p);
248     gr.Fit(func);     gr.Fit(func);
249     std::cout << "Ndf of TGraphErrors::Fit  = " << func->GetNDF() << std::endl;     std::cout << "Ndf of TGraphErrors::Fit  = " << func->GetNDF() << std::endl;
250       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TGraphErrors::Fit ",0.001);
251    
252    
253     // test graph fit (errors are 1) do a re-normalization     // test graph fit (errors are 1) do a re-normalization
# Line 229  Line 265 
265        std::cout << "Chi2 Graph Fit Failed " << std::endl;        std::cout << "Chi2 Graph Fit Failed " << std::endl;
266        return -1;        return -1;
267     }     }
268       //iret |= compareResult(fitter.Result().Chi2(), chi2ref,"TGraph fit (no errors) ",0.3);
269    
270    
271     // compare with TGraph::Fit (no errors)     // compare with TGraph::Fit (no errors)
# Line 237  Line 274 
274     gr2.Fit(func);     gr2.Fit(func);
275     std::cout << "Ndf of TGraph::Fit = " << func->GetNDF() << std::endl;     std::cout << "Ndf of TGraph::Fit = " << func->GetNDF() << std::endl;
276    
277       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TGraph::Fit ",0.001);
278    
279     // reddo chi2fit using Fumili  
280     std::cout << "\n\nRedo Chi2 Hist Fit using FUMILI" << std::endl;     // reddo chi2fit using Fumili2
281       std::cout << "\n\nRedo Chi2 Hist Fit using FUMILI2" << std::endl;
282     f.SetParameters(p);     f.SetParameters(p);
283     fitter.Config().SetMinimizer("Minuit2","Fumili");     fitter.Config().SetMinimizer("Minuit2","Fumili");
284     ret = fitter.Fit(d, f);     ret = fitter.Fit(d, f);
# Line 249  Line 288 
288        std::cout << "Chi2 Fit Failed " << std::endl;        std::cout << "Chi2 Fit Failed " << std::endl;
289        return -1;        return -1;
290     }     }
291       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D Histo Fumili2 fit ");
292    
293       // reddo chi2fit using old Fumili
294       std::cout << "\n\nRedo Chi2 Hist Fit using FUMILI" << std::endl;
295       f.SetParameters(p);
296       fitter.Config().SetMinimizer("Fumili");
297       ret = fitter.Fit(d, f);
298       if (ret)
299          fitter.Result().Print(std::cout);
300       else {
301          std::cout << "Chi2 Fit Failed " << std::endl;
302          return -1;
303       }
304       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D Histo Fumili fit ");
305    
306       // test using GSL multi fit (L.M. method)
307       std::cout << "\n\nRedo Chi2 Hist Fit using GSLMultiFit" << std::endl;
308       f.SetParameters(p);
309       fitter.Config().SetMinimizer("GSLMultiFit");
310       ret = fitter.Fit(d, f);
311       if (ret)
312          fitter.Result().Print(std::cout);
313       else {
314          std::cout << "Chi2 Fit Failed " << std::endl;
315          return -1;
316       }
317       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D Histo GSL NLS fit ");
318    
319     return 0;     // test using GSL multi min method
320       std::cout << "\n\nRedo Chi2 Hist Fit using GSLMultiMin" << std::endl;
321       f.SetParameters(p);
322       fitter.Config().SetMinimizer("GSLMultiMin","BFGS2");
323       ret = fitter.Fit(d, f);
324       if (ret)
325          fitter.Result().Print(std::cout);
326       else {
327          std::cout << "Chi2 Fit Failed " << std::endl;
328          return -1;
329       }
330       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"1D Histo GSL Minimizer fit ");
331    
332       return iret;
333  }  }
334    
335    
# Line 295  Line 373 
373     }     }
374    
375  private:  private:
376    
377     double DoEvalPar( const double *x, const double * p) const {     double DoEvalPar( const double *x, const double * p) const {
378        return p[0]*x[0]*x[0] + p[1]*x[0] + p[2]*x[1]*x[1] + p[3]*x[1] + p[4];        return p[0]*x[0]*x[0] + p[1]*x[0] + p[2]*x[1]*x[1] + p[3]*x[1] + p[4];
379     }     }
380     double DoDerivative(const double *x,  unsigned int icoord = 0) const {  //    double DoDerivative(const double *x,  unsigned int icoord = 0) const {
381        assert(icoord <= 1);  //       assert(icoord <= 1);
382        if (icoord == 0)  //       if (icoord == 0)
383           return 2. * fp[0] * x[0] + fp[1];  //          return 2. * fp[0] * x[0] + fp[1];
384        else  //       else
385           return 2. * fp[2] * x[1] + fp[3];  //          return 2. * fp[2] * x[1] + fp[3];
386     }  //    }
387    
388     double DoParameterDerivative(const double * x, const double * p, unsigned int ipar) const {     double DoParameterDerivative(const double * x, const double * p, unsigned int ipar) const {
389        std::vector<double> grad(NPar());        std::vector<double> grad(NPar());
390        ParameterGradient(x, p, &grad[0] );        ParameterGradient(x, p, &grad[0] );
# Line 326  Line 406 
406     func->SetParameter(2,3.0);     func->SetParameter(2,3.0);
407    
408     TRandom3 rndm;     TRandom3 rndm;
409       int iret = 0;
410       double chi2ref = 0;
411    
412     // fill an histogram     // fill an histogram
413     TH1D * h2 = new TH1D("h2","h2",30,-5.,5.);     TH1D * h2 = new TH1D("h2","h2",30,-5.,5.);
# Line 359  Line 441 
441        std::cout << " Fit Failed " << std::endl;        std::cout << " Fit Failed " << std::endl;
442        return -1;        return -1;
443     }     }
444       chi2ref = fitter.Result().Chi2();
445    
446     // compare with TH1::Fit     // compare with TH1::Fit
447     std::cout << "\n******************************\n\t TH1::Fit(pol2) Result with TMinuit \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit(pol2) Result with TMinuit \n" << std::endl;
448     func->SetParameters(p);     func->SetParameters(p);
449     h2->Fit(func,"F");     h2->Fit(func,"F");
450       iret |= compareResult(func->GetChisquare(),chi2ref,"TH1::Fit ",0.001);
451    
452    
453     std::cout << "\n\nTest histo polynomial linear fit " << std::endl;     std::cout << "\n\nTest histo polynomial linear fit " << std::endl;
454    
# Line 381  Line 466 
466        std::cout << " Fit Failed " << std::endl;        std::cout << " Fit Failed " << std::endl;
467        return -1;        return -1;
468     }     }
469       iret |= compareResult(fitter.Result().Chi2(),chi2ref,"1D histo linear Fit ");
470    
471     // compare with TH1::Fit     // compare with TH1::Fit
472     std::cout << "\n******************************\n\t TH1::Fit(pol2) Result with TLinearFitter \n" << std::endl;     std::cout << "\n******************************\n\t TH1::Fit(pol2) Result with TLinearFitter \n" << std::endl;
473     func->SetParameters(p);     func->SetParameters(p);
474     h2->Fit(func);     h2->Fit(func);
475       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TH1::Fit linear",0.001);
476    
477    
478    
479     return 0;     return iret;
480  }  }
481    
482  int testHisto2DFit() {  int testHisto2DFit() {
# Line 404  Line 491 
491     assert(func->GetNpar() == 5);     assert(func->GetNpar() == 5);
492    
493     TRandom3 rndm;     TRandom3 rndm;
494       double chi2ref = 0;
495       int iret = 0;
496    
497     // fill an histogram     // fill an histogram
498     TH2D * h2 = new TH2D("h2d","h2d",30,-5.,5.,30,-5.,5.);     TH2D * h2 = new TH2D("h2d","h2d",30,-5.,5.,30,-5.,5.);
499  //      h1->FillRandom(fname.c_str(),100);  //      h1->FillRandom(fname.c_str(),100);
500     for (int i = 0; i <1000; ++i) {     for (int i = 0; i <10000; ++i) {
501        double x,y = 0;        double x,y = 0;
502        func->GetRandom2(x,y);        func->GetRandom2(x,y);
503        h2->Fill(x,y);        h2->Fill(x,y);
# Line 428  Line 517 
517    
518    
519     // create the fitter     // create the fitter
   
520     ROOT::Fit::Fitter fitter;     ROOT::Fit::Fitter fitter;
521       //fitter.Config().MinimizerOptions().SetPrintLevel(3);
522    
523       std::cout <<"\ntest 2D histo fit using gradient" << std::endl;
524     bool ret = fitter.Fit(d, f);     bool ret = fitter.Fit(d, f);
525     if (ret)     if (ret)
526        fitter.Result().Print(std::cout);        fitter.Result().Print(std::cout);
# Line 437  Line 528 
528        std::cout << "Gradient Fit Failed " << std::endl;        std::cout << "Gradient Fit Failed " << std::endl;
529        return -1;        return -1;
530     }     }
531       chi2ref = fitter.Result().Chi2();
532    
533     // test without gradient     // test without gradient
534     std::cout <<"\ntest result without using gradient" << std::endl;     std::cout <<"\ntest result without using gradient" << std::endl;
# Line 448  Line 540 
540        std::cout << " Chi2 Fit Failed " << std::endl;        std::cout << " Chi2 Fit Failed " << std::endl;
541        return -1;        return -1;
542     }     }
543       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"2D histogram chi2 fit");
544    
545     // test binned likelihood gradient     // test binned likelihood gradient
546     std::cout <<"\ntest result using gradient and binned likelihood" << std::endl;     std::cout <<"\ntest result using gradient and binned likelihood" << std::endl;
# Line 471  Line 564 
564        std::cout << "Linear 2D Fit Failed " << std::endl;        std::cout << "Linear 2D Fit Failed " << std::endl;
565        return -1;        return -1;
566     }     }
567       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"2D histogram linear fit");
568    
569     // test fitting using TGraph2D     // test fitting using TGraph2D ( chi2 will be larger since errors are 1)
570       // should test with a TGraph2DErrors
571     TGraph2D g2(h2);     TGraph2D g2(h2);
572    
573     std::cout <<"\ntest using TGraph2D" << std::endl;     std::cout <<"\ntest using TGraph2D" << std::endl;
# Line 490  Line 585 
585        std::cout << " TGraph2D Fit Failed " << std::endl;        std::cout << " TGraph2D Fit Failed " << std::endl;
586        return -1;        return -1;
587     }     }
588       double chi2ref2 = fitter.Result().Chi2();
589    
590     // compare with TGraph2D::Fit     // compare with TGraph2D::Fit
591     std::cout << "\n******************************\n\t TGraph::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TGraph::Fit Result \n" << std::endl;
592     func->SetParameters(p);     func->SetParameters(p);
# Line 504  Line 601 
601        std::cout << " TGraph2D Grad Fit Failed " << std::endl;        std::cout << " TGraph2D Grad Fit Failed " << std::endl;
602        return -1;        return -1;
603     }     }
604       iret |= compareResult(fitter.Result().Chi2(), chi2ref2,"TGraph2D chi2 fit");
605    
606       std::cout <<"\ntest using TGraph2DErrors -  error only in Z" << std::endl;
607       TGraph2DErrors g2err(g2.GetN() );
608       // need to set error by hand since constructor from TH2 does not exist
609       for (int i = 0; i < g2.GetN(); ++i) {
610          double x = g2.GetX()[i];
611          double y = g2.GetY()[i];
612          g2err.SetPoint(i,x,y,g2.GetZ()[i]);
613          g2err.SetPointError(i,0,0,h2->GetBinError(h2->FindBin(x,y) ) );
614       }
615       func->SetParameters(p);
616       // g2err.Fit(func);
617       f.SetParameters(p);
618       ROOT::Fit::BinData d3;
619       ROOT::Fit::FillData(d3,&g2err,func);
620       ret = fitter.Fit(d3, f);
621       if (ret)
622          fitter.Result().Print(std::cout);
623       else {
624          std::cout << " TGraph2DErrors Fit Failed " << std::endl;
625          return -1;
626       }
627    
628       iret |= compareResult(fitter.Result().Chi2(), chi2ref,"TGraph2DErrors chi2 fit");
629    
630    
631     return 0;  
632       std::cout <<"\ntest using TGraph2DErrors -  with error  in X,Y,Z" << std::endl;
633       for (int i = 0; i < g2err.GetN(); ++i) {
634          double x = g2.GetX()[i];
635          double y = g2.GetY()[i];
636          g2err.SetPointError(i,0.5* h2->GetXaxis()->GetBinWidth(1),0.5*h2->GetXaxis()->GetBinWidth(1),h2->GetBinError(h2->FindBin(x,y) ) );
637       }
638       std::cout << "\n******************************\n\t TGraph2DErrors::Fit Result \n" << std::endl;
639       func->SetParameters(p);
640       g2err.Fit(func);
641    
642    
643       return iret;
644  }  }
645    
646    
# Line 560  Line 693 
693        std::cout << "Unbinned Likelihood Fit Failed " << std::endl;        std::cout << "Unbinned Likelihood Fit Failed " << std::endl;
694        iret |= 1;        iret |= 1;
695     }     }
696       double lref = fitter.Result().MinFcnValue();
697    
698     std::cout << "\n\nRedo Fit using FUMILI" << std::endl;     std::cout << "\n\nRedo Fit using FUMILI2" << std::endl;
699     f.SetParameters(p);     f.SetParameters(p);
700     fitter.Config().SetMinimizer("Fumili2");     fitter.Config().SetMinimizer("Fumili2");
701     // need to set function first (need to change this)     // need to set function first (need to change this)
# Line 574  Line 708 
708     if (ret)     if (ret)
709        fitter.Result().Print(std::cout);        fitter.Result().Print(std::cout);
710     else {     else {
711          std::cout << "Unbinned Likelihood Fit using FUMILI2 Failed " << std::endl;
712          iret |= 1;
713       }
714    
715       iret |= compareResult(fitter.Result().MinFcnValue(), lref,"1D unbin FUMILI2 fit");
716    
717       std::cout << "\n\nRedo Fit using FUMILI" << std::endl;
718       f.SetParameters(p);
719       fitter.Config().SetMinimizer("Fumili");
720       // fitter.Config().MinimizerOptions().SetPrintLevel(3);
721       // need to set function first (need to change this)
722       fitter.SetFunction(f);
723       fitter.Config().ParSettings(0).Fix(); //need to re-do it
724       // set range in sigma sigma > 0
725       fitter.Config().ParSettings(2).SetLowerLimit(0);
726    
727       ret = fitter.Fit(d);
728       if (ret)
729          fitter.Result().Print(std::cout);
730       else {
731        std::cout << "Unbinned Likelihood Fit using FUMILI Failed " << std::endl;        std::cout << "Unbinned Likelihood Fit using FUMILI Failed " << std::endl;
732        iret |= 1;        iret |= 1;
733     }     }
734    
735       iret |= compareResult(fitter.Result().MinFcnValue(), lref,"1D unbin FUMILI fit");
736    
737    
738     return iret;     return iret;
739  }  }
# Line 627  Line 783 
783        std::cout << "Chi2 Graph Fit Failed " << std::endl;        std::cout << "Chi2 Graph Fit Failed " << std::endl;
784        return -1;        return -1;
785     }     }
786       double chi2ref = fitter.Result().Chi2();
787    
788    
789     // compare with TGraph::Fit     // compare with TGraph::Fit
790     std::cout << "\n******************************\n\t TGraph::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TGraph::Fit Result \n" << std::endl;
791     func->SetParameters(p);     func->SetParameters(p);
792     gr.Fit(func,"F"); // use Minuit     gr.Fit(func,"F"); // use Minuit
793    
794       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TGraph::Fit ",0.001);
795    
796    
797     std::cout <<"\ntest TGraphErrors  " << std::endl;     std::cout <<"\ntest TGraphErrors  " << std::endl;
798     TGraphErrors grer(5, x,y,ex,ey);     TGraphErrors grer(5, x,y,ex,ey);
# Line 652  Line 812 
812        return -1;        return -1;
813     }     }
814    
815       iret |= compareResult(fitter.Result().Chi2(),chi2ref,"TGraphErrors fit with coord errors",0.8);
816    
817    
818     // compare with TGraph::Fit     // compare with TGraph::Fit
819     std::cout << "\n******************************\n\t TGraphErrors::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TGraphErrors::Fit Result \n" << std::endl;
820     func->SetParameters(p);     func->SetParameters(p);
821     grer.Fit(func,"F"); // use Minuit     grer.Fit(func,"F"); // use Minuit
822       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TGraphErrors::Fit ",0.001);
823    
824       chi2ref = fitter.Result().Chi2();
825    
826     std::cout <<"\ntest TGraphAsymmErrors  " << std::endl;     std::cout <<"\ntest TGraphAsymmErrors  " << std::endl;
827     TGraphAsymmErrors graer(5, x,y,ex,ex,eyl, eyh);     TGraphAsymmErrors graer(5, x,y,ex,ex,eyl, eyh);
# Line 675  Line 841 
841        std::cout << "Chi2 Graph Fit Failed " << std::endl;        std::cout << "Chi2 Graph Fit Failed " << std::endl;
842        return -1;        return -1;
843     }     }
844       //iret |= compareResult(fitter.Result().Chi2(),chi2ref,"TGraphAsymmErrors fit ",0.5);
845    
846     // compare with TGraph::Fit     // compare with TGraph::Fit
847     std::cout << "\n******************************\n\t TGraphAsymmErrors::Fit Result \n" << std::endl;     std::cout << "\n******************************\n\t TGraphAsymmErrors::Fit Result \n" << std::endl;
848     func->SetParameters(p);     func->SetParameters(p);
849     graer.Fit(func,"F"); // use Minuit     graer.Fit(func,"F"); // use Minuit
850       iret |= compareResult(func->GetChisquare(),fitter.Result().Chi2(),"TGraphAsymmErrors::Fit ",0.001);
851    
852    
853    
# Line 707  Line 875 
875     iret |= testFit( testHisto2DFit, "Histogram2D Gradient Fit");     iret |= testFit( testHisto2DFit, "Histogram2D Gradient Fit");
876     iret |= testFit( testUnBin1DFit, "Unbin 1D Fit");     iret |= testFit( testUnBin1DFit, "Unbin 1D Fit");
877     iret |= testFit( testGraphFit, "Graph 1D Fit");     iret |= testFit( testGraphFit, "Graph 1D Fit");
878    
879       std::cout << "\n******************************\n";
880       if (iret) std::cerr << "\n\t testFit FAILED !!!!!!!!!!!!!!!! \n";
881       else std::cout << "\n\t testFit all OK \n";
882     return iret;     return iret;
883  }  }
884    

Legend:
Removed from v.25485  
changed lines
  Added in v.25486

Subversion Admin
ViewVC Help
Powered by ViewVC 1.0.9