GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example4.cxx
Go to the documentation of this file.
1 // $Id: Example4.cxx 555 2010-01-27 12:40:54Z 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 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 = (TH1D*) f1->Get(HistogramName);
50  if (histo) histo->SetDirectory(0);
51  return histo;
52 }
53 
54 void Example4()
55 {
56 // create fitter, select fit function and add standard actions
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 components, which uses new model class to calculate gaussian shape
66  fitter.AddModel( "data1", new TModelTemplate("Gauss1",2,kTRUE) );
67  fitter.AddModel( "data1", new TModelTemplate("Gauss2",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 // perform all actions
76  fitter.DoActions();
77 
78 // add output actions
79  fitter.Draw ("#data1,Gauss1,Gauss2");
80  fitter.Print("Pars");
81 }
Bool_t SetParValue(const char *ParName, Double_t iValue)
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:707
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:983
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
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:54
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