GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example3.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 <iostream>
23
24#include "TH1.h"
25#include "TFile.h"
26#include "TApplication.h"
27
28#include "TGo4Fitter.h"
30
31void Example3();
32
33int main(int argc, char **argv)
34{
35 TApplication theApp("Application", nullptr, nullptr);
36
37 Example3();
38
39 theApp.Run();
40
41 return 0;
42}
43
44extern "C" Double_t gaussian_(Double_t *axis, Double_t *pars);
45
46// routine to read histogram from examples file
47TH1D* GetHistogram(const char *HistogramName)
48{
49 TFile *f = TFile::Open("histograms.root");
50 if (!f) return nullptr;
51 TH1D *histo = nullptr;
52 f->GetObject(HistogramName, histo);
53 if (histo) histo->SetDirectory(nullptr);
54 delete f;
55 return histo;
56}
57
59{
60// create fitter, select fit function and add standard actions list
61 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
62
63// add histogram to fitter, which should be fitted
64 fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
65
66// create polynom of first order
67 fitter.AddPolynomX( "data1", "Pol", 1);
68
69// create model, which uses user function to calculate gaussian shape
70 fitter.AddModel("data1", new TGo4FitModelFunction("Gauss1", &gaussian_, 2, kTRUE));
71 fitter.AddModel("data1", new TGo4FitModelFunction("Gauss2", &gaussian_, 2, kTRUE));
72
73// set initial values of user model parameters
74 fitter.SetParValue("Gauss1.Par0",2553.);
75 fitter.SetParValue("Gauss1.Par1",15.);
76 fitter.SetParValue("Gauss2.Par0",2672.);
77 fitter.SetParValue("Gauss2.Par1",15.);
78
79// add output actions
80 fitter.AddOutputAction("Draw","#data1,Gauss1,Gauss2");
81 fitter.AddOutputAction("Print","Pars");
82
83// perform all actions
84 fitter.DoActions();
85}
86
87#else
88
89void Example3()
90{
91 std::cout << "This example uses linked FORTRAN library," << std::endl;
92 std::cout << "therefore it can not be run in CINT" << std::endl;
93}
94
95#endif
96
int main(int argc, char **argv)
Definition Example3.cxx:33
void Example3()
Definition Example3.cxx:58
TH1D * GetHistogram(const char *HistogramName)
Definition Example3.cxx:47
Double_t gaussian_(Double_t *axis, Double_t *pars)
Model objects, which uses external user function to calculate model values.
Bool_t SetParValue(const char *ParName, Double_t iValue)
Set value of parameter with given name.
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
Executes actions list.
TGo4FitterOutput * AddOutputAction(const char *Action, const char *Option=nullptr)
Creates and add TGo4FitterOutput action with given parameters to 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 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.
TGo4FitModel * AddModel(TGo4FitModel *m)
Add model component to fitter.