GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
Example13.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#ifndef __CINT__
22
23#include <iostream>
24
25#include "TMath.h"
26#include "TH1.h"
27#include "TH2.h"
28#include "TCanvas.h"
29#include "TCutG.h"
30#include "TApplication.h"
31#include "TRandom.h"
32
33#include "TGo4Fitter.h"
35#include "TGo4FitDataRidge.h"
36#include "TGo4FitModelFormula.h"
37
38void Example13();
39
40int main(int argc, char **argv)
41{
42 TApplication theApp("Application", nullptr, nullptr);
43
44 Example13();
45
46 theApp.Run();
47
48 return 0;
49}
50
51#endif
52
53void AddRidge(TH2D *histo, double a, double k, double b, double xstart, int numsteps, int numpoints, double deviation)
54{
55 TRandom rnd(1234);
56
57 double x = xstart;
58
59 for (int i = 0; i < numsteps; i++) {
60 double y = a * exp(k * x) + b;
61
62 double alf = TMath::ATan(k * a * exp(k * x)) + TMath::Pi() / 2.;
63
64 for (int j = 0; j < numpoints; j++) {
65 double radius = rnd.Gaus(0., deviation);
66 histo->Fill(x + radius * cos(alf), y + radius * sin(alf));
67 }
68
69 x = x + 0.001 * sin(alf);
70 }
71}
72
74{
75 TH2D *histo = new TH2D("Histo", "Ridge y = a*exp(k*x)+b", 100, 0., 10., 100, 0., 10.);
76
77 std::cout << "Generating histogram " << std::endl;
78
79 AddRidge(histo, 10, -0.3, 2, 1.5, 10000, 100, 0.3);
80
81 AddRidge(histo, 10, -0.5, 0, 0.5, 10000, 50, 0.2);
82
83 AddRidge(histo, 10, -0.1, +2, 3.5, 10000, 50, 0.2);
84
85 std::cout << " Done " << std::endl;
86
87 return histo;
88}
89
90TCutG *MakeCut()
91{
92 Float_t xx[7] = {1.0, 4.0, 9.0, 9.5, 5.0, 2.0, 1.0};
93 Float_t yy[7] = {8.0, 2.5, 2.0, 4.0, 6.0, 9.5, 8.0};
94 return new TCutG("RangeCut", 7, xx, yy);
95}
96
98{
99 // model histogram with ridge with exponential function
100 TH2D *histo = MakeRidgeHistogram();
101 new TCanvas("Canvas1");
102 histo->Draw("LEGO2");
103
104 // create fitter, select fit function and not add standard actions list
105 TGo4Fitter fitter("Fitter", TGo4Fitter::ff_chi_square, kFALSE);
106
107 // create data object to represent of two-dimensional histogram
108 // bins, which are less then 3 are excluded
109 // select middle ridge by TCutG object
110 TGo4FitDataHistogram *datah = new TGo4FitDataHistogram("histogram", histo);
111 datah->SetExcludeLessThen(3);
112 datah->AddRangeCut(MakeCut());
113
114 // create ridge object, which select axis number 1 (y axis) as function of the rest coordinates
115 TGo4FitDataRidge *ridge = new TGo4FitDataRidge("ridge", datah, 1);
116 fitter.AddData(ridge);
117
118 // create formula function to approximate ridge function
119 // specific range and initial values for parameters need to be set
120 TGo4FitModelFormula *model = new TGo4FitModelFormula("RidgeFunc", "parA*exp(parK*x)+parB", 3, kFALSE);
121 model->SetRange(0, 2, 8.);
122 model->SetParsNames("parA", "parK", "parB");
123 model->SetParsValues(9., -0.2, 1.2);
124 fitter.AddModel("ridge", model);
125
126 // add minuit action
127 fitter.AddSimpleMinuit();
128
129 // use memory buffers for data objects
130 fitter.SetMemoryUsage(1);
131
132 // execute actions
133 fitter.DoActions();
134
135 // print parameters values
136 fitter.Print("Pars");
137
138 // draw results of fit
139 fitter.Draw("#ridge");
140}
int main(int argc, char **argv)
Definition Example13.cxx:40
TH2D * MakeRidgeHistogram()
Definition Example13.cxx:73
TCutG * MakeCut()
Definition Example13.cxx:90
void AddRidge(TH2D *histo, double a, double k, double b, double xstart, int numsteps, int numpoints, double deviation)
Definition Example13.cxx:53
void Example13()
Definition Example13.cxx:97
void SetRange(Int_t naxis, Double_t min, Double_t max)
Includes axis range in consideration.
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.
Special object to approximate ridges on multi-dimensional histograms.
void SetExcludeLessThen(Double_t limit=0.)
Sets limit to exclude bins, which not less then this limit.
Model object, which uses ROOT TFormula class facility.
void SetParsNames(const char *name0="Par0", const char *name1="Par1", const char *name2="Par2", const char *name3="Par3", const char *name4="Par4", const char *name5="Par5", const char *name6="Par6", const char *name7="Par7", const char *name8="Par8", const char *name9="Par9")
Set names of first 10 parameters.
void SetParsValues(Double_t *pars)
Set value for all parameters from array.
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.
void Draw(Option_t *option) override
Draw fitter on current canvas.
TGo4FitModel * AddModel(TGo4FitModel *m)
Add model component to fitter.