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

/Go4FitExample/Example8.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 void Example8();
00034 
00035 int main(int argc, char **argv)
00036 {
00037    TApplication theApp("Application", 0, 0);
00038 
00039    Example8();
00040 
00041    theApp.Run();
00042 
00043    return 0;
00044 }
00045 
00046 #endif
00047 
00048 void DrawHistogram(TH1* histo, const char* CanvasName, const char* DrawOption) {
00049    TCanvas *fCanvas = new TCanvas(CanvasName,"Draw of histogram",3);
00050    fCanvas->cd();
00051    histo->Draw(DrawOption);
00052    fCanvas->Update();
00053 }
00054 
00055 void AddRangeCut(TGo4FitComponent* comp) {
00056    Double_t x[] = { 2,3,8,7,2 };
00057    Double_t y[] = { 8,3,2,7,8 };
00058    TCutG* cut = new TCutG("cut1",5,x,y);
00059    comp->AddRangeCut(cut);
00060 }
00061 
00062 void Example8() {
00063 // create fitter
00064    TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
00065 
00066 // create dummy histogram and set with owneship flag
00067    TH2D *histo = new TH2D("histo","dummy histogram",100,0.,10.,100,0.,10.);
00068    fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
00069 
00070 // create models component and assign them to fitter
00071    TGo4FitModel* model = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss",5.,5.,1.,1.,-0.5) );
00072    model->SetAmplValue(1000.);
00073 // only selected range will be used for modeling
00074    AddRangeCut(model);
00075 
00076 // create result model without optimization, using initial parameters values
00077    TH1* res = (TH1*) fitter->CreateDrawObject("GaussModel","data",kTRUE);
00078    delete fitter;
00079 
00080 
00081 // draw modeled histogram
00082    DrawHistogram(res,"Canvas1","SURF1");
00083 
00084 // create new fitter
00085    fitter = new TGo4Fitter("Fitter2",TGo4Fitter::ff_ML_Poisson,kFALSE);
00086 
00087 // use modeled histogram as data
00088    TGo4FitData* data = fitter->AddData(new TGo4FitDataHistogram("data",res));
00089 // only selected range will be used for data extracting and modeling
00090    AddRangeCut(data);
00091 
00092 // create N-dimensional gauss with 2 dimensions and set postion and width parameters
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 }
00110 
00111 //----------------------------END OF GO4 SOURCE FILE ---------------------

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