GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example11.cxx
Go to the documentation of this file.
1 // $Id: Example11.cxx 555 2010-01-27 12:40:54Z 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 für 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 = (TH1D*) f1->Get(HistogramName);
47  if (histo) histo->SetDirectory(0);
48  return histo;
49 }
50 
51 void Example11()
52 {
53 // create fitter, select fit function and not add standard actions list
54  TGo4Fitter fitter("Fitter", TGo4Fitter::ff_ML_Poisson, kTRUE);
55 
56 // add histogram to fitter, which should be fitted
57  fitter.AddH1("data1", GetHistogram("hDeg120_P_c"), kTRUE, 2200., 2900.);
58 
59 
60 // Add peak finder for data1, which not remove previous models and
61 // will use 1-order polynom for background
62  TGo4FitPeakFinder* finder = new TGo4FitPeakFinder("Finder", "data1", kFALSE, 1);
63 
64 // setup parameters for first peak finder.
65 // Here first - amplitude threshold relative to amplitude maximum,
66 // and minimum and maximum line width
67  finder->SetupForFirst(.3, 5., 30.);
68 
69 // add peak finder action at the beginning
70  fitter.AddActionAt(finder, 0);
71 
72 // perform all actions
73 // kTRUE means, that action is able to add/delete components to fitter
74  fitter.DoActions(kTRUE);
75 
76 // print models parameters in lines sorting
77  fitter.Print("Lines");
78 
79 // Draw data and model
80  fitter.Draw("#data1");
81 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:707
virtual void Draw(Option_t *option)
Definition: TGo4Fitter.cxx:983
int main(int argc, char **argv)
Definition: Example11.cxx:28
void Example11()
Definition: Example11.cxx:51
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:126