GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example5.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
20
21#ifndef __CINT__
22
23#include "TH1.h"
24#include "TFile.h"
25#include "TApplication.h"
26
27#include "TGo4FitMinuit.h"
28#include "TGo4Fitter.h"
30
31void Example5();
32
33int main(int argc, char **argv)
34{
35 TApplication theApp("Application", nullptr, nullptr);
36
37 Example5();
38
39 theApp.Run();
40
41 return 0;
42}
43
44#endif
45
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 list
62 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
63
64// add histogram to fitter, which should be fitted
65 TGo4FitDataHistogram *data = 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 two gaussians
71 fitter.AddGauss1( "data1", "Gauss1",2553.,15.);
72 fitter.AddGauss1( "data1", "Gauss2",2672.,15.);
73
74// perform all actions
75 fitter.DoActions();
76
77// Draw results
78 fitter.Draw("#data1,Gauss1,Gauss2");
79
80
81// Up to here same as Example1
82// Now we modify fitter and data to fit
83
84// add two mode components (peaks) to fitter
85 fitter.AddGauss1( "data1", "Gauss3", 2597., 14.);
86 fitter.AddGauss1( "data1", "Gauss4", 2717., 14.);
87
88// provide new histogram to data object
89 data->SetHistogram(GetHistogram("hDeg120_CND"),kTRUE);
90
91// perform all actions
92 fitter.DoActions();
93
94// remove output actions and add new
95 fitter.Draw("#data1,Gauss1,Gauss2,Gauss3,Gauss4");
96 fitter.Print("Pars");
97}
void Example5()
Definition Example5.cxx:59
int main(int argc, char **argv)
Definition Example5.cxx:33
TH1D * GetHistogram(const char *HistogramName)
Definition Example5.cxx:48
Data objects, which provides access to generic TH1 ROOT histogram.
void SetHistogram(TH1 *iHistogram, Bool_t iHistogramOwned=kFALSE)
Set histogram to object.
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.
TGo4FitModelGauss1 * AddGauss1(const char *DataName, const char *ModelName, Double_t iPosition, Double_t iWidth, Double_t iAmpl=1., Int_t Axis=0)
Add 1-dim gaussian model 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.
void Draw(Option_t *option) override
Draw fitter on current canvas.