GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example4.cxx
Go to the documentation of this file.
1 // $Id: Example4.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 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", 0, 0);
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 *f1 = TFile::Open("histograms.root");
48  if (f1==0) return 0;
49  TH1D *histo = 0;
50  f1->GetObject(HistogramName, histo);
51  if (histo) histo->SetDirectory(0);
52  return histo;
53 }
54 
55 void Example4()
56 {
57 // create fitter, select fit function and add standard actions
58  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
59 
60 // add histogram to fitter, which should be fitted
61  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
62 
63 // create polynom of first order
64  fitter.AddPolynomX( "data1", "Pol", 1);
65 
66 // create model components, which uses new model class to calculate gaussian shape
67  fitter.AddModel( "data1", new TModelTemplate("Gauss1",2,kTRUE) );
68  fitter.AddModel( "data1", new TModelTemplate("Gauss2",2,kTRUE) );
69 
70 // set initial values of user model parameters
71  fitter.SetParValue("Gauss1.Par0",2553.);
72  fitter.SetParValue("Gauss1.Par1",15.);
73  fitter.SetParValue("Gauss2.Par0",2672.);
74  fitter.SetParValue("Gauss2.Par1",15.);
75 
76 // perform all actions
77  fitter.DoActions();
78 
79 // add output actions
80  fitter.Draw ("#data1,Gauss1,Gauss2");
81  fitter.Print("Pars");
82 }
Bool_t SetParValue(const char *ParName, Double_t iValue)
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: Example4.cxx:31
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TH1D * GetHistogram(const char *HistogramName)
Definition: Example4.cxx:45
void Example4()
Definition: Example4.cxx:55
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:201
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124