GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example11.cxx
Go to the documentation of this file.
1 // $Id: Example11.cxx 3058 2021-03-12 11:01:32Z linev $
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 
14 // Go4Fit Example N11
15 
16 
17 #ifndef __CINT__
18 
19 #include "TH1.h"
20 #include "TFile.h"
21 #include "TApplication.h"
22 
23 #include "TGo4Fitter.h"
24 #include "TGo4FitPeakFinder.h"
25 
26 void Example11();
27 
28 int main(int argc, char **argv)
29 {
30  TApplication theApp("Application", 0, 0);
31 
32  Example11();
33 
34  theApp.Run();
35 
36  return 0;
37 }
38 
39 #endif
40 
41 // routine to read histogram from examples file
42 TH1D* GetHistogram(const char* HistogramName)
43 {
44  TFile *f1 = TFile::Open("histograms.root");
45  if (f1==0) return 0;
46  TH1D *histo = 0;
47  f1->GetObject(HistogramName, histo);
48  if (histo) histo->SetDirectory(0);
49  return histo;
50 }
51 
52 void Example11()
53 {
54 // create fitter, select fit function and not add standard actions list
55  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
56 
57 // add histogram to fitter, which should be fitted
58  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
59 
60 
61 // Add peak finder for data1, which not remove previous models and
62 // will use 1-order polynom for background
63  TGo4FitPeakFinder* finder = new TGo4FitPeakFinder("Finder", "data1", kFALSE, 1);
64 
65 // setup parameters for first peak finder.
66 // Here first - amplitude threshold relative to amplitude maximum,
67 // and minimum and maximum line width
68  finder->SetupForFirst(.3, 5., 30.);
69 
70 // add peak finder action at the beginning
71  fitter.AddActionAt(finder, 0);
72 
73 // perform all actions
74 // kTRUE means, that action is able to add/delete components to fitter
75  fitter.DoActions(kTRUE);
76 
77 // print models parameters in lines sorting
78  fitter.Print("Lines");
79 
80 // Draw data and model
81  fitter.Draw("#data1");
82 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:705
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:981
int main(int argc, char **argv)
Definition: Example11.cxx:28
void Example11()
Definition: Example11.cxx:52
void SetupForFirst(Double_t MaxAmplFactor, Double_t MinWidth, Double_t MaxWidth)
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TH1D * GetHistogram(const char *HistogramName)
Definition: Example11.cxx:42
void AddActionAt(TGo4FitterAction *Action, Int_t indx)
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124