GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example1.cxx
Go to the documentation of this file.
1 // $Id: Example1.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 Examples
15  This is small examples how to fit part of histogram
16  with two gaussian and polynom function
17 */
18 
19 #ifndef __CINT__
20 
21 #include "TH1.h"
22 #include "TFile.h"
23 #include "TApplication.h"
24 
25 #include "TGo4Fitter.h"
26 
27 void Example1();
28 
29 int main(int argc, char **argv)
30 {
31  TApplication theApp("Application", 0, 0);
32 
33  Example1();
34 
35  theApp.Run();
36 
37  return 0;
38 }
39 
40 #endif
41 
42 // routine to read histogram from examples file
43 TH1D* GetHistogram(const char* HistogramName)
44 {
45  TFile* f1 = TFile::Open("histograms.root");
46  if (f1==0) return 0;
47  TH1D* histo = (TH1D*) f1->Get(HistogramName);
48  if (histo) histo->SetDirectory(0);
49  return histo;
50 }
51 
52 void Example1()
53 {
54 // create fitter, select fit function and add standard actions list
55  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
56 
57 // add histogram to fitter, which should be fitted
58  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
59 
60 // create polynom of first order
61  fitter.AddPolynomX("data1", "Pol", 1);
62 
63 // create two gaussians
64  fitter.AddGauss1("data1", "Gauss1", 2553., 15.);
65  fitter.AddGauss1("data1", "Gauss2", 2672., 15.);
66 
67 // execute all actions
68  fitter.DoActions();
69 
70 // draw data, full model and two gaussains on new canvas
71  fitter.Draw("#data1,Gauss1,Gauss2");
72 }
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:983
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
void Example1()
Definition: Example1.cxx:52
TH1D * GetHistogram(const char *HistogramName)
Definition: Example1.cxx:43
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
int main(int argc, char **argv)
Definition: Example1.cxx:29
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