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

Example2.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 Example N2
00017 
00018 
00019 #ifndef __CINT__
00020 
00021 #include "TH1.h"
00022 #include "TFile.h"
00023 #include "TApplication.h"
00024 
00025 #include "../Go4Fit/TGo4Fitter.h"
00026 #include "../Go4Fit/TGo4FitModelFunction.h"
00027 #include "../Go4Fit/TGo4FitModelFormula.h"
00028 
00029 void Example2();
00030 
00031 int main(int argc, char **argv) {
00032 
00033    TApplication theApp("Application", 0, 0);
00034 
00035    Example2();
00036 
00037    theApp.Run();
00038 
00039    return 0;
00040 }
00041 
00042 #endif
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 Example2() {
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 models, which are used user function and formula to calculate gaussian shape
00063    TGo4FitModel* model1 = fitter.AddModel( "data1",
00064      new TGo4FitModelFunction("Gauss1","Example2Func.so","gaussian",2,kTRUE) );
00065    TGo4FitModel* model2 = fitter.AddModel( "data1",
00066      new TGo4FitModelFormula("Gauss2", "exp(-0.5*(x-Pos)*(x-Pos)/Width/Width)",2,kTRUE));
00067 
00068 // set parameters names for models
00069    model1->SetParsNames("Ampl","Pos","Width");
00070    model2->SetParsNames("Ampl","Pos","Width");
00071 
00072 // set initial values of user model parameters
00073    model1->SetParsValues(1.,2553.,15.);
00074    model2->SetParsValues(1.,2672.,15.);
00075 
00076 // perform all actions
00077    fitter.DoActions();
00078 
00079 // printing of fitter parameters
00080    fitter.Print("Pars");
00081 
00082 // Draw data, model and two components
00083    fitter.Draw("#data1,Background,Gauss1,Gauss2");
00084 //   fitter.Draw("#data1");
00085 }
00086 
00087 //----------------------------END OF GO4 SOURCE FILE ---------------------

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