00001
00002
00003
00004
00005
00006
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
00039
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
00054
00055
00056
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
00082
00083
00084
00085