GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example10.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 N10
15  This is examples of using histogram as model component for another histogram
16 */
17 
18 #ifndef __CINT__
19 
20 #include "TH1.h"
21 #include "TFile.h"
22 #include "TCanvas.h"
23 #include "TApplication.h"
24 
25 #include "TGo4FitMinuit.h"
26 #include "TGo4Fitter.h"
27 #include "TGo4FitDataHistogram.h"
28 #include "TGo4FitModelPolynom.h"
29 #include "TGo4FitModelGauss1.h"
30 #include "TGo4FitModelFromData.h"
31 
32 void Example10();
33 
34 int main(int argc, char **argv)
35 {
36  TApplication theApp("Application", nullptr, nullptr);
37 
38  Example10();
39 
40  theApp.Run();
41 
42  return 0;
43 }
44 
45 #endif
46 
47 // routine to read histogram from examples file
48 TH1D* GetHistogram(const char *HistogramName)
49 {
50  TFile *f = TFile::Open("histograms.root");
51  if (!f) return nullptr;
52  TH1D *histo = nullptr;
53  f->GetObject(HistogramName, histo);
54  if (histo) histo->SetDirectory(nullptr);
55  delete f;
56  return histo;
57 }
58 
59 void Example10()
60 {
61 // create fitter and select function to fit
62  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
63 
64  TH1D* histo1 = GetHistogram("hDeg120_P_c"); // get histogram from file
65  TH1D* histo2 = GetHistogram("hDeg120_CND"); // get histogram from file
66 
67 // add histogram to fitter, which should be fitted
68  fitter.AddH1("data2", histo2, kTRUE, 2200., 2900.);
69 
70 // create polynom of first order
71  fitter.AddPolynomX("data2", "Pol", 1);
72 
73 // add first histogram as component of second histogram
74  fitter.AddModel("data2", new TGo4FitModelFromData("Model1",histo1,kTRUE) );
75 
76 // create two gaussians
77  fitter.AddGauss1("data2", "Gauss3", 2597., 14.);
78  fitter.AddGauss1("data2", "Gauss4", 2717., 14.);
79 
80 // perform all actions
81  fitter.DoActions();
82 
83  // call fitter Draw method with options #data1,Gauss1,Gauss2
84  fitter.Draw("#data2,Model1,Gauss3,Gauss4");
85  fitter.Print("Pars");
86 }
void Example10()
Definition: Example10.cxx:59
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: Example10.cxx:34
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
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:210
TH1D * GetHistogram(const char *HistogramName)
Definition: Example10.cxx:48
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