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