GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
Example9.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 
14 #ifndef __CINT__
15 
16 #include <iostream>
17 
18 #include "TH1.h"
19 #include "TH2.h"
20 #include "TFile.h"
21 #include "TCanvas.h"
22 #include "TApplication.h"
23 
24 #include "TGo4FitMinuit.h"
25 #include "TGo4Fitter.h"
26 #include "TGo4FitDataHistogram.h"
27 #include "TGo4FitModelPolynom.h"
28 #include "TGo4FitModelGauss2.h"
29 #include "TGo4FitModelGaussN.h"
30 
31 
32 void Example9();
33 
34 int main(int argc, char **argv)
35 {
36  TApplication theApp("Application", nullptr, nullptr);
37 
38  Example9();
39 
40  theApp.Run();
41 
42  return 0;
43 }
44 
45 #endif
46 
47 void DrawHistogram(TH1 *histo, const char *CanvasName, const char *DrawOption)
48 {
49  TCanvas *fCanvas = new TCanvas(CanvasName, "Draw of histogram",3);
50  fCanvas->cd();
51  histo->Draw(DrawOption);
52  fCanvas->Update();
53 }
54 
55 void Example9()
56 {
57  // create fitter
58  TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
59 
60  // create dummy histogram and set with ownership flag
61  TH2D *histo = new TH2D("histo","dummy histogram",1000,0.,10.,1000,0.,10.);
62  TGo4FitData *data = fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
63  data->SetRange(0,1.,3.); data->SetRange(0,7.,9.);
64  data->SetRange(1,1.,3.); data->SetRange(1,7.,9.);
65 
66  // create models component and assign them to fitter
67  TGo4FitModel *model1 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss1",2.,8.,.5,.5,0.) );
68  model1->SetAmplValue(1000.);
69 
70  TGo4FitModel *model2 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss2",8.,8.,.5,.5,0.) );
71  model2->SetAmplValue(1000.);
72 
73  TGo4FitModel *model3 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss3",8.,2.,.5,.5,0.) );
74  model3->SetAmplValue(1000.);
75 
76  TGo4FitModel *model4 = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss4",2.,2.,.5,.5,0.) );
77  model4->SetAmplValue(1000.);
78 
79 
80  // create result model without optimization, using initial parameters values
81  TH1 *res1 = (TH1 *) fitter->CreateDrawObject("Large", "data", kTRUE);
82 
83  histo = new TH2D("histo2","dummy histogram",10,0.,10.,10,0.,10.);
84  fitter->SetObject("data", histo, kTRUE);
85 
86  TH1 *res2 = (TH1 *) fitter->CreateDrawObject("Small", "data", kTRUE);
87 
88  model1->SetIntegrationsProperty(5);
89  model2->SetIntegrationsProperty(5);
90  model3->SetIntegrationsProperty(5);
91  model4->SetIntegrationsProperty(5);
92 
93  TH1 *res3 = (TH1 *) fitter->CreateDrawObject("SmallI", "data", kTRUE);
94 
95  delete fitter;
96 
97 
98  // draw modeled histogram
99 // DrawHistogram(res1,"Canvas1","SURF1"); // takes too long time
100  DrawHistogram(res2,"Canvas2","SURF1");
101  DrawHistogram(res3,"Canvas3","SURF1");
102 
103  Double_t i1 = res1->Integral()/1000000.;
104  Double_t i2 = res2->Integral()/100.;
105  Double_t i3 = res3->Integral()/100.;
106 
107  std::cout << "Integral over 1000x1000 points = " << i1 << std::endl;
108  std::cout << "Integral over 10x10 points = " << i2 << std::endl;
109  std::cout << "Integral over 10x10 with model integr. = " << i3 << std::endl << std::endl;
110 
111  std::cout << "Integral2/Integral1 = " << i2/i1 << std::endl;
112  std::cout << "Integral3/Integral1 = " << i3/i1 << std::endl;
113 }
TGo4FitSlot * SetObject(TObject *obj, Bool_t iOwned=kFALSE)
int main(int argc, char **argv)
Definition: Example9.cxx:34
void SetAmplValue(Double_t iAmpl)
TGo4FitData * AddData(TGo4FitData *d)
Definition: TGo4Fitter.cxx:119
void SetRange(Int_t naxis, Double_t min, Double_t max)
void DrawHistogram(TH1 *histo, const char *CanvasName, const char *DrawOption)
Definition: Example9.cxx:47
void SetIntegrationsProperty(Int_t iMinIntegrDepth, Int_t iMaxIntegrDepth=0, Double_t iIntegrEps=0., Bool_t iAbsoluteEps=kFALSE, Bool_t iIntegrScaling=kFALSE)
TObject * CreateDrawObject(const char *ObjName, const char *DataName, Bool_t IsModel=kFALSE, const char *ModelName=nullptr)
Definition: TGo4Fitter.cxx:935
TGo4FitModel * AddModel(TGo4FitModel *m)
Definition: TGo4Fitter.cxx:210
void Example9()
Definition: Example9.cxx:55