GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example2.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
19
20#ifndef __CINT__
21
22#include "TH1.h"
23#include "TFile.h"
24#include "TApplication.h"
25
26#include "TGo4Fitter.h"
28#include "TGo4FitModelFormula.h"
29
30void Example2();
31
32int main(int argc, char **argv) {
33
34 TApplication theApp("Application", nullptr, nullptr);
35
36 Example2();
37
38 theApp.Run();
39
40 return 0;
41}
42
43#endif
44
45// routine to read histogram from examples file
46TH1D* GetHistogram(const char *HistogramName)
47{
48 TFile *f = TFile::Open("histograms.root");
49 if (!f) return nullptr;
50 TH1D *histo = nullptr;
51 f->GetObject(HistogramName, histo);
52 if (histo) histo->SetDirectory(nullptr);
53 delete f;
54 return histo;
55}
56
58{
59// create fitter, select fit function and add standard actions list
60 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
61
62// add histogram to fitter, which should be fitted
63 fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
64
65// create polynom of first order
66 fitter.AddPolynomX( "data1", "Pol", 1);
67
68// create models, which are used user function and formula to calculate gaussian shape
69 TGo4FitModel *model1 = fitter.AddModel( "data1",
70 new TGo4FitModelFunction("Gauss1","libExample2Func.so","gaussian",2,kTRUE) );
71 TGo4FitModel *model2 = fitter.AddModel( "data1",
72 new TGo4FitModelFormula("Gauss2", "exp(-0.5*(x-Pos)*(x-Pos)/Width/Width)",2,kTRUE));
73
74// set parameters names for models
75 model1->SetParsNames("Ampl","Pos","Width");
76 model2->SetParsNames("Ampl","Pos","Width");
77
78// set initial values of user model parameters
79 model1->SetParsValues(1.,2553.,15.);
80 model2->SetParsValues(1.,2672.,15.);
81
82// perform all actions
83 fitter.DoActions();
84
85// printing of fitter parameters
86 fitter.Print("Pars");
87
88// Draw data, model and two components
89 fitter.Draw("#data1,Background,Gauss1,Gauss2");
90// fitter.Draw("#data1");
91}
int main(int argc, char **argv)
Definition Example2.cxx:32
TH1D * GetHistogram(const char *HistogramName)
Definition Example2.cxx:46
void Example2()
Definition Example2.cxx:57
Model object, which uses ROOT TFormula class facility.
Model objects, which uses external user function to calculate model values.
Basic abstract class for representing model components of fitted data.
void SetParsNames(const char *name0="Par0", const char *name1="Par1", const char *name2="Par2", const char *name3="Par3", const char *name4="Par4", const char *name5="Par5", const char *name6="Par6", const char *name7="Par7", const char *name8="Par8", const char *name9="Par9")
Set names of first 10 parameters.
void SetParsValues(Double_t *pars)
Set value for all parameters from array.
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
Executes actions list.
Central class of Go4Fit package.
Definition TGo4Fitter.h:38
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Create TGo4FitDataHistogram object and adds its to fitter.
void Print(Option_t *option="") const override
Print containment of fitter.
void AddPolynomX(const char *DataName, const char *NamePrefix, Int_t MaxOrder=1, Int_t GroupIndex=0, Double_t lrange=0., Double_t rrange=0.)
Construct 1-dim polynom for specified data object for x scale.
void Draw(Option_t *option) override
Draw fitter on current canvas.
TGo4FitModel * AddModel(TGo4FitModel *m)
Add model component to fitter.