GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example10.cxx
Go to the documentation of this file.
1 // $Id: Example10.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 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", 0, 0);
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 *f1 = TFile::Open("histograms.root");
51  if (f1==0) return 0;
52  TH1D *histo = 0;
53  f1->GetObject(HistogramName, histo);
54  if (histo) histo->SetDirectory(0);
55  return histo;
56 }
57 
58 void Example10()
59 {
60 // create fitter and select function to fit
61  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
62 
63  TH1D* histo1 = GetHistogram("hDeg120_P_c"); // get histogram from file
64  TH1D* histo2 = GetHistogram("hDeg120_CND"); // get histogram from file
65 
66 // add histogram to fitter, which should be fitted
67  fitter.AddH1("data2", histo2, kTRUE, 2200., 2900.);
68 
69 // create polynom of first order
70  fitter.AddPolynomX("data2", "Pol", 1);
71 
72 // add first histogram as component of second histogram
73  fitter.AddModel("data2", new TGo4FitModelFromData("Model1",histo1,kTRUE) );
74 
75 // create two gaussians
76  fitter.AddGauss1("data2", "Gauss3", 2597., 14.);
77  fitter.AddGauss1("data2", "Gauss4", 2717., 14.);
78 
79 // perform all actions
80  fitter.DoActions();
81 
82  // call fitter Draw method with options #data1,Gauss1,Gauss2
83  fitter.Draw("#data2,Model1,Gauss3,Gauss4");
84  fitter.Print("Pars");
85 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:705
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:981
void Example10()
Definition: Example10.cxx:58
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: 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:345
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:201
TH1D * GetHistogram(const char *HistogramName)
Definition: Example10.cxx:48
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124