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

Example3.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 // Go4Fit Examples N3
00017 
00018 #ifndef __CINT__
00019 
00020 #include "Riostream.h"
00021 
00022 #include "TH1.h"
00023 #include "TFile.h"
00024 #include "TApplication.h"
00025 
00026 #include "../Go4Fit/TGo4Fitter.h"
00027 #include "../Go4Fit/TGo4FitModelFunction.h"
00028 
00029 void Example3();
00030 
00031 int main(int argc, char **argv)
00032 {
00033    TApplication theApp("Application", 0, 0);
00034 
00035    Example3();
00036 
00037    theApp.Run();
00038 
00039    return 0;
00040 }
00041 
00042 extern "C" Double_t gaussian_(Double_t *axis, Double_t *pars);
00043 
00044 // routine to read histogram from examples file
00045 TH1D* GetHistogram(const char* HistogramName) {
00046    TFile f1("histograms.root");
00047    TH1D* histo = (TH1D*) f1.Get(HistogramName);
00048    histo->SetDirectory(0);
00049    return histo;
00050 }
00051 
00052 void Example3() {
00053 // create fitter, select fit function and add standard actions list
00054    TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
00055 
00056 // add histogram to fitter, which should be fitted
00057    fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
00058 
00059 // create polynom of first order
00060    fitter.AddPolynomX( "data1", "Pol", 1);
00061 
00062 // create model, which uses user function to calculate gaussian shape
00063    fitter.AddModel( "data1", new TGo4FitModelFunction("Gauss1",&gaussian_,2,kTRUE) );
00064    fitter.AddModel( "data1", new TGo4FitModelFunction("Gauss2",&gaussian_,2,kTRUE) );
00065 
00066 // set initial values of user model parameters
00067    fitter.SetParValue("Gauss1.Par0",2553.);
00068    fitter.SetParValue("Gauss1.Par1",15.);
00069    fitter.SetParValue("Gauss2.Par0",2672.);
00070    fitter.SetParValue("Gauss2.Par1",15.);
00071 
00072 // add output actions
00073    fitter.AddOutputAction("Draw","#data1,Gauss1,Gauss2");
00074    fitter.AddOutputAction("Print","Pars");
00075 
00076 // perform all actions
00077    fitter.DoActions();
00078 }
00079 
00080 #else
00081 
00082 void Example3() {
00083    cout << "This example uses linked FORTRAN libraray," << endl;
00084    cout << "therefore it can not be run in CINT" << endl;
00085 }
00086 
00087 #endif
00088 
00089 
00090 //----------------------------END OF GO4 SOURCE FILE ---------------------

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