testUserFunc.cxx

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: testUserFunc.cxx 20880 2007-11-19 11:23:41Z rdm $
00002 // Author: L. Moneta    10/2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 ROOT Foundation,  CERN/PH-SFT                   *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 
00011 #include "TApplication.h"
00012 #include "TH1.h"
00013 #include "TF1.h"
00014 #include "TRandom3.h"
00015 #include "TVirtualFitter.h"
00016 #include "TMath.h"
00017 
00018 #include <iostream>
00019 
00020 double myfunc( double * x, double * p) { 
00021 
00022   return p[0]*TMath::Gaus(x[0],p[1],p[2]);
00023 }
00024 
00025 void testUserFunc(std::string type="Minuit2", int n = 1000) { 
00026 
00027 
00028 
00029   gRandom = new TRandom3();
00030 
00031 
00032   TVirtualFitter::SetDefaultFitter(type.c_str() );
00033 
00034   
00035 
00036   TH1D * h1 = new TH1D("h1","fit histo 1",100, -5, 5. );
00037 
00038 //   gStyle->SetOptStat(1111111);
00039 //   gStyle->SetOptFit(1111111);
00040 
00041  
00042     
00043 
00044   for (int i = 0; i < n; ++i) { 
00045     h1->Fill( gRandom->Gaus(0,1) ); 
00046   }
00047  
00048   TF1 * f = new TF1("f",myfunc,-10,10,3);
00049   double p[3] = { 100.0, 0.0, 1.0 } ;
00050   f->SetParameters(p);
00051   
00052   h1->Fit(f); 
00053   // try fix a parameter 
00054   //TVirtualFitter * fitter = TVirtualFitter::GetFitter(); 
00055   //std::cout << typeid(*fitter).name() << std::endl; 
00056   //fitter->FixParameter(2); 
00057   f->FixParameter(2,1.0); 
00058 
00059   h1->Fit(f,"V");
00060 
00061   h1->Draw();
00062  
00063 
00064 
00065 }
00066 
00067 #ifndef __CINT__
00068 int main(int argc, char **argv)
00069 {
00070    if (argc > 1) {  
00071       TApplication theApp("App", &argc, argv);
00072       testUserFunc( );
00073       theApp.Run();
00074    }
00075    else 
00076       testUserFunc( );
00077    return 0;
00078 }
00079 #endif
00080 
00081 //#ifndef __CINT__
00082 //int main() { 
00083 //  testUserFunc( );
00084 //}
00085 //#endif

Generated on Tue Jul 5 14:37:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1