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