GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example12.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 N12
15 
16 #ifndef __CINT__
17 
18 #include "TGraph.h"
19 #include "TApplication.h"
20 
21 #include "TGo4Fitter.h"
22 #include "TGo4FitDataGraph.h"
23 
24 void Example12();
25 
26 int main(int argc, char **argv)
27 {
28  TApplication theApp("Application", nullptr, nullptr);
29 
30  Example12();
31 
32  theApp.Run();
33 
34  return 0;
35 }
36 
37 #endif
38 
39 // routine to generate example graph function
40 TGraph *MakeGraph()
41 {
42  TGraph *gr = new TGraph(40);
43  for (Int_t i = 0; i < 40; i++) {
44  Double_t x = (i + 1.) / 40.;
45  Double_t y = 5 - 0.5 * x + x * x;
46  if ((x > 0.3) && (x < 0.7))
47  y += 10. * (1. - 25. * (x - .5) * (x - .5));
48  gr->SetPoint(i, x, y);
49  }
50  return gr;
51 }
52 
53 void Example12()
54 {
55  // create fitter, select fit function and add standard actions list
56  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
57 
58  // add histogram to fitter, which should be fitted
59  fitter.AddGraph("data1", MakeGraph(), kTRUE);
60 
61  // add polynom of 2 order for background approx
62  fitter.AddPolynomX("data1", "BackgrPol", 2);
63 
64  // add polynom of 2 order for background approx
65  fitter.AddPolynomX("data1", "LinePol", 2, 123, 0.3, 0.7);
66 
67  // perform all actions
68  fitter.DoActions();
69 
70  // printing of fitter parameters
71  fitter.Print("Pars");
72 
73  // Draw data ("-" means without full model), Background and line (has group 123)
74  fitter.Draw("#data1-, Background, Group123");
75 }
TGo4FitDataGraph * AddGraph(const char *DataName, TGraph *gr, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:144
int main(int argc, char **argv)
Definition: Example12.cxx:26
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
void Example12()
Definition: Example12.cxx:53
TGraph * MakeGraph()
Definition: Example12.cxx:40
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
void Draw(Option_t *option) override
void Print(Option_t *option="") const override
Definition: TGo4Fitter.cxx:779