Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4FitExample/Example9.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #ifndef __CINT__
00017 
00018 #include <iostream.h>
00019 
00020 #include "TH1.h"
00021 #include "TH2.h"
00022 #include "TFile.h"
00023 #include "TCanvas.h"
00024 #include "TApplication.h"
00025 
00026 #include "../Go4Fit/TGo4FitMinuit.h"
00027 #include "../Go4Fit/TGo4Fitter.h"
00028 #include "../Go4Fit/TGo4FitDataHistogram.h"
00029 #include "../Go4Fit/TGo4FitModelPolynom.h"
00030 #include "../Go4Fit/TGo4FitModelGauss2.h"
00031 #include "../Go4Fit/TGo4FitModelGaussN.h"
00032 
00033 
00034 void Example9();
00035 
00036 int main(int argc, char **argv)
00037 {
00038    TApplication theApp("Application", 0, 0);
00039 
00040    Example9();
00041 
00042    theApp.Run();
00043 
00044    return 0;
00045 }
00046 
00047 #endif
00048 
00049 void DrawHistogram(TH1* histo, const char* CanvasName, const char* DrawOption) {
00050    TCanvas *fCanvas = new TCanvas(CanvasName,"Draw of histogram",3);
00051    fCanvas->cd();
00052    histo->Draw(DrawOption);
00053    fCanvas->Update();
00054 }
00055 
00056 void Example9() {
00057    // create fitter
00058    TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
00059 
00060    // create dummy histogram and set with owneship flag
00061    TH2D *histo = new TH2D("histo","dummy histogram",1000,0.,10.,1000,0.,10.);
00062    TGo4FitData* data = fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
00063    data->SetRange(0,1.,3.); data->SetRange(0,7.,9.);
00064    data->SetRange(1,1.,3.); data->SetRange(1,7.,9.);
00065 
00066     // create models component and assign them to fitter
00067    TGo4FitModel* model1 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss1",2.,8.,.5,.5,0.) );
00068    model1->SetAmplValue(1000.);
00069 
00070    TGo4FitModel* model2 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss2",8.,8.,.5,.5,0.) );
00071    model2->SetAmplValue(1000.);
00072 
00073    TGo4FitModel* model3 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss3",8.,2.,.5,.5,0.) );
00074    model3->SetAmplValue(1000.);
00075 
00076    TGo4FitModel* model4 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss4",2.,2.,.5,.5,0.) );
00077    model4->SetAmplValue(1000.);
00078 
00079 
00080    // create result model without optimization, using initial parameters values
00081    TH1* res1 = (TH1*) fitter->CreateDrawObject("Large", "data", kTRUE);
00082 
00083    histo = new TH2D("histo2","dummy histogram",10,0.,10.,10,0.,10.);
00084    fitter->SetObject("data", histo, kTRUE);
00085 
00086    TH1* res2 = (TH1*) fitter->CreateDrawObject("Small", "data", kTRUE);
00087 
00088    model1->SetIntegrationsProperty(5);
00089    model2->SetIntegrationsProperty(5);
00090    model3->SetIntegrationsProperty(5);
00091    model4->SetIntegrationsProperty(5);
00092 
00093    TH1* res3 = (TH1*) fitter->CreateDrawObject("SmallI", "data", kTRUE);
00094 
00095    delete fitter;
00096 
00097 
00098  // draw modeled histogram
00099 //   DrawHistogram(res1,"Canvas1","SURF1");           // takes too long time
00100    DrawHistogram(res2,"Canvas2","SURF1");
00101    DrawHistogram(res3,"Canvas3","SURF1");
00102 
00103    Double_t i1 = res1->Integral()/1000000.;
00104    Double_t i2 = res2->Integral()/100.;
00105    Double_t i3 = res3->Integral()/100.;
00106 
00107    cout << "Integral over 1000x1000 points         =  " << i1 << endl;
00108    cout << "Integral over 10x10 points             =  " << i2 << endl;
00109    cout << "Integral over 10x10 with model integr. =  " << i3 << endl << endl;
00110 
00111    cout << "Integral2/Integral1 = " << i2/i1 << endl;
00112    cout << "Integral3/Integral1 = " << i3/i1 << endl;
00113 }
00114 
00115 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:57 2005 for Go4-v2.10-5 by doxygen1.2.15