GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example4.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 Example N4
15  Same as small Example1, but for gaussian modelling new model component was constructed
16  First way is to define user function and assign it to in TGo4FitModelFunction class
17  In TModelTemplate class UserFunction method was redefined
18 */
19 
20 #ifndef __CINT__
21 
22 #include "TH1.h"
23 #include "TFile.h"
24 #include "TApplication.h"
25 
26 #include "TGo4Fitter.h"
27 #include "TModelTemplate.h"
28 
29 void Example4();
30 
31 int main(int argc, char **argv)
32 {
33  TApplication theApp("Application", nullptr, nullptr);
34 
35  Example4();
36 
37  theApp.Run();
38 
39  return 0;
40 }
41 
42 #endif
43 
44 // routine to read histogram from examples file
45 TH1D* GetHistogram(const char *HistogramName)
46 {
47  TFile *f = TFile::Open("histograms.root");
48  if (!f) return nullptr;
49  TH1D *histo = nullptr;
50  f->GetObject(HistogramName, histo);
51  if (histo) histo->SetDirectory(nullptr);
52  delete f;
53  return histo;
54 }
55 
56 void Example4()
57 {
58 // create fitter, select fit function and add standard actions
59  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
60 
61 // add histogram to fitter, which should be fitted
62  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
63 
64 // create polynom of first order
65  fitter.AddPolynomX( "data1", "Pol", 1);
66 
67 // create model components, which uses new model class to calculate gaussian shape
68  fitter.AddModel( "data1", new TModelTemplate("Gauss1",2,kTRUE) );
69  fitter.AddModel( "data1", new TModelTemplate("Gauss2",2,kTRUE) );
70 
71 // set initial values of user model parameters
72  fitter.SetParValue("Gauss1.Par0",2553.);
73  fitter.SetParValue("Gauss1.Par1",15.);
74  fitter.SetParValue("Gauss2.Par0",2672.);
75  fitter.SetParValue("Gauss2.Par1",15.);
76 
77 // perform all actions
78  fitter.DoActions();
79 
80 // add output actions
81  fitter.Draw ("#data1,Gauss1,Gauss2");
82  fitter.Print("Pars");
83 }
Bool_t SetParValue(const char *ParName, Double_t iValue)
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
int main(int argc, char **argv)
Definition: Example4.cxx:31
TH1D * GetHistogram(const char *HistogramName)
Definition: Example4.cxx:45
void Example4()
Definition: Example4.cxx:56
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:210
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
void Draw(Option_t *option) override
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:127
void Print(Option_t *option="") const override
Definition: TGo4Fitter.cxx:779