00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __CINT__
00015
00016 #include "TH1.h"
00017 #include "TH2.h"
00018 #include "TFile.h"
00019 #include "TCanvas.h"
00020 #include "TCutG.h"
00021 #include "TApplication.h"
00022
00023 #include "TGo4FitMinuit.h"
00024 #include "TGo4Fitter.h"
00025 #include "TGo4FitDataHistogram.h"
00026 #include "TGo4FitModelPolynom.h"
00027 #include "TGo4FitModelGauss2.h"
00028 #include "TGo4FitModelGaussN.h"
00029
00030 void Example8();
00031
00032 int main(int argc, char **argv)
00033 {
00034 TApplication theApp("Application", 0, 0);
00035
00036 Example8();
00037
00038 theApp.Run();
00039
00040 return 0;
00041 }
00042
00043 #endif
00044
00045 void DrawHistogram(TH1* histo, const char* CanvasName, const char* DrawOption)
00046 {
00047 TCanvas *fCanvas = new TCanvas(CanvasName,"Draw of histogram",3);
00048 fCanvas->cd();
00049 histo->Draw(DrawOption);
00050 fCanvas->Update();
00051 }
00052
00053 void AddRangeCut(TGo4FitComponent* comp)
00054 {
00055 Double_t x[] = { 2,3,8,7,2 };
00056 Double_t y[] = { 8,3,2,7,8 };
00057 TCutG* cut = new TCutG("cut1",5,x,y);
00058 comp->AddRangeCut(cut);
00059 }
00060
00061 void Example8()
00062 {
00063
00064 TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
00065
00066
00067 TH2D *histo = new TH2D("histo","dummy histogram",100,0.,10.,100,0.,10.);
00068 fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
00069
00070
00071 TGo4FitModel* model = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss",5.,5.,1.,1.,-0.5) );
00072 model->SetAmplValue(1000.);
00073
00074 AddRangeCut(model);
00075
00076
00077 TH1* res = (TH1*) fitter->CreateDrawObject("GaussModel","data",kTRUE);
00078 delete fitter;
00079
00080
00081
00082 DrawHistogram(res,"Canvas1","SURF1");
00083
00084
00085 fitter = new TGo4Fitter("Fitter2",TGo4Fitter::ff_ML_Poisson,kFALSE);
00086
00087
00088 TGo4FitData* data = fitter->AddData(new TGo4FitDataHistogram("data",res));
00089
00090 AddRangeCut(data);
00091
00092
00093 model = fitter->AddModel( "data", new TGo4FitModelGaussN("Gauss",2) );
00094 model->SetPosition(0,4.5);
00095 model->SetPosition(1,4.5);
00096 model->SetWidth(0,1.7);
00097 model->SetWidth(1,1.7);
00098 model->SetAmplValue(500.);
00099
00100 fitter->AddSimpleMinuit();
00101
00102 fitter->SetMemoryUsage(1);
00103
00104 fitter->DoActions();
00105
00106 fitter->Print("Pars");
00107
00108 delete fitter;
00109 }