GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example5.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 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", nullptr, nullptr);
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 *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 Example5()
57 {
58 // create fitter, select fit function and add standard actions list
59  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
60 
61 // add histogram to fitter, which should be fitted
62  TGo4FitDataHistogram *data = 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 two gaussians
68  fitter.AddGauss1( "data1", "Gauss1",2553.,15.);
69  fitter.AddGauss1( "data1", "Gauss2",2672.,15.);
70 
71 // perform all actions
72  fitter.DoActions();
73 
74 // Draw results
75  fitter.Draw("#data1,Gauss1,Gauss2");
76 
77 
78 // Up to here same as Example1
79 // Now we modify fitter and data to fit
80 
81 // add two mode components (peaks) to fitter
82  fitter.AddGauss1( "data1", "Gauss3", 2597., 14.);
83  fitter.AddGauss1( "data1", "Gauss4", 2717., 14.);
84 
85 // provide new histogram to data object
86  data->SetHistogram(GetHistogram("hDeg120_CND"),kTRUE);
87 
88 // perform all actions
89  fitter.DoActions();
90 
91 // remove output actions and add new
92  fitter.Draw("#data1,Gauss1,Gauss2,Gauss3,Gauss4");
93  fitter.Print("Pars");
94 }
void SetHistogram(TH1 *iHistogram, Bool_t iHistogramOwned=kFALSE)
TH1D * GetHistogram(const char *HistogramName)
Definition: Example5.cxx:45
int main(int argc, char **argv)
Definition: Example5.cxx:30
void Example5()
Definition: Example5.cxx:56
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
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:382
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