GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example3.cxx
Go to the documentation of this file.
1 // $Id$
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 fuer 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 <iostream>
19 
20 #include "TH1.h"
21 #include "TFile.h"
22 #include "TApplication.h"
23 
24 #include "TGo4Fitter.h"
25 #include "TGo4FitModelFunction.h"
26 
27 void Example3();
28 
29 int main(int argc, char **argv)
30 {
31  TApplication theApp("Application", nullptr, nullptr);
32 
33  Example3();
34 
35  theApp.Run();
36 
37  return 0;
38 }
39 
40 extern "C" Double_t gaussian_(Double_t *axis, Double_t *pars);
41 
42 // routine to read histogram from examples file
43 TH1D* GetHistogram(const char *HistogramName)
44 {
45  TFile *f = TFile::Open("histograms.root");
46  if (!f) return nullptr;
47  TH1D *histo = nullptr;
48  f->GetObject(HistogramName, histo);
49  if (histo) histo->SetDirectory(nullptr);
50  delete f;
51  return histo;
52 }
53 
54 void Example3()
55 {
56 // create fitter, select fit function and add standard actions list
57  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
58 
59 // add histogram to fitter, which should be fitted
60  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
61 
62 // create polynom of first order
63  fitter.AddPolynomX( "data1", "Pol", 1);
64 
65 // create model, which uses user function to calculate gaussian shape
66  fitter.AddModel("data1", new TGo4FitModelFunction("Gauss1", &gaussian_, 2, kTRUE));
67  fitter.AddModel("data1", new TGo4FitModelFunction("Gauss2", &gaussian_, 2, kTRUE));
68 
69 // set initial values of user model parameters
70  fitter.SetParValue("Gauss1.Par0",2553.);
71  fitter.SetParValue("Gauss1.Par1",15.);
72  fitter.SetParValue("Gauss2.Par0",2672.);
73  fitter.SetParValue("Gauss2.Par1",15.);
74 
75 // add output actions
76  fitter.AddOutputAction("Draw","#data1,Gauss1,Gauss2");
77  fitter.AddOutputAction("Print","Pars");
78 
79 // perform all actions
80  fitter.DoActions();
81 }
82 
83 #else
84 
85 void Example3()
86 {
87  std::cout << "This example uses linked FORTRAN library," << std::endl;
88  std::cout << "therefore it can not be run in CINT" << std::endl;
89 }
90 
91 #endif
92 
Bool_t SetParValue(const char *ParName, Double_t iValue)
int main(int argc, char **argv)
Definition: Example3.cxx:29
TH1D * GetHistogram(const char *HistogramName)
Definition: Example3.cxx:43
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:235
void Example3()
Definition: Example3.cxx:54
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:210
TGo4FitterOutput * AddOutputAction(const char *Action, const char *Option=nullptr)
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:127