GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example2.cxx
Go to the documentation of this file.
1 // $Id: Example2.cxx 3058 2021-03-12 11:01:32Z 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 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 Example N2
15 
16 
17 #ifndef __CINT__
18 
19 #include "TH1.h"
20 #include "TFile.h"
21 #include "TApplication.h"
22 
23 #include "TGo4Fitter.h"
24 #include "TGo4FitModelFunction.h"
25 #include "TGo4FitModelFormula.h"
26 
27 void Example2();
28 
29 int main(int argc, char **argv) {
30 
31  TApplication theApp("Application", 0, 0);
32 
33  Example2();
34 
35  theApp.Run();
36 
37  return 0;
38 }
39 
40 #endif
41 
42 // routine to read histogram from examples file
43 TH1D* GetHistogram(const char* HistogramName)
44 {
45  TFile *f1 = TFile::Open("histograms.root");
46  if (f1==0) return 0;
47  TH1D *histo = 0;
48  f1->GetObject(HistogramName, histo);
49  if (histo) histo->SetDirectory(0);
50  return histo;
51 }
52 
53 void Example2()
54 {
55 // create fitter, select fit function and add standard actions list
56  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
57 
58 // add histogram to fitter, which should be fitted
59  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
60 
61 // create polynom of first order
62  fitter.AddPolynomX( "data1", "Pol", 1);
63 
64 // create models, which are used user function and formula to calculate gaussian shape
65  TGo4FitModel* model1 = fitter.AddModel( "data1",
66  new TGo4FitModelFunction("Gauss1","Example2Func.so","gaussian",2,kTRUE) );
67  TGo4FitModel* model2 = fitter.AddModel( "data1",
68  new TGo4FitModelFormula("Gauss2", "exp(-0.5*(x-Pos)*(x-Pos)/Width/Width)",2,kTRUE));
69 
70 // set parameters names for models
71  model1->SetParsNames("Ampl","Pos","Width");
72  model2->SetParsNames("Ampl","Pos","Width");
73 
74 // set initial values of user model parameters
75  model1->SetParsValues(1.,2553.,15.);
76  model2->SetParsValues(1.,2672.,15.);
77 
78 // perform all actions
79  fitter.DoActions();
80 
81 // printing of fitter parameters
82  fitter.Print("Pars");
83 
84 // Draw data, model and two components
85  fitter.Draw("#data1,Background,Gauss1,Gauss2");
86 // fitter.Draw("#data1");
87 }
void SetParsNames(const char *name0="Par0", const char *name1="Par1", const char *name2="Par2", const char *name3="Par3", const char *name4="Par4", const char *name5="Par5", const char *name6="Par6", const char *name7="Par7", const char *name8="Par8", const char *name9="Par9")
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:705
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:981
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:223
int main(int argc, char **argv)
Definition: Example2.cxx:29
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TH1D * GetHistogram(const char *HistogramName)
Definition: Example2.cxx:43
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:201
void SetParsValues(Double_t *pars)
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124
void Example2()
Definition: Example2.cxx:53