GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example3.cxx
Go to the documentation of this file.
1 // $Id: Example3.cxx 934 2013-01-29 15:59:24Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 // Go4Fit Examples N3
15 
16 #ifndef __CINT__
17 
18 #include "Riostream.h"
19 #include "TH1.h"
20 #include "TFile.h"
21 #include "TApplication.h"
22 
23 #include "TGo4Fitter.h"
24 #include "TGo4FitModelFunction.h"
25 
26 void Example3();
27 
28 int main(int argc, char **argv)
29 {
30  TApplication theApp("Application", 0, 0);
31 
32  Example3();
33 
34  theApp.Run();
35 
36  return 0;
37 }
38 
39 extern "C" Double_t gaussian_(Double_t *axis, Double_t *pars);
40 
41 // routine to read histogram from examples file
42 TH1D* GetHistogram(const char* HistogramName)
43 {
44  TFile* f1 = TFile::Open("histograms.root");
45  if (f1==0) return 0;
46  TH1D* histo = (TH1D*) f1->Get(HistogramName);
47  if (histo) histo->SetDirectory(0);
48  return histo;
49 }
50 
51 void Example3()
52 {
53 // create fitter, select fit function and add standard actions list
54  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
55 
56 // add histogram to fitter, which should be fitted
57  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
58 
59 // create polynom of first order
60  fitter.AddPolynomX( "data1", "Pol", 1);
61 
62 // create model, which uses user function to calculate gaussian shape
63  fitter.AddModel( "data1", new TGo4FitModelFunction("Gauss1",&gaussian_,2,kTRUE) );
64  fitter.AddModel( "data1", new TGo4FitModelFunction("Gauss2",&gaussian_,2,kTRUE) );
65 
66 // set initial values of user model parameters
67  fitter.SetParValue("Gauss1.Par0",2553.);
68  fitter.SetParValue("Gauss1.Par1",15.);
69  fitter.SetParValue("Gauss2.Par0",2672.);
70  fitter.SetParValue("Gauss2.Par1",15.);
71 
72 // add output actions
73  fitter.AddOutputAction("Draw","#data1,Gauss1,Gauss2");
74  fitter.AddOutputAction("Print","Pars");
75 
76 // perform all actions
77  fitter.DoActions();
78 }
79 
80 #else
81 
82 void Example3()
83 {
84  std::cout << "This example uses linked FORTRAN library," << std::endl;
85  std::cout << "therefore it can not be run in CINT" << std::endl;
86 }
87 
88 #endif
89 
Bool_t SetParValue(const char *ParName, Double_t iValue)
int main(int argc, char **argv)
Definition: Example3.cxx:28
TH1D * GetHistogram(const char *HistogramName)
Definition: Example3.cxx:42
Double_t gaussian_(Double_t *axis, Double_t *pars)
void AddPolynomX(const char *DataName, const char *NamePrefix, Int_t MaxOrder=1, Int_t GroupIndex=0, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:225
TGo4FitterOutput * AddOutputAction(const char *Action, const char *Option=0)
void Example3()
Definition: Example3.cxx:51
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:203
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:126