GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example5.cxx
Go to the documentation of this file.
1 // $Id: Example5.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 N5
15  This is example how to fit one histogram and then apply fitter for another histogram
16 */
17 
18 #ifndef __CINT__
19 
20 #include "TH1.h"
21 #include "TFile.h"
22 #include "TApplication.h"
23 
24 #include "TGo4FitMinuit.h"
25 #include "TGo4Fitter.h"
26 #include "TGo4FitDataHistogram.h"
27 
28 void Example5();
29 
30 int main(int argc, char **argv)
31 {
32  TApplication theApp("Application", 0, 0);
33 
34  Example5();
35 
36  theApp.Run();
37 
38  return 0;
39 }
40 
41 #endif
42 
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 Example5()
56 {
57 // create fitter, select fit function and add standard actions list
58  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
59 
60 // add histogram to fitter, which should be fitted
61  TGo4FitDataHistogram *data = 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 two gaussians
67  fitter.AddGauss1( "data1", "Gauss1",2553.,15.);
68  fitter.AddGauss1( "data1", "Gauss2",2672.,15.);
69 
70 // perform all actions
71  fitter.DoActions();
72 
73 // Draw results
74  fitter.Draw("#data1,Gauss1,Gauss2");
75 
76 
77 // Up to here same as Example1
78 // Now we modify fitter and data to fit
79 
80 // add two mode components (peaks) to fitter
81  fitter.AddGauss1( "data1", "Gauss3", 2597., 14.);
82  fitter.AddGauss1( "data1", "Gauss4", 2717., 14.);
83 
84 // provide new histogram to data object
85  data->SetHistogram(GetHistogram("hDeg120_CND"),kTRUE);
86 
87 // perform all actions
88  fitter.DoActions();
89 
90 // remove output actions and add new
91  fitter.Draw("#data1,Gauss1,Gauss2,Gauss3,Gauss4");
92  fitter.Print("Pars");
93 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:705
void SetHistogram(TH1 *iHistogram, Bool_t iHistogramOwned=kFALSE)
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:981
TH1D * GetHistogram(const char *HistogramName)
Definition: Example5.cxx:45
int main(int argc, char **argv)
Definition: Example5.cxx:30
void Example5()
Definition: Example5.cxx:55
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
TGo4FitModelGauss1 * AddGauss1(const char *DataName, const char *ModelName, Double_t iPosition, Double_t iWidth, Double_t iAmpl=1., Int_t Axis=0)
Definition: TGo4Fitter.cxx:345
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124