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