GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example8.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 "TH1.h"
25#include "TH2.h"
26#include "TFile.h"
27#include "TCanvas.h"
28#include "TCutG.h"
29#include "TApplication.h"
30
31#include "TGo4FitMinuit.h"
32#include "TGo4Fitter.h"
34#include "TGo4FitModelPolynom.h"
35#include "TGo4FitModelGauss2.h"
36#include "TGo4FitModelGaussN.h"
37
38void Example8();
39
40int main(int argc, char **argv)
41{
42 TApplication theApp("Application", nullptr, nullptr);
43
44 Example8();
45
46 theApp.Run();
47
48 return 0;
49}
50
51#endif
52
53void DrawHistogram(TH1 *histo, const char *CanvasName, const char *DrawOption)
54{
55 TCanvas *fCanvas = new TCanvas(CanvasName,"Draw of histogram",3);
56 fCanvas->cd();
57 histo->Draw(DrawOption);
58 fCanvas->Update();
59}
60
62{
63 Double_t x[] = { 2,3,8,7,2 };
64 Double_t y[] = { 8,3,2,7,8 };
65 TCutG *cut = new TCutG("cut1",5,x,y);
66 comp->AddRangeCut(cut);
67}
68
70{
71// create fitter
72 TGo4Fitter *fitter = new TGo4Fitter("Fitter","Example fitter object");
73
74// create dummy histogram and set with owneship flag
75 TH2D *histo = new TH2D("histo","dummy histogram",100,0.,10.,100,0.,10.);
76 fitter->AddData(new TGo4FitDataHistogram("data",histo,kTRUE));
77
78// create models component and assign them to fitter
79 TGo4FitModel *model = fitter->AddModel( "data", new TGo4FitModelGauss2("Gauss",5.,5.,1.,1.,-0.5) );
80 model->SetAmplValue(1000.);
81// only selected range will be used for modeling
82 AddRangeCut(model);
83
84// create result model without optimization, using initial parameters values
85 TH1 *res = (TH1 *) fitter->CreateDrawObject("GaussModel","data",kTRUE);
86 delete fitter;
87
88
89// draw modeled histogram
90 DrawHistogram(res,"Canvas1","SURF1");
91
92// create new fitter
93 fitter = new TGo4Fitter("Fitter2",TGo4Fitter::ff_ML_Poisson,kFALSE);
94
95// use modeled histogram as data
96 TGo4FitData *data = fitter->AddData(new TGo4FitDataHistogram("data",res));
97// only selected range will be used for data extracting and modeling
98 AddRangeCut(data);
99
100// create N-dimensional gauss with 2 dimensions and set postion and width parameters
101 model = fitter->AddModel( "data", new TGo4FitModelGaussN("Gauss",2) );
102 model->SetPosition(0,4.5);
103 model->SetPosition(1,4.5);
104 model->SetWidth(0,1.7);
105 model->SetWidth(1,1.7);
106 model->SetAmplValue(500.);
107
108 fitter->AddSimpleMinuit();
109
110 fitter->SetMemoryUsage(1);
111
112 fitter->DoActions();
113
114 fitter->Print("Pars");
115
116 delete fitter;
117}
void AddRangeCut(TGo4FitComponent *comp)
Definition Example8.cxx:61
int main(int argc, char **argv)
Definition Example8.cxx:40
void DrawHistogram(TH1 *histo, const char *CanvasName, const char *DrawOption)
Definition Example8.cxx:53
void Example8()
Definition Example8.cxx:69
Basic abstract class, combining common properties of data and model.
void SetAmplValue(Double_t iAmpl)
Set value of amplitude parameter.
void AddRangeCut(TCutG *cut, Bool_t exclude=kFALSE)
Add TCutG object as range condition for two-dimensional case.
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.
N-dimensional gaussian peak.
Basic abstract class for representing model components of fitted data.
virtual Bool_t SetPosition(Int_t naxis, Double_t pos)
Sets position of model component, if possible.
virtual Bool_t SetWidth(Int_t naxis, Double_t width)
Sets width of model component, if possible.
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=nullptr)
Executes actions list.
void AddSimpleMinuit()
Creates and add TGo4FitMinuit object to actions list.
Central class of Go4Fit package.
Definition TGo4Fitter.h:38
void Print(Option_t *option="") const override
Print containment of fitter.
TGo4FitData * AddData(TGo4FitData *d)
Add data object to fitter.
void SetMemoryUsage(Int_t iMemoryUsage)
Set value of memory usage.
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.