GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example11.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
22#ifndef __CINT__
23
24#include "TH1.h"
25#include "TFile.h"
26#include "TApplication.h"
27
28#include "TGo4Fitter.h"
29#include "TGo4FitPeakFinder.h"
30
31void Example11();
32
33int main(int argc, char **argv)
34{
35 TApplication theApp("Application", nullptr, nullptr);
36
37 Example11();
38
39 theApp.Run();
40
41 return 0;
42}
43
44#endif
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 not 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
67// Add peak finder for data1, which not remove previous models and
68// will use 1-order polynom for background
69 TGo4FitPeakFinder* finder = new TGo4FitPeakFinder("Finder", "data1", kFALSE, 1);
70
71// setup parameters for first peak finder.
72// Here first - amplitude threshold relative to amplitude maximum,
73// and minimum and maximum line width
74 finder->SetupForFirst(.3, 5., 30.);
75
76// add peak finder action at the beginning
77 fitter.AddActionAt(finder, 0);
78
79// perform all actions
80// kTRUE means, that action is able to add/delete components to fitter
81 fitter.DoActions(kTRUE);
82
83// print models parameters in lines sorting
84 fitter.Print("Lines");
85
86// Draw data and model
87 fitter.Draw("#data1");
88}
int main(int argc, char **argv)
Definition Example11.cxx:33
TH1D * GetHistogram(const char *HistogramName)
Definition Example11.cxx:47
void Example11()
Definition Example11.cxx:58
Peak finder action.
void SetupForFirst(Double_t MaxAmplFactor, Double_t MinWidth, Double_t MaxWidth)
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
Executes actions list.
void AddActionAt(TGo4FitterAction *Action, Int_t indx)
Add action to action list at specified index.
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 Draw(Option_t *option) override
Draw fitter on current canvas.