GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Example8.cxx
Go to the documentation of this file.
1 // $Id: Example8.cxx 2627 2019-10-01 08:02:45Z 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 #ifndef __CINT__
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TFile.h"
19 #include "TCanvas.h"
20 #include "TCutG.h"
21 #include "TApplication.h"
22 
23 #include "TGo4FitMinuit.h"
24 #include "TGo4Fitter.h"
25 #include "TGo4FitDataHistogram.h"
26 #include "TGo4FitModelPolynom.h"
27 #include "TGo4FitModelGauss2.h"
28 #include "TGo4FitModelGaussN.h"
29 
30 void Example8();
31 
32 int main(int argc, char **argv)
33 {
34  TApplication theApp("Application", 0, 0);
35 
36  Example8();
37 
38  theApp.Run();
39 
40  return 0;
41 }
42 
43 #endif
44 
45 void DrawHistogram(TH1* histo, const char* CanvasName, const char* DrawOption)
46 {
47  TCanvas *fCanvas = new TCanvas(CanvasName,"Draw of histogram",3);
48  fCanvas->cd();
49  histo->Draw(DrawOption);
50  fCanvas->Update();
51 }
52 
54 {
55  Double_t x[] = { 2,3,8,7,2 };
56  Double_t y[] = { 8,3,2,7,8 };
57  TCutG* cut = new TCutG("cut1",5,x,y);
58  comp->AddRangeCut(cut);
59 }
60 
61 void Example8()
62 {
63 // create fitter
64  TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
65 
66 // create dummy histogram and set with owneship flag
67  TH2D *histo = new TH2D("histo","dummy histogram",100,0.,10.,100,0.,10.);
68  fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
69 
70 // create models component and assign them to fitter
71  TGo4FitModel* model = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss",5.,5.,1.,1.,-0.5) );
72  model->SetAmplValue(1000.);
73 // only selected range will be used for modeling
74  AddRangeCut(model);
75 
76 // create result model without optimization, using initial parameters values
77  TH1* res = (TH1*) fitter->CreateDrawObject("GaussModel","data",kTRUE);
78  delete fitter;
79 
80 
81 // draw modeled histogram
82  DrawHistogram(res,"Canvas1","SURF1");
83 
84 // create new fitter
85  fitter = new TGo4Fitter("Fitter2",TGo4Fitter::ff_ML_Poisson,kFALSE);
86 
87 // use modeled histogram as data
88  TGo4FitData* data = fitter->AddData(new TGo4FitDataHistogram("data",res));
89 // only selected range will be used for data extracting and modeling
90  AddRangeCut(data);
91 
92 // create N-dimensional gauss with 2 dimensions and set postion and width parameters
93  model = fitter->AddModel( "data", new TGo4FitModelGaussN("Gauss",2) );
94  model->SetPosition(0,4.5);
95  model->SetPosition(1,4.5);
96  model->SetWidth(0,1.7);
97  model->SetWidth(1,1.7);
98  model->SetAmplValue(500.);
99 
100  fitter->AddSimpleMinuit();
101 
102  fitter->SetMemoryUsage(1);
103 
104  fitter->DoActions();
105 
106  fitter->Print("Pars");
107 
108  delete fitter;
109 }
virtual void Print(Option_t *option) const
Definition: TGo4Fitter.cxx:705
void SetMemoryUsage(Int_t iMemoryUsage)
Definition: TGo4Fitter.cxx:70
int main(int argc, char **argv)
Definition: Example8.cxx:32
void AddRangeCut(TGo4FitComponent *comp)
Definition: Example8.cxx:53
virtual Bool_t SetPosition(Int_t naxis, Double_t pos)
void SetAmplValue(Double_t iAmpl)
TGo4FitData * AddData(TGo4FitData *d)
Definition: TGo4Fitter.cxx:116
void DrawHistogram(TH1 *histo, const char *CanvasName, const char *DrawOption)
Definition: Example8.cxx:45
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
void AddRangeCut(TCutG *cut, Bool_t exclude=kFALSE)
virtual Bool_t SetWidth(Int_t naxis, Double_t width)
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:201
TObject * CreateDrawObject(const char *ObjName, const char *DataName, Bool_t IsModel=kFALSE, const char *ModelName=0)
Definition: TGo4Fitter.cxx:851
void Example8()
Definition: Example8.cxx:61