GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4FitModelPolynom.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#include "TGo4FitModelPolynom.h"
15
16#include "TMath.h"
17
18#include "TGo4FitParameter.h"
19
23
24TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX) :
25 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
26{
27 CreateOrdersPars(&iOrderX, 0, 0);
29}
30
31TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX, Double_t iOrderY) :
32 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
33{
34 Double_t arr[2] = { iOrderX, iOrderY };
35 CreateOrdersPars(arr, 0, 1);
37}
38
39TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, Double_t iOrderX, Double_t iOrderY, Double_t iOrderZ) :
40 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
41{
42 Double_t arr[3] = { iOrderX, iOrderY, iOrderZ };
43 CreateOrdersPars(arr, 0, 2);
45}
46
47TGo4FitModelPolynom::TGo4FitModelPolynom(const char *iName, const TArrayD& iPolynomOrders) :
48 TGo4FitModel(iName,"polynomial function",kTRUE), fxAllOrders(nullptr)
49{
50 CreateOrdersPars(iPolynomOrders.GetArray(),0,iPolynomOrders.GetSize()-1);
52}
53
58
59void TGo4FitModelPolynom::CreateOrdersPars(const Double_t *orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx)
60{
61 for(Int_t n=startaxis;n<=maxaxis;n++) {
62 TString infostr;
63 infostr.Form("Polynom order for axis %d",n);
64 if (orders) NewParameter(GetOrderParName(n),infostr.Data(),orders[n],kTRUE, AtIndx);
65 else NewParameter(GetOrderParName(n),infostr.Data(),0.,kTRUE, AtIndx);
66 }
67}
68
69TString TGo4FitModelPolynom::GetOrderParName(Int_t naxis) const
70{
71 TString res;
72 res.Form("Order%d",naxis);
73 return res;
74}
75
77{
79 return par ? par->GetValue() : 0.;
80}
81
83{
84 Int_t naxis = 0;
85 while (FindPar(GetOrderParName(naxis)))
86 naxis++;
87 return naxis-1;
88}
89
91{
92 Int_t numaxisold = GetMaxNumAxis();
93 if ((numaxis < 0) || (numaxis == numaxisold))
94 return kFALSE;
95 if (numaxis < numaxisold)
96 for (Int_t n = numaxis + 1; n <= numaxisold; n++)
98 else {
99 Int_t indx = GetParIndex(FindPar(GetOrderParName(numaxisold)));
100 CreateOrdersPars(nullptr, numaxisold + 1, numaxis, indx + 1);
101 }
102
103 return kTRUE;
104}
105
106Bool_t TGo4FitModelPolynom::BeforeEval(Int_t NDimension)
107{
108 if (fxAllOrders)
109 delete fxAllOrders;
110 Par_ndim = NDimension;
111 fxAllOrders = new TArrayD(Par_ndim);
112 fxAllOrders->Reset(0.);
113 Par_orders = fxAllOrders->GetArray();
114 for (Int_t i = 0; i < Par_ndim; i++)
116 return kTRUE;
117}
118
119Double_t TGo4FitModelPolynom::EvalN(const Double_t *v)
120{
121 Double_t zn = 1.;
122 for (Int_t n = 0; n < Par_ndim; n++)
123 zn *= TMath::Power(v[n], Par_orders[n]);
124 return zn;
125}
126
128{
129 if (fxAllOrders) {
130 delete fxAllOrders;
131 fxAllOrders = nullptr;
132 }
133}
134
135void TGo4FitModelPolynom::Print(Option_t *option) const
136{
137 TGo4FitModel::Print(option);
138}
TGo4FitParameter * NewParameter(const char *Name, const char *Title, Double_t iValue=0., Bool_t Fixed=kFALSE, Int_t AtIndx=-1)
Create new parameter with provided properties and add to parameters list.
Double_t * Par_orders
Temporary variable for EvalN() function.
Bool_t BeforeEval(Int_t NDimension) override
Prepares (if necessary) some intermediate variables to be able calculate values of model via EvalN() ...
TArrayD * fxAllOrders
Temporary variable for EvalN() function.
Double_t GetPolynomOrder(Int_t naxis)
Get polynom order for specified axis.
Bool_t SetMaxNumAxis(Int_t numaxis)
Sets number of dimensions (maximum axis numbers) in polynom.
virtual ~TGo4FitModelPolynom()
Destroys TGo4FitModelPolynom object.
void Print(Option_t *option="") const override
Print information on standard output.
void CreateOrdersPars(const Double_t *orders, Int_t startaxis, Int_t maxaxis, Int_t AtIndx=-1)
Int_t GetMaxNumAxis()
Returns maximum axis number (dimensions number) in polynom.
TString GetOrderParName(Int_t naxis) const
Int_t Par_ndim
Temporary variable for EvalN() function.
TGo4FitModelPolynom()
Default constructor.
Double_t EvalN(const Double_t *v) override
Calculates value of model according current parameters values and provided axes values.
void AfterEval() override
Clear buffers, which were created by BeforeEval() method.
void SetBackgroundGroupIndex()
Set group index to background (index = 0).
void Print(Option_t *option="") const override
Print information about model object on standard output.
TGo4FitModel()
Default constructor.
Model and data objects parameter.
Double_t GetValue() const
Return parameter value.
TGo4FitParameter * FindPar(const char *ParName)
Find parameter object with given name.
Int_t GetParIndex(const TGo4FitParameter *par)
Return index of given parameter in list.
Bool_t RemovePar(const char *name)
Remove parameter from list with given name.