GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example5.cxx
Go to the documentation of this file.
1 // $Id: Example5.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 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 = (TH1D*) f1->Get(HistogramName);
50  if (histo) histo->SetDirectory(0);
51  return histo;
52 }
53 
54 void Example5()
55 {
56 // create fitter, select fit function and add standard actions list
57  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
58 
59 // add histogram to fitter, which should be fitted
60  TGo4FitDataHistogram *data = 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 two gaussians
66  fitter.AddGauss1( "data1", "Gauss1",2553.,15.);
67  fitter.AddGauss1( "data1", "Gauss2",2672.,15.);
68 
69 // perform all actions
70  fitter.DoActions();
71 
72 // Draw results
73  fitter.Draw("#data1,Gauss1,Gauss2");
74 
75 
76 // Up to here same as Example1
77 // Now we modify fitter and data to fit
78 
79 // add two mode components (peaks) to fitter
80  fitter.AddGauss1( "data1", "Gauss3", 2597., 14.);
81  fitter.AddGauss1( "data1", "Gauss4", 2717., 14.);
82 
83 // provide new histogram to data object
84  data->SetHistogram(GetHistogram("hDeg120_CND"),kTRUE);
85 
86 // perform all actions
87  fitter.DoActions();
88 
89 // remove output actions and add new
90  fitter.Draw("#data1,Gauss1,Gauss2,Gauss3,Gauss4");
91  fitter.Print("Pars");
92 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:707
void SetHistogram(TH1 *iHistogram, Bool_t iHistogramOwned=kFALSE)
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:983
TH1D * GetHistogram(const char *HistogramName)
Definition: Example5.cxx:45
int main(int argc, char **argv)
Definition: Example5.cxx:30
void Example5()
Definition: Example5.cxx:54
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
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:347
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:126