minuit2GausFit.C

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: minuit2GausFit.C 20881 2007-11-19 11:23:56Z 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 "TH1.h"
00012 #include "TF1.h"
00013 #include "TCanvas.h"
00014 #include "TRandom3.h"
00015 #include "TVirtualFitter.h"
00016 #include "TPaveLabel.h"
00017 #include "TStyle.h"
00018 
00019 #include <iostream>
00020 #include <string>
00021 
00022 
00023 void testGausFit( std::string type = "Minuit2", int n = 1000) { 
00024 
00025   gRandom = new TRandom3();
00026 
00027   TVirtualFitter::SetDefaultFitter(type.c_str() );
00028 
00029   std::string name; 
00030   name = "h1_" + type; 
00031   TH1D * h1 = new TH1D(name.c_str(),"Chi2 Fit",100, -5, 5. );
00032   name = "h2_" + type; 
00033   TH1D * h2 = new TH1D(name.c_str(),"Chi2 Fit with Minos Error",100, -5, 5. );
00034   name = "h3_" + type; 
00035   TH1D * h3 = new TH1D(name.c_str(),"Chi2 Fit with Integral and Minos",100, -5, 5. );
00036   name = "h4_" + type; 
00037   TH1D * h4 = new TH1D(name.c_str(),"Likelihood Fit with Minos Error",100, -5, 5. );
00038 
00039   gStyle->SetOptStat(1111111);
00040   gStyle->SetOptFit(1111111);    
00041 
00042   for (int i = 0; i < n; ++i) { 
00043      double x = gRandom->Gaus(0,1); 
00044      h1->Fill( x ); 
00045      h2->Fill( x ); 
00046      h3->Fill( x ); 
00047      h4->Fill( x ); 
00048   }
00049   
00050   std::string cname = type + "Canvas" ;    
00051   std::string ctitle = type + " Gaussian Fit" ;    
00052   TCanvas *c1 = new TCanvas(cname.c_str(),cname.c_str(),10,10,900,900);
00053   c1->Divide(2,2);
00054   
00055   c1->cd(1);
00056   cout << "\nDo Fit 1\n";
00057   h1->Fit("gaus","Q"); 
00058   h1->Draw();
00059   c1->cd(2);
00060   cout << "\nDo Fit 2\n";
00061   h2->Fit("gaus","VE"); 
00062   h2->Draw();
00063   c1->cd(3);
00064   cout << "\nDo Fit 3\n";
00065   h3->Fit("gaus","IE"); 
00066   h3->Draw();
00067   c1->cd(4);
00068   cout << "\nDo Fit 4\n";
00069   h4->Fit("gaus","VLE"); 
00070   h4->Draw();
00071 
00072 }
00073 
00074 void minuit2GausFit() { 
00075 
00076   int n = 1000; 
00077   testGausFit("Minuit2",n);
00078   testGausFit("Fumili2",n);
00079 
00080 }
00081 
00082 
00083 

Generated on Tue Jul 5 15:44:08 2011 for ROOT_528-00b_version by  doxygen 1.5.1