Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Example8.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "Riostream.h"
00019 
00020 #include "TH1.h"
00021 #include "TH2.h"
00022 #include "TFile.h"
00023 #include "TCanvas.h"
00024 #include "TCutG.h"
00025 #include "TApplication.h"
00026 
00027 #include "../Go4Fit/TGo4FitMinuit.h"
00028 #include "../Go4Fit/TGo4Fitter.h"
00029 #include "../Go4Fit/TGo4FitDataHistogram.h"
00030 #include "../Go4Fit/TGo4FitModelPolynom.h"
00031 #include "../Go4Fit/TGo4FitModelGauss2.h"
00032 #include "../Go4Fit/TGo4FitModelGaussN.h"
00033 
00034 void Example8();
00035 
00036 int main(int argc, char **argv)
00037 {
00038    TApplication theApp("Application", 0, 0);
00039 
00040    Example8();
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 AddRangeCut(TGo4FitComponent* comp) {
00057    Double_t x[] = { 2,3,8,7,2 };
00058    Double_t y[] = { 8,3,2,7,8 };
00059    TCutG* cut = new TCutG("cut1",5,x,y);
00060    comp->AddRangeCut(cut);
00061 }
00062 
00063 void Example8() {
00064 // create fitter
00065    TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
00066 
00067 // create dummy histogram and set with owneship flag
00068    TH2D *histo = new TH2D("histo","dummy histogram",100,0.,10.,100,0.,10.);
00069    fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
00070 
00071 // create models component and assign them to fitter
00072    TGo4FitModel* model = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss",5.,5.,1.,1.,-0.5) );
00073    model->SetAmplValue(1000.);
00074 // only selected range will be used for modeling
00075    AddRangeCut(model);
00076 
00077 // create result model without optimization, using initial parameters values
00078    TH1* res = (TH1*) fitter->CreateDrawObject("GaussModel","data",kTRUE);
00079    delete fitter;
00080 
00081 
00082 // draw modeled histogram
00083    DrawHistogram(res,"Canvas1","SURF1");
00084 
00085 // create new fitter
00086    fitter = new TGo4Fitter("Fitter2",TGo4Fitter::ff_ML_Poisson,kFALSE);
00087 
00088 // use modeled histogram as data
00089    TGo4FitData* data = fitter->AddData(new TGo4FitDataHistogram("data",res));
00090 // only selected range will be used for data extracting and modeling
00091    AddRangeCut(data);
00092 
00093 // create N-dimensional gauss with 2 dimensions and set postion and width parameters
00094    model = fitter->AddModel( "data", new TGo4FitModelGaussN("Gauss",2) );
00095    model->SetPosition(0,4.5);
00096    model->SetPosition(1,4.5);
00097    model->SetWidth(0,1.7);
00098    model->SetWidth(1,1.7);
00099    model->SetAmplValue(500.);
00100 
00101    fitter->AddSimpleMinuit();
00102 
00103    fitter->SetMemoryUsage(1);
00104 
00105    fitter->DoActions();
00106 
00107    fitter->Print("Pars");
00108 
00109    delete fitter;
00110 }
00111 
00112 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:13 2008 for Go4-v3.04-1 by  doxygen 1.4.2