GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example4.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
22
23#ifndef __CINT__
24
25#include "TH1.h"
26#include "TFile.h"
27#include "TApplication.h"
28
29#include "TGo4Fitter.h"
30#include "TModelTemplate.h"
31
32void Example4();
33
34int main(int argc, char **argv)
35{
36 TApplication theApp("Application", nullptr, nullptr);
37
38 Example4();
39
40 theApp.Run();
41
42 return 0;
43}
44
45#endif
46
47// routine to read histogram from examples file
48TH1D* GetHistogram(const char *HistogramName)
49{
50 TFile *f = TFile::Open("histograms.root");
51 if (!f) return nullptr;
52 TH1D *histo = nullptr;
53 f->GetObject(HistogramName, histo);
54 if (histo) histo->SetDirectory(nullptr);
55 delete f;
56 return histo;
57}
58
60{
61// create fitter, select fit function and add standard actions
62 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
63
64// add histogram to fitter, which should be fitted
65 fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
66
67// create polynom of first order
68 fitter.AddPolynomX( "data1", "Pol", 1);
69
70// create model components, which uses new model class to calculate gaussian shape
71 fitter.AddModel( "data1", new TModelTemplate("Gauss1",2,kTRUE) );
72 fitter.AddModel( "data1", new TModelTemplate("Gauss2",2,kTRUE) );
73
74// set initial values of user model parameters
75 fitter.SetParValue("Gauss1.Par0",2553.);
76 fitter.SetParValue("Gauss1.Par1",15.);
77 fitter.SetParValue("Gauss2.Par0",2672.);
78 fitter.SetParValue("Gauss2.Par1",15.);
79
80// perform all actions
81 fitter.DoActions();
82
83// add output actions
84 fitter.Draw ("#data1,Gauss1,Gauss2");
85 fitter.Print("Pars");
86}
int main(int argc, char **argv)
Definition Example4.cxx:34
void Example4()
Definition Example4.cxx:59
TH1D * GetHistogram(const char *HistogramName)
Definition Example4.cxx:48
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.
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.